@logicflow/extension 2.1.3 → 2.1.5

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.
@@ -9,7 +9,7 @@ var __values = (this && this.__values) || function(o) {
9
9
  };
10
10
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
11
  };
12
- import { createTeleportContainer } from '@logicflow/vue-node-registry';
12
+ import { createTeleportContainer, destroyTeleportContainer, } from '@logicflow/vue-node-registry';
13
13
  var MiniMap = /** @class */ (function () {
14
14
  function MiniMap(_a) {
15
15
  var lf = _a.lf, LogicFlow = _a.LogicFlow, options = _a.options;
@@ -95,8 +95,10 @@ var MiniMap = /** @class */ (function () {
95
95
  */
96
96
  this.show = function (left, top) {
97
97
  if (!_this.isShow) {
98
+ _this.initMiniMap();
99
+ _this.lf.on('graph:resize', _this.onGraphResize);
98
100
  _this.createMiniMap(left, top);
99
- _this.setView();
101
+ _this.setView(true);
100
102
  }
101
103
  _this.isShow = true;
102
104
  };
@@ -105,6 +107,13 @@ var MiniMap = /** @class */ (function () {
105
107
  */
106
108
  this.hide = function () {
107
109
  if (_this.isShow) {
110
+ // 隐藏小地图时摧毁实例
111
+ destroyTeleportContainer(_this.lfMap.graphModel.flowId);
112
+ _this.lf.off('graph:resize', _this.onGraphResize);
113
+ _this.lfMap.destroy();
114
+ // 保证重新创建实例时,小地图中内容偏移正确
115
+ _this.translateX = 0;
116
+ _this.translateY = 0;
108
117
  _this.removeMiniMap();
109
118
  _this.lf.emit('miniMap:close', {});
110
119
  }
@@ -233,8 +242,6 @@ var MiniMap = /** @class */ (function () {
233
242
  this.bounds = boundsInit;
234
243
  this.elementAreaBounds = boundsInit;
235
244
  this.viewPortBounds = boundsInit;
236
- this.initMiniMap();
237
- lf.on('graph:resize', this.onGraphResize);
238
245
  }
239
246
  /**
240
247
  * 初始化小地图的配置
@@ -519,6 +526,7 @@ var MiniMap = /** @class */ (function () {
519
526
  this.viewport = div;
520
527
  };
521
528
  MiniMap.prototype.destroy = function () {
529
+ destroyTeleportContainer(this.lfMap.graphModel.flowId);
522
530
  this.lf.off('graph:resize', this.onGraphResize);
523
531
  };
524
532
  MiniMap.pluginName = 'miniMap';
@@ -6,10 +6,18 @@ export type ProximityConnectProps = {
6
6
  distance: number;
7
7
  reverseDirection: boolean;
8
8
  virtualEdgeStyle: Record<string, unknown>;
9
+ /**
10
+ * proximityConnect 类型:
11
+ * - 'node': 节点-节点连接
12
+ * - 'anchor': 锚点-锚点连接
13
+ * - 'default': 节点-锚点连接
14
+ */
15
+ type: 'node' | 'anchor' | 'default';
9
16
  };
10
17
  export declare class ProximityConnect {
11
18
  static pluginName: string;
12
19
  enable: boolean;
20
+ type: 'node' | 'anchor' | 'default';
13
21
  lf: LogicFlow;
14
22
  closestNode?: BaseNodeModel;
15
23
  currentDistance: number;
@@ -15,6 +15,7 @@ var ProximityConnect = /** @class */ (function () {
15
15
  function ProximityConnect(_a) {
16
16
  var lf = _a.lf, options = _a.options;
17
17
  this.enable = true;
18
+ this.type = 'default';
18
19
  this.currentDistance = Infinity; // 当前间距
19
20
  this.thresholdDistance = 100; // 节点-节点连接距离阈值
20
21
  this.reverseDirection = false; // 节点-节点连线方向,默认是拖拽节点连向最近节点
@@ -34,6 +35,8 @@ var ProximityConnect = /** @class */ (function () {
34
35
  // 节点开始拖拽事件
35
36
  this.lf.graphModel.eventCenter.on('node:dragstart', function (_a) {
36
37
  var data = _a.data;
38
+ if (_this.type === 'anchor')
39
+ return;
37
40
  if (!_this.enable)
38
41
  return;
39
42
  var graphModel = _this.lf.graphModel;
@@ -42,12 +45,14 @@ var ProximityConnect = /** @class */ (function () {
42
45
  });
43
46
  // 节点拖拽事件
44
47
  this.lf.graphModel.eventCenter.on('node:drag', function () {
48
+ if (_this.type === 'anchor')
49
+ return;
45
50
  _this.handleNodeDrag();
46
51
  });
47
52
  // 锚点开始拖拽事件
48
53
  this.lf.graphModel.eventCenter.on('anchor:dragstart', function (_a) {
49
54
  var data = _a.data, nodeModel = _a.nodeModel;
50
- if (!_this.enable)
55
+ if (!_this.enable || _this.type === 'node')
51
56
  return;
52
57
  _this.currentNode = nodeModel;
53
58
  _this.currentAnchor = data;
@@ -55,20 +60,20 @@ var ProximityConnect = /** @class */ (function () {
55
60
  // 锚点拖拽事件
56
61
  this.lf.graphModel.eventCenter.on('anchor:drag', function (_a) {
57
62
  var _b = _a.e, clientX = _b.clientX, clientY = _b.clientY;
58
- if (!_this.enable)
63
+ if (!_this.enable || _this.type === 'node')
59
64
  return;
60
65
  _this.handleAnchorDrag(clientX, clientY);
61
66
  });
62
67
  // 节点、锚点拖拽结束事件
63
68
  this.lf.graphModel.eventCenter.on('node:drop', function () {
64
- if (!_this.enable)
69
+ if (!_this.enable || _this.type === 'anchor')
65
70
  return;
66
71
  _this.handleDrop();
67
72
  });
68
73
  // 锚点拖拽需要单独判断一下当前拖拽终点是否在某个锚点上,如果是,就不触发插件的连线,以免出现创建了两条连线的问题,表现见 issue 2140
69
74
  this.lf.graphModel.eventCenter.on('anchor:dragend', function (_a) {
70
75
  var e = _a.e, edgeModel = _a.edgeModel;
71
- if (!_this.enable)
76
+ if (!_this.enable || _this.type === 'node')
72
77
  return;
73
78
  var _b = _this.lf.graphModel.getPointByClient({
74
79
  x: e.clientX,
@@ -32,6 +32,14 @@ export type ToImageOptions = {
32
32
  * - `true`:只导出画面区域内的可见元素
33
33
  */
34
34
  partial?: boolean;
35
+ /**
36
+ * 导出图片时的安全系数,用于确保导出的图片能够容纳所有元素,默认值为 1.1
37
+ */
38
+ safetyFactor?: number;
39
+ /**
40
+ * 导出图片时的安全边距,用于确保导出的图片能够容纳所有元素,默认值为 40
41
+ */
42
+ safetyMargin?: number;
35
43
  };
36
44
  export type SnapshotResponse = {
37
45
  data: Blob | string;
@@ -404,7 +404,7 @@ var Snapshot = /** @class */ (function () {
404
404
  graphModel = this.lf.graphModel;
405
405
  transformModel = graphModel.transformModel;
406
406
  SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
407
- safetyFactor = 1.1 // 安全系数,增加20%的空间
407
+ safetyFactor = toImageOptions.safetyFactor || 1.1 // 安全系数,增加10%的空间
408
408
  ;
409
409
  actualWidth = (bbox.width / SCALE_X) * safetyFactor;
410
410
  actualHeight = (bbox.height / SCALE_Y) * safetyFactor;
@@ -413,7 +413,7 @@ var Snapshot = /** @class */ (function () {
413
413
  canvas = document.createElement('canvas');
414
414
  canvas.style.width = "".concat(bboxWidth, "px");
415
415
  canvas.style.height = "".concat(bboxHeight, "px");
416
- safetyMargin = 40 // 额外的安全边距
416
+ safetyMargin = toImageOptions.safetyMargin || 40 // 额外的安全边距
417
417
  ;
418
418
  _b = this.getCanvasDimensionsByBrowser(), maxCanvasDimension = _b.maxCanvasDimension, otherMaxCanvasDimension = _b.otherMaxCanvasDimension;
419
419
  MAX_CANVAS_DIMENSION = maxCanvasDimension;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * LogicFlow 节点配置(导入/导出过程中使用的中间结构)
3
+ * - id/type/x/y:节点基本信息
4
+ * - text:节点文本的中心坐标与内容(值为未转义的原始字符串)
5
+ * - properties:节点的额外属性(会保留到 BPMN 的扩展字段)
6
+ */
1
7
  type NodeConfig = {
2
8
  id: string;
3
9
  properties?: Record<string, unknown>;
@@ -10,10 +16,20 @@ type NodeConfig = {
10
16
  x: number;
11
17
  y: number;
12
18
  };
19
+ /**
20
+ * 点坐标结构(用于边的路径点)
21
+ */
13
22
  type Point = {
14
23
  x: number;
15
24
  y: number;
16
25
  };
26
+ /**
27
+ * LogicFlow 边配置(导入/导出过程中使用的中间结构)
28
+ * - id/type/sourceNodeId/targetNodeId:边的基本信息
29
+ * - pointsList:边的路径点(用于 BPMN 的 di:waypoint)
30
+ * - text:边文本的位置与内容(值为未转义的原始字符串)
31
+ * - properties:边的扩展属性
32
+ */
17
33
  type EdgeConfig = {
18
34
  id: string;
19
35
  sourceNodeId: string;
@@ -35,11 +51,29 @@ type EdgeConfig = {
35
51
  pointsList?: Point[];
36
52
  properties: Record<string, unknown>;
37
53
  };
54
+ /**
55
+ * 将普通 JSON 转换为 XML 风格 JSON(xmlJson)
56
+ * 输入:任意 JSON 对象;可选的保留属性字段 retainedFields
57
+ * 输出:遵循 XML 属性前缀约定的 xmlJson(属性键以 '-' 开头)
58
+ * 规则:
59
+ * - 原始字符串直接返回;数组逐项转换;对象根据键类型决定是否加 '-' 前缀。
60
+ * - 保留字段(fields)中出现的键以属性形式(带 '-')保留,否则视为子节点。
61
+ */
38
62
  declare function toXmlJson(retainedFields?: string[]): (json: string | any[] | Record<string, any>) => any;
39
63
  /**
40
- * 将xmlJson转换为普通的json,在内部使用。
64
+ * 将 XML 风格 JSON(xmlJson)转换回普通 JSON(内部使用)
65
+ * 输入:遵循 '-' 属性前缀约定的 xmlJson
66
+ * 输出:去除前缀并恢复原有结构的普通 JSON
41
67
  */
42
68
  declare function toNormalJson(xmlJson: any): {};
69
+ /**
70
+ * BpmnAdapter:基础适配器
71
+ *
72
+ * 作用:在 LogicFlow 数据与 BPMN JSON 之间进行转换,并注入 adapterIn/adapterOut 钩子。
73
+ * - processAttributes:导出时 BPMN process 的基础属性(可配置 isExecutable、id 等)。
74
+ * - definitionAttributes:导出时 BPMN definitions 的基础属性与命名空间声明。
75
+ * - shapeConfigMap:不同 BPMN 元素类型的默认宽高,用于坐标/Bounds 计算。
76
+ */
43
77
  declare class BpmnAdapter {
44
78
  static pluginName: string;
45
79
  static shapeConfigMap: Map<any, any>;
@@ -59,6 +93,11 @@ declare class BpmnAdapter {
59
93
  ['-exporterVersion']: string;
60
94
  [key: string]: any;
61
95
  };
96
+ /**
97
+ * 构造函数
98
+ * - 注入 LogicFlow 的 adapterIn/adapterOut(处理 JSON 方向的适配)
99
+ * - 初始化 process 与 definitions 的基础属性
100
+ */
62
101
  constructor({ lf }: {
63
102
  lf: any;
64
103
  });
@@ -68,6 +107,13 @@ declare class BpmnAdapter {
68
107
  * ["properties", "startPoint", "endPoint", "pointsList"]合并,
69
108
  * 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
70
109
  */
110
+ /**
111
+ * adapterOut:将 LogicFlow 图数据转换为 BPMN JSON
112
+ * 输入:
113
+ * - data:LogicFlow GraphData
114
+ * - retainedFields:扩展属性保留字段
115
+ * 输出:BPMN JSON(包含 definitions/process/diagram/plane)
116
+ */
71
117
  adapterOut: (data: any, retainedFields?: string[]) => {
72
118
  'bpmn:definitions': {
73
119
  [key: string]: any;
@@ -82,18 +128,55 @@ declare class BpmnAdapter {
82
128
  "-exporterVersion": string;
83
129
  };
84
130
  };
131
+ /**
132
+ * adapterIn:将 BPMN JSON 转换为 LogicFlow 图数据
133
+ * 输入:bpmnData:BPMN JSON
134
+ * 输出:GraphConfigData(nodes/edges)
135
+ */
85
136
  adapterIn: (bpmnData: any) => {
86
137
  nodes: NodeConfig[];
87
138
  edges: EdgeConfig[];
88
139
  } | undefined;
89
140
  }
141
+ /**
142
+ * BpmnXmlAdapter:XML 适配器(继承 BpmnAdapter)
143
+ *
144
+ * 作用:处理 XML 输入/输出的适配,使用 xml2json/json2xml 完成格式转换。
145
+ * 特殊处理:在 XML 导入前对 name 属性的非法字符进行预处理转义,提升容错。
146
+ */
90
147
  declare class BpmnXmlAdapter extends BpmnAdapter {
91
148
  static pluginName: string;
149
+ /**
150
+ * 构造函数
151
+ * - 覆盖 LogicFlow 的 adapterIn/adapterOut,使其面向 XML 输入与输出。
152
+ */
92
153
  constructor(data: any);
154
+ /**
155
+ * 预处理 XML:仅对 name 属性值进行非法字符转义(<, >, &),避免 DOM 解析失败。
156
+ * 注意:不影响已合法的实体(如 &amp;),仅在属性值中生效,不修改其它内容。
157
+ */
158
+ private sanitizeNameAttributes;
159
+ /**
160
+ * adapterXmlIn:将 BPMN XML 转换为 LogicFlow 图数据
161
+ * 输入:bpmnData:XML 字符串或对象
162
+ * 步骤:
163
+ * 1) 若为字符串,先对 name 属性进行预处理转义;
164
+ * 2) 使用 lfXml2Json 转换为 BPMN JSON;
165
+ * 3) 调用基础 adapterIn 转换为 GraphData。
166
+ */
93
167
  adapterXmlIn: (bpmnData: any) => {
94
168
  nodes: NodeConfig[];
95
169
  edges: EdgeConfig[];
96
170
  } | undefined;
171
+ /**
172
+ * adapterXmlOut:将 LogicFlow 图数据转换为 BPMN XML
173
+ * 输入:
174
+ * - data:GraphData
175
+ * - retainedFields:保留属性字段
176
+ * 步骤:
177
+ * 1) 调用基础 adapterOut 生成 BPMN JSON;
178
+ * 2) 使用 lfJson2Xml 转为合法的 XML 字符串(包含属性与文本的转义)。
179
+ */
97
180
  adapterXmlOut: (data: any, retainedFields?: string[]) => string;
98
181
  }
99
182
  export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };