mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): rename model.doc to store (#12172)
This commit is contained in:
@@ -387,7 +387,7 @@ export function responseToExpandMindmap(host: EditorHost, ctx: AIContext) {
|
||||
|
||||
if (!subtree) return;
|
||||
|
||||
surface.doc.transact(() => {
|
||||
surface.store.transact(() => {
|
||||
const updateNodeSize = (node: typeof subtree) => {
|
||||
fitContent(node.element as ShapeElementModel);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { literal } from 'lit/static-html.js';
|
||||
|
||||
export const AIChatBlockSpec: ExtensionType[] = [
|
||||
BlockViewExtension('affine:embed-ai-chat', model => {
|
||||
const parent = model.doc.getParent(model.id);
|
||||
const parent = model.store.getParent(model.id);
|
||||
|
||||
if (parent?.flavour === 'affine:surface') {
|
||||
return literal`affine-edgeless-ai-chat`;
|
||||
|
||||
@@ -42,7 +42,7 @@ export class MindmapSurfaceBlock extends BlockComponent<SurfaceBlockModel> {
|
||||
}
|
||||
|
||||
private _adjustNodeWidth() {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.elementModels.forEach(element => {
|
||||
if (element.type === 'shape') {
|
||||
fitContent(element as ShapeElementModel);
|
||||
|
||||
@@ -74,7 +74,7 @@ export function PDFViewerEmbedded({ model }: AttachmentViewerProps) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
const peek = useCallback(() => {
|
||||
const target = model.doc.getBlock(model.id);
|
||||
const target = model.store.getBlock(model.id);
|
||||
if (!target) return;
|
||||
peekView.open({ element: target }).catch(console.error);
|
||||
}, [peekView, model]);
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
let blob = await doc.blobSync.get(sourceId);
|
||||
|
||||
if (blob) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function patchForPDFEmbedView(reactToLit: ReactToLit): ExtensionType {
|
||||
const bound = Bound.deserialize(model.props.xywh);
|
||||
bound.w = 537 + 24 + 2;
|
||||
bound.h = 759 + 46 + 24 + 2;
|
||||
model.doc.updateBlock(model, {
|
||||
model.store.updateBlock(model, {
|
||||
embed: true,
|
||||
style: 'pdf',
|
||||
xywh: bound.serialize(),
|
||||
|
||||
@@ -54,7 +54,7 @@ const ToggleButton = ({ model }: { model: EmbedSyncedDocModel }) => {
|
||||
}, [model.props.preFoldHeight$, model.xywh$]);
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
model.doc.captureSync();
|
||||
model.store.captureSync();
|
||||
|
||||
batch(() => {
|
||||
const { x, y, w, h } = model.elementBound;
|
||||
|
||||
@@ -55,7 +55,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
const dispose = selection.slots.updated.subscribe(() => {
|
||||
if (selection.has(note.id) && selection.editing) {
|
||||
note.doc.transact(() => {
|
||||
note.store.transact(() => {
|
||||
note.props.edgeless.collapse = false;
|
||||
});
|
||||
}
|
||||
@@ -68,7 +68,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
track.edgeless.pageBlock.headerToolbar.toggle({
|
||||
type: collapsed ? 'expand' : 'collapse',
|
||||
});
|
||||
note.doc.transact(() => {
|
||||
note.store.transact(() => {
|
||||
if (collapsed) {
|
||||
note.props.edgeless.collapse = false;
|
||||
} else {
|
||||
@@ -134,7 +134,7 @@ const PageBlockInfoButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
return (
|
||||
<DocInfoButton
|
||||
docId={note.doc.id}
|
||||
docId={note.store.id}
|
||||
trackFn={trackFn}
|
||||
data-testid="edgeless-note-info-button"
|
||||
/>
|
||||
@@ -148,7 +148,7 @@ const NoteCopyLinkButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
return (
|
||||
<CopyLinkButton
|
||||
pageId={note.doc.id}
|
||||
pageId={note.store.id}
|
||||
blockId={note.id}
|
||||
mode="edgeless"
|
||||
trackFn={trackFn}
|
||||
|
||||
@@ -26,11 +26,13 @@ export function patchForEdgelessNoteConfig(
|
||||
reactToLit(<EdgelessNoteHeader note={note} />),
|
||||
pageBlockTitle: ({ note }) => {
|
||||
const journalService = framework.get(JournalService);
|
||||
const isJournal = !!journalService.journalDate$(note.doc.id).value;
|
||||
const isJournal = !!journalService.journalDate$(note.store.id).value;
|
||||
if (isJournal) {
|
||||
return reactToLit(<BlocksuiteEditorJournalDocTitle page={note.doc} />);
|
||||
return reactToLit(
|
||||
<BlocksuiteEditorJournalDocTitle page={note.store} />
|
||||
);
|
||||
} else {
|
||||
return html`<doc-title .doc=${note.doc}></doc-title>`;
|
||||
return html`<doc-title .doc=${note.store}></doc-title>`;
|
||||
}
|
||||
},
|
||||
pageBlockViewportFitAnimation: insidePeekView
|
||||
|
||||
@@ -42,7 +42,7 @@ function createCopyLinkToBlockMenuItem(
|
||||
},
|
||||
select: () => {
|
||||
const serverService = framework.get(ServerService);
|
||||
const pageId = model.doc.id;
|
||||
const pageId = model.store.id;
|
||||
const { editor } = framework.get(EditorService);
|
||||
const mode = editor.mode$.value;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
computed(() => {
|
||||
// find the last transcription block
|
||||
for (const key of [...this.props.childMap.value.keys()].reverse()) {
|
||||
const block = this.props.doc.getBlock$(key);
|
||||
const block = this.props.store.getBlock$(key);
|
||||
if (block?.flavour === TranscriptionBlockFlavour) {
|
||||
return block.model as unknown as TranscriptionBlockModel;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
|
||||
if (!transcriptionBlockProps) {
|
||||
// transcription block is not created yet, we need to create it
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:transcription',
|
||||
{
|
||||
transcription: {},
|
||||
@@ -179,14 +179,14 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
title: string,
|
||||
collapsed: boolean = false
|
||||
) => {
|
||||
const calloutId = this.props.doc.addBlock(
|
||||
const calloutId = this.props.store.addBlock(
|
||||
'affine:callout',
|
||||
{
|
||||
emoji,
|
||||
},
|
||||
this.transcriptionBlock$.value?.id
|
||||
);
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
type: 'h6',
|
||||
@@ -223,7 +223,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
insert: ': ' + sanitizeText(segment.transcription),
|
||||
},
|
||||
];
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new Text(deltaInserts),
|
||||
@@ -238,7 +238,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
await insertFromMarkdown(
|
||||
undefined,
|
||||
summary,
|
||||
this.props.doc,
|
||||
this.props.store,
|
||||
calloutId,
|
||||
1
|
||||
);
|
||||
@@ -252,7 +252,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
await insertFromMarkdown(
|
||||
undefined,
|
||||
actions ?? '',
|
||||
this.props.doc,
|
||||
this.props.store,
|
||||
calloutId,
|
||||
1
|
||||
);
|
||||
|
||||
@@ -28,8 +28,8 @@ export class AudioAttachmentService extends Service {
|
||||
const key = attachmentBlockAudioMediaKey({
|
||||
blobId: model.props.sourceId,
|
||||
blockId: model.id,
|
||||
docId: model.doc.id,
|
||||
workspaceId: model.doc.rootDoc.guid,
|
||||
docId: model.store.id,
|
||||
workspaceId: model.store.rootDoc.guid,
|
||||
});
|
||||
let exists = this.pool.get(key);
|
||||
if (!exists) {
|
||||
|
||||
@@ -308,8 +308,8 @@ export class AudioMediaManagerService extends Service {
|
||||
key: attachmentBlockAudioMediaKey({
|
||||
blobId: input.props.sourceId,
|
||||
blockId: input.id,
|
||||
docId: input.doc.id,
|
||||
workspaceId: input.doc.rootDoc.guid,
|
||||
docId: input.store.id,
|
||||
workspaceId: input.store.rootDoc.guid,
|
||||
}),
|
||||
name: input.props.name,
|
||||
size: input.props.size,
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function downloadBlobToBuffer(model: AttachmentBlockModel) {
|
||||
throw new Error('Attachment not found');
|
||||
}
|
||||
|
||||
const blob = await model.doc.blobSync.get(sourceId);
|
||||
const blob = await model.store.blobSync.get(sourceId);
|
||||
if (!blob) {
|
||||
throw new Error('Attachment not found');
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
// refModel can be null if the reference is invalid
|
||||
if (refModel) {
|
||||
const docId =
|
||||
'doc' in refModel ? refModel.doc.id : refModel.surface.doc.id;
|
||||
'store' in refModel ? refModel.store.id : refModel.surface.store.id;
|
||||
return {
|
||||
type: 'doc',
|
||||
docRef: {
|
||||
@@ -179,7 +179,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'attachment',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
filetype: blockModel.props.type,
|
||||
},
|
||||
@@ -188,7 +188,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'image',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
},
|
||||
};
|
||||
@@ -196,7 +196,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'ai-chat-block',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
},
|
||||
model: blockModel,
|
||||
|
||||
@@ -362,7 +362,7 @@ const ImagePreviewModalImpl = ({
|
||||
index,
|
||||
url: blobUrl,
|
||||
caption: blockModel.props.caption,
|
||||
onDelete: !blockModel.doc.readonly
|
||||
onDelete: !blockModel.store.readonly
|
||||
? () => {
|
||||
handleDelete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user