@bpmnkit/core 1.6.0 → 1.7.0

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 (41) hide show
  1. package/builder-reference.md +211 -0
  2. package/dist/bpmn/auto-layout.js +32 -4
  3. package/dist/bpmn/bpmn-builder.d.ts +125 -3
  4. package/dist/bpmn/bpmn-builder.js +253 -34
  5. package/dist/bpmn/bpmn-model.d.ts +2 -0
  6. package/dist/bpmn/bpmn-parser.js +8 -0
  7. package/dist/bpmn/bpmn-serializer.js +1 -1
  8. package/dist/bpmn/builder-coverage.js +4 -12
  9. package/dist/bpmn/camunda7/export.d.ts +25 -0
  10. package/dist/bpmn/camunda7/export.js +218 -0
  11. package/dist/bpmn/camunda7/migrate.d.ts +3 -0
  12. package/dist/bpmn/camunda7/migrate.js +3 -3
  13. package/dist/bpmn/compact.d.ts +21 -0
  14. package/dist/bpmn/compact.js +86 -1
  15. package/dist/bpmn/full-operations.js +336 -3
  16. package/dist/bpmn/operations.d.ts +42 -1
  17. package/dist/bpmn/operations.js +12 -2
  18. package/dist/bpmn/optimize/flow.js +2 -0
  19. package/dist/bpmn/strip-camunda8.d.ts +22 -0
  20. package/dist/bpmn/strip-camunda8.js +55 -0
  21. package/dist/bpmn/utils.js +151 -1
  22. package/dist/bpmn/zeebe-extensions.d.ts +59 -2
  23. package/dist/bpmn/zeebe-extensions.js +89 -1
  24. package/dist/connectors/apply-element.d.ts +7 -3
  25. package/dist/connectors/apply-element.js +115 -4
  26. package/dist/connectors/apply-many.d.ts +5 -1
  27. package/dist/connectors/apply-many.js +5 -2
  28. package/dist/connectors/apply.d.ts +24 -3
  29. package/dist/connectors/apply.js +103 -3
  30. package/dist/connectors/catalog.js +5 -0
  31. package/dist/connectors/index.d.ts +1 -1
  32. package/dist/connectors/template-types.d.ts +30 -0
  33. package/dist/connectors/validate.js +33 -0
  34. package/dist/index.d.ts +6 -2
  35. package/dist/index.js +2 -0
  36. package/dist/layout/annotations.d.ts +3 -1
  37. package/dist/layout/annotations.js +72 -14
  38. package/dist/layout/semantic/place.js +23 -5
  39. package/dist/layout/semantic/route.js +15 -0
  40. package/dist/layout/types.d.ts +2 -1
  41. package/package.json +2 -1
@@ -1,6 +1,6 @@
1
1
  import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
2
2
  import { buildFlowElement, defaultFlows, makeEventDef, } from "./compact.js";
3
- import { bpmnElementName, ensureZeebeExtension, isZeebePlacementAllowed, } from "./zeebe-extensions.js";
3
+ import { assertZeebePlacement, bpmnElementName, ensureZeebeExtension, isZeebePlacementAllowed, zeebeExtensionsToXmlElements, } from "./zeebe-extensions.js";
4
4
  /** Thrown by {@link applyBpmnOperations} in strict mode. */
