@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.
Files changed (236) hide show
  1. package/dist/index.css +3 -2
  2. package/dist/index.min.js +1 -1
  3. package/dist/index.min.js.map +1 -1
  4. package/es/LogicFlow.d.ts +9 -0
  5. package/es/LogicFlow.js +0 -1
  6. package/es/constant/index.d.ts +1 -1
  7. package/es/constant/index.js +1 -1
  8. package/es/constant/theme.d.ts +136 -0
  9. package/es/constant/theme.js +680 -0
  10. package/es/index.css +3 -2
  11. package/es/model/GraphModel.d.ts +10 -2
  12. package/es/model/GraphModel.js +48 -14
  13. package/es/model/TransformModel.js +9 -9
  14. package/es/model/edge/BaseEdgeModel.js +7 -2
  15. package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
  16. package/es/model/edge/PolylineEdgeModel.js +136 -7
  17. package/es/model/node/BaseNodeModel.d.ts +12 -1
  18. package/es/model/node/BaseNodeModel.js +9 -2
  19. package/es/model/node/HtmlNodeModel.d.ts +12 -0
  20. package/es/model/node/HtmlNodeModel.js +19 -0
  21. package/es/model/node/PolygonNodeModel.js +3 -3
  22. package/es/options.d.ts +4 -2
  23. package/es/style/index.css +3 -2
  24. package/es/style/index.less +3 -2
  25. package/es/style/raw.d.ts +1 -1
  26. package/es/style/raw.js +1 -1
  27. package/es/tool/MultipleSelectTool.js +10 -5
  28. package/es/util/drag.js +0 -1
  29. package/es/util/edge.d.ts +40 -1
  30. package/es/util/edge.js +43 -9
  31. package/es/util/geometry.d.ts +8 -0
  32. package/es/util/geometry.js +79 -0
  33. package/es/util/theme.d.ts +2 -65
  34. package/es/util/theme.js +4 -281
  35. package/es/view/Anchor.d.ts +1 -0
  36. package/es/view/Anchor.js +24 -21
  37. package/es/view/Control.d.ts +5 -0
  38. package/es/view/Control.js +44 -57
  39. package/es/view/edge/BaseEdge.js +9 -0
  40. package/es/view/edge/PolylineEdge.js +13 -2
  41. package/es/view/node/BaseNode.d.ts +1 -0
  42. package/es/view/node/BaseNode.js +23 -11
  43. package/es/view/node/HtmlNode.js +2 -4
  44. package/es/view/overlay/CanvasOverlay.js +5 -2
  45. package/es/view/overlay/Grid.d.ts +12 -1
  46. package/es/view/overlay/Grid.js +85 -23
  47. package/es/view/overlay/OutlineOverlay.d.ts +1 -0
  48. package/es/view/overlay/OutlineOverlay.js +18 -17
  49. package/es/view/overlay/gridConfig.d.ts +46 -0
  50. package/es/view/overlay/gridConfig.js +99 -0
  51. package/es/view/shape/Polygon.d.ts +0 -7
  52. package/es/view/shape/Polygon.js +12 -43
  53. package/lib/LogicFlow.d.ts +9 -0
  54. package/lib/LogicFlow.js +0 -1
  55. package/lib/constant/index.d.ts +1 -1
  56. package/lib/constant/index.js +16 -2
  57. package/lib/constant/theme.d.ts +136 -0
  58. package/lib/constant/theme.js +683 -0
  59. package/lib/index.css +3 -2
  60. package/lib/model/GraphModel.d.ts +10 -2
  61. package/lib/model/GraphModel.js +49 -15
  62. package/lib/model/TransformModel.js +9 -9
  63. package/lib/model/edge/BaseEdgeModel.js +7 -2
  64. package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
  65. package/lib/model/edge/PolylineEdgeModel.js +136 -7
  66. package/lib/model/node/BaseNodeModel.d.ts +12 -1
  67. package/lib/model/node/BaseNodeModel.js +9 -2
  68. package/lib/model/node/HtmlNodeModel.d.ts +12 -0
  69. package/lib/model/node/HtmlNodeModel.js +19 -0
  70. package/lib/model/node/PolygonNodeModel.js +3 -3
  71. package/lib/options.d.ts +4 -2
  72. package/lib/style/index.css +3 -2
  73. package/lib/style/index.less +3 -2
  74. package/lib/style/raw.d.ts +1 -1
  75. package/lib/style/raw.js +1 -1
  76. package/lib/tool/MultipleSelectTool.js +10 -5
  77. package/lib/util/drag.js +0 -1
  78. package/lib/util/edge.d.ts +40 -1
  79. package/lib/util/edge.js +43 -9
  80. package/lib/util/geometry.d.ts +8 -0
  81. package/lib/util/geometry.js +81 -1
  82. package/lib/util/theme.d.ts +2 -65
  83. package/lib/util/theme.js +15 -292
  84. package/lib/view/Anchor.d.ts +1 -0
  85. package/lib/view/Anchor.js +24 -21
  86. package/lib/view/Control.d.ts +5 -0
  87. package/lib/view/Control.js +44 -57
  88. package/lib/view/edge/BaseEdge.js +9 -0
  89. package/lib/view/edge/PolylineEdge.js +13 -2
  90. package/lib/view/node/BaseNode.d.ts +1 -0
  91. package/lib/view/node/BaseNode.js +22 -10
  92. package/lib/view/node/HtmlNode.js +1 -3
  93. package/lib/view/overlay/CanvasOverlay.js +5 -2
  94. package/lib/view/overlay/Grid.d.ts +12 -1
  95. package/lib/view/overlay/Grid.js +83 -21
  96. package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
  97. package/lib/view/overlay/OutlineOverlay.js +18 -17
  98. package/lib/view/overlay/gridConfig.d.ts +46 -0
  99. package/lib/view/overlay/gridConfig.js +104 -0
  100. package/lib/view/shape/Polygon.d.ts +0 -7
  101. package/lib/view/shape/Polygon.js +13 -45
  102. package/package.json +6 -1
  103. package/.turbo/turbo-build$colon$dev.log +0 -10
  104. package/.turbo/turbo-build.log +0 -33
  105. package/CHANGELOG.md +0 -1849
  106. package/__tests__/algorithm/egde.test.ts +0 -131
  107. package/__tests__/algorithm/index.test.ts +0 -74
  108. package/__tests__/algorithm/outline.test.ts +0 -43
  109. package/__tests__/bugs/1545-spec.test.ts +0 -42
  110. package/__tests__/event/event.test.ts +0 -22
  111. package/__tests__/history/history.test.ts +0 -28
  112. package/__tests__/logicflow.test.ts +0 -575
  113. package/__tests__/model/graphmodel.test.ts +0 -87
  114. package/__tests__/util/compatible.test.ts +0 -48
  115. package/__tests__/util/edge.test.ts +0 -224
  116. package/__tests__/util/geometry.test.ts +0 -14
  117. package/__tests__/util/graph.test.ts +0 -16
  118. package/__tests__/util/matrix.test.ts +0 -41
  119. package/__tests__/util/node.test.ts +0 -68
  120. package/__tests__/util/sampling.test.ts +0 -12
  121. package/__tests__/util/vector.test.ts +0 -50
  122. package/__tests__/util/zIndex.test.ts +0 -10
  123. package/src/LogicFlow.tsx +0 -2008
  124. package/src/algorithm/edge.ts +0 -67
  125. package/src/algorithm/index.ts +0 -70
  126. package/src/algorithm/outline.ts +0 -77
  127. package/src/algorithm/rotate.ts +0 -55
  128. package/src/common/drag.ts +0 -219
  129. package/src/common/history.ts +0 -108
  130. package/src/common/index.ts +0 -6
  131. package/src/common/keyboard.ts +0 -108
  132. package/src/common/matrix.ts +0 -122
  133. package/src/common/vector.ts +0 -93
  134. package/src/constant/index.ts +0 -179
  135. package/src/event/event.md +0 -66
  136. package/src/event/eventArgs.ts +0 -643
  137. package/src/event/eventEmitter.ts +0 -156
  138. package/src/history/index.ts +0 -119
  139. package/src/index.less +0 -1
  140. package/src/index.ts +0 -26
  141. package/src/keyboard/index.ts +0 -112
  142. package/src/keyboard/shortcut.ts +0 -200
  143. package/src/model/BaseModel.ts +0 -250
  144. package/src/model/EditConfigModel.ts +0 -334
  145. package/src/model/GraphModel.ts +0 -1788
  146. package/src/model/NestedTransformModel.ts +0 -121
  147. package/src/model/SnaplineModel.ts +0 -256
  148. package/src/model/TransformModel.ts +0 -258
  149. package/src/model/edge/BaseEdgeModel.ts +0 -777
  150. package/src/model/edge/BezierEdgeModel.ts +0 -197
  151. package/src/model/edge/LineEdgeModel.ts +0 -36
  152. package/src/model/edge/PolylineEdgeModel.ts +0 -672
  153. package/src/model/edge/index.ts +0 -4
  154. package/src/model/index.ts +0 -9
  155. package/src/model/node/BaseNodeModel.ts +0 -949
  156. package/src/model/node/CircleNodeModel.ts +0 -91
  157. package/src/model/node/DiamondNodeModel.ts +0 -132
  158. package/src/model/node/EllipseNodeModel.ts +0 -98
  159. package/src/model/node/HtmlNodeModel.ts +0 -50
  160. package/src/model/node/PolygonNodeModel.ts +0 -150
  161. package/src/model/node/RectNodeModel.ts +0 -69
  162. package/src/model/node/TextNodeModel.ts +0 -54
  163. package/src/model/node/index.ts +0 -8
  164. package/src/options.ts +0 -145
  165. package/src/style/index.less +0 -261
  166. package/src/style/raw.ts +0 -220
  167. package/src/tool/MultipleSelectTool.tsx +0 -132
  168. package/src/tool/TextEditTool.tsx +0 -193
  169. package/src/tool/index.ts +0 -101
  170. package/src/typings.d.ts +0 -5
  171. package/src/util/animation.ts +0 -29
  172. package/src/util/browser.ts +0 -4
  173. package/src/util/compatible.ts +0 -15
  174. package/src/util/drag.ts +0 -220
  175. package/src/util/edge.ts +0 -1060
  176. package/src/util/geometry.ts +0 -55
  177. package/src/util/graph.ts +0 -46
  178. package/src/util/index.ts +0 -17
  179. package/src/util/matrix.ts +0 -129
  180. package/src/util/mobx.ts +0 -23
  181. package/src/util/node.ts +0 -543
  182. package/src/util/raf.ts +0 -28
  183. package/src/util/resize.ts +0 -606
  184. package/src/util/sampling.ts +0 -85
  185. package/src/util/theme.ts +0 -375
  186. package/src/util/uuid.ts +0 -26
  187. package/src/util/vector.ts +0 -93
  188. package/src/util/zIndex.ts +0 -6
  189. package/src/view/Anchor.tsx +0 -445
  190. package/src/view/Control.tsx +0 -512
  191. package/src/view/Graph.tsx +0 -141
  192. package/src/view/Rotate.tsx +0 -113
  193. package/src/view/behavior/dnd.ts +0 -162
  194. package/src/view/behavior/index.ts +0 -2
  195. package/src/view/behavior/snapline.ts +0 -16
  196. package/src/view/edge/AdjustPoint.tsx +0 -425
  197. package/src/view/edge/Arrow.tsx +0 -54
  198. package/src/view/edge/BaseEdge.tsx +0 -650
  199. package/src/view/edge/BezierEdge.tsx +0 -101
  200. package/src/view/edge/LineEdge.tsx +0 -81
  201. package/src/view/edge/PolylineEdge.tsx +0 -299
  202. package/src/view/edge/index.ts +0 -6
  203. package/src/view/index.ts +0 -8
  204. package/src/view/node/BaseNode.tsx +0 -571
  205. package/src/view/node/CircleNode.tsx +0 -21
  206. package/src/view/node/DiamondNode.tsx +0 -24
  207. package/src/view/node/EllipseNode.tsx +0 -22
  208. package/src/view/node/HtmlNode.tsx +0 -95
  209. package/src/view/node/PolygonNode.tsx +0 -28
  210. package/src/view/node/RectNode.tsx +0 -30
  211. package/src/view/node/TextNode.tsx +0 -39
  212. package/src/view/node/index.ts +0 -8
  213. package/src/view/overlay/BackgroundOverlay.tsx +0 -34
  214. package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
  215. package/src/view/overlay/CanvasOverlay.tsx +0 -288
  216. package/src/view/overlay/Grid.tsx +0 -162
  217. package/src/view/overlay/ModificationOverlay.tsx +0 -31
  218. package/src/view/overlay/OutlineOverlay.tsx +0 -170
  219. package/src/view/overlay/SnaplineOverlay.tsx +0 -44
  220. package/src/view/overlay/ToolOverlay.tsx +0 -65
  221. package/src/view/overlay/getTransformHoc.tsx +0 -50
  222. package/src/view/overlay/index.ts +0 -8
  223. package/src/view/shape/Circle.tsx +0 -41
  224. package/src/view/shape/Ellipse.tsx +0 -42
  225. package/src/view/shape/Line.tsx +0 -39
  226. package/src/view/shape/Path.tsx +0 -22
  227. package/src/view/shape/Polygon.tsx +0 -91
  228. package/src/view/shape/Polyline.tsx +0 -31
  229. package/src/view/shape/Rect.tsx +0 -44
  230. package/src/view/shape/Text.tsx +0 -169
  231. package/src/view/shape/index.ts +0 -8
  232. package/src/view/text/BaseText.tsx +0 -134
  233. package/src/view/text/LineText.tsx +0 -168
  234. package/src/view/text/index.ts +0 -2
  235. package/stats.html +0 -4842
  236. package/tsconfig.json +0 -18
@@ -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
@@ -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
- }
@@ -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 }
@@ -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
- }
@@ -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
- ```