|
@@ -9,6 +9,7 @@ import { History } from '@antv/x6-plugin-history'
|
|
import { Keyboard } from '@antv/x6-plugin-keyboard'
|
|
import { Keyboard } from '@antv/x6-plugin-keyboard'
|
|
import { useModel } from 'umi'
|
|
import { useModel } from 'umi'
|
|
import '@/components/PageContainer'
|
|
import '@/components/PageContainer'
|
|
|
|
+import { handleGraphEvent } from '@/events'
|
|
export default function GraphModel() {
|
|
export default function GraphModel() {
|
|
const [graph, setGraph] = useState<Graph>();
|
|
const [graph, setGraph] = useState<Graph>();
|
|
const [dnd, setDnd] = useState<Dnd>();
|
|
const [dnd, setDnd] = useState<Dnd>();
|
|
@@ -35,6 +36,11 @@ export default function GraphModel() {
|
|
data: {
|
|
data: {
|
|
isPage: true,
|
|
isPage: true,
|
|
...pageState
|
|
...pageState
|
|
|
|
+ },
|
|
|
|
+ attrs: {
|
|
|
|
+ style: {
|
|
|
|
+ 'pointer-events': 'none'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
@@ -75,8 +81,8 @@ export default function GraphModel() {
|
|
multiple: true,
|
|
multiple: true,
|
|
rubberband: true,
|
|
rubberband: true,
|
|
movable: true,
|
|
movable: true,
|
|
- showNodeSelectionBox: true,
|
|
|
|
- showEdgeSelectionBox: true,
|
|
|
|
|
|
+ // showNodeSelectionBox: true,
|
|
|
|
+ // showEdgeSelectionBox: true,
|
|
pointerEvents: 'none',
|
|
pointerEvents: 'none',
|
|
strict: true,
|
|
strict: true,
|
|
filter: (cell: Cell) => {
|
|
filter: (cell: Cell) => {
|
|
@@ -100,44 +106,21 @@ export default function GraphModel() {
|
|
|
|
|
|
}));
|
|
}));
|
|
|
|
|
|
- // 控制连接桩显示/隐藏
|
|
|
|
- const showPorts = (ports: NodeListOf<SVGElement>, show: boolean) => {
|
|
|
|
- for (let i = 0, len = ports.length; i < len; i += 1) {
|
|
|
|
- ports[i].style.visibility = show ? 'visible' : 'hidden'
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- instance.on('node:mouseenter', ({_e, node}:{_e: React.MouseEvent<HTMLDivElement, MouseEvent>, node: Node.Metadata}) => {
|
|
|
|
- if(node.data?.isPage) return;
|
|
|
|
-
|
|
|
|
- const container = document.querySelector(`[data-cell-id="${node.id}"]`)!;
|
|
|
|
- if(!container) return;
|
|
|
|
- const ports = container.querySelectorAll(
|
|
|
|
- '.x6-port-body',
|
|
|
|
- ) as NodeListOf<SVGElement>;
|
|
|
|
- showPorts(ports, true);
|
|
|
|
- })
|
|
|
|
- instance.on('node:mouseleave', ({_e, node}:{_e: React.MouseEvent<HTMLDivElement, MouseEvent>, node: Node.Metadata}) => {
|
|
|
|
- if(node.data?.isPage) return;
|
|
|
|
|
|
+ setGraph(instance);
|
|
|
|
+ graphRef.current = instance;
|
|
|
|
|
|
- const container = document.querySelector('#graph-container')!;
|
|
|
|
- if(!container) return;
|
|
|
|
- const ports = container.querySelectorAll(
|
|
|
|
- '.x6-port-body',
|
|
|
|
- ) as NodeListOf<SVGElement>;
|
|
|
|
- showPorts(ports, false);
|
|
|
|
- })
|
|
|
|
// 选中的节点/边发生改变(增删)时触发
|
|
// 选中的节点/边发生改变(增删)时触发
|
|
instance.on('selection:changed', ({added, removed, selected}: {added: Cell[]; removed: Cell[]; selected: Cell[];}) => {
|
|
instance.on('selection:changed', ({added, removed, selected}: {added: Cell[]; removed: Cell[]; selected: Cell[];}) => {
|
|
setSelectedCell(selected);
|
|
setSelectedCell(selected);
|
|
})
|
|
})
|
|
|
|
|
|
- setGraph(instance);
|
|
|
|
- graphRef.current = instance;
|
|
|
|
-
|
|
|
|
instance.on('history:change', () => {
|
|
instance.on('history:change', () => {
|
|
setCanRedo(instance.canRedo());
|
|
setCanRedo(instance.canRedo());
|
|
setCanUndo(instance.canUndo());
|
|
setCanUndo(instance.canUndo());
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ // 通用事件处理
|
|
|
|
+ handleGraphEvent(instance);
|
|
}
|
|
}
|
|
|
|
|
|
/**初始化拖拽 */
|
|
/**初始化拖拽 */
|