feat(editor): unify block props api (#10888)

Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
Saul-Mirone
2025-03-16 05:48:34 +00:00
parent 8f9e5bf0aa
commit 26285f7dcb
193 changed files with 1019 additions and 891 deletions
@@ -87,7 +87,9 @@ export class FrameBlockModel
}
get childIds() {
return this.childElementIds ? Object.keys(this.childElementIds) : [];
return this.props.childElementIds
? Object.keys(this.props.childElementIds)
: [];
}
get descendantElements(): GfxModel[] {
@@ -98,7 +100,10 @@ export class FrameBlockModel
if (!canSafeAddToContainer(this, element)) return;
this.doc.transact(() => {
this.childElementIds = { ...this.childElementIds, [element.id]: true };
this.props.childElementIds = {
...this.props.childElementIds,
[element.id]: true,
};
});
}
@@ -114,8 +119,8 @@ export class FrameBlockModel
}
this.doc.transact(() => {
this.childElementIds = {
...this.childElementIds,
this.props.childElementIds = {
...this.props.childElementIds,
...newChildren,
};
});
@@ -126,7 +131,9 @@ export class FrameBlockModel
}
hasChild(element: GfxModel): boolean {
return this.childElementIds ? element.id in this.childElementIds : false;
return this.props.childElementIds
? element.id in this.props.childElementIds
: false;
}
hasDescendant(element: GfxModel): boolean {
@@ -147,7 +154,8 @@ export class FrameBlockModel
removeChild(element: GfxModel): void {
this.doc.transact(() => {
this.childElementIds && delete this.childElementIds[element.id];
this.props.childElementIds &&
delete this.props.childElementIds[element.id];
});
}
}