@logicflow/extension 2.0.17 → 2.0.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -1,5 +1,5 @@
1
- import LogicFlow, { BaseNodeModel } from '@logicflow/core'
2
- import { concat } from 'lodash-es'
1
+ import LogicFlow, { BaseEdgeModel, BaseNodeModel } from '@logicflow/core'
2
+ import { uniqBy, concat } from 'lodash-es'
3
3
 
4
4
  // 后续并入FlowPath
5
5
  const getPath = (id: string, lf: LogicFlow) => {
@@ -99,7 +99,7 @@ export class Highlight {
99
99
  this.enable = enable
100
100
  }
101
101
 
102
- setMode(mode: IMode) {
102
+ public setMode(mode: IMode) {
103
103
  this.mode = mode
104
104
  }
105
105
 
@@ -119,11 +119,14 @@ export class Highlight {
119
119
  model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id])
120
120
  model.targetNode.updateStyles(this.tempStyles[model.targetNode.id])
121
121
  }
122
+ this.lf.emit('highlight:single', {
123
+ data: model,
124
+ })
122
125
  }
123
126
 
124
127
  private highlightNeighbours(id: string) {
125
128
  const model = this.lf.getModelById(id)
126
-
129
+ let relateElements: (BaseNodeModel | BaseEdgeModel)[] = []
127
130
  if (model?.BaseType === 'node') {
128
131
  // 高亮节点
129
132
  model.updateStyles(this.tempStyles[id])
@@ -135,19 +138,41 @@ export class Highlight {
135
138
  concat(incomingEdges, outgoingEdges).forEach((edge) => {
136
139
  edge.updateStyles(this.tempStyles[edge.id])
137
140
  })
141
+ relateElements = uniqBy(
142
+ concat(
143
+ relateElements,
144
+ incomingNodes,
145
+ outgoingNodes,
146
+ incomingEdges,
147
+ outgoingEdges,
148
+ ),
149
+ 'id',
150
+ )
138
151
  } else if (model?.BaseType === 'edge') {
139
152
  // 高亮边及对应的节点
140
153
  model.updateStyles(this.tempStyles[id])
141
154
  model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id])
142
155
  model.targetNode.updateStyles(this.tempStyles[model.targetNode.id])
156
+ relateElements = [model.sourceNode, model.targetNode]
143
157
  }
158
+ this.lf.emit('highlight:neighbours', {
159
+ data: model,
160
+ relateElements,
161
+ })
144
162
  }
145
163
 
146
164
  private highlightPath(id: string) {
147
165
  const path = getPath(id, this.lf)
166
+ const relateElements: any[] = []
148
167
  path.forEach((_id) => {
168
+ const elementModel = this.lf.getModelById(_id)
149
169
  // 高亮路径上所有的边和节点
150
- this.lf.getModelById(_id)?.updateStyles(this.tempStyles[_id])
170
+ elementModel?.updateStyles(this.tempStyles[_id])
171
+ relateElements.push(elementModel)
172
+ })
173
+ this.lf.emit('highlight:path', {
174
+ data: this.lf.getModelById(id),
175
+ relateElements,
151
176
  })
152
177
  }
153
178
 
@@ -513,9 +513,6 @@ export class DynamicGroup {
513
513
  }
514
514
  })
515
515
 
516
- // TODO: 确认,递归的方式,是否将所有嵌套的边数据都有返回
517
- console.log('allRelatedEdges -->>', allRelatedEdges)
518
-
519
516
  // 1. 判断每一条边的开始节点、目标节点是否在 Group 中
520
517
  const edgesInnerGroup = filter(allRelatedEdges, (edge) => {
521
518
  return (
package/src/style/raw.ts CHANGED
@@ -193,6 +193,10 @@ export const content = `@import url('medium-editor/dist/css/medium-editor.min.cs
193
193
  background: #eaedf2;
194
194
  border: 1px solid #93a3b4;
195
195
  }
196
+ .lf-mini-map .lf-graph {
197
+ width: 100% !important;
198
+ height: 100% !important;
199
+ }
196
200
  .lf-mini-map-graph {
197
201
  position: relative;
198
202
  overflow: hidden;
@@ -3,6 +3,7 @@ import LogicFlow, {
3
3
  twoPointDistance,
4
4
  BaseNodeModel,
5
5
  BaseEdgeModel,
6
+ isInNode,
6
7
  } from '@logicflow/core'
7
8
  import { assign, isEmpty, isEqual, isNil, isFinite, reduce } from 'lodash-es'
8
9
 
@@ -78,10 +79,37 @@ export class ProximityConnect {
78
79
  },
79
80
  )
80
81
  // 节点、锚点拖拽结束事件
81
- this.lf.graphModel.eventCenter.on('node:drop,anchor:dragend', () => {
82
+ this.lf.graphModel.eventCenter.on('node:drop', () => {
82
83
  if (!this.enable) return
83
84
  this.handleDrop()
84
85
  })
86
+ // 锚点拖拽需要单独判断一下当前拖拽终点是否在某个锚点上,如果是,就不触发插件的连线,以免出现创建了两条连线的问题,表现见 issue 2140
87
+ this.lf.graphModel.eventCenter.on('anchor:dragend', ({ e, edgeModel }) => {
88
+ if (!this.enable) return
89
+ const {
90
+ canvasOverlayPosition: { x: eventX, y: eventY },
91
+ } = this.lf.graphModel.getPointByClient({
92
+ x: e.clientX,
93
+ y: e.clientY,
94
+ })
95
+
96
+ if (edgeModel && this.virtualEdge) {
97
+ const { id: virtualEdgeId } = this.virtualEdge as BaseEdgeModel
98
+ const { targetNodeId } = edgeModel as BaseEdgeModel
99
+ const targetNodeModel =
100
+ this.lf.graphModel.getNodeModelById(targetNodeId)
101
+ if (
102
+ targetNodeModel &&
103
+ isInNode({ x: eventX, y: eventY }, targetNodeModel)
104
+ ) {
105
+ // 如果当前拖拽点在锚点上,就不触发插件的连线
106
+ this.lf.deleteEdge(virtualEdgeId)
107
+ return
108
+ }
109
+ }
110
+
111
+ this.handleDrop()
112
+ })
85
113
  }
86
114
 
87
115
  // 节点拖拽动作
@@ -346,6 +374,7 @@ export class ProximityConnect {
346
374
  endPoint,
347
375
  pointsList,
348
376
  } = this.virtualEdge
377
+ this.lf.deleteEdge(this.virtualEdge.id)
349
378
  this.lf.addEdge({
350
379
  type,
351
380
  sourceNodeId,
@@ -356,7 +385,6 @@ export class ProximityConnect {
356
385
  endPoint,
357
386
  pointsList,
358
387
  })
359
- this.lf.deleteEdge(this.virtualEdge.id)
360
388
  }
361
389
 
362
390
  // 设置虚拟边样式
@@ -369,7 +397,6 @@ export class ProximityConnect {
369
397
 
370
398
  // 设置连线阈值
371
399
  public setThresholdDistance(distance: number) {
372
- console.log('distance', distance)
373
400
  if (!isFinite(distance)) return
374
401
  this.thresholdDistance = distance
375
402
  }