mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
refactor(editor): reduce dependency to doc collection (#9492)
This commit is contained in:
@@ -16,7 +16,8 @@ import {
|
||||
uploadBlobForImage,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Bound, getCommonBound } from '@blocksuite/affine/global/utils';
|
||||
import { type BlockProps, DocCollection, Text } from '@blocksuite/affine/store';
|
||||
import { type BlockProps, Text } from '@blocksuite/affine/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { getAIPanelWidget } from '../utils/ai-widgets';
|
||||
import type { AffineNode, AIContext } from '../utils/context';
|
||||
@@ -262,7 +263,7 @@ function addSurfaceRefBlock(host: EditorHost, bound: Bound, place: Place) {
|
||||
const frame = host.doc.addBlock(
|
||||
'affine:frame',
|
||||
{
|
||||
title: new Text(new DocCollection.Y.Text('Frame')),
|
||||
title: new Text(new Y.Text('Frame')),
|
||||
xywh: bound.serialize(),
|
||||
index: LayerManager.INITIAL_INDEX,
|
||||
},
|
||||
|
||||
@@ -41,7 +41,7 @@ const BlockSuiteEditorImpl = ({
|
||||
}: EditorProps) => {
|
||||
useEffect(() => {
|
||||
const disposable = page.slots.blockUpdated.once(() => {
|
||||
page.collection.setDocMeta(page.id, {
|
||||
page.collection.meta.setDocMeta(page.id, {
|
||||
updatedDate: Date.now(),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
useParams,
|
||||
useSearchParams,
|
||||
} from 'react-router-dom';
|
||||
import * as _Y from 'yjs';
|
||||
|
||||
import { AffineErrorBoundary } from '../../../components/affine/affine-error-boundary';
|
||||
import { WorkbenchRoot } from '../../../modules/workbench';
|
||||
@@ -46,11 +47,15 @@ declare global {
|
||||
var exportWorkspaceSnapshot: (docs?: string[]) => Promise<void>;
|
||||
// oxlint-disable-next-line no-var
|
||||
var importWorkspaceSnapshot: () => Promise<void>;
|
||||
// oxlint-disable-next-line no-var
|
||||
var Y: typeof _Y;
|
||||
interface WindowEventMap {
|
||||
'affine:workspace:change': CustomEvent<{ id: string }>;
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.Y = _Y;
|
||||
|
||||
export const Component = (): ReactElement => {
|
||||
const {
|
||||
workspacesService,
|
||||
|
||||
@@ -128,7 +128,7 @@ export class DocsStore extends Store {
|
||||
}
|
||||
|
||||
setDocMeta(id: string, meta: Partial<DocMeta>) {
|
||||
this.workspaceService.workspace.docCollection.setDocMeta(id, meta);
|
||||
this.workspaceService.workspace.docCollection.meta.setDocMeta(id, meta);
|
||||
}
|
||||
|
||||
setDocPrimaryModeSetting(id: string, mode: DocMode) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// the adapter is to bridge the workspace rootdoc & native js bindings
|
||||
import type { WorkspaceService } from '@affine/core/modules/workspace';
|
||||
import { createYProxy, type Y } from '@blocksuite/affine/store';
|
||||
import { createYProxy } from '@blocksuite/affine/store';
|
||||
import { LiveData, Service } from '@toeverything/infra';
|
||||
import { defaultsDeep } from 'lodash-es';
|
||||
import { Observable } from 'rxjs';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { FavoriteSupportTypeUnion } from '../../constant';
|
||||
import type { FavoriteService } from '../favorite';
|
||||
|
||||
@@ -86,7 +86,7 @@ export class TagStore extends Store {
|
||||
};
|
||||
|
||||
updatePageTags = (pageId: string, tags: string[]) => {
|
||||
this.workspaceService.workspace.docCollection.setDocMeta(pageId, {
|
||||
this.workspaceService.workspace.docCollection.meta.setDocMeta(pageId, {
|
||||
tags,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user