@logicflow/extension 2.2.0 → 2.2.1

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 (201) hide show
  1. package/README.md +16 -0
  2. package/dist/index.css +1 -1
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/es/NodeResize/node/RectResize.d.ts +0 -6
  6. package/es/NodeResize/node/RectResize.js +2 -11
  7. package/es/bpmn-elements-adapter/json2xml.d.ts +2 -1
  8. package/es/bpmn-elements-adapter/json2xml.js +18 -4
  9. package/es/bpmn-elements-adapter/xml2json.js +2 -7
  10. package/es/components/control/index.d.ts +1 -0
  11. package/es/components/control/index.js +24 -11
  12. package/es/components/mini-map/index.js +1 -1
  13. package/es/dynamic-group/model.d.ts +2 -1
  14. package/es/dynamic-group/model.js +28 -11
  15. package/es/dynamic-group/node.js +1 -0
  16. package/es/index.css +1 -1
  17. package/es/index.d.ts +1 -0
  18. package/es/index.js +2 -0
  19. package/es/insert-node-in-polyline/index.js +11 -35
  20. package/es/materials/curved-edge/index.js +49 -21
  21. package/es/materials/group/GroupNode.d.ts +0 -6
  22. package/es/materials/group/GroupNode.js +1 -6
  23. package/es/pool/LaneModel.d.ts +90 -0
  24. package/es/pool/LaneModel.js +252 -0
  25. package/es/pool/LaneView.d.ts +40 -0
  26. package/es/pool/LaneView.js +202 -0
  27. package/es/pool/PoolModel.d.ts +120 -0
  28. package/es/pool/PoolModel.js +586 -0
  29. package/es/pool/PoolView.d.ts +17 -0
  30. package/es/pool/PoolView.js +76 -0
  31. package/es/pool/constant.d.ts +15 -0
  32. package/es/pool/constant.js +17 -0
  33. package/es/pool/index.d.ts +89 -0
  34. package/es/pool/index.js +524 -0
  35. package/es/pool/utils.d.ts +19 -0
  36. package/es/pool/utils.js +33 -0
  37. package/es/style/index.css +1 -1
  38. package/es/style/raw.d.ts +1 -1
  39. package/es/style/raw.js +1 -1
  40. package/es/tools/label/LabelOverlay.js +3 -3
  41. package/es/tools/label/mediumEditor.d.ts +1 -1
  42. package/es/tools/label/mediumEditor.js +89 -52
  43. package/es/tools/snapshot/index.d.ts +7 -3
  44. package/es/tools/snapshot/index.js +72 -77
  45. package/lib/NodeResize/node/RectResize.d.ts +0 -6
  46. package/lib/NodeResize/node/RectResize.js +1 -10
  47. package/lib/bpmn-elements-adapter/json2xml.d.ts +2 -1
  48. package/lib/bpmn-elements-adapter/json2xml.js +19 -4
  49. package/lib/bpmn-elements-adapter/xml2json.js +2 -7
  50. package/lib/components/control/index.d.ts +1 -0
  51. package/lib/components/control/index.js +24 -11
  52. package/lib/components/mini-map/index.js +1 -1
  53. package/lib/dynamic-group/model.d.ts +2 -1
  54. package/lib/dynamic-group/model.js +28 -11
  55. package/lib/dynamic-group/node.js +1 -0
  56. package/lib/index.css +1 -1
  57. package/lib/index.d.ts +1 -0
  58. package/lib/index.js +2 -0
  59. package/lib/insert-node-in-polyline/index.js +10 -34
  60. package/lib/materials/curved-edge/index.js +49 -21
  61. package/lib/materials/group/GroupNode.d.ts +0 -6
  62. package/lib/materials/group/GroupNode.js +1 -6
  63. package/lib/pool/LaneModel.d.ts +90 -0
  64. package/lib/pool/LaneModel.js +255 -0
  65. package/lib/pool/LaneView.d.ts +40 -0
  66. package/lib/pool/LaneView.js +205 -0
  67. package/lib/pool/PoolModel.d.ts +120 -0
  68. package/lib/pool/PoolModel.js +589 -0
  69. package/lib/pool/PoolView.d.ts +17 -0
  70. package/lib/pool/PoolView.js +79 -0
  71. package/lib/pool/constant.d.ts +15 -0
  72. package/lib/pool/constant.js +20 -0
  73. package/lib/pool/index.d.ts +89 -0
  74. package/lib/pool/index.js +527 -0
  75. package/lib/pool/utils.d.ts +19 -0
  76. package/lib/pool/utils.js +38 -0
  77. package/lib/style/index.css +1 -1
  78. package/lib/style/raw.d.ts +1 -1
  79. package/lib/style/raw.js +1 -1
  80. package/lib/tools/label/LabelOverlay.js +2 -2
  81. package/lib/tools/label/mediumEditor.d.ts +1 -1
  82. package/lib/tools/label/mediumEditor.js +91 -53
  83. package/lib/tools/snapshot/index.d.ts +7 -3
  84. package/lib/tools/snapshot/index.js +72 -77
  85. package/package.json +10 -7
  86. package/.turbo/turbo-build.log +0 -38
  87. package/CHANGELOG.md +0 -1766
  88. package/__test__/bpmn-adapter.test.js +0 -227
  89. package/es/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  90. package/es/materials/curved-edge/__test__/curved-edge.test.js +0 -18
  91. package/jest.config.js +0 -198
  92. package/lib/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  93. package/lib/materials/curved-edge/__test__/curved-edge.test.js +0 -20
  94. package/rollup.config.js +0 -52
  95. package/src/NodeResize/BasicShape/Ellipse.tsx +0 -22
  96. package/src/NodeResize/BasicShape/Polygon.tsx +0 -24
  97. package/src/NodeResize/BasicShape/Rect.tsx +0 -44
  98. package/src/NodeResize/control/Control.tsx +0 -537
  99. package/src/NodeResize/control/ControlGroup.tsx +0 -76
  100. package/src/NodeResize/control/Util.ts +0 -206
  101. package/src/NodeResize/index.ts +0 -26
  102. package/src/NodeResize/node/DiamondResize.tsx +0 -149
  103. package/src/NodeResize/node/EllipseResize.tsx +0 -140
  104. package/src/NodeResize/node/HtmlResize.tsx +0 -125
  105. package/src/NodeResize/node/RectResize.tsx +0 -146
  106. package/src/NodeResize/node/index.ts +0 -4
  107. package/src/bpmn/constant.ts +0 -56
  108. package/src/bpmn/events/EndEvent.ts +0 -73
  109. package/src/bpmn/events/StartEvent.ts +0 -52
  110. package/src/bpmn/events/index.ts +0 -2
  111. package/src/bpmn/flow/SequenceFlow.ts +0 -25
  112. package/src/bpmn/flow/index.ts +0 -1
  113. package/src/bpmn/gateways/ExclusiveGateway.ts +0 -71
  114. package/src/bpmn/gateways/index.ts +0 -1
  115. package/src/bpmn/getBpmnId.ts +0 -31
  116. package/src/bpmn/index.ts +0 -60
  117. package/src/bpmn/tasks/ServiceTask.ts +0 -63
  118. package/src/bpmn/tasks/UserTask.ts +0 -64
  119. package/src/bpmn/tasks/index.ts +0 -2
  120. package/src/bpmn-adapter/bpmnIds.ts +0 -31
  121. package/src/bpmn-adapter/index.ts +0 -835
  122. package/src/bpmn-adapter/json2xml.ts +0 -127
  123. package/src/bpmn-adapter/xml2json.ts +0 -544
  124. package/src/bpmn-elements/README.md +0 -223
  125. package/src/bpmn-elements/__tests__/definition.test.js +0 -72
  126. package/src/bpmn-elements/index.d.ts +0 -26
  127. package/src/bpmn-elements/index.ts +0 -107
  128. package/src/bpmn-elements/presets/Event/EndEventFactory.ts +0 -114
  129. package/src/bpmn-elements/presets/Event/IntermediateCatchEvent.ts +0 -108
  130. package/src/bpmn-elements/presets/Event/IntermediateThrowEvent.ts +0 -109
  131. package/src/bpmn-elements/presets/Event/StartEventFactory.ts +0 -114
  132. package/src/bpmn-elements/presets/Event/boundaryEventFactory.ts +0 -117
  133. package/src/bpmn-elements/presets/Event/index.ts +0 -14
  134. package/src/bpmn-elements/presets/Flow/flow.d.ts +0 -6
  135. package/src/bpmn-elements/presets/Flow/index.ts +0 -8
  136. package/src/bpmn-elements/presets/Flow/manhattan.ts +0 -691
  137. package/src/bpmn-elements/presets/Flow/sequenceFlow.ts +0 -65
  138. package/src/bpmn-elements/presets/Gateway/gateway.ts +0 -107
  139. package/src/bpmn-elements/presets/Gateway/index.ts +0 -23
  140. package/src/bpmn-elements/presets/Pool/Lane.ts +0 -211
  141. package/src/bpmn-elements/presets/Pool/Pool.ts +0 -284
  142. package/src/bpmn-elements/presets/Pool/index.ts +0 -89
  143. package/src/bpmn-elements/presets/Task/index.ts +0 -122
  144. package/src/bpmn-elements/presets/Task/subProcess.ts +0 -189
  145. package/src/bpmn-elements/presets/Task/task.ts +0 -193
  146. package/src/bpmn-elements/presets/icons.ts +0 -155
  147. package/src/bpmn-elements/utils.ts +0 -52
  148. package/src/bpmn-elements-adapter/README.md +0 -293
  149. package/src/bpmn-elements-adapter/__tests__/adapter_in.test.js +0 -528
  150. package/src/bpmn-elements-adapter/__tests__/adapter_out.test.js +0 -569
  151. package/src/bpmn-elements-adapter/constant.ts +0 -76
  152. package/src/bpmn-elements-adapter/index.ts +0 -1134
  153. package/src/bpmn-elements-adapter/json2xml.ts +0 -91
  154. package/src/bpmn-elements-adapter/xml2json.ts +0 -548
  155. package/src/components/context-menu/index.ts +0 -253
  156. package/src/components/control/index.ts +0 -141
  157. package/src/components/dnd-panel/index.ts +0 -137
  158. package/src/components/highlight/index.ts +0 -227
  159. package/src/components/menu/index.ts +0 -748
  160. package/src/components/mini-map/index.ts +0 -686
  161. package/src/components/selection-select/index.ts +0 -387
  162. package/src/dynamic-group/index.ts +0 -775
  163. package/src/dynamic-group/model.ts +0 -562
  164. package/src/dynamic-group/node.ts +0 -288
  165. package/src/dynamic-group/utils.ts +0 -46
  166. package/src/index.less +0 -1
  167. package/src/index.ts +0 -45
  168. package/src/insert-node-in-polyline/edge.ts +0 -175
  169. package/src/insert-node-in-polyline/index.ts +0 -187
  170. package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
  171. package/src/materials/curved-edge/index.ts +0 -185
  172. package/src/materials/group/GroupNode.ts +0 -442
  173. package/src/materials/group/index.ts +0 -542
  174. package/src/materials/node-selection/index.ts +0 -380
  175. package/src/mindmap/fakerRoot.ts +0 -19
  176. package/src/mindmap/index.ts +0 -328
  177. package/src/mindmap/markContent.ts +0 -81
  178. package/src/mindmap/markContentOption.ts +0 -81
  179. package/src/mindmap/markEntity.ts +0 -82
  180. package/src/mindmap/markRoot.ts +0 -83
  181. package/src/mindmap/theme.ts +0 -11
  182. package/src/rect-label-node/RectLabelNodeView.ts +0 -33
  183. package/src/rect-label-node/index.ts +0 -15
  184. package/src/style/index.less +0 -342
  185. package/src/style/raw.ts +0 -295
  186. package/src/tools/auto-layout/index.ts +0 -282
  187. package/src/tools/flow-path/index.ts +0 -233
  188. package/src/tools/label/Label.tsx +0 -357
  189. package/src/tools/label/LabelModel.ts +0 -83
  190. package/src/tools/label/LabelOverlay.tsx +0 -158
  191. package/src/tools/label/algorithm.ts +0 -42
  192. package/src/tools/label/index.ts +0 -479
  193. package/src/tools/label/mediumEditor.ts +0 -94
  194. package/src/tools/label/utils.ts +0 -395
  195. package/src/tools/proximity-connect/index.ts +0 -435
  196. package/src/tools/snapshot/README.md +0 -145
  197. package/src/tools/snapshot/index.ts +0 -718
  198. package/src/tools/snapshot/utils.ts +0 -163
  199. package/src/turbo-adapter/index.ts +0 -212
  200. package/stats.html +0 -4842
  201. package/tsconfig.json +0 -18
