@logicflow/extension 1.0.5 → 1.0.7

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 (44) hide show
  1. package/cjs/bpmn-adapter/index.js +2 -3
  2. package/cjs/bpmn-adapter/json2xml.js +3 -2
  3. package/cjs/bpmn-adapter/xml2json.js +5 -1
  4. package/cjs/components/control/index.js +97 -71
  5. package/cjs/components/dnd-panel/index.js +11 -5
  6. package/cjs/index.js +2 -0
  7. package/cjs/tools/snapshot/index.js +5 -5
  8. package/es/bpmn-adapter/index.js +4 -5
  9. package/es/bpmn-adapter/json2xml.d.ts +2 -1
  10. package/es/bpmn-adapter/json2xml.js +2 -1
  11. package/es/bpmn-adapter/xml2json.d.ts +2 -2
  12. package/es/bpmn-adapter/xml2json.js +4 -1
  13. package/es/components/control/index.d.ts +16 -12
  14. package/es/components/control/index.js +98 -72
  15. package/es/components/dnd-panel/index.d.ts +3 -1
  16. package/es/components/dnd-panel/index.js +11 -5
  17. package/es/index.d.ts +2 -0
  18. package/es/index.js +2 -0
  19. package/es/tools/snapshot/index.js +5 -5
  20. package/lib/AutoLayout.js +1 -1
  21. package/lib/BpmnAdapter.js +1 -1
  22. package/lib/BpmnElement.js +1 -1
  23. package/lib/ContextMenu.js +1 -1
  24. package/lib/Control.js +1 -1
  25. package/lib/CurvedEdge.js +1 -1
  26. package/lib/DndPanel.js +1 -1
  27. package/lib/FlowPath.js +1 -1
  28. package/lib/Group.js +1 -1
  29. package/lib/InsertNodeInPolyline.js +1 -1
  30. package/lib/Menu.js +1 -1
  31. package/lib/MiniMap.js +1 -1
  32. package/lib/NodeResize.js +1 -1
  33. package/lib/RectLabelNode.js +1 -1
  34. package/lib/SelectionSelect.js +1 -1
  35. package/lib/Snapshot.js +1 -1
  36. package/lib/TurboAdapter.js +1 -1
  37. package/lib/lfJson2Xml.js +1 -0
  38. package/lib/lfXml2Json.js +1 -0
  39. package/package.json +2 -2
  40. package/types/bpmn-adapter/json2xml.d.ts +2 -1
  41. package/types/bpmn-adapter/xml2json.d.ts +2 -2
  42. package/types/components/control/index.d.ts +16 -12
  43. package/types/components/dnd-panel/index.d.ts +3 -1
  44. package/types/index.d.ts +2 -0
