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
@@ -24,10 +24,7 @@ import { updateXYWH } from '../utils/update-xywh.js';
/**
* Automatically arrange elements according to fixed row and column rules
*/
export const autoArrangeElementsCommand: Command<never, never, {}> = (
ctx,
next
) => {
export const autoArrangeElementsCommand: Command = (ctx, next) => {
const { updateBlock } = ctx.std.store;
const gfx = ctx.std.get(GfxControllerIdentifier);
@@ -42,10 +39,7 @@ export const autoArrangeElementsCommand: Command<never, never, {}> = (
/**
* Adjust the height of the selected element to a fixed value and arrange the elements
*/
export const autoResizeElementsCommand: Command<never, never, {}> = (
ctx,
next
) => {
export const autoResizeElementsCommand: Command = (ctx, next) => {
const { updateBlock } = ctx.std.store;
const gfx = ctx.std.get(GfxControllerIdentifier);
@@ -1,13 +1,5 @@
import type { BlockCommands } from '@blocksuite/block-std';
import {
export {
autoArrangeElementsCommand,
autoResizeElementsCommand,
} from './auto-align.js';
import { reassociateConnectorsCommand } from './reassociate-connectors.js';
export const commands: BlockCommands = {
reassociateConnectors: reassociateConnectorsCommand,
autoArrangeElements: autoArrangeElementsCommand,
autoResizeElements: autoResizeElementsCommand,
};
export { reassociateConnectorsCommand } from './reassociate-connectors.js';
@@ -6,11 +6,10 @@ import type { Command } from '@blocksuite/block-std';
* @param oldId - the old block id
* @param newId - the new block id
*/
export const reassociateConnectorsCommand: Command<
never,
never,
{ oldId: string; newId: string }
> = (ctx, next) => {
export const reassociateConnectorsCommand: Command<{
oldId: string;
newId: string;
}> = (ctx, next) => {
const { oldId, newId } = ctx;
const service = ctx.std.getService('affine:surface');
if (!oldId || !newId || !service) {
@@ -1,8 +1,3 @@
import type {
autoArrangeElementsCommand,
autoResizeElementsCommand,
} from './commands/auto-align.js';
import type { reassociateConnectorsCommand } from './commands/reassociate-connectors.js';
import { SurfaceBlockComponent } from './surface-block.js';
import { SurfaceBlockVoidComponent } from './surface-block-void.js';
import type { SurfaceBlockModel } from './surface-model.js';
@@ -21,10 +16,5 @@ declare global {
interface BlockModels {
'affine:surface': SurfaceBlockModel;
}
interface Commands {
reassociateConnectors: typeof reassociateConnectorsCommand;
autoArrangeElements: typeof autoArrangeElementsCommand;
autoResizeElements: typeof autoResizeElementsCommand;
}
}
}
@@ -116,3 +116,5 @@ export const MindmapUtils = {
hideNodeConnector,
containsNode,
};
export * from './commands';
@@ -1,8 +1,4 @@
import {
BlockViewExtension,
CommandExtension,
FlavourExtension,
} from '@blocksuite/block-std';
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
import type { ExtensionType } from '@blocksuite/store';
import { literal } from 'lit/static-html.js';
@@ -10,7 +6,6 @@ import {
EdgelessSurfaceBlockAdapterExtensions,
SurfaceBlockAdapterExtensions,
} from './adapters/extension';
import { commands } from './commands';
import {
EdgelessCRUDExtension,
EdgelessLegacySlotExtension,
@@ -21,7 +16,6 @@ import { MindMapView } from './view/mindmap';
const CommonSurfaceBlockSpec: ExtensionType[] = [
FlavourExtension('affine:surface'),
SurfaceBlockService,
CommandExtension(commands),
MindMapView,
EdgelessCRUDExtension,
EdgelessLegacySlotExtension,