mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 01:26:37 +08:00
chore: bump bs (#8227)
This commit is contained in:
+1
-3
@@ -42,7 +42,7 @@ const processTypeToPromptName = new Map(
|
||||
})
|
||||
);
|
||||
|
||||
function setupAIProvider() {
|
||||
export function setupAIProvider() {
|
||||
// a single workspace should have only a single chat session
|
||||
// user-id:workspace-id:doc-id -> chat session id
|
||||
const chatSessions = new Map<string, Promise<string>>();
|
||||
@@ -490,5 +490,3 @@ Could you make a new website based on these notes and send back just the html fi
|
||||
|
||||
setupTracker();
|
||||
}
|
||||
|
||||
setupAIProvider();
|
||||
|
||||
-39
@@ -1,4 +1,3 @@
|
||||
import type { ReferenceInfo } from '@blocksuite/affine-model';
|
||||
import type { DocMode } from '@blocksuite/blocks';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
@@ -21,21 +20,6 @@ import {
|
||||
import { BlocksuiteDocEditor, BlocksuiteEdgelessEditor } from './lit-adaper';
|
||||
import * as styles from './styles.css';
|
||||
|
||||
// copy forwardSlot from blocksuite, but it seems we need to dispose the pipe
|
||||
// after the component is unmounted right?
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function forwardSlot<T extends Record<string, Slot<any>>>(
|
||||
from: T,
|
||||
to: Partial<T>
|
||||
) {
|
||||
Object.entries(from).forEach(([key, slot]) => {
|
||||
const target = to[key];
|
||||
if (target) {
|
||||
slot.pipe(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
interface BlocksuiteEditorContainerProps {
|
||||
page: Doc;
|
||||
mode: DocMode;
|
||||
@@ -65,38 +49,15 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
|
||||
const slots: BlocksuiteEditorContainerRef['slots'] = useMemo(() => {
|
||||
return {
|
||||
docLinkClicked: new Slot<ReferenceInfo>(),
|
||||
editorModeSwitched: new Slot(),
|
||||
docUpdated: new Slot(),
|
||||
tagClicked: new Slot(),
|
||||
};
|
||||
}, []);
|
||||
|
||||
// forward the slot to the webcomponent
|
||||
useLayoutEffect(() => {
|
||||
requestAnimationFrame(() => {
|
||||
const docPage = rootRef.current?.querySelector('affine-page-root');
|
||||
const edgelessPage = rootRef.current?.querySelector(
|
||||
'affine-edgeless-root'
|
||||
);
|
||||
if (docPage) {
|
||||
forwardSlot(docPage.slots, slots);
|
||||
}
|
||||
|
||||
if (edgelessPage) {
|
||||
forwardSlot(edgelessPage.slots, slots);
|
||||
}
|
||||
});
|
||||
}, [page, slots]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
slots.docUpdated.emit({ newDocId: page.id });
|
||||
}, [page, slots.docUpdated]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
slots.editorModeSwitched.emit(mode);
|
||||
}, [mode, slots.editorModeSwitched]);
|
||||
|
||||
/**
|
||||
* mimic an AffineEditorContainer using proxy
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
export * from './blocksuite-editor';
|
||||
export { getFontConfigExtension } from './specs/font-extension';
|
||||
|
||||
import './ai/setup-provider';
|
||||
import './specs/preview';
|
||||
import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
||||
import { effects as presetsEffects } from '@blocksuite/presets/effects';
|
||||
|
||||
import { setupAIProvider } from './ai/setup-provider';
|
||||
import { effects as patchEffects } from './specs/preview';
|
||||
|
||||
blocksEffects();
|
||||
presetsEffects();
|
||||
patchEffects();
|
||||
setupAIProvider();
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
patchEdgelessClipboard,
|
||||
patchForSharedPage,
|
||||
patchNotificationService,
|
||||
patchParseDocUrlExtension,
|
||||
patchPeekViewService,
|
||||
patchQuickSearchService,
|
||||
patchReferenceRenderer,
|
||||
@@ -118,9 +119,8 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
||||
patched = patched.concat(patchNotificationService(confirmModal));
|
||||
patched = patched.concat(patchPeekViewService(peekViewService));
|
||||
patched = patched.concat(patchEdgelessClipboard());
|
||||
if (!page.readonly) {
|
||||
patched = patched.concat(patchQuickSearchService(framework));
|
||||
}
|
||||
patched = patched.concat(patchParseDocUrlExtension(framework));
|
||||
patched = patched.concat(patchQuickSearchService(framework));
|
||||
if (shared) {
|
||||
patched = patched.concat(patchForSharedPage());
|
||||
}
|
||||
@@ -134,7 +134,6 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
||||
docsService,
|
||||
editorService,
|
||||
framework,
|
||||
page.readonly,
|
||||
peekViewService,
|
||||
reactToLit,
|
||||
referenceRenderer,
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
LatexBlockSpec,
|
||||
ListBlockSpec,
|
||||
ParagraphBlockSpec,
|
||||
RefNodeSlotsExtension,
|
||||
RichTextExtensions,
|
||||
} from '@blocksuite/blocks';
|
||||
import { AIChatBlockSpec } from '@blocksuite/presets';
|
||||
@@ -29,6 +30,7 @@ import { AIChatBlockSpec } from '@blocksuite/presets';
|
||||
import { CustomAttachmentBlockSpec } from './custom/attachment-block';
|
||||
|
||||
const CommonBlockSpecs: ExtensionType[] = [
|
||||
RefNodeSlotsExtension(),
|
||||
EditPropsStore,
|
||||
RichTextExtensions,
|
||||
LatexBlockSpec,
|
||||
|
||||
+97
-106
@@ -8,7 +8,6 @@ import {
|
||||
type useConfirmModal,
|
||||
} from '@affine/component';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { DocsSearchService } from '@affine/core/modules/docs-search';
|
||||
import type { EditorService } from '@affine/core/modules/editor';
|
||||
import { resolveLinkToDoc } from '@affine/core/modules/navigation';
|
||||
import type { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
QuickSearchService,
|
||||
RecentDocsQuickSearchSession,
|
||||
} from '@affine/core/modules/quicksearch';
|
||||
import { ExternalLinksQuickSearchSession } from '@affine/core/modules/quicksearch/impls/external-links';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import {
|
||||
type BlockService,
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
EmbedLinkedDocBlockComponent,
|
||||
EmbedOptionProvider,
|
||||
NotificationExtension,
|
||||
ParseDocUrlExtension,
|
||||
PeekViewExtension,
|
||||
QuickSearchExtension,
|
||||
QuickSearchProvider,
|
||||
@@ -54,6 +55,7 @@ import {
|
||||
type DocService,
|
||||
DocsService,
|
||||
type FrameworkProvider,
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import { type TemplateResult } from 'lit';
|
||||
import { customElement } from 'lit/decorators.js';
|
||||
@@ -282,109 +284,84 @@ export function patchDocModeService(
|
||||
|
||||
export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
const QuickSearch = QuickSearchExtension({
|
||||
async searchDoc(options) {
|
||||
async openQuickSearch() {
|
||||
let searchResult: QuickSearchResult = null;
|
||||
if (options.skipSelection) {
|
||||
const query = options.userInput;
|
||||
if (!query) {
|
||||
logger.error('No user input provided');
|
||||
} else {
|
||||
const resolvedDoc = resolveLinkToDoc(query);
|
||||
if (resolvedDoc) {
|
||||
searchResult = {
|
||||
docId: resolvedDoc.docId,
|
||||
};
|
||||
} else if (
|
||||
query.startsWith('http://') ||
|
||||
query.startsWith('https://')
|
||||
) {
|
||||
searchResult = {
|
||||
userInput: query,
|
||||
};
|
||||
} else {
|
||||
const searchedDoc = (
|
||||
await framework.get(DocsSearchService).search(query)
|
||||
).at(0);
|
||||
if (searchedDoc) {
|
||||
searchResult = {
|
||||
docId: searchedDoc.docId,
|
||||
};
|
||||
searchResult = await new Promise(resolve =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
framework.get(CreationQuickSearchSession),
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(LinksQuickSearchSession),
|
||||
framework.get(ExternalLinksQuickSearchSession),
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
searchResult = await new Promise(resolve =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
framework.get(CreationQuickSearchSession),
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(LinksQuickSearchSession),
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'docs') {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (result.source === 'docs') {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'recent-doc') {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (result.source === 'recent-doc') {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'link') {
|
||||
if (result.payload.external) {
|
||||
const userInput = result.payload.external.url;
|
||||
resolve({ userInput });
|
||||
return;
|
||||
}
|
||||
if (result.source === 'link') {
|
||||
const { docId, blockIds, elementIds, mode } = result.payload;
|
||||
resolve({
|
||||
docId,
|
||||
params: {
|
||||
blockIds,
|
||||
elementIds,
|
||||
mode,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.payload.internal) {
|
||||
const { docId, params } = result.payload.internal;
|
||||
resolve({ docId, params });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (result.source === 'external-link') {
|
||||
const externalUrl = result.payload.url;
|
||||
resolve({ externalUrl });
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'creation') {
|
||||
const docsService = framework.get(DocsService);
|
||||
const mode =
|
||||
result.id === 'creation:create-edgeless'
|
||||
? 'edgeless'
|
||||
: 'page';
|
||||
const newDoc = docsService.createDoc({
|
||||
primaryMode: mode,
|
||||
title: result.payload.title,
|
||||
});
|
||||
if (result.source === 'creation') {
|
||||
const docsService = framework.get(DocsService);
|
||||
const mode =
|
||||
result.id === 'creation:create-edgeless' ? 'edgeless' : 'page';
|
||||
const newDoc = docsService.createDoc({
|
||||
primaryMode: mode,
|
||||
title: result.payload.title,
|
||||
});
|
||||
track.doc.editor.quickSearch.createDoc({
|
||||
mode,
|
||||
});
|
||||
|
||||
resolve({
|
||||
docId: newDoc.id,
|
||||
isNewDoc: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
resolve({
|
||||
docId: newDoc.id,
|
||||
});
|
||||
return;
|
||||
}
|
||||
},
|
||||
{
|
||||
label: {
|
||||
key: 'com.affine.cmdk.insert-links',
|
||||
},
|
||||
{
|
||||
defaultQuery: options.userInput,
|
||||
label: {
|
||||
key: 'com.affine.cmdk.insert-links',
|
||||
},
|
||||
placeholder: {
|
||||
key: 'com.affine.cmdk.docs.placeholder',
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
placeholder: {
|
||||
key: 'com.affine.cmdk.docs.placeholder',
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return searchResult;
|
||||
},
|
||||
@@ -408,7 +385,7 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
if (!quickSearchService)
|
||||
return oldAction({ model, rootComponent });
|
||||
|
||||
const result = await quickSearchService.searchDoc({});
|
||||
const result = await quickSearchService.openQuickSearch();
|
||||
if (result === null) return;
|
||||
|
||||
if ('docId' in result) {
|
||||
@@ -424,28 +401,23 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
pageId: linkedDoc.id,
|
||||
};
|
||||
|
||||
if (!result.isNewDoc && result.params) {
|
||||
if (result.params) {
|
||||
props.params = result.params;
|
||||
}
|
||||
|
||||
host.doc.addSiblingBlocks(model, [props]);
|
||||
|
||||
if (result.isNewDoc) {
|
||||
track.doc.editor.slashMenu.createDoc({ control: 'linkDoc' });
|
||||
track.doc.editor.slashMenu.linkDoc({ control: 'createDoc' });
|
||||
} else {
|
||||
track.doc.editor.slashMenu.linkDoc({ control: 'linkDoc' });
|
||||
}
|
||||
} else if ('userInput' in result) {
|
||||
track.doc.editor.slashMenu.linkDoc({ control: 'linkDoc' });
|
||||
} else if (result.externalUrl) {
|
||||
const embedOptions = std
|
||||
.get(EmbedOptionProvider)
|
||||
.getEmbedBlockOptions(result.userInput);
|
||||
.getEmbedBlockOptions(result.externalUrl);
|
||||
if (!embedOptions) return;
|
||||
|
||||
host.doc.addSiblingBlocks(model, [
|
||||
{
|
||||
flavour: embedOptions.flavour,
|
||||
url: result.userInput,
|
||||
url: result.externalUrl,
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -458,6 +430,25 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
return [QuickSearch, SlashMenuQuickSearchExtension];
|
||||
}
|
||||
|
||||
export function patchParseDocUrlExtension(framework: FrameworkProvider) {
|
||||
const workspaceService = framework.get(WorkspaceService);
|
||||
const ParseDocUrl = ParseDocUrlExtension({
|
||||
parseDocUrl(url) {
|
||||
const info = resolveLinkToDoc(url);
|
||||
if (!info || info.workspaceId !== workspaceService.workspace.id) return;
|
||||
|
||||
return {
|
||||
docId: info.docId,
|
||||
blockIds: info.blockIds,
|
||||
elementIds: info.elementIds,
|
||||
mode: info.mode,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
return [ParseDocUrl];
|
||||
}
|
||||
|
||||
export function patchEdgelessClipboard() {
|
||||
class EdgelessClipboardWatcher extends BlockServiceWatcher {
|
||||
static override readonly flavour = 'affine:page';
|
||||
|
||||
+4
-2
@@ -9,5 +9,7 @@ function patchPreviewSpec(id: string, specs: ExtensionType[]) {
|
||||
specProvider.extendSpec(id, specs);
|
||||
}
|
||||
|
||||
// Patch edgeless preview spec for blocksuite surface-ref and embed-synced-doc
|
||||
patchPreviewSpec('edgeless:preview', CustomSpecs);
|
||||
export function effects() {
|
||||
// Patch edgeless preview spec for blocksuite surface-ref and embed-synced-doc
|
||||
patchPreviewSpec('edgeless:preview', CustomSpecs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user