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
@@ -5,10 +5,11 @@ import { type Command, TextSelection } from '@blocksuite/block-std';
* Add a paragraph next to the current block.
*/
export const addParagraphCommand: Command<
never,
'paragraphConvertedId',
{
blockId?: string;
},
{
paragraphConvertedId: string;
}
> = (ctx, next) => {
const { std } = ctx;
@@ -6,11 +6,10 @@ import { Text } from '@blocksuite/store';
/**
* Append a paragraph block at the end of the whole page.
*/
export const appendParagraphCommand: Command<
never,
never,
{ text?: string }
> = (ctx, next) => {
export const appendParagraphCommand: Command<{ text?: string }> = (
ctx,
next
) => {
const { std, text = '' } = ctx;
const { store } = std;
if (!store.root) return;
@@ -6,9 +6,10 @@ import {
import { type Command, TextSelection } from '@blocksuite/block-std';
export const canDedentParagraphCommand: Command<
never,
'indentContext',
Partial<Omit<IndentContext, 'flavour' | 'type'>>
Partial<Omit<IndentContext, 'flavour' | 'type'>>,
{
indentContext: IndentContext;
}
> = (ctx, next) => {
let { blockId, inlineIndex } = ctx;
const { std } = ctx;
@@ -56,7 +57,9 @@ export const canDedentParagraphCommand: Command<
});
};
export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
export const dedentParagraphCommand: Command<{
indentContext: IndentContext;
}> = (ctx, next) => {
const { indentContext: dedentContext, std } = ctx;
const { store, selection, range, host } = std;
@@ -8,9 +8,10 @@ import {
import { type Command, TextSelection } from '@blocksuite/block-std';
export const canIndentParagraphCommand: Command<
never,
'indentContext',
Partial<Omit<IndentContext, 'flavour' | 'type'>>
Partial<Omit<IndentContext, 'flavour' | 'type'>>,
{
indentContext: IndentContext;
}
> = (cxt, next) => {
let { blockId, inlineIndex } = cxt;
const { std } = cxt;
@@ -60,7 +61,9 @@ export const canIndentParagraphCommand: Command<
});
};
export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
export const indentParagraphCommand: Command<{
indentContext: IndentContext;
}> = (ctx, next) => {
const { indentContext, std } = ctx;
const { store, selection, host, range } = std;
@@ -1,23 +1,11 @@
import type { BlockCommands } from '@blocksuite/block-std';
import { addParagraphCommand } from './add-paragraph.js';
import { appendParagraphCommand } from './append-paragraph.js';
import {
export { addParagraphCommand } from './add-paragraph.js';
export { appendParagraphCommand } from './append-paragraph.js';
export {
canDedentParagraphCommand,
dedentParagraphCommand,
} from './dedent-paragraph.js';
import {
export {
canIndentParagraphCommand,
indentParagraphCommand,
} from './indent-paragraph.js';
import { splitParagraphCommand } from './split-paragraph.js';
export const commands: BlockCommands = {
appendParagraph: appendParagraphCommand,
splitParagraph: splitParagraphCommand,
addParagraph: addParagraphCommand,
canIndentParagraph: canIndentParagraphCommand,
canDedentParagraph: canDedentParagraphCommand,
indentParagraph: indentParagraphCommand,
dedentParagraph: dedentParagraphCommand,
};
export { splitParagraphCommand } from './split-paragraph.js';
@@ -6,10 +6,11 @@ import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { type Command, TextSelection } from '@blocksuite/block-std';
export const splitParagraphCommand: Command<
never,
'paragraphConvertedId',
{
blockId?: string;
},
{
paragraphConvertedId: string;
}
> = (ctx, next) => {
const { std } = ctx;