@soonspacejs/plugin-drawing-topology 2.13.17 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +100 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Object3D } from 'three';
|
|
2
|
-
import SoonSpace,
|
|
3
|
-
import type { Topology, TopologyInfo } from 'soonspacejs';
|
|
2
|
+
import { default as SoonSpace, TopologyNodeInfo, Topology, TopologyInfo } from 'soonspacejs';
|
|
4
3
|
export interface StartOptions extends TopologyInfo {
|
|
5
4
|
onCancel?: () => void;
|
|
6
5
|
onAdd?: (node: TopologyNodeInfo, intersectObject: Object3D) => void;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,100 @@
|
|
|
1
|
-
import
|
|
1
|
+
import h from "soonspacejs";
|
|
2
|
+
const { randomString: n } = h.utils;
|
|
3
|
+
class d {
|
|
4
|
+
constructor(s) {
|
|
5
|
+
this.ssp = s, this.viewport = s.viewport, this.onMouseDowm = this.onMouseDowm.bind(this), this.onMouseMove = this.onMouseMove.bind(this), this.onClick = this.onClick.bind(this), this.onDblClick = this.onDblClick.bind(this), this.onRightClick = this.onRightClick.bind(this), this.onKeyUp = this.onKeyUp.bind(this);
|
|
6
|
+
}
|
|
7
|
+
viewport;
|
|
8
|
+
// 绘制状态
|
|
9
|
+
drawing = !1;
|
|
10
|
+
nodes = [];
|
|
11
|
+
topology = null;
|
|
12
|
+
mouseDownNode = null;
|
|
13
|
+
mouseDownObject = null;
|
|
14
|
+
mouseMoveNode = null;
|
|
15
|
+
options = {
|
|
16
|
+
id: "drawing_topology",
|
|
17
|
+
type: "line",
|
|
18
|
+
nodes: []
|
|
19
|
+
};
|
|
20
|
+
start(s) {
|
|
21
|
+
this.options = s, this.drawing = !0, this.ssp.signals.mouseDown.add(this.onMouseDowm), this.ssp.signals.mouseMove.add(this.onMouseMove), this.ssp.signals.click.add(this.onClick), this.ssp.signals.dblClick.add(this.onDblClick), this.ssp.signals.rightClick.add(this.onRightClick), this.ssp.signals.keyUp.add(this.onKeyUp);
|
|
22
|
+
}
|
|
23
|
+
undo() {
|
|
24
|
+
const s = this.nodes.pop();
|
|
25
|
+
s && (this.renderTopology(this.nodes), this.options.onUndo?.(s));
|
|
26
|
+
}
|
|
27
|
+
done() {
|
|
28
|
+
this.renderTopology(this.nodes), this.options.onDone?.([...this.nodes], this.topology), this.stop();
|
|
29
|
+
}
|
|
30
|
+
cancel() {
|
|
31
|
+
this.topology && this.ssp.removeObject(this.topology), this.options.onCancel?.(), this.stop();
|
|
32
|
+
}
|
|
33
|
+
stop() {
|
|
34
|
+
this.nodes = [], this.topology = null, this.mouseDownNode = null, this.mouseDownObject = null, this.mouseMoveNode = null, this.options = {
|
|
35
|
+
id: "drawing_topology",
|
|
36
|
+
type: "line",
|
|
37
|
+
nodes: []
|
|
38
|
+
}, this.drawing = !1, this.ssp.signals.mouseDown.remove(this.onMouseDowm), this.ssp.signals.mouseMove.remove(this.onMouseMove), this.ssp.signals.click.remove(this.onClick), this.ssp.signals.dblClick.remove(this.onDblClick), this.ssp.signals.rightClick.remove(this.onRightClick), this.ssp.signals.keyUp.remove(this.onKeyUp);
|
|
39
|
+
}
|
|
40
|
+
onMouseDowm(s) {
|
|
41
|
+
const [o] = this.ssp.viewport.getIntersects(s);
|
|
42
|
+
if (o) {
|
|
43
|
+
const { object: i, point: t } = o, e = n();
|
|
44
|
+
this.mouseDownNode = {
|
|
45
|
+
id: `node${e}`,
|
|
46
|
+
name: `node${e}`,
|
|
47
|
+
position: t.setY(t.y + 0.01),
|
|
48
|
+
graphs: []
|
|
49
|
+
}, this.mouseDownObject = i;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
onMouseMove(s) {
|
|
53
|
+
const [o] = this.ssp.viewport.getIntersects(s);
|
|
54
|
+
if (o) {
|
|
55
|
+
const i = n();
|
|
56
|
+
this.mouseMoveNode = {
|
|
57
|
+
id: `node${i}`,
|
|
58
|
+
name: `node${i}`,
|
|
59
|
+
position: o.point.clone().setY(o.point.y),
|
|
60
|
+
graphs: []
|
|
61
|
+
}, this.renderTopology([...this.nodes, this.mouseMoveNode]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
onClick() {
|
|
65
|
+
this.pushNode();
|
|
66
|
+
}
|
|
67
|
+
onDblClick() {
|
|
68
|
+
this.pushNode(), this.options.onDone?.([...this.nodes], this.topology), this.stop();
|
|
69
|
+
}
|
|
70
|
+
onRightClick() {
|
|
71
|
+
this.undo();
|
|
72
|
+
}
|
|
73
|
+
onKeyUp(s) {
|
|
74
|
+
switch (s.code) {
|
|
75
|
+
case "Backspace":
|
|
76
|
+
this.undo();
|
|
77
|
+
break;
|
|
78
|
+
case "Enter":
|
|
79
|
+
this.done();
|
|
80
|
+
break;
|
|
81
|
+
case "Escape":
|
|
82
|
+
this.cancel();
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
pushNode() {
|
|
87
|
+
this.mouseDownNode && this.mouseDownObject && (this.nodes.push(this.mouseDownNode), this.renderTopology(this.nodes), this.options.onAdd?.(this.mouseDownNode, this.mouseDownObject), this.mouseDownNode = null, this.mouseDownObject = null);
|
|
88
|
+
}
|
|
89
|
+
renderTopology(s) {
|
|
90
|
+
this.topology ? this.ssp.resetTopologyNodes(this.topology, s) : this.topology = this.ssp.createTopology({
|
|
91
|
+
...this.options,
|
|
92
|
+
// 正在绘制中的路径不在导航计算范围内,所以类型使用 network,因为 line 会移动计算
|
|
93
|
+
type: "line",
|
|
94
|
+
nodes: s
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
d as default
|
|
100
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-drawing-topology",
|
|
3
3
|
"pluginName": "DrawingTopologyPlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.1",
|
|
5
5
|
"description": "DrawingTopologyPlugin plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "xunwei",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.
|
|
18
|
+
"soonspacejs": "2.14.1"
|
|
19
19
|
}
|
|
20
20
|
}
|