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:
@@ -156,7 +156,7 @@ export class FramePanelBody extends SignalWatcher(
|
||||
};
|
||||
|
||||
get frames() {
|
||||
const frames = this.editorHost.doc
|
||||
const frames = this.editorHost.store
|
||||
.getBlocksByFlavour('affine:frame')
|
||||
.map(block => block.model as FrameBlockModel);
|
||||
return frames.sort(compare);
|
||||
@@ -318,7 +318,7 @@ export class FramePanelBody extends SignalWatcher(
|
||||
before = newIndex;
|
||||
});
|
||||
|
||||
this.editorHost.doc.captureSync();
|
||||
this.editorHost.store.captureSync();
|
||||
this._updateFrames();
|
||||
}
|
||||
}
|
||||
@@ -392,9 +392,9 @@ export class FramePanelBody extends SignalWatcher(
|
||||
|
||||
override updated(_changedProperties: PropertyValues) {
|
||||
if (_changedProperties.has('editorHost') && this.editorHost) {
|
||||
this._setDocDisposables(this.editorHost.doc);
|
||||
this._setDocDisposables(this.editorHost.store);
|
||||
// after switch to edgeless mode, should update the selection
|
||||
if (this.editorHost.doc.id === this._lastEdgelessRootId) {
|
||||
if (this.editorHost.store.id === this._lastEdgelessRootId) {
|
||||
this._gfx.selection.set({
|
||||
elements: this._selected,
|
||||
editing: false,
|
||||
@@ -402,7 +402,7 @@ export class FramePanelBody extends SignalWatcher(
|
||||
} else {
|
||||
this._selected = this._selected.length ? [] : this._selected;
|
||||
}
|
||||
this._lastEdgelessRootId = this.editorHost.doc.id;
|
||||
this._lastEdgelessRootId = this.editorHost.store.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export class OutlineNotice extends SignalWatcher(
|
||||
}
|
||||
|
||||
const shouldShowNotice =
|
||||
getNotesFromDoc(this._context.editor$.value.doc, [
|
||||
getNotesFromDoc(this._context.editor$.value.store, [
|
||||
NoteDisplayMode.DocOnly,
|
||||
]).length > 0;
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ export class OutlinePanelBody extends SignalWatcher(
|
||||
}
|
||||
|
||||
private get doc() {
|
||||
return this.editor.doc;
|
||||
return this.editor.store;
|
||||
}
|
||||
|
||||
get viewportPadding(): [number, number, number, number] {
|
||||
@@ -262,14 +262,14 @@ export class OutlinePanelBody extends SignalWatcher(
|
||||
|
||||
private _watchSelectedNotes() {
|
||||
return effect(() => {
|
||||
const { std, doc } = this.editor;
|
||||
const { std, store } = this.editor;
|
||||
const docModeService = this.editor.std.get(DocModeProvider);
|
||||
const mode = docModeService.getEditorMode();
|
||||
if (mode !== 'edgeless') return;
|
||||
|
||||
const currSelectedNotes = std.selection
|
||||
.filter(SurfaceSelection)
|
||||
.map(({ blockId }) => doc.getBlock(blockId)?.model)
|
||||
.map(({ blockId }) => store.getBlock(blockId)?.model)
|
||||
.filter(model => {
|
||||
return !!model && matchModels(model, [NoteBlockModel]);
|
||||
});
|
||||
|
||||
@@ -168,10 +168,10 @@ export class MobileOutlineMenu extends SignalWatcher(
|
||||
override render() {
|
||||
const docModeService = this.editor.std.get(DocModeProvider);
|
||||
const mode = docModeService.getEditorMode();
|
||||
if (this.editor.doc.root === null || mode === 'edgeless') return nothing;
|
||||
if (this.editor.store.root === null || mode === 'edgeless') return nothing;
|
||||
|
||||
const headingBlocks = getHeadingBlocksFromDoc(
|
||||
this.editor.doc,
|
||||
this.editor.store,
|
||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||
true
|
||||
);
|
||||
@@ -179,7 +179,7 @@ export class MobileOutlineMenu extends SignalWatcher(
|
||||
if (headingBlocks.length === 0) return nothing;
|
||||
|
||||
const items = [
|
||||
...(this.editor.doc.meta?.title !== '' ? [this.editor.doc.root] : []),
|
||||
...(this.editor.store.meta?.title !== '' ? [this.editor.store.root] : []),
|
||||
...headingBlocks,
|
||||
];
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ export class OutlineViewer extends SignalWatcher(
|
||||
);
|
||||
|
||||
this.disposables.add(
|
||||
this.editor.doc.workspace.meta.docMetaUpdated.subscribe(() => {
|
||||
this.editor.store.workspace.meta.docMetaUpdated.subscribe(() => {
|
||||
this.requestUpdate();
|
||||
})
|
||||
);
|
||||
@@ -223,10 +223,10 @@ export class OutlineViewer extends SignalWatcher(
|
||||
override render() {
|
||||
const docModeService = this.editor.std.get(DocModeProvider);
|
||||
const mode = docModeService.getEditorMode();
|
||||
if (this.editor.doc.root === null || mode === 'edgeless') return nothing;
|
||||
if (this.editor.store.root === null || mode === 'edgeless') return nothing;
|
||||
|
||||
const headingBlocks = getHeadingBlocksFromDoc(
|
||||
this.editor.doc,
|
||||
this.editor.store,
|
||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||
true
|
||||
);
|
||||
@@ -234,7 +234,7 @@ export class OutlineViewer extends SignalWatcher(
|
||||
if (headingBlocks.length === 0) return nothing;
|
||||
|
||||
const items = [
|
||||
...(this.editor.doc.meta?.title !== '' ? [this.editor.doc.root] : []),
|
||||
...(this.editor.store.meta?.title !== '' ? [this.editor.store.root] : []),
|
||||
...headingBlocks,
|
||||
];
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export function scrollToBlock(host: EditorHost, blockId: string) {
|
||||
const mode = docModeService.getEditorMode();
|
||||
if (mode === 'edgeless') return;
|
||||
|
||||
if (host.doc.root?.id === blockId) {
|
||||
if (host.store.root?.id === blockId) {
|
||||
const docTitle = getDocTitleByEditorHost(host);
|
||||
if (!docTitle) return;
|
||||
|
||||
@@ -60,12 +60,12 @@ export const observeActiveHeadingDuringScroll = (
|
||||
const host = getEditor();
|
||||
|
||||
const headings = getHeadingBlocksFromDoc(
|
||||
host.doc,
|
||||
host.store,
|
||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||
true
|
||||
);
|
||||
|
||||
let activeHeadingId = host.doc.root?.id ?? null;
|
||||
let activeHeadingId = host.store.root?.id ?? null;
|
||||
headings.forEach(heading => {
|
||||
if (isBlockBeforeViewportCenter(heading.id, host)) {
|
||||
activeHeadingId = heading.id;
|
||||
@@ -87,7 +87,7 @@ let highlightTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
function highlightBlock(host: EditorHost, blockId: string) {
|
||||
const emptyClear = () => {};
|
||||
|
||||
if (host.doc.root?.id === blockId) return emptyClear;
|
||||
if (host.store.root?.id === blockId) return emptyClear;
|
||||
|
||||
const rootComponent = host.querySelector<
|
||||
HTMLElement & { viewport: Viewport }
|
||||
|
||||
Reference in New Issue
Block a user