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

@@ -46,10 +46,10 @@ export function insertEmbedCard(
if (blockId) {
const block = host.view.getBlock(blockId);
if (!block) return;
const parent = host.doc.getParent(block.model);
const parent = host.store.getParent(block.model);
if (!parent) return;
const index = parent.children.indexOf(block.model);
const cardId = host.doc.addBlock(
const cardId = host.store.addBlock(
flavour as never,
props,
parent,

View File

@@ -22,7 +22,7 @@ export const embedFigmaSlashMenuConfig: SlashMenuConfig = {
action: ({ std, model }) => {
(async () => {
const { host } = std;
const parentModel = host.doc.getParent(model);
const parentModel = host.store.getParent(model);
if (!parentModel) {
return;
}

View File

@@ -49,8 +49,8 @@ export class EmbedFigmaBlockComponent extends EmbedBlockComponent<EmbedFigmaMode
this._cardStyle = this.model.props.style;
if (!this.model.props.title) {
this.doc.withoutTransact(() => {
this.doc.updateBlock(this.model, {
this.store.withoutTransact(() => {
this.store.updateBlock(this.model, {
title: 'Figma',
});
});

View File

@@ -22,7 +22,7 @@ export const embedGithubSlashMenuConfig: SlashMenuConfig = {
action: ({ std, model }) => {
(async () => {
const { host } = std;
const parentModel = host.doc.getParent(model);
const parentModel = host.store.getParent(model);
if (!parentModel) {
return;
}

View File

@@ -83,12 +83,12 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
!this.model.props.repo ||
!this.model.props.githubId
) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
const url = this.model.props.url;
const urlMatch = url.match(githubUrlRegex);
if (urlMatch) {
const [, owner, repo, githubType, githubId] = urlMatch;
this.doc.updateBlock(this.model, {
this.store.updateBlock(this.model, {
owner,
repo,
githubType: githubType === 'issue' ? 'issue' : 'pr',
@@ -98,7 +98,7 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
});
}
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
if (!this.model.props.description && !this.model.props.title) {
this.refreshData();
} else {
@@ -132,7 +132,7 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
const loading = this.loading;
const theme = this.std.get(ThemeProvider).theme;
const imageProxyService = this.doc.get(ImageProxyService);
const imageProxyService = this.store.get(ImageProxyService);
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
const titleIcon = loading ? LoadingIcon : GithubIcon;
const statusIcon = status

View File

@@ -110,7 +110,7 @@ export async function refreshEmbedGithubUrlData(
if (signal?.aborted) return;
embedGithubElement.doc.updateBlock(embedGithubElement.model, {
embedGithubElement.store.updateBlock(embedGithubElement.model, {
image,
status,
statusReason,
@@ -144,7 +144,7 @@ export async function refreshEmbedGithubStatus(
if (!githubApiData.status || signal?.aborted) return;
embedGithubElement.doc.updateBlock(embedGithubElement.model, {
embedGithubElement.store.updateBlock(embedGithubElement.model, {
status: githubApiData.status,
statusReason: githubApiData.statusReason,
createdAt: githubApiData.createdAt,

View File

@@ -56,10 +56,10 @@ export const insertEmbedIframeWithUrlCommand: Command<
if (selectedBlockId) {
const block = host.view.getBlock(selectedBlockId);
if (!block) return;
const parent = host.doc.getParent(block.model);
const parent = host.store.getParent(block.model);
if (!parent) return;
const index = parent.children.indexOf(block.model);
newBlockId = host.doc.addBlock(flavour, props, parent, index + 1);
newBlockId = host.store.addBlock(flavour, props, parent, index + 1);
} else {
// When there is no selected block and in edgeless mode
// We should insert the embed iframe block to surface

View File

@@ -177,7 +177,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
// update model
const iframeUrl = this._getIframeUrl(embedData) ?? currentIframeUrl;
this.doc.updateBlock(this.model, {
this.store.updateBlock(this.model, {
iframeUrl,
title: embedData?.title || previewData?.title,
description: embedData?.description || previewData?.description,
@@ -373,7 +373,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
// if the iframe url is not set, refresh the data to get the iframe url
if (!this.model.props.iframeUrl) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
this.refreshData().catch(console.error);
});
} else {
@@ -452,7 +452,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
};
get readonly() {
return this.doc.readonly;
return this.store.readonly;
}
get selectionManager() {

View File

@@ -22,7 +22,7 @@ export const embedLoomSlashMenuConfig: SlashMenuConfig = {
action: ({ std, model }) => {
(async () => {
const { host } = std;
const parentModel = host.doc.getParent(model);
const parentModel = host.store.getParent(model);
if (!parentModel) {
return;
}

View File

@@ -60,12 +60,12 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
this._cardStyle = this.model.props.style;
if (!this.model.props.videoId) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
const url = this.model.props.url;
const urlMatch = url.match(loomUrlRegex);
if (urlMatch) {
const [, videoId] = urlMatch;
this.doc.updateBlock(this.model, {
this.store.updateBlock(this.model, {
videoId,
});
}
@@ -73,7 +73,7 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
}
if (!this.model.props.description && !this.model.props.title) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
this.refreshData();
});
}
@@ -93,7 +93,7 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
const loading = this.loading;
const theme = this.std.get(ThemeProvider).theme;
const imageProxyService = this.doc.get(ImageProxyService);
const imageProxyService = this.store.get(ImageProxyService);
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
const titleIcon = loading ? LoadingIcon : LoomIcon;
const titleText = loading ? 'Loading...' : title;

View File

@@ -62,7 +62,7 @@ export async function refreshEmbedLoomUrlData(
if (signal?.aborted) return;
embedLoomElement.doc.updateBlock(embedLoomElement.model, {
embedLoomElement.store.updateBlock(embedLoomElement.model, {
title,
description,
image,

View File

@@ -22,7 +22,7 @@ export const embedYoutubeSlashMenuConfig: SlashMenuConfig = {
action: ({ std, model }) => {
(async () => {
const { host } = std;
const parentModel = host.doc.getParent(model);
const parentModel = host.store.getParent(model);
if (!parentModel) {
return;
}

View File

@@ -63,12 +63,12 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
this._cardStyle = this.model.props.style;
if (!this.model.props.videoId) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
const url = this.model.props.url;
const urlMatch = url.match(youtubeUrlRegex);
if (urlMatch) {
const [, videoId] = urlMatch;
this.doc.updateBlock(this.model, {
this.store.updateBlock(this.model, {
videoId,
});
}
@@ -76,7 +76,7 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
}
if (!this.model.props.description && !this.model.props.title) {
this.doc.withoutTransact(() => {
this.store.withoutTransact(() => {
this.refreshData();
});
}
@@ -107,7 +107,7 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
const loading = this.loading;
const theme = this.std.get(ThemeProvider).theme;
const imageProxyService = this.doc.get(ImageProxyService);
const imageProxyService = this.store.get(ImageProxyService);
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
const titleIcon = loading ? LoadingIcon : YoutubeIcon;
const titleText = loading ? 'Loading...' : title;

View File

@@ -97,7 +97,7 @@ export async function refreshEmbedYoutubeUrlData(
if (signal?.aborted) return;
embedYoutubeElement.doc.updateBlock(embedYoutubeElement.model, {
embedYoutubeElement.store.updateBlock(embedYoutubeElement.model, {
image,
title,
description,