mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08: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,6 +1,13 @@
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { getSelectedBlocksCommand } from '../block-crud/get-selected-blocks';
|
||||
import {
|
||||
getBlockSelectionsCommand,
|
||||
getImageSelectionsCommand,
|
||||
getTextSelectionCommand,
|
||||
} from '../selection';
|
||||
|
||||
/**
|
||||
* Retrieves the selected models based on the provided selection types and mode.
|
||||
*
|
||||
@@ -29,11 +36,12 @@ import type { BlockModel } from '@blocksuite/store';
|
||||
* @returns An object containing the selected models as an array of BlockModel instances.
|
||||
*/
|
||||
export const getSelectedModelsCommand: Command<
|
||||
never,
|
||||
'selectedModels',
|
||||
{
|
||||
types?: Array<'image' | 'text' | 'block'>;
|
||||
mode?: 'all' | 'flat' | 'highest';
|
||||
},
|
||||
{
|
||||
selectedModels: BlockModel[];
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const types = ctx.types ?? ['block', 'text', 'image'];
|
||||
@@ -42,15 +50,12 @@ export const getSelectedModelsCommand: Command<
|
||||
ctx.std.command
|
||||
.chain()
|
||||
.tryAll(chain => [
|
||||
chain.getTextSelection(),
|
||||
chain.getBlockSelections(),
|
||||
chain.getImageSelections(),
|
||||
chain.pipe(getTextSelectionCommand),
|
||||
chain.pipe(getBlockSelectionsCommand),
|
||||
chain.pipe(getImageSelectionsCommand),
|
||||
])
|
||||
.getSelectedBlocks({
|
||||
types,
|
||||
mode,
|
||||
})
|
||||
.inline(ctx => {
|
||||
.pipe(getSelectedBlocksCommand, { types, mode })
|
||||
.pipe(ctx => {
|
||||
const { selectedBlocks = [] } = ctx;
|
||||
selectedModels.push(...selectedBlocks.map(el => el.model));
|
||||
})
|
||||
@@ -58,15 +63,3 @@ export const getSelectedModelsCommand: Command<
|
||||
|
||||
next({ selectedModels });
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface CommandContext {
|
||||
selectedModels?: BlockModel[];
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
getSelectedModels: typeof getSelectedModelsCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user