@logicflow/extension 1.2.0-alpha.0 → 1.2.0-alpha.3

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 (53) hide show
  1. package/cjs/components/control/index.js +16 -16
  2. package/cjs/components/menu/index.js +9 -9
  3. package/cjs/index.js +1 -0
  4. package/cjs/locale/en-locale/en.js +22 -0
  5. package/cjs/locale/en-locale/index.js +29 -0
  6. package/cjs/locale/locale.js +19 -0
  7. package/cjs/tools/snapshot/index.js +47 -46
  8. package/cjs/turbo-adapter/index.js +71 -41
  9. package/es/components/control/index.d.ts +2 -3
  10. package/es/components/control/index.js +16 -16
  11. package/es/components/menu/index.d.ts +2 -3
  12. package/es/components/menu/index.js +9 -9
  13. package/es/index.d.ts +1 -0
  14. package/es/index.js +1 -0
  15. package/es/locale/en-locale/en.d.ts +19 -0
  16. package/es/locale/en-locale/en.js +19 -0
  17. package/es/locale/en-locale/index.d.ts +9 -0
  18. package/es/locale/en-locale/index.js +26 -0
  19. package/es/locale/locale.d.ts +6 -0
  20. package/es/locale/locale.js +16 -0
  21. package/es/tools/snapshot/index.d.ts +15 -7
  22. package/es/tools/snapshot/index.js +47 -46
  23. package/es/turbo-adapter/index.d.ts +6 -7
  24. package/es/turbo-adapter/index.js +70 -40
  25. package/lib/AutoLayout.js +1 -1
  26. package/lib/BpmnAdapter.js +1 -1
  27. package/lib/BpmnElement.js +1 -1
  28. package/lib/ContextMenu.js +1 -1
  29. package/lib/Control.js +1 -1
  30. package/lib/CurvedEdge.js +1 -1
  31. package/lib/DndPanel.js +1 -1
  32. package/lib/EnLocale.js +1 -0
  33. package/lib/FlowPath.js +1 -1
  34. package/lib/Group.js +1 -1
  35. package/lib/InsertNodeInPolyline.js +1 -1
  36. package/lib/Menu.js +1 -1
  37. package/lib/MiniMap.js +1 -1
  38. package/lib/NodeResize.js +1 -1
  39. package/lib/RectLabelNode.js +1 -1
  40. package/lib/SelectionSelect.js +1 -1
  41. package/lib/Snapshot.js +1 -1
  42. package/lib/TurboAdapter.js +1 -1
  43. package/lib/lfJson2Xml.js +1 -1
  44. package/lib/lfXml2Json.js +1 -1
  45. package/package.json +2 -2
  46. package/types/components/control/index.d.ts +2 -3
  47. package/types/components/menu/index.d.ts +2 -3
  48. package/types/index.d.ts +1 -0
  49. package/types/locale/en-locale/en.d.ts +19 -0
  50. package/types/locale/en-locale/index.d.ts +9 -0
  51. package/types/locale/locale.d.ts +6 -0
  52. package/types/tools/snapshot/index.d.ts +15 -7
  53. package/types/turbo-adapter/index.d.ts +6 -7
@@ -19,15 +19,16 @@ var __spread = (this && this.__spread) || function () {
19
19
  return ar;
20
20
  };
