mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
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:
@@ -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 (
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user