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
@@ -1,3 +1,4 @@
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
import {
CanvasElementType,
EdgelessCRUDIdentifier,
@@ -254,10 +255,13 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
.get(FeatureFlagService)
.getFlag('enable_edgeless_text');
if (textFlag) {
const { textId } = this.edgeless.std.command.exec('insertEdgelessText', {
x: bound.x,
y: bound.y,
});
const [_, { textId }] = this.edgeless.std.command.exec(
insertEdgelessTextCommand,
{
x: bound.x,
y: bound.y,
}
);
if (!textId) return;
const textElement = this.crud.getElementById(textId);
@@ -1,3 +1,4 @@
import { insertLinkByQuickSearchCommand } from '@blocksuite/affine-block-bookmark';
import { menu } from '@blocksuite/affine-components/context-menu';
import { LinkIcon } from '@blocksuite/affine-components/icons';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
@@ -9,8 +10,8 @@ export const buildLinkDenseMenu: DenseMenuBuilder = edgeless =>
name: 'Link',
prefix: LinkIcon,
select: () => {
const { insertedLinkType } = edgeless.std.command.exec(
'insertLinkByQuickSearch'
const [_, { insertedLinkType }] = edgeless.std.command.exec(
insertLinkByQuickSearchCommand
);
insertedLinkType
@@ -1,3 +1,4 @@
import { insertLinkByQuickSearchCommand } from '@blocksuite/affine-block-bookmark';
import { LinkIcon } from '@blocksuite/affine-components/icons';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import { css, html, LitElement } from 'lit';
@@ -17,8 +18,8 @@ export class EdgelessLinkToolButton extends QuickToolMixin(LitElement) {
override type = 'default' as const;
private _onClick() {
const { insertedLinkType } = this.edgeless.std.command.exec(
'insertLinkByQuickSearch'
const [_, { insertedLinkType }] = this.edgeless.std.command.exec(
insertLinkByQuickSearchCommand
);
insertedLinkType
?.then(type => {
@@ -1,3 +1,4 @@
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
import { CanvasElementType } from '@blocksuite/affine-block-surface';
import { type MindmapStyle, TextElementModel } from '@blocksuite/affine-model';
import {
@@ -111,10 +112,13 @@ export const textRender: DraggableTool['render'] = (
.getFlag('enable_edgeless_text');
let id: string;
if (flag) {
const { textId } = edgeless.std.command.exec('insertEdgelessText', {
x: bound.x,
y: vCenter - h / 2,
});
const [_, { textId }] = edgeless.std.command.exec(
insertEdgelessTextCommand,
{
x: bound.x,
y: vCenter - h / 2,
}
);
id = textId!;
} else {
id = service.crud.addElement(CanvasElementType.TEXT, {
@@ -1,4 +1,5 @@
import { addAttachments } from '@blocksuite/affine-block-attachment';
import { insertLinkByQuickSearchCommand } from '@blocksuite/affine-block-bookmark';
import { addImages, LoadedImageIcon } from '@blocksuite/affine-block-image';
import { AttachmentIcon, LinkIcon } from '@blocksuite/affine-components/icons';
import { MAX_IMAGE_WIDTH } from '@blocksuite/affine-model';
@@ -65,8 +66,8 @@ export class EdgelessNoteMenu extends EdgelessToolbarToolMixin(LitElement) {
}
private _onHandleLinkButtonClick() {
const { insertedLinkType } = this.edgeless.service.std.command.exec(
'insertLinkByQuickSearch'
const [_, { insertedLinkType }] = this.edgeless.service.std.command.exec(
insertLinkByQuickSearchCommand
);
insertedLinkType
@@ -1,3 +1,4 @@
import { insertLinkByQuickSearchCommand } from '@blocksuite/affine-block-bookmark';
import { EdgelessTextBlockComponent } from '@blocksuite/affine-block-edgeless-text';
import { toast } from '@blocksuite/affine-components/toast';
import {
@@ -182,8 +183,8 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
) {
return;
}
const { insertedLinkType } = std.command.exec(
'insertLinkByQuickSearch'
const [_, { insertedLinkType }] = std.command.exec(
insertLinkByQuickSearchCommand
);
insertedLinkType
@@ -16,7 +16,6 @@ import { AFFINE_SCROLL_ANCHORING_WIDGET } from '@blocksuite/affine-widget-scroll
import {
BlockServiceWatcher,
BlockViewExtension,
CommandExtension,
FlavourExtension,
WidgetViewMapExtension,
} from '@blocksuite/block-std';
@@ -26,7 +25,6 @@ import { literal, unsafeStatic } from 'lit/static-html.js';
import { ExportManagerExtension } from '../../_common/export-manager/export-manager.js';
import { RootBlockAdapterExtensions } from '../adapters/extension.js';
import { commands } from '../commands/index.js';
import { AFFINE_EDGELESS_AUTO_CONNECT_WIDGET } from '../widgets/edgeless-auto-connect/edgeless-auto-connect.js';
import { AFFINE_EDGELESS_ZOOM_TOOLBAR_WIDGET } from '../widgets/edgeless-zoom-toolbar/index.js';
import { EDGELESS_ELEMENT_TOOLBAR_WIDGET } from '../widgets/element-toolbar/index.js';
@@ -93,7 +91,6 @@ const EdgelessCommonExtension: ExtensionType[] = [
DocModeService,
ThemeService,
EmbedOptionService,
CommandExtension(commands),
ExportManagerExtension,
ToolController,
DNDAPIExtension,
@@ -1,3 +1,4 @@
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
import {
ConnectorUtils,
OverlayIdentifier,
@@ -792,7 +793,7 @@ export class DefaultTool extends BaseTool {
if (textFlag) {
const [x, y] = this.gfx.viewport.toModelCoord(e.x, e.y);
this.std.command.exec('insertEdgelessText', { x, y });
this.std.command.exec(insertEdgelessTextCommand, { x, y });
} else {
addText(this._edgeless, e);
}
@@ -1,3 +1,4 @@
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
import type { TextElementModel } from '@blocksuite/affine-model';
import {
FeatureFlagService,
@@ -47,7 +48,7 @@ export class TextTool extends BaseTool {
if (textFlag) {
const [x, y] = this.gfx.viewport.toModelCoord(e.x, e.y);
this.gfx.std.command.exec('insertEdgelessText', { x, y });
this.gfx.std.command.exec(insertEdgelessTextCommand, { x, y });
this.gfx.tool.setTool('default');
} else {
addText(this.gfx, e);