21
21
  var Control = /** @class */ (function () {
22
- function Control(_a) {
22
+ function Control(args) {
23
23
  var _this = this;
24
- var lf = _a.lf;
24
+ this.lf = args.lf;
25
+ this.LogicFlow = args.LogicFlow;
25
26
  this.controlItems = [
26
27
  {
27
28
  key: 'zoom-out',
28
29
  iconClass: 'lf-control-zoomOut',
29
- title: '缩小流程图',
30
- text: '缩小',
30
+ title: this.LogicFlow.t('缩小流程图'),
31
+ text: this.LogicFlow.t('缩小'),
31
32
  onClick: function () {
32
33
  _this.lf.zoom(false);
33
34
  },
@@ -35,8 +36,8 @@ var Control = /** @class */ (function () {
35
36
  {
36
37
  key: 'zoom-in',
37
38
  iconClass: 'lf-control-zoomIn',
38
- title: '放大流程图',
39
- text: '放大',
39
+ title: this.LogicFlow.t('放大流程图'),
40
+ text: this.LogicFlow.t('放大'),
40
41
  onClick: function () {
41
42
  _this.lf.zoom(true);
42
43
  },
@@ -44,8 +45,8 @@ var Control = /** @class */ (function () {
44
45
  {
45
46
  key: 'reset',
46
47
  iconClass: 'lf-control-fit',
47
- title: '恢复流程原有尺寸',
48
- text: '适应',
48
+ title: this.LogicFlow.t('恢复流程原有尺寸'),
49
+ text: this.LogicFlow.t('适应'),
49
50
  onClick: function () {
50
51
  _this.lf.resetZoom();
51
52
  },
@@ -53,8 +54,8 @@ var Control = /** @class */ (function () {
53
54
  {
54
55
  key: 'undo',
55
56
  iconClass: 'lf-control-undo',
56
- title: '回到上一步',
57
- text: '上一步',
57
+ title: this.LogicFlow.t('回到上一步'),
58
+ text: this.LogicFlow.t('上一步'),
58
59
  onClick: function () {
59
60
  _this.lf.undo();
60
61
  },
@@ -62,14 +63,13 @@ var Control = /** @class */ (function () {
62
63
  {
63
64
  key: 'redo',
64
65
  iconClass: 'lf-control-redo',
65
- title: '移到下一步',
66
- text: '下一步',
66
+ title: this.LogicFlow.t('移到下一步'),
67
+ text: this.LogicFlow.t('下一步'),
67
68
  onClick: function () {
68
69
  _this.lf.redo();
69
70
  },
70
71
  },
71
72
  ];
72
- this.lf = lf;
73
73
  }
74
74
  Control.prototype.render = function (lf, domContainer) {
75
75
  this.destroy();
@@ -110,14 +110,14 @@ var Control = /** @class */ (function () {
110
110
  text.title = item.title;
111
111
  text.innerText = item.text;
112
112
  itemContainer.append(icon, text);
113
- switch (item.text) {
114
- case '上一步':
113
+ switch (item.key) {
114
+ case 'undo':
115
115
  _this.lf.on('history:change', function (_a) {
116
116
  var undoAble = _a.data.undoAble;
117
117
  itemContainer.className = undoAble ? NORMAL : DISABLED;
118
118
  });
119
119
  break;
120
- case '下一步':
120
+ case 'redo':
121
121
  _this.lf.on('history:change', function (_a) {
122
122
  var redoAble = _a.data.redoAble;
123
123
  itemContainer.className = redoAble ? NORMAL : DISABLED;
@@ -13,14 +13,13 @@ export declare type MenuConfig = {
13
13
  };
14
14
  declare class Menu {
15
15
  lf: LogicFlow;
16
+ LogicFlow: any;
16
17
  private __container;
17
18
  private __menuDOM;
18
19
  private menuTypeMap;
19
20
  private __currentData;
20
21
  static pluginName: string;
21
- constructor({ lf }: {
22
- lf: any;
23
- });
22
+ constructor(args: any);
24
23
  /**
25
24
  * 初始化设置默认内置菜单栏
26
25
  */
@@ -23,11 +23,11 @@ var DefaultEdgeMenuKey = 'lf:defaultEdgeMenu';
23
23
  var DefaultGraphMenuKey = 'lf:defaultGraphMenu';
24
24
  var DefaultSelectionMenuKey = 'lf:defaultSelectionMenu';
25
25
  var Menu = /** @class */ (function () {
26
- function Menu(_a) {
26
+ function Menu(args) {
27
27
  var _this = this;
28
- var lf = _a.lf;
29
28
  this.__menuDOM = document.createElement('ul');
30
- this.lf = lf;
29
+ this.lf = args.lf;
30
+ this.LogicFlow = args.LogicFlow;
31
31
  this.menuTypeMap = new Map();
32
32
  this.init();
33
33
  this.lf.setMenuConfig = function (config) {
@@ -47,19 +47,19 @@ var Menu = /** @class */ (function () {
47
47
  var _this = this;
48
48
  var defaultNodeMenu = [
49
49
  {
50
- text: '删除',
50
+ text: this.LogicFlow.t('删除'),
51
51
  callback: function (node) {
52
52
  _this.lf.deleteNode(node.id);
53
53
  },
54
54
  },
55
55
  {
56
- text: '编辑文本',
56
+ text: this.LogicFlow.t('编辑文本'),
57
57
  callback: function (node) {
58
58
  _this.lf.graphModel.editText(node.id);
59
59
  },
60
60
  },
61
61
  {
62
- text: '复制',
62
+ text: this.LogicFlow.t('复制'),
63
63
  callback: function (node) {
64
64
  _this.lf.cloneNode(node.id);
65
65
  },
@@ -68,13 +68,13 @@ var Menu = /** @class */ (function () {
68
68
  this.menuTypeMap.set(DefaultNodeMenuKey, defaultNodeMenu);
69
69
  var defaultEdgeMenu = [
70
70
  {
71
- text: '删除',
71
+ text: this.LogicFlow.t('删除'),
72
72
  callback: function (edge) {
73
73
  _this.lf.deleteEdge(edge.id);
74
74
  },
75
75
  },
76
76
  {
77
- text: '编辑文本',
77
+ text: this.LogicFlow.t('编辑文本'),
78
78
  callback: function (edge) {
79
79
  _this.lf.graphModel.editText(edge.id);
80
80
  },
@@ -84,7 +84,7 @@ var Menu = /** @class */ (function () {
84
84
  this.menuTypeMap.set(DefaultGraphMenuKey, []);
85
85
  var DefaultSelectionMenu = [
86
86
  {
87
- text: '删除',
87
+ text: this.LogicFlow.t('删除'),
88
88
  callback: function (elements) {
89
89
  _this.lf.clearSelectElements();
90
90
  elements.edges.forEach(function (edge) { return _this.lf.deleteEdge(edge.id); });
package/es/index.d.ts CHANGED
@@ -16,3 +16,4 @@ export * from './tools/flow-path';
16
16
  export * from './tools/auto-layout';
17
17
  export * from './bpmn-adapter/xml2json';
18
18
  export * from './bpmn-adapter/json2xml';
19
+ export * from './locale/en-locale';
package/es/index.js CHANGED
@@ -17,3 +17,4 @@ export * from './tools/flow-path';
17
17
  export * from './tools/auto-layout';
18
18
  export * from './bpmn-adapter/xml2json';
19
19
  export * from './bpmn-adapter/json2xml';
20
+ export * from './locale/en-locale';
@@ -0,0 +1,19 @@
1
+ declare const en: {
2
+ 文本: string;
3
+ 开始: string;
4
+ 缩小流程图: string;
5
+ 缩小: string;
6
+ 放大流程图: string;
7
+ 放大: string;
8
+ 恢复流程原有尺寸: string;
9
+ 适应: string;
10
+ 回到上一步: string;
11
+ 上一步: string;
12
+ 移到下一步: string;
13
+ 下一步: string;
14
+ 删除: string;
15
+ 编辑文本: string;
16
+ 复制: string;
17
+ };
18
+ export default en;
19
+ export { en };
@@ -0,0 +1,19 @@
1
+ var en = {
2
+ 文本: 'text',
3
+ 开始: 'start',
4
+ 缩小流程图: 'zoom in',
5
+ 缩小: 'zoom in',
6
+ 放大流程图: 'zoom out',
7
+ 放大: 'zoom out',
8
+ 恢复流程原有尺寸: 'adapt to original size',
9
+ 适应: 'adapt',
10
+ 回到上一步: 'undo',
11
+ 上一步: 'undo',
12
+ 移到下一步: 'redo',
13
+ 下一步: 'redo',
14
+ 删除: 'delete',
15
+ 编辑文本: 'edit text',
16
+ 复制: 'copy',
17
+ };
18
+ export default en;
19
+ export { en };
@@ -0,0 +1,9 @@
1
+ import { Locale } from '../locale';
2
+ declare class EnLocale extends Locale {
3
+ static pluginName: string;
4
+ constructor({ LogicFlow }: {
5
+ LogicFlow: any;
6
+ });
7
+ }
8
+ export default EnLocale;
9
+ export { EnLocale };
@@ -0,0 +1,26 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { Locale } from '../locale';
15
+ import en from './en';
16
+ var EnLocale = /** @class */ (function (_super) {
17
+ __extends(EnLocale, _super);
18
+ function EnLocale(_a) {
19
+ var LogicFlow = _a.LogicFlow;
20
+ return _super.call(this, LogicFlow, en) || this;
21
+ }
22
+ EnLocale.pluginName = 'enLocale';
23
+ return EnLocale;
24
+ }(Locale));
25
+ export default EnLocale;
26
+ export { EnLocale };
@@ -0,0 +1,6 @@
1
+ export declare class Locale {
2
+ constructor(LogicFlow?: any, map?: Object);
3
+ replaceTranslator(LogicFlow: any, map: Object): void;
4
+ setDefault(LogicFlow: any): void;
5
+ static defaultTranslator: (text: string) => string;
6
+ }
@@ -0,0 +1,16 @@
1
+ var Locale = /** @class */ (function () {
2
+ function Locale(LogicFlow, map) {
3
+ if (LogicFlow && map) {
4
+ this.replaceTranslator(LogicFlow, map);
5
+ }
6
+ }
7
+ Locale.prototype.replaceTranslator = function (LogicFlow, map) {
8
+ LogicFlow.t = function (text) { return (map[text] ? map[text] : text); };
9
+ };
10
+ Locale.prototype.setDefault = function (LogicFlow) {
11
+ LogicFlow.t = Locale.defaultTranslator;
12
+ };
13
+ Locale.defaultTranslator = function (text) { return text; };
14
+ return Locale;
15
+ }());
16
+ export { Locale };
@@ -1,17 +1,25 @@
1
1
  /**
2
2
  * 快照插件,生成视图
3
3
  */
4
- declare const Snapshot: {
5
- pluginName: string;
6
- install(lf: any): void;
4
+ declare class Snapshot {
5
+ static pluginName: string;
6
+ lf: any;
7
+ offsetX: number;
8
+ offsetY: number;
9
+ fileName: string;
10
+ customCssRules: string;
11
+ useGlobalRules: boolean;
12
+ constructor({ lf }: {
13
+ lf: any;
14
+ });
7
15
  getSvgRootElement(lf: any): any;
8
16
  triggerDownload(imgURI: string): void;
9
17
  removeAnchor(element: any): void;
10
- downloadSvg(svg: SVGGraphicsElement, fileName: string, backgroundColor: string): void;
11
- getBase64(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
12
- getBlob(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
18
+ getSnapshot(fileName: string, backgroundColor: string): void;
19
+ getSnapshotBase64(backgroundColor: string): Promise<unknown>;
20
+ getSnapshotBlob(backgroundColor: string): Promise<unknown>;
13
21
  getClassRules(): string;
14
22
  getCanvasData(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
15
- };
23
+ }
16
24
  export default Snapshot;
17
25
  export { Snapshot, };
@@ -1,37 +1,27 @@
1
1
  /**
2
2
  * 快照插件,生成视图
3
3
  */
4
- var Snapshot = {
5
- pluginName: 'snapshot',
6
- install: function (lf) {
4
+ var Snapshot = /** @class */ (function () {
5
+ function Snapshot(_a) {
7
6
  var _this = this;
7
+ var lf = _a.lf;
8
8
  this.lf = lf;
9
+ this.customCssRules = '';
10
+ this.useGlobalRules = true;
9
11
  /* 下载快照 */
10
12
  lf.getSnapshot = function (fileName, backgroundColor) {
11
- _this.offsetX = Number.MAX_SAFE_INTEGER;
12
- _this.offsetY = Number.MAX_SAFE_INTEGER;
13
- _this.fileName = fileName || "logic-flow." + Date.now() + ".png";
14
- var svgRootElement = _this.getSvgRootElement(lf);
15
- _this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
13
+ _this.getSnapshot(fileName, backgroundColor);
16
14
  };
17
15
  /* 获取Blob对象,用户图片上传 */
18
- lf.getSnapshotBlob = function (backgroundColor) {
19
- _this.offsetX = Number.MAX_SAFE_INTEGER;
20
- _this.offsetY = Number.MAX_SAFE_INTEGER;
21
- var svgRootElement = _this.getSvgRootElement(lf);
22
- return _this.getBlob(svgRootElement, backgroundColor);
23
- };
16
+ lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(backgroundColor); };
24
17
  /* 获取Base64对象,用户图片上传 */
25
- lf.getSnapshotBase64 = function (backgroundColor) {
26
- _this.offsetX = Number.MAX_SAFE_INTEGER;
27
- _this.offsetY = Number.MAX_SAFE_INTEGER;
28
- var svgRootElement = _this.getSvgRootElement(lf);
29
- return _this.getBase64(svgRootElement, backgroundColor);
30
- };
31
- },
18
+ lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
19
+ }
32
20
  /* 获取svgRoot对象 */
33
- getSvgRootElement: function (lf) {
21
+ Snapshot.prototype.getSvgRootElement = function (lf) {
34
22
  var _this = this;
23
+ this.offsetX = Number.MAX_SAFE_INTEGER;
24
+ this.offsetY = Number.MAX_SAFE_INTEGER;
35
25
  lf.graphModel.nodes.forEach(function (item) {
36
26
  var x = item.x, width = item.width, y = item.y, height = item.height;
37
27
  var offsetX = x - width / 2;
@@ -58,8 +48,8 @@ var Snapshot = {
58
48
  });
59
49
  var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
60
50
  return svgRootElement;
61
- },
62
- triggerDownload: function (imgURI) {
51
+ };
52
+ Snapshot.prototype.triggerDownload = function (imgURI) {
63
53
  var evt = new MouseEvent('click', {
64
54
  view: window,
65
55
  bubbles: false,
@@ -70,8 +60,8 @@ var Snapshot = {
70
60
  a.setAttribute('href', imgURI);
71
61
  a.setAttribute('target', '_blank');
72
62
  a.dispatchEvent(evt);
73
- },
74
- removeAnchor: function (element) {
63
+ };
64
+ Snapshot.prototype.removeAnchor = function (element) {
75
65
  var childNodes = element.childNodes;
76
66
  var childLength = element.childNodes && element.childNodes.length;
77
67
  for (var i = 0; i < childLength; i++) {
@@ -83,20 +73,22 @@ var Snapshot = {
83
73
  i--;
84
74
  }
85
75
  }
86
- },
76
+ };
87
77
  /* 下载图片 */
88
- downloadSvg: function (svg, fileName, backgroundColor) {
78
+ Snapshot.prototype.getSnapshot = function (fileName, backgroundColor) {
89
79
  var _this = this;
80
+ this.fileName = fileName || "logic-flow." + Date.now() + ".png";
81
+ var svg = this.getSvgRootElement(this.lf);
90
82
  this.getCanvasData(svg, backgroundColor).then(function (canvas) {
91
- var imgURI = canvas
92
- .toDataURL('image/png')
83
+ var imgURI = canvas.toDataURL('image/png')
93
84
  .replace('image/png', 'image/octet-stream');
94
- _this.triggerDownload(imgURI, fileName);
85
+ _this.triggerDownload(imgURI);
95
86
  });
96
- },
87
+ };
97
88
  /* 获取base64对象 */
98
- getBase64: function (svg, backgroundColor) {
89
+ Snapshot.prototype.getSnapshotBase64 = function (backgroundColor) {
99
90
  var _this = this;
91
+ var svg = this.getSvgRootElement(this.lf);
100
92
  return new Promise(function (resolve) {
101
93
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
102
94
  var base64 = canvas.toDataURL('image/png');
@@ -104,10 +96,11 @@ var Snapshot = {
104
96
  resolve({ data: base64, width: canvas.width, height: canvas.height });
105
97
  });
106
98
  });
107
- },
99
+ };
108
100
  /* 获取Blob对象 */
109
- getBlob: function (svg, backgroundColor) {
101
+ Snapshot.prototype.getSnapshotBlob = function (backgroundColor) {
110
102
  var _this = this;
103
+ var svg = this.getSvgRootElement(this.lf);
111
104
  return new Promise(function (resolve) {
112
105
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
113
106
  canvas.toBlob(function (blob) {
@@ -116,20 +109,25 @@ var Snapshot = {
116
109
  }, 'image/png');
117
110
  });
118
111
  });
119
- },
120
- getClassRules: function () {
112
+ };
113
+ Snapshot.prototype.getClassRules = function () {
121
114
  var rules = '';
122
- var styleSheets = document.styleSheets;
123
- for (var i = 0; i < styleSheets.length; i++) {
124
- var sheet = styleSheets[i];
125
- for (var j = 0; j < sheet.cssRules.length; j++) {
126
- rules += sheet.cssRules[j].cssText;
115
+ if (this.useGlobalRules) {
116
+ var styleSheets = document.styleSheets;
117
+ for (var i = 0; i < styleSheets.length; i++) {
118
+ var sheet = styleSheets[i];
119
+ for (var j = 0; j < sheet.cssRules.length; j++) {
120
+ rules += sheet.cssRules[j].cssText;
121
+ }
127
122
  }
128
123
  }
124
+ if (this.customCssRules) {
125
+ rules += this.customCssRules;
126
+ }
129
127
  return rules;
130
- },
128
+ };
131
129
  // 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
132
- getCanvasData: function (svg, backgroundColor) {
130
+ Snapshot.prototype.getCanvasData = function (svg, backgroundColor) {
133
131
  var _this = this;
134
132
  var copy = svg.cloneNode(true);
135
133
  var graph = copy.lastChild;
@@ -201,12 +199,15 @@ var Snapshot = {
201
199
  因为svg中存在dom存放在foreignObject元素中
202
200
  SVG图形转成img对象
203
201
  todo: 会导致一些清晰度问题这个需要再解决
202
+ fixme: XMLSerializer的中的css background url不会下载图片
204
203
  */
205
204
  var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
206
205
  var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
207
206
  img.src = imgSrc;
208
207
  });
209
- },
210
- };
208
+ };
209
+ Snapshot.pluginName = 'snapshot';
210
+ return Snapshot;
211
+ }());
211
212
  export default Snapshot;
212
213
  export { Snapshot, };
@@ -5,11 +5,11 @@ export declare function toLogicflowData(data: any): {
5
5
  nodes: any[];
6
6
  edges: any[];
7
7
  };
8
- declare const TurboAdapter: {
9
- pluginName: string;
10
- install(lf: any): void;
11
- shapeConfigMap: Map<any, any>;
12
- setCustomShape(key: any, val: any): void;
8
+ declare class TurboAdapter {
9
+ static pluginName: string;
10
+ constructor({ lf }: {
11
+ lf: any;
12
+ });
13
13
  adapterOut(logicflowData: any): {
14
14
  flowElementList: any[];
15
15
  };
@@ -17,6 +17,5 @@ declare const TurboAdapter: {
17
17
  nodes: any[];
18
18
  edges: any[];
19
19
  };
20
- };
21
- export { TurboAdapter };
20
+ }
22
21
  export default TurboAdapter;