5
5
  export class OperationError extends Error {
6
6
  problems;
@@ -96,7 +96,227 @@ const PATCH_EXTENSIONS = [
96
96
  ["outputs", "zeebe:ioMapping"],
97
97
  ["nativeUserTask", "zeebe:userTask"],
98
98
  ["taskHeaders", "zeebe:taskHeaders"],
99
+ ["assignee", "zeebe:assignmentDefinition"],
100
+ ["candidateGroups", "zeebe:assignmentDefinition"],
101
+ ["candidateUsers", "zeebe:assignmentDefinition"],
102
+ ["dueDate", "zeebe:taskSchedule"],
103
+ ["followUpDate", "zeebe:taskSchedule"],
104
+ ["priority", "zeebe:priorityDefinition"],
105
+ ["properties", "zeebe:properties"],
106
+ ["executionListeners", "zeebe:executionListeners"],
107
+ ["taskListeners", "zeebe:taskListeners"],
99
108
  ];
109
+ /** Activities that can carry a `bpmn:multiInstanceLoopCharacteristics`. */
110
+ const LOOPABLE = new Set([
111
+ "serviceTask",
112
+ "scriptTask",
113
+ "userTask",
114
+ "businessRuleTask",
115
+ "callActivity",
116
+ "sendTask",
117
+ "receiveTask",
118
+ "manualTask",
119
+ "task",
120
+ "subProcess",
121
+ "adHocSubProcess",
122
+ "transaction",
123
+ ]);
124
+ const ROOT_FIELDS = [
125
+ ["messageName", "message", "name"],
126
+ ["errorCode", "error", "errorCode"],
127
+ ["escalationCode", "escalation", "escalationCode"],
128
+ ["signalName", "signal", "name"],
129
+ ];
130
+ const TIMER_FIELDS = [
131
+ ["timerDuration", "timeDuration"],
132
+ ["timerDate", "timeDate"],
133
+ ["timerCycle", "timeCycle"],
134
+ ];
135
+ function rootsOf(definitions, kind) {
136
+ return kind === "message"
137
+ ? definitions.messages
138
+ : kind === "error"
139
+ ? definitions.errors
140
+ : kind === "escalation"
141
+ ? definitions.escalations
142
+ : definitions.signals;
143
+ }
144
+ function refKey(kind) {
145
+ return `${kind}Ref`;
146
+ }
147
+ function eventDefinitionOf(element, type) {
148
+ return "eventDefinitions" in element
149
+ ? element.eventDefinitions.find((d) => d.type === type)
150
+ : undefined;
151
+ }
152
+ /** How many events reference the root element, so a shared one is not edited for all. */
153
+ function referenceCount(definitions, kind, id) {
154
+ let count = 0;
155
+ for (const container of containersOf(definitions)) {
156
+ for (const candidate of container.flowElements) {
157
+ // A send/receive task points at its message directly.
158
+ if (asRecord(candidate)[refKey(kind)] === id)
159
+ count++;
160
+ if (!("eventDefinitions" in candidate))
161
+ continue;
162
+ for (const definition of candidate.eventDefinitions) {
163
+ if (definition.type === kind && asRecord(definition)[refKey(kind)] === id)
164
+ count++;
165
+ }
166
+ }
167
+ }
168
+ return count;
169
+ }
170
+ /**
171
+ * Checks the event-definition fields of a patch without writing, so a failure
172
+ * leaves the element as it was. Returns the reason, or nothing.
173
+ */
174
+ function misplacedEventFields(definitions, element, patch) {
175
+ for (const [field, kind] of ROOT_FIELDS) {
176
+ if (patch[field] === undefined)
177
+ continue;
178
+ const definition = eventDefinitionOf(element, kind);
179
+ if (!definition)
180
+ return `${field} needs a ${kind} event definition, and "${element.id}" has none`;
181
+ const ref = asRecord(definition)[refKey(kind)];
182
+ if (typeof ref === "string" &&
183
+ rootsOf(definitions, kind).some((root) => root.id === ref) &&
184
+ referenceCount(definitions, kind, ref) > 1) {
185
+ return `${field}: the ${kind} "${ref}" is shared by ${referenceCount(definitions, kind, ref)} elements; changing it would change them all`;
186
+ }
187
+ }
188
+ for (const [field] of TIMER_FIELDS) {
189
+ if (patch[field] !== undefined && !eventDefinitionOf(element, "timer")) {
190
+ return `${field} needs a timer event definition, and "${element.id}" has none`;
191
+ }
192
+ }
193
+ if (patch.condition !== undefined && !eventDefinitionOf(element, "conditional")) {
194
+ return `condition needs a conditional event definition, and "${element.id}" has none`;
195
+ }
196
+ if (patch.messageName === "" && patch.correlationKey !== undefined) {
197
+ return 'correlationKey needs a message, and messageName: "" clears it';
198
+ }
199
+ if (patch.multiInstance !== undefined) {
200
+ if (!LOOPABLE.has(element.type)) {
201
+ return `multiInstance is not allowed on <${bpmnElementName(element)}>: only activities can run multi-instance`;
202
+ }
203
+ const current = "loopCharacteristics" in element ? element.loopCharacteristics : undefined;
204
+ if (!current && !patch.multiInstance.collection && patch.multiInstance.collection !== "") {
205
+ return "multiInstance needs a collection to add a loop to this element";
206
+ }
207
+ }
208
+ return undefined;
209
+ }
210
+ function idTaken(definitions, id) {
211
+ return (findElement(definitions, id) !== undefined ||
212
+ definitions.processes.some((p) => p.id === id) ||
213
+ [
214
+ ...definitions.messages,
215
+ ...definitions.errors,
216
+ ...definitions.escalations,
217
+ ...definitions.signals,
218
+ ].some((root) => root.id === id));
219
+ }
220
+ /** Index access on a model object, for fields chosen by name at runtime. */
221
+ function asRecord(value) {
222
+ return value;
223
+ }
224
+ /** Sets or, for `""`, removes a field on a plain record. */
225
+ function setOrDelete(target, key, value) {
226
+ const record = asRecord(target);
227
+ if (value === "")
228
+ delete record[key];
229
+ else
230
+ record[key] = value;
231
+ }
232
+ function applyEventFields(definitions, element, patch) {
233
+ for (const [field, kind, target] of ROOT_FIELDS) {
234
+ const value = patch[field];
235
+ if (value === undefined)
236
+ continue;
237
+ const found = eventDefinitionOf(element, kind);
238
+ if (!found)
239
+ continue;
240
+ const definition = asRecord(found);
241
+ const roots = rootsOf(definitions, kind);
242
+ let root = roots.find((candidate) => candidate.id === definition[refKey(kind)]);
243
+ if (!root) {
244
+ if (value === "")
245
+ continue;
246
+ let id = `${kind[0]?.toUpperCase()}${kind.slice(1)}_${element.id}`;
247
+ // Ids are unique across the whole document, not per kind.
248
+ while (idTaken(definitions, id))
249
+ id += "_";
250
+ root = { id, unknownAttributes: {} };
251
+ roots.push(root);
252
+ definition[refKey(kind)] = id;
253
+ }
254
+ setOrDelete(root, target, value);
255
+ }
256
+ const timer = eventDefinitionOf(element, "timer");
257
+ if (timer) {
258
+ for (const [field, key] of TIMER_FIELDS) {
259
+ const value = patch[field];
260
+ if (value === undefined)
261
+ continue;
262
+ setOrDelete(timer, key, value);
263
+ if (value === "")
264
+ delete asRecord(timer)[`${key}Attributes`];
265
+ }
266
+ }
267
+ const conditional = eventDefinitionOf(element, "conditional");
268
+ if (conditional?.type === "conditional" && patch.condition !== undefined) {
269
+ // "" stays "" rather than deleting the key: that is how the parser
270
+ // represents an empty condition, so a no-change reconcile stays a no-op.
271
+ conditional.condition = patch.condition;
272
+ if (patch.condition !== "") {
273
+ conditional.conditionAttributes ??= { "xsi:type": "bpmn:tFormalExpression" };
274
+ }
275
+ }
276
+ }
277
+ /** Applies the named parts of a multi-instance loop; see {@link ElementPatch.multiInstance}. */
278
+ function applyMultiInstance(element, patch) {
279
+ if (!("loopCharacteristics" in element) && !LOOPABLE.has(element.type))
280
+ return;
281
+ const holder = element;
282
+ if (patch.collection === "") {
283
+ Reflect.deleteProperty(holder, "loopCharacteristics");
284
+ return;
285
+ }
286
+ holder.loopCharacteristics ??= { extensionElements: [] };
287
+ const loop = holder.loopCharacteristics;
288
+ const zeebe = ensureLoopExtension(loop);
289
+ if (patch.collection !== undefined)
290
+ zeebe.attributes.inputCollection = patch.collection;
291
+ if (patch.sequential !== undefined)
292
+ loop.isSequential = patch.sequential || undefined;
293
+ for (const key of ["element", "outputCollection", "outputElement"]) {
294
+ const value = patch[key];
295
+ if (value === undefined)
296
+ continue;
297
+ setOrDelete(zeebe.attributes, key === "element" ? "inputElement" : key, value);
298
+ }
299
+ const wanted = patch.completionCondition;
300
+ if (wanted === "")
301
+ loop.completionCondition = undefined;
302
+ // Keeps the existing attributes (namespace declarations) when only the text changes.
303
+ else if (wanted !== undefined && loop.completionCondition)
304
+ loop.completionCondition.text = wanted;
305
+ else if (wanted !== undefined) {
306
+ loop.completionCondition = {
307
+ text: wanted,
308
+ attributes: { "xsi:type": "bpmn:tFormalExpression" },
309
+ };
310
+ }
311
+ }
312
+ function ensureLoopExtension(loop) {
313
+ const existing = loop.extensionElements.find((e) => e.name === "zeebe:loopCharacteristics");
314
+ if (existing)
315
+ return existing;
316
+ const created = { name: "zeebe:loopCharacteristics", attributes: {}, children: [] };
317
+ loop.extensionElements.push(created);
318
+ return created;
319
+ }
100
320
  /**
101
321
  * Reports a patch field that would write an extension the Zeebe schema does not
102
322
  * allow on this element — `decisionId` on a service task, say.
@@ -128,6 +348,24 @@ function misplacedExtensions(element, patch) {
128
348
  function setExtensionAttribute(element, extensionName, attribute, value) {
129
349
  ensureExtension(element, extensionName).attributes[attribute] = value;
130
350
  }
351
+ /**
352
+ * Like {@link setExtensionAttribute}, but an empty string removes the attribute
353
+ * and an extension left with nothing in it. The only way for a patch to unset a
354
+ * value, since `""` is never a meaningful assignee, schedule or priority.
355
+ */
356
+ function setOrClearAttribute(element, extensionName, attribute, value) {
357
+ if (value !== "") {
358
+ setExtensionAttribute(element, extensionName, attribute, value);
359
+ return;
360
+ }
361
+ const extension = element.extensionElements.find((candidate) => candidate.name === extensionName);
362
+ if (!extension)
363
+ return;
364
+ delete extension.attributes[attribute];
365
+ if (Object.keys(extension.attributes).length === 0 && extension.children.length === 0) {
366
+ element.extensionElements.splice(element.extensionElements.indexOf(extension), 1);
367
+ }
368
+ }
131
369
  /** Replaces the `zeebe:taskHeaders` children, which are a map and move together. */
132
370
  function setTaskHeaders(element, headers) {
133
371
  const extension = ensureExtension(element, "zeebe:taskHeaders");
@@ -137,6 +375,57 @@ function setTaskHeaders(element, headers) {
137
375
  children: [],
138
376
  }));
