refactor(editor): rename doc to store on block components (#12173)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Refactor**
  - Unified internal data access by replacing all references from `doc` to `store` across all components, blocks, widgets, and utilities. This affects how readonly state, block operations, and service retrieval are handled throughout the application.
- **Tests**
  - Updated all test utilities and test cases to use `store` instead of `doc` for document-related operations.
- **Chores**
  - Updated context providers and property names to reflect the change from `doc` to `store` for improved consistency and maintainability.

No user-facing features or behaviors have changed.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-05-08 01:01:05 +00:00
parent a45347656e
commit 388641bc89
140 changed files with 480 additions and 456 deletions

View File

@@ -160,8 +160,8 @@ function addAIChatBlock(
return;
}
const { doc } = host;
const surfaceBlock = doc
const { store } = host;
const surfaceBlock = store
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
@@ -174,15 +174,15 @@ function addAIChatBlock(
const x = viewportCenter.x - width / 2;
const y = viewportCenter.y - height / 2;
const bound = new Bound(x, y, width, height);
const aiChatBlockId = doc.addBlock(
const aiChatBlockId = store.addBlock(
'affine:embed-ai-chat',
{
xywh: bound.serialize(),
messages: JSON.stringify(messages),
index,
sessionId,
rootWorkspaceId: doc.workspace.id,
rootDocId: doc.id,
rootWorkspaceId: store.workspace.id,
rootDocId: store.id,
},
surfaceBlock.id
);
@@ -379,8 +379,8 @@ const SAVE_AS_BLOCK: ChatAction = {
try {
const newSessionId = await AIProvider.forkChat?.({
workspaceId: host.doc.workspace.id,
docId: host.doc.id,
workspaceId: host.store.workspace.id,
docId: host.store.id,
sessionId: parentSessionId,
latestMessageId: messageId,
});
@@ -391,7 +391,7 @@ const SAVE_AS_BLOCK: ChatAction = {
// Get messages before the latest message
const messages = await constructRootChatBlockMessages(
host.doc,
host.store,
newSessionId
);
@@ -441,7 +441,7 @@ const ADD_TO_EDGELESS_AS_NOTE = {
toast: 'New note created',
handler: async (host: EditorHost, content: string): Promise<boolean> => {
reportResponse('result:add-note');
const { doc } = host;
const { store } = host;
const gfx = host.std.get(GfxControllerIdentifier);
const elements = gfx.selection.selectedElements;
@@ -457,9 +457,9 @@ const ADD_TO_EDGELESS_AS_NOTE = {
props.xywh = newBound.serialize();
}
const id = doc.addBlock('affine:note', props, doc.root?.id);
const id = store.addBlock('affine:note', props, store.root?.id);
await insertFromMarkdown(host, content, doc, id, 0);
await insertFromMarkdown(host, content, store, id, 0);
gfx.selection.set({
elements: [id],
@@ -477,7 +477,7 @@ const SAVE_AS_DOC = {
toast: 'New doc created',
handler: (host: EditorHost, content: string) => {
reportResponse('result:add-page');
const doc = host.doc.workspace.createDoc();
const doc = host.store.workspace.createDoc();
const newDoc = doc.getStore();
newDoc.load();
const rootId = newDoc.addBlock('affine:page');
@@ -498,8 +498,10 @@ const SAVE_AS_DOC = {
return;
}
complete = true;
const { doc } = newHost;
insertFromMarkdown(newHost, content, doc, noteId, 0).catch(console.error);
const { store } = newHost;
insertFromMarkdown(newHost, content, store, noteId, 0).catch(
console.error
);
})();
return true;
@@ -519,8 +521,8 @@ const CREATE_AS_LINKED_DOC = {
handler: async (host: EditorHost, content: string) => {
reportResponse('result:add-page');
const { doc } = host;
const surfaceBlock = doc
const { store } = host;
const surfaceBlock = store
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
@@ -534,7 +536,7 @@ const CREATE_AS_LINKED_DOC = {
}
// Create a new doc and add the content to it
const newDoc = host.doc.workspace.createDoc().getStore();
const newDoc = host.store.workspace.createDoc().getStore();
newDoc.load();
const rootId = newDoc.addBlock('affine:page');
newDoc.addBlock('affine:surface', {}, rootId);

View File

@@ -107,8 +107,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
signal,
control,
where,
docId: host.doc.id,
workspaceId: host.doc.workspace.id,
docId: host.store.id,
workspaceId: host.store.workspace.id,
webSearch: visible?.value && enabled?.value,
} as Parameters<typeof action>[0];
// @ts-expect-error TODO(@Peng): maybe fix this

View File

@@ -53,7 +53,7 @@ async function getContentFromEmbedSyncedDocModel(
host: EditorHost,
models: EmbedSyncedDocModel[]
) {
const slice = Slice.fromModels(host.doc, models);
const slice = Slice.fromModels(host.store, models);
return (await getContentFromSlice(host, slice)).trim();
}
@@ -64,7 +64,7 @@ async function getContentFromHubBlockModel(
return (
await Promise.all(
models.map(model => {
const slice = Slice.fromModels(host.doc, model.children);
const slice = Slice.fromModels(host.store, model.children);
return getContentFromSlice(host, slice);
})
)
@@ -195,8 +195,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
where,
models,
host,
docId: host.doc.id,
workspaceId: host.doc.workspace.id,
docId: host.store.id,
workspaceId: host.store.workspace.id,
webSearch: visible?.value && enabled?.value,
} as Parameters<typeof action>[0];
@@ -237,8 +237,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
models,
control: 'format-bar',
host,
docId: host.doc.id,
workspaceId: host.doc.workspace.id,
docId: host.store.id,
workspaceId: host.store.workspace.id,
} as Parameters<typeof action>[0];
// @ts-expect-error TODO(@Peng): maybe fix this

View File

@@ -61,7 +61,7 @@ type ErrorConfig = Exclude<
>['errorStateConfig'];
export function getToolbar(host: EditorHost) {
const rootBlockId = host.doc.root?.id as string;
const rootBlockId = host.store.root?.id as string;
const toolbar = host.view.getWidget(
AFFINE_TOOLBAR_WIDGET,
rootBlockId
@@ -211,7 +211,7 @@ export function asCaption<T extends keyof BlockSuitePresets.AIActions>(
const imageBlock = selectedElements[0];
if (!(imageBlock instanceof ImageBlockModel)) return;
host.doc.updateBlock(imageBlock, { caption });
host.store.updateBlock(imageBlock, { caption });
panel.hide();
},
};
@@ -223,7 +223,7 @@ function insertBelow(
parentId: string,
index = 0
) {
insertFromMarkdown(host, markdown, host.doc, parentId, index)
insertFromMarkdown(host, markdown, host.store, parentId, index)
.then(() => {
const gfx = host.std.get(GfxControllerIdentifier);
@@ -242,7 +242,7 @@ function createBlockAndInsert(
markdown: string,
type: 'edgelessText' | 'note'
) {
const doc = host.doc;
const doc = host.store;
const edgelessCopilot = getEdgelessCopilotWidget(host);
doc.transact(() => {
if (!doc.root) return;
@@ -340,11 +340,11 @@ function responseToCreateImage(host: EditorHost) {
const gfx = host.std.get(GfxControllerIdentifier);
const [x, y] = gfx.viewport.toViewCoord(minX, minY);
host.doc.transact(() => {
host.store.transact(() => {
addImages(host.std, [img], { point: [x, y] })
.then(blockIds => {
const imageBlockId = blockIds[0];
const imageBlock = host.doc.getBlock(imageBlockId);
const imageBlock = host.store.getBlock(imageBlockId);
if (!imageBlock || !selectedBound) return;
// Update the image width and height to the same with the selected image
@@ -356,7 +356,7 @@ function responseToCreateImage(host: EditorHost) {
selectedBound.w,
selectedBound.h
);
host.doc.updateBlock(imageModel, { xywh: newBound.serialize() });
host.store.updateBlock(imageModel, { xywh: newBound.serialize() });
})
.catch(console.error);
});
@@ -365,7 +365,7 @@ function responseToCreateImage(host: EditorHost) {
}
export function responseToExpandMindmap(host: EditorHost, ctx: AIContext) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
const elements = ctx.get().selectedElements;
@@ -414,7 +414,7 @@ function responseToBrainstormMindmap(host: EditorHost, ctx: AIContext) {
const gfx = host.std.get(GfxControllerIdentifier);
const edgelessCopilot = getEdgelessCopilotWidget(host);
const selectionRect = edgelessCopilot.selectionModelRect;
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
const { node, style, selectedElements } = ctx.get();
@@ -440,7 +440,7 @@ function responseToBrainstormMindmap(host: EditorHost, ctx: AIContext) {
});
const mindmap = surface.getElementById(mindmapId) as MindmapElementModel;
host.doc.transact(() => {
host.store.transact(() => {
mindmap.childElements.forEach(shape => {
fitContent(shape as ShapeElementModel);
});
@@ -477,7 +477,7 @@ function responseToMakeItReal(host: EditorHost, ctx: AIContext) {
html = preprocessHtml(html);
const edgelessCopilot = getEdgelessCopilotWidget(host);
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
const data = ctx.get();
@@ -489,8 +489,8 @@ function responseToMakeItReal(host: EditorHost, ctx: AIContext) {
edgelessCopilot.hideCopilotPanel();
aiPanel.hide();
host.doc.transact(() => {
host.doc.addBlock(
host.store.transact(() => {
host.store.addBlock(
'affine:embed-html',
{
html,

View File

@@ -66,10 +66,10 @@ function responseToBrainstormMindmap(
ctx: AIContext,
place: Place
) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
host.doc.transact(() => {
host.store.transact(() => {
const { node, style } = ctx.get();
if (!node) return;
const bound = getEdgelessContentBound(host);
@@ -106,7 +106,7 @@ function responseToBrainstormMindmap(
}
function responseToMakeItReal(host: EditorHost, ctx: AIContext, place: Place) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
const aiPanel = getAIPanelWidget(host);
if (!aiPanel.answer || !surface) return;
@@ -116,8 +116,8 @@ function responseToMakeItReal(host: EditorHost, ctx: AIContext, place: Place) {
const y = bound ? bound.y : 0;
const htmlBound = new Bound(x, y + PADDING, width || 800, height || 600);
const html = preprocessHtml(aiPanel.answer);
host.doc.transact(() => {
host.doc.addBlock(
host.store.transact(() => {
host.store.addBlock(
'affine:embed-html',
{
html,
@@ -137,7 +137,7 @@ async function responseToCreateSlides(
place: Place
) {
const { contents, images = [] } = ctx.get();
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!contents || !surface) return;
try {
@@ -235,11 +235,11 @@ function getSelection(host: EditorHost) {
}
function getEdgelessContentBound(host: EditorHost) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
const elements = (
host.doc
host.store
.getAllModels()
.filter(
model =>
@@ -262,9 +262,9 @@ function expandBound(bound: Bound, margin: number) {
}
function addSurfaceRefBlock(host: EditorHost, bound: Bound, place: Place) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
if (!surface) return;
const frame = host.doc.addBlock(
const frame = host.store.addBlock(
'affine:frame',
{
title: new Text(new Y.Text('Frame')),
@@ -296,7 +296,7 @@ function addSiblingBlocks(
) {
const targetModel = getTargetModel(host, place);
if (!targetModel) return;
return host.doc.addSiblingBlocks(targetModel, props, place);
return host.store.addSiblingBlocks(targetModel, props, place);
}
function findFrameObject(obj: AffineNode): AffineNode | null {

View File

@@ -70,7 +70,7 @@ function asCaption<T extends keyof BlockSuitePresets.AIActions>(
const imageBlock = selectedBlocks[0].model;
if (!(imageBlock instanceof ImageBlockModel)) return;
host.doc.updateBlock(imageBlock, { caption });
host.store.updateBlock(imageBlock, { caption });
panel.hide();
},
};
@@ -97,7 +97,7 @@ function createNewNote(host: EditorHost): AIItemConfig {
// create a new note block at the left of the current note block
const bound = Bound.deserialize(noteModel.xywh);
const newBound = new Bound(bound.x - bound.w - 20, bound.y, bound.w, 72);
const doc = host.doc;
const doc = host.store;
const panel = getAIPanelWidget(host);
const gfx = host.std.get(GfxControllerIdentifier);
doc.transact(() => {

View File

@@ -9,9 +9,9 @@ import { type AIChatBlockModel } from './model';
import { AIChatBlockStyles } from './styles';
@Peekable({
enableOn: ({ doc }: AIChatBlockComponent) => {
enableOn: ({ store }: AIChatBlockComponent) => {
// Disable on mobile and readonly mode
return !BUILD_CONFIG.isMobileEdition && !doc.readonly;
return !BUILD_CONFIG.isMobileEdition && !store.readonly;
},
})
export class AIChatBlockComponent extends BlockComponent<AIChatBlockModel> {

View File

@@ -174,7 +174,7 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
private _renderAIOnboarding() {
return this.isLoading ||
!this.host?.doc.get(FeatureFlagService).getFlag('enable_ai_onboarding')
!this.host?.store.get(FeatureFlagService).getFlag('enable_ai_onboarding')
? nothing
: html`<div class="onboarding-wrapper" data-testid="ai-onboarding">
${repeat(
@@ -328,7 +328,7 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
disposables.add(
docModeService.onPrimaryModeChange(
() => this.requestUpdate(),
this.host.doc.id
this.host.store.id
)
);
}
@@ -364,12 +364,12 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
}
this.updateContext({ messages, status: 'loading', error: null });
const { doc } = this.host;
const { store } = this.host;
const stream = await AIProvider.actions.chat({
sessionId,
retry: true,
docId: doc.id,
workspaceId: doc.workspace.id,
docId: store.id,
workspaceId: store.workspace.id,
host: this.host,
stream: true,
signal: abortController.signal,

View File

@@ -404,7 +404,7 @@ export class ChatPanelChips extends SignalWatcher(
if (!contextId || !AIProvider.context) {
throw new Error('Context not found');
}
const blobId = await this.host.doc.blobSync.set(chip.file);
const blobId = await this.host.store.blobSync.set(chip.file);
const contextFile = await AIProvider.context.addContextFile(chip.file, {
contextId,
blobId,

View File

@@ -232,7 +232,7 @@ export class AIChatComposer extends SignalWatcher(
const fileChips: FileChip[] = await Promise.all(
files.map(async file => {
const blob = await this.host.doc.blobSync.get(file.blobId);
const blob = await this.host.store.blobSync.get(file.blobId);
return {
file: new File(blob ? [blob] : [], file.name),
blobId: file.blobId,

View File

@@ -551,9 +551,9 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
sessionId,
input: userInput,
contexts,
docId: this.host.doc.id,
docId: this.host.store.id,
attachments: images,
workspaceId: this.host.doc.workspace.id,
workspaceId: this.host.store.workspace.id,
host: this.host,
stream: true,
signal: abortController.signal,
@@ -616,8 +616,8 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
if (!last.id) {
const sessionId = await this.getSessionId();
const historyIds = await AIProvider.histories?.ids(
this.host.doc.workspace.id,
this.host.doc.id,
this.host.store.workspace.id,
this.host.store.id,
{ sessionId }
);
if (!historyIds || !historyIds[0]) return;

View File

@@ -30,7 +30,7 @@ export function AiSlashMenuConfigExtension() {
const showWhenWrapper =
(item?: AIItemConfig) =>
({ std }: SlashMenuContext) => {
const root = std.host.doc.root;
const root = std.host.store.root;
if (!root) return false;
const affineAIPanelWidget = std.view.getWidget(
AFFINE_AI_PANEL_WIDGET,
@@ -40,7 +40,7 @@ export function AiSlashMenuConfigExtension() {
const chain = std.host.command.chain();
const docModeService = std.get(DocModeProvider);
const editorMode = docModeService.getPrimaryMode(std.host.doc.id);
const editorMode = docModeService.getPrimaryMode(std.host.store.id);
return item?.showWhen?.(chain, editorMode, std.host) ?? true;
};
@@ -80,7 +80,7 @@ export function AiSlashMenuConfigExtension() {
icon: AIStarIcon,
when: showWhenWrapper(),
action: ({ std }) => {
const root = std.host.doc.root;
const root = std.host.store.root;
if (!root) return;
const affineAIPanelWidget = std.view.getWidget(
AFFINE_AI_PANEL_WIDGET,

View File

@@ -56,7 +56,7 @@ export const createMindmapExecuteRenderer: (
}
ctx.set({
node: markdownToMindmap(answer, host.doc, host.std.store.provider),
node: markdownToMindmap(answer, host.store, host.std.store.provider),
});
handler(host, ctx);

View File

@@ -156,10 +156,10 @@ export class AIChatBlockPeekView extends LitElement {
const lastMessage = this._historyMessages.at(-1);
if (!lastMessage) return;
const { doc } = this.host;
const { store } = this.host;
const forkSessionId = await AIProvider.forkChat?.({
workspaceId: doc.workspace.id,
docId: doc.id,
workspaceId: store.workspace.id,
docId: store.id,
sessionId: this._sessionId,
latestMessageId: lastMessage.id,
});
@@ -195,9 +195,9 @@ export class AIChatBlockPeekView extends LitElement {
return;
}
const { doc } = this.host;
const { store } = this.host;
// create a new AI chat block
const surfaceBlock = doc
const surfaceBlock = store
.getAllModels()
.find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) {
@@ -262,8 +262,8 @@ export class AIChatBlockPeekView extends LitElement {
return;
}
const { doc } = this.host;
const chatBlock = doc.getBlock(this._forkBlockId);
const { store } = this.host;
const chatBlock = store.getBlock(this._forkBlockId);
if (!chatBlock) return;
// Get fork session messages
@@ -276,7 +276,7 @@ export class AIChatBlockPeekView extends LitElement {
if (!messages.length) {
return;
}
doc.updateBlock(chatBlock.model, {
store.updateBlock(chatBlock.model, {
messages: JSON.stringify(messages),
});
};
@@ -298,12 +298,12 @@ export class AIChatBlockPeekView extends LitElement {
private readonly _onHistoryCleared = async () => {
const { _forkBlockId, host } = this;
if (_forkBlockId) {
const surface = getSurfaceBlock(host.doc);
const surface = getSurfaceBlock(host.store);
const crud = host.std.get(EdgelessCRUDIdentifier);
const chatBlock = host.doc.getBlock(_forkBlockId)?.model;
const chatBlock = host.store.getBlock(_forkBlockId)?.model;
if (chatBlock) {
const connectors = surface?.getConnectors(chatBlock.id);
host.doc.transact(() => {
host.store.transact(() => {
// Delete the AI chat block
crud.removeElement(_forkBlockId);
// Delete the connectors
@@ -335,12 +335,12 @@ export class AIChatBlockPeekView extends LitElement {
}
this.updateContext({ messages, status: 'loading', error: null });
const { doc } = this.host;
const { store } = this.host;
const stream = await AIProvider.actions.chat({
sessionId: _forkSessionId,
retry: true,
docId: doc.id,
workspaceId: doc.workspace.id,
docId: store.id,
workspaceId: store.workspace.id,
host: this.host,
stream: true,
signal: abortController.signal,
@@ -505,7 +505,7 @@ export class AIChatBlockPeekView extends LitElement {
<div class="history-clear-container">
<ai-history-clear
.host=${this.host}
.doc=${this.host.doc}
.doc=${this.host.store}
.getSessionId=${this._getSessionId}
.onHistoryCleared=${this._onHistoryCleared}
.chatContextValue=${chatContext}
@@ -514,7 +514,7 @@ export class AIChatBlockPeekView extends LitElement {
</div>
<ai-chat-composer
.host=${host}
.doc=${this.host.doc}
.doc=${this.host.store}
.getSessionId=${this._getSessionId}
.createSessionId=${this._createSessionId}
.chatContextValue=${chatContext}

View File

@@ -56,7 +56,7 @@ export const PPTBuilder = (host: EditorHost) => {
return {
process: async (text: string) => {
try {
const snapshot = await markdownToSnapshot(text, host.doc, host);
const snapshot = await markdownToSnapshot(text, host.store, host);
const block = snapshot.snapshot?.content[0];
if (!block) {
@@ -73,7 +73,7 @@ export const PPTBuilder = (host: EditorHost) => {
return { contents, images: allImages };
},
done: async (text: string) => {
const snapshot = await markdownToSnapshot(text, host.doc, host);
const snapshot = await markdownToSnapshot(text, host.store, host);
const block = snapshot.snapshot?.content[0];
if (!block) {
return;

View File

@@ -6,7 +6,7 @@ import {
} from '../widgets/ai-panel/ai-panel';
export const getAIPanelWidget = (host: EditorHost): AffineAIPanelWidget => {
const rootBlockId = host.doc.root?.id;
const rootBlockId = host.store.root?.id;
if (!rootBlockId) {
throw new Error('rootBlockId is not found');
}

View File

@@ -48,7 +48,7 @@ export function isMindmapChild(ele: GfxModel) {
export function getEdgelessCopilotWidget(
host: EditorHost
): EdgelessCopilotWidget {
const rootBlockId = host.doc.root?.id as string;
const rootBlockId = host.store.root?.id as string;
const copilotWidget = host.view.getWidget(
AFFINE_EDGELESS_COPILOT_WIDGET,
rootBlockId

View File

@@ -67,11 +67,11 @@ export const insert = async (
);
const insertIndex = below ? index + 1 : index;
const { doc } = host;
const { store } = host;
const models = await insertFromMarkdown(
host,
content,
doc,
store,
blockParent.model.id,
insertIndex
);
@@ -112,27 +112,27 @@ export const replace = async (
host.std.command.exec(deleteTextCommand, { textSelection });
const { snapshot, transformer } = await markdownToSnapshot(
content,
host.doc,
host.store,
host
);
if (snapshot) {
await transformer.snapshotToSlice(
snapshot,
host.doc,
host.store,
firstBlockParent.model.id,
firstIndex + 1
);
}
} else {
selectedModels.forEach(model => {
host.doc.deleteBlock(model);
host.store.deleteBlock(model);
});
const { doc } = host;
const { store } = host;
const models = await insertFromMarkdown(
host,
content,
doc,
store,
firstBlockParent.model.id,
firstIndex
);

View File

@@ -133,7 +133,7 @@ export async function selectAboveBlocks(editorHost: EditorHost, num = 10) {
let lastRootModel: BlockModel | null = null;
while (noteModel && noteModel.flavour !== 'affine:note') {
lastRootModel = noteModel;
noteModel = editorHost.doc.getParent(noteModel);
noteModel = editorHost.store.getParent(noteModel);
}
if (!noteModel || !lastRootModel) return '';
@@ -177,8 +177,8 @@ export async function selectAboveBlocks(editorHost: EditorHost, num = 10) {
}
export function getSurfaceElementFromEditor(editor: EditorHost) {
const { doc } = editor;
const surfaceModel = getSurfaceBlock(doc);
const { store } = editor;
const surfaceModel = getSurfaceBlock(store);
if (!surfaceModel) return null;
const surfaceId = surfaceModel.id;
@@ -224,7 +224,7 @@ export const getSelectedImagesAsBlobs = async (host: EditorHost) => {
data.selectedBlocks?.map(async b => {
const sourceId = (b.model as ImageBlockModel).props.sourceId;
if (!sourceId) return null;
const blob = await host.doc.blobSync.get(sourceId);
const blob = await host.store.blobSync.get(sourceId);
if (!blob) return null;
return new File([blob], sourceId);
}) ?? []
@@ -256,7 +256,7 @@ export const imageCustomInput = async (host: EditorHost) => {
if (!(imageBlock instanceof ImageBlockModel)) return;
if (!imageBlock.props.sourceId) return;
const blob = await host.doc.blobSync.get(imageBlock.props.sourceId);
const blob = await host.store.blobSync.get(imageBlock.props.sourceId);
if (!blob) return;
return {

View File

@@ -327,7 +327,7 @@ export class AffineAIPanelWidget extends WidgetComponent {
}
get viewportOverlayWidget() {
const rootId = this.host.doc.root?.id;
const rootId = this.host.store.root?.id;
return rootId
? (this.host.view.getWidget(
AFFINE_VIEWPORT_OVERLAY_WIDGET,

View File

@@ -85,7 +85,7 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
if (!referenceElement || !referenceElement.isConnected) return;
// show ai input
const rootBlockId = this.host.doc.root?.id;
const rootBlockId = this.host.store.root?.id;
if (!rootBlockId) return;
const input = this.host.view.getWidget(

View File

@@ -95,7 +95,7 @@ const StarterBarNotEmpty = ({ doc }: { doc: Store }) => {
const std = editorService.editor.editorContainer$.value?.std;
if (!std) return;
const rootBlockId = std.host.doc.root?.id;
const rootBlockId = std.host.store.root?.id;
if (!rootBlockId) return;
const rootComponent = std.view.getBlock(rootBlockId);

View File

@@ -225,7 +225,7 @@ class FileCellManager {
this.selectCurrentCell = props.selectCurrentCell;
this.isEditing = props.isEditing$;
this.blobSync = this.cell?.view?.contextGet
? this.cell.view.contextGet(HostContextKey)?.doc.blobSync
? this.cell.view.contextGet(HostContextKey)?.store.blobSync
: undefined;
this.fileUploadManager = this.blobSync

View File

@@ -44,7 +44,7 @@ function processSnapshot(
text: TextSelection,
host: EditorHost
) {
const model = host.doc.getModelById(snapshot.id);
const model = host.store.getModelById(snapshot.id);
if (!model) {
return;
}

View File

@@ -369,7 +369,7 @@ export class AtMenuConfigService extends Service {
this.workspaceServerService.server?.scope.get(NotificationService);
if (!notificationService) return;
const doc = block.doc;
const doc = block.store;
const workspaceId = doc.workspace.id;
const docId = doc.id;
const mode = block.std.get(DocModeProvider).getEditorMode() ?? 'page';