@logicflow/extension 0.7.7 → 0.7.11

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
@@ -3,6 +3,62 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.7.11](https://github.com/didi/LogicFlow/compare/@logicflow/extension@0.7.10...@logicflow/extension@0.7.11) (2021-11-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * support disabled tool in core package ([1c7527f](https://github.com/didi/LogicFlow/commit/1c7527fc75929c444d9e5fb4b0b70b87086694c8))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.7.10](https://github.com/didi/LogicFlow/compare/@logicflow/extension@0.7.9...@logicflow/extension@0.7.10) (2021-11-26)
18
+
19
+
20
+ ### Features
21
+
22
+ * add mind map plugin ([11ae7e0](https://github.com/didi/LogicFlow/commit/11ae7e06f878cb6b8c82f2f73f74e8e4620fecb6))
23
+ * hide mind map ([2aa1120](https://github.com/didi/LogicFlow/commit/2aa112002023b87188c9b132dbeb6c77e92e17bf))
24
+
25
+
26
+
27
+
28
+
29
+ ## [0.7.9](https://github.com/didi/LogicFlow/compare/@logicflow/extension@0.7.8...@logicflow/extension@0.7.9) (2021-11-23)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * context menu edge icon position ([f06ead4](https://github.com/didi/LogicFlow/commit/f06ead4e687498550012e654765430d1fa1f48a2))
35
+ * nodeResize outline bugfix ([8e76f5f](https://github.com/didi/LogicFlow/commit/8e76f5f8e79a18189f48339b85904b06d29cfda2))
36
+
37
+
38
+ ### Features
39
+
40
+ * context-menu use className ([e58eaea](https://github.com/didi/LogicFlow/commit/e58eaea67aaf7c8f420aed849a4f77b753a1bc6c))
41
+
42
+
43
+
44
+
45
+
46
+ ## [0.7.8](https://github.com/didi/LogicFlow/compare/@logicflow/extension@0.7.7...@logicflow/extension@0.7.8) (2021-11-22)
47
+
48
+
49
+ ### Bug Fixes
50
+
51
+ * nodeResize getResizeShape bugfix ([e617013](https://github.com/didi/LogicFlow/commit/e617013f979cd67dbe438dad141f0eef25690aa2))
52
+
53
+
54
+ ### Features
55
+
56
+ * export context menu ([f0ff960](https://github.com/didi/LogicFlow/commit/f0ff960a2518cfe0e3f9d2a5abb843b87957def6))
57
+
58
+
59
+
60
+
61
+
6
62
  ## [0.7.7](https://github.com/didi/LogicFlow/compare/@logicflow/extension@0.7.6...@logicflow/extension@0.7.7) (2021-11-19)
7
63
 
8
64
 
@@ -71,7 +71,9 @@ var ControlGroup = /** @class */ (function (_super) {
71
71
  return (preact_1.h(Rect_1.default, { fill: "none", x: x, y: y, width: width, height: height, stroke: stroke, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray }));
72
72
  };
73
73
  ControlGroup.prototype.render = function () {
74
- return (preact_1.h("g", { className: "lf-resize-control" }, this.getResizeControl()));
74
+ return (preact_1.h("g", { className: "lf-resize-control" },
75
+ this.getGroupSolid(),
76
+ this.getResizeControl()));
75
77
  };
76
78
  return ControlGroup;
77
79
  }(preact_1.Component));
@@ -33,6 +33,7 @@ var DiamondResizeModel = /** @class */ (function (_super) {
33
33
  return _super !== null && _super.apply(this, arguments) || this;
34
34
  }
35
35
  DiamondResizeModel.prototype.setAttributes = function () {
36
+ this.hideOutline = true;
36
37
  // @ts-ignore
37
38
  var nodeSize = this.properties.nodeSize;
38
39
  if (nodeSize) {
@@ -38,6 +38,7 @@ var EllipseResizeModel = /** @class */ (function (_super) {
38
38
  return _this;
39
39
  }
40
40
  EllipseResizeModel.prototype.setAttributes = function () {
41
+ this.hideOutline = true;
41
42
  // @ts-ignore
42
43
  var nodeSize = this.properties.nodeSize;
43
44
  if (nodeSize) {
@@ -37,6 +37,7 @@ var RectResizeModel = /** @class */ (function (_super) {
37
37
  return _this;
38
38
  }
39
39
  RectResizeModel.prototype.setAttributes = function () {
40
+ this.hideOutline = true;
40
41
  // @ts-ignore
41
42
  var nodeSize = this.properties.nodeSize;
42
43
  if (nodeSize) {
@@ -55,15 +56,15 @@ var RectResizeView = /** @class */ (function (_super) {
55
56
  var _a = this.props, model = _a.model, graphModel = _a.graphModel;
56
57
  return (core_1.h(ControlGroup_1.default, __assign({}, attributes, { nodeModel: model, graphModel: graphModel })));
57
58
  };
58
- // // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
59
- // getResizeShape() {
60
- // return super.getShape();
61
- // }
59
+ // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
60
+ RectResizeView.prototype.getResizeShape = function () {
61
+ return _super.prototype.getShape.call(this);
62
+ };
62
63
  RectResizeView.prototype.getShape = function () {
63
64
  var attributes = _super.prototype.getAttributes.call(this);
64
65
  var isSelected = this.props.model.isSelected;
65
66
  return (core_1.h("g", null,
66
- _super.prototype.getShape.call(this),
67
+ this.getResizeShape(),
67
68
  isSelected ? this.getControlGroup(attributes) : ''));
68
69
  };
69
70
  return RectResizeView;
@@ -47,21 +47,6 @@ var NodeResize = {
47
47
  },
48
48
  },
49
49
  install: function (lf) {
50
- // 设置默认样式,主要将outlineColor设置为透明,不再core包中默认的节点外框
51
- lf.setTheme({
52
- rect: {
53
- strokeWidth: 2,
54
- outlineColor: 'transparent',
55
- },
56
- ellipse: {
57
- strokeWidth: 2,
58
- outlineColor: 'transparent',
59
- },
60
- diamond: {
61
- strokeWidth: 2,
62
- outlineColor: 'transparent',
63
- },
64
- });
65
50
  lf.register({
66
51
  type: RectResize_1.default.type,
67
52
  view: RectResize_1.default.view,
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.ContextMenu = void 0;
20
+ var COMMON_TYPE_KEY = 'menu-common';
21
+ var NEXT_X_DISTANCE = 200;
22
+ var NEXT_Y_DISTANCE = 100;
23
+ var ContextMenu = /** @class */ (function () {
24
+ function ContextMenu(_a) {
25
+ var _this = this;
26
+ var lf = _a.lf;
27
+ this.menuTypeMap = new Map();
28
+ this.listenDelete = function () {
29
+ _this.hideMenu();
30
+ };
31
+ this.lf = lf;
32
+ this.__menuDOM = document.createElement('div');
33
+ this.__menuDOM.className = 'lf-inner-context';
34
+ // const commonMenu = [];
35
+ this.menuTypeMap.set(COMMON_TYPE_KEY, []);
36
+ this.lf.setContextMenuByType = function (type, menus) {
37
+ _this.menuTypeMap.set(type, menus);
38
+ };
39
+ this.lf.setContextMenuItems = function (menus) {
40
+ _this.menuTypeMap.set(COMMON_TYPE_KEY, menus);
41
+ };
42
+ this.lf.showContextMenu = function (data) {
43
+ if (!data || !data.id) {
44
+ console.warn('请检查传入的参数');
45
+ return;
46
+ }
47
+ _this._activeData = data;
48
+ _this.createContextMenu();
49
+ };
50
+ this.lf.hideContextMenu = function () {
51
+ _this.hideMenu();
52
+ };
53
+ }
54
+ ContextMenu.prototype.render = function (lf, container) {
55
+ var _this = this;
56
+ this.container = container;
57
+ lf.on('node:click', function (_a) {
58
+ var data = _a.data;
59
+ _this._activeData = data;
60
+ _this.createContextMenu();
61
+ });
62
+ lf.on('edge:click', function (_a) {
63
+ var data = _a.data;
64
+ // 获取右上角坐标
65
+ _this._activeData = data;
66
+ _this.createContextMenu();
67
+ });
68
+ lf.on('blank:click', function () {
69
+ _this.hideMenu();
70
+ });
71
+ };
72
+ /**
73
+ * 获取新菜单位置
74
+ */
75
+ ContextMenu.prototype.getContextMenuPosition = function () {
76
+ var data = this._activeData;
77
+ var Model = this.lf.graphModel.getElement(data.id);
78
+ if (!Model) {
79
+ console.warn("\u627E\u4E0D\u5230\u5143\u7D20" + data.id);
80
+ return;
81
+ }
82
+ var x;
83
+ var y;
84
+ if (Model.BaseType === 'edge') {
85
+ x = Number.MIN_SAFE_INTEGER;
86
+ y = Number.MAX_SAFE_INTEGER;
87
+ var edgeData = Model.getData();
88
+ x = Math.max(edgeData.startPoint.x, x);
89
+ y = Math.min(edgeData.startPoint.y, y);
90
+ x = Math.max(edgeData.endPoint.x, x);
91
+ y = Math.min(edgeData.endPoint.y, y);
92
+ if (edgeData.pointsList) {
93
+ edgeData.pointsList.forEach(function (point) {
94
+ x = Math.max(point.x, x);
95
+ y = Math.min(point.y, y);
96
+ });
97
+ }
98
+ }
99
+ if (Model.BaseType === 'node') {
100
+ x = data.x + Model.width / 2;
101
+ y = data.y - Model.height / 2;
102
+ }
103
+ return this.lf.graphModel.transformMatrix.CanvasPointToHtmlPoint([x, y]);
104
+ };
105
+ ContextMenu.prototype.createContextMenu = function () {
106
+ var _this = this;
107
+ var isSilentMode = this.lf.options.isSilentMode;
108
+ // 静默模式不显示菜单
109
+ if (isSilentMode) {
110
+ return;
111
+ }
112
+ var items = this.menuTypeMap.get(this._activeData.type) || [];
113
+ items = items.concat(this.menuTypeMap.get(COMMON_TYPE_KEY));
114
+ var menus = document.createDocumentFragment();
115
+ items.forEach(function (item) {
116
+ var menuItem = document.createElement('div');
117
+ menuItem.className = 'lf-context-item';
118
+ var img = document.createElement('img');
119
+ img.src = item.icon;
120
+ img.className = 'lf-context-img';
121
+ if (item.className) {
122
+ menuItem.className = menuItem.className + " " + item.className;
123
+ }
124
+ img.addEventListener('click', function () {
125
+ _this.hideMenu();
126
+ if (item.callback) {
127
+ item.callback(_this._activeData);
128
+ }
129
+ else {
130
+ _this.addNode({
131
+ sourceId: _this._activeData.id,
132
+ x: _this._activeData.x,
133
+ y: _this._activeData.y,
134
+ properties: item.properties,
135
+ type: item.type,
136
+ });
137
+ }
138
+ });
139
+ menuItem.appendChild(img);
140
+ menus.appendChild(menuItem);
141
+ });
142
+ this.__menuDOM.innerHTML = '';
143
+ this.__menuDOM.appendChild(menus);
144
+ this.showMenu();
145
+ };
146
+ ContextMenu.prototype.addNode = function (node, y) {
147
+ var isDeep = y !== undefined;
148
+ if (y === undefined) {
149
+ y = node.y;
150
+ }
151
+ var nodeModel = this.lf.getNodeModel(node.sourceId);
152
+ var leftTopX = node.x - nodeModel.width + NEXT_X_DISTANCE;
153
+ var leftTopY = y - node.y / 2 - 20;
154
+ var rightBottomX = node.x + nodeModel.width + NEXT_X_DISTANCE;
155
+ var rightBottomY = y + node.y / 2 + 20;
156
+ var exsitElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
157
+ if (exsitElements.length) {
158
+ y = y + NEXT_Y_DISTANCE;
159
+ this.addNode(node, y);
160
+ return;
161
+ }
162
+ var newNode = this.lf.addNode({
163
+ type: node.type,
164
+ x: node.x + 200,
165
+ y: y,
166
+ properties: node.properties,
167
+ });
168
+ var startPoint;
169
+ var endPoint;
170
+ if (isDeep) {
171
+ startPoint = {
172
+ x: node.x,
173
+ y: node.y + nodeModel.height / 2,
174
+ };
175
+ endPoint = {
176
+ x: newNode.x - newNode.width / 2,
177
+ y: newNode.y,
178
+ };
179
+ }
180
+ this.lf.createEdge({
181
+ sourceNodeId: node.sourceId,
182
+ targetNodeId: newNode.id,
183
+ startPoint: startPoint,
184
+ endPoint: endPoint,
185
+ });
186
+ };
187
+ ContextMenu.prototype.showMenu = function () {
188
+ var _a = __read(this.getContextMenuPosition(), 2), x = _a[0], y = _a[1];
189
+ this.__menuDOM.style.display = 'flex';
190
+ this.__menuDOM.style.top = y + "px";
191
+ this.__menuDOM.style.left = x + 10 + "px";
192
+ this.container.appendChild(this.__menuDOM);
193
+ // 菜单显示的时候,监听删除,同时隐藏
194
+ !this.isShow && this.lf.on('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
195
+ this.isShow = true;
196
+ };
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';
207
+ return ContextMenu;
208
+ }());
209
+ exports.ContextMenu = ContextMenu;
210
+ exports.default = ContextMenu;
@@ -8,6 +8,10 @@ var DndPanel = /** @class */ (function () {
8
8
  this.lf = lf;
9
9
  this.lf.setPatternItems = function (shapeList) {
10
10
  _this.shapeList = shapeList;
11
+ // 支持渲染后重新设置拖拽面板
12
+ if (_this.domContainer) {
13
+ _this.render(_this.lf, _this.domContainer);
14
+ }
11
15
  };
12
16
  }
13
17
  DndPanel.prototype.render = function (lf, domContainer) {
@@ -23,6 +27,7 @@ var DndPanel = /** @class */ (function () {
23
27
  _this.panelEl.appendChild(_this.createDndItem(shapeItem));
24
28
  });
25
29
  domContainer.appendChild(this.panelEl);
30
+ this.domContainer = domContainer;
26
31
  };
27
32
  DndPanel.prototype.createDndItem = function (shapeItem) {
28
33
  var _this = this;
package/cjs/index.js CHANGED
@@ -11,12 +11,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./bpmn"), exports);
14
+ // export * from './~mindmap';
14
15
  __exportStar(require("./tools/snapshot"), exports);
15
16
  __exportStar(require("./bpmn-adapter"), exports);
16
17
  __exportStar(require("./turbo-adapter"), exports);
17
18
  __exportStar(require("./insert-node-in-polyline"), exports);
18
19
  __exportStar(require("./components/control"), exports);
19
20
  __exportStar(require("./components/menu"), exports);
21
+ __exportStar(require("./components/context-menu"), exports);
20
22
  __exportStar(require("./components/dnd-panel"), exports);
21
23
  __exportStar(require("./components/selection-select"), exports);
22
24
  __exportStar(require("./components/mini-map"), exports);
@@ -191,7 +191,17 @@
191
191
  width: 20px;
192
192
  height: 20px;
193
193
  margin: 0 2px 2px 0;
194
+ box-sizing: content-box;
194
195
  }
195
196
  .lf-context-item:hover {
196
197
  background: rgba(201, 217, 216, 0.5);
198
+ }
199
+ .lf-context-img {
200
+ width: 20px;
201
+ height: 20px;
202
+ cursor: pointer;
203
+ }
204
+ /* mind map */
205
+ .lf-mindmap_addIcon {
206
+ margin-top: 10px;
197
207
  }
@@ -69,7 +69,9 @@ var ControlGroup = /** @class */ (function (_super) {
69
69
  return (h(Rect, { fill: "none", x: x, y: y, width: width, height: height, stroke: stroke, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray }));
70
70
  };
71
71
  ControlGroup.prototype.render = function () {
72
- return (h("g", { className: "lf-resize-control" }, this.getResizeControl()));
72
+ return (h("g", { className: "lf-resize-control" },
73
+ this.getGroupSolid(),
74
+ this.getResizeControl()));
73
75
  };
74
76
  return ControlGroup;
75
77
  }(Component));
@@ -31,6 +31,7 @@ var DiamondResizeModel = /** @class */ (function (_super) {
31
31
  return _super !== null && _super.apply(this, arguments) || this;
32
32
  }
33
33
  DiamondResizeModel.prototype.setAttributes = function () {
34
+ this.hideOutline = true;
34
35
  // @ts-ignore
35
36
  var nodeSize = this.properties.nodeSize;
36
37
  if (nodeSize) {
@@ -36,6 +36,7 @@ var EllipseResizeModel = /** @class */ (function (_super) {
36
36
  return _this;
37
37
  }
38
38
  EllipseResizeModel.prototype.setAttributes = function () {
39
+ this.hideOutline = true;
39
40
  // @ts-ignore
40
41
  var nodeSize = this.properties.nodeSize;
41
42
  if (nodeSize) {
@@ -8,6 +8,7 @@ declare class RectResizeModel extends RectNodeModel {
8
8
  }
9
9
  declare class RectResizeView extends RectNode {
10
10
  getControlGroup(attributes: any): h.JSX.Element;
11
+ getResizeShape(): h.JSX.Element;
11
12
  getShape(): h.JSX.Element;
12
13
  }
13
14
  declare const RectResize: {
@@ -35,6 +35,7 @@ var RectResizeModel = /** @class */ (function (_super) {
35
35
  return _this;
36
36
  }
37
37
  RectResizeModel.prototype.setAttributes = function () {
38
+ this.hideOutline = true;
38
39
  // @ts-ignore
39
40
  var nodeSize = this.properties.nodeSize;
40
41
  if (nodeSize) {
@@ -53,15 +54,15 @@ var RectResizeView = /** @class */ (function (_super) {
53
54
  var _a = this.props, model = _a.model, graphModel = _a.graphModel;
54
55
  return (h(ControlGroup, __assign({}, attributes, { nodeModel: model, graphModel: graphModel })));
55
56
  };
56
- // // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
57
- // getResizeShape() {
58
- // return super.getShape();
59
- // }
57
+ // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
58
+ RectResizeView.prototype.getResizeShape = function () {
59
+ return _super.prototype.getShape.call(this);
60
+ };
60
61
  RectResizeView.prototype.getShape = function () {
61
62
  var attributes = _super.prototype.getAttributes.call(this);
62
63
  var isSelected = this.props.model.isSelected;
63
64
  return (h("g", null,
64
- _super.prototype.getShape.call(this),
65
+ this.getResizeShape(),
65
66
  isSelected ? this.getControlGroup(attributes) : ''));
66
67
  };
67
68
  return RectResizeView;
@@ -41,21 +41,6 @@ var NodeResize = {
41
41
  },
42
42
  },
43
43
  install: function (lf) {
44
- // 设置默认样式,主要将outlineColor设置为透明,不再core包中默认的节点外框
45
- lf.setTheme({
46
- rect: {
47
- strokeWidth: 2,
48
- outlineColor: 'transparent',
49
- },
50
- ellipse: {
51
- strokeWidth: 2,
52
- outlineColor: 'transparent',
53
- },
54
- diamond: {
55
- strokeWidth: 2,
56
- outlineColor: 'transparent',
57
- },
58
- });
59
44
  lf.register({
60
45
  type: RectResize.type,
61
46
  view: RectResize.view,
@@ -0,0 +1,24 @@
1
+ declare class ContextMenu {
2
+ static pluginName: string;
3
+ private __menuDOM;
4
+ private lf;
5
+ private _activeData;
6
+ private menuTypeMap;
7
+ container: any;
8
+ isShow: boolean;
9
+ constructor({ lf }: {
10
+ lf: any;
11
+ });
12
+ render(lf: any, container: any): void;
13
+ /**
14
+ * 获取新菜单位置
15
+ */
16
+ private getContextMenuPosition;
17
+ private createContextMenu;
18
+ private addNode;
19
+ private showMenu;
20
+ listenDelete: () => void;
21
+ private hideMenu;
22
+ }
23
+ export default ContextMenu;
24
+ export { ContextMenu, };