mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
refactor(editor): rename store api (#9518)
This commit is contained in:
@@ -195,7 +195,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
if (this._answers.length > 0) {
|
||||
const latestAnswer = this._answers.pop();
|
||||
this._answers = [];
|
||||
const schema = this.schema ?? this.host?.std.doc.collection.schema;
|
||||
const schema = this.schema ?? this.host?.std.doc.workspace.schema;
|
||||
let provider: ServiceProvider;
|
||||
if (this.host) {
|
||||
provider = this.host.std.provider;
|
||||
@@ -220,11 +220,11 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
)
|
||||
.then(doc => {
|
||||
this.disposeDoc();
|
||||
this._doc = doc.blockCollection.getDoc({
|
||||
this._doc = doc.doc.getBlocks({
|
||||
query: this._query,
|
||||
});
|
||||
this.disposables.add(() => {
|
||||
doc.blockCollection.clearQuery(this._query);
|
||||
doc.doc.clearQuery(this._query);
|
||||
});
|
||||
this._doc.readonly = true;
|
||||
this.requestUpdate();
|
||||
@@ -256,7 +256,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
private disposeDoc() {
|
||||
this._doc?.dispose();
|
||||
this._doc?.collection.dispose();
|
||||
this._doc?.workspace.dispose();
|
||||
}
|
||||
|
||||
override disconnectedCallback() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||
import type {
|
||||
EditorHost,
|
||||
TextRangePoint,
|
||||
@@ -80,15 +80,15 @@ export async function getContentFromSlice(
|
||||
type: 'markdown' | 'plain-text' = 'markdown'
|
||||
) {
|
||||
const job = new Job({
|
||||
schema: host.std.doc.collection.schema,
|
||||
blobCRUD: host.std.doc.collection.blobSync,
|
||||
schema: host.std.doc.workspace.schema,
|
||||
blobCRUD: host.std.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => host.std.doc.collection.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.collection.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.collection.removeDoc(id),
|
||||
create: (id: string) => host.std.doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.workspace.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [
|
||||
titleMiddleware(host.std.doc.collection.meta.docMetas),
|
||||
titleMiddleware(host.std.doc.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
],
|
||||
});
|
||||
@@ -110,14 +110,14 @@ export async function getContentFromSlice(
|
||||
|
||||
export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
||||
const job = new Job({
|
||||
schema: host.std.doc.collection.schema,
|
||||
blobCRUD: host.std.doc.collection.blobSync,
|
||||
schema: host.std.doc.workspace.schema,
|
||||
blobCRUD: host.std.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => host.std.doc.collection.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.collection.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.collection.removeDoc(id),
|
||||
create: (id: string) => host.std.doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.workspace.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [titleMiddleware(host.std.doc.collection.meta.docMetas)],
|
||||
middlewares: [titleMiddleware(host.std.doc.workspace.meta.docMetas)],
|
||||
});
|
||||
const snapshot = job.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
@@ -137,12 +137,12 @@ export const markdownToSnapshot = async (
|
||||
host: EditorHost
|
||||
) => {
|
||||
const job = new Job({
|
||||
schema: host.std.doc.collection.schema,
|
||||
blobCRUD: host.std.doc.collection.blobSync,
|
||||
schema: host.std.doc.workspace.schema,
|
||||
blobCRUD: host.std.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => host.std.doc.collection.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.collection.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.collection.removeDoc(id),
|
||||
create: (id: string) => host.std.doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => host.std.doc.workspace.getDoc(id),
|
||||
delete: (id: string) => host.std.doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
||||
});
|
||||
@@ -150,7 +150,7 @@ export const markdownToSnapshot = async (
|
||||
const payload = {
|
||||
file: markdown,
|
||||
assets: job.assetsManager,
|
||||
workspaceId: host.std.doc.collection.id,
|
||||
workspaceId: host.std.doc.workspace.id,
|
||||
pageId: host.std.doc.id,
|
||||
};
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ export async function constructRootChatBlockMessages(
|
||||
// Convert chat messages to AI chat block messages
|
||||
const userInfo = await AIProvider.userInfo;
|
||||
const forkMessages = await queryHistoryMessages(
|
||||
doc.collection.id,
|
||||
doc.workspace.id,
|
||||
doc.id,
|
||||
forkSessionId
|
||||
);
|
||||
@@ -171,7 +171,7 @@ function addAIChatBlock(
|
||||
messages: JSON.stringify(messages),
|
||||
index,
|
||||
sessionId,
|
||||
rootWorkspaceId: doc.collection.id,
|
||||
rootWorkspaceId: doc.workspace.id,
|
||||
rootDocId: doc.id,
|
||||
},
|
||||
surfaceBlock.id
|
||||
@@ -330,7 +330,7 @@ const SAVE_CHAT_TO_BLOCK_ACTION: ChatAction = {
|
||||
|
||||
try {
|
||||
const newSessionId = await AIProvider.forkChat?.({
|
||||
workspaceId: host.doc.collection.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
docId: host.doc.id,
|
||||
sessionId: parentSessionId,
|
||||
latestMessageId: messageId,
|
||||
@@ -425,7 +425,7 @@ const CREATE_AS_DOC = {
|
||||
toast: 'New doc created',
|
||||
handler: (host: EditorHost, content: string) => {
|
||||
reportResponse('result:add-page');
|
||||
const newDoc = host.doc.collection.createDoc();
|
||||
const newDoc = host.doc.workspace.createDoc();
|
||||
newDoc.load();
|
||||
const rootId = newDoc.addBlock('affine:page');
|
||||
newDoc.addBlock('affine:surface', {}, rootId);
|
||||
@@ -479,7 +479,7 @@ const CREATE_AS_LINKED_DOC = {
|
||||
}
|
||||
|
||||
// Create a new doc and add the content to it
|
||||
const newDoc = host.doc.collection.createDoc();
|
||||
const newDoc = host.doc.workspace.createDoc();
|
||||
newDoc.load();
|
||||
const rootId = newDoc.addBlock('affine:page');
|
||||
newDoc.addBlock('affine:surface', {}, rootId);
|
||||
|
||||
@@ -107,7 +107,7 @@ export function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
control,
|
||||
where,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.collection.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
} as Parameters<typeof action>[0];
|
||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||
stream = action(options);
|
||||
@@ -238,7 +238,7 @@ export function handleInlineAskAIAction(host: EditorHost) {
|
||||
where: 'inline-chat-panel',
|
||||
control: 'chat-send',
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.collection.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
});
|
||||
bindTextStream(stream, { update, finish, signal });
|
||||
})
|
||||
|
||||
@@ -189,7 +189,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
models,
|
||||
host,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.collection.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
} as Parameters<typeof action>[0];
|
||||
|
||||
const content = ctx.get().content;
|
||||
@@ -230,7 +230,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
control: 'format-bar',
|
||||
host,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.collection.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
} as Parameters<typeof action>[0];
|
||||
|
||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||
|
||||
@@ -488,7 +488,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
|
||||
input: content,
|
||||
docId: doc.id,
|
||||
attachments: images,
|
||||
workspaceId: doc.collection.id,
|
||||
workspaceId: doc.workspace.id,
|
||||
host: this.host,
|
||||
stream: true,
|
||||
signal: abortController.signal,
|
||||
@@ -519,7 +519,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
|
||||
const last = items[items.length - 1] as ChatMessage;
|
||||
if (!last.id) {
|
||||
const historyIds = await AIProvider.histories?.ids(
|
||||
doc.collection.id,
|
||||
doc.workspace.id,
|
||||
doc.id,
|
||||
{ sessionId: this.chatContextValue.chatSessionId }
|
||||
);
|
||||
|
||||
@@ -426,7 +426,7 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
||||
sessionId: chatSessionId,
|
||||
retry: true,
|
||||
docId: doc.id,
|
||||
workspaceId: doc.collection.id,
|
||||
workspaceId: doc.workspace.id,
|
||||
host: this.host,
|
||||
stream: true,
|
||||
signal: abortController.signal,
|
||||
|
||||
@@ -107,8 +107,8 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
||||
const { doc } = this;
|
||||
|
||||
const [histories, actions] = await Promise.all([
|
||||
AIProvider.histories?.chats(doc.collection.id, doc.id, { fork: false }),
|
||||
AIProvider.histories?.actions(doc.collection.id, doc.id),
|
||||
AIProvider.histories?.chats(doc.workspace.id, doc.id, { fork: false }),
|
||||
AIProvider.histories?.actions(doc.workspace.id, doc.id),
|
||||
]);
|
||||
|
||||
if (counter !== this._resettingCounter) return;
|
||||
@@ -175,7 +175,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
||||
cancelText: 'Cancel',
|
||||
})
|
||||
) {
|
||||
await AIProvider.histories?.cleanup(this.doc.collection.id, this.doc.id, [
|
||||
await AIProvider.histories?.cleanup(this.doc.workspace.id, this.doc.id, [
|
||||
this.chatContextValue.chatSessionId ?? '',
|
||||
...(
|
||||
this.chatContextValue.items.filter(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||
import { BlockStdScope, type EditorHost } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
type AffineAIPanelWidgetConfig,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace.js';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace.js';
|
||||
import { BlockStdScope, type EditorHost } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
MarkdownAdapter,
|
||||
@@ -239,12 +239,12 @@ export const markdownToMindmap = (
|
||||
) => {
|
||||
let result: Node | null = null;
|
||||
const job = new Job({
|
||||
schema: doc.collection.schema,
|
||||
blobCRUD: doc.collection.blobSync,
|
||||
schema: doc.workspace.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => doc.collection.createDoc({ id }),
|
||||
get: (id: string) => doc.collection.getDoc(id),
|
||||
delete: (id: string) => doc.collection.removeDoc(id),
|
||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id),
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const markdown = new MarkdownAdapter(job, provider);
|
||||
|
||||
@@ -403,7 +403,7 @@ export class ChatBlockInput extends LitElement {
|
||||
let chatSessionId = currentSessionId;
|
||||
if (!chatSessionId) {
|
||||
const forkSessionId = await AIProvider.forkChat?.({
|
||||
workspaceId: doc.collection.id,
|
||||
workspaceId: doc.workspace.id,
|
||||
docId: doc.id,
|
||||
sessionId: this.parentSessionId,
|
||||
latestMessageId: this.latestMessageId,
|
||||
@@ -421,7 +421,7 @@ export class ChatBlockInput extends LitElement {
|
||||
sessionId: chatSessionId,
|
||||
docId: doc.id,
|
||||
attachments: images,
|
||||
workspaceId: doc.collection.id,
|
||||
workspaceId: doc.workspace.id,
|
||||
host: this.host,
|
||||
stream: true,
|
||||
signal: abortController.signal,
|
||||
|
||||
@@ -269,7 +269,7 @@ export class AIChatBlockPeekView extends LitElement {
|
||||
) {
|
||||
const { doc } = this.host;
|
||||
if (currentSessionId) {
|
||||
await AIProvider.histories?.cleanup(doc.collection.id, doc.id, [
|
||||
await AIProvider.histories?.cleanup(doc.workspace.id, doc.id, [
|
||||
currentSessionId,
|
||||
]);
|
||||
}
|
||||
@@ -323,7 +323,7 @@ export class AIChatBlockPeekView extends LitElement {
|
||||
sessionId: currentSessionId,
|
||||
retry: true,
|
||||
docId: doc.id,
|
||||
workspaceId: doc.collection.id,
|
||||
workspaceId: doc.workspace.id,
|
||||
host: this.host,
|
||||
stream: true,
|
||||
signal: abortController.signal,
|
||||
|
||||
@@ -155,6 +155,6 @@ export const copyText = async (host: EditorHost, text: string) => {
|
||||
const slice = Slice.fromModels(previewDoc, models);
|
||||
await host.std.clipboard.copySlice(slice);
|
||||
previewDoc.dispose();
|
||||
previewDoc.collection.dispose();
|
||||
previewDoc.workspace.dispose();
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useDocMetaHelper } from '@affine/core/components/hooks/use-block-suite-
|
||||
import { useDocCollectionPage } from '@affine/core/components/hooks/use-block-suite-workspace-page';
|
||||
import { FetchService, GraphQLService } from '@affine/core/modules/cloud';
|
||||
import { getAFFiNEWorkspaceSchema } from '@affine/core/modules/workspace';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { ListHistoryQuery } from '@affine/graphql';
|
||||
import { listHistoryQuery, recoverDocMutation } from '@affine/graphql';
|
||||
|
||||
@@ -41,7 +41,7 @@ const BlockSuiteEditorImpl = ({
|
||||
}: EditorProps) => {
|
||||
useEffect(() => {
|
||||
const disposable = page.slots.blockUpdated.once(() => {
|
||||
page.collection.meta.setDocMeta(page.id, {
|
||||
page.workspace.meta.setDocMeta(page.id, {
|
||||
updatedDate: Date.now(),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,16 +59,16 @@ async function exportDoc(
|
||||
config: AdapterConfig
|
||||
) {
|
||||
const job = new Job({
|
||||
schema: doc.collection.schema,
|
||||
blobCRUD: doc.collection.blobSync,
|
||||
schema: doc.workspace.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => doc.collection.createDoc({ id }),
|
||||
get: (id: string) => doc.collection.getDoc(id),
|
||||
delete: (id: string) => doc.collection.removeDoc(id),
|
||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id),
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [
|
||||
docLinkBaseURLMiddleware(doc.collection.id),
|
||||
titleMiddleware(doc.collection.meta.docMetas),
|
||||
docLinkBaseURLMiddleware(doc.workspace.id),
|
||||
titleMiddleware(doc.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
],
|
||||
});
|
||||
@@ -148,7 +148,7 @@ async function exportHandler({
|
||||
await exportToMarkdown(page, editorRoot?.std);
|
||||
return;
|
||||
case 'snapshot':
|
||||
await ZipTransformer.exportDocs(page.collection, [page]);
|
||||
await ZipTransformer.exportDocs(page.workspace, [page]);
|
||||
return;
|
||||
case 'pdf':
|
||||
await printToPdf(editorContainer);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
||||
import type { Blocks, DocSnapshot } from '@blocksuite/affine/store';
|
||||
import { Job, Schema } from '@blocksuite/affine/store';
|
||||
|
||||
@@ -265,7 +265,7 @@ const WorkspacePage = ({ meta }: { meta: WorkspaceMetadata }) => {
|
||||
workspace.docCollection,
|
||||
Array.from(workspace.docCollection.docs.values())
|
||||
.filter(doc => (docs ? docs.includes(doc.id) : true))
|
||||
.map(doc => doc.getDoc())
|
||||
.map(doc => doc.getBlocks())
|
||||
);
|
||||
};
|
||||
window.importWorkspaceSnapshot = async () => {
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
} from 'yjs';
|
||||
|
||||
import { getAFFiNEWorkspaceSchema } from '../../workspace/global-schema';
|
||||
import { WorkspaceImpl } from '../../workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '../../workspace/impls/workspace';
|
||||
import type { BlockIndexSchema, DocIndexSchema } from '../schema';
|
||||
import type {
|
||||
WorkerIngoingMessage,
|
||||
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
type WorkspaceMetadata,
|
||||
type WorkspaceProfileInfo,
|
||||
} from '../../workspace';
|
||||
import { WorkspaceImpl } from '../../workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '../../workspace/impls/workspace';
|
||||
import type { WorkspaceEngineStorageProvider } from '../providers/engine';
|
||||
import { BroadcastChannelAwarenessConnection } from './engine/awareness-broadcast-channel';
|
||||
import { CloudAwarenessConnection } from './engine/awareness-cloud';
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
type WorkspaceMetadata,
|
||||
type WorkspaceProfileInfo,
|
||||
} from '../../workspace';
|
||||
import { WorkspaceImpl } from '../../workspace/impl/workspace';
|
||||
import { WorkspaceImpl } from '../../workspace/impls/workspace';
|
||||
import type { WorkspaceEngineStorageProvider } from '../providers/engine';
|
||||
import { BroadcastChannelAwarenessConnection } from './engine/awareness-broadcast-channel';
|
||||
import { StaticBlobStorage } from './engine/blob-static';
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Awareness } from 'y-protocols/awareness.js';
|
||||
|
||||
import { WorkspaceDBService } from '../../db';
|
||||
import { getAFFiNEWorkspaceSchema } from '../global-schema';
|
||||
import { WorkspaceImpl } from '../impl/workspace';
|
||||
import { WorkspaceImpl } from '../impls/workspace';
|
||||
import type { WorkspaceScope } from '../scopes/workspace';
|
||||
import { WorkspaceEngineService } from '../services/engine';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
Blocks,
|
||||
type BlockSuiteDoc,
|
||||
type Doc,
|
||||
type GetDocOptions,
|
||||
type GetBlocksOptions,
|
||||
type Query,
|
||||
type Workspace,
|
||||
type YBlock,
|
||||
@@ -128,7 +128,7 @@ export class DocImpl implements Doc {
|
||||
};
|
||||
|
||||
get blobSync() {
|
||||
return this.collection.blobSync;
|
||||
return this.workspace.blobSync;
|
||||
}
|
||||
|
||||
get canRedo() {
|
||||
@@ -139,12 +139,12 @@ export class DocImpl implements Doc {
|
||||
return this._canUndo.peek();
|
||||
}
|
||||
|
||||
get collection() {
|
||||
get workspace() {
|
||||
return this._collection;
|
||||
}
|
||||
|
||||
get docSync() {
|
||||
return this.collection.docSync;
|
||||
return this.workspace.docSync;
|
||||
}
|
||||
|
||||
get history() {
|
||||
@@ -160,7 +160,7 @@ export class DocImpl implements Doc {
|
||||
}
|
||||
|
||||
get meta() {
|
||||
return this.collection.meta.getDocMeta(this.id);
|
||||
return this.workspace.meta.getDocMeta(this.id);
|
||||
}
|
||||
|
||||
get readonly(): boolean {
|
||||
@@ -172,7 +172,7 @@ export class DocImpl implements Doc {
|
||||
}
|
||||
|
||||
get schema() {
|
||||
return this.collection.schema;
|
||||
return this.workspace.schema;
|
||||
}
|
||||
|
||||
get spaceDoc() {
|
||||
@@ -200,8 +200,8 @@ export class DocImpl implements Doc {
|
||||
|
||||
private _handleVersion() {
|
||||
// Initialization from empty yDoc, indicating that the document is new.
|
||||
if (!this.collection.meta.hasVersion) {
|
||||
this.collection.meta.writeVersion(this.collection);
|
||||
if (!this.workspace.meta.hasVersion) {
|
||||
this.workspace.meta.writeVersion(this.workspace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ export class DocImpl implements Doc {
|
||||
}
|
||||
}
|
||||
|
||||
getDoc({ readonly, query }: GetDocOptions = {}) {
|
||||
getBlocks({ readonly, query }: GetBlocksOptions = {}) {
|
||||
const readonlyKey = this._getReadonlyKey(readonly);
|
||||
|
||||
const key = JSON.stringify(query);
|
||||
@@ -290,7 +290,7 @@ export class DocImpl implements Doc {
|
||||
|
||||
const doc = new Blocks({
|
||||
blockCollection: this,
|
||||
schema: this.collection.schema,
|
||||
schema: this.workspace.schema,
|
||||
readonly,
|
||||
query,
|
||||
});
|
||||
@@ -307,7 +307,7 @@ export class DocImpl implements Doc {
|
||||
|
||||
this._ySpaceDoc.load();
|
||||
|
||||
if ((this.collection.meta.docs?.length ?? 0) <= 1) {
|
||||
if ((this.workspace.meta.docs?.length ?? 0) <= 1) {
|
||||
this._handleVersion();
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@ import {
|
||||
AwarenessStore,
|
||||
type Blocks,
|
||||
BlockSuiteDoc,
|
||||
type CreateDocOptions,
|
||||
type CreateBlocksOptions,
|
||||
type Doc,
|
||||
DocCollectionMeta,
|
||||
type GetDocOptions,
|
||||
type GetBlocksOptions,
|
||||
type IdGenerator,
|
||||
nanoid,
|
||||
type Schema,
|
||||
type Workspace,
|
||||
type WorkspaceMeta,
|
||||
} from '@blocksuite/affine/store';
|
||||
import {
|
||||
AwarenessEngine,
|
||||
@@ -74,7 +75,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
|
||||
readonly idGenerator: IdGenerator;
|
||||
|
||||
meta: DocCollectionMeta;
|
||||
meta: WorkspaceMeta;
|
||||
|
||||
slots = {
|
||||
docListUpdated: new Slot(),
|
||||
@@ -153,7 +154,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
* If the `init` parameter is passed, a `surface`, `note`, and `paragraph` block
|
||||
* will be created in the doc simultaneously.
|
||||
*/
|
||||
createDoc(options: CreateDocOptions = {}) {
|
||||
createDoc(options: CreateBlocksOptions = {}) {
|
||||
const { id: docId = this.idGenerator(), query, readonly } = options;
|
||||
if (this._hasDoc(docId)) {
|
||||
throw new BlockSuiteError(
|
||||
@@ -191,9 +192,9 @@ export class WorkspaceImpl implements Workspace {
|
||||
return space ?? null;
|
||||
}
|
||||
|
||||
getDoc(docId: string, options?: GetDocOptions): Blocks | null {
|
||||
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
|
||||
const collection = this.getBlockCollection(docId);
|
||||
return collection?.getDoc(options) ?? null;
|
||||
return collection?.getBlocks(options) ?? null;
|
||||
}
|
||||
|
||||
removeDoc(docId: string) {
|
||||
Reference in New Issue
Block a user