@logicflow/core 2.2.0-alpha.3 → 2.2.0-alpha.4

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.
@@ -131,6 +131,10 @@ var GraphModel = /** @class */ (function () {
131
131
  for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
132
132
  var entry = entries_1_1.value;
133
133
  if (entry.target === _this.rootEl) {
134
+ // 检查元素是否仍在DOM中
135
+ var isElementInDOM = document.body.contains(_this.rootEl);
136
+ if (!isElementInDOM)
137
+ return;
134
138
  _this.resize();
135
139
  _this.eventCenter.emit('graph:resize', {
136
140
  target: _this.rootEl,
@@ -1392,12 +1396,30 @@ var GraphModel = /** @class */ (function () {
1392
1396
  * 重新设置画布的宽高
1393
1397
  */
1394
1398
  GraphModel.prototype.resize = function (width, height) {
1395
- this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
1396
- this.isContainerWidth = isNil(width);
1397
- this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
1398
- this.isContainerHeight = isNil(height);
1399
- if (!this.width || !this.height) {
1400
- console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
1399
+ // 检查当前实例是否已被销毁或rootEl不存在
1400
+ if (!this.rootEl)
1401
+ return;
1402
+ // 检查元素是否仍在DOM中
1403
+ var isElementInDOM = document.body.contains(this.rootEl);
1404
+ if (!isElementInDOM)
1405
+ return;
1406
+ // 检查元素是否可见
1407
+ var isVisible = this.rootEl.offsetParent !== null;
1408
+ if (!isVisible)
1409
+ return;
1410
+ try {
1411
+ this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
1412
+ this.isContainerWidth = isNil(width);
1413
+ this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
1414
+ this.isContainerHeight = isNil(height);
1415
+ // 只有在元素可见且应该有宽高的情况下才显示警告
1416
+ if (isVisible && (!this.width || !this.height)) {
1417
+ console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
1418
+ }
1419
+ }
1420
+ catch (error) {
1421
+ // 捕获可能的DOM操作错误
1422
+ console.warn('获取画布宽高时发生错误:', error);
1401
1423
  }
1402
1424
  };
1403
1425
  /**
@@ -55,6 +55,10 @@ var MultipleSelect = /** @class */ (function (_super) {
55
55
  function MultipleSelect(props) {
56
56
  var _this = _super.call(this, props) || this;
57
57
  _this.handleMouseDown = function (ev) {
58
+ // 多选区域的拖拽步长随缩放变化
59
+ var _a = _this.props, gridSize = _a.graphModel.gridSize, lf = _a.lf;
60
+ var SCALE_X = lf.getTransform().SCALE_X;
61
+ _this.stepDrag.setStep(gridSize * SCALE_X);
58
62
  _this.stepDrag.handleMouseDown(ev);
59
63
  };
60
64
  // 使多选区域的滚轮事件可以触发画布的滚轮事件
@@ -242,6 +242,15 @@ var BaseNode = /** @class */ (function (_super) {
242
242
  else {
243
243
  graphModel.eventCenter.emit(EventType.ELEMENT_CLICK, eventOptions);
244
244
  graphModel.eventCenter.emit(EventType.NODE_CLICK, eventOptions);
245
+ // 复制粘贴后会出现点击节点时,节点会失去焦点的问题,这里手动让节点获焦以解决这个问题
246
+ var el_1 = e.currentTarget;
247
+ var rAF = typeof window !== 'undefined' &&
248
+ typeof window.requestAnimationFrame === 'function'
249
+ ? window.requestAnimationFrame.bind(window)
250
+ : function (fn) { return setTimeout(fn, 0); };
251
+ rAF(function () {
252
+ el_1.focus();
253
+ });
245
254
  }
246
255
  };
247
256
  _this.handleContextMenu = function (ev) {
@@ -97,6 +97,9 @@ var CanvasOverlay = /** @class */ (function (_super) {
97
97
  if (selectElements.size > 0) {
98
98
  graphModel.clearSelectElements();
99
99
  }
100
+ // 如果是拖拽状态,不触发点击事件
101
+ if (_this.state.isDragging)
102
+ return;
100
103
  graphModel.eventCenter.emit(EventType.BLANK_CLICK, { e: ev });
101
104
  }
102
105
  };
@@ -158,8 +161,6 @@ var CanvasOverlay = /** @class */ (function (_super) {
158
161
  else {
159
162
  eventCenter.emit(EventType.BLANK_MOUSEDOWN, { e: ev });
160
163
  }
161
- // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
162
- _this.clickHandler(ev);
163
164
  }
164
165
  };
165
166
  _this.pointerMoveHandler = function (ev) {
@@ -217,6 +218,8 @@ var CanvasOverlay = /** @class */ (function (_super) {
217
218
  var editConfigModel = _this.props.graphModel.editConfigModel;
218
219
  // 标记退出捏合,框选等交互可恢复
219
220
  editConfigModel.updateEditConfig({ isPinching: false });
221
+ // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
222
+ _this.clickHandler(ev);
220
223
  }
221
224
  };
222
225
  var _a = props.graphModel, gridSize = _a.gridSize, eventCenter = _a.eventCenter;
@@ -137,6 +137,10 @@ var GraphModel = /** @class */ (function () {
137
137
  for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
138
138
  var entry = entries_1_1.value;
139
139
  if (entry.target === _this.rootEl) {
140
+ // 检查元素是否仍在DOM中
141
+ var isElementInDOM = document.body.contains(_this.rootEl);
142
+ if (!isElementInDOM)
143
+ return;
140
144
  _this.resize();
141
145
  _this.eventCenter.emit('graph:resize', {
142
146
  target: _this.rootEl,
@@ -1398,12 +1402,30 @@ var GraphModel = /** @class */ (function () {
1398
1402
  * 重新设置画布的宽高
1399
1403
  */
1400
1404
  GraphModel.prototype.resize = function (width, height) {
1401
- this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
1402
- this.isContainerWidth = (0, lodash_es_1.isNil)(width);
1403
- this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
1404
- this.isContainerHeight = (0, lodash_es_1.isNil)(height);
1405
- if (!this.width || !this.height) {
1406
- console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
1405
+ // 检查当前实例是否已被销毁或rootEl不存在
1406
+ if (!this.rootEl)
1407
+ return;
1408
+ // 检查元素是否仍在DOM中
1409
+ var isElementInDOM = document.body.contains(this.rootEl);
1410
+ if (!isElementInDOM)
1411
+ return;
1412
+ // 检查元素是否可见
1413
+ var isVisible = this.rootEl.offsetParent !== null;
1414
+ if (!isVisible)
1415
+ return;
1416
+ try {
1417
+ this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
1418
+ this.isContainerWidth = (0, lodash_es_1.isNil)(width);
1419
+ this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
1420
+ this.isContainerHeight = (0, lodash_es_1.isNil)(height);
1421
+ // 只有在元素可见且应该有宽高的情况下才显示警告
1422
+ if (isVisible && (!this.width || !this.height)) {
1423
+ console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
1424
+ }
1425
+ }
1426
+ catch (error) {
1427
+ // 捕获可能的DOM操作错误
1428
+ console.warn('获取画布宽高时发生错误:', error);
1407
1429
  }
1408
1430
  };
1409
1431
  /**
@@ -57,6 +57,10 @@ var MultipleSelect = /** @class */ (function (_super) {
57
57
  function MultipleSelect(props) {
58
58
  var _this = _super.call(this, props) || this;
59
59
  _this.handleMouseDown = function (ev) {
60
+ // 多选区域的拖拽步长随缩放变化
61
+ var _a = _this.props, gridSize = _a.graphModel.gridSize, lf = _a.lf;
62
+ var SCALE_X = lf.getTransform().SCALE_X;
63
+ _this.stepDrag.setStep(gridSize * SCALE_X);
60
64
  _this.stepDrag.handleMouseDown(ev);
61
65
  };
62
66
  // 使多选区域的滚轮事件可以触发画布的滚轮事件
@@ -246,6 +246,15 @@ var BaseNode = /** @class */ (function (_super) {
246
246
  else {
247
247
  graphModel.eventCenter.emit(constant_1.EventType.ELEMENT_CLICK, eventOptions);
248
248
  graphModel.eventCenter.emit(constant_1.EventType.NODE_CLICK, eventOptions);
249
+ // 复制粘贴后会出现点击节点时,节点会失去焦点的问题,这里手动让节点获焦以解决这个问题
250
+ var el_1 = e.currentTarget;
251
+ var rAF = typeof window !== 'undefined' &&
252
+ typeof window.requestAnimationFrame === 'function'
253
+ ? window.requestAnimationFrame.bind(window)
254
+ : function (fn) { return setTimeout(fn, 0); };
255
+ rAF(function () {
256
+ el_1.focus();
257
+ });
249
258
  }
250
259
  };
251
260
  _this.handleContextMenu = function (ev) {
@@ -100,6 +100,9 @@ var CanvasOverlay = /** @class */ (function (_super) {
100
100
  if (selectElements.size > 0) {
101
101
  graphModel.clearSelectElements();
102
102
  }
103
+ // 如果是拖拽状态,不触发点击事件
104
+ if (_this.state.isDragging)
105
+ return;
103
106
  graphModel.eventCenter.emit(constant_1.EventType.BLANK_CLICK, { e: ev });
104
107
  }
105
108
  };
@@ -161,8 +164,6 @@ var CanvasOverlay = /** @class */ (function (_super) {
161
164
  else {
162
165
  eventCenter.emit(constant_1.EventType.BLANK_MOUSEDOWN, { e: ev });
163
166
  }
164
- // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
165
- _this.clickHandler(ev);
166
167
  }
167
168
  };
168
169
  _this.pointerMoveHandler = function (ev) {
@@ -220,6 +221,8 @@ var CanvasOverlay = /** @class */ (function (_super) {
220
221
  var editConfigModel = _this.props.graphModel.editConfigModel;
221
222
  // 标记退出捏合,框选等交互可恢复
222
223
  editConfigModel.updateEditConfig({ isPinching: false });
224
+ // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
225
+ _this.clickHandler(ev);
223
226
  }
224
227
  };
225
228
  var _a = props.graphModel, gridSize = _a.gridSize, eventCenter = _a.eventCenter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.2.0-alpha.3",
3
+ "version": "2.2.0-alpha.4",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -23,10 +23,10 @@ export interface IEditConfigType {
23
23
  * - [number, number, number, number]:[minX, minY, maxX, maxY] 画布可拖动范围
24
24
  */
25
25
  stopMoveGraph:
26
- | boolean
27
- | 'vertical'
28
- | 'horizontal'
29
- | [number, number, number, number]
26
+ | boolean
27
+ | 'vertical'
28
+ | 'horizontal'
29
+ | [number, number, number, number]
30
30
  /**
31
31
  * 允许调整边
32
32
  */
@@ -206,6 +206,9 @@ export class GraphModel {
206
206
  ((entries) => {
207
207
  for (const entry of entries) {
208
208
  if (entry.target === this.rootEl) {
209
+ // 检查元素是否仍在DOM中
210
+ const isElementInDOM = document.body.contains(this.rootEl)
211
+ if (!isElementInDOM) return
209
212
  this.resize()
210
213
  this.eventCenter.emit('graph:resize', {
211
214
  target: this.rootEl,
@@ -1601,15 +1604,32 @@ export class GraphModel {
1601
1604
  * 重新设置画布的宽高
1602
1605
  */
1603
1606
  @action resize(width?: number, height?: number): void {
1604
- this.width = width ?? this.rootEl.getBoundingClientRect().width
1605
- this.isContainerWidth = isNil(width)
1606
- this.height = height ?? this.rootEl.getBoundingClientRect().height
1607
- this.isContainerHeight = isNil(height)
1608
-
1609
- if (!this.width || !this.height) {
1610
- console.warn(
1611
- '渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675',
1612
- )
1607
+ // 检查当前实例是否已被销毁或rootEl不存在
1608
+ if (!this.rootEl) return
1609
+
1610
+ // 检查元素是否仍在DOM中
1611
+ const isElementInDOM = document.body.contains(this.rootEl)
1612
+ if (!isElementInDOM) return
1613
+
1614
+ // 检查元素是否可见
1615
+ const isVisible = this.rootEl.offsetParent !== null
1616
+ if (!isVisible) return
1617
+
1618
+ try {
1619
+ this.width = width ?? this.rootEl.getBoundingClientRect().width
1620
+ this.isContainerWidth = isNil(width)
1621
+ this.height = height ?? this.rootEl.getBoundingClientRect().height
1622
+ this.isContainerHeight = isNil(height)
1623
+
1624
+ // 只有在元素可见且应该有宽高的情况下才显示警告
1625
+ if (isVisible && (!this.width || !this.height)) {
1626
+ console.warn(
1627
+ '渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675',
1628
+ )
1629
+ }
1630
+ } catch (error) {
1631
+ // 捕获可能的DOM操作错误
1632
+ console.warn('获取画布宽高时发生错误:', error)
1613
1633
  }
1614
1634
  }
1615
1635
 
@@ -57,8 +57,7 @@ export interface IBaseNodeModel<P extends PropertiesType>
57
57
  }
58
58
 
59
59
  export class BaseNodeModel<P extends PropertiesType = PropertiesType>
60
- implements IBaseNodeModel<P>
61
- {
60
+ implements IBaseNodeModel<P> {
62
61
  readonly BaseType = ElementType.NODE
63
62
  static BaseType: ElementType = ElementType.NODE
64
63
 
@@ -226,7 +225,7 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
226
225
  *
227
226
  * @overridable 支持重写
228
227
  */
229
- public setAttributes() {}
228
+ public setAttributes() { }
230
229
 
231
230
  /**
232
231
  * @overridable 支持重写,自定义此类型节点默认生成方式
@@ -307,7 +306,7 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
307
306
  }
308
307
 
309
308
  // TODO: 等比例缩放
310
- proportionalResize() {}
309
+ proportionalResize() { }
311
310
 
312
311
  /**
313
312
  * 获取被保存时返回的数据
@@ -27,6 +27,13 @@ export default class MultipleSelect extends Component<IToolProps> {
27
27
  }
28
28
 
29
29
  handleMouseDown = (ev: PointerEvent) => {
30
+ // 多选区域的拖拽步长随缩放变化
31
+ const {
32
+ graphModel: { gridSize },
33
+ lf,
34
+ } = this.props
35
+ const { SCALE_X } = lf.getTransform()
36
+ this.stepDrag.setStep(gridSize * SCALE_X)
30
37
  this.stepDrag.handleMouseDown(ev)
31
38
  }
32
39
  // 使多选区域的滚轮事件可以触发画布的滚轮事件
@@ -407,6 +407,16 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
407
407
  } else {
408
408
  graphModel.eventCenter.emit(EventType.ELEMENT_CLICK, eventOptions)
409
409
  graphModel.eventCenter.emit(EventType.NODE_CLICK, eventOptions)
410
+ // 复制粘贴后会出现点击节点时,节点会失去焦点的问题,这里手动让节点获焦以解决这个问题
411
+ const el = e.currentTarget as HTMLElement
412
+ const rAF =
413
+ typeof window !== 'undefined' &&
414
+ typeof window.requestAnimationFrame === 'function'
415
+ ? window.requestAnimationFrame.bind(window)
416
+ : (fn: () => void) => setTimeout(fn, 0)
417
+ rAF(() => {
418
+ el.focus()
419
+ })
410
420
  }
411
421
  }
412
422
 
@@ -115,6 +115,8 @@ export class CanvasOverlay extends Component<IProps, IState> {
115
115
  if (selectElements.size > 0) {
116
116
  graphModel.clearSelectElements()
117
117
  }
118
+ // 如果是拖拽状态,不触发点击事件
119
+ if (this.state.isDragging) return
118
120
  graphModel.eventCenter.emit(EventType.BLANK_CLICK, { e: ev })
119
121
  }
120
122
  }
@@ -184,8 +186,6 @@ export class CanvasOverlay extends Component<IProps, IState> {
184
186
  } else {
185
187
  eventCenter.emit(EventType.BLANK_MOUSEDOWN, { e: ev })
186
188
  }
187
- // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
188
- this.clickHandler(ev)
189
189
  }
190
190
  }
191
191
  pointerMoveHandler = (ev: PointerEvent) => {
@@ -249,6 +249,8 @@ export class CanvasOverlay extends Component<IProps, IState> {
249
249
  } = this.props
250
250
  // 标记退出捏合,框选等交互可恢复
251
251
  editConfigModel.updateEditConfig({ isPinching: false })
252
+ // 为了处理画布移动的时候,编辑和菜单仍然存在的问题。
253
+ this.clickHandler(ev)
252
254
  }
253
255
  }
254
256