refactor(editor): remove dependency of command global types (#9903)

Closes: [BS-2216](https://linear.app/affine-design/issue/BS-2216/remove-global-types-in-command)
This commit is contained in:
Saul-Mirone
2025-01-27 12:28:46 +00:00
parent 4b549e0484
commit 17bf75e843
170 changed files with 1461 additions and 2124 deletions

View File

@@ -1,5 +1,10 @@
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
import { type DocMode, getLastNoteBlock } from '@blocksuite/affine/blocks';
import {
appendParagraphCommand,
type DocMode,
focusBlockEnd,
getLastNoteBlock,
} from '@blocksuite/affine/blocks';
import { Slot } from '@blocksuite/affine/global/utils';
import type {
AffineEditorContainer,
@@ -148,14 +153,15 @@ export const BlocksuiteEditorContainer = forwardRef<
lastBlock.flavour === 'affine:paragraph' &&
lastBlock.text?.length === 0
) {
std.command.exec('focusBlockEnd' as never, {
focusBlock: std.view.getBlock(lastBlock.id) as never,
const focusBlock = std.view.getBlock(lastBlock.id) ?? undefined;
std.command.exec(focusBlockEnd, {
focusBlock,
});
return;
}
}
std.command.exec('appendParagraph' as never, {});
std.command.exec(appendParagraphCommand);
}, [affineEditorContainerProxy, page, shared]);
return (

View File

@@ -53,6 +53,7 @@ import {
EdgelessRootBlockComponent,
EmbedLinkedDocBlockComponent,
GenerateDocUrlExtension,
insertLinkByQuickSearchCommand,
MobileSpecsPatches,
NativeClipboardExtension,
NoteConfigExtension,
@@ -460,34 +461,28 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
(item.name === 'Linked Doc' || item.name === 'Link')
) {
item.action = async ({ rootComponent }) => {
// @ts-expect-error fixme
const { success, insertedLinkType } =
// @ts-expect-error fixme
rootComponent.std.command.exec('insertLinkByQuickSearch');
const [success, { insertedLinkType }] =
rootComponent.std.command.exec(insertLinkByQuickSearchCommand);
if (!success) return;
insertedLinkType
?.then(
(type: {
flavour?: 'affine:embed-linked-doc' | 'affine:bookmark';
}) => {
const flavour = type?.flavour;
if (!flavour) return;
?.then(type => {
const flavour = type?.flavour;
if (!flavour) return;
if (flavour === 'affine:bookmark') {
track.doc.editor.slashMenu.bookmark();
return;
}
if (flavour === 'affine:embed-linked-doc') {
track.doc.editor.slashMenu.linkDoc({
control: 'linkDoc',
});
return;
}
if (flavour === 'affine:bookmark') {
track.doc.editor.slashMenu.bookmark();
return;
}
)
if (flavour === 'affine:embed-linked-doc') {
track.doc.editor.slashMenu.linkDoc({
control: 'linkDoc',
});
return;
}
})
.catch(console.error);
};
}

View File

@@ -6,7 +6,14 @@ import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import { type EditorHost } from '@blocksuite/affine/block-std';
import { GfxBlockElementModel } from '@blocksuite/affine/block-std/gfx';
import type { DocMode, EdgelessRootService } from '@blocksuite/affine/blocks';
import {
type DocMode,
type EdgelessRootService,
getBlockSelectionsCommand,
getImageSelectionsCommand,
getSelectedModelsCommand,
getTextSelectionCommand,
} from '@blocksuite/affine/blocks';
import { useService } from '@toeverything/infra';
import { useCallback } from 'react';
@@ -97,11 +104,11 @@ export const getSelectedNodes = (
const [success, ctx] = std.command
.chain()
.tryAll(chain => [
chain.getTextSelection(),
chain.getBlockSelections(),
chain.getImageSelections(),
chain.pipe(getTextSelectionCommand),
chain.pipe(getBlockSelectionsCommand),
chain.pipe(getImageSelectionsCommand),
])
.getSelectedModels({
.pipe(getSelectedModelsCommand, {
mode: 'highest',
})
.run();