mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 18:41:52 +08:00
refactor(editor): doc as store extension (#12170)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced new exports related to workspace management, making additional workspace features available. - **Refactor** - Updated how document and workspace types are imported and exported, consolidating and reorganizing module structure. - Shifted dependency management for document instances to use an internal provider mechanism. - Streamlined and centralized type imports across various modules. - **Bug Fixes** - Removed an unused schema definition to improve code clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -2,3 +2,4 @@ export * from './extension';
|
||||
export * from './schema';
|
||||
export * from './selection';
|
||||
export * from './store-extension';
|
||||
export * from './workspace';
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { createIdentifier } from '@blocksuite/global/di';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { Store, StoreOptions, YBlock } from '../../model';
|
||||
import type { AwarenessStore } from '../../yjs';
|
||||
import type { Workspace } from './workspace.js';
|
||||
import type { DocMeta } from './workspace-meta.js';
|
||||
|
||||
export type GetStoreOptions = Omit<StoreOptions, 'schema' | 'doc'>;
|
||||
export type RemoveStoreOptions = Pick<
|
||||
StoreOptions,
|
||||
'query' | 'id' | 'readonly'
|
||||
>;
|
||||
|
||||
export interface Doc {
|
||||
readonly id: string;
|
||||
get meta(): DocMeta | undefined;
|
||||
|
||||
remove(): void;
|
||||
load(initFn?: () => void): void;
|
||||
get ready(): boolean;
|
||||
dispose(): void;
|
||||
|
||||
clear(): void;
|
||||
getStore(options?: GetStoreOptions): Store;
|
||||
removeStore(options: RemoveStoreOptions): void;
|
||||
|
||||
get loaded(): boolean;
|
||||
get awarenessStore(): AwarenessStore;
|
||||
|
||||
get workspace(): Workspace;
|
||||
|
||||
get rootDoc(): Y.Doc;
|
||||
get spaceDoc(): Y.Doc;
|
||||
get yBlocks(): Y.Map<YBlock>;
|
||||
}
|
||||
|
||||
export const DocIdentifier = createIdentifier<Doc>('store-doc');
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './doc';
|
||||
export * from './workspace';
|
||||
export * from './workspace-meta';
|
||||
@@ -0,0 +1,46 @@
|
||||
import type { Subject } from 'rxjs';
|
||||
|
||||
export type Tag = {
|
||||
id: string;
|
||||
value: string;
|
||||
color: string;
|
||||
};
|
||||
export type DocsPropertiesMeta = {
|
||||
tags?: {
|
||||
options: Tag[];
|
||||
};
|
||||
};
|
||||
export interface DocMeta {
|
||||
id: string;
|
||||
title: string;
|
||||
tags: string[];
|
||||
createDate: number;
|
||||
updatedDate?: number;
|
||||
favorite?: boolean;
|
||||
}
|
||||
|
||||
export interface WorkspaceMeta {
|
||||
get docMetas(): DocMeta[];
|
||||
|
||||
addDocMeta(props: DocMeta, index?: number): void;
|
||||
getDocMeta(id: string): DocMeta | undefined;
|
||||
setDocMeta(id: string, props: Partial<DocMeta>): void;
|
||||
removeDocMeta(id: string): void;
|
||||
|
||||
get properties(): DocsPropertiesMeta;
|
||||
setProperties(meta: DocsPropertiesMeta): void;
|
||||
|
||||
get avatar(): string | undefined;
|
||||
setAvatar(avatar: string): void;
|
||||
|
||||
get name(): string | undefined;
|
||||
setName(name: string): void;
|
||||
|
||||
get docs(): unknown[] | undefined;
|
||||
initialize(): void;
|
||||
|
||||
commonFieldsUpdated: Subject<void>;
|
||||
docMetaAdded: Subject<string>;
|
||||
docMetaRemoved: Subject<string>;
|
||||
docMetaUpdated: Subject<void>;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { BlobEngine } from '@blocksuite/sync';
|
||||
import type { Subject } from 'rxjs';
|
||||
import type { Awareness } from 'y-protocols/awareness.js';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { IdGenerator } from '../../utils/id-generator';
|
||||
import type { Doc } from './doc.js';
|
||||
import type { WorkspaceMeta } from './workspace-meta.js';
|
||||
|
||||
export interface Workspace {
|
||||
readonly id: string;
|
||||
readonly meta: WorkspaceMeta;
|
||||
readonly idGenerator: IdGenerator;
|
||||
readonly blobSync: BlobEngine;
|
||||
readonly onLoadDoc?: (doc: Y.Doc) => void;
|
||||
readonly onLoadAwareness?: (awareness: Awareness) => void;
|
||||
|
||||
get doc(): Y.Doc;
|
||||
get docs(): Map<string, Doc>;
|
||||
|
||||
slots: {
|
||||
docListUpdated: Subject<void>;
|
||||
docCreated: Subject<string>;
|
||||
docRemoved: Subject<string>;
|
||||
};
|
||||
|
||||
createDoc(docId?: string): Doc;
|
||||
getDoc(docId: string): Doc | null;
|
||||
removeDoc(docId: string): void;
|
||||
|
||||
dispose(): void;
|
||||
}
|
||||
Reference in New Issue
Block a user