@logicflow/extension 2.1.4 → 2.1.6

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 (37) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +23 -0
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/es/bpmn-adapter/index.d.ts +84 -1
  6. package/es/bpmn-adapter/index.js +235 -12
  7. package/es/bpmn-adapter/json2xml.d.ts +10 -1
  8. package/es/bpmn-adapter/json2xml.js +28 -4
  9. package/es/bpmn-adapter/xml2json.js +2 -7
  10. package/es/components/mini-map/index.js +9 -7
  11. package/es/components/selection-select/index.d.ts +1 -0
  12. package/es/components/selection-select/index.js +11 -5
  13. package/es/tools/proximity-connect/index.d.ts +8 -0
  14. package/es/tools/proximity-connect/index.js +9 -4
  15. package/es/tools/snapshot/index.d.ts +8 -0
  16. package/es/tools/snapshot/index.js +2 -2
  17. package/lib/bpmn-adapter/index.d.ts +84 -1
  18. package/lib/bpmn-adapter/index.js +235 -12
  19. package/lib/bpmn-adapter/json2xml.d.ts +10 -1
  20. package/lib/bpmn-adapter/json2xml.js +29 -4
  21. package/lib/bpmn-adapter/xml2json.js +2 -7
  22. package/lib/components/mini-map/index.js +9 -7
  23. package/lib/components/selection-select/index.d.ts +1 -0
  24. package/lib/components/selection-select/index.js +11 -5
  25. package/lib/tools/proximity-connect/index.d.ts +8 -0
  26. package/lib/tools/proximity-connect/index.js +9 -4
  27. package/lib/tools/snapshot/index.d.ts +8 -0
  28. package/lib/tools/snapshot/index.js +2 -2
  29. package/package.json +5 -5
  30. package/src/bpmn-adapter/index.ts +256 -17
  31. package/src/bpmn-adapter/json2xml.ts +30 -4
  32. package/src/bpmn-adapter/xml2json.ts +2 -7
  33. package/src/components/mini-map/index.ts +11 -11
  34. package/src/components/selection-select/index.ts +11 -8
  35. package/src/tools/proximity-connect/index.ts +14 -4
  36. package/src/tools/snapshot/index.ts +10 -2
  37. package/stats.html +1 -1
@@ -1,8 +1,4 @@
1
1
  import LogicFlow from '@logicflow/core'
2
- import {
3
- createTeleportContainer,
4
- destroyTeleportContainer,
5
- } from '@logicflow/vue-node-registry'
6
2
 
7
3
  import Position = LogicFlow.Position
8
4
  import MiniMapOption = MiniMap.MiniMapOption
@@ -198,8 +194,6 @@ export class MiniMap {
198
194
  this.bounds = boundsInit
199
195
  this.elementAreaBounds = boundsInit
200
196
  this.viewPortBounds = boundsInit
201
- this.initMiniMap()
202
- lf.on('graph:resize', this.onGraphResize)
203
197
  }
204
198
 
205
199
  onGraphResize = () => {
@@ -230,8 +224,10 @@ export class MiniMap {
230
224
  */
231
225
  public show = (left?: number, top?: number) => {
232
226
  if (!this.isShow) {
227
+ this.initMiniMap()
228
+ this.lf.on('graph:resize', this.onGraphResize)
233
229
  this.createMiniMap(left, top)
234
- this.setView()
230
+ this.setView(true)
235
231
  }
236
232
  this.isShow = true
237
233
  }
@@ -240,6 +236,12 @@ export class MiniMap {
240
236
  */
241
237
  public hide = () => {
242
238
  if (this.isShow) {
239
+ this.lf.off('graph:resize', this.onGraphResize)
240
+ this.lfMap.destroy()
241
+ // 保证重新创建实例时,小地图中内容偏移正确
242
+ this.translateX = 0
243
+ this.translateY = 0
244
+
243
245
  this.removeMiniMap()
244
246
  this.lf.emit('miniMap:close', {})
245
247
  }
@@ -355,14 +357,12 @@ export class MiniMap {
355
357
  history: false,
356
358
  snapline: false,
357
359
  disabledPlugins: this.disabledPlugins,
360
+ isMiniMap: true,
358
361
  })
359
362
  // minimap中禁用adapter。
360
363
  // this.lfMap.adapterIn = (a) => a
361
364
  // this.lfMap.adapterOut = (a) => a
362
365
 
363
- // 创建teleport容器(vue3中生效)
364
- createTeleportContainer(miniMapWrap, this.lfMap.graphModel.flowId)
365
-
366
366
  this.miniMapWrap = miniMapWrap
367
367
  this.createViewPort()
368
368
  miniMapWrap.addEventListener('click', this.mapClick)
@@ -677,8 +677,8 @@ export class MiniMap {
677
677
  },
678
678
  })
679
679
  }