139
377
  }
378
+ /** Replaces the listener container wholesale, like headers; an empty list removes it. */
379
+ function setListeners(element, extensionName, listeners) {
380
+ if (listeners.length > 0)
381
+ assertZeebePlacement(bpmnElementName(element), extensionName);
382
+ element.extensionElements = element.extensionElements.filter((e) => e.name !== extensionName);
383
+ if (listeners.length === 0)
384
+ return;
385
+ const [rebuilt] = zeebeExtensionsToXmlElements(extensionName === "zeebe:executionListeners"
386
+ ? { executionListeners: listeners }
387
+ : { taskListeners: listeners });
388
+ if (rebuilt)
389
+ element.extensionElements.push(rebuilt);
390
+ }
391
+ /** Replaces the `zeebe:properties` children, which, like headers, are a map. */
392
+ function setProperties(element, properties) {
393
+ if (Object.keys(properties).length === 0) {
394
+ element.extensionElements = element.extensionElements.filter((e) => e.name !== "zeebe:properties");
395
+ return;
396
+ }
397
+ const extension = ensureExtension(element, "zeebe:properties");
398
+ extension.children = Object.entries(properties).map(([name, value]) => ({
399
+ name: "zeebe:property",
400
+ attributes: { name, value },
401
+ children: [],
402
+ }));
403
+ }
404
+ /**
405
+ * The `zeebe:subscription` that holds this element's correlation key, created
406
+ * if missing. An element still carrying its own subscription keeps it there;
407
+ * otherwise it belongs on the referenced `bpmn:message`, where Camunda reads it.
408
+ */
409
+ function subscriptionFor(definitions, element) {
410
+ const own = element.extensionElements.find((e) => e.name === "zeebe:subscription");
411
+ if (own)
412
+ return own;
413
+ const ref = "messageRef" in element && typeof element.messageRef === "string"
414
+ ? element.messageRef
415
+ : "eventDefinitions" in element
416
+ ? element.eventDefinitions.find((d) => d.type === "message")?.messageRef
417
+ : undefined;
418
+ const message = ref === undefined ? undefined : definitions.messages.find((m) => m.id === ref);
419
+ if (!message)
420
+ return undefined;
421
+ message.extensionElements ??= [];
422
+ const existing = message.extensionElements.find((e) => e.name === "zeebe:subscription");
423
+ if (existing)
424
+ return existing;
425
+ const created = { name: "zeebe:subscription", attributes: {}, children: [] };
426
+ message.extensionElements.push(created);
427
+ return created;
428
+ }
140
429
  /** Sets the named mappings of one kind, keeping the others of the `zeebe:ioMapping`. */
