mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 20:41:50 +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,18 +1,22 @@
|
||||
import type { BlockComponent, Command } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
export const getBlockIndexCommand: Command<
|
||||
'currentSelectionPath',
|
||||
'blockIndex' | 'parentBlock',
|
||||
{
|
||||
currentSelectionPath?: string;
|
||||
path?: string;
|
||||
},
|
||||
{
|
||||
blockIndex?: number;
|
||||
parentBlock?: BlockComponent;
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const path = ctx.path ?? ctx.currentSelectionPath;
|
||||
assertExists(
|
||||
path,
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
if (!path) {
|
||||
console.error(
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const parentModel = ctx.std.store.getParent(path);
|
||||
if (!parentModel) return;
|
||||
@@ -29,16 +33,3 @@ export const getBlockIndexCommand: Command<
|
||||
parentBlock: parent as BlockComponent,
|
||||
});
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface CommandContext {
|
||||
blockIndex?: number;
|
||||
parentBlock?: BlockComponent;
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
getBlockIndex: typeof getBlockIndexCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { BlockComponent, Command } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
import { getNextContentBlock } from '../../utils/index.js';
|
||||
|
||||
@@ -13,17 +12,21 @@ function getNextBlock(std: BlockSuite.Std, path: string) {
|
||||
}
|
||||
|
||||
export const getNextBlockCommand: Command<
|
||||
'currentSelectionPath',
|
||||
'nextBlock',
|
||||
{
|
||||
currentSelectionPath?: string;
|
||||
path?: string;
|
||||
},
|
||||
{
|
||||
nextBlock?: BlockComponent;
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const path = ctx.path ?? ctx.currentSelectionPath;
|
||||
assertExists(
|
||||
path,
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
if (!path) {
|
||||
console.error(
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const nextBlock = getNextBlock(ctx.std, path);
|
||||
|
||||
@@ -31,15 +34,3 @@ export const getNextBlockCommand: Command<
|
||||
next({ nextBlock });
|
||||
}
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface CommandContext {
|
||||
nextBlock?: BlockComponent;
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
getNextBlock: typeof getNextBlockCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { BlockComponent, Command } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
import { getPrevContentBlock } from '../../utils/index.js';
|
||||
|
||||
@@ -14,17 +13,21 @@ function getPrevBlock(std: BlockSuite.Std, path: string) {
|
||||
}
|
||||
|
||||
export const getPrevBlockCommand: Command<
|
||||
'currentSelectionPath',
|
||||
'prevBlock',
|
||||
{
|
||||
currentSelectionPath?: string;
|
||||
path?: string;
|
||||
},
|
||||
{
|
||||
prevBlock?: BlockComponent;
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const path = ctx.path ?? ctx.currentSelectionPath;
|
||||
assertExists(
|
||||
path,
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
if (!path) {
|
||||
console.error(
|
||||
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const prevBlock = getPrevBlock(ctx.std, path);
|
||||
|
||||
@@ -32,15 +35,3 @@ export const getPrevBlockCommand: Command<
|
||||
next({ prevBlock });
|
||||
}
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface CommandContext {
|
||||
prevBlock?: BlockComponent;
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
getPrevBlock: typeof getPrevBlockCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ import type { RoleType } from '@blocksuite/store';
|
||||
import type { ImageSelection } from '../../selection/index.js';
|
||||
|
||||
export const getSelectedBlocksCommand: Command<
|
||||
'currentTextSelection' | 'currentBlockSelections' | 'currentImageSelections',
|
||||
'selectedBlocks',
|
||||
{
|
||||
currentTextSelection?: TextSelection;
|
||||
currentBlockSelections?: BlockSelection[];
|
||||
currentImageSelections?: ImageSelection[];
|
||||
textSelection?: TextSelection;
|
||||
blockSelections?: BlockSelection[];
|
||||
imageSelections?: ImageSelection[];
|
||||
@@ -19,6 +20,9 @@ export const getSelectedBlocksCommand: Command<
|
||||
types?: Array<'image' | 'text' | 'block'>;
|
||||
roles?: RoleType[];
|
||||
mode?: 'all' | 'flat' | 'highest';
|
||||
},
|
||||
{
|
||||
selectedBlocks: BlockComponent[];
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const {
|
||||
@@ -146,15 +150,3 @@ export const getSelectedBlocksCommand: Command<
|
||||
selectedBlocks: result,
|
||||
});
|
||||
};
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface CommandContext {
|
||||
selectedBlocks?: BlockComponent[];
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
getSelectedBlocks: typeof getSelectedBlocksCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user