mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
chore: bump bs (#8204)
This commit is contained in:
4
packages/common/env/package.json
vendored
4
packages/common/env/package.json
vendored
@@ -3,8 +3,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@blocksuite/global": "0.17.6",
|
||||
"@blocksuite/store": "0.17.6",
|
||||
"@blocksuite/global": "0.17.7",
|
||||
"@blocksuite/store": "0.17.7",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"vitest": "2.0.5"
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
"@affine/debug": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@blocksuite/blocks": "0.17.6",
|
||||
"@blocksuite/global": "0.17.6",
|
||||
"@blocksuite/presets": "0.17.6",
|
||||
"@blocksuite/store": "0.17.6",
|
||||
"@blocksuite/blocks": "0.17.7",
|
||||
"@blocksuite/global": "0.17.7",
|
||||
"@blocksuite/presets": "0.17.7",
|
||||
"@blocksuite/store": "0.17.7",
|
||||
"@datastructures-js/binary-search-tree": "^5.3.2",
|
||||
"foxact": "^0.2.33",
|
||||
"fuse.js": "^7.0.0",
|
||||
@@ -34,8 +34,8 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@blocksuite/block-std": "0.17.6",
|
||||
"@blocksuite/presets": "0.17.6",
|
||||
"@blocksuite/block-std": "0.17.7",
|
||||
"@blocksuite/presets": "0.17.7",
|
||||
"@testing-library/react": "^16.0.0",
|
||||
"async-call-rpc": "^6.4.0",
|
||||
"fake-indexeddb": "^6.0.0",
|
||||
|
||||
@@ -81,12 +81,12 @@
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blocksuite/block-std": "0.17.6",
|
||||
"@blocksuite/blocks": "0.17.6",
|
||||
"@blocksuite/global": "0.17.6",
|
||||
"@blocksuite/block-std": "0.17.7",
|
||||
"@blocksuite/blocks": "0.17.7",
|
||||
"@blocksuite/global": "0.17.7",
|
||||
"@blocksuite/icons": "2.1.67",
|
||||
"@blocksuite/presets": "0.17.6",
|
||||
"@blocksuite/store": "0.17.6",
|
||||
"@blocksuite/presets": "0.17.7",
|
||||
"@blocksuite/store": "0.17.7",
|
||||
"@chromatic-com/storybook": "^1",
|
||||
"@storybook/addon-actions": "^8.2.9",
|
||||
"@storybook/addon-essentials": "^8.2.9",
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
"@affine/graphql": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@blocksuite/affine-block-surface": "0.17.6",
|
||||
"@blocksuite/block-std": "0.17.6",
|
||||
"@blocksuite/blocks": "0.17.6",
|
||||
"@blocksuite/global": "0.17.6",
|
||||
"@blocksuite/affine-block-surface": "0.17.7",
|
||||
"@blocksuite/block-std": "0.17.7",
|
||||
"@blocksuite/blocks": "0.17.7",
|
||||
"@blocksuite/global": "0.17.7",
|
||||
"@blocksuite/icons": "2.1.67",
|
||||
"@blocksuite/inline": "0.17.6",
|
||||
"@blocksuite/presets": "0.17.6",
|
||||
"@blocksuite/store": "0.17.6",
|
||||
"@blocksuite/inline": "0.17.7",
|
||||
"@blocksuite/presets": "0.17.7",
|
||||
"@blocksuite/store": "0.17.7",
|
||||
"@dnd-kit/core": "^6.1.0",
|
||||
"@dnd-kit/modifiers": "^7.0.0",
|
||||
"@dnd-kit/sortable": "^8.0.0",
|
||||
|
||||
@@ -8,7 +8,9 @@ import {
|
||||
type DocMode,
|
||||
DocModeProvider,
|
||||
type EdgelessRootService,
|
||||
EditPropsStore,
|
||||
type ImageSelection,
|
||||
NotificationProvider,
|
||||
type PageRootService,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/blocks';
|
||||
@@ -114,7 +116,7 @@ function getViewportCenter(
|
||||
) {
|
||||
const center = { x: 400, y: 50 };
|
||||
if (mode === 'page') {
|
||||
const viewport = rootService.editPropsStore.getStorage('viewport');
|
||||
const viewport = rootService.std.get(EditPropsStore).getStorage('viewport');
|
||||
if (viewport) {
|
||||
if ('xywh' in viewport) {
|
||||
const bound = Bound.deserialize(viewport.xywh);
|
||||
@@ -178,7 +180,7 @@ function addAIChatBlock(
|
||||
}
|
||||
|
||||
export function promptDocTitle(host: EditorHost, autofill?: string) {
|
||||
const notification = host.std.getService('affine:page')?.notificationService;
|
||||
const notification = host.std.getOptional(NotificationProvider);
|
||||
if (!notification) return Promise.resolve(undefined);
|
||||
|
||||
return notification.prompt({
|
||||
@@ -302,7 +304,7 @@ const SAVE_CHAT_TO_BLOCK_ACTION: ChatAction = {
|
||||
const surfaceService = host.std.getService('affine:surface');
|
||||
if (!rootService || !surfaceService) return false;
|
||||
|
||||
const { notificationService } = rootService;
|
||||
const notificationService = host.std.getOptional(NotificationProvider);
|
||||
const docModeService = host.std.get(DocModeProvider);
|
||||
const { layer } = surfaceService;
|
||||
const curMode = docModeService.getEditorMode() || 'page';
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
EditorHost,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { ImageSelection } from '@blocksuite/blocks';
|
||||
import { type ImageSelection, NotificationProvider } from '@blocksuite/blocks';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
@@ -59,10 +59,6 @@ export class ChatActionList extends LitElement {
|
||||
return this.host.selection.value;
|
||||
}
|
||||
|
||||
private get _rootService() {
|
||||
return this.host.std.getService('affine:page');
|
||||
}
|
||||
|
||||
private get _currentTextSelection(): TextSelection | undefined {
|
||||
return this._selectionValue.find(v => v.type === 'text') as TextSelection;
|
||||
}
|
||||
@@ -148,7 +144,7 @@ export class ChatActionList extends LitElement {
|
||||
messageId
|
||||
);
|
||||
if (success) {
|
||||
this._rootService?.notificationService?.notify({
|
||||
this.host.std.getOptional(NotificationProvider)?.notify({
|
||||
title: action.toast,
|
||||
accent: 'success',
|
||||
onClose: function (): void {},
|
||||
|
||||
@@ -4,7 +4,11 @@ import type {
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import { WithDisposable } from '@blocksuite/block-std';
|
||||
import { createButtonPopper, Tooltip } from '@blocksuite/blocks';
|
||||
import {
|
||||
createButtonPopper,
|
||||
NotificationProvider,
|
||||
Tooltip,
|
||||
} from '@blocksuite/blocks';
|
||||
import { noop } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
|
||||
import { customElement, property, query, state } from 'lit/decorators.js';
|
||||
@@ -129,7 +133,7 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
|
||||
|
||||
private readonly _notifySuccess = (title: string) => {
|
||||
if (!this._rootService) return;
|
||||
const { notificationService } = this._rootService;
|
||||
const notificationService = this.host.std.getOptional(NotificationProvider);
|
||||
notificationService?.notify({
|
||||
title: title,
|
||||
accent: 'success',
|
||||
|
||||
@@ -3,6 +3,7 @@ import './chat-panel-messages';
|
||||
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { ShadowlessElement, WithDisposable } from '@blocksuite/block-std';
|
||||
import { NotificationProvider } from '@blocksuite/blocks';
|
||||
import { debounce } from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import { css, html, type PropertyValues } from 'lit';
|
||||
@@ -159,8 +160,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
||||
};
|
||||
|
||||
private readonly _cleanupHistories = async () => {
|
||||
const notification =
|
||||
this.host.std.getService('affine:page')?.notificationService;
|
||||
const notification = this.host.std.getOptional(NotificationProvider);
|
||||
if (!notification) return;
|
||||
|
||||
if (
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type EdgelessRootService,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/blocks';
|
||||
import { NotificationProvider } from '@blocksuite/blocks';
|
||||
import {
|
||||
type AIChatBlockModel,
|
||||
type ChatMessage,
|
||||
@@ -255,7 +256,7 @@ export class AIChatBlockPeekView extends LitElement {
|
||||
*/
|
||||
cleanCurrentChatHistories = async () => {
|
||||
if (!this._rootService) return;
|
||||
const { notificationService } = this._rootService;
|
||||
const notificationService = this.host.std.getOptional(NotificationProvider);
|
||||
if (!notificationService) return;
|
||||
|
||||
const { currentChatBlockId, currentSessionId } = this.chatContext;
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
DatabaseBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
EditPropsStore,
|
||||
EmbedFigmaBlockSpec,
|
||||
EmbedGithubBlockSpec,
|
||||
EmbedHtmlBlockSpec,
|
||||
@@ -28,6 +29,7 @@ import { AIChatBlockSpec } from '@blocksuite/presets';
|
||||
import { CustomAttachmentBlockSpec } from './custom/attachment-block';
|
||||
|
||||
const CommonBlockSpecs: ExtensionType[] = [
|
||||
EditPropsStore,
|
||||
RichTextExtensions,
|
||||
LatexBlockSpec,
|
||||
ListBlockSpec,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ConfigExtension, type ExtensionType } from '@blocksuite/block-std';
|
||||
import {
|
||||
AffineCanvasTextFonts,
|
||||
EdgelessRootBlockSpec,
|
||||
EditorSettingExtension,
|
||||
FontLoaderService,
|
||||
PageRootBlockSpec,
|
||||
} from '@blocksuite/blocks';
|
||||
@@ -49,14 +50,18 @@ function getTelemetryExtension(): ExtensionType {
|
||||
};
|
||||
}
|
||||
|
||||
function getEditorConfigExtension(framework: FrameworkProvider) {
|
||||
function getEditorConfigExtension(
|
||||
framework: FrameworkProvider
|
||||
): ExtensionType[] {
|
||||
const editorSettingService = framework.get(EditorSettingService);
|
||||
return ConfigExtension('affine:page', {
|
||||
linkedWidget: createLinkedWidgetConfig(framework),
|
||||
editorSetting: editorSettingService.editorSetting.settingSignal,
|
||||
toolbarMoreMenu: createToolbarMoreMenuConfig(framework),
|
||||
databaseOptions: createDatabaseOptionsConfig(framework),
|
||||
});
|
||||
return [
|
||||
EditorSettingExtension(editorSettingService.editorSetting.settingSignal),
|
||||
ConfigExtension('affine:page', {
|
||||
linkedWidget: createLinkedWidgetConfig(framework),
|
||||
toolbarMoreMenu: createToolbarMoreMenuConfig(framework),
|
||||
databaseOptions: createDatabaseOptionsConfig(framework),
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
export function createPageRootBlockSpec(
|
||||
@@ -64,11 +69,11 @@ export function createPageRootBlockSpec(
|
||||
enableAI: boolean
|
||||
): ExtensionType[] {
|
||||
return [
|
||||
...(enableAI ? AIPageRootBlockSpec : PageRootBlockSpec),
|
||||
enableAI ? AIPageRootBlockSpec : PageRootBlockSpec,
|
||||
FontLoaderService,
|
||||
getTelemetryExtension(),
|
||||
getEditorConfigExtension(framework),
|
||||
];
|
||||
].flat();
|
||||
}
|
||||
|
||||
export function createEdgelessRootBlockSpec(
|
||||
@@ -76,10 +81,10 @@ export function createEdgelessRootBlockSpec(
|
||||
enableAI: boolean
|
||||
): ExtensionType[] {
|
||||
return [
|
||||
...(enableAI ? AIEdgelessRootBlockSpec : EdgelessRootBlockSpec),
|
||||
enableAI ? AIEdgelessRootBlockSpec : EdgelessRootBlockSpec,
|
||||
FontLoaderService,
|
||||
getFontConfigExtension(),
|
||||
getTelemetryExtension(),
|
||||
getEditorConfigExtension(framework),
|
||||
];
|
||||
].flat();
|
||||
}
|
||||
|
||||
@@ -28,17 +28,21 @@ import {
|
||||
type WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { BlockServiceWatcher } from '@blocksuite/block-std';
|
||||
import {
|
||||
type AffineReference,
|
||||
type DocMode,
|
||||
EmbedOptionProvider,
|
||||
type RootService,
|
||||
import type {
|
||||
AffineReference,
|
||||
DocMode,
|
||||
DocModeProvider,
|
||||
RootService,
|
||||
} from '@blocksuite/blocks';
|
||||
import {
|
||||
AffineSlashMenuWidget,
|
||||
DocModeProvider,
|
||||
DocModeExtension,
|
||||
EdgelessRootBlockComponent,
|
||||
EmbedLinkedDocBlockComponent,
|
||||
EmbedOptionProvider,
|
||||
NotificationExtension,
|
||||
PeekViewExtension,
|
||||
QuickSearchExtension,
|
||||
QuickSearchProvider,
|
||||
ReferenceNodeConfigExtension,
|
||||
} from '@blocksuite/blocks';
|
||||
@@ -108,125 +112,121 @@ export function patchNotificationService({
|
||||
closeConfirmModal,
|
||||
openConfirmModal,
|
||||
}: ReturnType<typeof useConfirmModal>) {
|
||||
return patchSpecService<RootService>('affine:page', service => {
|
||||
service.notificationService = {
|
||||
confirm: async ({ title, message, confirmText, cancelText, abort }) => {
|
||||
return new Promise<boolean>(resolve => {
|
||||
openConfirmModal({
|
||||
title: toReactNode(title),
|
||||
description: toReactNode(message),
|
||||
confirmText,
|
||||
confirmButtonOptions: {
|
||||
variant: 'primary',
|
||||
},
|
||||
cancelText,
|
||||
onConfirm: () => {
|
||||
resolve(true);
|
||||
},
|
||||
onCancel: () => {
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
abort?.addEventListener('abort', () => {
|
||||
resolve(false);
|
||||
closeConfirmModal();
|
||||
});
|
||||
});
|
||||
},
|
||||
prompt: async ({
|
||||
title,
|
||||
message,
|
||||
confirmText,
|
||||
placeholder,
|
||||
cancelText,
|
||||
autofill,
|
||||
abort,
|
||||
}) => {
|
||||
return new Promise<string | null>(resolve => {
|
||||
let value = autofill || '';
|
||||
const description = (
|
||||
<div>
|
||||
<span style={{ marginBottom: 12 }}>{toReactNode(message)}</span>
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
defaultValue={value}
|
||||
onChange={e => (value = e)}
|
||||
ref={input => input?.select()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
openConfirmModal({
|
||||
title: toReactNode(title),
|
||||
description: description,
|
||||
confirmText: confirmText ?? 'Confirm',
|
||||
confirmButtonOptions: {
|
||||
variant: 'primary',
|
||||
},
|
||||
cancelText: cancelText ?? 'Cancel',
|
||||
onConfirm: () => {
|
||||
resolve(value);
|
||||
},
|
||||
onCancel: () => {
|
||||
resolve(null);
|
||||
},
|
||||
});
|
||||
abort?.addEventListener('abort', () => {
|
||||
resolve(null);
|
||||
closeConfirmModal();
|
||||
});
|
||||
});
|
||||
},
|
||||
toast: (message: string, options: ToastOptions) => {
|
||||
return toast(message, options);
|
||||
},
|
||||
notify: notification => {
|
||||
const accentToNotify = {
|
||||
error: notify.error,
|
||||
success: notify.success,
|
||||
warning: notify.warning,
|
||||
info: notify,
|
||||
};
|
||||
|
||||
const fn = accentToNotify[notification.accent || 'info'];
|
||||
if (!fn) {
|
||||
throw new Error('Invalid notification accent');
|
||||
}
|
||||
|
||||
const toastId = fn(
|
||||
{
|
||||
title: toReactNode(notification.title),
|
||||
message: toReactNode(notification.message),
|
||||
action: notification.action?.onClick
|
||||
? {
|
||||
label: toReactNode(notification.action?.label),
|
||||
onClick: notification.action.onClick,
|
||||
}
|
||||
: undefined,
|
||||
onDismiss: notification.onClose,
|
||||
return NotificationExtension({
|
||||
confirm: async ({ title, message, confirmText, cancelText, abort }) => {
|
||||
return new Promise<boolean>(resolve => {
|
||||
openConfirmModal({
|
||||
title: toReactNode(title),
|
||||
description: toReactNode(message),
|
||||
confirmText,
|
||||
confirmButtonOptions: {
|
||||
variant: 'primary',
|
||||
},
|
||||
cancelText,
|
||||
onConfirm: () => {
|
||||
resolve(true);
|
||||
},
|
||||
onCancel: () => {
|
||||
resolve(false);
|
||||
},
|
||||
{
|
||||
duration: notification.duration || 0,
|
||||
onDismiss: notification.onClose,
|
||||
onAutoClose: notification.onClose,
|
||||
}
|
||||
);
|
||||
|
||||
notification.abort?.addEventListener('abort', () => {
|
||||
notify.dismiss(toastId);
|
||||
});
|
||||
},
|
||||
};
|
||||
abort?.addEventListener('abort', () => {
|
||||
resolve(false);
|
||||
closeConfirmModal();
|
||||
});
|
||||
});
|
||||
},
|
||||
prompt: async ({
|
||||
title,
|
||||
message,
|
||||
confirmText,
|
||||
placeholder,
|
||||
cancelText,
|
||||
autofill,
|
||||
abort,
|
||||
}) => {
|
||||
return new Promise<string | null>(resolve => {
|
||||
let value = autofill || '';
|
||||
const description = (
|
||||
<div>
|
||||
<span style={{ marginBottom: 12 }}>{toReactNode(message)}</span>
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
defaultValue={value}
|
||||
onChange={e => (value = e)}
|
||||
ref={input => input?.select()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
openConfirmModal({
|
||||
title: toReactNode(title),
|
||||
description: description,
|
||||
confirmText: confirmText ?? 'Confirm',
|
||||
confirmButtonOptions: {
|
||||
variant: 'primary',
|
||||
},
|
||||
cancelText: cancelText ?? 'Cancel',
|
||||
onConfirm: () => {
|
||||
resolve(value);
|
||||
},
|
||||
onCancel: () => {
|
||||
resolve(null);
|
||||
},
|
||||
});
|
||||
abort?.addEventListener('abort', () => {
|
||||
resolve(null);
|
||||
closeConfirmModal();
|
||||
});
|
||||
});
|
||||
},
|
||||
toast: (message: string, options: ToastOptions) => {
|
||||
return toast(message, options);
|
||||
},
|
||||
notify: notification => {
|
||||
const accentToNotify = {
|
||||
error: notify.error,
|
||||
success: notify.success,
|
||||
warning: notify.warning,
|
||||
info: notify,
|
||||
};
|
||||
|
||||
const fn = accentToNotify[notification.accent || 'info'];
|
||||
if (!fn) {
|
||||
throw new Error('Invalid notification accent');
|
||||
}
|
||||
|
||||
const toastId = fn(
|
||||
{
|
||||
title: toReactNode(notification.title),
|
||||
message: toReactNode(notification.message),
|
||||
action: notification.action?.onClick
|
||||
? {
|
||||
label: toReactNode(notification.action?.label),
|
||||
onClick: notification.action.onClick,
|
||||
}
|
||||
: undefined,
|
||||
onDismiss: notification.onClose,
|
||||
},
|
||||
{
|
||||
duration: notification.duration || 0,
|
||||
onDismiss: notification.onClose,
|
||||
onAutoClose: notification.onClose,
|
||||
}
|
||||
);
|
||||
|
||||
notification.abort?.addEventListener('abort', () => {
|
||||
notify.dismiss(toastId);
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function patchPeekViewService(service: PeekViewService) {
|
||||
return patchSpecService<RootService>('affine:page', pageService => {
|
||||
pageService.peekViewService = {
|
||||
peek: (target: ActivePeekView['target'], template?: TemplateResult) => {
|
||||
logger.debug('center peek', target, template);
|
||||
return service.peekView.open(target, template);
|
||||
},
|
||||
};
|
||||
return PeekViewExtension({
|
||||
peek: (target: ActivePeekView['target'], template?: TemplateResult) => {
|
||||
logger.debug('center peek', target, template);
|
||||
return service.peekView.open(target, template);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,128 +274,119 @@ export function patchDocModeService(
|
||||
};
|
||||
}
|
||||
|
||||
const docModeExtension: ExtensionType = {
|
||||
setup: di => [di.override(DocModeProvider, AffineDocModeService)],
|
||||
};
|
||||
const docModeExtension = DocModeExtension(new AffineDocModeService());
|
||||
|
||||
return docModeExtension;
|
||||
}
|
||||
|
||||
export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
const QuickSearchExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(QuickSearchProvider, () => ({
|
||||
async searchDoc(options) {
|
||||
let searchResult:
|
||||
| { docId: string; isNewDoc?: boolean }
|
||||
| { userInput: string }
|
||||
| null = 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
const QuickSearch = QuickSearchExtension({
|
||||
async searchDoc(options) {
|
||||
let searchResult:
|
||||
| { docId: string; isNewDoc?: boolean }
|
||||
| { userInput: string }
|
||||
| null = 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 {
|
||||
searchResult = await new Promise(resolve =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(CreationQuickSearchSession),
|
||||
(query: string) => {
|
||||
if (
|
||||
(query.startsWith('http://') ||
|
||||
query.startsWith('https://')) &&
|
||||
resolveLinkToDoc(query) === null
|
||||
) {
|
||||
return [
|
||||
{
|
||||
id: 'link',
|
||||
source: 'link',
|
||||
icon: LinkIcon,
|
||||
label: {
|
||||
key: 'com.affine.cmdk.affine.insert-link',
|
||||
},
|
||||
payload: { url: query },
|
||||
} as QuickSearchItem<'link', { url: string }>,
|
||||
];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
result.source === 'docs' ||
|
||||
result.source === 'recent-doc'
|
||||
) {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
} else if (result.source === 'link') {
|
||||
resolve({
|
||||
userInput: result.payload.url,
|
||||
});
|
||||
} else 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,
|
||||
});
|
||||
resolve({
|
||||
docId: newDoc.id,
|
||||
isNewDoc: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
defaultQuery: options.userInput,
|
||||
label: {
|
||||
key: 'com.affine.cmdk.insert-links',
|
||||
},
|
||||
placeholder: {
|
||||
key: 'com.affine.cmdk.docs.placeholder',
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
const searchedDoc = (
|
||||
await framework.get(DocsSearchService).search(query)
|
||||
).at(0);
|
||||
if (searchedDoc) {
|
||||
searchResult = {
|
||||
docId: searchedDoc.docId,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
searchResult = await new Promise(resolve =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(CreationQuickSearchSession),
|
||||
(query: string) => {
|
||||
if (
|
||||
(query.startsWith('http://') ||
|
||||
query.startsWith('https://')) &&
|
||||
resolveLinkToDoc(query) === null
|
||||
) {
|
||||
return [
|
||||
{
|
||||
id: 'link',
|
||||
source: 'link',
|
||||
icon: LinkIcon,
|
||||
label: {
|
||||
key: 'com.affine.cmdk.affine.insert-link',
|
||||
},
|
||||
payload: { url: query },
|
||||
} as QuickSearchItem<'link', { url: string }>,
|
||||
];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
if (result.source === 'docs' || result.source === 'recent-doc') {
|
||||
resolve({
|
||||
docId: result.payload.docId,
|
||||
});
|
||||
} else if (result.source === 'link') {
|
||||
resolve({
|
||||
userInput: result.payload.url,
|
||||
});
|
||||
} else 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,
|
||||
});
|
||||
resolve({
|
||||
docId: newDoc.id,
|
||||
isNewDoc: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
defaultQuery: options.userInput,
|
||||
label: {
|
||||
key: 'com.affine.cmdk.insert-links',
|
||||
},
|
||||
placeholder: {
|
||||
key: 'com.affine.cmdk.docs.placeholder',
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
},
|
||||
}));
|
||||
return searchResult;
|
||||
},
|
||||
};
|
||||
});
|
||||
const SlashMenuQuickSearchExtension = patchSpecService<RootService>(
|
||||
'affine:page',
|
||||
() => {},
|
||||
@@ -452,7 +443,7 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
}
|
||||
}
|
||||
);
|
||||
return [QuickSearchExtension, SlashMenuQuickSearchExtension];
|
||||
return [QuickSearch, SlashMenuQuickSearchExtension];
|
||||
}
|
||||
|
||||
export function patchEdgelessClipboard() {
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/native": "workspace:*",
|
||||
"@blocksuite/block-std": "0.17.6",
|
||||
"@blocksuite/blocks": "0.17.6",
|
||||
"@blocksuite/presets": "0.17.6",
|
||||
"@blocksuite/store": "0.17.6",
|
||||
"@blocksuite/block-std": "0.17.7",
|
||||
"@blocksuite/blocks": "0.17.7",
|
||||
"@blocksuite/presets": "0.17.7",
|
||||
"@blocksuite/store": "0.17.7",
|
||||
"@electron-forge/cli": "^7.3.0",
|
||||
"@electron-forge/core": "^7.3.0",
|
||||
"@electron-forge/core-utils": "^7.3.0",
|
||||
|
||||
Reference in New Issue
Block a user