141
430
  function setMappings(element, kind, mappings) {
142
431
  const ioMapping = ensureExtension(element, "zeebe:ioMapping");
@@ -185,13 +474,26 @@ function setResultVariable(element, resultVariable) {
185
474
  * attribute rather than one extension element, so everything the compact form
186
475
  * does not model stays exactly as it was.
187
476
  */
188
- function patchElement(element, patch) {
477
+ function patchElement(definitions, element, patch) {
189
478
  if (patch.type !== undefined && patch.type !== element.type) {
190
479
  return `changing type (${element.type} → ${patch.type}) needs a delete and an insert, so that what the new element should carry is explicit`;
191
480
  }
192
481
  const misplaced = misplacedExtensions(element, patch);
193
482
  if (misplaced !== undefined)
194
483
  return misplaced;
484
+ const misplacedEvent = misplacedEventFields(definitions, element, patch);
485
+ if (misplacedEvent !== undefined)
486
+ return misplacedEvent;
487
+ // Resolved before anything is written, so a failure leaves the element as it was.
488
+ let subscription;
489
+ // With messageName in the same patch the message may not exist yet; it is
490
+ // looked up again once messageName has created it.
491
+ if (patch.correlationKey !== undefined && patch.messageName === undefined) {
492
+ subscription = subscriptionFor(definitions, element);
493
+ if (!subscription) {
494
+ return "correlationKey needs a message, and this element references no message";
495
+ }
496
+ }
195
497
  if (patch.name !== undefined)
196
498
  element.name = patch.name;
197
499
  if (patch.documentation !== undefined)
@@ -230,6 +532,37 @@ function patchElement(element, patch) {
230
532
  ensureExtension(element, "zeebe:userTask");
231
533
  if (patch.taskHeaders !== undefined)
232
534
  setTaskHeaders(element, patch.taskHeaders);
535
+ for (const key of ["assignee", "candidateGroups", "candidateUsers"]) {
536
+ const value = patch[key];
537
+ if (value !== undefined) {
538
+ setOrClearAttribute(element, "zeebe:assignmentDefinition", key, value);
539
+ }
540
+ }
541
+ for (const key of ["dueDate", "followUpDate"]) {
542
+ const value = patch[key];
543
+ if (value !== undefined)
544
+ setOrClearAttribute(element, "zeebe:taskSchedule", key, value);
545
+ }
546
+ if (patch.priority !== undefined) {
547
+ setOrClearAttribute(element, "zeebe:priorityDefinition", "priority", String(patch.priority));
548
+ }
549
+ if (patch.properties !== undefined)
550
+ setProperties(element, patch.properties);
551
+ if (patch.executionListeners !== undefined) {
552
+ setListeners(element, "zeebe:executionListeners", patch.executionListeners);
553
+ }
554
+ if (patch.taskListeners !== undefined) {
555
+ setListeners(element, "zeebe:taskListeners", patch.taskListeners);
556
+ }
557
+ applyEventFields(definitions, element, patch);
558
+ if (patch.multiInstance !== undefined)
559
+ applyMultiInstance(element, patch.multiInstance);
560
+ if (patch.correlationKey !== undefined && patch.messageName !== undefined) {
561
+ subscription = subscriptionFor(definitions, element);
562
+ }
563
+ if (subscription && patch.correlationKey !== undefined) {
564
+ subscription.attributes.correlationKey = patch.correlationKey;
565
+ }
233
566
  if (patch.eventType !== undefined && "eventDefinitions" in element) {
234
567
  const current = element.eventDefinitions[0]?.type;
235
568
  if (current !== patch.eventType) {
@@ -288,7 +621,7 @@ function applyOne(definitions, operation) {
288
621
  const found = findElement(definitions, operation.id);
289
622
  if (!found)
290
623
  return `no element with id "${operation.id}"`;
291
- return patchElement(found.element, operation.patch);
624
+ return patchElement(definitions, found.element, operation.patch);
292
625
  }
293
626
  case "delete": {
294
627
  const found = findElement(definitions, operation.id);
@@ -1,4 +1,45 @@
1
1
  import type { CompactDiagram, CompactElement } from "./compact.js";
2
+ import type { ZeebeListener } from "./zeebe-extensions.js";
3
+ /**
4
+ * The fields an `update` operation may set: any {@link CompactElement} field,
5
+ * plus the ones that live outside the element itself.
6
+ */
7
+ export type ElementPatch = Partial<Omit<CompactElement, "multiInstance">> & {
8
+ /**
9
+ * Changes only the named parts of the element's multi-instance loop; an empty
10
+ * string clears one, and an empty `collection` removes the loop. Adding a loop
11
+ * needs a `collection`. Only {@link applyBpmnOperations} applies it.
12
+ */
13
+ multiInstance?: Partial<NonNullable<CompactElement["multiInstance"]>>;
14
+ /**
15
+ * Names the `bpmn:message` / sets the error, escalation or signal the element's
16
+ * event definition references: they are written on that root element, created
17
+ * if the reference is missing. A root shared by several elements is reported
18
+ * rather than changed for all of them. `""` clears. Only
19
+ * {@link applyBpmnOperations} applies these.
20
+ */
21
+ messageName?: string;
22
+ errorCode?: string;
23
+ escalationCode?: string;
24
+ signalName?: string;
25
+ /** A timer's date (`timeDate`) and cycle (`timeCycle`); `timerDuration` is the duration. */
26
+ timerDate?: string;
27
+ timerCycle?: string;
28
+ /**
29
+ * The message correlation key (`zeebe:subscription`). It is written onto the
30
+ * `bpmn:message` the element references, where Camunda reads it, so every
31
+ * element sharing that message gets it. Only {@link applyBpmnOperations}
32
+ * applies it: the compact form has no messages to hold it.
33
+ */
34
+ correlationKey?: string;
35
+ /**
36
+ * Replaces the element's `zeebe:executionListeners`; `[]` removes them. Only
37
+ * {@link applyBpmnOperations} applies it: the compact form carries no listeners.
38
+ */
39
+ executionListeners?: ZeebeListener[];
40
+ /** Replaces a user task's `zeebe:taskListeners`; `[]` removes them. Same scope as above. */
41
+ taskListeners?: ZeebeListener[];
42
+ };
2
43
  /**
3
44
  * An atomic edit operation on a {@link CompactDiagram}.
4
45
  * All element/flow references use stable string IDs, not array positions.
@@ -17,7 +58,7 @@ export type BpmnOperation =
17
58
  | {
18
59
  op: "update";
19
60
  id: string;
20
- patch: Partial<CompactElement>;
61
+ patch: ElementPatch;
21
62
  }
22
63
  /** Remove an element by ID. */
23
64
  | {
@@ -67,8 +67,18 @@ function applyOne(diagram, op) {
67
67
  }
68
68
  case "update": {
69
69
  const found = findElementIn(process, op.id);
70
- if (found)
71
- Object.assign(found.element, op.patch);
70
+ if (found) {
71
+ // Root-element fields have no home in the compact form.
72
+ const { correlationKey: _messageLevel, messageName: _m, errorCode: _e, escalationCode: _x, signalName: _s, timerDate: _d, timerCycle: _c, multiInstance, ...patch } = op.patch;
73
+ Object.assign(found.element, patch);
74
+ if (multiInstance?.collection === "")
75
+ found.element.multiInstance = undefined;
76
+ else if (multiInstance) {
77
+ const merged = { ...found.element.multiInstance, ...multiInstance };
78
+ if (merged.collection)
79
+ found.element.multiInstance = { ...merged, collection: merged.collection };
80
+ }
81
+ }
72
82
  break;
73
83
  }
74
84
  case "delete": {
@@ -196,6 +196,8 @@ export function analyzeFlow(p, _opts) {
196
196
  id: `${gatewayId}_di`,
197
197
  bpmnElement: gatewayId,
198
198
  bounds: { x: gwX, y: gwY, width: gwWidth, height: gwHeight },
199
+ // The bpmn-js Viewer draws the "X" only when the shape says so.
200
+ isMarkerVisible: true,
199
201
  unknownAttributes: {},
200
202
  });
201
203
  for (const inFlowId of oldIncomingIds) {
@@ -0,0 +1,22 @@
1
+ import type { BpmnDefinitions } from "./bpmn-model.js";
2
+ /** One Camunda 8 vendor bit removed by {@link stripCamunda8}. */
3
+ export interface DroppedCamunda8Item {
4
+ /** Id of the owning element (`"definitions"` when it has none). */
5
+ elementId: string;
6
+ kind: "extensionElement" | "attribute" | "namespace";
7
+ /** Qualified name, e.g. `zeebe:taskDefinition`, `modeler:executionPlatform`, `xmlns:zeebe`. */
8
+ name: string;
9
+ }
10
+ export interface StripCamunda8Result {
11
+ definitions: BpmnDefinitions;
12
+ dropped: DroppedCamunda8Item[];
13
+ }
14
+ /**
15
+ * Returns a copy of `definitions` without Camunda 8 vendor content (`zeebe:*`
16
+ * extension elements and attributes, `modeler:*` attributes) so the export is
17
+ * plain BPMN, e.g. as a base for Camunda 7/Operaton. Opt-in and non-mutating;
18
+ * `camunda:*` and other vendors are left alone. Their `xmlns` declarations go
19
+ * too, unless some remaining content still uses the prefix.
20
+ */
21
+ export declare function stripCamunda8(definitions: BpmnDefinitions): StripCamunda8Result;
22
+ //# sourceMappingURL=strip-camunda8.d.ts.map
@@ -0,0 +1,55 @@
1
+ const PREFIXES = ["zeebe", "modeler"];
2
+ const isVendor = (qname) => PREFIXES.some((p) => qname.startsWith(`${p}:`));
3
+ /**
4
+ * Returns a copy of `definitions` without Camunda 8 vendor content (`zeebe:*`
5
+ * extension elements and attributes, `modeler:*` attributes) so the export is
6
+ * plain BPMN, e.g. as a base for Camunda 7/Operaton. Opt-in and non-mutating;
7
+ * `camunda:*` and other vendors are left alone. Their `xmlns` declarations go
8
+ * too, unless some remaining content still uses the prefix.
9
+ */
10
+ export function stripCamunda8(definitions) {
11
+ const copy = structuredClone(definitions);
12
+ const dropped = [];
13
+ const walk = (node, ownerId) => {
14
+ if (Array.isArray(node)) {
15
+ for (const item of node)
16
+ walk(item, ownerId);
17
+ return;
18
+ }
19
+ if (node === null || typeof node !== "object")
20
+ return;
21
+ const obj = node;
22
+ const id = typeof obj.id === "string" ? obj.id : ownerId;
23
+ for (const [key, value] of Object.entries(obj)) {
24
+ if (key === "extensionElements" && Array.isArray(value)) {
25
+ obj[key] = value.filter((x) => {
26
+ if (typeof x.name !== "string" || !isVendor(x.name))
27
+ return true;
28
+ dropped.push({ elementId: id, kind: "extensionElement", name: x.name });
29
+ return false;
30
+ });
31
+ }
32
+ else if (key === "unknownAttributes" && value && typeof value === "object") {
33
+ for (const a of Object.keys(value)) {
34
+ if (!isVendor(a))
35
+ continue;
36
+ delete value[a];
37
+ dropped.push({ elementId: id, kind: "attribute", name: a });
38
+ }
39
+ }
40
+ }
41
+ for (const value of Object.values(obj))
42
+ walk(value, id);
43
+ };
44
+ walk(copy, "definitions");
45
+ // Namespaces last: only drop a declaration nothing left refers to.
46
+ const remaining = JSON.stringify({ ...copy, namespaces: undefined });
47
+ for (const prefix of PREFIXES) {
48
+ if (!(prefix in copy.namespaces) || remaining.includes(`"${prefix}:`))
49
+ continue;
50
+ delete copy.namespaces[prefix];
51
+ dropped.push({ elementId: "definitions", kind: "namespace", name: `xmlns:${prefix}` });
52
+ }
53
+ return { definitions: copy, dropped };
54
+ }
55
+ //# sourceMappingURL=strip-camunda8.js.map