@@ -477,13 +477,12 @@ var BpmnXmlAdapter = {
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;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __read = (this && this.__read) || function (o, n) {
3
14
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
15
  if (!m) return o;
@@ -21,83 +32,96 @@ var __spread = (this && this.__spread) || function () {
21
32
  };
22
33
  Object.defineProperty(exports, "__esModule", { value: true });
23
34
  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);
35
+ var Control = /** @class */ (function () {
36
+ function Control(_a) {
37
+ var _b;
38
+ var _this = this;
39
+ var lf = _a.lf;
40
+ var _c;
41
+ this.controlItems = [
42
+ {
43
+ key: 'zoom-out',
44
+ iconClass: 'lf-control-zoomOut',
45
+ title: '缩小流程图',
46
+ text: '缩小',
47
+ onClick: function () {
48
+ _this.lf.zoom(false);
49
+ },
50
+ },
51
+ {
52
+ key: 'zoom-in',
53
+ iconClass: 'lf-control-zoomIn',
54
+ title: '放大流程图',
55
+ text: '放大',
56
+ onClick: function () {
57
+ _this.lf.zoom(true);
58
+ },
59
+ },
60
+ {
61
+ key: 'reset',
62
+ iconClass: 'lf-control-fit',
63
+ title: '恢复流程原有尺寸',
64
+ text: '适应',
65
+ onClick: function () {
66
+ _this.lf.resetZoom();
67
+ },
68
+ },
69
+ {
70
+ key: 'undo',
71
+ iconClass: 'lf-control-undo',
72
+ title: '回到上一步',
73
+ text: '上一步',
74
+ onClick: function () {
75
+ _this.lf.undo();
76
+ },
77
+ },
78
+ {
79
+ key: 'redo',
80
+ iconClass: 'lf-control-redo',
81
+ title: '移到下一步',
82
+ text: '下一步',
83
+ onClick: function () {
84
+ _this.lf.redo();
85
+ },
86
+ },
87
+ ];
88
+ this.lf = lf;
89
+ this.lf.extension = __assign(__assign({}, ((_c = this.lf.extension) !== null && _c !== void 0 ? _c : {})), (_b = {}, _b[Control.pluginName] = this, _b));
90
+ }
91
+ Control.prototype.render = function (lf, domContainer) {
92
+ this.destroy();
93
+ var toolEl = this.getControlTool();
94
+ this.toolEl = toolEl;
95
+ domContainer.appendChild(toolEl);
96
+ this.domContainer = domContainer;
97
+ };
98
+ Control.prototype.destroy = function () {
99
+ if (this.domContainer && this.toolEl && this.domContainer.contains(this.toolEl)) {
100
+ this.domContainer.removeChild(this.toolEl);
82
101
  }
83
- catch (e) {
84
- console.warn('unexpect destory error', e);
85
- } // todo: 目前某些情况存在此处报错情况,暂时这样处理。后续改成class写法就没有问题了。
86
- },
87
- __getControlTool: function () {
102
+ };
103
+ Control.prototype.addItem = function (item) {
104
+ this.controlItems.push(item);
105
+ };
106
+ Control.prototype.removeItem = function (key) {
107
+ var index = this.controlItems.findIndex(function (item) { return item.key === key; });
108
+ return this.controlItems.splice(index, 1)[0];
109
+ };
110
+ Control.prototype.getControlTool = function () {
111
+ var _this = this;
88
112
  var NORMAL = 'lf-control-item';
89
113
  var DISABLED = 'lf-control-item disabled';
90
114
  var controlTool = document.createElement('div');
91
115
  var controlElements = [];
92
116
  controlTool.className = 'lf-control';
93
- Control.__controlItems.forEach(function (item) {
117
+ this.controlItems.forEach(function (item) {
94
118
  var itemContainer = document.createElement('div');
95
119
  var icon = document.createElement('i');
96
120
  var text = document.createElement('span');
97
121
  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));
122
+ item.onClick && (itemContainer.onclick = item.onClick.bind(null, _this.lf));
123
+ item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, _this.lf));
124
+ item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, _this.lf));
101
125
  icon.className = item.iconClass;
102
126
  text.className = 'lf-control-text';
103
127
  text.title = item.title;
@@ -105,13 +129,13 @@ var Control = {
105
129
  itemContainer.append(icon, text);
106
130
  switch (item.text) {
107
131
  case '上一步':
108
- Control.__lf.on('history:change', function (_a) {
132
+ _this.lf.on('history:change', function (_a) {
109
133
  var undoAble = _a.data.undoAble;
110
134
  itemContainer.className = undoAble ? NORMAL : DISABLED;
111
135
  });
112
136
  break;
113
137
  case '下一步':
114
- Control.__lf.on('history:change', function (_a) {
138
+ _this.lf.on('history:change', function (_a) {
115
139
  var redoAble = _a.data.redoAble;
116
140
  itemContainer.className = redoAble ? NORMAL : DISABLED;
117
141
  });
@@ -124,7 +148,9 @@ var Control = {
124
148
  });
125
149
  controlTool.append.apply(controlTool, __spread(controlElements));
126
150
  return controlTool;
127
- },
128
- };
151
+ };
152
+ Control.pluginName = 'control';
153
+ return Control;
154
+ }());
129
155
  exports.Control = Control;
130
156
  exports.default = Control;
@@ -16,11 +16,12 @@ var DndPanel = /** @class */ (function () {
16
16
  }
17
17
  DndPanel.prototype.render = function (lf, domContainer) {
18
18
  var _this = this;
19
- if (this.panelEl) {
20
- domContainer.removeChild(this.panelEl);
21
- }
22
- if (!this.shapeList || this.shapeList.length === 0)
19
+ this.destroy();
20
+ if (!this.shapeList || this.shapeList.length === 0) {
21
+ // 首次render后失败后,后续调用setPatternItems支持渲染
22
+ this.domContainer = domContainer;
23
23
  return;
24
+ }
24
25
  this.panelEl = document.createElement('div');
25
26
  this.panelEl.className = 'lf-dndpanel';
26
27
  this.shapeList.forEach(function (shapeItem) {
@@ -29,6 +30,11 @@ var DndPanel = /** @class */ (function () {
29
30
  domContainer.appendChild(this.panelEl);
30
31
  this.domContainer = domContainer;
31
32
  };
33
+ DndPanel.prototype.destroy = function () {
34
+ if (this.domContainer && this.panelEl && this.domContainer.contains(this.panelEl)) {
35
+ this.domContainer.removeChild(this.panelEl);
36
+ }
37
+ };
32
38
  DndPanel.prototype.createDndItem = function (shapeItem) {
33
39
  var _this = this;
34
40
  var el = document.createElement('div');
@@ -54,7 +60,7 @@ var DndPanel = /** @class */ (function () {
54
60
  });
55
61
  }
56
62
  if (shapeItem.callback) {
57
- shapeItem.callback();
63
+ shapeItem.callback(_this.lf, _this.domContainer);
58
64
  }
59
65
  };
60
66
  return el;
package/cjs/index.js CHANGED
@@ -27,3 +27,5 @@ __exportStar(require("./materials/group"), exports);
27
27
  __exportStar(require("./NodeResize"), exports);
28
28
  __exportStar(require("./tools/flow-path"), exports);
29
29
  __exportStar(require("./tools/auto-layout"), exports);
30
+ __exportStar(require("./bpmn-adapter/xml2json"), exports);
31
+ __exportStar(require("./bpmn-adapter/json2xml"), exports);
@@ -132,11 +132,6 @@ var Snapshot = {
132
132
  var _this = this;
133
133
  var copy = svg.cloneNode(true);
134
134
  var graph = copy.lastChild;
135
- var style = document.createElement('style');
136
- style.innerHTML = this.getClassRules();
137
- var foreignObject = document.createElement('foreignObject');
138
- foreignObject.appendChild(style);
139
- copy.appendChild(foreignObject);
140
135
  var childLength = graph.childNodes && graph.childNodes.length;
141
136
  if (childLength) {
142
137
  for (var i = 0; i < childLength; i++) {
@@ -190,6 +185,11 @@ var Snapshot = {
190
185
  ctx.clearRect(0, 0, bboxWidth, bboxHeight);
191
186
  }
192
187
  var img = new Image();
188
+ var style = document.createElement('style');
189
+ style.innerHTML = this.getClassRules();
190
+ var foreignObject = document.createElement('foreignObject');
191
+ foreignObject.appendChild(style);
192
+ copy.appendChild(foreignObject);
193
193
  return new Promise(function (resolve) {
194
194
  img.onload = function () {
195
195
  ctx.drawImage(img, 0, 0);
@@ -15,8 +15,8 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  return ar;
16
16
  };
17
17
  import { getBpmnId } from './bpmnIds';
18
- import json2xml from './json2xml';
19
- import XML from './xml2json';
18
+ import { lfJson2Xml } from './json2xml';
19
+ import { lfXml2Json } from './xml2json';
20
20
  import { ExclusiveGatewayConfig, StartEventConfig, EndEventConfig, ServiceTaskConfig, UserTaskConfig, } from '../bpmn/constant';
21
21
  var BpmnElements;
22
22
  (function (BpmnElements) {
@@ -473,13 +473,12 @@ var BpmnXmlAdapter = {
473
473
  lf.adapterOut = this.adapterXmlOut;
474
474
  },
475
475
  adapterXmlIn: function (bpmnData) {
476
- // @ts-ignore
477
- var json = new XML.ObjTree().parseXML(bpmnData);
476
+ var json = lfXml2Json(bpmnData);
478
477
  return BpmnAdapter.adapterIn(json);
479
478
  },
480
479
  adapterXmlOut: function (data) {
481
480
  var outData = BpmnAdapter.adapterOut(data);
482
- return json2xml(outData);
481
+ return lfJson2Xml(outData);
483
482
  },
484
483
  };
485
484
  export { BpmnAdapter, BpmnXmlAdapter, };
@@ -1 +1,2 @@
1
- export default function json2xml(o: any): string;
1
+ declare function lfJson2Xml(o: any): string;
2
+ export { lfJson2Xml };
@@ -49,10 +49,11 @@ function toXml(v, name, ind, deep) {
49
49
  return xml;
50
50
  }
51
51
  ;
52
- export default function json2xml(o) {
52
+ function lfJson2Xml(o) {
53
53
  var xmlStr = "";
54
54
  for (var m in o) {
55
55
  xmlStr += toXml(o[m], m, "\t\n", 0);
56
56
  }
57
57
  return xmlStr;
58
58
  }
59
+ export { lfJson2Xml };
@@ -1,2 +1,2 @@
1
- declare let XML: () => void;
2
- export default XML;
1
+ declare const lfXml2Json: (xmlData: any) => any;
2
+ export { lfXml2Json, };
@@ -520,4 +520,7 @@ which I will do instead of keeping this documentation like it is.
520
520
  =cut
521
521
  // ========================================================================
522
522
  */
523
- export default XML;
523
+ var lfXml2Json = function (xmlData) {
524
+ return new XML.ObjTree().parseXML(xmlData);
525
+ };
526
+ export { lfXml2Json, };
@@ -1,4 +1,4 @@
1
- import LogicFlow, { Extension } from '@logicflow/core';
1
+ import LogicFlow from '@logicflow/core';
2
2
  declare type ControlItem = {
3
3
  key: string;
4
4
  iconClass: string;
@@ -8,16 +8,20 @@ declare type ControlItem = {
8
8
  onMouseEnter?: Function;
9
9
  onMouseLeave?: Function;
10
10
  };
11
- interface ControlPlugin extends Extension {
12
- pluginName: string;
13
- __lf?: LogicFlow;
14
- __controlItems: ControlItem[];
15
- addItem: (item: ControlItem) => void;
16
- removeItem: (key: string) => ControlItem;
17
- install: (lf: any) => void;
18
- render: (lf: any, domContainer: any) => void;
19
- __getControlTool: () => HTMLElement;
11
+ declare class Control {
12
+ lf: LogicFlow;
13
+ static pluginName: string;
14
+ controlItems: ControlItem[];
15
+ domContainer: HTMLElement;
16
+ toolEl: HTMLElement;
17
+ constructor({ lf }: {
18
+ lf: any;
19
+ });
20
+ render(lf: any, domContainer: any): void;
21
+ destroy(): void;
22
+ addItem(item: any): void;
23
+ removeItem(key: any): ControlItem;
24
+ private getControlTool;
20
25
  }
21
- declare const Control: ControlPlugin;
22
26
  export default Control;
23
- export { Control, };
27
+ export { Control };
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __read = (this && this.__read) || function (o, n) {
2
13
  var m = typeof Symbol === "function" && o[Symbol.iterator];
3
14
  if (!m) return o;
@@ -18,83 +29,96 @@ var __spread = (this && this.__spread) || function () {
18
29
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
19
30
  return ar;
20
31
  };
21
- var Control = {
22
- pluginName: 'control',
23
- __lf: null,
24
- __controlItems: [
25
- {
26
- key: 'zoom-out',
27
- iconClass: 'lf-control-zoomOut',
28
- title: '缩小流程图',
29
- text: '缩小',
30
- onClick: function () { Control.__lf.zoom(false); },
31
- },
32
- {
33
- key: 'zoom-in',
34
- iconClass: 'lf-control-zoomIn',
35
- title: '放大流程图',
36
- text: '放大',
37
- onClick: function () { Control.__lf.zoom(true); },
38
- },
39
- {
40
- key: 'reset',
41
- iconClass: 'lf-control-fit',
42
- title: '恢复流程原有尺寸',
43
- text: '适应',
44
- onClick: function () { Control.__lf.resetZoom(); },
45
- },
46
- {
47
- key: 'undo',
48
- iconClass: 'lf-control-undo',
49
- title: '回到上一步',
50
- text: '上一步',
51
- onClick: function () { Control.__lf.undo(); },
52
- },
53
- {
54
- key: 'redo',
55
- iconClass: 'lf-control-redo',
56
- title: '移到下一步',
57
- text: '下一步',
58
- onClick: function () { Control.__lf.redo(); },
59
- },
60
- ],
61
- addItem: function (item) {
62
- Control.__controlItems.push(item);
63
- },
64
- removeItem: function (key) {
65
- var index = Control.__controlItems.findIndex(function (item) { return item.key === key; });
66
- return Control.__controlItems.splice(index, 1)[0];
67
- },
68
- install: function () { },
69
- render: function (lf, domContainer) {
70
- Control.__lf = lf;
71
- Control.__domContainer = domContainer;
72
- Control.__tool = this.__getControlTool();
73
- domContainer.appendChild(Control.__tool);
74
- },
75
- destroy: function () {
76
- var _a;
77
- try {
78
- (_a = Control.__domContainer) === null || _a === void 0 ? void 0 : _a.removeChild(Control.__tool);
32
+ var Control = /** @class */ (function () {
33
+ function Control(_a) {
34
+ var _b;
35
+ var _this = this;
36
+ var lf = _a.lf;
37
+ var _c;
38
+ this.controlItems = [
39
+ {
40
+ key: 'zoom-out',
41
+ iconClass: 'lf-control-zoomOut',
42
+ title: '缩小流程图',
43
+ text: '缩小',
44
+ onClick: function () {
45
+ _this.lf.zoom(false);
46
+ },
47
+ },
48
+ {
49
+ key: 'zoom-in',
50
+ iconClass: 'lf-control-zoomIn',
51
+ title: '放大流程图',
52
+ text: '放大',
53
+ onClick: function () {
54
+ _this.lf.zoom(true);
55
+ },
56
+ },
57
+ {
58
+ key: 'reset',
59
+ iconClass: 'lf-control-fit',
60
+ title: '恢复流程原有尺寸',
61
+ text: '适应',
62
+ onClick: function () {
63
+ _this.lf.resetZoom();
64
+ },
65
+ },
66
+ {
67
+ key: 'undo',
68
+ iconClass: 'lf-control-undo',
69
+ title: '回到上一步',
70
+ text: '上一步',
71
+ onClick: function () {
72
+ _this.lf.undo();
73
+ },
74
+ },
75
+ {
76
+ key: 'redo',
77
+ iconClass: 'lf-control-redo',
78
+ title: '移到下一步',
79
+ text: '下一步',
80
+ onClick: function () {
81
+ _this.lf.redo();
82
+ },
83
+ },
84
+ ];
85
+ this.lf = lf;
86
+ this.lf.extension = __assign(__assign({}, ((_c = this.lf.extension) !== null && _c !== void 0 ? _c : {})), (_b = {}, _b[Control.pluginName] = this, _b));
87
+ }
88
+ Control.prototype.render = function (lf, domContainer) {
89
+ this.destroy();
90
+ var toolEl = this.getControlTool();
91
+ this.toolEl = toolEl;
92
+ domContainer.appendChild(toolEl);
93
+ this.domContainer = domContainer;
94
+ };
95
+ Control.prototype.destroy = function () {
96
+ if (this.domContainer && this.toolEl && this.domContainer.contains(this.toolEl)) {
97
+ this.domContainer.removeChild(this.toolEl);
79
98
  }
80
- catch (e) {
81
- console.warn('unexpect destory error', e);
82
- } // todo: 目前某些情况存在此处报错情况,暂时这样处理。后续改成class写法就没有问题了。
83
- },
84
- __getControlTool: function () {
99
+ };
100
+ Control.prototype.addItem = function (item) {
101
+ this.controlItems.push(item);
102
+ };
103
+ Control.prototype.removeItem = function (key) {
104
+ var index = this.controlItems.findIndex(function (item) { return item.key === key; });
105
+ return this.controlItems.splice(index, 1)[0];
106
+ };
107
+ Control.prototype.getControlTool = function () {
108
+ var _this = this;
85
109
  var NORMAL = 'lf-control-item';
86
110
  var DISABLED = 'lf-control-item disabled';
87
111
  var controlTool = document.createElement('div');
88
112
  var controlElements = [];
89
113
  controlTool.className = 'lf-control';
90
- Control.__controlItems.forEach(function (item) {
114
+ this.controlItems.forEach(function (item) {
91
115
  var itemContainer = document.createElement('div');
92
116
  var icon = document.createElement('i');
93
117
  var text = document.createElement('span');
94
118
  itemContainer.className = DISABLED;
95
- item.onClick && (itemContainer.onclick = item.onClick.bind(null, Control.__lf));
96
- item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, Control.__lf));
97
- item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, Control.__lf));
119
+ item.onClick && (itemContainer.onclick = item.onClick.bind(null, _this.lf));
120
+ item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, _this.lf));
121
+ item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, _this.lf));
98
122
  icon.className = item.iconClass;
99
123
  text.className = 'lf-control-text';
100
124
  text.title = item.title;
@@ -102,13 +126,13 @@ var Control = {
102
126
  itemContainer.append(icon, text);
103
127
  switch (item.text) {
104
128
  case '上一步':
105
- Control.__lf.on('history:change', function (_a) {
129
+ _this.lf.on('history:change', function (_a) {
106
130
  var undoAble = _a.data.undoAble;
107
131
  itemContainer.className = undoAble ? NORMAL : DISABLED;
108
132
  });
109
133
  break;
110
134
  case '下一步':
111
- Control.__lf.on('history:change', function (_a) {
135
+ _this.lf.on('history:change', function (_a) {
112
136
  var redoAble = _a.data.redoAble;
113
137
  itemContainer.className = redoAble ? NORMAL : DISABLED;
114
138
  });
@@ -121,7 +145,9 @@ var Control = {
121
145
  });
122
146
  controlTool.append.apply(controlTool, __spread(controlElements));
123
147
  return controlTool;
124
- },
125
- };
148
+ };
149
+ Control.pluginName = 'control';
150
+ return Control;
151
+ }());
126
152
  export default Control;
127
- export { Control, };
153
+ export { Control };