fix: fix node parent assignment and update settings check

This commit is contained in:
liujuping 2024-03-06 17:20:51 +08:00 committed by 林熠
parent 0d7ae43b79
commit d2138d7edb
4 changed files with 14 additions and 2 deletions

View File

@ -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);
}

View File

@ -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;
@ -988,6 +988,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
this.props.purge();
this.settingEntry?.purge();
this.children?.purge();
this._settingEntry = undefined;
}
internalPurgeStart() {

View File

@ -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!;

View File

@ -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">