@logicflow/core 2.2.0 → 2.2.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.css +3 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +9 -0
- package/es/LogicFlow.js +0 -1
- package/es/constant/index.d.ts +1 -1
- package/es/constant/index.js +1 -1
- package/es/constant/theme.d.ts +136 -0
- package/es/constant/theme.js +680 -0
- package/es/index.css +3 -2
- package/es/model/GraphModel.d.ts +10 -2
- package/es/model/GraphModel.js +48 -14
- package/es/model/TransformModel.js +9 -9
- package/es/model/edge/BaseEdgeModel.js +7 -2
- package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/es/model/edge/PolylineEdgeModel.js +136 -7
- package/es/model/node/BaseNodeModel.d.ts +12 -1
- package/es/model/node/BaseNodeModel.js +9 -2
- package/es/model/node/HtmlNodeModel.d.ts +12 -0
- package/es/model/node/HtmlNodeModel.js +19 -0
- package/es/model/node/PolygonNodeModel.js +3 -3
- package/es/options.d.ts +4 -2
- package/es/style/index.css +3 -2
- package/es/style/index.less +3 -2
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/tool/MultipleSelectTool.js +10 -5
- package/es/util/drag.js +0 -1
- package/es/util/edge.d.ts +40 -1
- package/es/util/edge.js +43 -9
- package/es/util/geometry.d.ts +8 -0
- package/es/util/geometry.js +79 -0
- package/es/util/theme.d.ts +2 -65
- package/es/util/theme.js +4 -281
- package/es/view/Anchor.d.ts +1 -0
- package/es/view/Anchor.js +24 -21
- package/es/view/Control.d.ts +5 -0
- package/es/view/Control.js +44 -57
- package/es/view/edge/BaseEdge.js +9 -0
- package/es/view/edge/PolylineEdge.js +13 -2
- package/es/view/node/BaseNode.d.ts +1 -0
- package/es/view/node/BaseNode.js +23 -11
- package/es/view/node/HtmlNode.js +2 -4
- package/es/view/overlay/CanvasOverlay.js +5 -2
- package/es/view/overlay/Grid.d.ts +12 -1
- package/es/view/overlay/Grid.js +85 -23
- package/es/view/overlay/OutlineOverlay.d.ts +1 -0
- package/es/view/overlay/OutlineOverlay.js +18 -17
- package/es/view/overlay/gridConfig.d.ts +46 -0
- package/es/view/overlay/gridConfig.js +99 -0
- package/es/view/shape/Polygon.d.ts +0 -7
- package/es/view/shape/Polygon.js +12 -43
- package/lib/LogicFlow.d.ts +9 -0
- package/lib/LogicFlow.js +0 -1
- package/lib/constant/index.d.ts +1 -1
- package/lib/constant/index.js +16 -2
- package/lib/constant/theme.d.ts +136 -0
- package/lib/constant/theme.js +683 -0
- package/lib/index.css +3 -2
- package/lib/model/GraphModel.d.ts +10 -2
- package/lib/model/GraphModel.js +49 -15
- package/lib/model/TransformModel.js +9 -9
- package/lib/model/edge/BaseEdgeModel.js +7 -2
- package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/lib/model/edge/PolylineEdgeModel.js +136 -7
- package/lib/model/node/BaseNodeModel.d.ts +12 -1
- package/lib/model/node/BaseNodeModel.js +9 -2
- package/lib/model/node/HtmlNodeModel.d.ts +12 -0
- package/lib/model/node/HtmlNodeModel.js +19 -0
- package/lib/model/node/PolygonNodeModel.js +3 -3
- package/lib/options.d.ts +4 -2
- package/lib/style/index.css +3 -2
- package/lib/style/index.less +3 -2
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/tool/MultipleSelectTool.js +10 -5
- package/lib/util/drag.js +0 -1
- package/lib/util/edge.d.ts +40 -1
- package/lib/util/edge.js +43 -9
- package/lib/util/geometry.d.ts +8 -0
- package/lib/util/geometry.js +81 -1
- package/lib/util/theme.d.ts +2 -65
- package/lib/util/theme.js +15 -292
- package/lib/view/Anchor.d.ts +1 -0
- package/lib/view/Anchor.js +24 -21
- package/lib/view/Control.d.ts +5 -0
- package/lib/view/Control.js +44 -57
- package/lib/view/edge/BaseEdge.js +9 -0
- package/lib/view/edge/PolylineEdge.js +13 -2
- package/lib/view/node/BaseNode.d.ts +1 -0
- package/lib/view/node/BaseNode.js +22 -10
- package/lib/view/node/HtmlNode.js +1 -3
- package/lib/view/overlay/CanvasOverlay.js +5 -2
- package/lib/view/overlay/Grid.d.ts +12 -1
- package/lib/view/overlay/Grid.js +83 -21
- package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
- package/lib/view/overlay/OutlineOverlay.js +18 -17
- package/lib/view/overlay/gridConfig.d.ts +46 -0
- package/lib/view/overlay/gridConfig.js +104 -0
- package/lib/view/shape/Polygon.d.ts +0 -7
- package/lib/view/shape/Polygon.js +13 -45
- package/package.json +6 -1
- package/.turbo/turbo-build$colon$dev.log +0 -10
- package/.turbo/turbo-build.log +0 -33
- package/CHANGELOG.md +0 -1849
- package/__tests__/algorithm/egde.test.ts +0 -131
- package/__tests__/algorithm/index.test.ts +0 -74
- package/__tests__/algorithm/outline.test.ts +0 -43
- package/__tests__/bugs/1545-spec.test.ts +0 -42
- package/__tests__/event/event.test.ts +0 -22
- package/__tests__/history/history.test.ts +0 -28
- package/__tests__/logicflow.test.ts +0 -575
- package/__tests__/model/graphmodel.test.ts +0 -87
- package/__tests__/util/compatible.test.ts +0 -48
- package/__tests__/util/edge.test.ts +0 -224
- package/__tests__/util/geometry.test.ts +0 -14
- package/__tests__/util/graph.test.ts +0 -16
- package/__tests__/util/matrix.test.ts +0 -41
- package/__tests__/util/node.test.ts +0 -68
- package/__tests__/util/sampling.test.ts +0 -12
- package/__tests__/util/vector.test.ts +0 -50
- package/__tests__/util/zIndex.test.ts +0 -10
- package/src/LogicFlow.tsx +0 -2008
- package/src/algorithm/edge.ts +0 -67
- package/src/algorithm/index.ts +0 -70
- package/src/algorithm/outline.ts +0 -77
- package/src/algorithm/rotate.ts +0 -55
- package/src/common/drag.ts +0 -219
- package/src/common/history.ts +0 -108
- package/src/common/index.ts +0 -6
- package/src/common/keyboard.ts +0 -108
- package/src/common/matrix.ts +0 -122
- package/src/common/vector.ts +0 -93
- package/src/constant/index.ts +0 -179
- package/src/event/event.md +0 -66
- package/src/event/eventArgs.ts +0 -643
- package/src/event/eventEmitter.ts +0 -156
- package/src/history/index.ts +0 -119
- package/src/index.less +0 -1
- package/src/index.ts +0 -26
- package/src/keyboard/index.ts +0 -112
- package/src/keyboard/shortcut.ts +0 -200
- package/src/model/BaseModel.ts +0 -250
- package/src/model/EditConfigModel.ts +0 -334
- package/src/model/GraphModel.ts +0 -1788
- package/src/model/NestedTransformModel.ts +0 -121
- package/src/model/SnaplineModel.ts +0 -256
- package/src/model/TransformModel.ts +0 -258
- package/src/model/edge/BaseEdgeModel.ts +0 -777
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -672
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -949
- package/src/model/node/CircleNodeModel.ts +0 -91
- package/src/model/node/DiamondNodeModel.ts +0 -132
- package/src/model/node/EllipseNodeModel.ts +0 -98
- package/src/model/node/HtmlNodeModel.ts +0 -50
- package/src/model/node/PolygonNodeModel.ts +0 -150
- package/src/model/node/RectNodeModel.ts +0 -69
- package/src/model/node/TextNodeModel.ts +0 -54
- package/src/model/node/index.ts +0 -8
- package/src/options.ts +0 -145
- package/src/style/index.less +0 -261
- package/src/style/raw.ts +0 -220
- package/src/tool/MultipleSelectTool.tsx +0 -132
- package/src/tool/TextEditTool.tsx +0 -193
- package/src/tool/index.ts +0 -101
- package/src/typings.d.ts +0 -5
- package/src/util/animation.ts +0 -29
- package/src/util/browser.ts +0 -4
- package/src/util/compatible.ts +0 -15
- package/src/util/drag.ts +0 -220
- package/src/util/edge.ts +0 -1060
- package/src/util/geometry.ts +0 -55
- package/src/util/graph.ts +0 -46
- package/src/util/index.ts +0 -17
- package/src/util/matrix.ts +0 -129
- package/src/util/mobx.ts +0 -23
- package/src/util/node.ts +0 -543
- package/src/util/raf.ts +0 -28
- package/src/util/resize.ts +0 -606
- package/src/util/sampling.ts +0 -85
- package/src/util/theme.ts +0 -375
- package/src/util/uuid.ts +0 -26
- package/src/util/vector.ts +0 -93
- package/src/util/zIndex.ts +0 -6
- package/src/view/Anchor.tsx +0 -445
- package/src/view/Control.tsx +0 -512
- package/src/view/Graph.tsx +0 -141
- package/src/view/Rotate.tsx +0 -113
- package/src/view/behavior/dnd.ts +0 -162
- package/src/view/behavior/index.ts +0 -2
- package/src/view/behavior/snapline.ts +0 -16
- package/src/view/edge/AdjustPoint.tsx +0 -425
- package/src/view/edge/Arrow.tsx +0 -54
- package/src/view/edge/BaseEdge.tsx +0 -650
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -299
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -571
- package/src/view/node/CircleNode.tsx +0 -21
- package/src/view/node/DiamondNode.tsx +0 -24
- package/src/view/node/EllipseNode.tsx +0 -22
- package/src/view/node/HtmlNode.tsx +0 -95
- package/src/view/node/PolygonNode.tsx +0 -28
- package/src/view/node/RectNode.tsx +0 -30
- package/src/view/node/TextNode.tsx +0 -39
- package/src/view/node/index.ts +0 -8
- package/src/view/overlay/BackgroundOverlay.tsx +0 -34
- package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
- package/src/view/overlay/CanvasOverlay.tsx +0 -288
- package/src/view/overlay/Grid.tsx +0 -162
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -170
- package/src/view/overlay/SnaplineOverlay.tsx +0 -44
- package/src/view/overlay/ToolOverlay.tsx +0 -65
- package/src/view/overlay/getTransformHoc.tsx +0 -50
- package/src/view/overlay/index.ts +0 -8
- package/src/view/shape/Circle.tsx +0 -41
- package/src/view/shape/Ellipse.tsx +0 -42
- package/src/view/shape/Line.tsx +0 -39
- package/src/view/shape/Path.tsx +0 -22
- package/src/view/shape/Polygon.tsx +0 -91
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -169
- package/src/view/shape/index.ts +0 -8
- package/src/view/text/BaseText.tsx +0 -134
- package/src/view/text/LineText.tsx +0 -168
- package/src/view/text/index.ts +0 -2
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
package/src/common/keyboard.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import Mousetrap, { MousetrapInstance } from 'mousetrap'
|
|
2
|
-
import { forEach, isArray } from 'lodash-es'
|
|
3
|
-
import LogicFlow from '..'
|
|
4
|
-
|
|
5
|
-
export class Keyboard {
|
|
6
|
-
private target: HTMLElement
|
|
7
|
-
readonly mousetrap: MousetrapInstance
|
|
8
|
-
options: Required<Keyboard.Options>
|
|
9
|
-
|
|
10
|
-
constructor(options: Keyboard.Options) {
|
|
11
|
-
const { lf } = options
|
|
12
|
-
if (!options.keyboard) {
|
|
13
|
-
options.keyboard = { enabled: false }
|
|
14
|
-
}
|
|
15
|
-
this.options = options as Required<Keyboard.Options>
|
|
16
|
-
this.target = lf.container
|
|
17
|
-
this.mousetrap = new Mousetrap(this.target)
|
|
18
|
-
|
|
19
|
-
if (options.keyboard?.enabled) {
|
|
20
|
-
this.enable(true)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected formatKey(key: string) {
|
|
25
|
-
return key
|
|
26
|
-
.toLowerCase()
|
|
27
|
-
.replace(/\s/g, '')
|
|
28
|
-
.replace('delete', 'del')
|
|
29
|
-
.replace('cmd', 'command')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private getKeys(keys: string | string[]) {
|
|
33
|
-
return (isArray(keys) ? keys : [keys]).map((key) => this.formatKey(key))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get disabled() {
|
|
37
|
-
return this.options.keyboard?.enabled !== true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
on(
|
|
41
|
-
keys: string | string[],
|
|
42
|
-
callback: Keyboard.HandlerFunc,
|
|
43
|
-
action?: Keyboard.ActionType,
|
|
44
|
-
) {
|
|
45
|
-
this.mousetrap.bind(this.getKeys(keys), callback, action)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
off(keys: string | string[], action?: Keyboard.ActionType) {
|
|
49
|
-
this.mousetrap.unbind(this.getKeys(keys), action)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
enable(force: boolean) {
|
|
53
|
-
if (this.disabled || force) {
|
|
54
|
-
this.options.keyboard.enabled = true
|
|
55
|
-
if (this.target instanceof HTMLElement) {
|
|
56
|
-
this.target.setAttribute('tabindex', '-1')
|
|
57
|
-
// 去掉节点被选中时 container 出现的边框
|
|
58
|
-
this.target.style.outline = 'none'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
disable() {
|
|
64
|
-
if (!this.disabled) {
|
|
65
|
-
this.options.keyboard.enabled = false
|
|
66
|
-
if (this.target instanceof HTMLElement) {
|
|
67
|
-
this.target.removeAttribute('tabindex')
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
initShortcuts() {
|
|
73
|
-
const { shortcuts } = this.options.keyboard
|
|
74
|
-
if (shortcuts) {
|
|
75
|
-
if (isArray(shortcuts)) {
|
|
76
|
-
forEach(shortcuts, ({ keys, callback, action }) => {
|
|
77
|
-
this.on(keys, callback, action)
|
|
78
|
-
})
|
|
79
|
-
} else {
|
|
80
|
-
const { keys, callback, action } = shortcuts
|
|
81
|
-
this.on(keys, callback, action)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export namespace Keyboard {
|
|
88
|
-
export type ActionType = 'keypress' | 'keydown' | 'keyup'
|
|
89
|
-
export type HandlerFunc = (e: KeyboardEvent) => void
|
|
90
|
-
|
|
91
|
-
export interface Shortcut {
|
|
92
|
-
keys: string | string[]
|
|
93
|
-
callback: HandlerFunc
|
|
94
|
-
action?: ActionType
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface KeyboardDef {
|
|
98
|
-
enabled: boolean
|
|
99
|
-
shortcuts?: Shortcut | Shortcut[]
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface Options {
|
|
103
|
-
lf: LogicFlow
|
|
104
|
-
keyboard?: KeyboardDef
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default Keyboard
|
package/src/common/matrix.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Vector } from './vector'
|
|
2
|
-
|
|
3
|
-
export class Matrix extends Array {
|
|
4
|
-
rows: number
|
|
5
|
-
columns: number
|
|
6
|
-
|
|
7
|
-
constructor(...vectors: any[]) {
|
|
8
|
-
super(vectors.length)
|
|
9
|
-
this.fill(new Array(3))
|
|
10
|
-
vectors.forEach((v: any, index: number) => {
|
|
11
|
-
this[index] = v
|
|
12
|
-
})
|
|
13
|
-
this.columns = vectors[0].length
|
|
14
|
-
this.rows = vectors.length
|
|
15
|
-
Object.setPrototypeOf(this, Matrix.prototype)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getRow(index: number) {
|
|
19
|
-
return this[index]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getColumn(index: number) {
|
|
23
|
-
return [...this.map((row: number[]) => row[index])]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 转置
|
|
27
|
-
transpose() {
|
|
28
|
-
const rows: any[] = []
|
|
29
|
-
for (let i = 0; i < this.columns; i++) {
|
|
30
|
-
rows.push(this.getColumn(i))
|
|
31
|
-
}
|
|
32
|
-
return new Matrix(...rows)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 叉乘
|
|
36
|
-
cross(m1: Matrix) {
|
|
37
|
-
const arr = new Array(this.rows).fill('').map((): any => [])
|
|
38
|
-
if (this.columns === m1.rows) {
|
|
39
|
-
for (let i = 0; i < this.rows; i++) {
|
|
40
|
-
const row = this.getRow(i)
|
|
41
|
-
for (let j = 0; j < m1.columns; j++) {
|
|
42
|
-
const column = m1.getColumn(j)
|
|
43
|
-
arr[i][j] = row.reduce(
|
|
44
|
-
(prev: number, r: number, index: number) =>
|
|
45
|
-
prev + r * column[index],
|
|
46
|
-
0,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return new Matrix(...arr)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 返回二维坐标(降维)
|
|
55
|
-
to2D() {
|
|
56
|
-
return this.map((item: any) => [item[0], item[1]])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
toString(): string {
|
|
60
|
-
const [[a, b], [c, d], [e, f]] = this
|
|
61
|
-
return `matrix(${a} ${b} ${c} ${d} ${e} ${f})`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
translate(tx: number, ty: number): Matrix {
|
|
65
|
-
return this.cross(new TranslateMatrix(tx, ty))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
rotate(angle: number): Matrix {
|
|
69
|
-
return this.cross(new RotateMatrix(angle))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
scale(sx: number, sy: number): Matrix {
|
|
73
|
-
return this.cross(new ScaleMatrix(sx, sy))
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export class RotateMatrix extends Matrix {
|
|
78
|
-
constructor(theta: number) {
|
|
79
|
-
super(
|
|
80
|
-
new Vector(+Math.cos(theta).toFixed(2), +Math.sin(theta).toFixed(2), 0),
|
|
81
|
-
new Vector(-Math.sin(theta).toFixed(2), +Math.cos(theta).toFixed(2), 0),
|
|
82
|
-
new Vector(0, 0, 1),
|
|
83
|
-
)
|
|
84
|
-
Object.setPrototypeOf(this, RotateMatrix.prototype)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
inverse() {
|
|
88
|
-
return this.transpose()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class ScaleMatrix extends Matrix {
|
|
93
|
-
private readonly sx: number
|
|
94
|
-
private readonly sy: number
|
|
95
|
-
|
|
96
|
-
constructor(sx: number, sy: number) {
|
|
97
|
-
super(new Vector(sx, 0, 0), new Vector(0, sy, 0), new Vector(0, 0, 1))
|
|
98
|
-
this.sx = sx
|
|
99
|
-
this.sy = sy
|
|
100
|
-
Object.setPrototypeOf(this, ScaleMatrix.prototype)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
inverse() {
|
|
104
|
-
return new ScaleMatrix(1 / this.sx, 1 / this.sy)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export class TranslateMatrix extends Matrix {
|
|
109
|
-
private readonly tx: number
|
|
110
|
-
private readonly ty: number
|
|
111
|
-
|
|
112
|
-
constructor(tx: number, ty: number) {
|
|
113
|
-
super(new Vector(1, 0, 0), new Vector(0, 1, 0), new Vector(tx, ty, 1))
|
|
114
|
-
this.tx = tx
|
|
115
|
-
this.ty = ty
|
|
116
|
-
Object.setPrototypeOf(this, TranslateMatrix.prototype)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
inverse() {
|
|
120
|
-
return new TranslateMatrix(-this.tx, -this.ty)
|
|
121
|
-
}
|
|
122
|
-
}
|
package/src/common/vector.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
function isVector(a1: any, a2: any): boolean {
|
|
2
|
-
return a1 instanceof Vector && a2 instanceof Vector
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
class Base extends Array {
|
|
6
|
-
x: number
|
|
7
|
-
y: number
|
|
8
|
-
z: number
|
|
9
|
-
|
|
10
|
-
constructor(x: number, y: number, z: number) {
|
|
11
|
-
super(3)
|
|
12
|
-
this[0] = x
|
|
13
|
-
this[1] = y
|
|
14
|
-
this[2] = z
|
|
15
|
-
this.x = x
|
|
16
|
-
this.y = y
|
|
17
|
-
this.z = z
|
|
18
|
-
Object.setPrototypeOf(this, Base.prototype)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
add(v1: Vector | Point): Vector | Point {
|
|
22
|
-
if (isVector(this, v1)) {
|
|
23
|
-
return new Vector(this.x + v1.x, this.y + v1.y)
|
|
24
|
-
}
|
|
25
|
-
const z = this.z + v1.z
|
|
26
|
-
return new Point((this.x + v1.x) / z, (this.y + v1.y) / z)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
subtract(v1: Vector | Point): Vector | Point {
|
|
30
|
-
if (isVector(this, v1)) {
|
|
31
|
-
return new Vector(this.x - v1.x, this.y - v1.y)
|
|
32
|
-
}
|
|
33
|
-
const z = this.z - v1.z
|
|
34
|
-
return z === 0
|
|
35
|
-
? new Vector(this.x - v1.x, this.y - v1.y)
|
|
36
|
-
: new Point((this.x - v1.x) / z, (this.y - v1.y) / z)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class Vector extends Base {
|
|
41
|
-
constructor(x: number, y: number, z?: number) {
|
|
42
|
-
super(x, y, z ?? 0)
|
|
43
|
-
Object.setPrototypeOf(this, Vector.prototype)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
toString(): string {
|
|
47
|
-
return 'Vector'
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
dot(v1: Vector) {
|
|
51
|
-
return v1.reduce((prev, cur, index) => prev + cur * this[index])
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
cross(v1: Vector) {
|
|
55
|
-
return new Vector(
|
|
56
|
-
this.y * v1.z - this.z * v1.y,
|
|
57
|
-
this.z * v1.x - this.x * v1.z,
|
|
58
|
-
this.x * v1.y - this.y * v1.x,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getLength() {
|
|
63
|
-
return Math.hypot(this.x, this.y)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
normalize() {
|
|
67
|
-
const len = this.getLength()
|
|
68
|
-
return new Vector(this.x / len, this.y / len)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
crossZ(v1: Vector) {
|
|
72
|
-
return this.x * v1.y - this.y * v1.x
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
angle(v1: Vector) {
|
|
76
|
-
const negative = this.crossZ(v1)
|
|
77
|
-
const r = Math.acos(this.normalize().dot(v1.normalize()))
|
|
78
|
-
return negative >= 0 ? r : -r
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
class Point extends Base {
|
|
83
|
-
constructor(x: number, y: number) {
|
|
84
|
-
super(x, y, 1)
|
|
85
|
-
Object.setPrototypeOf(this, Point.prototype)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
toString(): string {
|
|
89
|
-
return 'Point'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { Vector, Point }
|
package/src/constant/index.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_VISIBLE_SPACE = 200
|
|
2
|
-
export const ELEMENT_MAX_Z_INDEX = 9999
|
|
3
|
-
|
|
4
|
-
export const DEFAULT_GRID_SIZE = 10
|
|
5
|
-
|
|
6
|
-
export enum ElementState {
|
|
7
|
-
DEFAULT = 1, // 默认显示
|
|
8
|
-
TEXT_EDIT, // 此元素正在进行文本编辑
|
|
9
|
-
SHOW_MENU, // 显示菜单,废弃请使用菜单插件
|
|
10
|
-
ALLOW_CONNECT, // 此元素允许作为当前边的目标节点
|
|
11
|
-
NOT_ALLOW_CONNECT, // 此元素不允许作为当前边的目标节点
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export enum ElementType {
|
|
15
|
-
NODE = 'node',
|
|
16
|
-
EDGE = 'edge',
|
|
17
|
-
GRAPH = 'graph',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export enum ModelType {
|
|
21
|
-
NODE = 'node',
|
|
22
|
-
CIRCLE_NODE = 'circle-node',
|
|
23
|
-
POLYGON_NODE = 'polygon-node',
|
|
24
|
-
RECT_NODE = 'rect-node',
|
|
25
|
-
TEXT_NODE = 'text-node',
|
|
26
|
-
ELLIPSE_NODE = 'ellipse-node',
|
|
27
|
-
DIAMOND_NODE = 'diamond-node',
|
|
28
|
-
HTML_NODE = 'html-node',
|
|
29
|
-
CUSTOM_HTML_NODE = 'custom-html-node',
|
|
30
|
-
EDGE = 'edge',
|
|
31
|
-
LINE_EDGE = 'line-edge',
|
|
32
|
-
POLYLINE_EDGE = 'polyline-edge',
|
|
33
|
-
BEZIER_EDGE = 'bezier-edge',
|
|
34
|
-
GRAPH = 'graph',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export enum EventType {
|
|
38
|
-
ELEMENT_CLICK = 'element:click', // 是 node:click & edge:click 的并集
|
|
39
|
-
|
|
40
|
-
// Node events
|
|
41
|
-
NODE_ADD = 'node:add',
|
|
42
|
-
NODE_DELETE = 'node:delete',
|
|
43
|
-
NODE_CLICK = 'node:click',
|
|
44
|
-
NODE_DBCLICK = 'node:dbclick',
|
|
45
|
-
|
|
46
|
-
NODE_GROUP_COPY = 'node:group-copy-add',
|
|
47
|
-
NODE_DND_ADD = 'node:dnd-add',
|
|
48
|
-
NODE_DND_DRAG = 'node:dnd-drag',
|
|
49
|
-
NODE_MOUSEDOWN = 'node:mousedown',
|
|
50
|
-
NODE_DRAGSTART = 'node:dragstart',
|
|
51
|
-
NODE_DRAG = 'node:drag',
|
|
52
|
-
NODE_DROP = 'node:drop',
|
|
53
|
-
NODE_MOUSEUP = 'node:mouseup',
|
|
54
|
-
NODE_MOUSEMOVE = 'node:mousemove',
|
|
55
|
-
NODE_MOUSEENTER = 'node:mouseenter',
|
|
56
|
-
NODE_MOUSELEAVE = 'node:mouseleave',
|
|
57
|
-
NODE_CONTEXTMENU = 'node:contextmenu',
|
|
58
|
-
NODE_ROTATE = 'node:rotate',
|
|
59
|
-
NODE_RESIZE = 'node:resize',
|
|
60
|
-
NODE_FOCUS = 'node:focus',
|
|
61
|
-
NODE_BLUR = 'node:blur',
|
|
62
|
-
|
|
63
|
-
// 节点 properties 变化事件
|
|
64
|
-
NODE_PROPERTIES_CHANGE = 'node:properties-change',
|
|
65
|
-
NODE_PROPERTIES_DELETE = 'node:properties-delete',
|
|
66
|
-
|
|
67
|
-
// Edge events
|
|
68
|
-
EDGE_ADD = 'edge:add',
|
|
69
|
-
EDGE_DELETE = 'edge:delete',
|
|
70
|
-
EDGE_CLICK = 'edge:click',
|
|
71
|
-
EDGE_DBCLICK = 'edge:dbclick',
|
|
72
|
-
EDGE_FOCUS = 'edge:focus',
|
|
73
|
-
EDGE_BLUR = 'edge:blur',
|
|
74
|
-
|
|
75
|
-
EDGE_MOUSEENTER = 'edge:mouseenter',
|
|
76
|
-
EDGE_MOUSELEAVE = 'edge:mouseleave',
|
|
77
|
-
EDGE_CONTEXTMENU = 'edge:contextmenu',
|
|
78
|
-
EDGE_ADJUST = 'edge:adjust',
|
|
79
|
-
EDGE_EXCHANGE_NODE = 'edge:exchange-node',
|
|
80
|
-
|
|
81
|
-
// Anchor events
|
|
82
|
-
ANCHOR_CLICK = 'anchor:click',
|
|
83
|
-
ANCHOR_MOUSEDOWN = 'anchor:mousedown',
|
|
84
|
-
ANCHOR_DRAGSTART = 'anchor:dragstart',
|
|
85
|
-
ANCHOR_DRAG = 'anchor:drag',
|
|
86
|
-
ANCHOR_DROP = 'anchor:drop',
|
|
87
|
-
ANCHOR_DRAGEND = 'anchor:dragend',
|
|
88
|
-
|
|
89
|
-
// Adjust point events
|
|
90
|
-
ADJUST_POINT_MOUSEDOWN = 'adjustPoint:mousedown',
|
|
91
|
-
ADJUST_POINT_MOUSEUP = 'adjustPoint:mouseup',
|
|
92
|
-
ADJUST_POINT_MOUSEMOVE = 'adjustPoint:mousemove',
|
|
93
|
-
ADJUST_POINT_DRAGSTART = 'adjustPoint:dragstart',
|
|
94
|
-
ADJUST_POINT_DRAG = 'adjustPoint:drag',
|
|
95
|
-
ADJUST_POINT_DROP = 'adjustPoint:drop',
|
|
96
|
-
ADJUST_POINT_DRAGEND = 'adjustPoint:dragend',
|
|
97
|
-
|
|
98
|
-
// Blank events
|
|
99
|
-
BLANK_MOUSEDOWN = 'blank:mousedown',
|
|
100
|
-
BLANK_DRAGSTART = 'blank:dragstart',
|
|
101
|
-
BLANK_DRAG = 'blank:drag',
|
|
102
|
-
BLANK_DROP = 'blank:drop',
|
|
103
|
-
BLANK_MOUSEMOVE = 'blank:mousemove',
|
|
104
|
-
BLANK_CANVAS_MOUSEMOVE = 'blank:canvas-mousemove',
|
|
105
|
-
BLANK_MOUSEUP = 'blank:mouseup',
|
|
106
|
-
BLANK_CLICK = 'blank:click',
|
|
107
|
-
BLANK_CONTEXTMENU = 'blank:contextmenu',
|
|
108
|
-
|
|
109
|
-
// Selection events
|
|
110
|
-
SELECTION_MOUSEDOWN = 'selection:mousedown',
|
|
111
|
-
SELECTION_DRAGSTART = 'selection:dragstart',
|
|
112
|
-
SELECTION_DRAG = 'selection:drag',
|
|
113
|
-
SELECTION_DROP = 'selection:drop',
|
|
114
|
-
SELECTION_MOUSEMOVE = 'selection:mousemove',
|
|
115
|
-
SELECTION_MOUSEUP = 'selection:mouseup',
|
|
116
|
-
SELECTION_CONTEXTMENU = 'selection:contextmenu',
|
|
117
|
-
CONNECTION_NOT_ALLOWED = 'connection:not-allowed',
|
|
118
|
-
|
|
119
|
-
// Text events
|
|
120
|
-
TEXT_MOUSEDOWN = 'text:mousedown',
|
|
121
|
-
TEXT_DRAGSTART = 'text:dragstart',
|
|
122
|
-
TEXT_DRAG = 'text:drag',
|
|
123
|
-
TEXT_DROP = 'text:drop',
|
|
124
|
-
TEXT_CLICK = 'text:click',
|
|
125
|
-
TEXT_DBCLICK = 'text:dbclick',
|
|
126
|
-
TEXT_BLUR = 'text:blur',
|
|
127
|
-
TEXT_MOUSEMOVE = 'text:mousemove',
|
|
128
|
-
TEXT_MOUSEUP = 'text:mouseup',
|
|
129
|
-
TEXT_FOCUS = 'text:focus',
|
|
130
|
-
TEXT_ADD = 'text:add',
|
|
131
|
-
TEXT_UPDATE = 'text:update',
|
|
132
|
-
TEXT_CLEAR = 'text:clear',
|
|
133
|
-
|
|
134
|
-
// label events
|
|
135
|
-
LABEL_MOUSEDOWN = 'label:mousedown',
|
|
136
|
-
LABEL_DRAGSTART = 'label:dragstart',
|
|
137
|
-
LABEL_DRAG = 'label:drag',
|
|
138
|
-
LABEL_DROP = 'label:drop',
|
|
139
|
-
LABEL_CLICK = 'label:click',
|
|
140
|
-
LABEL_DBCLICK = 'label:dbclick',
|
|
141
|
-
LABEL_BLUR = 'label:blur',
|
|
142
|
-
LABEL_MOUSEMOVE = 'label:mousemove',
|
|
143
|
-
LABEL_MOUSEUP = 'label:mouseup',
|
|
144
|
-
LABEL_FOCUS = 'label:focus',
|
|
145
|
-
LABEL_ADD = 'label:add',
|
|
146
|
-
LABEL_UPDATE = 'label:update',
|
|
147
|
-
LABEL_CLEAR = 'label:clear',
|
|
148
|
-
LABEL_DELETE = 'label:delete',
|
|
149
|
-
LABEL_SHOULD_ADD = 'label:should-add',
|
|
150
|
-
LABEL_BATCH_ADD = 'label:batch-add',
|
|
151
|
-
LABEL_SHOULD_UPDATE = 'label:should-update',
|
|
152
|
-
LABEL_SHOULD_DELETE = 'label:should-delete',
|
|
153
|
-
LABEL_BATCH_DELETE = 'label:batch-delete',
|
|
154
|
-
LABEL_NOT_ALLOWED_ADD = 'label:not-allowed-add',
|
|
155
|
-
|
|
156
|
-
// Other events
|
|
157
|
-
HISTORY_CHANGE = 'history:change',
|
|
158
|
-
GRAPH_TRANSFORM = 'graph:transform',
|
|
159
|
-
GRAPH_RENDERED = 'graph:rendered',
|
|
160
|
-
GRAPH_UPDATED = 'graph:updated',
|
|
161
|
-
EDIT_CONFIG_CHANGED = 'editConfig:changed',
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export enum OverlapMode {
|
|
165
|
-
STATIC = -1, // 静态(元素层级不随点击变化)
|
|
166
|
-
DEFAULT = 0, // 默认
|
|
167
|
-
INCREASE = 1, // 递增
|
|
168
|
-
EDGE_TOP = 2, // 边固定在顶部
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export enum SegmentDirection {
|
|
172
|
-
HORIZONTAL = 'horizontal',
|
|
173
|
-
VERTICAL = 'vertical',
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export enum TextMode {
|
|
177
|
-
TEXT = 'text',
|
|
178
|
-
LABEL = 'label',
|
|
179
|
-
}
|
package/src/event/event.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# EventCenter
|
|
2
|
-
|
|
3
|
-
`eventCenter` 是 LogicFlow 内部的通讯中心,通过 `eventCenter` 来发布事件或者监听事件,以低耦合的方式使两个实例产生交互。
|
|
4
|
-
|
|
5
|
-
在开发过程中,使用 `eventCenter` 也需要遵循一些规范。
|
|
6
|
-
|
|
7
|
-
## 事件名
|
|
8
|
-
|
|
9
|
-
### 规范
|
|
10
|
-
|
|
11
|
-
命名遵循 `namespace:eventName` 的结构,同类 eventName 通过 namespace 来区分。
|
|
12
|
-
|
|
13
|
-
比如 node 和 edge 抛出的都是 click 事件,但是观察者可能是不同群体,通过 namespace 使得事件监听更精确,不容易出错。
|
|
14
|
-
|
|
15
|
-
目前 core 包中定义的 namespace 包括:
|
|
16
|
-
|
|
17
|
-
- `node`:节点事件
|
|
18
|
-
- `edge`:边事件
|
|
19
|
-
- `anchor`:锚点事件
|
|
20
|
-
- `blank`:画布空白区域事件
|
|
21
|
-
- `history`:历史记录事件
|
|
22
|
-
- `selection`:选区事件
|
|
23
|
-
|
|
24
|
-
### 开发注意
|
|
25
|
-
|
|
26
|
-
内部均通过 `eventCenter` 来抛出事件,包括以下两种情况:
|
|
27
|
-
|
|
28
|
-
- `graphModel` 中通过 `this.eventCenter` 调用 `eventCenter` 对象的 `emit` 方法抛出事件。
|
|
29
|
-
- 组件通过 `props` 获取到 `eventCenter` 实例对象,然后在组件内部调用 `eventCenter` 的 `emit` 方法来抛出事件。
|
|
30
|
-
- 部分组件会从 `props` 中直接获取 `eventCenter` 实例
|
|
31
|
-
- 而另一部分组件则需要从 `props` 中获取 `graphModel` 实例,然后通过 `graphModel.eventCenter` 获取 `eventCenter` 实例
|
|
32
|
-
|
|
33
|
-
用户可以通过 LogicFlow 的实例 `lf` 去监听我们抛出的事件。
|
|
34
|
-
|
|
35
|
-
如果组件内部监听了 `eventCenter` 事件,在组件销毁的时候,需要取消这些监听。
|
|
36
|
-
|
|
37
|
-
## 事件对象
|
|
38
|
-
|
|
39
|
-
在使用 `emit` 方法抛出事件时,可以传递一个对象作为第二个参数,该对象将作为对应的事件监听器的回调函数的入参。
|
|
40
|
-
|
|
41
|
-
事件对象可以包含任何与当前事件相关的信息,比如节点的 id,边的 id,原生鼠标事件对象等。
|
|
42
|
-
|
|
43
|
-
以 `node:click` 事件为例:
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
// 抛出 node:click 事件
|
|
47
|
-
eventCenter.emit('node:click', {
|
|
48
|
-
data: {
|
|
49
|
-
// 节点数据
|
|
50
|
-
},
|
|
51
|
-
e: MouseEvent,
|
|
52
|
-
position: {
|
|
53
|
-
// 鼠标点击的位置信息
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// 监听 node:click 事件
|
|
58
|
-
eventCenter.on('node:click', (event) => {
|
|
59
|
-
console.log(event); // event 即为抛出事件时传递的对象
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// 使用解构赋值可以便捷地获取事件对象中的信息
|
|
63
|
-
eventCenter.on('node:click', ({ data, e, position }) => {
|
|
64
|
-
console.log(data, e, position);
|
|
65
|
-
});
|
|
66
|
-
```
|