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
|
||||
) {
|
||||
|
||||
@@ -317,7 +317,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
||||
})
|
||||
);
|
||||
this._disposables.add(
|
||||
this.doc.slots.blockUpdated.subscribe(payload => {
|
||||
this.store.slots.blockUpdated.subscribe(payload => {
|
||||
if (payload.flavour === 'affine:surface-ref') {
|
||||
switch (payload.type) {
|
||||
case 'add':
|
||||
@@ -585,7 +585,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
override render() {
|
||||
const advancedVisibilityEnabled = this.doc
|
||||
const advancedVisibilityEnabled = this.store
|
||||
.get(FeatureFlagService)
|
||||
.getFlag('enable_advanced_block_visibility');
|
||||
|
||||
|
||||
@@ -660,7 +660,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
|
||||
override render() {
|
||||
const type = this.edgelessTool;
|
||||
if (this.doc.readonly && type !== 'frameNavigator') {
|
||||
if (this.store.readonly && type !== 'frameNavigator') {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const AFFINE_FRAME_TITLE_WIDGET = 'affine-frame-title-widget';
|
||||
|
||||
export class AffineFrameTitleWidget extends WidgetComponent<RootBlockModel> {
|
||||
private get _frames() {
|
||||
return Object.values(this.doc.blocks.value)
|
||||
return Object.values(this.store.blocks.value)
|
||||
.map(({ model }) => model)
|
||||
.filter(model => model instanceof FrameBlockModel);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export class EdgelessFrameTitleEditor extends WithDisposable(
|
||||
}
|
||||
|
||||
override render() {
|
||||
const rootBlockId = this.editorHost.doc.root?.id;
|
||||
const rootBlockId = this.editorHost.store.root?.id;
|
||||
if (!rootBlockId) return nothing;
|
||||
|
||||
const viewport = this.gfx.viewport;
|
||||
|
||||
@@ -110,9 +110,9 @@ export class AffineKeyboardToolbarWidget extends WidgetComponent<RootBlockModel>
|
||||
|
||||
override render() {
|
||||
if (
|
||||
this.doc.readonly ||
|
||||
this.store.readonly ||
|
||||
!IS_MOBILE ||
|
||||
!this.doc
|
||||
!this.store
|
||||
.get(FeatureFlagService)
|
||||
.getFlag('enable_mobile_keyboard_toolbar')
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ export function createLinkedDocMenuGroup(
|
||||
editorHost: EditorHost,
|
||||
inlineEditor: AffineInlineEditor
|
||||
) {
|
||||
const doc = editorHost.doc;
|
||||
const doc = editorHost.store;
|
||||
const { docMetas } = doc.workspace.meta;
|
||||
const filteredDocList = docMetas
|
||||
.filter(({ id }) => id !== doc.id)
|
||||
@@ -122,7 +122,7 @@ export function createNewDocMenuGroup(
|
||||
editorHost: EditorHost,
|
||||
inlineEditor: AffineInlineEditor
|
||||
): LinkedMenuGroup {
|
||||
const doc = editorHost.doc;
|
||||
const doc = editorHost.store;
|
||||
const docName = query || DEFAULT_DOC_NAME;
|
||||
const displayDocName =
|
||||
docName.slice(0, DISPLAY_NAME_LENGTH) +
|
||||
|
||||
@@ -307,7 +307,7 @@ export class AffineLinkedDocWidget extends WidgetComponent<RootBlockModel> {
|
||||
|
||||
this._updateInputRects();
|
||||
|
||||
const enableMobile = this.doc
|
||||
const enableMobile = this.store
|
||||
.get(FeatureFlagService)
|
||||
.getFlag('enable_mobile_linked_doc_menu');
|
||||
this._mode$.value = enableMobile ? mode : 'desktop';
|
||||
|
||||
@@ -118,7 +118,7 @@ export function getSelectingBlockPaths(
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const block = blocks[i];
|
||||
const parent = blocks[i].element.doc.getParent(block.element.model);
|
||||
const parent = blocks[i].element.store.getParent(block.element.model);
|
||||
const parentId = parent?.id;
|
||||
if (parentId) {
|
||||
const isParentInBlocks = blocks.some(
|
||||
|
||||
@@ -58,7 +58,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
|
||||
private _remoteColorManager: RemoteColorManager | null = null;
|
||||
|
||||
private readonly _remoteSelections = computed(() => {
|
||||
const status = this.doc.awarenessStore.getStates();
|
||||
const status = this.store.awarenessStore.getStates();
|
||||
return [...this.std.selection.remoteSelections.entries()].map(
|
||||
([id, selections]) => {
|
||||
return {
|
||||
|
||||
@@ -90,7 +90,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent<RootBlockMode
|
||||
private readonly _updateRemoteCursor = () => {
|
||||
const remoteCursors: EdgelessRemoteSelectionWidget['_remoteCursors'] =
|
||||
new Map();
|
||||
const status = this.doc.awarenessStore.getStates();
|
||||
const status = this.store.awarenessStore.getStates();
|
||||
|
||||
this.selection.remoteCursorSelectionMap.forEach(
|
||||
(cursorSelection, clientId) => {
|
||||
@@ -177,7 +177,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent<RootBlockMode
|
||||
override connectedCallback() {
|
||||
super.connectedCallback();
|
||||
|
||||
const { _disposables, doc } = this;
|
||||
const { _disposables, store } = this;
|
||||
|
||||
if (this.surface) {
|
||||
_disposables.add(
|
||||
@@ -192,7 +192,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent<RootBlockMode
|
||||
}
|
||||
|
||||
_disposables.add(
|
||||
doc.slots.blockUpdated.subscribe(this._updateOnElementChange)
|
||||
store.slots.blockUpdated.subscribe(this._updateOnElementChange)
|
||||
);
|
||||
|
||||
_disposables.add(
|
||||
|
||||
@@ -82,13 +82,18 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
group: '8_Actions@0',
|
||||
action: ({ std, model }) => {
|
||||
const { host } = std;
|
||||
const previousSiblingModel = host.doc.getPrev(model);
|
||||
const previousSiblingModel = host.store.getPrev(model);
|
||||
if (!previousSiblingModel) return;
|
||||
|
||||
const parentModel = host.doc.getParent(previousSiblingModel);
|
||||
const parentModel = host.store.getParent(previousSiblingModel);
|
||||
if (!parentModel) return;
|
||||
|
||||
host.doc.moveBlocks([model], parentModel, previousSiblingModel, true);
|
||||
host.store.moveBlocks(
|
||||
[model],
|
||||
parentModel,
|
||||
previousSiblingModel,
|
||||
true
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -99,13 +104,13 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
group: '8_Actions@1',
|
||||
action: ({ std, model }) => {
|
||||
const { host } = std;
|
||||
const nextSiblingModel = host.doc.getNext(model);
|
||||
const nextSiblingModel = host.store.getNext(model);
|
||||
if (!nextSiblingModel) return;
|
||||
|
||||
const parentModel = host.doc.getParent(nextSiblingModel);
|
||||
const parentModel = host.store.getParent(nextSiblingModel);
|
||||
if (!parentModel) return;
|
||||
|
||||
host.doc.moveBlocks([model], parentModel, nextSiblingModel, false);
|
||||
host.store.moveBlocks([model], parentModel, nextSiblingModel, false);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -139,7 +144,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
return;
|
||||
}
|
||||
const { host } = std;
|
||||
const parent = host.doc.getParent(model);
|
||||
const parent = host.store.getParent(model);
|
||||
if (!parent) {
|
||||
console.error(
|
||||
'Failed to duplicate block! Parent not found: ' +
|
||||
@@ -152,7 +157,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
const index = parent.children.indexOf(model);
|
||||
|
||||
// FIXME: this clone is not correct
|
||||
host.doc.addBlock(
|
||||
host.store.addBlock(
|
||||
model.flavour,
|
||||
{
|
||||
type: (model as ParagraphBlockModel).props.type,
|
||||
@@ -163,7 +168,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
),
|
||||
checked: (model as ListBlockModel).props.checked,
|
||||
},
|
||||
host.doc.getParent(model),
|
||||
host.store.getParent(model),
|
||||
index
|
||||
);
|
||||
},
|
||||
@@ -176,7 +181,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
tooltip: slashMenuToolTips['Delete'],
|
||||
group: '8_Actions@4',
|
||||
action: ({ std, model }) => {
|
||||
std.host.doc.deleteBlock(model);
|
||||
std.host.store.deleteBlock(model);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -76,7 +76,7 @@ export class AffineSlashMenuWidget extends WidgetComponent {
|
||||
const textSelection = this.host.selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
const model = this.host.doc.getBlock(textSelection.blockId)?.model;
|
||||
const model = this.host.store.getBlock(textSelection.blockId)?.model;
|
||||
if (!model) return;
|
||||
|
||||
return getInlineEditorByModel(this.std, model);
|
||||
|
||||
Reference in New Issue
Block a user