@logicflow/core 2.1.3 → 2.1.5

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.
@@ -144,10 +144,8 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
144
144
  } = this.graphModel
145
145
  this.isShowAdjustPoint = adjustEdgeStartAndEnd
146
146
  assign(this, pickEdgeConfig(data))
147
- const { overlapMode } = this.graphModel
148
- if (overlapMode === OverlapMode.INCREASE) {
149
- this.zIndex = data.zIndex || getZIndex()
150
- }
147
+ const { overlapMode, eventCenter } = this.graphModel
148
+ this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
151
149
  // 设置边的 anchors,也就是边的两个端点
152
150
  // 端点依赖于 edgeData 的 sourceNode 和 targetNode
153
151
  this.setAnchors()
@@ -155,6 +153,11 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
155
153
  this.initPoints()
156
154
  // 文本位置依赖于边上的所有拐点
157
155
  this.formatText(data)
156
+
157
+ eventCenter.on('overlap:change', (data) => {
158
+ const { overlapMode: newMode } = data
159
+ this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
160
+ })
158
161
  }
159
162
 
160
163
  /**
@@ -397,7 +400,13 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
397
400
  startPoint: assign({}, this.startPoint),
398
401
  endPoint: assign({}, this.endPoint),
399
402
  }
400
- if (this.graphModel.overlapMode === OverlapMode.INCREASE) {
403
+ // 因为默认模式和边在上模式下,对节点的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
404
+ // 所以只在递增模式和静态模式下设置zIndex
405
+ if (
406
+ [OverlapMode.INCREASE, OverlapMode.STATIC].includes(
407
+ this.graphModel.overlapMode,
408
+ )
409
+ ) {
401
410
  data.zIndex = this.zIndex
402
411
  }
403
412
  const { x, y, value } = this.text
@@ -745,6 +754,24 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
745
754
  this.updateStartPoint({ x: startPoint.x, y: startPoint.y })
746
755
  this.updateEndPoint({ x: endPoint.x, y: endPoint.y })
747
756
  }
757
+
758
+ // 堆叠模式变化时,更新zIndex
759
+ @action
760
+ updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
761
+ switch (overlapMode) {
762
+ case OverlapMode.DEFAULT:
763
+ this.zIndex = 0
764
+ break
765
+ case OverlapMode.EDGE_TOP:
766
+ this.zIndex = 1
767
+ break
768
+ case OverlapMode.INCREASE:
769
+ this.zIndex = defaultZIndex
770
+ break
771
+ default:
772
+ break
773
+ }
774
+ }
748
775
  }
749
776
 
750
777
  export default BaseEdgeModel
@@ -206,10 +206,12 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
206
206
  // TODO: 确认 constructor 中赋值 properties 是否必要,此处将 NodeConfig 中所有属性赋值给 this,包括 rotate、rotatable,resizable 等
207
207
  assign(this, pickNodeConfig(data))
208
208
 
209
- const { overlapMode } = this.graphModel
210
- if (overlapMode === OverlapMode.INCREASE) {
211
- this.zIndex = data.zIndex || getZIndex()
212
- }
209
+ const { overlapMode, eventCenter } = this.graphModel
210
+ this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
211
+ eventCenter.on('overlap:change', (data) => {
212
+ const { overlapMode: newMode } = data
213
+ this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
214
+ })
213
215
  }
214
216
 
215
217
  /**
@@ -339,7 +341,13 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
339
341
  if (this.rotate) {
340
342
  data.rotate = this.rotate
341
343
  }
342
- if (this.graphModel.overlapMode === OverlapMode.INCREASE) {
344
+ // 因为默认模式和节点在上模式下,对边的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
345
+ // 所以只在递增模式和静态模式下设置zIndex
346
+ if (
347
+ [OverlapMode.INCREASE, OverlapMode.STATIC].includes(
348
+ this.graphModel.overlapMode,
349
+ )
350
+ ) {
343
351
  data.zIndex = this.zIndex
344
352
  }
345
353
  if (value) {
@@ -914,6 +922,23 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
914
922
  @action updateAttributes(attributes: any) {
915
923
  assign(this, attributes)
916
924
  }
925
+ // 堆叠模式变化时,更新zIndex
926
+ @action
927
+ updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
928
+ switch (overlapMode) {
929
+ case OverlapMode.DEFAULT:
930
+ this.zIndex = 1
931
+ break
932
+ case OverlapMode.EDGE_TOP:
933
+ this.zIndex = 0
934
+ break
935
+ case OverlapMode.INCREASE:
936
+ this.zIndex = defaultZIndex
937
+ break
938
+ default:
939
+ break
940
+ }
941
+ }
917
942
  }
918
943
 
919
944
  export namespace BaseNodeModel {
@@ -42,6 +42,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
42
42
  mouseUpDrag?: boolean
43
43
  startTime?: number
44
44
  modelDisposer: IReactionDisposer
45
+ mouseDownPosition?: LogicFlow.Position
45
46
 
46
47
  constructor(props: IProps) {
47
48
  super()
@@ -249,6 +250,10 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
249
250
  } = graphModel
250
251
  model.isDragging = true
251
252
  const { clientX, clientY } = event!
253
+ const { x: mouseDownX, y: mouseDownY } = this.mouseDownPosition!
254
+ if (clientX - mouseDownX > gridSize || clientY - mouseDownY > gridSize) {
255
+ model.isDragging = true
256
+ }
252
257
  let {
253
258
  canvasOverlayPosition: { x, y },
254
259
  } = graphModel.getPointByClient({
@@ -336,9 +341,17 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
336
341
  // 节点拖拽进画布之后,不触发click事件相关emit
337
342
  // 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
338
343
  const isDragging = this.mouseUpDrag === false
344
+ const curTime = new Date().getTime()
339
345
  if (!this.startTime) return
346
+ const timeInterval = curTime - this.startTime
340
347
  const { model, graphModel } = this.props
341
- if (!isDragging) return // 如果是拖拽, 不触发click事件。
348
+ // 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
349
+ // 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
350
+ if (!isDragging && timeInterval > 300) return
351
+ if (!isDragging) {
352
+ this.onDragEnd()
353
+ this.handleMouseUp()
354
+ }
342
355
  // 节点数据,多为事件对象数据抛出
343
356
  const nodeData = model.getData()
344
357
  const position = graphModel.getPointByClient({
@@ -425,6 +438,7 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
425
438
 
426
439
  handleMouseDown = (ev: MouseEvent) => {
427
440
  const { model, graphModel } = this.props
441
+ this.mouseDownPosition = { x: ev.clientX, y: ev.clientY }
428
442
  this.startTime = new Date().getTime()
429
443
  const { editConfigModel } = graphModel
430
444
  if (editConfigModel.adjustNodePosition && model.draggable) {
@@ -440,6 +454,8 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
440
454
  }
441
455
 
442
456
  handleBlur = () => {
457
+ // 当节点通过自定义锚点实现节点删除时,这里props会变成undefined,需兼容一下
458
+ if (!this.props) return
443
459
  const { model, graphModel } = this.props
444
460
  graphModel.eventCenter.emit(EventType.NODE_BLUR, {
445
461
  data: model.getData(),