Skip to content

Commit

Permalink
fix: fix node parent assignment and update settings check
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Mar 7, 2024
1 parent 4c83b94 commit 20ddbed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/designer/src/document/node/node-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export class NodeChildren implements Omit<IPublicModelNodeChildren<INode>,
let removedNode;
if (node) {
removedNode = this.children.splice(start, deleteCount, node);
node.internalSetParent(this.owner);
} else {
removedNode = this.children.splice(start, deleteCount);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/designer/src/document/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>

isInited = false;

_settingEntry: ISettingTopEntry;
_settingEntry?: ISettingTopEntry;

get settingEntry(): ISettingTopEntry {
if (this._settingEntry) return this._settingEntry;
Expand Down Expand Up @@ -988,6 +988,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
this.props.purge();
this.settingEntry?.purge();
this.children?.purge();
this._settingEntry = undefined;
}

internalPurgeStart() {
Expand Down
10 changes: 10 additions & 0 deletions packages/designer/tests/document/node/node-children.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe('NodeChildren 方法测试', () => {
expect(children.length).toBe(2);
});

it('split add node and update node parent', () => {
const firstBtn = doc.getNode('node_k1ow3cbn')!;
const { children } = firstBtn.parent!;
const node = doc.createNode({ componentName: 'Button' });

children.splice(0, 0, node);

expect(node.parent).toBe(firstBtn.parent);
})

it('map', () => {
const firstBtn = doc.getNode('node_k1ow3cbn')!;
const { children } = firstBtn.parent!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class SettingsPrimaryPane extends Component<ISettingsPrimaryPaneProps, {
render() {
const { settings } = this.main;
const editor = this.props.engineEditor;
if (!settings) {
if (!settings || !settings.first) {
// 未选中节点,提示选中 或者 显示根节点设置
return (
<div className="lc-settings-main">
Expand Down

0 comments on commit 20ddbed

Please sign in to comment.