fix(editor): move insert link command to bookmark to remove ts ignore (#9370)

This commit is contained in:
Saul-Mirone
2024-12-27 09:09:29 +00:00
parent fee86304ae
commit 1fbb462389
7 changed files with 21 additions and 18 deletions
@@ -1,9 +1,9 @@
import type { BlockCommands } from '@blocksuite/block-std';
import { insertEmbedLinkedDocCommand } from './insert-embed-linked-doc.js';
import { insertLinkByQuickSearchCommand } from './insert-link-by-quick-search.js';
export const commands: BlockCommands = {
insertEmbedLinkedDoc: insertEmbedLinkedDocCommand,
insertLinkByQuickSearch: insertLinkByQuickSearchCommand,
};
export type { InsertedLinkType } from './insert-embed-linked-doc';
@@ -3,6 +3,10 @@ import type { Command } from '@blocksuite/block-std';
import { insertEmbedCard } from '../../common/insert-embed-card.js';
export type InsertedLinkType = {
flavour?: 'affine:bookmark' | 'affine:embed-linked-doc';
} | null;
export const insertEmbedLinkedDocCommand: Command<
never,
'insertedLinkType',
@@ -1,48 +0,0 @@
import { QuickSearchProvider } from '@blocksuite/affine-shared/services';
import type { Command } from '@blocksuite/block-std';
export type InsertedLinkType = {
flavour?: 'affine:bookmark' | 'affine:embed-linked-doc';
} | null;
export const insertLinkByQuickSearchCommand: Command<
never,
'insertedLinkType'
> = (ctx, next) => {
const { std } = ctx;
const quickSearchService = std.getOptional(QuickSearchProvider);
if (!quickSearchService) {
next();
return;
}
const insertedLinkType: Promise<InsertedLinkType> = quickSearchService
.openQuickSearch()
.then(result => {
if (!result) return null;
// add linked doc
if ('docId' in result) {
std.command.exec('insertEmbedLinkedDoc', {
docId: result.docId,
params: result.params,
});
return {
flavour: 'affine:embed-linked-doc',
};
}
// add normal link;
if ('externalUrl' in result) {
// @ts-expect-error FIXME: fix after bookmark refactor
std.command.exec('insertBookmark', { url: result.externalUrl });
return {
flavour: 'affine:bookmark',
};
}
return null;
});
next({ insertedLinkType });
};
@@ -1,4 +1,5 @@
export * from './adapters/index.js';
export * from './embed-linked-doc-block.js';
export * from './embed-linked-doc-config.js';
export * from './embed-linked-doc-spec.js';
export * from './adapters';
export type { InsertedLinkType } from './commands';
export * from './embed-linked-doc-block';
export * from './embed-linked-doc-config';
export * from './embed-linked-doc-spec';