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,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;
}
}
}