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:
@@ -35,13 +35,13 @@ export class PreviewHelper {
|
||||
if (!selectedIds.includes(parent)) {
|
||||
ids.push({ viewType: 'bypass', id: parent });
|
||||
}
|
||||
parent = this.widget.doc.getParent(parent)?.id ?? null;
|
||||
parent = this.widget.store.getParent(parent)?.id ?? null;
|
||||
} while (parent && !ids.map(({ id }) => id).includes(parent));
|
||||
});
|
||||
|
||||
// The children of the selected blocks should be rendered as Display
|
||||
const addChildren = (id: string) => {
|
||||
const model = this.widget.doc.getBlock(id)?.model;
|
||||
const model = this.widget.store.getBlock(id)?.model;
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ export class PreviewHelper {
|
||||
const docModeService = std.get(DocModeProvider);
|
||||
const editorSetting = std.get(EditorSettingProvider);
|
||||
const query = this._calculateQuery(blockIds as string[]);
|
||||
const store = widget.doc.doc.getStore({ query });
|
||||
const store = widget.store.doc.getStore({ query });
|
||||
let previewSpec = widget.std
|
||||
.get(ViewExtensionManagerIdentifier)
|
||||
.get('preview-page');
|
||||
|
||||
@@ -79,7 +79,7 @@ export const containChildBlock = (
|
||||
if (currentBlock.id === block.model.id) {
|
||||
return true;
|
||||
}
|
||||
currentBlock = block.doc.getParent(currentBlock.id);
|
||||
currentBlock = block.store.getParent(currentBlock.id);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -501,7 +501,7 @@ export class DragEventWatcher {
|
||||
// can't drop edgeless content on the same doc
|
||||
if (
|
||||
dragPayload.bsEntity?.fromMode === 'gfx' &&
|
||||
dragPayload.from?.docId === this.widget.doc.id
|
||||
dragPayload.from?.docId === this.widget.store.id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -550,7 +550,7 @@ export class DragEventWatcher {
|
||||
|
||||
// drop on the same place, do nothing
|
||||
if (
|
||||
(dragPayload.from?.docId === this.widget.doc.id &&
|
||||
(dragPayload.from?.docId === this.widget.store.id &&
|
||||
result.placement === 'after' &&
|
||||
parent.children[index]?.id === snapshot.content[0].id) ||
|
||||
(result.placement === 'before' &&
|
||||
@@ -566,7 +566,7 @@ export class DragEventWatcher {
|
||||
) {
|
||||
snapshot.content = snapshot.content.filter(
|
||||
block =>
|
||||
dragPayload.from?.docId !== this.widget.doc.id ||
|
||||
dragPayload.from?.docId !== this.widget.store.id ||
|
||||
block.id !== parent.id
|
||||
);
|
||||
if (snapshot.content.length) {
|
||||
@@ -590,7 +590,7 @@ export class DragEventWatcher {
|
||||
matchModels(parent, [NoteBlockModel])
|
||||
) {
|
||||
// if the snapshot comes from the same doc, just create a surface-ref block
|
||||
if (dragPayload.from?.docId === this.widget.doc.id) {
|
||||
if (dragPayload.from?.docId === this.widget.store.id) {
|
||||
let largestElem!: {
|
||||
size: number;
|
||||
id: string;
|
||||
@@ -1194,7 +1194,7 @@ export class DragEventWatcher {
|
||||
};
|
||||
|
||||
this._rewriteSnapshotXYWH(pageSnapshot, point, true);
|
||||
this._dropToModel(pageSnapshot, this.widget.doc.root!.id)
|
||||
this._dropToModel(pageSnapshot, this.widget.store.root!.id)
|
||||
.then(slices => {
|
||||
slices?.content.forEach((block, idx) => {
|
||||
if (block.flavour === 'affine:embed-iframe') {
|
||||
@@ -1259,7 +1259,7 @@ export class DragEventWatcher {
|
||||
DEFAULT_NOTE_HEIGHT
|
||||
).serialize(),
|
||||
},
|
||||
this.widget.doc.root!
|
||||
this.widget.store.root!
|
||||
);
|
||||
|
||||
this._dropToModel(
|
||||
@@ -1508,7 +1508,7 @@ export class DragEventWatcher {
|
||||
*/
|
||||
if (source.data.bsEntity?.type === 'blocks') {
|
||||
return (
|
||||
source.data.from?.docId !== widget.doc.id ||
|
||||
source.data.from?.docId !== widget.store.id ||
|
||||
source.data.bsEntity.modelIds.every(id => id !== view.model.id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export class EdgelessWatcher {
|
||||
|
||||
updateAnchorElement = () => {
|
||||
if (!this.widget.isConnected) return;
|
||||
if (this.widget.doc.readonly || this.widget.mode === 'page') {
|
||||
if (this.widget.store.readonly || this.widget.mode === 'page') {
|
||||
this.widget.hide();
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,11 @@ export class EdgelessWatcher {
|
||||
const editing = selection.editing;
|
||||
const selectedElements = selection.selectedElements;
|
||||
|
||||
if (editing || selectedElements.length !== 1 || this.widget.doc.readonly) {
|
||||
if (
|
||||
editing ||
|
||||
selectedElements.length !== 1 ||
|
||||
this.widget.store.readonly
|
||||
) {
|
||||
this.widget.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export class PageWatcher {
|
||||
const { disposables } = this.widget;
|
||||
|
||||
disposables.add(
|
||||
this.widget.doc.slots.blockUpdated.subscribe(() => this.widget.hide())
|
||||
this.widget.store.slots.blockUpdated.subscribe(() => this.widget.hide())
|
||||
);
|
||||
|
||||
disposables.add(
|
||||
|
||||
@@ -41,7 +41,7 @@ export class PointerEventWatcher {
|
||||
}
|
||||
|
||||
private readonly _canEditing = (noteBlock: BlockComponent) => {
|
||||
if (noteBlock.doc.id !== this.widget.doc.id) return false;
|
||||
if (noteBlock.store.id !== this.widget.store.id) return false;
|
||||
|
||||
if (this.widget.mode === 'page') return true;
|
||||
|
||||
@@ -178,7 +178,7 @@ export class PointerEventWatcher {
|
||||
|
||||
this.widget.anchorBlockId.value = blockId;
|
||||
|
||||
if (insideDatabaseTable(closestBlock) || this.widget.doc.readonly) {
|
||||
if (insideDatabaseTable(closestBlock) || this.widget.store.readonly) {
|
||||
this.widget.hide();
|
||||
return;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ export class PointerEventWatcher {
|
||||
ctx => {
|
||||
if (this._isPointerDown) return;
|
||||
if (
|
||||
this.widget.doc.readonly ||
|
||||
this.widget.store.readonly ||
|
||||
this.widget.dragging ||
|
||||
!this.widget.isConnected
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user