@logicflow/extension 1.0.6 → 1.1.0-alpha.0

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.
Files changed (73) hide show
  1. package/cjs/NodeResize/index.js +1 -1
  2. package/cjs/bpmn/index.js +1 -1
  3. package/cjs/bpmn-adapter/index.js +3 -4
  4. package/cjs/bpmn-adapter/json2xml.js +3 -2
  5. package/cjs/bpmn-adapter/xml2json.js +5 -1
  6. package/cjs/components/context-menu/index.js +34 -22
  7. package/cjs/components/control/index.js +83 -71
  8. package/cjs/components/dnd-panel/index.js +20 -11
  9. package/cjs/components/menu/index.js +10 -10
  10. package/cjs/components/mini-map/index.js +159 -156
  11. package/cjs/components/selection-select/index.js +27 -14
  12. package/cjs/index.js +2 -0
  13. package/cjs/insert-node-in-polyline/index.js +1 -1
  14. package/cjs/materials/curved-edge/index.js +1 -1
  15. package/cjs/tools/flow-path/index.js +1 -1
  16. package/cjs/turbo-adapter/index.js +1 -1
  17. package/es/NodeResize/index.js +1 -1
  18. package/es/bpmn/index.js +1 -1
  19. package/es/bpmn-adapter/index.js +5 -6
  20. package/es/bpmn-adapter/json2xml.d.ts +2 -1
  21. package/es/bpmn-adapter/json2xml.js +2 -1
  22. package/es/bpmn-adapter/xml2json.d.ts +2 -2
  23. package/es/bpmn-adapter/xml2json.js +4 -1
  24. package/es/components/context-menu/index.d.ts +10 -1
  25. package/es/components/context-menu/index.js +34 -22
  26. package/es/components/control/index.d.ts +15 -12
  27. package/es/components/control/index.js +84 -72
  28. package/es/components/dnd-panel/index.d.ts +4 -1
  29. package/es/components/dnd-panel/index.js +20 -11
  30. package/es/components/menu/index.d.ts +2 -2
  31. package/es/components/menu/index.js +10 -10
  32. package/es/components/mini-map/index.d.ts +73 -2
  33. package/es/components/mini-map/index.js +159 -156
  34. package/es/components/selection-select/index.d.ts +8 -0
  35. package/es/components/selection-select/index.js +27 -14
  36. package/es/index.d.ts +2 -0
  37. package/es/index.js +2 -0
  38. package/es/insert-node-in-polyline/index.js +1 -1
  39. package/es/materials/curved-edge/index.js +1 -1
  40. package/es/tools/flow-path/index.js +1 -1
  41. package/es/turbo-adapter/index.js +1 -1
  42. package/lib/AutoLayout.js +1 -1
  43. package/lib/BpmnAdapter.js +1 -1
  44. package/lib/BpmnElement.js +1 -1
  45. package/lib/ContextMenu.js +1 -1
  46. package/lib/Control.js +1 -1
  47. package/lib/CurvedEdge.js +1 -1
  48. package/lib/DndPanel.js +1 -1
  49. package/lib/FlowPath.js +1 -1
  50. package/lib/Group.js +1 -1
  51. package/lib/InsertNodeInPolyline.js +1 -1
  52. package/lib/Menu.js +1 -1
  53. package/lib/MiniMap.js +1 -1
  54. package/lib/NodeResize.js +1 -1
  55. package/lib/RectLabelNode.js +1 -1
  56. package/lib/SelectionSelect.js +1 -1
  57. package/lib/Snapshot.js +1 -1
  58. package/lib/TurboAdapter.js +1 -1
  59. package/lib/lfJson2Xml.js +1 -0
  60. package/lib/lfXml2Json.js +1 -0
  61. package/package.json +2 -2
  62. package/types/bpmn-adapter/json2xml.d.ts +2 -1
  63. package/types/bpmn-adapter/xml2json.d.ts +2 -2
  64. package/types/components/context-menu/index.d.ts +10 -1
  65. package/types/components/control/index.d.ts +15 -12
  66. package/types/components/dnd-panel/index.d.ts +4 -1
  67. package/types/components/menu/index.d.ts +2 -2
  68. package/types/components/mini-map/index.d.ts +73 -2
  69. package/types/components/selection-select/index.d.ts +8 -0
  70. package/types/index.d.ts +2 -0
  71. package/cjs/curved.js +0 -0
  72. package/es/curved.d.ts +0 -0
  73. package/es/curved.js +0 -0
