refactor(editor): remove gfx tool global type (#12116)

Closes: BS-2650
This commit is contained in:
Saul-Mirone
2025-05-04 13:53:26 +00:00
parent f3b5c36cf7
commit 30a2e5b4fb
95 changed files with 664 additions and 521 deletions

View File

@@ -1,4 +1,5 @@
import { splitElements } from '@blocksuite/affine/blocks/root';
import { DefaultTool } from '@blocksuite/affine/blocks/surface';
import type * as PointerEffect from '@blocksuite/affine/gfx/pointer';
import {
CodeBlockModel,
@@ -358,7 +359,7 @@ function updateEdgelessAIPanelConfig<
config.hideCallback = () => {
aiPanel.updateComplete
.finally(() => {
edgelessCopilot.gfx.tool.setTool('default');
edgelessCopilot.gfx.tool.setTool(DefaultTool);
edgelessCopilot.gfx.selection.set({
elements: [],
editing: false,
@@ -431,7 +432,7 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(
if (!referenceElement) {
const gfx = host.std.get(GfxControllerIdentifier);
gfx?.tool.setTool({ type: 'default' });
gfx?.tool.setTool(DefaultTool);
edgelessCopilot.lockToolbar(false);
return;
}

View File

@@ -1,4 +1,5 @@
/* oxlint-disable @typescript-eslint/no-non-null-assertion */
import { DefaultTool } from '@blocksuite/affine/blocks/surface';
import { IS_MAC } from '@blocksuite/affine/global/env';
import {
Bound,
@@ -67,7 +68,7 @@ export class CopilotTool extends BaseTool {
this._dragging = false;
this.dragStartPoint = [0, 0];
this.dragLastPoint = [0, 0];
this.gfx.tool.setTool('default');
this.gfx.tool.setTool(DefaultTool);
}
override activate(): void {
@@ -129,7 +130,7 @@ export class CopilotTool extends BaseTool {
: evt.raw.ctrlKey);
if (useCopilot) {
this.controller.setTool('copilot');
this.controller.setTool(CopilotTool);
return false;
}
@@ -143,7 +144,7 @@ export class CopilotTool extends BaseTool {
return;
}
this.gfx.tool.setTool('default');
this.gfx.tool.setTool(DefaultTool);
}
updateDragPointsWith(selectedElements: GfxModel[], padding = 0) {

View File

@@ -10,7 +10,7 @@ import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import type { AIItemGroupConfig } from '../../components/ai-item/types';
import type { CopilotTool } from '../../tool/copilot-tool';
import { CopilotTool } from '../../tool/copilot-tool';
export class EdgelessCopilotToolbarEntry extends WithDisposable(LitElement) {
static override styles = css`
@@ -51,7 +51,7 @@ export class EdgelessCopilotToolbarEntry extends WithDisposable(LitElement) {
}
});
this._gfx.tool.setTool('copilot');
this._gfx.tool.setTool(CopilotTool);
(this._gfx.tool.currentTool$.peek() as CopilotTool).updateSelectionWith(
Array.from(toBeSelected),
10

View File

@@ -1,3 +1,4 @@
import { CopilotTool } from '@affine/core/blocksuite/ai/tool/copilot-tool';
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine/blocks/surface';
import {
Bound,
@@ -205,7 +206,7 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
override connectedCallback(): void {
super.connectedCallback();
const CopilotSelectionTool = this.gfx.tool.get('copilot');
const CopilotSelectionTool = this.gfx.tool.get(CopilotTool);
this._disposables.add(
CopilotSelectionTool.draggingAreaUpdated.subscribe(shouldShowPanel => {

View File

@@ -1,5 +1,7 @@
import type { AffineEditorContainer } from '@affine/core/blocksuite/block-suite-editor';
import type { DefaultOpenProperty } from '@affine/core/components/doc-properties';
import { PresentTool } from '@blocksuite/affine/blocks/frame';
import { DefaultTool } from '@blocksuite/affine/blocks/surface';
import type { DocTitle } from '@blocksuite/affine/fragments/doc-title';
import type { DocMode, ReferenceParams } from '@blocksuite/affine/model';
import { HighlightSelection } from '@blocksuite/affine/shared/selection';
@@ -75,9 +77,11 @@ export class Editor extends Entity {
GfxControllerIdentifier
);
if (!gfx) return;
gfx.tool.setTool({
type: !this.isPresenting$.value ? 'frameNavigator' : 'default',
});
if (!this.isPresenting$.value) {
gfx.tool.setTool(PresentTool);
} else {
gfx.tool.setTool(DefaultTool);
}
}
setSelector(selector: EditorSelector | undefined) {