680
+
680
681
  destroy() {
681
- destroyTeleportContainer(this.lfMap.graphModel.flowId)
682
682
  this.lf.off('graph:resize', this.onGraphResize)
683
683
  }
684
684
  }
@@ -18,6 +18,7 @@ export class SelectionSelect {
18
18
  private disabled = true
19
19
  private isWholeNode = true
20
20
  private isWholeEdge = true
21
+ private originStatusSaved = false
21
22
  exclusiveMode = false // 框选独占模式:true 表示只能进行框选操作,false 表示可以同时进行其他画布操作
22
23
  // 用于区分选区和点击事件
23
24
  private mouseDownInfo: {
@@ -97,7 +98,6 @@ export class SelectionSelect {
97
98
 
98
99
  private addEventListeners() {
99
100
  if (!this.container) return
100
-
101
101
  if (this.exclusiveMode) {
102
102
  // 独占模式:监听 container 的 mousedown 事件
103
103
  this.container.style.pointerEvents = 'auto'
@@ -143,9 +143,12 @@ export class SelectionSelect {
143
143
  y: e.clientY,
144
144
  time: Date.now(),
145
145
  }
146
-
147
146
  // 记录原始设置并临时禁止画布移动
148
- this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph!
147
+ if (!this.originStatusSaved) {
148
+ // 为了防止在开启框选时用户多次点击画布导致缓存的stopMoveGraph变化,所以只在第一次点击时记录原始的stopMoveGraph issue #2263
149
+ this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph!
150
+ this.originStatusSaved = true
151
+ }
149
152
  this.lf.updateEditConfig({
150
153
  stopMoveGraph: true,
151
154
  })
@@ -249,6 +252,11 @@ export class SelectionSelect {
249
252
  }
250
253
  }
251
254
  private drawOff = (e: MouseEvent) => {
255
+ // 恢复原始的 stopMoveGraph 设置
256
+ this.lf.updateEditConfig({
257
+ stopMoveGraph: this.originalStopMoveGraph,
258
+ })
259
+ this.originStatusSaved = false
252
260
  // 处理鼠标抬起事件
253
261
  // 首先判断是否是点击,如果是,则清空框选
254
262
  if (this.mouseDownInfo) {
@@ -271,11 +279,6 @@ export class SelectionSelect {
271
279
  document.removeEventListener('mouseup', this.drawOff)
272
280
  }
273
281
 
274
- // 恢复原始的 stopMoveGraph 设置
275
- this.lf.updateEditConfig({
276
- stopMoveGraph: this.originalStopMoveGraph,
277
- })
278
-
279
282
  if (curStartPoint && curEndPoint) {
280
283
  const { x, y } = curStartPoint
281
284
  const { x: x1, y: y1 } = curEndPoint
@@ -15,11 +15,19 @@ export type ProximityConnectProps = {
15
15
  distance: number
16
16
  reverseDirection: boolean
17
17
  virtualEdgeStyle: Record<string, unknown>
18
+ /**
19
+ * proximityConnect 类型:
20
+ * - 'node': 节点-节点连接
21
+ * - 'anchor': 锚点-锚点连接
22
+ * - 'default': 节点-锚点连接
23
+ */
24
+ type: 'node' | 'anchor' | 'default'
18
25
  }
19
26
 
20
27
  export class ProximityConnect {
21
28
  static pluginName = 'proximityConnect'
22
29
  enable: boolean = true
30
+ type: 'node' | 'anchor' | 'default' = 'default'
23
31
  lf: LogicFlow // lf实例
24
32
  closestNode?: BaseNodeModel // 当前距离最近的节点
25
33
  currentDistance: number = Infinity // 当前间距
@@ -52,6 +60,7 @@ export class ProximityConnect {
52
60
  addEventListeners() {
53
61
  // 节点开始拖拽事件
54
62
  this.lf.graphModel.eventCenter.on('node:dragstart', ({ data }) => {
63
+ if (this.type === 'anchor') return
55
64
  if (!this.enable) return
56
65
  const { graphModel } = this.lf
57
66
  const { id } = data
@@ -59,13 +68,14 @@ export class ProximityConnect {
59
68
  })
60
69
  // 节点拖拽事件
61
70
  this.lf.graphModel.eventCenter.on('node:drag', () => {
71
+ if (this.type === 'anchor') return
62
72
  this.handleNodeDrag()
63
73
  })
64
74
  // 锚点开始拖拽事件
65
75
  this.lf.graphModel.eventCenter.on(
66
76
  'anchor:dragstart',
67
77
  ({ data, nodeModel }) => {
68
- if (!this.enable) return
78
+ if (!this.enable || this.type === 'node') return
69
79
  this.currentNode = nodeModel
70
80
  this.currentAnchor = data
71
81
  },
@@ -74,18 +84,18 @@ export class ProximityConnect {
74
84
  this.lf.graphModel.eventCenter.on(
75
85
  'anchor:drag',
76
86
  ({ e: { clientX, clientY } }) => {
77
- if (!this.enable) return
87
+ if (!this.enable || this.type === 'node') return
78
88
  this.handleAnchorDrag(clientX, clientY)
79
89
  },
80
90
  )
81
91
  // 节点、锚点拖拽结束事件
82
92
  this.lf.graphModel.eventCenter.on('node:drop', () => {
83
- if (!this.enable) return
93
+ if (!this.enable || this.type === 'anchor') return
84
94
  this.handleDrop()
85
95
  })
86
96
  // 锚点拖拽需要单独判断一下当前拖拽终点是否在某个锚点上,如果是,就不触发插件的连线,以免出现创建了两条连线的问题,表现见 issue 2140
87
97
  this.lf.graphModel.eventCenter.on('anchor:dragend', ({ e, edgeModel }) => {
88
- if (!this.enable) return
98
+ if (!this.enable || this.type === 'node') return
89
99
  const {
90
100
  canvasOverlayPosition: { x: eventX, y: eventY },
91
101
  } = this.lf.graphModel.getPointByClient({
@@ -35,6 +35,14 @@ export type ToImageOptions = {
35
35
  * - `true`:只导出画面区域内的可见元素
36
36
  */
37
37
  partial?: boolean
38
+ /**
39
+ * 导出图片时的安全系数,用于确保导出的图片能够容纳所有元素,默认值为 1.1
40
+ */
41
+ safetyFactor?: number
42
+ /**
43
+ * 导出图片时的安全边距,用于确保导出的图片能够容纳所有元素,默认值为 40
44
+ */
45
+ safetyMargin?: number
38
46
  }
39
47
 
40
48
  // Blob | base64
@@ -381,7 +389,7 @@ export class Snapshot {
381
389
  // 计算实际宽高,考虑缩放因素
382
390
  // 在宽画布情况下,getBoundingClientRect可能无法获取到所有元素的边界
383
391
  // 因此我们添加一个安全系数来确保能够容纳所有元素
384
- const safetyFactor = 1.1 // 安全系数,增加20%的空间
392
+ const safetyFactor = toImageOptions.safetyFactor || 1.1 // 安全系数,增加10%的空间
385
393
  const actualWidth = (bbox.width / SCALE_X) * safetyFactor
386
394
  const actualHeight = (bbox.height / SCALE_Y) * safetyFactor
387
395
 
@@ -394,7 +402,7 @@ export class Snapshot {
394
402
 
395
403
  // 宽高值 默认加padding 40,保证图形不会紧贴着下载图片
396
404
  // 为宽画布添加额外的安全边距,确保不会裁剪
397
- const safetyMargin = 40 // 额外的安全边距
405
+ const safetyMargin = toImageOptions.safetyMargin || 40 // 额外的安全边距
398
406
 
399
407
  // 获取当前浏览器类型,不同浏览器对canvas的限制不同
400
408
  const { maxCanvasDimension, otherMaxCanvasDimension } =