refactor(editor): rename model.doc to store (#12172)

This commit is contained in:
Saul-Mirone
2025-05-07 09:17:01 +00:00
parent eb62d0e853
commit 95b9e4b3d0
95 changed files with 264 additions and 246 deletions

View File

@@ -42,7 +42,7 @@ import { downloadAttachmentBlob, refreshData } from './utils';
@Peekable({
enableOn: ({ model }: AttachmentBlockComponent) => {
return !model.doc.readonly && model.props.type.endsWith('pdf');
return !model.store.readonly && model.props.type.endsWith('pdf');
},
})
export class AttachmentBlockComponent extends CaptionedBlockComponent<AttachmentBlockModel> {

View File

@@ -41,7 +41,7 @@ export const RenameModal = ({
toast(editorHost, 'File name cannot be empty');
return;
}
model.doc.updateBlock(model, {
model.store.updateBlock(model, {
name: newFileName,
});
abort();

View File

@@ -18,7 +18,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
searchAlias: ['file'],
group: '4_Content & Media@3',
when: ({ model }) =>
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
model.store.schema.flavourSchemaMap.has('affine:attachment'),
action: ({ std, model }) => {
(async () => {
const file = await openFileOrFiles();
@@ -41,7 +41,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
},
group: '4_Content & Media@4',
when: ({ model }) =>
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
model.store.schema.flavourSchemaMap.has('affine:attachment'),
action: ({ std, model }) => {
(async () => {
const file = await openFileOrFiles();

View File

@@ -98,7 +98,7 @@ export class AttachmentEmbedService extends Extension {
convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
const config = this.values.find(config => config.check(model, maxFileSize));
if (!config?.action) {
model.doc.updateBlock(model, { embed: true });
model.store.updateBlock(model, { embed: true });
return;
}
config.action(model, this.std)?.catch(console.error);
@@ -129,7 +129,7 @@ const embedConfig: AttachmentEmbedConfig[] = [
{
name: 'image',
check: model =>
model.doc.schema.flavourSchemaMap.has('affine:image') &&
model.store.schema.flavourSchemaMap.has('affine:image') &&
model.props.type.startsWith('image/'),
async action(model, std) {
const component = std.view.getBlock(model.id);
@@ -189,7 +189,7 @@ const embedConfig: AttachmentEmbedConfig[] = [
* Turn the attachment block into an image block.
*/
async function turnIntoImageBlock(model: AttachmentBlockModel) {
if (!model.doc.schema.flavourSchemaMap.has('affine:image')) {
if (!model.store.schema.flavourSchemaMap.has('affine:image')) {
console.error('The image flavour is not supported!');
return;
}

View File

@@ -27,7 +27,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
const type = type$.peek();
if (!sourceId) return null;
const doc = model.doc;
const doc = model.store;
const blob = await doc.blobSync.get(sourceId);
if (!blob) return null;