@logicflow/core 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/es/LogicFlow.d.ts CHANGED
@@ -568,6 +568,8 @@ export declare class LogicFlow {
568
568
  * 加载插件-内部方法
569
569
  */
570
570
  private installPlugin;
571
+ /** 销毁当前实例 */
572
+ destroy(): void;
571
573
  }
572
574
  export declare namespace LogicFlow {
573
575
  /**
@@ -638,6 +640,7 @@ export declare namespace LogicFlow {
638
640
  };
639
641
  type LabelConfig = {
640
642
  id?: string;
643
+ type?: string;
641
644
  x: number;
642
645
  y: number;
643
646
  content?: string;
package/es/LogicFlow.js CHANGED
@@ -1166,6 +1166,10 @@ var LogicFlow = /** @class */ (function () {
1166
1166
  this.components.push(extensionIns.render.bind(extensionIns));
1167
1167
  this.extension[pluginName] = extensionIns;
1168
1168
  };
1169
+ /** 销毁当前实例 */
1170
+ LogicFlow.prototype.destroy = function () {
1171
+ this.graphModel.destroy();
1172
+ };
1169
1173
  // 全局配置的插件,所有的LogicFlow示例都会使用
1170
1174
  LogicFlow.extensions = new Map();
1171
1175
  return LogicFlow;
@@ -349,6 +349,16 @@ interface CommonEventArgs {
349
349
  */
350
350
  data: GraphData;
351
351
  };
352
+ /**
353
+ * 画布容器大小发生变化触发,为了性能考虑对事件做了防抖处理,间隔为16ms
354
+ */
355
+ 'graph:resize': {
356
+ /**
357
+ * 更新后的画布数据
358
+ */
359
+ target: HTMLElement;
360
+ contentRect: DOMRectReadOnly;
361
+ };
352
362
  }
353
363
  type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = Pick<{
354
364
  /**
@@ -62,6 +62,7 @@ export declare class GraphModel {
62
62
  editConfigModel: EditConfigModel;
63
63
  partial: boolean;
64
64
  [propName: string]: any;
65
+ private waitCleanEffects;
65
66
  constructor(options: LFOptions.Common);
66
67
  get nodesMap(): GraphModel.NodesMapType;
67
68
  get edgesMap(): GraphModel.EdgesMapType;
@@ -70,15 +71,15 @@ export declare class GraphModel {
70
71
  * 基于zIndex对元素进行排序。
71
72
  * todo: 性能优化
72
73
  */
73
- get sortElements(): (BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType>)[];
74
+ get sortElements(): (BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType>)[];
74
75
  /**
75
76
  * 当前编辑的元素,低频操作,先循环找。
76
77
  */
77
- get textEditElement(): BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType> | undefined;
78
+ get textEditElement(): BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType> | undefined;
78
79
  /**
79
80
  * 当前画布所有被选中的元素
80
81
  */
81
- get selectElements(): Map<string, BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType>>;
82
+ get selectElements(): Map<string, BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType>>;
82
83
  get selectNodes(): BaseNodeModel<LogicFlow.PropertiesType>[];
83
84
  /**
84
85
  * 获取指定区域内的所有元素
@@ -437,6 +438,8 @@ export declare class GraphModel {
437
438
  * @returns
438
439
  */
439
440
  setPartial(partial: boolean): void;
441
+ /** 销毁当前实例 */
442
+ destroy(): void;
440
443
  }
441
444
  export declare namespace GraphModel {
442
445
  type NodesMapType = Record<string, {
@@ -15,6 +15,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
15
15
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
16
16
  return c > 3 && r && Object.defineProperty(target, key, r), r;
17
17
  };
18
+ var __values = (this && this.__values) || function(o) {
19
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20
+ if (m) return m.call(o);
21
+ if (o && typeof o.length === "number") return {
22
+ next: function () {
23
+ if (o && i >= o.length) o = void 0;
24
+ return { value: o && o[i++], done: !o };
25
+ }
26
+ };
27
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
+ };
18
29
  var __read = (this && this.__read) || function (o, n) {
19
30
  var m = typeof Symbol === "function" && o[Symbol.iterator];
20
31
  if (!m) return o;
@@ -40,7 +51,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
51
  }
41
52
  return to.concat(ar || Array.prototype.slice.call(from));
42
53
  };
43
- import { find, forEach, map, merge, isBoolean, isEqual } from 'lodash-es';
54
+ import { find, forEach, map, merge, isBoolean, debounce, isEqual } from 'lodash-es';
44
55
  import { action, computed, observable } from 'mobx';
45
56
  import { EditConfigModel, TransformModel, } from '.';
46
57
  import { DEFAULT_VISIBLE_SPACE, ELEMENT_MAX_Z_INDEX, ElementState, ElementType, EventType, ModelType, OverlapMode, TextMode, } from '../constant';
@@ -49,6 +60,7 @@ import EventEmitter from '../event/eventEmitter';
49
60
  import { Grid } from '../view/overlay';
50
61
  var GraphModel = /** @class */ (function () {
51
62
  function GraphModel(options) {
63
+ var _this = this;
52
64
  // 维护所有节点和边类型对应的 model
53
65
  this.modelMap = new Map();
54
66
  // Remind:用于记录当前画布上所有节点和边的 model 的 Map
@@ -81,6 +93,7 @@ var GraphModel = /** @class */ (function () {
81
93
  this.gridSize = 1;
82
94
  // 控制是否开启局部渲染
83
95
  this.partial = false;
96
+ this.waitCleanEffects = [];
84
97
  var container = options.container, partial = options.partial, _a = options.background, background = _a === void 0 ? {} : _a, grid = options.grid, idGenerator = options.idGenerator, edgeGenerator = options.edgeGenerator, animation = options.animation, customTrajectory = options.customTrajectory;
85
98
  this.rootEl = container;
86
99
  this.partial = !!partial;
@@ -95,6 +108,32 @@ var GraphModel = /** @class */ (function () {
95
108
  this.overlapMode = options.overlapMode || OverlapMode.DEFAULT;
96
109
  this.width = options.width || this.rootEl.getBoundingClientRect().width;
97
110
  this.height = options.height || this.rootEl.getBoundingClientRect().height;
111
+ var resizeObserver = new ResizeObserver(debounce((function (entries) {
112
+ var e_1, _a;
113
+ try {
114
+ for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
115
+ var entry = entries_1_1.value;
116
+ if (entry.target === _this.rootEl) {
117
+ _this.resize();
118
+ _this.eventCenter.emit('graph:resize', {
119
+ target: _this.rootEl,
120
+ contentRect: entry.contentRect,
121
+ });
122
+ }
123
+ }
124
+ }
125
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
126
+ finally {
127
+ try {
128
+ if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
129
+ }
130
+ finally { if (e_1) throw e_1.error; }
131
+ }
132
+ }), 16));
133
+ resizeObserver.observe(this.rootEl);
134
+ this.waitCleanEffects.push(function () {
135
+ resizeObserver.disconnect();
136
+ });
98
137
  this.eventCenter = new EventEmitter();
99
138
  this.editConfigModel = new EditConfigModel(options);
100
139
  this.transformModel = new TransformModel(this.eventCenter, options);
@@ -1407,6 +1446,18 @@ var GraphModel = /** @class */ (function () {
1407
1446
  GraphModel.prototype.setPartial = function (partial) {
1408
1447
  this.partial = partial;
1409
1448
  };
1449
+ /** 销毁当前实例 */
1450
+ GraphModel.prototype.destroy = function () {
1451
+ try {
1452
+ this.waitCleanEffects.forEach(function (fn) {
1453
+ fn();
1454
+ });
1455
+ }
1456
+ catch (err) {
1457
+ console.warn('error on destroy GraphModel', err);
1458
+ }
1459
+ this.waitCleanEffects.length = 0;
1460
+ };
1410
1461
  __decorate([
1411
1462
  observable
1412
1463
  ], GraphModel.prototype, "width", void 0);
@@ -172,8 +172,8 @@ export declare class BaseNodeModel<P extends PropertiesType = PropertiesType> im
172
172
  color?: string | undefined;
173
173
  fontSize: number;
174
174
  lineHeight?: number | undefined;
175
- textAnchor?: "start" | "end" | "middle" | undefined;
176
- dominantBaseline?: "middle" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "central" | "mathematical" | "hanging" | "text-top" | undefined;
175
+ textAnchor?: "middle" | "start" | "end" | undefined;
176
+ dominantBaseline?: "middle" | "central" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "mathematical" | "hanging" | "text-top" | undefined;
177
177
  };
178
178
  /**
179
179
  * @overridable 支持重写
@@ -24,8 +24,8 @@ export declare class TextNodeModel<P extends ITextNodeProperties = ITextNodeProp
24
24
  fontSize: number;
25
25
  textWidth?: number | undefined;
26
26
  lineHeight?: number | undefined;
27
- textAnchor?: "start" | "end" | "middle" | undefined;
28
- dominantBaseline?: "middle" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "central" | "mathematical" | "hanging" | "text-top" | undefined;
27
+ textAnchor?: "middle" | "start" | "end" | undefined;
28
+ dominantBaseline?: "middle" | "central" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "mathematical" | "hanging" | "text-top" | undefined;
29
29
  overflowMode?: "default" | "autoWrap" | "ellipsis" | undefined;
30
30
  wrapPadding?: string | undefined;
31
31
  };
@@ -218,7 +218,7 @@ var BaseNode = /** @class */ (function (_super) {
218
218
  // 不是双击的,默认都是单击
219
219
  if (isDoubleClick) {
220
220
  if (editConfigModel.nodeTextEdit) {
221
- if (model.text.editable) {
221
+ if (model.text.editable && editConfigModel.textMode === TextMode.TEXT) {
222
222
  model.setSelected(false);
223
223
  graphModel.setElementStateById(model.id, ElementState.TEXT_EDIT);
224
224
  }
@@ -25,7 +25,7 @@ export declare function getTransform<P>(WrappedComponent: ComponentType<P>): {
25
25
  props: import("preact").RenderableProps<IProps & P, any>;
26
26
  context: any;
27
27
  base?: Element | Text | undefined;
28
- setState<K extends never>(state: ((prevState: Readonly<{}>, props: Readonly<IProps & P>) => Pick<{}, K> | Partial<{}> | null) | Pick<{}, K> | Partial<{}> | null, callback?: (() => void) | undefined): void;
28
+ setState<K extends never>(state: Partial<{}> | ((prevState: Readonly<{}>, props: Readonly<IProps & P>) => Partial<{}> | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
29
29
  forceUpdate(callback?: (() => void) | undefined): void;
30
30
  };
31
31
  displayName?: string | undefined;
@@ -568,6 +568,8 @@ export declare class LogicFlow {
568
568
  * 加载插件-内部方法
569
569
  */
570
570
  private installPlugin;
571
+ /** 销毁当前实例 */
572
+ destroy(): void;
571
573
  }
572
574
  export declare namespace LogicFlow {
573
575
  /**
@@ -638,6 +640,7 @@ export declare namespace LogicFlow {
638
640
  };
639
641
  type LabelConfig = {
640
642
  id?: string;
643
+ type?: string;
641
644
  x: number;
642
645
  y: number;
643
646
  content?: string;
package/lib/LogicFlow.js CHANGED
@@ -1195,6 +1195,10 @@ var LogicFlow = /** @class */ (function () {
1195
1195
  this.components.push(extensionIns.render.bind(extensionIns));
1196
1196
  this.extension[pluginName] = extensionIns;
1197
1197
  };
1198
+ /** 销毁当前实例 */
1199
+ LogicFlow.prototype.destroy = function () {
1200
+ this.graphModel.destroy();
1201
+ };
1198
1202
  // 全局配置的插件,所有的LogicFlow示例都会使用
1199
1203
  LogicFlow.extensions = new Map();
1200
1204
  return LogicFlow;
@@ -349,6 +349,16 @@ interface CommonEventArgs {
349
349
  */
350
350
  data: GraphData;
351
351
  };
352
+ /**
353
+ * 画布容器大小发生变化触发,为了性能考虑对事件做了防抖处理,间隔为16ms
354
+ */
355
+ 'graph:resize': {
356
+ /**
357
+ * 更新后的画布数据
358
+ */
359
+ target: HTMLElement;
360
+ contentRect: DOMRectReadOnly;
361
+ };
352
362
  }
353
363
  type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = Pick<{
354
364
  /**
@@ -62,6 +62,7 @@ export declare class GraphModel {
62
62
  editConfigModel: EditConfigModel;
63
63
  partial: boolean;
64
64
  [propName: string]: any;
65
+ private waitCleanEffects;
65
66
  constructor(options: LFOptions.Common);
66
67
  get nodesMap(): GraphModel.NodesMapType;
67
68
  get edgesMap(): GraphModel.EdgesMapType;
@@ -70,15 +71,15 @@ export declare class GraphModel {
70
71
  * 基于zIndex对元素进行排序。
71
72
  * todo: 性能优化
72
73
  */
73
- get sortElements(): (BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType>)[];
74
+ get sortElements(): (BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType>)[];
74
75
  /**
75
76
  * 当前编辑的元素,低频操作,先循环找。
76
77
  */
77
- get textEditElement(): BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType> | undefined;
78
+ get textEditElement(): BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType> | undefined;
78
79
  /**
79
80
  * 当前画布所有被选中的元素
80
81
  */
81
- get selectElements(): Map<string, BaseEdgeModel<LogicFlow.PropertiesType> | BaseNodeModel<LogicFlow.PropertiesType>>;
82
+ get selectElements(): Map<string, BaseNodeModel<LogicFlow.PropertiesType> | BaseEdgeModel<LogicFlow.PropertiesType>>;
82
83
  get selectNodes(): BaseNodeModel<LogicFlow.PropertiesType>[];
83
84
  /**
84
85
  * 获取指定区域内的所有元素
@@ -437,6 +438,8 @@ export declare class GraphModel {
437
438
  * @returns
438
439
  */
439
440
  setPartial(partial: boolean): void;
441
+ /** 销毁当前实例 */
442
+ destroy(): void;
440
443
  }
441
444
  export declare namespace GraphModel {
442
445
  type NodesMapType = Record<string, {
@@ -16,6 +16,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
16
16
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
17
  return c > 3 && r && Object.defineProperty(target, key, r), r;
18
18
  };
19
+ var __values = (this && this.__values) || function(o) {
20
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
21
+ if (m) return m.call(o);
22
+ if (o && typeof o.length === "number") return {
23
+ next: function () {
24
+ if (o && i >= o.length) o = void 0;
25
+ return { value: o && o[i++], done: !o };
26
+ }
27
+ };
28
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
29
+ };
19
30
  var __read = (this && this.__read) || function (o, n) {
20
31
  var m = typeof Symbol === "function" && o[Symbol.iterator];
21
32
  if (!m) return o;
@@ -55,6 +66,7 @@ var eventEmitter_1 = __importDefault(require("../event/eventEmitter"));
55
66
  var overlay_1 = require("../view/overlay");
56
67
  var GraphModel = /** @class */ (function () {
57
68
  function GraphModel(options) {
69
+ var _this = this;
58
70
  // 维护所有节点和边类型对应的 model
59
71
  this.modelMap = new Map();
60
72
  // Remind:用于记录当前画布上所有节点和边的 model 的 Map
@@ -87,6 +99,7 @@ var GraphModel = /** @class */ (function () {
87
99
  this.gridSize = 1;
88
100
  // 控制是否开启局部渲染
89
101
  this.partial = false;
102
+ this.waitCleanEffects = [];
90
103
  var container = options.container, partial = options.partial, _a = options.background, background = _a === void 0 ? {} : _a, grid = options.grid, idGenerator = options.idGenerator, edgeGenerator = options.edgeGenerator, animation = options.animation, customTrajectory = options.customTrajectory;
91
104
  this.rootEl = container;
92
105
  this.partial = !!partial;
@@ -101,6 +114,32 @@ var GraphModel = /** @class */ (function () {
101
114
  this.overlapMode = options.overlapMode || constant_1.OverlapMode.DEFAULT;
102
115
  this.width = options.width || this.rootEl.getBoundingClientRect().width;
103
116
  this.height = options.height || this.rootEl.getBoundingClientRect().height;
117
+ var resizeObserver = new ResizeObserver((0, lodash_es_1.debounce)((function (entries) {
118
+ var e_1, _a;
119
+ try {
120
+ for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
121
+ var entry = entries_1_1.value;
122
+ if (entry.target === _this.rootEl) {
123
+ _this.resize();
124
+ _this.eventCenter.emit('graph:resize', {
125
+ target: _this.rootEl,
126
+ contentRect: entry.contentRect,
127
+ });
128
+ }
129
+ }
130
+ }
131
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
132
+ finally {
133
+ try {
134
+ if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
135
+ }
136
+ finally { if (e_1) throw e_1.error; }
137
+ }
138
+ }), 16));
139
+ resizeObserver.observe(this.rootEl);
140
+ this.waitCleanEffects.push(function () {
141
+ resizeObserver.disconnect();
142
+ });
104
143
  this.eventCenter = new eventEmitter_1.default();
105
144
  this.editConfigModel = new _1.EditConfigModel(options);
106
145
  this.transformModel = new _1.TransformModel(this.eventCenter, options);
@@ -1413,6 +1452,18 @@ var GraphModel = /** @class */ (function () {
1413
1452
  GraphModel.prototype.setPartial = function (partial) {
1414
1453
  this.partial = partial;
1415
1454
  };
1455
+ /** 销毁当前实例 */
1456
+ GraphModel.prototype.destroy = function () {
1457
+ try {
1458
+ this.waitCleanEffects.forEach(function (fn) {
1459
+ fn();
1460
+ });
1461
+ }
1462
+ catch (err) {
1463
+ console.warn('error on destroy GraphModel', err);
1464
+ }
1465
+ this.waitCleanEffects.length = 0;
1466
+ };
1416
1467
  __decorate([
1417
1468
  mobx_1.observable
1418
1469
  ], GraphModel.prototype, "width", void 0);
@@ -172,8 +172,8 @@ export declare class BaseNodeModel<P extends PropertiesType = PropertiesType> im
172
172
  color?: string | undefined;
173
173
  fontSize: number;
174
174
  lineHeight?: number | undefined;
175
- textAnchor?: "start" | "end" | "middle" | undefined;
176
- dominantBaseline?: "middle" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "central" | "mathematical" | "hanging" | "text-top" | undefined;
175
+ textAnchor?: "middle" | "start" | "end" | undefined;
176
+ dominantBaseline?: "middle" | "central" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "mathematical" | "hanging" | "text-top" | undefined;
177
177
  };
178
178
  /**
179
179
  * @overridable 支持重写
@@ -24,8 +24,8 @@ export declare class TextNodeModel<P extends ITextNodeProperties = ITextNodeProp
24
24
  fontSize: number;
25
25
  textWidth?: number | undefined;
26
26
  lineHeight?: number | undefined;
27
- textAnchor?: "start" | "end" | "middle" | undefined;
28
- dominantBaseline?: "middle" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "central" | "mathematical" | "hanging" | "text-top" | undefined;
27
+ textAnchor?: "middle" | "start" | "end" | undefined;
28
+ dominantBaseline?: "middle" | "central" | "auto" | "text-bottom" | "alphabetic" | "ideographic" | "mathematical" | "hanging" | "text-top" | undefined;
29
29
  overflowMode?: "default" | "autoWrap" | "ellipsis" | undefined;
30
30
  wrapPadding?: string | undefined;
31
31
  };
@@ -222,7 +222,7 @@ var BaseNode = /** @class */ (function (_super) {
222
222
  // 不是双击的,默认都是单击
223
223
  if (isDoubleClick) {
224
224
  if (editConfigModel.nodeTextEdit) {
225
- if (model.text.editable) {
225
+ if (model.text.editable && editConfigModel.textMode === constant_1.TextMode.TEXT) {
226
226
  model.setSelected(false);
227
227
  graphModel.setElementStateById(model.id, constant_1.ElementState.TEXT_EDIT);
228
228
  }
@@ -25,7 +25,7 @@ export declare function getTransform<P>(WrappedComponent: ComponentType<P>): {
25
25
  props: import("preact").RenderableProps<IProps & P, any>;
26
26
  context: any;
27
27
  base?: Element | Text | undefined;
28
- setState<K extends never>(state: ((prevState: Readonly<{}>, props: Readonly<IProps & P>) => Pick<{}, K> | Partial<{}> | null) | Pick<{}, K> | Partial<{}> | null, callback?: (() => void) | undefined): void;
28
+ setState<K extends never>(state: Partial<{}> | ((prevState: Readonly<{}>, props: Readonly<IProps & P>) => Partial<{}> | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
29
29
  forceUpdate(callback?: (() => void) | undefined): void;
30
30
  };
31
31
  displayName?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",