@logicflow/extension 2.0.8 → 2.0.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(core&extension): fix bugs from issues
8
+ - fix(extension): 【dynamic-group】修复resize和move的冲突问题(#1826)
9
+ - Updated dependencies
10
+ - @logicflow/core@2.0.5
11
+
3
12
  ## 2.0.8
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -20,7 +20,7 @@
20
20
  "author": "Logicflow-Team",
21
21
  "license": "Apache-2.0",
22
22
  "peerDependencies": {
23
- "@logicflow/core": "2.0.4"
23
+ "@logicflow/core": "2.0.5"
24
24
  },
25
25
  "dependencies": {
26
26
  "@antv/hierarchy": "^0.6.11",
@@ -31,7 +31,7 @@
31
31
  "preact": "^10.17.1",
32
32
  "rangy": "^1.3.1",
33
33
  "vanilla-picker": "^2.12.3",
34
- "@logicflow/core": "2.0.4"
34
+ "@logicflow/core": "2.0.5"
35
35
  },
36
36
  "devDependencies": {
37
37
  "less": "^4.1.1",
@@ -50,27 +50,6 @@ export class DynamicGroup {
50
50
  this.init()
51
51
  }
52
52
 
53
- /**
54
- * 获取分组内的节点
55
- * @param groupModel
56
- */
57
- getNodesInGroup(groupModel: DynamicGroupNodeModel): string[] {
58
- let nodeIds: string[] = []
59
- if (groupModel.isGroup) {
60
- forEach(Array.from(groupModel.children), (nodeId: string) => {
61
- nodeIds.push(nodeId)
62
-
63
- const nodeModel = this.lf.getNodeModelById(nodeId)
64
- if (nodeModel?.isGroup) {
65
- nodeIds = nodeIds.concat(
66
- this.getNodesInGroup(nodeModel as DynamicGroupNodeModel),
67
- )
68
- }
69
- })
70
- }
71
- return nodeIds
72
- }
73
-
74
53
  /**
75
54
  * 获取节点所属的分组
76
55
  * @param nodeId
@@ -492,8 +471,13 @@ export class DynamicGroup {
492
471
  graphModel.addNodeMoveRules((model, deltaX, deltaY) => {
493
472
  // 判断如果是 group,移动时需要同时移动组内的所有节点
494
473
  if (model.isGroup) {
495
- const nodeIds = this.getNodesInGroup(model as DynamicGroupNodeModel)
496
- graphModel.moveNodes(nodeIds, deltaX, deltaY, true)
474
+ // https://github.com/didi/LogicFlow/issues/1826
475
+ // 这里不应该触发移动子节点的逻辑,这里是判断是否可以移动,而不是触发移动逻辑
476
+ // 而且这里触发移动,会导致resize操作的this.x变动也会触发子item的this.x变动
477
+ // resize时的deltaX跟正常移动的deltaX是不同的
478
+
479
+ // const nodeIds = this.getNodesInGroup(model as DynamicGroupNodeModel)
480
+ // graphModel.moveNodes(nodeIds, deltaX, deltaY, true)
497
481
  return true
498
482
  }
499
483
 
@@ -503,7 +487,7 @@ export class DynamicGroup {
503
487
  ) as DynamicGroupNodeModel
504
488
 
505
489
  if (groupModel && groupModel.isRestrict) {
506
- // 如果移动的节点存在与分组中,且这个分组禁止子节点移出去
490
+ // 如果移动的节点存在于某个分组中,且这个分组禁止子节点移出去
507
491
  const groupBounds = groupModel.getBounds()
508
492
  return isAllowMoveTo(groupBounds, model, deltaX, deltaY)
509
493
  }
@@ -1,7 +1,11 @@
1
- import LogicFlow, { GraphModel, h, RectNode } from '@logicflow/core'
1
+ import LogicFlow, {
2
+ GraphModel,
3
+ h,
4
+ RectNode,
5
+ handleResize,
6
+ } from '@logicflow/core'
2
7
  import { forEach } from 'lodash-es'
3
8
  import { DynamicGroupNodeModel } from './model'
4
- import { handleResize } from '@logicflow/core/es/util/resize'
5
9
 
6
10
  import Position = LogicFlow.Position
7
11
  import { rotatePointAroundCenter } from '../tools/label/utils'
@@ -53,27 +57,73 @@ export class DynamicGroupNode<
53
57
  })
54
58
 
55
59
  // 在 group 缩放时,对组内的所有子节点也进行对应的缩放计算
56
- eventCenter.on('node:resize', ({ deltaX, deltaY, index, model }) => {
57
- // TODO: 目前 Resize 的比例值有问题,导致缩放时,节点会变形,需要修复
58
- if (model.id === curGroup.id) {
59
- forEach(Array.from(curGroup.children), (childId) => {
60
- const child = graphModel.getNodeModelById(childId)
61
- if (child) {
62
- // child.rotate = model.rotate
63
- handleResize({
64
- deltaX,
65
- deltaY,
66
- index,
67
- nodeModel: child,
68
- graphModel,
69
- cancelCallback: () => {},
70
- })
71
- }
72
- })
60
+ eventCenter.on(
61
+ 'node:resize',
62
+ ({ deltaX, deltaY, index, model, preData }) => {
63
+ if (model.id === curGroup.id) {
64
+ // node:resize是group已经改变width和height后的回调
65
+ // 因此这里一定得用preData(没resize改变width之前的值),而不是data/model
66
+ const { properties } = preData
67
+ const { width: groupWidth, height: groupHeight } = properties || {}
68
+ forEach(Array.from(curGroup.children), (childId) => {
69
+ const child = graphModel.getNodeModelById(childId)
70
+ if (child) {
71
+ // 根据比例去控制缩放dx和dy
72
+ const childDx = (child.width / groupWidth!) * deltaX
73
+ const childDy = (child.height / groupHeight!) * deltaY
74
+
75
+ // child.rotate = model.rotate
76
+ handleResize({
77
+ deltaX: childDx,
78
+ deltaY: childDy,
79
+ index,
80
+ nodeModel: child,
81
+ graphModel,
82
+ cancelCallback: () => {},
83
+ })
84
+ }
85
+ })
86
+ }
87
+ },
88
+ )
89
+
90
+ // 在 group 移动时,对组内的所有子节点也进行对应的移动计算
91
+ eventCenter.on('node:mousemove', ({ deltaX, deltaY, data }) => {
92
+ if (data.id === curGroup.id) {
93
+ const { model: curGroup, graphModel } = this.props
94
+ const nodeIds = this.getNodesInGroup(curGroup, graphModel)
95
+ graphModel.moveNodes(nodeIds, deltaX, deltaY, true)
73
96
  }
74
97
  })
75
98
  }
76
99
 
100
+ /**
101
+ * 获取分组内的节点
102
+ * @param groupModel
103
+ */
104
+ getNodesInGroup(
105
+ groupModel: DynamicGroupNodeModel,
106
+ graphModel: GraphModel,
107
+ ): string[] {
108
+ let nodeIds: string[] = []
109
+ if (groupModel.isGroup) {
110
+ forEach(Array.from(groupModel.children), (nodeId: string) => {
111
+ nodeIds.push(nodeId)
112
+
113
+ const nodeModel = graphModel.getNodeModelById(nodeId)
114
+ if (nodeModel?.isGroup) {
115
+ nodeIds = nodeIds.concat(
116
+ this.getNodesInGroup(
117
+ nodeModel as DynamicGroupNodeModel,
118
+ graphModel,
119
+ ),
120
+ )
121
+ }
122
+ })
123
+ }
124
+ return nodeIds
125
+ }
126
+
77
127
  getResizeControl(): h.JSX.Element | null {
78
128
  const { resizable, isCollapsed } = this.props.model
79
129
  const showResizeControl = resizable && !isCollapsed