@@ -8,7 +8,7 @@ exports.EllipseResize = EllipseResize_1.default;
8
8
  var DiamondResize_1 = require("./Node/DiamondResize");
9
9
  exports.DiamondResize = DiamondResize_1.default;
10
10
  var NodeResize = {
11
- pluginName: 'node-resize',
11
+ pluginName: 'nodeResize',
12
12
  // 拖动step
13
13
  step: 0,
14
14
  // 边框和contol拖动点样式的设置
package/cjs/bpmn/index.js CHANGED
@@ -37,7 +37,7 @@ var BpmnElement = /** @class */ (function () {
37
37
  lf.setDefaultEdgeType('bpmn:sequenceFlow');
38
38
  }
39
39
  }
40
- BpmnElement.pluginName = 'BpmnElement';
40
+ BpmnElement.pluginName = 'bpmnElement';
41
41
  return BpmnElement;
42
42
  }());
43
43
  exports.BpmnElement = BpmnElement;
@@ -471,19 +471,18 @@ BpmnAdapter.shapeConfigMap.set(BpmnElements.USER, {
471
471
  height: constant_1.UserTaskConfig.height,
472
472
  });
473
473
  var BpmnXmlAdapter = {
474
- pluginName: 'bpmn-xml-adapter',
474
+ pluginName: 'bpmnXmlAdapter',
475
475
  install: function (lf) {
476
476
  lf.adapterIn = this.adapterXmlIn;
477
477
  lf.adapterOut = this.adapterXmlOut;
478
478
  },
479
479
  adapterXmlIn: function (bpmnData) {
480
- // @ts-ignore
481
- var json = new xml2json_1.default.ObjTree().parseXML(bpmnData);
480
+ var json = xml2json_1.lfXml2Json(bpmnData);
482
481
  return BpmnAdapter.adapterIn(json);
483
482
  },
484
483
  adapterXmlOut: function (data) {
485
484
  var outData = BpmnAdapter.adapterOut(data);
486
- return json2xml_1.default(outData);
485
+ return json2xml_1.lfJson2Xml(outData);
487
486
  },
488
487
  };
489
488
  exports.BpmnXmlAdapter = BpmnXmlAdapter;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lfJson2Xml = void 0;
3
4
  /**
4
5
  * This work is licensed under Creative Commons GNU LGPL License.
5
6
  * License:
@@ -51,11 +52,11 @@ function toXml(v, name, ind, deep) {
51
52
  return xml;
52
53
  }
53
54
  ;
54
- function json2xml(o) {
55
+ function lfJson2Xml(o) {
55
56
  var xmlStr = "";
56
57
  for (var m in o) {
57
58
  xmlStr += toXml(o[m], m, "\t\n", 0);
58
59
  }
59
60
  return xmlStr;
60
61
  }
61
- exports.default = json2xml;
62
+ exports.lfJson2Xml = lfJson2Xml;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.lfXml2Json = void 0;
4
5
  // ========================================================================
5
6
  // XML.ObjTree -- XML source code from/to JavaScript object like E4X
6
7
  // ========================================================================
@@ -522,4 +523,7 @@ which I will do instead of keeping this documentation like it is.
522
523
  =cut
523
524
  // ========================================================================
524
525
  */
