mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 18:41:52 +08: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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user