refactor(editor): rename model.doc to store (#12172)

This commit is contained in:
Saul-Mirone
2025-05-07 09:17:01 +00:00
parent eb62d0e853
commit 95b9e4b3d0
95 changed files with 264 additions and 246 deletions

View File

@@ -12,9 +12,9 @@ export const connectorWatcher: SurfaceMiddleware = (
surface: SurfaceBlockModel
) => {
const hasElementById = (id: string) =>
surface.hasElementById(id) || surface.doc.hasBlock(id);
surface.hasElementById(id) || surface.store.hasBlock(id);
const elementGetter = (id: string) =>
surface.getElementById(id) ?? (surface.doc.getModelById(id) as GfxModel);
surface.getElementById(id) ?? (surface.store.getModelById(id) as GfxModel);
const updateConnectorPath = (connector: ConnectorElementModel) => {
if (
((connector.source?.id && hasElementById(connector.source.id)) ||
@@ -70,7 +70,7 @@ export const connectorWatcher: SurfaceMiddleware = (
addToUpdateList(element as ConnectorElementModel);
}
}),
surface.doc.slots.blockUpdated.subscribe(payload => {
surface.store.slots.blockUpdated.subscribe(payload => {
if (
payload.type === 'add' ||
(payload.type === 'update' && payload.props.key === 'xywh')

View File

@@ -34,7 +34,7 @@ export const mindmap: ElementRenderer<MindmapElementModel> = (
const { connector, outdated } = result;
const elementGetter = (id: string) =>
model.surface.getElementById(id) ??
(model.surface.doc.getModelById(id) as GfxModel);
(model.surface.store.getModelById(id) as GfxModel);
if (outdated) {
ConnectorPathGenerator.updatePath(connector, null, elementGetter);

View File

@@ -116,7 +116,7 @@ function moveNodePosition(
)
: (node.detail.index ?? undefined);
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
const val: NodeDetail = {
...node.detail,
index,
@@ -139,7 +139,7 @@ export function applyStyle(
mindmap: MindmapElementModel,
shouldFitContent: boolean = false
) {
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
const style = mindmap.styleGetter;
if (!style) return;
@@ -208,7 +208,7 @@ export function addNode(
)
: node.detail.index;
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
mindmap.children.set(node.id, {
...node.detail,
index,
@@ -281,7 +281,7 @@ export function addTree(
if (!('text' in tree)) {
// Modify the children ymap directly hence need transaction
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
traverse(tree, parent, sibling);
});
@@ -328,7 +328,7 @@ export function detachMindmap(
subtree.children.forEach(child => traverse(child));
};
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
traverse(subtree);
});
@@ -351,7 +351,7 @@ export function handleLayout(
applyStyle(mindmap, true);
}
mindmap.surface.doc.transact(() => {
mindmap.surface.store.transact(() => {
const path = mindmap.getPath(tree.id);
layout(tree, mindmap, layoutType ?? mindmap.getLayoutDir(tree.id), path);
});

View File

@@ -68,7 +68,7 @@ export function drawGeneralShape(
const { blur, offsetX, offsetY, color } = shapeModel.shadow;
const scale = ctx.getTransform().a;
const enableShadowBlur = shapeModel.surface.doc
const enableShadowBlur = shapeModel.surface.store
.get(FeatureFlagService)
.getFlag('enable_shape_shadow_blur');

View File

@@ -21,7 +21,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
const { blockJson } = data;
const newId = regeneratedIdMap.has(blockJson.id)
? regeneratedIdMap.get(blockJson.id)!
: job.model.doc.workspace.idGenerator();
: job.model.store.workspace.idGenerator();
if (!regeneratedIdMap.has(blockJson.id)) {
regeneratedIdMap.set(blockJson.id, newId);
@@ -63,7 +63,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
});
blockJson.children.forEach(block => {
regeneratedIdMap.set(block.id, job.model.doc.workspace.idGenerator());
regeneratedIdMap.set(block.id, job.model.store.workspace.idGenerator());
});
defered.forEach(id => {

View File

@@ -97,7 +97,7 @@ export class TemplateJob {
type: TemplateType;
constructor({ model, type, middlewares }: TemplateJobConfig) {
this.job = model.doc.getTransformer();
this.job = model.store.getTransformer();
this.model = model;
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
? (type as TemplateType)
@@ -118,7 +118,7 @@ export class TemplateJob {
private _getMergeBlockId(modelData: BlockSnapshot) {
switch (modelData.flavour as MergeBlockFlavour) {
case 'affine:page':
return this.model.doc.root!.id;
return this.model.store.root!.id;
case 'affine:surface':
return this.model.id;
}
@@ -174,7 +174,7 @@ export class TemplateJob {
index?: number;
}[]
) {
const doc = this.model.doc;
const doc = this.model.store;
const mergeIdMapping = new Map<string, string>();
const deferInserting: typeof modelDataList = [];
@@ -199,7 +199,7 @@ export class TemplateJob {
if (isMergeBlock) {
this._mergeProps(
json,
this.model.doc.getModelById(
this.model.store.getModelById(
this._getMergeBlockId(json)
) as BlockModel
);
@@ -320,12 +320,12 @@ export class TemplateJob {
from: Record<string, Record<string, unknown>>,
to: Y.Map<Y.Map<unknown>>
) {
const schema = this.model.doc.schema.get('affine:surface');
const schema = this.model.store.schema.get('affine:surface');
const surfaceTransformer = schema?.transformer?.(
new Map()
) as SurfaceBlockTransformer;
this.model.doc.transact(() => {
this.model.store.transact(() => {
const defered: [string, Record<string, unknown>][] = [];
Object.entries(from).forEach(([id, val]) => {