525
- exports.default = XML;
526
+ var lfXml2Json = function (xmlData) {
527
+ return new XML.ObjTree().parseXML(xmlData);
528
+ };
529
+ exports.lfXml2Json = lfXml2Json;
@@ -26,29 +26,23 @@ var ContextMenu = /** @class */ (function () {
26
26
  var lf = _a.lf;
27
27
  this.menuTypeMap = new Map();
28
28
  this.listenDelete = function () {
29
- _this.hideMenu();
29
+ _this.hideContextMenu();
30
30
  };
31
31
  this.lf = lf;
32
32
  this.__menuDOM = document.createElement('div');
33
33
  this.__menuDOM.className = 'lf-inner-context';
34
- // const commonMenu = [];
35
34
  this.menuTypeMap.set(COMMON_TYPE_KEY, []);
36
35
  this.lf.setContextMenuByType = function (type, menus) {
37
36
  _this.menuTypeMap.set(type, menus);
38
37
  };
39
38
  this.lf.setContextMenuItems = function (menus) {
40
- _this.menuTypeMap.set(COMMON_TYPE_KEY, menus);
39
+ _this.setContextMenuItems(menus);
41
40
  };
42
41
  this.lf.showContextMenu = function (data) {
43
- if (!data || !data.id) {
44
- console.warn('请检查传入的参数');
45
- return;
46
- }
47
- _this._activeData = data;
48
- _this.createContextMenu();
42
+ _this.showContextMenu(data);
49
43
  };
50
44
  this.lf.hideContextMenu = function () {
51
- _this.hideMenu();
45
+ _this.hideContextMenu();
52
46
  };
53
47
  }
54
48
  ContextMenu.prototype.render = function (lf, container) {
@@ -66,9 +60,36 @@ var ContextMenu = /** @class */ (function () {
66
60
  _this.createContextMenu();
67
61
  });
68
62
  lf.on('blank:click', function () {
69
- _this.hideMenu();
63
+ _this.hideContextMenu();
70
64
  });
71
65
  };
66
+ /**
67
+ * 隐藏菜单
68
+ */
69
+ ContextMenu.prototype.hideContextMenu = function () {
70
+ this.__menuDOM.innerHTML = '';
71
+ this.__menuDOM.style.display = 'none';
72
+ if (this.isShow) {
73
+ this.container.removeChild(this.__menuDOM);
74
+ }
75
+ this.lf.off('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
76
+ this.isShow = false;
77
+ };
78
+ /**
79
+ * 显示指定元素菜单
80
+ * @param data 节点id、节点类型、菜单位置
81
+ */
82
+ ContextMenu.prototype.showContextMenu = function (data) {
83
+ if (!data || !data.id) {
84
+ console.warn('请检查传入的参数');
85
+ return;
86
+ }
87
+ this._activeData = data;
88
+ this.createContextMenu();
89
+ };
90
+ ContextMenu.prototype.setContextMenuItems = function (menus) {
91
+ this.menuTypeMap.set(COMMON_TYPE_KEY, menus);
92
+ };
72
93
  /**
73
94
  * 获取新菜单位置
74
95
  */
@@ -122,7 +143,7 @@ var ContextMenu = /** @class */ (function () {
122
143
  menuItem.className = menuItem.className + " " + item.className;
123
144
  }
124
145
  img.addEventListener('click', function () {
125
- _this.hideMenu();
146
+ _this.hideContextMenu();
126
147
  if (item.callback) {
127
148
  item.callback(_this._activeData);
128
149
  }
@@ -194,16 +215,7 @@ var ContextMenu = /** @class */ (function () {
194
215
  !this.isShow && this.lf.on('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
195
216
  this.isShow = true;
196
217
  };
197
- ContextMenu.prototype.hideMenu = function () {
198
- this.__menuDOM.innerHTML = '';
199
- this.__menuDOM.style.display = 'none';
200
- if (this.isShow) {
201
- this.container.removeChild(this.__menuDOM);
202
- }
203
- this.lf.off('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
204
- this.isShow = false;
205
- };
206
- ContextMenu.pluginName = 'ContextMenu';
218
+ ContextMenu.pluginName = 'contextMenu';
207
219
  return ContextMenu;
208
220
  }());
209
221
  exports.ContextMenu = ContextMenu;
@@ -21,83 +21,93 @@ var __spread = (this && this.__spread) || function () {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.Control = void 0;
24
- var Control = {
25
- pluginName: 'control',
26
- __lf: null,
27
- __controlItems: [
28
- {
29
- key: 'zoom-out',
30
- iconClass: 'lf-control-zoomOut',
31
- title: '缩小流程图',
32
- text: '缩小',
33
- onClick: function () { Control.__lf.zoom(false); },
34
- },
35
- {
36
- key: 'zoom-in',
37
- iconClass: 'lf-control-zoomIn',
38
- title: '放大流程图',
39
- text: '放大',
40
- onClick: function () { Control.__lf.zoom(true); },
41
- },
42
- {
43
- key: 'reset',
44
- iconClass: 'lf-control-fit',
45
- title: '恢复流程原有尺寸',
46
- text: '适应',
47
- onClick: function () { Control.__lf.resetZoom(); },
48
- },
49
- {
50
- key: 'undo',
51
- iconClass: 'lf-control-undo',
52
- title: '回到上一步',
53
- text: '上一步',
54
- onClick: function () { Control.__lf.undo(); },
55
- },
56
- {
57
- key: 'redo',
58
- iconClass: 'lf-control-redo',
59
- title: '移到下一步',
60
- text: '下一步',
61
- onClick: function () { Control.__lf.redo(); },
62
- },
63
- ],
64
- addItem: function (item) {
65
- Control.__controlItems.push(item);
66
- },
67
- removeItem: function (key) {
68
- var index = Control.__controlItems.findIndex(function (item) { return item.key === key; });
69
- return Control.__controlItems.splice(index, 1)[0];
70
- },
71
- install: function () { },
72
- render: function (lf, domContainer) {
73
- Control.__lf = lf;
74
- Control.__domContainer = domContainer;
75
- Control.__tool = this.__getControlTool();
76
- domContainer.appendChild(Control.__tool);
77
- },
78
- destroy: function () {
79
- var _a;
80
- try {
81
- (_a = Control.__domContainer) === null || _a === void 0 ? void 0 : _a.removeChild(Control.__tool);
24
+ var Control = /** @class */ (function () {
25
+ function Control(_a) {
26
+ var _this = this;
27
+ var lf = _a.lf;
28
+ this.controlItems = [
29
+ {
30
+ key: 'zoom-out',
31
+ iconClass: 'lf-control-zoomOut',
32
+ title: '缩小流程图',
33
+ text: '缩小',
34
+ onClick: function () {
35
+ _this.lf.zoom(false);
36
+ },
37
+ },
38
+ {
39
+ key: 'zoom-in',
40
+ iconClass: 'lf-control-zoomIn',
41
+ title: '放大流程图',
42
+ text: '放大',
43
+ onClick: function () {
44
+ _this.lf.zoom(true);
45
+ },
46
+ },
47
+ {
48
+ key: 'reset',
49
+ iconClass: 'lf-control-fit',
50
+ title: '恢复流程原有尺寸',
51
+ text: '适应',
52
+ onClick: function () {
53
+ _this.lf.resetZoom();
54
+ },
55
+ },
56
+ {
57
+ key: 'undo',
58
+ iconClass: 'lf-control-undo',
59
+ title: '回到上一步',
60
+ text: '上一步',
61
+ onClick: function () {
62
+ _this.lf.undo();
63
+ },
64
+ },
65
+ {
66
+ key: 'redo',
67
+ iconClass: 'lf-control-redo',
68
+ title: '移到下一步',
69
+ text: '下一步',
70
+ onClick: function () {
71
+ _this.lf.redo();
72
+ },
73
+ },
74
+ ];
75
+ this.lf = lf;
76
+ }
77
+ Control.prototype.render = function (lf, domContainer) {
78
+ this.destroy();
79
+ var toolEl = this.getControlTool();
80
+ this.toolEl = toolEl;
81
+ domContainer.appendChild(toolEl);
82
+ this.domContainer = domContainer;
83
+ };
84
+ Control.prototype.destroy = function () {
85
+ if (this.domContainer && this.toolEl && this.domContainer.contains(this.toolEl)) {
86
+ this.domContainer.removeChild(this.toolEl);
82
87
  }
83
- catch (e) {
84
- console.warn('unexpect destory error', e);
85
- } // todo: 目前某些情况存在此处报错情况,暂时这样处理。后续改成class写法就没有问题了。
86
- },
87
- __getControlTool: function () {
88
+ };
89
+ Control.prototype.addItem = function (item) {
90
+ this.controlItems.push(item);
91
+ };
92
+ Control.prototype.removeItem = function (key) {
93
+ var index = this.controlItems.findIndex(function (item) { return item.key === key; });
94
+ return this.controlItems.splice(index, 1)[0];
95
+ };
96
+ Control.prototype.getControlTool = function () {
97
+ var _this = this;
88
98
  var NORMAL = 'lf-control-item';
89
99
  var DISABLED = 'lf-control-item disabled';
90
100
  var controlTool = document.createElement('div');
91
101
  var controlElements = [];
92
102
  controlTool.className = 'lf-control';
93
- Control.__controlItems.forEach(function (item) {
103
+ this.controlItems.forEach(function (item) {
94
104
  var itemContainer = document.createElement('div');
95
105
  var icon = document.createElement('i');
96
106
  var text = document.createElement('span');
97
107
  itemContainer.className = DISABLED;
98
- item.onClick && (itemContainer.onclick = item.onClick.bind(null, Control.__lf));
99
- item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, Control.__lf));
100
- item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, Control.__lf));
108
+ item.onClick && (itemContainer.onclick = item.onClick.bind(null, _this.lf));
109
+ item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, _this.lf));
110
+ item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, _this.lf));
101
111
  icon.className = item.iconClass;
102
112
  text.className = 'lf-control-text';
103
113
  text.title = item.title;
@@ -105,13 +115,13 @@ var Control = {
105
115
  itemContainer.append(icon, text);
106
116
  switch (item.text) {
107
117
  case '上一步':
108
- Control.__lf.on('history:change', function (_a) {
118
+ _this.lf.on('history:change', function (_a) {
109
119
  var undoAble = _a.data.undoAble;
110
120
  itemContainer.className = undoAble ? NORMAL : DISABLED;
111
121
  });
112
122
  break;
113
123
  case '下一步':
114
- Control.__lf.on('history:change', function (_a) {
124
+ _this.lf.on('history:change', function (_a) {
115
125
  var redoAble = _a.data.redoAble;
116
126
  itemContainer.className = redoAble ? NORMAL : DISABLED;
117
127
  });
@@ -124,7 +134,9 @@ var Control = {
124
134
  });
125
135
  controlTool.append.apply(controlTool, __spread(controlElements));
126
136
  return controlTool;
127
- },
128
- };
137
+ };
138
+ Control.pluginName = 'control';
139
+ return Control;
140
+ }());
129
141
  exports.Control = Control;
130
142
  exports.default = Control;
@@ -7,20 +7,17 @@ var DndPanel = /** @class */ (function () {
7
7
  var lf = _a.lf;
8
8
  this.lf = lf;
9
9
  this.lf.setPatternItems = function (shapeList) {
10
- _this.shapeList = shapeList;
11
- // 支持渲染后重新设置拖拽面板
12
- if (_this.domContainer) {
13
- _this.render(_this.lf, _this.domContainer);
14
- }
10
+ _this.setPatternItems(shapeList);
15
11
  };
16
12
  }
17
13
  DndPanel.prototype.render = function (lf, domContainer) {
18
14
  var _this = this;
19
- if (this.panelEl) {
20
- domContainer.removeChild(this.panelEl);
21
- }
22
- if (!this.shapeList || this.shapeList.length === 0)
15
+ this.destroy();
16
+ if (!this.shapeList || this.shapeList.length === 0) {
17
+ // 首次render后失败后,后续调用setPatternItems支持渲染
18
+ this.domContainer = domContainer;
23
19
  return;
20
+ }
24
21
  this.panelEl = document.createElement('div');
25
22
  this.panelEl.className = 'lf-dndpanel';
26
23
  this.shapeList.forEach(function (shapeItem) {
@@ -29,6 +26,18 @@ var DndPanel = /** @class */ (function () {
29
26
  domContainer.appendChild(this.panelEl);
30
27
  this.domContainer = domContainer;
31
28
  };
29
+ DndPanel.prototype.destroy = function () {
30
+ if (this.domContainer && this.panelEl && this.domContainer.contains(this.panelEl)) {
31
+ this.domContainer.removeChild(this.panelEl);
32
+ }
33
+ };
34
+ DndPanel.prototype.setPatternItems = function (shapeList) {
35
+ this.shapeList = shapeList;
36
+ // 支持渲染后重新设置拖拽面板
37
+ if (this.domContainer) {
38
+ this.render(this.lf, this.domContainer);
39
+ }
40
+ };
32
41
  DndPanel.prototype.createDndItem = function (shapeItem) {
33
42
  var _this = this;
34
43
  var el = document.createElement('div');
@@ -54,12 +63,12 @@ var DndPanel = /** @class */ (function () {
54
63
  });
55
64
  }
56
65
  if (shapeItem.callback) {
57
- shapeItem.callback();
66
+ shapeItem.callback(_this.lf, _this.domContainer);
58
67
  }
59
68
  };
60
69
  return el;
61
70
  };
62
- DndPanel.pluginName = 'DndPanel';
71
+ DndPanel.pluginName = 'dndPanel';
63
72
  return DndPanel;
64
73
  }());
65
74
  exports.DndPanel = DndPanel;
@@ -33,13 +33,13 @@ var Menu = /** @class */ (function () {
33
33
  this.lf = lf;
34
34
  this.menuTypeMap = new Map();
35
35
  this.init();
36
- this.lf.setMenuConfig = function (config) {
37
- _this.resetMenuItem(config);
36
+ this.lf.extension.menu.setMenuConfig = function (config) {
37
+ _this.setMenuConfig(config);
38
38
  };
39
- this.lf.addMenuConfig = function (config) {
40
- _this.addMenuItem(config);
39
+ this.lf.extension.menu.addMenuConfig = function (config) {
40
+ _this.addMenuConfig(config);
41
41
  };
42
- this.lf.setMenuByType = function (config) {
42
+ this.lf.extension.menu.setMenuByType = function (config) {
43
43
  _this.setMenuByType(config);
44
44
  };
45
45
  }
@@ -250,7 +250,7 @@ var Menu = /** @class */ (function () {
250
250
  return menuList;
251
251
  };
252
252
  // 复写菜单
253
- Menu.prototype.resetMenuItem = function (config) {
253
+ Menu.prototype.setMenuConfig = function (config) {
254
254
  if (!config) {
255
255
  return;
256
256
  }
@@ -265,7 +265,7 @@ var Menu = /** @class */ (function () {
265
265
  && this.menuTypeMap.set(DefalutGraphMenuKey, config.graphMenu ? config.graphMenu : []);
266
266
  };
267
267
  // 在默认菜单后面追加菜单项
268
- Menu.prototype.addMenuItem = function (config) {
268
+ Menu.prototype.addMenuConfig = function (config) {
269
269
  if (!config) {
270
270
  return;
271
271
  }
@@ -289,14 +289,14 @@ var Menu = /** @class */ (function () {
289
289
  */
290
290
  Menu.prototype.changeMenuItem = function (type, config) {
291
291
  if (type === 'add')
292
- this.addMenuItem(config);
292
+ this.addMenuConfig(config);
293
293
  else if (type === 'reset')
294
- this.resetMenuItem(config);
294
+ this.setMenuConfig(config);
295
295
  else {
296
296
  throw new Error('The first parameter of changeMenuConfig should be \'add\' or \'reset\'');
297
297
  }
298
298
  };
299
- Menu.pluginName = 'Menu';
299
+ Menu.pluginName = 'menu';
300
300
  return Menu;
301
301
  }());
302
302
  exports.Menu = Menu;