mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 13:58:50 +08:00
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:
@@ -146,14 +146,14 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
private _initHotkey() {
|
||||
const selection = this.host.selection;
|
||||
const addParagraph = () => {
|
||||
if (!this.doc.getParent(this.model)) return;
|
||||
if (!this.store.getParent(this.model)) return;
|
||||
|
||||
const [paragraphId] = this.doc.addSiblingBlocks(this.model, [
|
||||
const [paragraphId] = this.store.addSiblingBlocks(this.model, [
|
||||
{
|
||||
flavour: 'affine:paragraph',
|
||||
},
|
||||
]);
|
||||
const model = this.doc.getModelById(paragraphId);
|
||||
const model = this.store.getModelById(paragraphId);
|
||||
if (!model) return;
|
||||
|
||||
requestConnectedFrame(() => {
|
||||
@@ -185,7 +185,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
|
||||
private _initReferencedModel() {
|
||||
const findReferencedModel = (): [GfxModel | null, string] => {
|
||||
if (!this.model.props.reference) return [null, this.doc.id];
|
||||
if (!this.model.props.reference) return [null, this.store.id];
|
||||
const referenceId = this.model.props.reference;
|
||||
|
||||
const find = (doc: Store): [GfxModel | null, string] => {
|
||||
@@ -203,7 +203,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
};
|
||||
|
||||
// find current doc first
|
||||
let result = find(this.doc);
|
||||
let result = find(this.store);
|
||||
if (result[0]) return result;
|
||||
|
||||
for (const doc of this.std.workspace.docs.values()) {
|
||||
@@ -211,7 +211,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
if (result[0]) return result;
|
||||
}
|
||||
|
||||
return [null, this.doc.id];
|
||||
return [null, this.store.id];
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
@@ -220,7 +220,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
this._referencedModel =
|
||||
referencedModel && referencedModel.xywh ? referencedModel : null;
|
||||
// TODO(@L-Sun): clear query cache
|
||||
const doc = this.doc.workspace.getDoc(docId);
|
||||
const doc = this.store.workspace.getDoc(docId);
|
||||
this._previewDoc = doc?.getStore({ readonly: true }) ?? null;
|
||||
};
|
||||
|
||||
@@ -249,7 +249,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
|
||||
if (this._referencedModel instanceof GfxBlockElementModel) {
|
||||
this._disposables.add(
|
||||
this.doc.slots.blockUpdated.subscribe(({ type, id }) => {
|
||||
this.store.slots.blockUpdated.subscribe(({ type, id }) => {
|
||||
if (type === 'delete' && id === this.model.props.reference) {
|
||||
init();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user