mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
refactor(editor): remove global gfx tool types (#12119)
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
import type { FrameTool } from './frame-tool';
|
|
||||||
import type { PresentTool, PresentToolOption } from './present-tool';
|
|
||||||
|
|
||||||
export * from './edgeless-clipboard-config';
|
export * from './edgeless-clipboard-config';
|
||||||
export * from './edgeless-toolbar';
|
export * from './edgeless-toolbar';
|
||||||
export * from './frame-block';
|
export * from './frame-block';
|
||||||
@@ -10,14 +7,3 @@ export * from './frame-spec';
|
|||||||
export * from './frame-tool';
|
export * from './frame-tool';
|
||||||
export * from './frame-toolbar';
|
export * from './frame-toolbar';
|
||||||
export * from './present-tool';
|
export * from './present-tool';
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
frameNavigator: PresentTool;
|
|
||||||
frame: FrameTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GfxToolsOption {
|
|
||||||
frameNavigator: PresentToolOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
import type * as BrushEffect from '@blocksuite/affine-gfx-brush';
|
|
||||||
import type * as NoteEffect from '@blocksuite/affine-gfx-note';
|
|
||||||
import type * as PointerEffect from '@blocksuite/affine-gfx-pointer';
|
|
||||||
import type * as ShapeEffect from '@blocksuite/affine-gfx-shape';
|
|
||||||
|
|
||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
export * from './clipboard/index.js';
|
export * from './clipboard/index.js';
|
||||||
export * from './edgeless/edgeless-root-spec.js';
|
export * from './edgeless/edgeless-root-spec.js';
|
||||||
@@ -10,9 +5,3 @@ export * from './edgeless/index.js';
|
|||||||
export * from './page/page-root-block.js';
|
export * from './page/page-root-block.js';
|
||||||
export * from './preview/preview-root-block.js';
|
export * from './preview/preview-root-block.js';
|
||||||
export * from './types.js';
|
export * from './types.js';
|
||||||
|
|
||||||
declare type _GLOBAL_ =
|
|
||||||
| typeof PointerEffect
|
|
||||||
| typeof NoteEffect
|
|
||||||
| typeof BrushEffect
|
|
||||||
| typeof ShapeEffect;
|
|
||||||
|
|||||||
@@ -416,9 +416,3 @@ export class DefaultTool extends BaseTool {
|
|||||||
|
|
||||||
override unmounted(): void {}
|
override unmounted(): void {}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
default: DefaultTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -177,9 +177,3 @@ export class BrushTool extends BaseTool {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
brush: BrushTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -155,9 +155,3 @@ export class EraserTool extends BaseTool {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
eraser: EraserTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -177,9 +177,3 @@ export class HighlighterTool extends BaseTool {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
highlighter: HighlighterTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -224,13 +224,3 @@ export class ConnectorTool extends BaseTool<ConnectorToolOptions> {
|
|||||||
this.findTargetByPoint(point);
|
this.findTargetByPoint(point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
connector: ConnectorTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GfxToolsOption {
|
|
||||||
connector: ConnectorToolOptions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -218,16 +218,6 @@ export class NoteTool extends BaseTool<NoteToolOption> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
'affine:note': NoteTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GfxToolsOption {
|
|
||||||
'affine:note': NoteToolOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type NoteOptions = {
|
type NoteOptions = {
|
||||||
childFlavour: NoteChildrenFlavour;
|
childFlavour: NoteChildrenFlavour;
|
||||||
childType: string | null;
|
childType: string | null;
|
||||||
|
|||||||
@@ -6,9 +6,3 @@ import { BaseTool } from '@blocksuite/std/gfx';
|
|||||||
export class EmptyTool extends BaseTool {
|
export class EmptyTool extends BaseTool {
|
||||||
static override toolName: string = 'empty';
|
static override toolName: string = 'empty';
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
empty: EmptyTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -78,13 +78,3 @@ export class PanTool extends BaseTool<PanToolOption> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
pan: PanTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GfxToolsOption {
|
|
||||||
pan: PanToolOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -336,13 +336,3 @@ export class ShapeTool extends BaseTool<ShapeToolOption> {
|
|||||||
this._disableOverlay = disable;
|
this._disableOverlay = disable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
shape: ShapeTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GfxToolsOption {
|
|
||||||
shape: ShapeToolOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,9 +3,3 @@ import { BaseTool } from '@blocksuite/std/gfx';
|
|||||||
export class TemplateTool extends BaseTool {
|
export class TemplateTool extends BaseTool {
|
||||||
static override toolName: string = 'template';
|
static override toolName: string = 'template';
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
template: TemplateTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
import {
|
|
||||||
CanvasElementType,
|
|
||||||
DefaultTool,
|
|
||||||
EdgelessCRUDIdentifier,
|
|
||||||
type IModelCoord,
|
|
||||||
} from '@blocksuite/affine-block-surface';
|
|
||||||
import { TextElementModel } from '@blocksuite/affine-model';
|
|
||||||
import { Bound } from '@blocksuite/global/gfx';
|
|
||||||
import type { BlockComponent, PointerEventState } from '@blocksuite/std';
|
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
|
||||||
import * as Y from 'yjs';
|
|
||||||
|
|
||||||
import { EdgelessTextEditor } from './edgeless-text-editor';
|
|
||||||
import { getCursorByCoord } from './element-renderer/utils';
|
|
||||||
|
|
||||||
export function mountTextElementEditor(
|
|
||||||
textElement: TextElementModel,
|
|
||||||
edgeless: BlockComponent,
|
|
||||||
focusCoord?: IModelCoord
|
|
||||||
) {
|
|
||||||
let cursorIndex = textElement.text.length;
|
|
||||||
if (focusCoord) {
|
|
||||||
cursorIndex = Math.min(
|
|
||||||
getCursorByCoord(textElement, focusCoord),
|
|
||||||
cursorIndex
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const textEditor = new EdgelessTextEditor();
|
|
||||||
textEditor.element = textElement;
|
|
||||||
|
|
||||||
edgeless.append(textEditor);
|
|
||||||
textEditor.updateComplete
|
|
||||||
.then(() => {
|
|
||||||
textEditor.inlineEditor?.focusIndex(cursorIndex);
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
const gfx = edgeless.std.get(GfxControllerIdentifier);
|
|
||||||
|
|
||||||
gfx.tool.setTool(DefaultTool);
|
|
||||||
gfx.selection.set({
|
|
||||||
elements: [textElement.id],
|
|
||||||
editing: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* Canvas Text has been deprecated
|
|
||||||
*/
|
|
||||||
export function addText(edgeless: BlockComponent, event: PointerEventState) {
|
|
||||||
const gfx = edgeless.std.get(GfxControllerIdentifier);
|
|
||||||
const crud = edgeless.std.get(EdgelessCRUDIdentifier);
|
|
||||||
const [x, y] = gfx.viewport.toModelCoord(event.x, event.y);
|
|
||||||
const selected = gfx.getElementByPoint(x, y);
|
|
||||||
|
|
||||||
if (!selected) {
|
|
||||||
const [modelX, modelY] = gfx.viewport.toModelCoord(event.x, event.y);
|
|
||||||
|
|
||||||
const id = edgeless.std
|
|
||||||
.get(EdgelessCRUDIdentifier)
|
|
||||||
.addElement(CanvasElementType.TEXT, {
|
|
||||||
xywh: new Bound(modelX, modelY, 32, 32).serialize(),
|
|
||||||
text: new Y.Text(),
|
|
||||||
});
|
|
||||||
if (!id) return;
|
|
||||||
|
|
||||||
edgeless.doc.captureSync();
|
|
||||||
const textElement = crud.getElementById(id);
|
|
||||||
if (!textElement) return;
|
|
||||||
if (textElement instanceof TextElementModel) {
|
|
||||||
mountTextElementEditor(textElement, edgeless);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import { BaseTool, type GfxController } from '@blocksuite/std/gfx';
|
|||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { insertEdgelessTextCommand } from './commands/insert-edgeless-text';
|
import { insertEdgelessTextCommand } from './commands/insert-edgeless-text';
|
||||||
import { mountTextElementEditor } from './mount-text-editor';
|
import { mountTextElementEditor } from './edgeless-text-editor';
|
||||||
|
|
||||||
function addText(gfx: GfxController, event: PointerEventState) {
|
function addText(gfx: GfxController, event: PointerEventState) {
|
||||||
const [x, y] = gfx.viewport.toModelCoord(event.x, event.y);
|
const [x, y] = gfx.viewport.toModelCoord(event.x, event.y);
|
||||||
@@ -64,9 +64,3 @@ export class TextTool extends BaseTool {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
text: TextTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -90,10 +90,6 @@ export {
|
|||||||
} from './surface-middleware.js';
|
} from './surface-middleware.js';
|
||||||
export {
|
export {
|
||||||
BaseTool,
|
BaseTool,
|
||||||
type GfxToolsFullOption,
|
|
||||||
type GfxToolsFullOptionValue,
|
|
||||||
type GfxToolsMap,
|
|
||||||
type GfxToolsOption,
|
|
||||||
type ToolOptions,
|
type ToolOptions,
|
||||||
type ToolOptionWithType,
|
type ToolOptionWithType,
|
||||||
type ToolType,
|
type ToolType,
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ export interface ToolEventTarget {
|
|||||||
): void;
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const eventTarget = Symbol('eventTarget');
|
|
||||||
|
|
||||||
export class ToolController extends GfxExtension {
|
export class ToolController extends GfxExtension {
|
||||||
static override key = 'ToolController';
|
static override key = 'ToolController';
|
||||||
|
|
||||||
|
|||||||
@@ -123,16 +123,3 @@ export type ToolOptionWithType<T extends BaseTool = BaseTool> = {
|
|||||||
toolType?: ToolType<T>;
|
toolType?: ToolType<T>;
|
||||||
options?: ToolOptions<T>;
|
options?: ToolOptions<T>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface GfxToolsMap {}
|
|
||||||
|
|
||||||
export interface GfxToolsOption {}
|
|
||||||
|
|
||||||
export type GfxToolsFullOption = {
|
|
||||||
[Key in keyof GfxToolsMap]: Key extends keyof GfxToolsOption
|
|
||||||
? { type: Key } & GfxToolsOption[Key]
|
|
||||||
: { type: Key };
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GfxToolsFullOptionValue =
|
|
||||||
GfxToolsFullOption[keyof GfxToolsFullOption];
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { splitElements } from '@blocksuite/affine/blocks/root';
|
import { splitElements } from '@blocksuite/affine/blocks/root';
|
||||||
import { DefaultTool } from '@blocksuite/affine/blocks/surface';
|
import { DefaultTool } from '@blocksuite/affine/blocks/surface';
|
||||||
import type * as PointerEffect from '@blocksuite/affine/gfx/pointer';
|
|
||||||
import {
|
import {
|
||||||
CodeBlockModel,
|
CodeBlockModel,
|
||||||
EdgelessTextBlockModel,
|
EdgelessTextBlockModel,
|
||||||
@@ -50,8 +49,6 @@ import {
|
|||||||
getToolbar,
|
getToolbar,
|
||||||
} from './edgeless-response';
|
} from './edgeless-response';
|
||||||
|
|
||||||
declare type _GLOBAL_ = typeof PointerEffect;
|
|
||||||
|
|
||||||
async function getContentFromEmbedSyncedDocModel(
|
async function getContentFromEmbedSyncedDocModel(
|
||||||
host: EditorHost,
|
host: EditorHost,
|
||||||
models: EmbedSyncedDocModel[]
|
models: EmbedSyncedDocModel[]
|
||||||
|
|||||||
@@ -172,9 +172,3 @@ export class CopilotTool extends BaseTool {
|
|||||||
this.draggingAreaUpdated.next(true);
|
this.draggingAreaUpdated.next(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@blocksuite/std/gfx' {
|
|
||||||
interface GfxToolsMap {
|
|
||||||
copilot: CopilotTool;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import type * as Effect from '@blocksuite/affine/effects';
|
import type * as Effect from '@blocksuite/affine/effects';
|
||||||
import type * as ConnectorEffect from '@blocksuite/affine/gfx/connector';
|
|
||||||
import type * as ShapeEffect from '@blocksuite/affine/gfx/shape';
|
|
||||||
import type { EditorHost } from '@blocksuite/affine/std';
|
import type { EditorHost } from '@blocksuite/affine/std';
|
||||||
import type { Store, Transformer, Workspace } from '@blocksuite/affine/store';
|
import type { Store, Transformer, Workspace } from '@blocksuite/affine/store';
|
||||||
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
||||||
|
|
||||||
declare type _GLOBAL_ =
|
declare type _GLOBAL_ = typeof Effect;
|
||||||
| typeof Effect
|
|
||||||
| typeof ConnectorEffect
|
|
||||||
| typeof ShapeEffect;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|||||||
Reference in New Issue
Block a user