diff --git a/packages/g6/__tests__/unit/behaviors/drag-element-bug.spec.ts b/packages/g6/__tests__/unit/behaviors/drag-element-bug.spec.ts index 519eb288a6..5e1e441f23 100644 --- a/packages/g6/__tests__/unit/behaviors/drag-element-bug.spec.ts +++ b/packages/g6/__tests__/unit/behaviors/drag-element-bug.spec.ts @@ -1,4 +1,4 @@ -import { Graph } from '@/src'; +import { Graph, NodeEvent } from '@/src'; import { positionOf } from '@/src/utils/position'; import { createGraphCanvas } from '@@/utils'; @@ -18,21 +18,21 @@ describe('behavior drag element bug', () => { expect(graph.getZoom()).toBe(1); expect(positionOf(graph.getNodeData('node-1'))).toEqual([100, 100, 0]); - graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' }); - graph.emit('node:drag', { dx: 20, dy: 20 }); - graph.emit('node:dragend'); + graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' }); + graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 }); + graph.emit(NodeEvent.DRAG_END); expect(positionOf(graph.getNodeData('node-1'))).toEqual([120, 120, 0]); graph.zoomTo(2); - graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' }); - graph.emit('node:drag', { dx: 20, dy: 20 }); - graph.emit('node:dragend'); + graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' }); + graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 }); + graph.emit(NodeEvent.DRAG_END); expect(positionOf(graph.getNodeData('node-1'))).toEqual([130, 130, 0]); graph.zoomTo(0.5); - graph.emit('node:dragstart', { target: { id: 'node-1' }, targetType: 'node' }); - graph.emit('node:drag', { dx: 20, dy: 20 }); - graph.emit('node:dragend'); + graph.emit(NodeEvent.DRAG_START, { target: { id: 'node-1' }, targetType: 'node' }); + graph.emit(NodeEvent.DRAG, { dx: 20, dy: 20 }); + graph.emit(NodeEvent.DRAG_END); expect(positionOf(graph.getNodeData('node-1'))).toEqual([170, 170, 0]); graph.destroy(); diff --git a/packages/g6/__tests__/unit/plugins/tooltip.spec.ts b/packages/g6/__tests__/unit/plugins/tooltip.spec.ts index 0288955a8a..f68a168261 100644 --- a/packages/g6/__tests__/unit/plugins/tooltip.spec.ts +++ b/packages/g6/__tests__/unit/plugins/tooltip.spec.ts @@ -1,25 +1,26 @@ import { pluginTooltip } from '@/__tests__/demos'; -import { idOf, type Tooltip } from '@/src'; +import type { Tooltip } from '@/src'; +import { ComboEvent, EdgeEvent, NodeEvent, idOf } from '@/src'; import { createDemoGraph } from '@@/utils'; describe('plugin tooltip', () => { it('node', async () => { const graph = await createDemoGraph(pluginTooltip); - graph.emit('node:click', { targetType: 'node', target: { id: '6' } }); + graph.emit(NodeEvent.CLICK, { targetType: 'node', target: { id: '6' } }); await expect(graph).toMatchSnapshot(__filename, 'node'); graph.destroy(); }); it.skip('combo', async () => { const graph = await createDemoGraph(pluginTooltip); - graph.emit('combo:click', { targetType: 'combo', target: { id: 'a' } }); + graph.emit(ComboEvent.CLICK, { targetType: 'combo', target: { id: 'a' } }); await expect(graph).toMatchSnapshot(__filename, 'combo'); graph.destroy(); }); it('edge', async () => { const graph = await createDemoGraph(pluginTooltip); - graph.emit('edge:click', { targetType: 'edge', target: { id: idOf({ source: '0', target: '1' }) } }); + graph.emit(EdgeEvent.CLICK, { targetType: 'edge', target: { id: idOf({ source: '0', target: '1' }) } }); await expect(graph).toMatchSnapshot(__filename, 'edge'); graph.destroy(); }); @@ -37,7 +38,7 @@ describe('plugin tooltip', () => { return plugin; }), ); - graph.emit('node:pointerenter', { targetType: 'node', target: { id: '6' } }); + graph.emit(NodeEvent.POINTER_ENTER, { targetType: 'node', target: { id: '6' } }); await expect(graph).toMatchSnapshot(__filename, 'hover'); graph.destroy(); }); diff --git a/packages/g6/src/elements/nodes/html.ts b/packages/g6/src/elements/nodes/html.ts index f475334b85..4065d0f72b 100644 --- a/packages/g6/src/elements/nodes/html.ts +++ b/packages/g6/src/elements/nodes/html.ts @@ -10,7 +10,7 @@ import { Rect, } from '@antv/g'; import { isNil, isUndefined, pick } from '@antv/util'; -import { NodeEvent } from '../../constants'; +import { CommonEvent } from '../../constants'; import type { BaseNodeStyleProps } from './base-node'; import { BaseNode } from './base-node'; @@ -55,12 +55,12 @@ export class HTML extends BaseNode { private get events() { return [ - NodeEvent.CLICK, - NodeEvent.POINTER_DOWN, - NodeEvent.POINTER_MOVE, - NodeEvent.POINTER_UP, - NodeEvent.POINTER_OVER, - NodeEvent.POINTER_LEAVE, + CommonEvent.CLICK, + CommonEvent.POINTER_DOWN, + CommonEvent.POINTER_MOVE, + CommonEvent.POINTER_UP, + CommonEvent.POINTER_OVER, + CommonEvent.POINTER_LEAVE, ]; }