mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 22:38:56 +08:00
refactor(editor): rename model.doc to store (#12172)
This commit is contained in:
@@ -78,7 +78,7 @@ export class FrameBlockModel
|
||||
for (const key of this.childIds) {
|
||||
const element =
|
||||
this.surface.getElementById(key) ||
|
||||
(this.surface.doc.getModelById(key) as GfxBlockElementModel);
|
||||
(this.surface.store.getModelById(key) as GfxBlockElementModel);
|
||||
|
||||
element && elements.push(element);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ export class FrameBlockModel
|
||||
addChild(element: GfxModel) {
|
||||
if (!canSafeAddToContainer(this, element)) return;
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds = {
|
||||
...this.props.childElementIds,
|
||||
[element.id]: true,
|
||||
@@ -118,7 +118,7 @@ export class FrameBlockModel
|
||||
newChildren[id] = true;
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds = {
|
||||
...this.props.childElementIds,
|
||||
...newChildren,
|
||||
@@ -153,7 +153,7 @@ export class FrameBlockModel
|
||||
}
|
||||
|
||||
removeChild(element: GfxModel): void {
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds &&
|
||||
delete this.props.childElementIds[element.id];
|
||||
});
|
||||
|
||||
@@ -14,15 +14,17 @@ export class RootBlockModel extends BlockModel<RootBlockProps> {
|
||||
super();
|
||||
const createdSubscription = this.created.subscribe(() => {
|
||||
createdSubscription.unsubscribe();
|
||||
this.doc.slots.rootAdded.subscribe(id => {
|
||||
const model = this.doc.getModelById(id);
|
||||
this.store.slots.rootAdded.subscribe(id => {
|
||||
const model = this.store.getModelById(id);
|
||||
if (model instanceof RootBlockModel) {
|
||||
const newDocMeta = this.doc.workspace.meta.getDocMeta(model.doc.id);
|
||||
const newDocMeta = this.store.workspace.meta.getDocMeta(
|
||||
model.store.id
|
||||
);
|
||||
if (
|
||||
!newDocMeta ||
|
||||
newDocMeta.title !== model.props.title.toString()
|
||||
) {
|
||||
this.doc.workspace.meta.setDocMeta(model.doc.id, {
|
||||
this.store.workspace.meta.setDocMeta(model.store.id, {
|
||||
title: model.props.title.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
return;
|
||||
}
|
||||
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.set(element.id, true);
|
||||
});
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
if (!this.children) {
|
||||
return;
|
||||
}
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.delete(element.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ function watchLayoutType(
|
||||
return;
|
||||
}
|
||||
|
||||
instance.surface.doc.transact(() => {
|
||||
instance.surface.store.transact(() => {
|
||||
instance['_tree']?.children.forEach(child => {
|
||||
if (!instance.children.has(child.id)) {
|
||||
return;
|
||||
@@ -285,7 +285,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
|
||||
const type = (props.type as string) ?? 'shape';
|
||||
let id: string;
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
const parentNode = parent ? this._nodeMap.get(parent)! : null;
|
||||
|
||||
if (parentNode) {
|
||||
@@ -433,7 +433,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
const loops = findInfiniteLoop(rootNode, mindmapNodeMap);
|
||||
|
||||
if (loops.length) {
|
||||
this.surface.doc.withoutTransact(() => {
|
||||
this.surface.store.withoutTransact(() => {
|
||||
loops.forEach(loop => {
|
||||
if (loop.detached) {
|
||||
loop.chain.forEach(node => {
|
||||
@@ -745,7 +745,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
const offsetX = targetPos[0] - x;
|
||||
const offsetY = targetPos[1] - y;
|
||||
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.childElements.forEach(el => {
|
||||
const deserializedXYWH = deserializeXYWH(el.xywh);
|
||||
|
||||
@@ -775,7 +775,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
removedDescendants.push(node.id);
|
||||
};
|
||||
|
||||
surface.doc.transact(() => {
|
||||
surface.store.transact(() => {
|
||||
remove(this._nodeMap.get(element.id)!);
|
||||
});
|
||||
|
||||
@@ -877,7 +877,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
};
|
||||
|
||||
node.children.forEach(changeNodesVisibility);
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.set(node.id, {
|
||||
...node.detail,
|
||||
collapsed,
|
||||
@@ -921,7 +921,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
|
||||
const map: Y.Map<NodeDetail> = new Y.Map();
|
||||
const surface = instance.surface;
|
||||
const doc = surface.doc;
|
||||
const doc = surface.store;
|
||||
const recursive = (
|
||||
node: NodeType,
|
||||
parent: string | null = null,
|
||||
|
||||
Reference in New Issue
Block a user