From 95b9e4b3d08ff00507d3164ee84599cef02abd1a Mon Sep 17 00:00:00 2001 From: Saul-Mirone Date: Wed, 7 May 2025 09:17:01 +0000 Subject: [PATCH] refactor(editor): rename model.doc to store (#12172) --- .github/actions/deploy/deploy.mjs | 2 +- .../blocks/attachment/src/attachment-block.ts | 2 +- .../attachment/src/components/rename-model.ts | 2 +- .../attachment/src/configs/slash-menu.ts | 4 +- .../affine/blocks/attachment/src/embed.ts | 6 +-- .../affine/blocks/attachment/src/utils.ts | 2 +- .../blocks/bookmark/src/configs/slash-menu.ts | 4 +- .../blocks/callout/src/configs/slash-menu.ts | 15 ++++--- .../affine/blocks/code/src/code-block.ts | 2 +- .../blocks/code/src/code-toolbar/utils.ts | 2 +- .../data-view/src/configs/slash-menu.ts | 4 +- .../blocks/data-view/src/data-source.ts | 4 +- .../blocks/data-view/src/data-view-model.ts | 14 +++---- .../blocks/database/src/configs/slash-menu.ts | 4 +- .../affine/blocks/database/src/data-source.ts | 12 +++--- .../blocks/database/src/database-block.ts | 4 +- .../src/detail-panel/note-renderer.ts | 2 +- .../blocks/database/src/utils/block-utils.ts | 28 ++++++------- .../configs/slash-menu.ts | 10 +++-- .../embed-edgeless-linked-doc-block.ts | 4 +- .../embed-linked-doc-block.ts | 14 +++---- .../embed-edgeless-synced-doc-block.ts | 4 +- .../embed-synced-doc-block.ts | 16 +++---- .../embed-figma-block/configs/slash-menu.ts | 2 +- .../embed-github-block/configs/slash-menu.ts | 2 +- .../components/embed-iframe-error-card.ts | 2 +- .../embed-iframe-link-input-base.ts | 2 +- .../configs/slash-menu/slash-menu.ts | 2 +- .../embed-loom-block/configs/slash-menu.ts | 2 +- .../embed-youtube-block/configs/slash-menu.ts | 2 +- .../blocks/image/src/configs/slash-menu.ts | 2 +- .../blocks/image/src/image-resize-manager.ts | 4 +- .../affine/blocks/image/src/image-spec.ts | 2 +- blocksuite/affine/blocks/image/src/utils.ts | 8 ++-- .../blocks/list/src/utils/get-list-icon.ts | 6 +-- .../blocks/note/src/configs/slash-menu.ts | 10 +++-- .../blocks/note/src/note-edgeless-block.ts | 4 +- .../paragraph/src/utils/merge-with-prev.ts | 6 +-- .../blocks/surface-ref/src/portal/note.ts | 6 +-- .../surface-ref/src/surface-ref-block.ts | 2 +- .../export-manager/export-manager.ts | 2 +- .../blocks/surface/src/surface-model.ts | 2 +- .../blocks/surface/src/utils/update-xywh.ts | 2 +- .../blocks/table/src/configs/slash-menu.ts | 2 +- .../blocks/table/src/table-data-manager.ts | 42 +++++++++---------- .../embed-card-modal/embed-card-edit-modal.ts | 5 ++- .../frame-panel/src/body/frame-panel-body.ts | 2 +- .../frame-panel/src/card/frame-preview.ts | 2 +- .../outline/src/card/outline-preview.ts | 2 +- .../gfx/connector/src/connector-watcher.ts | 6 +-- .../gfx/mindmap/src/element-renderer.ts | 2 +- .../affine/gfx/mindmap/src/view/utils.ts | 12 +++--- .../shape/src/element-renderer/shape/utils.ts | 2 +- .../src/services/template-middlewares.ts | 4 +- .../gfx/template/src/services/template.ts | 12 +++--- .../model/src/blocks/frame/frame-model.ts | 8 ++-- .../model/src/blocks/root/root-block-model.ts | 10 +++-- .../affine/model/src/elements/group/group.ts | 4 +- .../model/src/elements/mindmap/mindmap.ts | 14 +++---- .../affine/rich-text/src/markdown/to-code.ts | 2 +- .../src/adapters/middlewares/replace-id.ts | 2 +- .../shared/src/utils/dnd/calc-drop-target.ts | 2 +- .../src/utils/model/get-content-block.ts | 4 +- .../src/utils/model/merge-to-code-model.ts | 2 +- .../shared/src/utils/model/transform-model.ts | 2 +- .../drag-handle/src/helpers/preview-helper.ts | 2 +- .../widgets/frame-title/src/frame-title.ts | 2 +- .../std/src/gfx/model/gfx-block-model.ts | 6 +-- .../src/gfx/model/surface/decorators/field.ts | 4 +- .../src/gfx/model/surface/element-model.ts | 8 ++-- .../src/gfx/model/surface/surface-model.ts | 26 ++++++------ .../store/src/model/block/block-model.ts | 6 +-- .../src/model/block/flat-sync-controller.ts | 2 +- .../store/src/model/block/sync-controller.ts | 2 +- .../framework/store/src/model/store/query.ts | 2 +- .../__tests__/edgeless/surface-model.spec.ts | 2 +- .../src/__tests__/utils/setup.ts | 2 +- .../components/attachment-viewer-panel.ts | 2 +- .../ai/actions/edgeless-response.ts | 2 +- .../ai/blocks/ai-chat-block/ai-chat-spec.ts | 2 +- .../ai/mini-mindmap/surface-block.ts | 2 +- .../pdf/pdf-viewer-embedded.tsx | 2 +- .../src/blocksuite/attachment-viewer/utils.ts | 2 +- .../extensions/attachment-embed-view.tsx | 2 +- .../edgeless-embed-synced-doc-header.tsx | 2 +- .../edgeless-note-header.tsx | 8 ++-- .../edgeless-block-header/index.tsx | 8 ++-- .../extensions/editor-config/database.ts | 2 +- .../media/entities/audio-attachment-block.ts | 14 +++---- .../media/services/audio-attachment.ts | 4 +- .../media/services/audio-media-manager.ts | 4 +- .../frontend/core/src/modules/media/utils.ts | 2 +- .../modules/peek-view/entities/peek-view.ts | 8 ++-- .../peek-view/view/image-preview/index.tsx | 2 +- tests/blocksuite/e2e/utils/asserts.ts | 4 +- 95 files changed, 264 insertions(+), 246 deletions(-) diff --git a/.github/actions/deploy/deploy.mjs b/.github/actions/deploy/deploy.mjs index e4af662745..e0633fc277 100644 --- a/.github/actions/deploy/deploy.mjs +++ b/.github/actions/deploy/deploy.mjs @@ -104,7 +104,7 @@ const createHelmCommand = ({ isDryRun }) => { `--set web.resources.requests.cpu="${cpu.web}"`, `--set graphql.resources.requests.cpu="${cpu.graphql}"`, `--set sync.resources.requests.cpu="${cpu.sync}"`, - `--set doc.resources.requests.cpu="${cpu.doc}"`, + `--set doc.resources.requests.cpu="${cpu.store}"`, ] : []; diff --git a/blocksuite/affine/blocks/attachment/src/attachment-block.ts b/blocksuite/affine/blocks/attachment/src/attachment-block.ts index 98490d6803..e411cd033b 100644 --- a/blocksuite/affine/blocks/attachment/src/attachment-block.ts +++ b/blocksuite/affine/blocks/attachment/src/attachment-block.ts @@ -42,7 +42,7 @@ import { downloadAttachmentBlob, refreshData } from './utils'; @Peekable({ enableOn: ({ model }: AttachmentBlockComponent) => { - return !model.doc.readonly && model.props.type.endsWith('pdf'); + return !model.store.readonly && model.props.type.endsWith('pdf'); }, }) export class AttachmentBlockComponent extends CaptionedBlockComponent { diff --git a/blocksuite/affine/blocks/attachment/src/components/rename-model.ts b/blocksuite/affine/blocks/attachment/src/components/rename-model.ts index 1a151a3a44..4d69a3dbb4 100644 --- a/blocksuite/affine/blocks/attachment/src/components/rename-model.ts +++ b/blocksuite/affine/blocks/attachment/src/components/rename-model.ts @@ -41,7 +41,7 @@ export const RenameModal = ({ toast(editorHost, 'File name cannot be empty'); return; } - model.doc.updateBlock(model, { + model.store.updateBlock(model, { name: newFileName, }); abort(); diff --git a/blocksuite/affine/blocks/attachment/src/configs/slash-menu.ts b/blocksuite/affine/blocks/attachment/src/configs/slash-menu.ts index 6f6900fd0e..9572e95de0 100644 --- a/blocksuite/affine/blocks/attachment/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/attachment/src/configs/slash-menu.ts @@ -18,7 +18,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = { searchAlias: ['file'], group: '4_Content & Media@3', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:attachment'), + model.store.schema.flavourSchemaMap.has('affine:attachment'), action: ({ std, model }) => { (async () => { const file = await openFileOrFiles(); @@ -41,7 +41,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@4', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:attachment'), + model.store.schema.flavourSchemaMap.has('affine:attachment'), action: ({ std, model }) => { (async () => { const file = await openFileOrFiles(); diff --git a/blocksuite/affine/blocks/attachment/src/embed.ts b/blocksuite/affine/blocks/attachment/src/embed.ts index 80729bec19..6a44d9ee94 100644 --- a/blocksuite/affine/blocks/attachment/src/embed.ts +++ b/blocksuite/affine/blocks/attachment/src/embed.ts @@ -98,7 +98,7 @@ export class AttachmentEmbedService extends Extension { convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) { const config = this.values.find(config => config.check(model, maxFileSize)); if (!config?.action) { - model.doc.updateBlock(model, { embed: true }); + model.store.updateBlock(model, { embed: true }); return; } config.action(model, this.std)?.catch(console.error); @@ -129,7 +129,7 @@ const embedConfig: AttachmentEmbedConfig[] = [ { name: 'image', check: model => - model.doc.schema.flavourSchemaMap.has('affine:image') && + model.store.schema.flavourSchemaMap.has('affine:image') && model.props.type.startsWith('image/'), async action(model, std) { const component = std.view.getBlock(model.id); @@ -189,7 +189,7 @@ const embedConfig: AttachmentEmbedConfig[] = [ * Turn the attachment block into an image block. */ async function turnIntoImageBlock(model: AttachmentBlockModel) { - if (!model.doc.schema.flavourSchemaMap.has('affine:image')) { + if (!model.store.schema.flavourSchemaMap.has('affine:image')) { console.error('The image flavour is not supported!'); return; } diff --git a/blocksuite/affine/blocks/attachment/src/utils.ts b/blocksuite/affine/blocks/attachment/src/utils.ts index 768b480f46..a3a0245590 100644 --- a/blocksuite/affine/blocks/attachment/src/utils.ts +++ b/blocksuite/affine/blocks/attachment/src/utils.ts @@ -27,7 +27,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) { const type = type$.peek(); if (!sourceId) return null; - const doc = model.doc; + const doc = model.store; const blob = await doc.blobSync.get(sourceId); if (!blob) return null; diff --git a/blocksuite/affine/blocks/bookmark/src/configs/slash-menu.ts b/blocksuite/affine/blocks/bookmark/src/configs/slash-menu.ts index cf43bab94e..10ea2860ad 100644 --- a/blocksuite/affine/blocks/bookmark/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/bookmark/src/configs/slash-menu.ts @@ -23,7 +23,7 @@ const bookmarkSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@2', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:bookmark'), + model.store.schema.flavourSchemaMap.has('affine:bookmark'), action: ({ std, model }) => { const { host } = std; const parentModel = host.doc.getParent(model); @@ -45,7 +45,7 @@ const bookmarkSlashMenuConfig: SlashMenuConfig = { ) .then(() => { if (model.text?.length === 0) { - model.doc.deleteBlock(model); + model.store.deleteBlock(model); } }) .catch(console.error); diff --git a/blocksuite/affine/blocks/callout/src/configs/slash-menu.ts b/blocksuite/affine/blocks/callout/src/configs/slash-menu.ts index 095fa5d7e4..9de6047c0e 100644 --- a/blocksuite/affine/blocks/callout/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/callout/src/configs/slash-menu.ts @@ -33,19 +33,24 @@ export const calloutSlashMenuConfig: SlashMenuConfig = { when: ({ std, model }) => { return ( std.get(FeatureFlagService).getFlag('enable_callout') && - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text') + !isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text') ); }, action: ({ model, std }) => { - const { doc } = model; - const parent = doc.getParent(model); + const { store } = model; + const parent = store.getParent(model); if (!parent) return; const index = parent.children.indexOf(model); if (index === -1) return; - const calloutId = doc.addBlock('affine:callout', {}, parent, index + 1); + const calloutId = store.addBlock( + 'affine:callout', + {}, + parent, + index + 1 + ); if (!calloutId) return; - const paragraphId = doc.addBlock('affine:paragraph', {}, calloutId); + const paragraphId = store.addBlock('affine:paragraph', {}, calloutId); if (!paragraphId) return; std.host.updateComplete .then(() => { diff --git a/blocksuite/affine/blocks/code/src/code-block.ts b/blocksuite/affine/blocks/code/src/code-block.ts index 202d075da8..df71b7de1b 100644 --- a/blocksuite/affine/blocks/code/src/code-block.ts +++ b/blocksuite/affine/blocks/code/src/code-block.ts @@ -363,7 +363,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent copyCode() { const model = this.model; - const slice = Slice.fromModels(model.doc, [model]); + const slice = Slice.fromModels(model.store, [model]); this.std.clipboard .copySlice(slice) .then(() => { diff --git a/blocksuite/affine/blocks/code/src/code-toolbar/utils.ts b/blocksuite/affine/blocks/code/src/code-toolbar/utils.ts index e9162af7fd..0909982f15 100644 --- a/blocksuite/affine/blocks/code/src/code-toolbar/utils.ts +++ b/blocksuite/affine/blocks/code/src/code-toolbar/utils.ts @@ -12,5 +12,5 @@ export const duplicateCodeBlock = (model: CodeBlockModel) => { ...duplicateProps, }; - return model.doc.addSiblingBlocks(model, [newProps])[0]; + return model.store.addSiblingBlocks(model, [newProps])[0]; }; diff --git a/blocksuite/affine/blocks/data-view/src/configs/slash-menu.ts b/blocksuite/affine/blocks/data-view/src/configs/slash-menu.ts index 0a9f4e8bfc..06bd36b48d 100644 --- a/blocksuite/affine/blocks/data-view/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/data-view/src/configs/slash-menu.ts @@ -21,7 +21,7 @@ export const dataViewSlashMenuConfig: SlashMenuConfig = { }, group: '7_Database@1', when: ({ model, std }) => - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text') && + !isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text') && !!std.get(FeatureFlagService).getFlag('enable_block_query'), action: ({ model, std }) => { @@ -43,7 +43,7 @@ export const dataViewSlashMenuConfig: SlashMenuConfig = { dataView?.dataSource.viewManager.viewAdd('table'); if (model.text?.length === 0) { - model.doc.deleteBlock(model); + model.store.deleteBlock(model); } }, }, diff --git a/blocksuite/affine/blocks/data-view/src/data-source.ts b/blocksuite/affine/blocks/data-view/src/data-source.ts index 86908306ee..dd87b4137d 100644 --- a/blocksuite/affine/blocks/data-view/src/data-source.ts +++ b/blocksuite/affine/blocks/data-view/src/data-source.ts @@ -169,7 +169,7 @@ export class BlockQueryDataSource extends DataSourceBase { insertToPosition: InsertToPosition, type: string | undefined ): string { - const doc = this.block.doc; + const doc = this.block.store; doc.captureSync(); const column = DatabaseBlockDataSource.propertiesMap.value[ type ?? propertyPresets.multiSelectPropertyConfig.type @@ -292,7 +292,7 @@ export class BlockQueryDataSource extends DataSourceBase { ].config.propertyData.default(), cells: currentCells.map(() => undefined), }; - this.block.doc.captureSync(); + this.block.store.captureSync(); viewColumn.type = toType; viewColumn.data = result.property; currentCells.forEach((value, i) => { diff --git a/blocksuite/affine/blocks/data-view/src/data-view-model.ts b/blocksuite/affine/blocks/data-view/src/data-view-model.ts index e2bf7c69e0..4551fc97d6 100644 --- a/blocksuite/affine/blocks/data-view/src/data-view-model.ts +++ b/blocksuite/affine/blocks/data-view/src/data-view-model.ts @@ -24,21 +24,21 @@ export class DataViewBlockModel extends BlockModel { } applyViewsUpdate() { - this.doc.updateBlock(this, { + this.store.updateBlock(this, { views: this.props.views, }); } deleteView(id: string) { - this.doc.captureSync(); - this.doc.transact(() => { + this.store.captureSync(); + this.store.transact(() => { this.props.views = this.props.views.filter(v => v.id !== id); }); } duplicateView(id: string): string { - const newId = this.doc.workspace.idGenerator(); - this.doc.transact(() => { + const newId = this.store.workspace.idGenerator(); + this.store.transact(() => { const index = this.props.views.findIndex(v => v.id === id); const view = this.props.views[index]; if (view) { @@ -53,7 +53,7 @@ export class DataViewBlockModel extends BlockModel { } moveViewTo(id: string, position: InsertToPosition) { - this.doc.transact(() => { + this.store.transact(() => { this.props.views = arrayMove( this.props.views, v => v.id === id, @@ -67,7 +67,7 @@ export class DataViewBlockModel extends BlockModel { id: string, update: (data: DataViewDataType) => Partial ) { - this.doc.transact(() => { + this.store.transact(() => { this.props.views = this.props.views.map(v => { if (v.id !== id) { return v; diff --git a/blocksuite/affine/blocks/database/src/configs/slash-menu.ts b/blocksuite/affine/blocks/database/src/configs/slash-menu.ts index de2cb375e7..887053a39f 100644 --- a/blocksuite/affine/blocks/database/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/database/src/configs/slash-menu.ts @@ -25,7 +25,7 @@ export const databaseSlashMenuConfig: SlashMenuConfig = { }, group: '7_Database@0', when: ({ model }) => - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'), + !isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'), action: ({ std }) => { std.command .chain() @@ -58,7 +58,7 @@ export const databaseSlashMenuConfig: SlashMenuConfig = { }, group: '7_Database@2', when: ({ model }) => - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'), + !isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'), action: ({ std }) => { std.command .chain() diff --git a/blocksuite/affine/blocks/database/src/data-source.ts b/blocksuite/affine/blocks/database/src/data-source.ts index 66f7d81b33..f5f95bda80 100644 --- a/blocksuite/affine/blocks/database/src/data-source.ts +++ b/blocksuite/affine/blocks/database/src/data-source.ts @@ -99,7 +99,7 @@ export class DatabaseBlockDataSource extends DataSourceBase { readonly$: ReadonlySignal = computed(() => { return ( - this._model.doc.readonly || + this._model.store.readonly || // TODO(@L-Sun): use block level readonly IS_MOBILE ); @@ -120,7 +120,7 @@ export class DatabaseBlockDataSource extends DataSourceBase { viewMetas = databaseBlockViews; get doc() { - return this._model.doc; + return this._model.store; } allPropertyMetas$ = computed[]>(() => { @@ -302,7 +302,7 @@ export class DatabaseBlockDataSource extends DataSourceBase { return; } const { column: prevColumn, index } = result; - this._model.doc.transact(() => { + this._model.store.transact(() => { if (index >= 0) { const result = updater(prevColumn); this._model.props.columns[index] = { ...prevColumn, ...result }; @@ -500,15 +500,15 @@ export class DatabaseBlockDataSource extends DataSourceBase { } viewDataAdd(viewData: DataViewDataType): string { - this._model.doc.captureSync(); - this._model.doc.transact(() => { + this._model.store.captureSync(); + this._model.store.transact(() => { this._model.props.views = [...this._model.props.views, viewData]; }); return viewData.id; } viewDataDelete(viewId: string): void { - this._model.doc.captureSync(); + this._model.store.captureSync(); deleteView(this._model, viewId); } diff --git a/blocksuite/affine/blocks/database/src/database-block.ts b/blocksuite/affine/blocks/database/src/database-block.ts index 4aef0e97f0..84b6989904 100644 --- a/blocksuite/affine/blocks/database/src/database-block.ts +++ b/blocksuite/affine/blocks/database/src/database-block.ts @@ -434,13 +434,13 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent { - return this.databaseBlock.doc.getBlock(this.rowId)?.model?.text; + return this.databaseBlock.store.getBlock(this.rowId)?.model?.text; }); allowCreateDoc$ = computed(() => { diff --git a/blocksuite/affine/blocks/database/src/utils/block-utils.ts b/blocksuite/affine/blocks/database/src/utils/block-utils.ts index 580e6e4d44..587ffb7794 100644 --- a/blocksuite/affine/blocks/database/src/utils/block-utils.ts +++ b/blocksuite/affine/blocks/database/src/utils/block-utils.ts @@ -19,11 +19,11 @@ export function addProperty( id?: string; } ): string { - const id = column.id ?? model.doc.workspace.idGenerator(); + const id = column.id ?? model.store.workspace.idGenerator(); if (model.props.columns.some(v => v.id === id)) { return id; } - model.doc.transact(() => { + model.store.transact(() => { const col: ColumnDataType = { ...column, id, @@ -42,7 +42,7 @@ export function copyCellsByProperty( fromId: ColumnDataType['id'], toId: ColumnDataType['id'] ) { - model.doc.transact(() => { + model.store.transact(() => { Object.keys(model.props.cells).forEach(rowId => { const cell = model.props.cells[rowId]?.[fromId]; if (cell && model.props.cells[rowId]) { @@ -62,13 +62,13 @@ export function deleteColumn( const index = model.props.columns.findIndex(v => v.id === columnId); if (index < 0) return; - model.doc.transact(() => { + model.store.transact(() => { model.props.columns.splice(index, 1); }); } export function deleteRows(model: DatabaseBlockModel, rowIds: string[]) { - model.doc.transact(() => { + model.store.transact(() => { for (const rowId of rowIds) { delete model.props.cells[rowId]; } @@ -76,15 +76,15 @@ export function deleteRows(model: DatabaseBlockModel, rowIds: string[]) { } export function deleteView(model: DatabaseBlockModel, id: string) { - model.doc.captureSync(); - model.doc.transact(() => { + model.store.captureSync(); + model.store.transact(() => { model.props.views = model.props.views.filter(v => v.id !== id); }); } export function duplicateView(model: DatabaseBlockModel, id: string): string { - const newId = model.doc.workspace.idGenerator(); - model.doc.transact(() => { + const newId = model.store.workspace.idGenerator(); + model.store.transact(() => { const index = model.props.views.findIndex(v => v.id === id); const view = model.props.views[index]; if (view) { @@ -131,7 +131,7 @@ export function moveViewTo( id: string, position: InsertToPosition ) { - model.doc.transact(() => { + model.store.transact(() => { model.props.views = arrayMove( model.props.views, v => v.id === id, @@ -145,7 +145,7 @@ export function updateCell( rowId: string, cell: CellDataType ) { - model.doc.transact(() => { + model.store.transact(() => { const columnId = cell.columnId; if ( rowId === '__proto__' || @@ -180,7 +180,7 @@ export function updateCells( columnId: string, cells: Record ) { - model.doc.transact(() => { + model.store.transact(() => { Object.entries(cells).forEach(([rowId, value]) => { if ( rowId === '__proto__' || @@ -212,7 +212,7 @@ export function updateProperty( if (index == null) { return; } - model.doc.transact(() => { + model.store.transact(() => { const column = model.props.columns[index]; if (!column) { return; @@ -228,7 +228,7 @@ export const updateView = ( id: string, update: (data: ViewData) => Partial ) => { - model.doc.transact(() => { + model.store.transact(() => { model.props.views = model.props.views.map(v => { if (v.id !== id) { return v; diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/configs/slash-menu.ts b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/configs/slash-menu.ts index b2428f5326..8bcf3b9700 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/configs/slash-menu.ts @@ -23,7 +23,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = { }, group: '3_Page@0', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'), + model.store.schema.flavourSchemaMap.has('affine:embed-linked-doc'), action: ({ std, model }) => { const newDoc = createDefaultDoc(std.host.doc.workspace); insertContent(std, model, REFERENCE_NODE, { @@ -45,7 +45,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = { searchAlias: ['dual link'], group: '3_Page@1', when: ({ std, model }) => { - const root = model.doc.root; + const root = model.store.root; if (!root) return false; const linkedDocWidget = std.view.getWidget( 'affine-linked-doc-widget', @@ -53,10 +53,12 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = { ); if (!linkedDocWidget) return false; - return model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'); + return model.store.schema.flavourSchemaMap.has( + 'affine:embed-linked-doc' + ); }, action: ({ model, std }) => { - const root = model.doc.root; + const root = model.store.root; if (!root) return; const linkedDocWidget = std.view.getWidget( 'affine-linked-doc-widget', diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-edgeless-linked-doc-block.ts b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-edgeless-linked-doc-block.ts index 8c57896d2c..ca162fd8fe 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-edgeless-linked-doc-block.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-edgeless-linked-doc-block.ts @@ -21,7 +21,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock( ) { override convertToEmbed = () => { const { caption, xywh } = this.model.props; - const { doc, id } = this.model; + const { store, id } = this.model; const style = 'syncedDoc'; const bound = Bound.deserialize(xywh); @@ -50,7 +50,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock( elements: [newId], }); - doc.deleteBlock(this.model); + store.deleteBlock(this.model); }; protected override _handleClick = (evt: MouseEvent): void => { diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-linked-doc-block.ts b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-linked-doc-block.ts index 3105ff4741..678815ec7e 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-linked-doc-block.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-linked-doc-block.ts @@ -137,10 +137,10 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent { - const { doc } = this.model; - const parent = doc.getParent(this.model); + const { store } = this.model; + const parent = store.getParent(this.model); if (!parent) { return; } @@ -175,7 +175,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent { diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-edgeless-synced-doc-block.ts b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-edgeless-synced-doc-block.ts index 30a163d449..06110436ff 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-edgeless-synced-doc-block.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-edgeless-synced-doc-block.ts @@ -145,7 +145,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock( }; override convertToCard = (aliasInfo?: AliasInfo) => { - const { id, doc, xywh } = this.model; + const { id, store, xywh } = this.model; const { caption } = this.model.props; const style = 'vertical'; @@ -176,7 +176,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock( editing: false, elements: [newId], }); - doc.deleteBlock(this.model); + store.deleteBlock(this.model); }; override renderGfxBlock() { diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts index f7e098b9db..7873283dcf 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts @@ -276,10 +276,10 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent { - const { doc } = this.model; + const { store } = this.model; const { caption } = this.model.props; - const parent = doc.getParent(this.model); + const parent = store.getParent(this.model); if (!parent) { console.error( `Trying to convert synced doc to card, but the parent is not found.` @@ -288,14 +288,14 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent { - const { doc } = this.model; - const parent = doc.getParent(this.model); + const { store } = this.model; + const parent = store.getParent(this.model); if (!parent) { console.error( `Trying to convert synced doc to inline, but the parent is not found.` @@ -323,7 +323,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent - model.doc.schema.flavourSchemaMap.has('affine:embed-figma'), + model.store.schema.flavourSchemaMap.has('affine:embed-figma'), action: ({ std, model }) => { (async () => { const { host } = std; diff --git a/blocksuite/affine/blocks/embed/src/embed-github-block/configs/slash-menu.ts b/blocksuite/affine/blocks/embed/src/embed-github-block/configs/slash-menu.ts index 4a553f0e27..dd8f3fe894 100644 --- a/blocksuite/affine/blocks/embed/src/embed-github-block/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/embed/src/embed-github-block/configs/slash-menu.ts @@ -18,7 +18,7 @@ export const embedGithubSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@7', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:embed-github'), + model.store.schema.flavourSchemaMap.has('affine:embed-github'), action: ({ std, model }) => { (async () => { const { host } = std; diff --git a/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-error-card.ts b/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-error-card.ts index 6e797d69fb..c02c889064 100644 --- a/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-error-card.ts +++ b/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-error-card.ts @@ -282,7 +282,7 @@ export class EmbedIframeErrorCard extends WithDisposable(LitElement) { } get readonly() { - return this.model.doc.readonly; + return this.model.store.readonly; } get telemetryService() { diff --git a/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-link-input-base.ts b/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-link-input-base.ts index 4a8efcf89f..570cb39fd4 100644 --- a/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-link-input-base.ts +++ b/blocksuite/affine/blocks/embed/src/embed-iframe-block/components/embed-iframe-link-input-base.ts @@ -133,7 +133,7 @@ export class EmbedIframeLinkInputBase extends WithDisposable(LitElement) { } get store() { - return this.model.doc; + return this.model.store; } get notificationService() { diff --git a/blocksuite/affine/blocks/embed/src/embed-iframe-block/configs/slash-menu/slash-menu.ts b/blocksuite/affine/blocks/embed/src/embed-iframe-block/configs/slash-menu/slash-menu.ts index 431ef910d3..ddf795b562 100644 --- a/blocksuite/affine/blocks/embed/src/embed-iframe-block/configs/slash-menu/slash-menu.ts +++ b/blocksuite/affine/blocks/embed/src/embed-iframe-block/configs/slash-menu/slash-menu.ts @@ -17,7 +17,7 @@ export const embedIframeSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@5', when: ({ model }) => { - return model.doc.schema.flavourSchemaMap.has('affine:embed-iframe'); + return model.store.schema.flavourSchemaMap.has('affine:embed-iframe'); }, action: ({ std }) => { std.command diff --git a/blocksuite/affine/blocks/embed/src/embed-loom-block/configs/slash-menu.ts b/blocksuite/affine/blocks/embed/src/embed-loom-block/configs/slash-menu.ts index 11b0765f7e..b80eaeb4b9 100644 --- a/blocksuite/affine/blocks/embed/src/embed-loom-block/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/embed/src/embed-loom-block/configs/slash-menu.ts @@ -18,7 +18,7 @@ export const embedLoomSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@9', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:embed-loom'), + model.store.schema.flavourSchemaMap.has('affine:embed-loom'), action: ({ std, model }) => { (async () => { const { host } = std; diff --git a/blocksuite/affine/blocks/embed/src/embed-youtube-block/configs/slash-menu.ts b/blocksuite/affine/blocks/embed/src/embed-youtube-block/configs/slash-menu.ts index fa9f9721e6..2f7a54f1a9 100644 --- a/blocksuite/affine/blocks/embed/src/embed-youtube-block/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/embed/src/embed-youtube-block/configs/slash-menu.ts @@ -18,7 +18,7 @@ export const embedYoutubeSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@6', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:embed-youtube'), + model.store.schema.flavourSchemaMap.has('affine:embed-youtube'), action: ({ std, model }) => { (async () => { const { host } = std; diff --git a/blocksuite/affine/blocks/image/src/configs/slash-menu.ts b/blocksuite/affine/blocks/image/src/configs/slash-menu.ts index 6f495d7b39..f4e0f68ffb 100644 --- a/blocksuite/affine/blocks/image/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/image/src/configs/slash-menu.ts @@ -17,7 +17,7 @@ export const imageSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@1', when: ({ model }) => - model.doc.schema.flavourSchemaMap.has('affine:image'), + model.store.schema.flavourSchemaMap.has('affine:image'), action: ({ std }) => { const [success, ctx] = std.command .chain() diff --git a/blocksuite/affine/blocks/image/src/image-resize-manager.ts b/blocksuite/affine/blocks/image/src/image-resize-manager.ts index 5f2c0db8e7..41d3e6fdf9 100644 --- a/blocksuite/affine/blocks/image/src/image-resize-manager.ts +++ b/blocksuite/affine/blocks/image/src/image-resize-manager.ts @@ -23,9 +23,9 @@ export class ImageResizeManager { } const dragModel = getModelByElement(this._activeComponent); - dragModel?.doc.captureSync(); + dragModel?.store.captureSync(); const { width, height } = this._imageContainer.getBoundingClientRect(); - dragModel?.doc.updateBlock(dragModel, { + dragModel?.store.updateBlock(dragModel, { width: width / this._zoom, height: height / this._zoom, }); diff --git a/blocksuite/affine/blocks/image/src/image-spec.ts b/blocksuite/affine/blocks/image/src/image-spec.ts index b71300e32a..069c90bf6b 100644 --- a/blocksuite/affine/blocks/image/src/image-spec.ts +++ b/blocksuite/affine/blocks/image/src/image-spec.ts @@ -13,7 +13,7 @@ const flavour = ImageBlockSchema.model.flavour; export const ImageBlockSpec: ExtensionType[] = [ FlavourExtension(flavour), BlockViewExtension(flavour, model => { - const parent = model.doc.getParent(model.id); + const parent = model.store.getParent(model.id); if (parent?.flavour === 'affine:surface') { return literal`affine-edgeless-image`; diff --git a/blocksuite/affine/blocks/image/src/utils.ts b/blocksuite/affine/blocks/image/src/utils.ts index 8107cdbd71..1a00e3605a 100644 --- a/blocksuite/affine/blocks/image/src/utils.ts +++ b/blocksuite/affine/blocks/image/src/utils.ts @@ -36,7 +36,7 @@ async function getImageBlob(model: ImageBlockModel) { const sourceId = model.props.sourceId$.peek(); if (!sourceId) return null; - const doc = model.doc; + const doc = model.store; let blob = await doc.blobSync.get(sourceId); if (!blob) return null; @@ -419,15 +419,15 @@ export function duplicate(block: ImageBlockComponent) { ...duplicateProps } = blockProps; - const { doc } = model; - const parent = doc.getParent(model); + const { store } = model; + const parent = store.getParent(model); if (!parent) { console.error(`Parent not found for block(${model.flavour}) ${model.id}`); return; } const index = parent?.children.indexOf(model); - const duplicateId = doc.addBlock( + const duplicateId = store.addBlock( model.flavour, duplicateProps, parent, diff --git a/blocksuite/affine/blocks/list/src/utils/get-list-icon.ts b/blocksuite/affine/blocks/list/src/utils/get-list-icon.ts index 7cb6964620..4de1bb39b0 100644 --- a/blocksuite/affine/blocks/list/src/utils/get-list-icon.ts +++ b/blocksuite/affine/blocks/list/src/utils/get-list-icon.ts @@ -15,10 +15,10 @@ import { getNumberPrefix } from './get-number-prefix.js'; const getListDeep = (model: ListBlockModel): number => { let deep = 0; - let parent = model.doc.getParent(model); + let parent = model.store.getParent(model); while (parent?.flavour === model.flavour) { deep++; - parent = model.doc.getParent(parent); + parent = model.store.getParent(parent); } return deep; }; @@ -56,7 +56,7 @@ export function getListIcon( case 'todo': return html`
${model.props.checked diff --git a/blocksuite/affine/blocks/note/src/configs/slash-menu.ts b/blocksuite/affine/blocks/note/src/configs/slash-menu.ts index f78b16a398..3806ea865e 100644 --- a/blocksuite/affine/blocks/note/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/note/src/configs/slash-menu.ts @@ -45,8 +45,12 @@ const noteSlashMenuConfig: SlashMenuConfig = { ({ ...createConversionItem(config, `0_Basic@${basicIndex++}`), when: ({ model }) => - model.doc.schema.flavourSchemaMap.has(config.flavour) && - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'), + model.store.schema.flavourSchemaMap.has(config.flavour) && + !isInsideBlockByFlavour( + model.store, + model, + 'affine:edgeless-text' + ), }) satisfies SlashMenuActionItem ), @@ -75,7 +79,7 @@ function createConversionItem( description, icon, tooltip: tooltips[name], - when: ({ model }) => model.doc.schema.flavourSchemaMap.has(flavour), + when: ({ model }) => model.store.schema.flavourSchemaMap.has(flavour), action: ({ std }) => { std.command.exec(updateBlockType, { flavour, diff --git a/blocksuite/affine/blocks/note/src/note-edgeless-block.ts b/blocksuite/affine/blocks/note/src/note-edgeless-block.ts index f2d7ad4b1e..a52e2192e7 100644 --- a/blocksuite/affine/blocks/note/src/note-edgeless-block.ts +++ b/blocksuite/affine/blocks/note/src/note-edgeless-block.ts @@ -130,14 +130,14 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent( const { collapse, collapsedHeight } = this.model.props.edgeless; if (collapse) { - this.model.doc.updateBlock(this.model, () => { + this.model.store.updateBlock(this.model, () => { this.model.props.edgeless.collapse = false; }); } else if (collapsedHeight) { const { xywh, edgeless } = this.model.props; const bound = Bound.deserialize(xywh); bound.h = collapsedHeight * (edgeless.scale ?? 1); - this.model.doc.updateBlock(this.model, () => { + this.model.store.updateBlock(this.model, () => { this.model.props.edgeless.collapse = true; this.model.props.xywh = bound.serialize(); }); diff --git a/blocksuite/affine/blocks/paragraph/src/utils/merge-with-prev.ts b/blocksuite/affine/blocks/paragraph/src/utils/merge-with-prev.ts index 36920f80b5..e9b4634088 100644 --- a/blocksuite/affine/blocks/paragraph/src/utils/merge-with-prev.ts +++ b/blocksuite/affine/blocks/paragraph/src/utils/merge-with-prev.ts @@ -41,7 +41,7 @@ import type { BlockModel, Text } from '@blocksuite/store'; * - line3 */ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) { - const doc = model.doc; + const doc = model.store; const parent = doc.getParent(model); if (!parent) return false; @@ -118,7 +118,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) { } function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) { - const doc = model.doc; + const doc = model.store; const text = model.text; const parent = doc.getParent(model); if (!parent) return false; @@ -137,7 +137,7 @@ function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) { return false; } - const rootModel = model.doc.root as RootBlockModel; + const rootModel = model.store.root as RootBlockModel; const title = rootModel.props.title; doc.captureSync(); diff --git a/blocksuite/affine/blocks/surface-ref/src/portal/note.ts b/blocksuite/affine/blocks/surface-ref/src/portal/note.ts index aa39f8688d..3c94b13fbe 100644 --- a/blocksuite/affine/blocks/surface-ref/src/portal/note.ts +++ b/blocksuite/affine/blocks/surface-ref/src/portal/note.ts @@ -43,7 +43,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) { let parent: BlockModel | null = this.model; while (parent) { this.ancestors.add(parent.id); - parent = this.model.doc.getParent(parent.id); + parent = this.model.store.getParent(parent.id); } const query: Query = { mode: 'include', @@ -54,7 +54,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) { }; this.query = query; - const doc = this.model.doc; + const doc = this.model.store; this._disposables.add(() => { doc.doc.removeStore({ query, readonly: true }); }); @@ -118,7 +118,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) { console.error('Query is not set before rendering note preview'); return nothing; } - const doc = this.model.doc.doc.getStore({ + const doc = this.model.store.doc.getStore({ query: this.query, readonly: true, }); diff --git a/blocksuite/affine/blocks/surface-ref/src/surface-ref-block.ts b/blocksuite/affine/blocks/surface-ref/src/surface-ref-block.ts index 2bb47b7ac5..6cd2b23750 100644 --- a/blocksuite/affine/blocks/surface-ref/src/surface-ref-block.ts +++ b/blocksuite/affine/blocks/surface-ref/src/surface-ref-block.ts @@ -402,7 +402,7 @@ export class SurfaceRefBlockComponent extends BlockComponent { - const pageId = this.referenceModel?.surface?.doc.id; + const pageId = this.referenceModel?.surface?.store.id; if (!pageId) return; this.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.next({ diff --git a/blocksuite/affine/blocks/surface/src/extensions/export-manager/export-manager.ts b/blocksuite/affine/blocks/surface/src/extensions/export-manager/export-manager.ts index c285e09d07..0cd9f30770 100644 --- a/blocksuite/affine/blocks/surface/src/extensions/export-manager/export-manager.ts +++ b/blocksuite/affine/blocks/surface/src/extensions/export-manager/export-manager.ts @@ -438,7 +438,7 @@ export class ExportManager { if (matchModels(block, [ImageBlockModel])) { if (!block.props.sourceId) return; - const blob = await block.doc.blobSync.get(block.props.sourceId); + const blob = await block.store.blobSync.get(block.props.sourceId); if (!blob) return; const blobToImage = (blob: Blob) => diff --git a/blocksuite/affine/blocks/surface/src/surface-model.ts b/blocksuite/affine/blocks/surface/src/surface-model.ts index a655ed9277..a789debf9a 100644 --- a/blocksuite/affine/blocks/surface/src/surface-model.ts +++ b/blocksuite/affine/blocks/surface/src/surface-model.ts @@ -44,7 +44,7 @@ export class SurfaceBlockModel extends BaseSurfaceModel { override _init() { this._extendElement(elementsCtorMap); super._init(); - this.doc.provider + this.store.provider .getAll(surfaceMiddlewareIdentifier) .forEach(({ middleware }) => { this._disposables.add(middleware(this)); diff --git a/blocksuite/affine/blocks/surface/src/utils/update-xywh.ts b/blocksuite/affine/blocks/surface/src/utils/update-xywh.ts index 33624dbb71..f68acfac36 100644 --- a/blocksuite/affine/blocks/surface/src/utils/update-xywh.ts +++ b/blocksuite/affine/blocks/surface/src/utils/update-xywh.ts @@ -51,7 +51,7 @@ export function updateXYWH( bound.w = clamp(bound.w, NOTE_MIN_WIDTH * scale, Infinity); bound.h = clamp(bound.h, NOTE_MIN_HEIGHT * scale, Infinity); if (bound.h >= NOTE_MIN_HEIGHT * scale) { - updateBlock.call(ele.doc, ele, () => { + updateBlock.call(ele.store, ele, () => { ele.props.edgeless.collapse = true; ele.props.edgeless.collapsedHeight = bound.h / scale; }); diff --git a/blocksuite/affine/blocks/table/src/configs/slash-menu.ts b/blocksuite/affine/blocks/table/src/configs/slash-menu.ts index 07dfea63f2..7b53167714 100644 --- a/blocksuite/affine/blocks/table/src/configs/slash-menu.ts +++ b/blocksuite/affine/blocks/table/src/configs/slash-menu.ts @@ -20,7 +20,7 @@ export const tableSlashMenuConfig: SlashMenuConfig = { }, group: '4_Content & Media@0', when: ({ model }) => - !isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'), + !isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'), action: ({ std }) => { std.command .chain() diff --git a/blocksuite/affine/blocks/table/src/table-data-manager.ts b/blocksuite/affine/blocks/table/src/table-data-manager.ts index 10431325d6..916999d4c5 100644 --- a/blocksuite/affine/blocks/table/src/table-data-manager.ts +++ b/blocksuite/affine/blocks/table/src/table-data-manager.ts @@ -8,7 +8,7 @@ import type { TableAreaSelection } from './selection-schema'; export class TableDataManager { constructor(private readonly model: TableBlockModel) {} readonly readonly$: ReadonlySignal = computed(() => { - return this.model.doc.readonly; + return this.model.store.readonly; }); readonly ui = { columnIndicatorIndex$: signal(), @@ -83,7 +83,7 @@ export class TableDataManager { addRow(after?: number) { const order = this.getOrder(this.rows$.value, after); const rowId = nanoid(); - this.model.doc.transact(() => { + this.model.store.transact(() => { this.model.props.rows[rowId] = { rowId, order, @@ -102,7 +102,7 @@ export class TableDataManager { return; } if (count > 0) { - this.model.doc.transact(() => { + this.model.store.transact(() => { for (let i = 0; i < count; i++) { this.addRow(this.rows$.value.length - 1); } @@ -110,7 +110,7 @@ export class TableDataManager { } else { const rows = this.rows$.value; const rowCount = rows.length; - this.model.doc.transact(() => { + this.model.store.transact(() => { rows.slice(rowCount + count, rowCount).forEach(row => { this.deleteRow(row.rowId); }); @@ -123,7 +123,7 @@ export class TableDataManager { return; } if (count > 0) { - this.model.doc.transact(() => { + this.model.store.transact(() => { for (let i = 0; i < count; i++) { this.addColumn(this.columns$.value.length - 1); } @@ -131,7 +131,7 @@ export class TableDataManager { } else { const columns = this.columns$.value; const columnCount = columns.length; - this.model.doc.transact(() => { + this.model.store.transact(() => { columns.slice(columnCount + count, columnCount).forEach(column => { this.deleteColumn(column.columnId); }); @@ -153,7 +153,7 @@ export class TableDataManager { addColumn(after?: number) { const order = this.getOrder(this.columns$.value, after); const columnId = nanoid(); - this.model.doc.transact(() => { + this.model.store.transact(() => { this.model.props.columns[columnId] = { columnId, order, @@ -168,7 +168,7 @@ export class TableDataManager { } deleteRow(rowId: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { Object.keys(this.model.props.rows).forEach(id => { if (id === rowId) { delete this.model.props.rows[id]; @@ -183,7 +183,7 @@ export class TableDataManager { } deleteColumn(columnId: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { Object.keys(this.model.props.columns).forEach(id => { if (id === columnId) { delete this.model.props.columns[id]; @@ -198,7 +198,7 @@ export class TableDataManager { } updateRowOrder(rowId: string, newOrder: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { if (this.model.props.rows[rowId]) { this.model.props.rows[rowId].order = newOrder; } @@ -206,7 +206,7 @@ export class TableDataManager { } updateColumnOrder(columnId: string, newOrder: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { if (this.model.props.columns[columnId]) { this.model.props.columns[columnId].order = newOrder; } @@ -214,7 +214,7 @@ export class TableDataManager { } setRowBackgroundColor(rowId: string, color?: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { if (this.model.props.rows[rowId]) { this.model.props.rows[rowId].backgroundColor = color; } @@ -222,7 +222,7 @@ export class TableDataManager { } setColumnBackgroundColor(columnId: string, color?: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { if (this.model.props.columns[columnId]) { this.model.props.columns[columnId].backgroundColor = color; } @@ -230,7 +230,7 @@ export class TableDataManager { } setColumnWidth(columnId: string, width: number) { - this.model.doc.transact(() => { + this.model.store.transact(() => { if (this.model.props.columns[columnId]) { this.model.props.columns[columnId].width = width; } @@ -238,7 +238,7 @@ export class TableDataManager { } clearRow(rowId: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { Object.keys(this.model.props.cells).forEach(id => { if (id.startsWith(rowId)) { this.model.props.cells[id]?.text.replace( @@ -252,7 +252,7 @@ export class TableDataManager { } clearColumn(columnId: string) { - this.model.doc.transact(() => { + this.model.store.transact(() => { Object.keys(this.model.props.cells).forEach(id => { if (id.endsWith(`:${columnId}`)) { this.model.props.cells[id]?.text.replace( @@ -290,7 +290,7 @@ export class TableDataManager { } clearCells(cells: { rowId: string; columnId: string }[]) { - this.model.doc.transact(() => { + this.model.store.transact(() => { cells.forEach(({ rowId, columnId }) => { const text = this.model.props.cells[`${rowId}:${columnId}`]?.text; if (text) { @@ -313,7 +313,7 @@ export class TableDataManager { const column = columns[from]; if (!column) return; const order = this.getOrder(columns, after); - this.model.doc.transact(() => { + this.model.store.transact(() => { const realColumn = this.model.props.columns[column.columnId]; if (realColumn) { realColumn.order = order; @@ -326,7 +326,7 @@ export class TableDataManager { const row = rows[from]; if (!row) return; const order = this.getOrder(rows, after); - this.model.doc.transact(() => { + this.model.store.transact(() => { const realRow = this.model.props.rows[row.rowId]; if (realRow) { realRow.order = order; @@ -339,7 +339,7 @@ export class TableDataManager { if (!oldColumn) return; const order = this.getOrder(this.columns$.value, index); const newColumnId = nanoid(); - this.model.doc.transact(() => { + this.model.store.transact(() => { this.model.props.columns[newColumnId] = { ...oldColumn, columnId: newColumnId, @@ -362,7 +362,7 @@ export class TableDataManager { if (!oldRow) return; const order = this.getOrder(this.rows$.value, index); const newRowId = nanoid(); - this.model.doc.transact(() => { + this.model.store.transact(() => { this.model.props.rows[newRowId] = { ...oldRow, rowId: newRowId, diff --git a/blocksuite/affine/components/src/embed-card-modal/embed-card-edit-modal.ts b/blocksuite/affine/components/src/embed-card-modal/embed-card-edit-modal.ts index d2592e0375..cfaadaa97a 100644 --- a/blocksuite/affine/components/src/embed-card-modal/embed-card-edit-modal.ts +++ b/blocksuite/affine/components/src/embed-card-modal/embed-card-edit-modal.ts @@ -163,7 +163,10 @@ export class EmbedCardEditModal extends SignalWatcher( const std = blockComponent.std; - this.model.doc.updateBlock(this.model, { title: null, description: null }); + this.model.store.updateBlock(this.model, { + title: null, + description: null, + }); this.onReset?.(std, blockComponent); diff --git a/blocksuite/affine/fragments/frame-panel/src/body/frame-panel-body.ts b/blocksuite/affine/fragments/frame-panel/src/body/frame-panel-body.ts index d9d07033e4..c1acba8738 100644 --- a/blocksuite/affine/fragments/frame-panel/src/body/frame-panel-body.ts +++ b/blocksuite/affine/fragments/frame-panel/src/body/frame-panel-body.ts @@ -312,7 +312,7 @@ export class FramePanelBody extends SignalWatcher( const after = frames[insertIndex]?.props.presentationIndex || null; selectedFrames.forEach(frame => { const newIndex = generateKeyBetweenV2(before, after); - frame.doc.updateBlock(frame, { + frame.store.updateBlock(frame, { presentationIndex: newIndex, }); before = newIndex; diff --git a/blocksuite/affine/fragments/frame-panel/src/card/frame-preview.ts b/blocksuite/affine/fragments/frame-panel/src/card/frame-preview.ts index db05b6516a..53f0cd0f4b 100644 --- a/blocksuite/affine/fragments/frame-panel/src/card/frame-preview.ts +++ b/blocksuite/affine/fragments/frame-panel/src/card/frame-preview.ts @@ -112,7 +112,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) { }; get _originalDoc() { - return this.frame.doc; + return this.frame.store; } private _initPreviewDoc() { diff --git a/blocksuite/affine/fragments/outline/src/card/outline-preview.ts b/blocksuite/affine/fragments/outline/src/card/outline-preview.ts index 51ba71e810..511c1ca0ef 100644 --- a/blocksuite/affine/fragments/outline/src/card/outline-preview.ts +++ b/blocksuite/affine/fragments/outline/src/card/outline-preview.ts @@ -52,7 +52,7 @@ export class OutlineBlockPreview extends SignalWatcher( if (delta.attributes?.reference) { // If linked doc, render linked doc icon and the doc title. const refAttribute = delta.attributes.reference; - const refMeta = block.doc.workspace.meta.docMetas.find( + const refMeta = block.store.workspace.meta.docMetas.find( doc => doc.id === refAttribute.pageId ); const unavailable = !refMeta; diff --git a/blocksuite/affine/gfx/connector/src/connector-watcher.ts b/blocksuite/affine/gfx/connector/src/connector-watcher.ts index b9bf9efb83..776ca9ad82 100644 --- a/blocksuite/affine/gfx/connector/src/connector-watcher.ts +++ b/blocksuite/affine/gfx/connector/src/connector-watcher.ts @@ -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') diff --git a/blocksuite/affine/gfx/mindmap/src/element-renderer.ts b/blocksuite/affine/gfx/mindmap/src/element-renderer.ts index 5a166a0df4..dda6019d2c 100644 --- a/blocksuite/affine/gfx/mindmap/src/element-renderer.ts +++ b/blocksuite/affine/gfx/mindmap/src/element-renderer.ts @@ -34,7 +34,7 @@ export const mindmap: ElementRenderer = ( 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); diff --git a/blocksuite/affine/gfx/mindmap/src/view/utils.ts b/blocksuite/affine/gfx/mindmap/src/view/utils.ts index c56fea3681..15bdb84349 100644 --- a/blocksuite/affine/gfx/mindmap/src/view/utils.ts +++ b/blocksuite/affine/gfx/mindmap/src/view/utils.ts @@ -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); }); diff --git a/blocksuite/affine/gfx/shape/src/element-renderer/shape/utils.ts b/blocksuite/affine/gfx/shape/src/element-renderer/shape/utils.ts index 52fbfd4372..77991c0200 100644 --- a/blocksuite/affine/gfx/shape/src/element-renderer/shape/utils.ts +++ b/blocksuite/affine/gfx/shape/src/element-renderer/shape/utils.ts @@ -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'); diff --git a/blocksuite/affine/gfx/template/src/services/template-middlewares.ts b/blocksuite/affine/gfx/template/src/services/template-middlewares.ts index f065bbd0a0..c0abaf70c7 100644 --- a/blocksuite/affine/gfx/template/src/services/template-middlewares.ts +++ b/blocksuite/affine/gfx/template/src/services/template-middlewares.ts @@ -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 => { diff --git a/blocksuite/affine/gfx/template/src/services/template.ts b/blocksuite/affine/gfx/template/src/services/template.ts index 6332895e5e..0064551474 100644 --- a/blocksuite/affine/gfx/template/src/services/template.ts +++ b/blocksuite/affine/gfx/template/src/services/template.ts @@ -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(); 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>, to: Y.Map> ) { - 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][] = []; Object.entries(from).forEach(([id, val]) => { diff --git a/blocksuite/affine/model/src/blocks/frame/frame-model.ts b/blocksuite/affine/model/src/blocks/frame/frame-model.ts index fe09ed49f1..8683c580e2 100644 --- a/blocksuite/affine/model/src/blocks/frame/frame-model.ts +++ b/blocksuite/affine/model/src/blocks/frame/frame-model.ts @@ -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]; }); diff --git a/blocksuite/affine/model/src/blocks/root/root-block-model.ts b/blocksuite/affine/model/src/blocks/root/root-block-model.ts index 3a0c6f8e5c..c71a2dee4f 100644 --- a/blocksuite/affine/model/src/blocks/root/root-block-model.ts +++ b/blocksuite/affine/model/src/blocks/root/root-block-model.ts @@ -14,15 +14,17 @@ export class RootBlockModel extends BlockModel { 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(), }); } diff --git a/blocksuite/affine/model/src/elements/group/group.ts b/blocksuite/affine/model/src/elements/group/group.ts index cca324fe15..bb1fba3621 100644 --- a/blocksuite/affine/model/src/elements/group/group.ts +++ b/blocksuite/affine/model/src/elements/group/group.ts @@ -58,7 +58,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel { + this.surface.store.transact(() => { this.children.set(element.id, true); }); } @@ -79,7 +79,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel { + this.surface.store.transact(() => { this.children.delete(element.id); }); } diff --git a/blocksuite/affine/model/src/elements/mindmap/mindmap.ts b/blocksuite/affine/model/src/elements/mindmap/mindmap.ts index a8c9f3b736..4fdfe36e7c 100644 --- a/blocksuite/affine/model/src/elements/mindmap/mindmap.ts +++ b/blocksuite/affine/model/src/elements/mindmap/mindmap.ts @@ -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 { + this.surface.store.transact(() => { const parentNode = parent ? this._nodeMap.get(parent)! : null; if (parentNode) { @@ -433,7 +433,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { + this.surface.store.withoutTransact(() => { loops.forEach(loop => { if (loop.detached) { loop.chain.forEach(node => { @@ -745,7 +745,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { + this.surface.store.transact(() => { this.childElements.forEach(el => { const deserializedXYWH = deserializeXYWH(el.xywh); @@ -775,7 +775,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { + surface.store.transact(() => { remove(this._nodeMap.get(element.id)!); }); @@ -877,7 +877,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel { + this.surface.store.transact(() => { this.children.set(node.id, { ...node.detail, collapsed, @@ -921,7 +921,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel = new Y.Map(); const surface = instance.surface; - const doc = surface.doc; + const doc = surface.store; const recursive = ( node: NodeType, parent: string | null = null, diff --git a/blocksuite/affine/rich-text/src/markdown/to-code.ts b/blocksuite/affine/rich-text/src/markdown/to-code.ts index a0aeca30e7..cff7248428 100644 --- a/blocksuite/affine/rich-text/src/markdown/to-code.ts +++ b/blocksuite/affine/rich-text/src/markdown/to-code.ts @@ -18,7 +18,7 @@ export function toCode( return; } - const doc = model.doc; + const doc = model.store; const parent = doc.getParent(model); if (!parent) { return; diff --git a/blocksuite/affine/shared/src/adapters/middlewares/replace-id.ts b/blocksuite/affine/shared/src/adapters/middlewares/replace-id.ts index d1cb573eaa..849528d55c 100644 --- a/blocksuite/affine/shared/src/adapters/middlewares/replace-id.ts +++ b/blocksuite/affine/shared/src/adapters/middlewares/replace-id.ts @@ -80,7 +80,7 @@ export const replaceIdMiddleware = model.props.reference = idMap.get(original)!; } else if ( model.props.refFlavour === 'affine:frame' && - !model.doc.hasBlock(original) + !model.store.hasBlock(original) ) { const newId = idGenerator(); idMap.set(original, newId); diff --git a/blocksuite/affine/shared/src/utils/dnd/calc-drop-target.ts b/blocksuite/affine/shared/src/utils/dnd/calc-drop-target.ts index 8e3995fd8d..3a3f20abf0 100644 --- a/blocksuite/affine/shared/src/utils/dnd/calc-drop-target.ts +++ b/blocksuite/affine/shared/src/utils/dnd/calc-drop-target.ts @@ -45,7 +45,7 @@ export function calcDropTarget( */ allowSublist: boolean = true ): DropTarget | null { - const schema = model.doc.schema.get('affine:database'); + const schema = model.store.schema.get('affine:database'); const children = schema?.model.children ?? []; let shouldAppendToDatabase = true; diff --git a/blocksuite/affine/shared/src/utils/model/get-content-block.ts b/blocksuite/affine/shared/src/utils/model/get-content-block.ts index d7251fdb66..ad4c52c66a 100644 --- a/blocksuite/affine/shared/src/utils/model/get-content-block.ts +++ b/blocksuite/affine/shared/src/utils/model/get-content-block.ts @@ -26,7 +26,7 @@ export function getPrevContentBlock( model: BlockModel ): BlockModel | null { const getPrev = (model: BlockModel) => { - const parent = model.doc.getParent(model); + const parent = model.store.getParent(model); if (!parent) return null; const index = parent.children.indexOf(model); @@ -113,7 +113,7 @@ export function getNextContentBlock( } map[model.id] = true; - const doc = model.doc; + const doc = model.store; if (model.children.length) { return model.children[0]; } diff --git a/blocksuite/affine/shared/src/utils/model/merge-to-code-model.ts b/blocksuite/affine/shared/src/utils/model/merge-to-code-model.ts index 12849c2f57..3fd4d41b55 100644 --- a/blocksuite/affine/shared/src/utils/model/merge-to-code-model.ts +++ b/blocksuite/affine/shared/src/utils/model/merge-to-code-model.ts @@ -5,7 +5,7 @@ export function mergeToCodeModel(models: BlockModel[]) { if (models.length === 0) { return null; } - const doc = models[0].doc; + const doc = models[0].store; const parent = doc.getParent(models[0]); if (!parent) { diff --git a/blocksuite/affine/shared/src/utils/model/transform-model.ts b/blocksuite/affine/shared/src/utils/model/transform-model.ts index 54aebb525b..c8b227b4d8 100644 --- a/blocksuite/affine/shared/src/utils/model/transform-model.ts +++ b/blocksuite/affine/shared/src/utils/model/transform-model.ts @@ -5,7 +5,7 @@ export function transformModel( flavour: string, props?: Parameters[1] ) { - const doc = model.doc; + const doc = model.store; const parent = doc.getParent(model); if (!parent) { return null; diff --git a/blocksuite/affine/widgets/drag-handle/src/helpers/preview-helper.ts b/blocksuite/affine/widgets/drag-handle/src/helpers/preview-helper.ts index 39fafe5553..dc94cb4e37 100644 --- a/blocksuite/affine/widgets/drag-handle/src/helpers/preview-helper.ts +++ b/blocksuite/affine/widgets/drag-handle/src/helpers/preview-helper.ts @@ -88,7 +88,7 @@ export class PreviewHelper { setup(di) { di.override(BlockViewIdentifier('affine:image'), () => { return (model: BlockModel) => { - const parent = model.doc.getParent(model.id); + const parent = model.store.getParent(model.id); if (parent?.flavour === 'affine:surface') { return literal`affine-edgeless-placeholder-preview-image`; diff --git a/blocksuite/affine/widgets/frame-title/src/frame-title.ts b/blocksuite/affine/widgets/frame-title/src/frame-title.ts index dde14611d5..ab63b6e38f 100644 --- a/blocksuite/affine/widgets/frame-title/src/frame-title.ts +++ b/blocksuite/affine/widgets/frame-title/src/frame-title.ts @@ -75,7 +75,7 @@ export class AffineFrameTitle extends SignalWatcher( } get doc() { - return this.model.doc; + return this.model.store; } get gfx() { diff --git a/blocksuite/framework/std/src/gfx/model/gfx-block-model.ts b/blocksuite/framework/std/src/gfx/model/gfx-block-model.ts index e75984a117..d60640db05 100644 --- a/blocksuite/framework/std/src/gfx/model/gfx-block-model.ts +++ b/blocksuite/framework/std/src/gfx/model/gfx-block-model.ts @@ -164,7 +164,7 @@ export class GfxBlockElementModel< } get surface(): SurfaceBlockModel | null { - const result = this.doc.getBlocksByFlavour('affine:surface'); + const result = this.store.getBlocksByFlavour('affine:surface'); if (result.length === 0) return null; return result[0].model as SurfaceBlockModel; } @@ -257,11 +257,11 @@ export class GfxBlockElementModel< } lock() { - lockElementImpl(this.doc, this); + lockElementImpl(this.store, this); } unlock() { - unlockElementImpl(this.doc, this); + unlockElementImpl(this.store, this); } } diff --git a/blocksuite/framework/std/src/gfx/model/surface/decorators/field.ts b/blocksuite/framework/std/src/gfx/model/surface/decorators/field.ts index 2d0c829f68..c4694de9c4 100644 --- a/blocksuite/framework/std/src/gfx/model/surface/decorators/field.ts +++ b/blocksuite/framework/std/src/gfx/model/surface/decorators/field.ts @@ -38,7 +38,7 @@ export function field(fallback?: V) { if (this.yMap) { if (this.yMap.doc) { - this.surface.doc.transact(() => { + this.surface.store.transact(() => { this.yMap.set(prop as string, v); }); } else { @@ -69,7 +69,7 @@ export function field(fallback?: V) { : convertProps(prop, originalVal, this); if (this.yMap.doc) { - this.surface.doc.transact(() => { + this.surface.store.transact(() => { this.yMap.set(prop as string, val); }); } else { diff --git a/blocksuite/framework/std/src/gfx/model/surface/element-model.ts b/blocksuite/framework/std/src/gfx/model/surface/element-model.ts index 29498d888e..22fbfb8e11 100644 --- a/blocksuite/framework/std/src/gfx/model/surface/element-model.ts +++ b/blocksuite/framework/std/src/gfx/model/surface/element-model.ts @@ -256,7 +256,7 @@ export abstract class GfxPrimitiveElementModel< } lock() { - lockElementImpl(this.surface.doc, this); + lockElementImpl(this.surface.store, this); } onCreated() {} @@ -278,7 +278,7 @@ export abstract class GfxPrimitiveElementModel< if (getFieldPropsSet(this).has(prop as string)) { if (!isEqual(value, this.yMap.get(prop as string))) { - this.surface.doc.transact(() => { + this.surface.store.transact(() => { this.yMap.set(prop as string, value); }); } @@ -339,7 +339,7 @@ export abstract class GfxPrimitiveElementModel< } unlock() { - unlockElementImpl(this.surface.doc, this); + unlockElementImpl(this.surface.store, this); } @local() @@ -396,7 +396,7 @@ export abstract class GfxGroupLikeElementModel< 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); } diff --git a/blocksuite/framework/std/src/gfx/model/surface/surface-model.ts b/blocksuite/framework/std/src/gfx/model/surface/surface-model.ts index d46ffc8118..35f1153bbc 100644 --- a/blocksuite/framework/std/src/gfx/model/surface/surface-model.ts +++ b/blocksuite/framework/std/src/gfx/model/surface/surface-model.ts @@ -368,7 +368,7 @@ export class SurfaceBlockModel extends BlockModel { mount(); }); - Object.values(this.doc.blocks.peek()).forEach(block => { + Object.values(this.store.blocks.peek()).forEach(block => { if (isGfxGroupCompatibleModel(block.model)) { this._groupLikeModels.set(block.id, block.model); } @@ -376,7 +376,7 @@ export class SurfaceBlockModel extends BlockModel { elementsYMap.observe(onElementsMapChange); - const subscription = this.doc.slots.blockUpdated.subscribe(payload => { + const subscription = this.store.slots.blockUpdated.subscribe(payload => { switch (payload.type) { case 'add': if (isGfxGroupCompatibleModel(payload.model)) { @@ -468,7 +468,7 @@ export class SurfaceBlockModel extends BlockModel { const disposables = new DisposableGroup(); disposables.add(this.elementAdded.subscribe(updateIsEmpty)); disposables.add(this.elementRemoved.subscribe(updateIsEmpty)); - this.doc.slots.blockUpdated.subscribe(payload => { + this.store.slots.blockUpdated.subscribe(payload => { if (['add', 'delete'].includes(payload.type)) { updateIsEmpty(); } @@ -503,7 +503,7 @@ export class SurfaceBlockModel extends BlockModel { addElement>( props: Partial & { type: string } ) { - if (this.doc.readonly) { + if (this.store.readonly) { throw new Error('Cannot add element in readonly mode'); } @@ -535,7 +535,7 @@ export class SurfaceBlockModel extends BlockModel { this._elementModels.set(id, elementModel); - this.doc.transact(() => { + this.store.transact(() => { this.elements.getValue()!.set(id, elementModel.model.yMap); }); @@ -552,7 +552,7 @@ export class SurfaceBlockModel extends BlockModel { } deleteElement(id: string) { - if (this.doc.readonly) { + if (this.store.readonly) { throw new Error('Cannot remove element in readonly mode'); } @@ -560,7 +560,7 @@ export class SurfaceBlockModel extends BlockModel { return; } - this.doc.transact(() => { + this.store.transact(() => { const element = this.getElementById(id)!; const group = this.getGroup(id); @@ -568,8 +568,8 @@ export class SurfaceBlockModel extends BlockModel { element.childIds.forEach(childId => { if (this.hasElementById(childId)) { this.deleteElement(childId); - } else if (this.doc.hasBlock(childId)) { - this.doc.deleteBlock(this.doc.getBlock(childId)!.model); + } else if (this.store.hasBlock(childId)) { + this.store.deleteBlock(this.store.getBlock(childId)!.model); } }); } @@ -610,7 +610,7 @@ export class SurfaceBlockModel extends BlockModel { elem = typeof elem === 'string' ? ((this.getElementById(elem) ?? - this.doc.getBlock(elem)?.model) as GfxModel) + this.store.getBlock(elem)?.model) as GfxModel) : elem; if (!elem) return null; @@ -655,7 +655,7 @@ export class SurfaceBlockModel extends BlockModel { const el = this.getElementById(element); if (el) return isGfxGroupCompatibleModel(el); - const blockModel = this.doc.getBlock(element)?.model; + const blockModel = this.store.getBlock(element)?.model; if (blockModel) return isGfxGroupCompatibleModel(blockModel); return false; @@ -668,7 +668,7 @@ export class SurfaceBlockModel extends BlockModel { id: string, props: Partial ) { - if (this.doc.readonly) { + if (this.store.readonly) { throw new Error('Cannot update element in readonly mode'); } @@ -678,7 +678,7 @@ export class SurfaceBlockModel extends BlockModel { throw new Error(`Element ${id} is not found`); } - this.doc.transact(() => { + this.store.transact(() => { props = this._propsToY( elementModel.type, props as Record diff --git a/blocksuite/framework/store/src/model/block/block-model.ts b/blocksuite/framework/store/src/model/block/block-model.ts index 438cbc8d34..16062ee293 100644 --- a/blocksuite/framework/store/src/model/block/block-model.ts +++ b/blocksuite/framework/store/src/model/block/block-model.ts @@ -97,16 +97,16 @@ export class BlockModel { return this._childModels.value; } - get doc() { + get store() { return this._store; } - set doc(doc: Store) { + set store(doc: Store) { this._store = doc; } get parent() { - return this.doc.getParent(this); + return this.store.getParent(this); } get role() { diff --git a/blocksuite/framework/store/src/model/block/flat-sync-controller.ts b/blocksuite/framework/store/src/model/block/flat-sync-controller.ts index 97ad52efdf..293410b051 100644 --- a/blocksuite/framework/store/src/model/block/flat-sync-controller.ts +++ b/blocksuite/framework/store/src/model/block/flat-sync-controller.ts @@ -63,7 +63,7 @@ export class FlatSyncController { model.stash = this.stash; model.pop = this.pop; if (this.doc) { - model.doc = this.doc; + model.store = this.doc; } const defaultProps = schema.model.props?.(internalPrimitives); diff --git a/blocksuite/framework/store/src/model/block/sync-controller.ts b/blocksuite/framework/store/src/model/block/sync-controller.ts index 3986d769e7..d9ae13b3a6 100644 --- a/blocksuite/framework/store/src/model/block/sync-controller.ts +++ b/blocksuite/framework/store/src/model/block/sync-controller.ts @@ -168,7 +168,7 @@ export class SyncController { model.stash = this.stash; model.pop = this.pop; if (this.doc) { - model.doc = this.doc; + model.store = this.doc; } const proxy = new Proxy(signalWithProps, { diff --git a/blocksuite/framework/store/src/model/store/query.ts b/blocksuite/framework/store/src/model/store/query.ts index e06c359233..0d146526f6 100644 --- a/blocksuite/framework/store/src/model/store/query.ts +++ b/blocksuite/framework/store/src/model/store/query.ts @@ -70,7 +70,7 @@ function getBlockViewType(query: Query, block: Block): BlockViewType { } function setAncestorsToDisplayIfHidden(mode: QueryMode, block: Block) { - const doc = block.model.doc; + const doc = block.model.store; let parent = doc.getParent(block.model); while (parent) { const parentBlock = doc.getBlock(parent.id); diff --git a/blocksuite/integration-test/src/__tests__/edgeless/surface-model.spec.ts b/blocksuite/integration-test/src/__tests__/edgeless/surface-model.spec.ts index 011426b1b9..0652c107be 100644 --- a/blocksuite/integration-test/src/__tests__/edgeless/surface-model.spec.ts +++ b/blocksuite/integration-test/src/__tests__/edgeless/surface-model.spec.ts @@ -82,7 +82,7 @@ describe('group', () => { }); const group = model.getElementById(groupId) as GroupElementModel; - model.doc.transact(() => { + model.store.transact(() => { group.children.delete(id); group.children.delete(id2); }); diff --git a/blocksuite/integration-test/src/__tests__/utils/setup.ts b/blocksuite/integration-test/src/__tests__/utils/setup.ts index c62d1c0796..75d648460a 100644 --- a/blocksuite/integration-test/src/__tests__/utils/setup.ts +++ b/blocksuite/integration-test/src/__tests__/utils/setup.ts @@ -141,7 +141,7 @@ export function cleanup() { delete (window as any).editor; - delete (window as any).doc; + delete (window as any).store; } declare global { diff --git a/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts b/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts index 05ddc555ae..32153db93c 100644 --- a/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts +++ b/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts @@ -182,7 +182,7 @@ export class AttachmentViewerPanel extends SignalWatcher( console.debug('connected'); this.#state.value = State.Connected; - const blob = await model.doc.blobSync.get(model.props.sourceId!); + const blob = await model.store.blobSync.get(model.props.sourceId!); if (!blob) return; const buffer = await blob.arrayBuffer(); diff --git a/packages/frontend/core/src/blocksuite/ai/actions/edgeless-response.ts b/packages/frontend/core/src/blocksuite/ai/actions/edgeless-response.ts index 65d8ca26e7..48937c0e7e 100644 --- a/packages/frontend/core/src/blocksuite/ai/actions/edgeless-response.ts +++ b/packages/frontend/core/src/blocksuite/ai/actions/edgeless-response.ts @@ -387,7 +387,7 @@ export function responseToExpandMindmap(host: EditorHost, ctx: AIContext) { if (!subtree) return; - surface.doc.transact(() => { + surface.store.transact(() => { const updateNodeSize = (node: typeof subtree) => { fitContent(node.element as ShapeElementModel); diff --git a/packages/frontend/core/src/blocksuite/ai/blocks/ai-chat-block/ai-chat-spec.ts b/packages/frontend/core/src/blocksuite/ai/blocks/ai-chat-block/ai-chat-spec.ts index f72e61f3a3..a779c299ec 100644 --- a/packages/frontend/core/src/blocksuite/ai/blocks/ai-chat-block/ai-chat-spec.ts +++ b/packages/frontend/core/src/blocksuite/ai/blocks/ai-chat-block/ai-chat-spec.ts @@ -4,7 +4,7 @@ import { literal } from 'lit/static-html.js'; export const AIChatBlockSpec: ExtensionType[] = [ BlockViewExtension('affine:embed-ai-chat', model => { - const parent = model.doc.getParent(model.id); + const parent = model.store.getParent(model.id); if (parent?.flavour === 'affine:surface') { return literal`affine-edgeless-ai-chat`; diff --git a/packages/frontend/core/src/blocksuite/ai/mini-mindmap/surface-block.ts b/packages/frontend/core/src/blocksuite/ai/mini-mindmap/surface-block.ts index 4864cc7b4e..30ee7bb752 100644 --- a/packages/frontend/core/src/blocksuite/ai/mini-mindmap/surface-block.ts +++ b/packages/frontend/core/src/blocksuite/ai/mini-mindmap/surface-block.ts @@ -42,7 +42,7 @@ export class MindmapSurfaceBlock extends BlockComponent { } private _adjustNodeWidth() { - this.model.doc.transact(() => { + this.model.store.transact(() => { this.model.elementModels.forEach(element => { if (element.type === 'shape') { fitContent(element as ShapeElementModel); diff --git a/packages/frontend/core/src/blocksuite/attachment-viewer/pdf/pdf-viewer-embedded.tsx b/packages/frontend/core/src/blocksuite/attachment-viewer/pdf/pdf-viewer-embedded.tsx index 957cee8598..1f4cee8dfa 100644 --- a/packages/frontend/core/src/blocksuite/attachment-viewer/pdf/pdf-viewer-embedded.tsx +++ b/packages/frontend/core/src/blocksuite/attachment-viewer/pdf/pdf-viewer-embedded.tsx @@ -74,7 +74,7 @@ export function PDFViewerEmbedded({ model }: AttachmentViewerProps) { const canvasRef = useRef(null); const peek = useCallback(() => { - const target = model.doc.getBlock(model.id); + const target = model.store.getBlock(model.id); if (!target) return; peekView.open({ element: target }).catch(console.error); }, [peekView, model]); diff --git a/packages/frontend/core/src/blocksuite/attachment-viewer/utils.ts b/packages/frontend/core/src/blocksuite/attachment-viewer/utils.ts index 3bb54c4164..79f31dd11f 100644 --- a/packages/frontend/core/src/blocksuite/attachment-viewer/utils.ts +++ b/packages/frontend/core/src/blocksuite/attachment-viewer/utils.ts @@ -10,7 +10,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) { return null; } - const doc = model.doc; + const doc = model.store; let blob = await doc.blobSync.get(sourceId); if (blob) { diff --git a/packages/frontend/core/src/blocksuite/extensions/attachment-embed-view.tsx b/packages/frontend/core/src/blocksuite/extensions/attachment-embed-view.tsx index 37d8a11747..ed375c8388 100644 --- a/packages/frontend/core/src/blocksuite/extensions/attachment-embed-view.tsx +++ b/packages/frontend/core/src/blocksuite/extensions/attachment-embed-view.tsx @@ -16,7 +16,7 @@ export function patchForPDFEmbedView(reactToLit: ReactToLit): ExtensionType { const bound = Bound.deserialize(model.props.xywh); bound.w = 537 + 24 + 2; bound.h = 759 + 46 + 24 + 2; - model.doc.updateBlock(model, { + model.store.updateBlock(model, { embed: true, style: 'pdf', xywh: bound.serialize(), diff --git a/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-embed-synced-doc-header.tsx b/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-embed-synced-doc-header.tsx index f34d32ada1..3af1dd358a 100644 --- a/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-embed-synced-doc-header.tsx +++ b/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-embed-synced-doc-header.tsx @@ -54,7 +54,7 @@ const ToggleButton = ({ model }: { model: EmbedSyncedDocModel }) => { }, [model.props.preFoldHeight$, model.xywh$]); const toggle = useCallback(() => { - model.doc.captureSync(); + model.store.captureSync(); batch(() => { const { x, y, w, h } = model.elementBound; diff --git a/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-note-header.tsx b/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-note-header.tsx index 08867ab122..1ac900e788 100644 --- a/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-note-header.tsx +++ b/packages/frontend/core/src/blocksuite/extensions/edgeless-block-header/edgeless-note-header.tsx @@ -55,7 +55,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => { const dispose = selection.slots.updated.subscribe(() => { if (selection.has(note.id) && selection.editing) { - note.doc.transact(() => { + note.store.transact(() => { note.props.edgeless.collapse = false; }); } @@ -68,7 +68,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => { track.edgeless.pageBlock.headerToolbar.toggle({ type: collapsed ? 'expand' : 'collapse', }); - note.doc.transact(() => { + note.store.transact(() => { if (collapsed) { note.props.edgeless.collapse = false; } else { @@ -134,7 +134,7 @@ const PageBlockInfoButton = ({ note }: { note: NoteBlockModel }) => { return ( @@ -148,7 +148,7 @@ const NoteCopyLinkButton = ({ note }: { note: NoteBlockModel }) => { return ( ), pageBlockTitle: ({ note }) => { const journalService = framework.get(JournalService); - const isJournal = !!journalService.journalDate$(note.doc.id).value; + const isJournal = !!journalService.journalDate$(note.store.id).value; if (isJournal) { - return reactToLit(); + return reactToLit( + + ); } else { - return html``; + return html``; } }, pageBlockViewportFitAnimation: insidePeekView diff --git a/packages/frontend/core/src/blocksuite/extensions/editor-config/database.ts b/packages/frontend/core/src/blocksuite/extensions/editor-config/database.ts index 24eac2eceb..06bca485bc 100644 --- a/packages/frontend/core/src/blocksuite/extensions/editor-config/database.ts +++ b/packages/frontend/core/src/blocksuite/extensions/editor-config/database.ts @@ -42,7 +42,7 @@ function createCopyLinkToBlockMenuItem( }, select: () => { const serverService = framework.get(ServerService); - const pageId = model.doc.id; + const pageId = model.store.id; const { editor } = framework.get(EditorService); const mode = editor.mode$.value; diff --git a/packages/frontend/core/src/modules/media/entities/audio-attachment-block.ts b/packages/frontend/core/src/modules/media/entities/audio-attachment-block.ts index 3dc1b90ae4..1040bb4123 100644 --- a/packages/frontend/core/src/modules/media/entities/audio-attachment-block.ts +++ b/packages/frontend/core/src/modules/media/entities/audio-attachment-block.ts @@ -66,7 +66,7 @@ export class AudioAttachmentBlock extends Entity { computed(() => { // find the last transcription block for (const key of [...this.props.childMap.value.keys()].reverse()) { - const block = this.props.doc.getBlock$(key); + const block = this.props.store.getBlock$(key); if (block?.flavour === TranscriptionBlockFlavour) { return block.model as unknown as TranscriptionBlockModel; } @@ -113,7 +113,7 @@ export class AudioAttachmentBlock extends Entity { if (!transcriptionBlockProps) { // transcription block is not created yet, we need to create it - this.props.doc.addBlock( + this.props.store.addBlock( 'affine:transcription', { transcription: {}, @@ -179,14 +179,14 @@ export class AudioAttachmentBlock extends Entity { title: string, collapsed: boolean = false ) => { - const calloutId = this.props.doc.addBlock( + const calloutId = this.props.store.addBlock( 'affine:callout', { emoji, }, this.transcriptionBlock$.value?.id ); - this.props.doc.addBlock( + this.props.store.addBlock( 'affine:paragraph', { type: 'h6', @@ -223,7 +223,7 @@ export class AudioAttachmentBlock extends Entity { insert: ': ' + sanitizeText(segment.transcription), }, ]; - this.props.doc.addBlock( + this.props.store.addBlock( 'affine:paragraph', { text: new Text(deltaInserts), @@ -238,7 +238,7 @@ export class AudioAttachmentBlock extends Entity { await insertFromMarkdown( undefined, summary, - this.props.doc, + this.props.store, calloutId, 1 ); @@ -252,7 +252,7 @@ export class AudioAttachmentBlock extends Entity { await insertFromMarkdown( undefined, actions ?? '', - this.props.doc, + this.props.store, calloutId, 1 ); diff --git a/packages/frontend/core/src/modules/media/services/audio-attachment.ts b/packages/frontend/core/src/modules/media/services/audio-attachment.ts index ca4959612c..da1b5c7686 100644 --- a/packages/frontend/core/src/modules/media/services/audio-attachment.ts +++ b/packages/frontend/core/src/modules/media/services/audio-attachment.ts @@ -28,8 +28,8 @@ export class AudioAttachmentService extends Service { const key = attachmentBlockAudioMediaKey({ blobId: model.props.sourceId, blockId: model.id, - docId: model.doc.id, - workspaceId: model.doc.rootDoc.guid, + docId: model.store.id, + workspaceId: model.store.rootDoc.guid, }); let exists = this.pool.get(key); if (!exists) { diff --git a/packages/frontend/core/src/modules/media/services/audio-media-manager.ts b/packages/frontend/core/src/modules/media/services/audio-media-manager.ts index dbff5649ee..c4586d1786 100644 --- a/packages/frontend/core/src/modules/media/services/audio-media-manager.ts +++ b/packages/frontend/core/src/modules/media/services/audio-media-manager.ts @@ -308,8 +308,8 @@ export class AudioMediaManagerService extends Service { key: attachmentBlockAudioMediaKey({ blobId: input.props.sourceId, blockId: input.id, - docId: input.doc.id, - workspaceId: input.doc.rootDoc.guid, + docId: input.store.id, + workspaceId: input.store.rootDoc.guid, }), name: input.props.name, size: input.props.size, diff --git a/packages/frontend/core/src/modules/media/utils.ts b/packages/frontend/core/src/modules/media/utils.ts index 6f0a57740f..3a2a567d58 100644 --- a/packages/frontend/core/src/modules/media/utils.ts +++ b/packages/frontend/core/src/modules/media/utils.ts @@ -60,7 +60,7 @@ export async function downloadBlobToBuffer(model: AttachmentBlockModel) { throw new Error('Attachment not found'); } - const blob = await model.doc.blobSync.get(sourceId); + const blob = await model.store.blobSync.get(sourceId); if (!blob) { throw new Error('Attachment not found'); } diff --git a/packages/frontend/core/src/modules/peek-view/entities/peek-view.ts b/packages/frontend/core/src/modules/peek-view/entities/peek-view.ts index 64cf57179a..52e828c2bd 100644 --- a/packages/frontend/core/src/modules/peek-view/entities/peek-view.ts +++ b/packages/frontend/core/src/modules/peek-view/entities/peek-view.ts @@ -165,7 +165,7 @@ function resolvePeekInfoFromPeekTarget( // refModel can be null if the reference is invalid if (refModel) { const docId = - 'doc' in refModel ? refModel.doc.id : refModel.surface.doc.id; + 'store' in refModel ? refModel.store.id : refModel.surface.store.id; return { type: 'doc', docRef: { @@ -179,7 +179,7 @@ function resolvePeekInfoFromPeekTarget( return { type: 'attachment', docRef: { - docId: blockModel.doc.id, + docId: blockModel.store.id, blockIds: [blockModel.id], filetype: blockModel.props.type, }, @@ -188,7 +188,7 @@ function resolvePeekInfoFromPeekTarget( return { type: 'image', docRef: { - docId: blockModel.doc.id, + docId: blockModel.store.id, blockIds: [blockModel.id], }, }; @@ -196,7 +196,7 @@ function resolvePeekInfoFromPeekTarget( return { type: 'ai-chat-block', docRef: { - docId: blockModel.doc.id, + docId: blockModel.store.id, blockIds: [blockModel.id], }, model: blockModel, diff --git a/packages/frontend/core/src/modules/peek-view/view/image-preview/index.tsx b/packages/frontend/core/src/modules/peek-view/view/image-preview/index.tsx index 038f98aef0..522f8c8d7a 100644 --- a/packages/frontend/core/src/modules/peek-view/view/image-preview/index.tsx +++ b/packages/frontend/core/src/modules/peek-view/view/image-preview/index.tsx @@ -362,7 +362,7 @@ const ImagePreviewModalImpl = ({ index, url: blobUrl, caption: blockModel.props.caption, - onDelete: !blockModel.doc.readonly + onDelete: !blockModel.store.readonly ? () => { handleDelete(); } diff --git a/tests/blocksuite/e2e/utils/asserts.ts b/tests/blocksuite/e2e/utils/asserts.ts index 942ede1c09..61471815a4 100644 --- a/tests/blocksuite/e2e/utils/asserts.ts +++ b/tests/blocksuite/e2e/utils/asserts.ts @@ -440,7 +440,7 @@ export async function assertParentBlockId( if (!model) { throw new Error(`Block with id ${blockId} not found`); } - return model.doc.getParent(model)?.id; + return model.store.getParent(model)?.id; }, { blockId } ); @@ -458,7 +458,7 @@ export async function assertParentBlockFlavour( if (!model) { throw new Error(`Block with id ${blockId} not found`); } - return model.doc.getParent(model)?.flavour; + return model.store.getParent(model)?.flavour; }, { blockId } );