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
@@ -73,7 +73,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
flavour: 'affine:list',
@@ -93,7 +93,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
flavour: ['affine:list', 'affine:code'],
@@ -114,7 +114,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
role: 'content',
flavour: 'affine:list',
@@ -153,7 +153,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
role: 'hub',
@@ -173,7 +173,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
role: 'hub',
@@ -193,7 +193,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
flavour: 'affine:list',
@@ -217,7 +217,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-2')?.model;
const note = host.store.getBlock('note-2')?.model;
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
role: 'content',
@@ -73,7 +73,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
flavour: 'affine:list',
@@ -93,7 +93,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
flavour: ['affine:list', 'affine:code'],
@@ -114,7 +114,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
role: 'content',
flavour: 'affine:list',
@@ -153,7 +153,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
role: 'hub',
@@ -173,7 +173,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
role: 'hub',
@@ -193,7 +193,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-1')?.model;
const note = host.store.getBlock('note-1')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
flavour: 'affine:list',
@@ -217,7 +217,7 @@ describe('commands/block-crud', () => {
</affine-page>
`;
const note = host.doc.getBlock('note-2')?.model;
const note = host.store.getBlock('note-2')?.model;
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
role: 'content',
@@ -12,17 +12,17 @@ describe('helpers/affine-template', () => {
</affine-page>
`;
expect(host.doc).toBeDefined();
expect(host.store).toBeDefined();
const pageBlock = host.doc.getBlock('page');
const pageBlock = host.store.getBlock('page');
expect(pageBlock).toBeDefined();
expect(pageBlock?.flavour).toBe('affine:page');
const noteBlock = host.doc.getBlock('note');
const noteBlock = host.store.getBlock('note');
expect(noteBlock).toBeDefined();
expect(noteBlock?.flavour).toBe('affine:note');
const paragraphBlock = host.doc.getBlock('paragraph-1');
const paragraphBlock = host.store.getBlock('paragraph-1');
expect(paragraphBlock).toBeDefined();
expect(paragraphBlock?.flavour).toBe('affine:paragraph');
});
@@ -38,16 +38,17 @@ describe('helpers/affine-template', () => {
</affine-page>
`;
const noteBlocks = host.doc.getBlocksByFlavour('affine:note');
const paragraphBlocks = host.doc.getBlocksByFlavour('affine:paragraph');
const listBlocks = host.doc.getBlocksByFlavour('affine:list');
const noteBlocks = host.store.getBlocksByFlavour('affine:note');
const paragraphBlocks = host.store.getBlocksByFlavour('affine:paragraph');
const listBlocks = host.store.getBlocksByFlavour('affine:list');
expect(noteBlocks.length).toBe(1);
expect(paragraphBlocks.length).toBe(2);
expect(listBlocks.length).toBe(1);
const noteBlock = noteBlocks[0];
const noteChildren = host.doc.getBlock(noteBlock.id)?.model.children || [];
const noteChildren =
host.store.getBlock(noteBlock.id)?.model.children || [];
expect(noteChildren.length).toBe(3);
expect(noteChildren[0].flavour).toBe('affine:paragraph');
@@ -64,10 +65,10 @@ describe('helpers/affine-template', () => {
</affine-page>
`;
const paragraphBlocks = host.doc.getBlocksByFlavour('affine:paragraph');
const paragraphBlocks = host.store.getBlocksByFlavour('affine:paragraph');
expect(paragraphBlocks.length).toBe(1);
const paragraphBlock = host.doc.getBlock(paragraphBlocks[0].id);
const paragraphBlock = host.store.getBlock(paragraphBlocks[0].id);
const paragraphText = paragraphBlock?.model.text?.toString() || '';
expect(paragraphText).toBe('');
});
@@ -229,10 +229,10 @@ export function createTestHost(doc: Store): EditorHost {
};
const host = {
doc: doc,
store: doc,
std: std as any,
};
host.doc = doc;
host.store = doc;
host.std = std as any;
std.host = host;
@@ -23,7 +23,7 @@ export const getFirstBlockCommand: Command<
firstBlock: BlockModel | null;
}
> = (ctx, next) => {
const root = ctx.root || ctx.std.host.doc.root;
const root = ctx.root || ctx.std.host.store.root;
if (!root) {
next({
firstBlock: null,
@@ -23,7 +23,7 @@ export const getLastBlockCommand: Command<
lastBlock: BlockModel | null;
}
> = (ctx, next) => {
const root = ctx.root || ctx.std.host.doc.root;
const root = ctx.root || ctx.std.host.store.root;
if (!root) {
next({
lastBlock: null,