@logicflow/extension 2.1.5 → 2.2.0

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.
@@ -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
@@ -240,8 +236,6 @@ export class MiniMap {
240
236
  */
241
237
  public hide = () => {
242
238
  if (this.isShow) {
243
- // 隐藏小地图时摧毁实例
244
- destroyTeleportContainer(this.lfMap.graphModel.flowId)
245
239
  this.lf.off('graph:resize', this.onGraphResize)
246
240
  this.lfMap.destroy()
247
241
  // 保证重新创建实例时,小地图中内容偏移正确
@@ -363,14 +357,12 @@ export class MiniMap {
363
357
  history: false,
364
358
  snapline: false,
365
359
  disabledPlugins: this.disabledPlugins,
360
+ isMiniMap: true,
366
361
  })
367
362
  // minimap中禁用adapter。
368
363
  // this.lfMap.adapterIn = (a) => a
369
364
  // this.lfMap.adapterOut = (a) => a
370
365
 
371
- // 创建teleport容器(vue3中生效)
372
- createTeleportContainer(miniMapWrap, this.lfMap.graphModel.flowId)
373
-
374
366
  this.miniMapWrap = miniMapWrap
375
367
  this.createViewPort()
376
368
  miniMapWrap.addEventListener('click', this.mapClick)
@@ -624,8 +616,8 @@ export class MiniMap {
624
616
  const div = document.createElement('div')
625
617
  div.className = 'lf-minimap-viewport'
626
618
 
627
- // 拖拽预览视窗,主画布视口跟随移动
628
- div.addEventListener('mousedown', this.startDrag)
619
+ div.style.touchAction = 'none'
620
+ div.addEventListener('pointerdown', this.startDrag)
629
621
 
630
622
  // 禁止预览视窗的点击事件冒泡
631
623
  div.addEventListener('click', (e: MouseEvent) => {
@@ -634,9 +626,9 @@ export class MiniMap {
634
626
  this.viewport = div
635
627
  }
636
628
 
637
- private startDrag = (e: MouseEvent) => {
638
- document.addEventListener('mousemove', this.drag)
639
- document.addEventListener('mouseup', this.drop)
629
+ private startDrag = (e: PointerEvent) => {
630
+ document.addEventListener('pointermove', this.drag)
631
+ document.addEventListener('pointerup', this.drop)
640
632
  const { x, y } = e
641
633
  this.startPosition = { x, y }
642
634
  }
@@ -644,7 +636,7 @@ export class MiniMap {
644
636
  /**
645
637
  * 拖拽预览视窗过程中,更新主画布视口
646
638
  */
647
- private drag = (e: MouseEvent) => {
639
+ private drag = (e: PointerEvent) => {
648
640
  const { x, y } = e
649
641
  const translateX = (x - this.startPosition.x) / this.scale
650
642
  const translateY = (y - this.startPosition.y) / this.scale
@@ -667,8 +659,8 @@ export class MiniMap {
667
659
  * 拖拽预览视窗结束,移除拖拽事件
668
660
  */
669
661
  private drop = () => {
670
- document.removeEventListener('mousemove', this.drag)
671
- document.removeEventListener('mouseup', this.drop)
662
+ document.removeEventListener('pointermove', this.drag)
663
+ document.removeEventListener('pointerup', this.drop)
672
664
  }
673
665
 
674
666
  /**
@@ -687,7 +679,6 @@ export class MiniMap {
687
679
  }
688
680
 
689
681
  destroy() {
690
- destroyTeleportContainer(this.lfMap.graphModel.flowId)
691
682
  this.lf.off('graph:resize', this.onGraphResize)
692
683
  }
693
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: {
@@ -75,8 +76,8 @@ export class SelectionSelect {
75
76
  this.mouseDownInfo = null
76
77
 
77
78
  // 移除事件监听
78
- document.removeEventListener('mousemove', this.draw)
79
- document.removeEventListener('mouseup', this.drawOff)
79
+ document.removeEventListener('pointermove', this.draw)
80
+ document.removeEventListener('pointerup', this.drawOff)
80
81
  }
81
82
 
82
83
  /**
@@ -97,11 +98,11 @@ 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'
104
- this.container.addEventListener('mousedown', this.handleMouseDown)
104
+ this.container.style.touchAction = 'none'
105
+ this.container.addEventListener('pointerdown', this.handleMouseDown)
105
106
  } else {
106
107
  // 非独占模式:监听画布的 blank:mousedown 事件
107
108
  this.container.style.pointerEvents = 'none'
@@ -113,7 +114,7 @@ export class SelectionSelect {
113
114
  private removeEventListeners() {
114
115
  if (this.container) {
115
116
  this.container.style.pointerEvents = 'none'
116
- this.container.removeEventListener('mousedown', this.handleMouseDown)
117
+ this.container.removeEventListener('pointerdown', this.handleMouseDown)
117
118
  }
118
119
  // 移除 blank:mousedown 事件监听
119
120
  this.lf.off('blank:mousedown', this.handleBlankMouseDown)
@@ -122,15 +123,16 @@ export class SelectionSelect {
122
123
  /**
123
124
  * 处理画布空白处鼠标按下事件(非独占模式)
124
125
  */
125
- private handleBlankMouseDown = ({ e }: { e: MouseEvent }) => {
126
- this.handleMouseDown(e)
126
+ private handleBlankMouseDown = ({ e }: { e: MouseEvent | PointerEvent }) => {
127
+ this.handleMouseDown(e as PointerEvent)
127
128
  }
128
129
 
129
130
  /**
130
131
  * 处理鼠标按下事件
131
132
  */
132
- private handleMouseDown(e: MouseEvent) {
133
+ private handleMouseDown(e: PointerEvent) {
133
134
  if (!this.container || this.disabled) return
135
+ if (this.lf.graphModel.editConfigModel.isPinching) return
134
136
 
135
137
  // 禁用右键框选
136
138
  const isRightClick = e.button === 2
@@ -143,9 +145,12 @@ export class SelectionSelect {
143
145
  y: e.clientY,
144
146
  time: Date.now(),
145
147
  }
146
-
147
148
  // 记录原始设置并临时禁止画布移动
148
- this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph!
149
+ if (!this.originStatusSaved) {
150
+ // 为了防止在开启框选时用户多次点击画布导致缓存的stopMoveGraph变化,所以只在第一次点击时记录原始的stopMoveGraph issue #2263
151
+ this.originalStopMoveGraph = this.lf.getEditConfig().stopMoveGraph!
152
+ this.originStatusSaved = true
153
+ }
149
154
  this.lf.updateEditConfig({
150
155
  stopMoveGraph: true,
151
156
  })
@@ -167,8 +172,8 @@ export class SelectionSelect {
167
172
  this.container?.appendChild(wrapper)
168
173
  this.wrapper = wrapper
169
174
 
170
- document.addEventListener('mousemove', this.draw)
171
- document.addEventListener('mouseup', this.drawOff)
175
+ document.addEventListener('pointermove', this.draw)
176
+ document.addEventListener('pointerup', this.drawOff)
172
177
  }
173
178
 
174
179
  /**
@@ -207,7 +212,7 @@ export class SelectionSelect {
207
212
  if (this.wrapper && this.startPoint && this.endPoint) {
208
213
  // 记录上一次的结束点,用于触发 mouseup 事件
209
214
  const lastEndPoint = cloneDeep(this.endPoint)
210
- const lastEvent = new MouseEvent('mouseup', {
215
+ const lastEvent = new PointerEvent('pointerup', {
211
216
  clientX: lastEndPoint.x,
212
217
  clientY: lastEndPoint.y,
213
218
  })
@@ -218,7 +223,13 @@ export class SelectionSelect {
218
223
  this.close()
219
224
  }
220
225
 
221
- private draw = (ev: MouseEvent) => {
226
+ private draw = (ev: PointerEvent) => {
227
+ if (this.lf.graphModel.editConfigModel.isPinching) {
228
+ this.lf.updateEditConfig({ stopMoveGraph: this.originalStopMoveGraph })
229
+ this.originStatusSaved = false
230
+ this.cleanupSelectionState()
231
+ return
232
+ }
222
233
  const {
223
234
  domOverlayPosition: { x: x1, y: y1 },
224
235
  } = this.lf.getPointByClient(ev.clientX, ev.clientY)
@@ -248,7 +259,12 @@ export class SelectionSelect {
248
259
  }
249
260
  }
250
261
  }
251
- private drawOff = (e: MouseEvent) => {
262
+ private drawOff = (e: PointerEvent) => {
263
+ // 恢复原始的 stopMoveGraph 设置
264
+ this.lf.updateEditConfig({
265
+ stopMoveGraph: this.originalStopMoveGraph,
266
+ })
267
+ this.originStatusSaved = false
252
268
  // 处理鼠标抬起事件
253
269
  // 首先判断是否是点击,如果是,则清空框选
254
270
  if (this.mouseDownInfo) {
@@ -266,16 +282,11 @@ export class SelectionSelect {
266
282
 
267
283
  const curStartPoint = cloneDeep(this.startPoint)
268
284
  const curEndPoint = cloneDeep(this.endPoint)
269
- document.removeEventListener('mousemove', this.draw)
285
+ document.removeEventListener('pointermove', this.draw)
270
286
  if (!this.exclusiveMode) {
271
- document.removeEventListener('mouseup', this.drawOff)
287
+ document.removeEventListener('pointerup', this.drawOff)
272
288
  }
273
289
 
274
- // 恢复原始的 stopMoveGraph 设置
275
- this.lf.updateEditConfig({
276
- stopMoveGraph: this.originalStopMoveGraph,
277
- })
278
-
279
290
  if (curStartPoint && curEndPoint) {
280
291
  const { x, y } = curStartPoint
281
292
  const { x: x1, y: y1 } = curEndPoint
@@ -72,7 +72,7 @@ export class Label extends Component<ILabelProps, ILabelState> {
72
72
  element.setHovered(false)
73
73
  }
74
74
 
75
- handleMouseDown = (e: MouseEvent) => {
75
+ handleMouseDown = (e: PointerEvent) => {
76
76
  const { label, graphModel } = this.props
77
77
  const {
78
78
  editConfigModel: { nodeTextDraggable },
@@ -86,7 +86,7 @@ export class Label extends Component<ILabelProps, ILabelState> {
86
86
  this.stepDrag.handleMouseDown(e)
87
87
  }
88
88
  }
89
- handleMouseUp = (e: MouseEvent) => {
89
+ handleMouseUp = (e: PointerEvent) => {
90
90
  if (this.state.isDragging) {
91
91
  this.stepDrag.handleMouseUp(e)
92
92
  }
@@ -320,8 +320,8 @@ export class Label extends Component<ILabelProps, ILabelState> {
320
320
  id={`element-container-${id}`}
321
321
  className={classNames('lf-label-editor-container')}
322
322
  style={containerStyle}
323
- onMouseDown={this.handleMouseDown}
324
- onMouseUp={this.handleMouseUp}
323
+ onPointerDown={this.handleMouseDown}
324
+ onPointerUp={this.handleMouseUp}
325
325
  onClick={this.handleClick}
326
326
  onDblClick={this.handleDbClick}
327
327
  onBlur={this.handleBlur}