@@ -1,1134 +0,0 @@
1
- /* eslint-disable func-names */
2
- /* eslint-disable no-continue */
3
- /* eslint-disable @typescript-eslint/naming-convention */
4
- /* eslint-disable no-cond-assign */
5
- /* eslint-disable no-shadow */
6
- import _ from 'lodash-es'
7
- import {
8
- ExclusiveGatewayConfig,
9
- InclusiveGatewayConfig,
10
- ParallelGatewayConfig,
11
- StartEventConfig,
12
- EndEventConfig,
13
- BoundaryEventConfig,
14
- IntermediateEventConfig,
15
- ServiceTaskConfig,
16
- UserTaskConfig,
17
- SubProcessConfig,
18
- } from './constant'
19
- import { lfXml2Json } from './xml2json'
20
- import { lfJson2Xml, handleAttributes } from './json2xml'
21
-
22
- type NodeConfig = {
23
- id: string
24
- properties?: Record<string, unknown>
25
- text?: {
26
- x: number
27
- y: number
28
- value: string
29
- }
30
- type: string
31
- x: number
32
- y: number
33
- children?: string[]
34
- }
35
-
36
- type Point = {
37
- x: number
38
- y: number
39
- }
40
-
41
- type EdgeConfig = {
42
- id: string
43
- sourceNodeId: string
44
- targetNodeId: string
45
- type: string
46
- startPoint?: {
47
- x: number
48
- y: number
49
- }
50
- endPoint?: {
51
- x: number
52
- y: number
53
- }
54
- text?: {
55
- x: number
56
- y: number
57
- value: string
58
- }
59
- pointsList?: Point[]
60
- properties: Record<string, unknown>
61
- }
62
-
63
- type TransformerType = {
64
- [key: string]: {
65
- in?: (key: string, data: any) => any
66
- out?: (data: any) => any
67
- }
68
- }
69
-
70
- type MappingType = {
71
- in?: {
72
- [key: string]: string
73
- }
74
- out?: {
75
- [key: string]: string
76
- }
77
- }
78
-
79
- type excludeFieldsType = {
80
- in?: Set<string>
81
- out?: Set<string>
82
- }
83
-
84
- type ExtraPropsType = {
85
- retainedAttrsFields?: string[]
86
- excludeFields?: excludeFieldsType
87
- transformer?: TransformerType
88
- mapping?: MappingType
89
- }
90
-
91
- enum BpmnElements {
92
- START = 'bpmn:startEvent',
93
- END = 'bpmn:endEvent',
94
- INTERMEDIATE_CATCH = 'bpmn:intermediateCatchEvent',
95
- INTERMEDIATE_THROW = 'bpmn:intermediateThrowEvent',
96
- BOUNDARY = 'bpmn:boundaryEvent',
97
- PARALLEL_GATEWAY = 'bpmn:parallelGateway',
98
- INCLUSIVE_GATEWAY = 'bpmn:inclusiveGateway',
99
- EXCLUSIVE_GATEWAY = 'bpmn:exclusiveGateway',
100
- USER = 'bpmn:userTask',
101
- SYSTEM = 'bpmn:serviceTask',
102
- FLOW = 'bpmn:sequenceFlow',
103
- SUBPROCESS = 'bpmn:subProcess',
104
- }
105
-
106
- const defaultAttrsForInput = [
107
- '-name',
108
- '-id',
109
- 'bpmn:incoming',
110
- 'bpmn:outgoing',
111
- '-sourceRef',
112
- '-targetRef',
113
- '-children',
114
- ]
115
-
116
- const defaultRetainedProperties = [
117
- 'properties',
118
- 'startPoint',
119
- 'endPoint',
120
- 'pointsList',
121
- ]
122
-
123
- const defaultExcludeFields = {
124
- in: [],
125
- out: [
126
- 'properties.panels',
127
- 'properties.nodeSize',
128
- 'properties.definitionId',
129
- 'properties.timerValue',
130
- 'properties.timerType',
131
- 'properties.definitionType',
132
- 'properties.parent',
133
- 'properties.isBoundaryEventTouchingTask',
134
- ],
135
- }
136
-
137
- const mergeInNOutObject = (target: any, source: any): TransformerType => {
138
- const sourceKeys = Object.keys(source || {})
139
- sourceKeys.forEach((key) => {
140
- if (target[key]) {
141
- const { in: fnIn, out: fnOut } = source[key]
142
- if (fnIn) {
143
- target[key].in = fnIn
144
- }
145
- if (fnOut) {
146
- target[key].out = fnOut
147
- }
148
- } else {
149
- target[key] = source[key]
150
- }
151
- })
152
- return target
153
- }
154
-
155
- // @ts-ignore
156
- let defaultTransformer: TransformerType = {
157
- 'bpmn:startEvent': {
158
- out(data: any) {
159
- const { properties } = data
160
- return defaultTransformer[properties.definitionType]?.out?.(data) || {}
161
- },
162
- },
163
- // 'bpmn:endEvent': undefined,
164
- 'bpmn:intermediateCatchEvent': {
165
- out(data: any) {
166
- const { properties } = data
167
- return defaultTransformer[properties.definitionType]?.out?.(data) || {}
168
- },
169
- },
170
- 'bpmn:intermediateThrowEvent': {
171
- out(data: any) {
172
- const { properties } = data
173
- return defaultTransformer[properties.definitionType]?.out?.(data) || {}
174
- },
175
- },
176
- 'bpmn:boundaryEvent': {
177
- out(data: any) {
178
- const { properties } = data
179
- return defaultTransformer[properties.definitionType]?.out?.(data) || {}
180
- },
181
- },
182
- // 'bpmn:userTask': undefined,
183
- 'bpmn:sequenceFlow': {
184
- out(data: any) {
185
- const {
186
- properties: { expressionType, condition },
187
- } = data
188
- if (condition) {
189
- if (expressionType === 'cdata') {
190
- return {
191
- json: `<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression"><![CDATA[\${${condition}}]]></bpmn:conditionExpression>`,
192
- }
193
- }
194
- return {
195
- json: `<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition}</bpmn:conditionExpression>`,
196
- }
197
- }
198
- return {
199
- json: '',
200
- }
201
- },
202
- },
203
- // 'bpmn:subProcess': undefined,
204
- // 'bpmn:participant': undefined,
205
- 'bpmn:timerEventDefinition': {
206
- out(data: any) {
207
- const {
208
- properties: { timerType, timerValue, definitionId },
209
- } = data
210
-
211
- const typeFunc = () =>
212
- `<bpmn:${timerType} xsi:type="bpmn:tFormalExpression">${timerValue}</bpmn:${timerType}>`
213
-
214
- return {
215
- json: `<bpmn:timerEventDefinition id="${definitionId}"${
216
- timerType && timerValue
217
- ? `>${typeFunc()}</bpmn:timerEventDefinition>`
218
- : '/>'
219
- }`,
220
- }
221
- },
222
- in(key: string, data: any) {
223
- const definitionType = key
224
- const definitionId = data['-id']
225
- let timerType = ''
226
- let timerValue = ''
227
- for (const key of Object.keys(data)) {
228
- if (key.includes('bpmn:')) {
229
- ;[, timerType] = key.split(':')
230
- timerValue = data[key]?.['#text']
231
- }
232
- }
233
- return {
234
- '-definitionId': definitionId,
235
- '-definitionType': definitionType,
236
- '-timerType': timerType,
237
- '-timerValue': timerValue,
238
- }
239
- },
240
- },
241
- 'bpmn:conditionExpression': {
242
- in(_key: string, data: any) {
243
- let condition = ''
244
- let expressionType = ''
245
- if (data['#cdata-section']) {
246
- expressionType = 'cdata'
247
- condition = /^\$\{(.*)\}$/g.exec(data['#cdata-section'])?.[1] || ''
248
- } else if (data['#text']) {
249
- expressionType = 'normal'
250
- condition = data['#text']
251
- }
252
-
253
- return {
254
- '-condition': condition,
255
- '-expressionType': expressionType,
256
- }
257
- },
258
- },
259
- }
260
-
261
- /**
262
- * 将普通json转换为xmlJson
263
- * xmlJson中property会以“-”开头
264
- * 如果没有“-”表示为子节点
265
- * fix issue https://github.com/didi/LogicFlow/issues/718, contain the process of #text/#cdata and array
266
- * @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
267
- * @param retainedAttrsFields retainedAttrsFields会和默认的defaultRetainedProperties:
268
- * ["properties", "startPoint", "endPoint", "pointsList"]合并
269
- * 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性
270
- * @param excludeFields excludeFields会和默认的defaultExcludeFields合并,出现在这个数组中的字段在转换时会被忽略
271
- * @param transformer 对应节点或者边的子内容转换规则
272
- */
273
- function convertNormalToXml(other?: ExtraPropsType) {
274
- const { retainedAttrsFields, excludeFields, transformer } = other ?? {}
275
- const retainedAttrsSet = new Set([
276
- ...defaultRetainedProperties,
277
- ...(retainedAttrsFields || []),
278
- ])
279
- const excludeFieldsSet = {
280
- in: new Set([...defaultExcludeFields.in, ...(excludeFields?.in || [])]),
281
- out: new Set([...defaultExcludeFields.out, ...(excludeFields?.out || [])]),
282
- }
283
-
284
- defaultTransformer = mergeInNOutObject(defaultTransformer, transformer)
285
-
286
- return (object: { nodes: any; edges: any }) => {
287
- const { nodes } = object
288
- const { edges } = object
289
- function ToXmlJson(obj: any, path: string): any {
290
- if (obj?.flag === 1) {
291
- return
292
- }
293
-
294
- let fn
295
- // @ts-ignore
296
- if ((fn = defaultTransformer[obj.type]) && fn.out) {
297
- const output = fn.out(obj)
298
- const keys = Object.keys(output)
299
- if (keys.length > 0) {
300
- keys.forEach((key: string) => {
301
- obj[key] = output[key]
302
- })
303
- }
304
- }
305
-
306
- if (obj?.children) {
307
- obj.children = obj.children.map((key: any) => {
308
- const target =
309
- nodes.find((item: { id: any }) => item.id === key) ||
310
- edges.find((item: { id: any }) => item.id === key)
311
- return target || {}
312
- })
313
- }
314
-
315
- const xmlJson: any = {}
316
-
317
- if (typeof obj === 'string') {
318
- return obj
319
- }
320
-
321
- if (Array.isArray(obj)) {
322
- return (
323
- obj
324
- .map((item) => ToXmlJson(item, ''))
325
- // eslint-disable-next-line eqeqeq
326
- .filter((item) => item != undefined)
327
- )
328
- }
329
-
330
- for (const [key, value] of Object.entries(obj)) {
331
- if ((value as any)?.['flag'] === 1) {
332
- return
333
- }
334
- const newPath = [path, key].filter((item) => item).join('.')
335
- if (excludeFieldsSet.out.has(newPath)) {
336
- continue
337
- } else if (typeof value !== 'object') {
338
- // node type reference https://www.w3schools.com/xml/dom_nodetype.asp
339
- if (
340
- key.indexOf('-') === 0 ||
341
- ['#text', '#cdata-section', '#comment'].includes(key)
342
- ) {
343
- xmlJson[key] = value
344
- } else {
345
- xmlJson[`-${key}`] = value
346
- }
347
- } else if (retainedAttrsSet.has(newPath)) {
348
- xmlJson[`-${key}`] = ToXmlJson(value, newPath)
349
- } else {
350
- xmlJson[key] = ToXmlJson(value, newPath)
351
- }
352
- }
353
-
354
- return xmlJson
355
- }
356
- return ToXmlJson(object, '')
357
- }
358
- }
359
-
360
- /**
361
- * 将xmlJson转换为普通的json,在内部使用。
362
- */
363
- function convertXmlToNormal(xmlJson: any) {
364
- const json: any = {}
365
- for (const [key, value] of Object.entries(xmlJson)) {
366
- if (key.indexOf('-') === 0) {
367
- json[key.substring(1)] = handleAttributes(value)
368
- } else if (typeof value === 'string') {
369
- json[key] = value
370
- } else if (Object.prototype.toString.call(value) === '[object Object]') {
371
- json[key] = convertXmlToNormal(value)
372
- } else if (Array.isArray(value)) {
373
- // contain the process of array
374
- json[key] = value.map((v) => convertXmlToNormal(v))
375
- } else {
376
- json[key] = value
377
- }
378
- }
379
- return json
380
- }
381
-
382
- /**
383
- * 设置bpmn process信息
384
- * 目标格式请参考examples/bpmn.json
385
- * bpmn因为是默认基于xml格式的,其特点与json存在差异。
386
- * 1) 如果是xml的属性,json中属性用'-'开头
387
- * 2)如果只有一个子元素,json中表示为正常属性
388
- * 3)如果是多个子元素,json中使用数组存储
389
- */
390
- function convertLf2ProcessData(
391
- bpmnData: any,
392
- data: any,
393
- other?: ExtraPropsType,
394
- ) {
395
- const nodeIdMap = new Map()
396
-
397
- const xmlJsonData = convertNormalToXml(other)(data)
398
-
399
- xmlJsonData.nodes.forEach((node: any) => {
400
- const {
401
- '-id': nodeId,
402
- '-type': nodeType,
403
- text,
404
- children,
405
- ...otherProps
406
- } = node
407
- const processNode: any = { '-id': nodeId }
408
-
409
- if (text?.['-value']) {
410
- processNode['-name'] = text['-value']
411
- }
412
-
413
- if (otherProps['-json']) {
414
- processNode['-json'] = otherProps['-json']
415
- }
416
-
417
- if (otherProps['-properties']) {
418
- Object.assign(processNode, otherProps['-properties'])
419
- }
420
-
421
- if (children) {
422
- processNode.children = children
423
- }
424
-
425
- // (bpmnData[nodeType] ??= []).push(processNode);
426
-
427
- if (!bpmnData[nodeType]) {
428
- bpmnData[nodeType] = []
429
- }
430
- bpmnData[nodeType].push(processNode)
431
-
432
- nodeIdMap.set(nodeId, processNode)
433
- })
434
-
435
- const sequenceFlow = xmlJsonData.edges.map((edge: any) => {
436
- const {
437
- '-id': id,
438
- // '-type': type,
439
- '-sourceNodeId': sourceNodeId,
440
- '-targetNodeId': targetNodeId,
441
- text,
442
- ...otherProps
443
- } = edge
444
- const targetNode = nodeIdMap.get(targetNodeId)
445
- // (targetNode['bpmn:incoming'] ??= []).push(id);
446
-
447
- if (!targetNode['bpmn:incoming']) {
448
- targetNode['bpmn:incoming'] = []
449
- }
450
- targetNode['bpmn:incoming'].push(id)
451
-
452
- const edgeConfig: any = {
453
- '-id': id,
454
- '-sourceRef': sourceNodeId,
455
- '-targetRef': targetNodeId,
456
- }
457
-
458
- if (text?.['-value']) {
459
- edgeConfig['-name'] = text['-value']
460
- }
461
-
462
- if (otherProps['-json']) {
463
- edgeConfig['-json'] = otherProps['-json']
464
- }
465
-
466
- if (otherProps['-properties']) {
467
- Object.assign(edgeConfig, otherProps['-properties'])
468
- }
469
-
470
- return edgeConfig
471
- })
472
-
473
- // @see https://github.com/didi/LogicFlow/issues/325
474
- // 需要保证incoming在outgoing之前
475
- data.edges.forEach(({ sourceNodeId, id }: any) => {
476
- const sourceNode = nodeIdMap.get(sourceNodeId)
477
- // (sourceNode['bpmn:outgoing'] ??= []).push(id);
478
-
479
- if (!sourceNode['bpmn:outgoing']) {
480
- sourceNode['bpmn:outgoing'] = []
481
- }
482
- sourceNode['bpmn:outgoing'].push(id)
483
- })
484
-
485
- bpmnData['bpmn:subProcess']?.forEach((item: any) => {
486
- const setMap: any = {
487
- 'bpmn:incoming': new Set<string>(),
488
- 'bpmn:outgoing': new Set<string>(),
489
- }
490
- const edgesInSubProcess: any = []
491
- item.children.forEach((child: any) => {
492
- const target = nodeIdMap.get(child['-id'])
493
- ;['bpmn:incoming', 'bpmn:outgoing'].forEach((key: string) => {
494
- target[key] &&
495
- target[key].forEach((value: string) => {
496
- setMap[key].add(value)
497
- })
498
- })
499
-
500
- const index = bpmnData[child['-type']]?.findIndex(
501
- (_item: any) => _item['-id'] === child['-id'],
502
- )
503
- if (index >= 0) {
504
- bpmnData[child['-type']].splice(index, 1)
505
- }
506
-
507
- nodeIdMap.delete(child['-id'])
508
-
509
- // (item[child['-type']] ??= []).push(target);
510
- if (!item[child['-type']]) {
511
- item[child['-type']] = []
512
- }
513
- item[child['-type']].push(target)
514
- })
515
-
516
- const { 'bpmn:incoming': incomingSet, 'bpmn:outgoing': outgoingSet } =
517
- setMap
518
-
519
- outgoingSet.forEach((value: string) => {
520
- incomingSet.has(value) && edgesInSubProcess.push(value)
521
- })
522
-
523
- for (let i = 0; i < edgesInSubProcess.length; ) {
524
- const index = sequenceFlow.findIndex(
525
- (item: any) => item['-id'] === edgesInSubProcess[i],
526
- )
527
- if (index >= 0) {
528
- // (item['bpmn:sequenceFlow'] ??= []).push(sequenceFlow[index]);
529
- if (!item['bpmn:sequenceFlow']) {
530
- item['bpmn:sequenceFlow'] = []
531
- }
532
- item['bpmn:sequenceFlow'].push(sequenceFlow[index])
533
- sequenceFlow.splice(index, 1)
534
- } else {
535
- i++
536
- }
537
- }
538
-
539
- delete item.children
540
- })
541
-
542
- bpmnData[BpmnElements.FLOW] = sequenceFlow
543
-
544
- return bpmnData
545
- }
546
-
547
- /**
548
- * adapterOut 设置bpmn diagram信息
549
- */
550
- function convertLf2DiagramData(bpmnDiagramData: any, data: any) {
551
- bpmnDiagramData['bpmndi:BPMNEdge'] = data.edges.map((edge: any) => {
552
- const edgeId = edge.id
553
- const pointsList = edge.pointsList.map(
554
- ({ x, y }: { x: number; y: number }) => ({
555
- '-x': x,
556
- '-y': y,
557
- }),
558
- )
559
- const diagramData: any = {
560
- '-id': `${edgeId}_di`,
561
- '-bpmnElement': edgeId,
562
- 'di:waypoint': pointsList,
563
- }
564
- if (edge.text?.value) {
565
- diagramData['bpmndi:BPMNLabel'] = {
566
- 'dc:Bounds': {
567
- '-x': edge.text.x - (edge.text.value.length * 10) / 2,
568
- '-y': edge.text.y - 7,
569
- '-width': edge.text.value.length * 10,
570
- '-height': 14,
571
- },
572
- }
573
- }
574
- return diagramData
575
- })
576
- bpmnDiagramData['bpmndi:BPMNShape'] = data.nodes.map((node: any) => {
577
- const nodeId = node.id
578
- let width = 100
579
- let height = 80
580
- let { x, y } = node
581
- // bpmn坐标是基于左上角,LogicFlow基于中心点,此处处理一下。
582
- const shapeConfig = BPMNBaseAdapter.shapeConfigMap.get(node.type)
583
- if (shapeConfig) {
584
- width = shapeConfig.width
585
- height = shapeConfig.height
586
- }
587
- x -= width / 2
588
- y -= height / 2
589
- const diagramData: any = {
590
- '-id': `${nodeId}_di`,
591
- '-bpmnElement': nodeId,
592
- 'dc:Bounds': {
593
- '-x': x,
594
- '-y': y,
595
- '-width': width,
596
- '-height': height,
597
- },
598
- }
599
- if (node.text?.value) {
600
- diagramData['bpmndi:BPMNLabel'] = {
601
- 'dc:Bounds': {
602
- '-x': node.text.x - (node.text.value.length * 10) / 2,
603
- '-y': node.text.y - 7,
604
- '-width': node.text.value.length * 10,
605
- '-height': 14,
606
- },
607
- }
608
- }
609
- return diagramData
610
- })
611
- }
612
-
613
- const ignoreType = ['bpmn:incoming', 'bpmn:outgoing']
614
-
615
- /**
616
- * 将bpmn数据转换为LogicFlow内部能识别数据
617
- */
618
- function convertBpmn2LfData(bpmnData: any, other?: ExtraPropsType) {
619
- let nodes: any[] = []
620
- let edges: any[] = []
621
-
622
- const eleMap = new Map<string, any>()
623
-
624
- const { transformer, excludeFields } = other ?? {}
625
-
626
- const excludeFieldsSet = {
627
- in: new Set([...defaultExcludeFields.in, ...(excludeFields?.in || [])]),
628
- out: new Set([...defaultExcludeFields.out, ...(excludeFields?.out || [])]),
629
- }
630
-
631
- defaultTransformer = mergeInNOutObject(defaultTransformer, transformer)
632
-
633
- const definitions = bpmnData['bpmn:definitions']
634
- if (definitions) {
635
- const process = definitions['bpmn:process']
636
- ;(function (data, callbacks) {
637
- callbacks.forEach((callback) => {
638
- try {
639
- Object.keys(data).forEach((key: string) => {
640
- try {
641
- callback(key)
642
- } catch (error) {
643
- console.error(error)
644
- }
645
- })
646
- } catch (error) {
647
- console.error(error)
648
- }
649
- })
650
- })(process, [
651
- (key: string) => {
652
- // 将bpmn:subProcess中的数据提升到process中
653
- function subProcessProcessing(data: any) {
654
- // data['-children'] ??= [];
655
- if (!data['-children']) {
656
- data['-children'] = []
657
- }
658
- Object.keys(data).forEach((key: string) => {
659
- if (key.indexOf('bpmn:') === 0 && !ignoreType.includes(key)) {
660
- // process[key] ??= [];
661
- if (!process[key]) {
662
- process[key] = []
663
- }
664
- !Array.isArray(process[key]) && (process[key] = [process[key]])
665
- Array.isArray(data[key])
666
- ? process[key].push(...data[key])
667
- : process[key].push(data[key])
668
- if (Array.isArray(data[key])) {
669
- data[key].forEach((item: any) => {
670
- !key.includes('Flow') && data['-children'].push(item['-id'])
671
- })
672
- } else {
673
- !key.includes('Flow') &&
674
- data['-children'].push(data[key]['-id'])
675
- }
676
- delete data[key]
677
- }
678
- })
679
- }
680
- if (key === 'bpmn:subProcess') {
681
- const data = process[key]
682
- if (Array.isArray(data)) {
683
- data.forEach((item: any) => {
684
- key === 'bpmn:subProcess' && subProcessProcessing(item)
685
- })
686
- } else {
687
- subProcessProcessing(data)
688
- }
689
- }
690
- },
691
- (key: string) => {
692
- // 处理被提升的节点、边, 主要是通过definitionTransformer处理出节点的属性
693
- const fn = (obj: any) => {
694
- Object.keys(obj).forEach((key: string) => {
695
- if (key.includes('bpmn:')) {
696
- let props: any = {}
697
- if (defaultTransformer[key] && defaultTransformer[key].in) {
698
- props = defaultTransformer[key].in?.(key, _.cloneDeep(obj[key]))
699
- delete obj[key]
700
- } else {
701
- func(obj[key])
702
- }
703
- let keys: (string | number | symbol)[]
704
- if ((keys = Reflect.ownKeys(props)).length > 0) {
705
- keys.forEach((key) => {
706
- Reflect.set(obj, key, props[key])
707
- })
708
- }
709
- }
710
- })
711
- }
712
- function func(data: any) {
713
- eleMap.set(data['-id'], data)
714
- if (Array.isArray(data)) {
715
- data.forEach((item) => {
716
- func(item)
717
- })
718
- } else if (typeof data === 'object') {
719
- fn(data)
720
- }
721
- }
722
- func(process[key])
723
- },
724
- (key: string) => {
725
- if (key.indexOf('bpmn:') === 0) {
726
- const value = process[key]
727
- if (key === 'bpmn:sequenceFlow') {
728
- const bpmnEdges =
729
- definitions['bpmndi:BPMNDiagram']['bpmndi:BPMNPlane'][
730
- 'bpmndi:BPMNEdge'
731
- ]
732
- edges = getLfEdges(value, bpmnEdges)
733
- } else {
734
- const shapes =
735
- definitions['bpmndi:BPMNDiagram']['bpmndi:BPMNPlane'][
736
- 'bpmndi:BPMNShape'
737
- ]
738
- if (key === 'bpmn:boundaryEvent') {
739
- const data = process[key]
740
- const fn = (item: any) => {
741
- const { '-attachedToRef': attachedToRef } = item
742
- const attachedToNode = eleMap.get(attachedToRef)
743
-
744
- // attachedToNode['-boundaryEvents'] ??= [];
745
-
746
- if (!attachedToNode['-boundaryEvents']) {
747
- attachedToNode['-boundaryEvents'] = []
748
- }
749
-
750
- attachedToNode['-boundaryEvents'].push(item['-id'])
751
- }
752
- if (Array.isArray(data)) {
753
- data.forEach((item) => {
754
- fn(item)
755
- })
756
- } else {
757
- fn(data)
758
- }
759
- }
760
- nodes = nodes.concat(getLfNodes(value, shapes, key))
761
- }
762
- }
763
- },
764
- ])
765
- }
766
-
767
- const ignoreFields = (
768
- obj: Record<string, any>,
769
- filterSet: Set<string>,
770
- path: string,
771
- ) => {
772
- Object.keys(obj).forEach((key) => {
773
- const tmpPath = path ? `${path}.${key}` : key
774
- if (filterSet.has(tmpPath)) {
775
- delete obj[key]
776
- } else if (typeof obj[key] === 'object') {
777
- ignoreFields(obj[key], filterSet, tmpPath)
778
- }
779
- })
780
- }
781
-
782
- nodes.forEach((node) => {
783
- if (other?.mapping?.in) {
784
- const mapping = other?.mapping?.in
785
- const { type } = node
786
- if (mapping[type]) {
787
- node.type = mapping[type]
788
- }
789
- }
790
- ignoreFields(node, excludeFieldsSet.in, '')
791
- // Object.keys(node.properties).forEach((key) => {
792
- // excludeFieldsSet.in.has(key) && delete node.properties[key];
793
- // });
794
- })
795
-
796
- edges.forEach((edge) => {
797
- if (other?.mapping?.in) {
798
- const mapping = other?.mapping?.in
799
- const { type } = edge
800
- if (mapping[type]) {
801
- edge.type = mapping[type]
802
- }
803
- }
804
- ignoreFields(edge, excludeFieldsSet.in, '')
805
- // Object.keys(edge.properties).forEach((key) => {
806
- // excludeFieldsSet.in.has(key) && delete edge.properties[key];
807
- // });
808
- })
809
-
810
- return {
811
- nodes,
812
- edges,
813
- }
814
- }
815
-
816
- function getLfNodes(value: any, shapes: any, key: any) {
817
- const nodes: NodeConfig[] = []
818
- if (Array.isArray(value)) {
819
- // 数组
820
- value.forEach((val) => {
821
- let shapeValue: any
822
- if (Array.isArray(shapes)) {
823
- shapeValue = shapes.find(
824
- (shape) => shape['-bpmnElement'] === val['-id'],
825
- )
826
- } else {
827
- shapeValue = shapes
828
- }
829
- const node = getNodeConfig(shapeValue, key, val)
830
- nodes.push(node)
831
- })
832
- } else {
833
- let shapeValue
834
- if (Array.isArray(shapes)) {
835
- shapeValue = shapes.find(
836
- (shape) => shape['-bpmnElement'] === value['-id'],
837
- )
838
- } else {
839
- shapeValue = shapes
840
- }
841
- const node = getNodeConfig(shapeValue, key, value)
842
- nodes.push(node)
843
- }
844
- return nodes
845
- }
846
-
847
- function getNodeConfig(shapeValue: any, type: any, processValue: any) {
848
- let x = Number(shapeValue['dc:Bounds']['-x'])
849
- let y = Number(shapeValue['dc:Bounds']['-y'])
850
- const { '-children': children } = processValue
851
- const name = processValue['-name']
852
- const shapeConfig = BPMNBaseAdapter.shapeConfigMap.get(type)
853
- if (shapeConfig) {
854
- x += shapeConfig.width / 2
855
- y += shapeConfig.height / 2
856
- }
857
- let properties: any = {}
858
- // 判断是否存在额外的属性,将额外的属性放到properties中
859
- Object.entries(processValue).forEach(([key, value]) => {
860
- if (!defaultAttrsForInput.includes(key)) {
861
- properties[key] = value
862
- }
863
- })
864
- properties = convertXmlToNormal(properties)
865
- let text
866
- if (name) {
867
- text = {
868
- x,
869
- y,
870
- value: name,
871
- }
872
- // 自定义文本位置
873
- if (
874
- shapeValue['bpmndi:BPMNLabel'] &&
875
- shapeValue['bpmndi:BPMNLabel']['dc:Bounds']
876
- ) {
877
- const textBounds = shapeValue['bpmndi:BPMNLabel']['dc:Bounds']
878
- text.x = Number(textBounds['-x']) + Number(textBounds['-width']) / 2
879
- text.y = Number(textBounds['-y']) + Number(textBounds['-height']) / 2
880
- }
881
- }
882
- const nodeConfig: NodeConfig = {
883
- id: shapeValue['-bpmnElement'],
884
- type,
885
- x,
886
- y,
887
- properties,
888
- }
889
- children && (nodeConfig.children = children)
890
- if (text) {
891
- nodeConfig.text = text
892
- }
893
- return nodeConfig
894
- }
895
-
896
- function getLfEdges(value: any, bpmnEdges: any) {
897
- const edges: EdgeConfig[] = []
898
- if (Array.isArray(value)) {
899
- value.forEach((val) => {
900
- let edgeValue
901
- if (Array.isArray(bpmnEdges)) {
902
- edgeValue = bpmnEdges.find(
903
- (edge) => edge['-bpmnElement'] === val['-id'],
904
- )
905
- } else {
906
- edgeValue = bpmnEdges
907
- }
908
- edges.push(getEdgeConfig(edgeValue, val))
909
- })
910
- } else {
911
- let edgeValue
912
- if (Array.isArray(bpmnEdges)) {
913
- edgeValue = bpmnEdges.find(
914
- (edge) => edge['-bpmnElement'] === value['-id'],
915
- )
916
- } else {
917
- edgeValue = bpmnEdges
918
- }
919
- edges.push(getEdgeConfig(edgeValue, value))
920
- }
921
- return edges
922
- }
923
-
924
- function getEdgeConfig(edgeValue: any, processValue: any) {
925
- let text
926
- const textVal = processValue['-name'] ? `${processValue['-name']}` : ''
927
- if (textVal) {
928
- const textBounds = edgeValue['bpmndi:BPMNLabel']['dc:Bounds']
929
- // 如果边文本换行,则其偏移量应该是最长一行的位置
930
- let textLength = 0
931
- textVal.split('\n').forEach((textSpan: string) => {
932
- if (textLength < textSpan.length) {
933
- textLength = textSpan.length
934
- }
935
- })
936
-
937
- text = {
938
- value: textVal,
939
- x: Number(textBounds['-x']) + (textLength * 10) / 2,
940
- y: Number(textBounds['-y']) + 7,
941
- }
942
- }
943
- let properties: any = {}
944
- // 判断是否存在额外的属性,将额外的属性放到properties中
945
- Object.entries(processValue).forEach(([key, value]) => {
946
- if (!defaultAttrsForInput.includes(key)) {
947
- properties[key] = value
948
- }
949
- })
950
- properties = convertXmlToNormal(properties)
951
- const pointsList = edgeValue['di:waypoint'].map((point: any) => ({
952
- x: Number(point['-x']),
953
- y: Number(point['-y']),
954
- }))
955
- const edge: EdgeConfig = {
956
- id: processValue['-id'],
957
- type: BpmnElements.FLOW,
958
- pointsList,
959
- sourceNodeId: processValue['-sourceRef'],
960
- targetNodeId: processValue['-targetRef'],
961
- properties,
962
- }
963
- if (text) {
964
- edge.text = text
965
- }
966
- return edge
967
- }
968
-
969
- class BPMNBaseAdapter {
970
- static pluginName = 'bpmn-adapter'
971
- static shapeConfigMap = new Map()
972
- processAttributes: {
973
- ['-isExecutable']: string
974
- ['-id']: string
975
- }
976
- definitionAttributes: {
977
- ['-id']: string
978
- ['-xmlns:xsi']: string
979
- ['-xmlns:bpmn']: string
980
- ['-xmlns:bpmndi']: string
981
- ['-xmlns:dc']: string
982
- ['-xmlns:di']: string
983
- ['-targetNamespace']: string
984
- ['-exporter']: string
985
- ['-exporterVersion']: string
986
- [key: string]: any
987
- }
988
- constructor({ lf }: any) {
989
- lf.adapterIn = this.adapterIn
990
- lf.adapterOut = this.adapterOut
991
- this.processAttributes = {
992
- '-isExecutable': 'true',
993
- '-id': 'Process',
994
- }
995
- this.definitionAttributes = {
996
- '-id': 'Definitions',
997
- '-xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
998
- '-xmlns:bpmn': 'http://www.omg.org/spec/BPMN/20100524/MODEL',
999
- '-xmlns:bpmndi': 'http://www.omg.org/spec/BPMN/20100524/DI',
1000
- '-xmlns:dc': 'http://www.omg.org/spec/DD/20100524/DC',
1001
- '-xmlns:di': 'http://www.omg.org/spec/DD/20100524/DI',
1002
- '-targetNamespace': 'http://logic-flow.org',
1003
- '-exporter': 'logicflow',
1004
- '-exporterVersion': '1.2.10',
1005
- }
1006
- }
1007
- setCustomShape(key: string, val: any) {
1008
- BPMNBaseAdapter.shapeConfigMap.set(key, val)
1009
- }
1010
- /**
1011
- * @param retainedAttrsFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
1012
- * ["properties", "startPoint", "endPoint", "pointsList"]合并,
1013
- * 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
1014
- * @param excludeFields excludeFields会和默认的defaultExcludeFields合并,出现在这个数组中的字段在转换时会被忽略
1015
- * @param transformer 对应节点或者边的内容转换规则
1016
- */
1017
- adapterOut = (data: any, other?: ExtraPropsType) => {
1018
- const bpmnProcessData = { ...this.processAttributes }
1019
- convertLf2ProcessData(bpmnProcessData, data, other)
1020
- const bpmnDiagramData = {
1021
- '-id': 'BPMNPlane_1',
1022
- '-bpmnElement': bpmnProcessData['-id'],
1023
- }
1024
- convertLf2DiagramData(bpmnDiagramData, data)
1025
- const definitions = this.definitionAttributes
1026
- definitions['bpmn:process'] = bpmnProcessData
1027
- definitions['bpmndi:BPMNDiagram'] = {
1028
- '-id': 'BPMNDiagram_1',
1029
- 'bpmndi:BPMNPlane': bpmnDiagramData,
1030
- }
1031
- const bpmnData = {
1032
- 'bpmn:definitions': definitions,
1033
- }
1034
-
1035
- if (other?.mapping?.out) {
1036
- const mapping = other?.mapping?.out
1037
-
1038
- const nameMapping = (obj: Record<string, any> | any[]): any => {
1039
- if (Array.isArray(obj)) {
1040
- obj.forEach((item) => nameMapping(item))
1041
- }
1042
- if (typeof obj === 'object') {
1043
- Object.keys(obj).forEach((key: string) => {
1044
- let mappingName: string
1045
- if ((mappingName = mapping[key])) {
1046
- obj[mappingName] = _.cloneDeep(obj[key])
1047
- delete obj[key]
1048
- nameMapping(obj[mappingName])
1049
- } else {
1050
- nameMapping(obj[key])
1051
- }
1052
- })
1053
- }
1054
- }
1055
- nameMapping(bpmnData)
1056
- }
1057
-
1058
- return bpmnData
1059
- }
1060
- adapterIn = (bpmnData: any, other?: ExtraPropsType) => {
1061
- if (bpmnData) {
1062
- return convertBpmn2LfData(bpmnData, other)
1063
- }
1064
- }
1065
- }
1066
-
1067
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.START, {
1068
- width: StartEventConfig.width,
1069
- height: StartEventConfig.height,
1070
- })
1071
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.END, {
1072
- width: EndEventConfig.width,
1073
- height: EndEventConfig.height,
1074
- })
1075
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.INTERMEDIATE_CATCH, {
1076
- width: IntermediateEventConfig.width,
1077
- height: IntermediateEventConfig.height,
1078
- })
1079
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.INTERMEDIATE_THROW, {
1080
- width: IntermediateEventConfig.width,
1081
- height: IntermediateEventConfig.height,
1082
- })
1083
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.BOUNDARY, {
1084
- width: BoundaryEventConfig.width,
1085
- height: BoundaryEventConfig.height,
1086
- })
1087
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.PARALLEL_GATEWAY, {
1088
- width: ParallelGatewayConfig.width,
1089
- height: ParallelGatewayConfig.height,
1090
- })
1091
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.INCLUSIVE_GATEWAY, {
1092
- width: InclusiveGatewayConfig.width,
1093
- height: InclusiveGatewayConfig.height,
1094
- })
1095
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.EXCLUSIVE_GATEWAY, {
1096
- width: ExclusiveGatewayConfig.width,
1097
- height: ExclusiveGatewayConfig.height,
1098
- })
1099
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.SYSTEM, {
1100
- width: ServiceTaskConfig.width,
1101
- height: ServiceTaskConfig.height,
1102
- })
1103
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.USER, {
1104
- width: UserTaskConfig.width,
1105
- height: UserTaskConfig.height,
1106
- })
1107
- BPMNBaseAdapter.shapeConfigMap.set(BpmnElements.SUBPROCESS, {
1108
- width: SubProcessConfig.width,
1109
- height: SubProcessConfig.height,
1110
- })
1111
-
1112
- class BPMNAdapter extends BPMNBaseAdapter {
1113
- static pluginName = 'BPMNAdapter'
1114
- private props: ExtraPropsType
1115
- constructor(data: any) {
1116
- super(data)
1117
- const { lf, props } = data
1118
- lf.adapterIn = this.adapterXmlIn
1119
- lf.adapterOut = this.adapterXmlOut
1120
- this.props = props
1121
- }
1122
- adapterXmlIn = (bpmnData: any) => {
1123
- const json = lfXml2Json(bpmnData)
1124
- return this.adapterIn(json, this.props)
1125
- }
1126
- adapterXmlOut = (data: any) => {
1127
- const outData = this.adapterOut(data, this.props)
1128
- return lfJson2Xml(outData)
1129
- }
1130
- }
1131
-
1132
- export { BPMNBaseAdapter, BPMNAdapter, convertNormalToXml, convertXmlToNormal }
1133
-
1134
- export default BPMNAdapter