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

@@ -13,12 +13,12 @@ export const convertToNumberedListCommand: Command<
> = (ctx, next) => {
const { std, id, order, stopCapturing = true } = ctx;
const host = std.host as EditorHost;
const doc = host.doc;
const doc = host.store;
const model = doc.getBlock(id)?.model;
if (!model || !model.text) return;
if (stopCapturing) host.doc.captureSync();
if (stopCapturing) host.store.captureSync();
const listConvertedId = toNumberedList(std, model, order);

View File

@@ -15,7 +15,7 @@ export const splitListCommand: Command<{
}> = (ctx, next) => {
const { blockId, inlineIndex, std } = ctx;
const host = std.host as EditorHost;
const doc = host.doc;
const doc = host.store;
const model = doc.getBlock(blockId)?.model;
if (!model || !matchModels(model, [ListBlockModel])) {

View File

@@ -39,22 +39,22 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
e.preventDefault();
if (this.model.props.type === 'toggle') {
if (this.doc.readonly) {
if (this.store.readonly) {
this._readonlyCollapsed = !this._readonlyCollapsed;
} else {
this.doc.captureSync();
this.doc.updateBlock(this.model, {
this.store.captureSync();
this.store.updateBlock(this.model, {
collapsed: !this.model.props.collapsed,
});
}
return;
} else if (this.model.props.type === 'todo') {
if (this.doc.readonly) return;
if (this.store.readonly) return;
this.doc.captureSync();
this.store.captureSync();
const checkedPropObj = { checked: !this.model.props.checked };
this.doc.updateBlock(this.model, checkedPropObj);
this.store.updateBlock(this.model, checkedPropObj);
if (this.model.props.checked) {
const checkEl = this.querySelector('.affine-list-block__todo-prefix');
if (checkEl) {
@@ -120,7 +120,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
const order = this.model.props.order$.value;
// old numbered list has no order
if (type === 'numbered' && !Number.isInteger(order)) {
correctNumberedListsOrderToPrev(this.doc, this.model, false);
correctNumberedListsOrderToPrev(this.store, this.model, false);
}
// if list is not numbered, order should be null
if (type !== 'numbered' && order !== null) {
@@ -138,7 +138,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
override renderBlock(): TemplateResult<1> {
const { model, _onClickIcon } = this;
const collapsed = this.doc.readonly
const collapsed = this.store.readonly
? this._readonlyCollapsed
: model.props.collapsed;
@@ -169,11 +169,11 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
<blocksuite-toggle-button
.collapsed=${collapsed}
.updateCollapsed=${(value: boolean) => {
if (this.doc.readonly) {
if (this.store.readonly) {
this._readonlyCollapsed = value;
} else {
this.doc.captureSync();
this.doc.updateBlock(this.model, {
this.store.captureSync();
this.store.updateBlock(this.model, {
collapsed: value,
});
}
@@ -185,12 +185,12 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
<rich-text
.yText=${this.model.props.text.yText}
.inlineEventSource=${this.topContenteditableElement ?? nothing}
.undoManager=${this.doc.history}
.undoManager=${this.store.history}
.attributeRenderer=${this.attributeRenderer}
.attributesSchema=${this.attributesSchema}
.markdownMatches=${this.inlineManager?.markdownMatches}
.embedChecker=${this.embedChecker}
.readonly=${this.doc.readonly}
.readonly=${this.store.readonly}
.inlineRangeProvider=${this._inlineRangeProvider}
.enableClipboard=${false}
.enableUndoRedo=${false}