@emaarco/bpmn-js-data-simulation 0.0.0 → 0.2.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.
- package/README.md +99 -0
- package/dist/assets/bpmn-js-data-simulation.css +127 -0
- package/dist/domain/GatewayRouter.d.ts +11 -0
- package/dist/domain/GatewayRouter.d.ts.map +1 -0
- package/dist/domain/ScenarioError.d.ts +4 -0
- package/dist/domain/ScenarioError.d.ts.map +1 -0
- package/dist/domain/ScenarioParser.d.ts +7 -0
- package/dist/domain/ScenarioParser.d.ts.map +1 -0
- package/dist/domain/StartFieldCodec.d.ts +7 -0
- package/dist/domain/StartFieldCodec.d.ts.map +1 -0
- package/dist/domain/StartFieldDeriver.d.ts +7 -0
- package/dist/domain/StartFieldDeriver.d.ts.map +1 -0
- package/dist/domain/model.d.ts +64 -0
- package/dist/domain/model.d.ts.map +1 -0
- package/dist/engines/EngineRegistry.d.ts +6 -0
- package/dist/engines/EngineRegistry.d.ts.map +1 -0
- package/dist/engines/camunda7/Camunda7Engine.d.ts +17 -0
- package/dist/engines/camunda7/Camunda7Engine.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/JuelError.d.ts +4 -0
- package/dist/engines/camunda7/juel/JuelError.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/JuelEvaluator.d.ts +18 -0
- package/dist/engines/camunda7/juel/JuelEvaluator.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/JuelLexer.d.ts +6 -0
- package/dist/engines/camunda7/juel/JuelLexer.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/JuelParser.d.ts +19 -0
- package/dist/engines/camunda7/juel/JuelParser.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/JuelTemplate.d.ts +11 -0
- package/dist/engines/camunda7/juel/JuelTemplate.d.ts.map +1 -0
- package/dist/engines/camunda7/juel/juelSyntax.d.ts +34 -0
- package/dist/engines/camunda7/juel/juelSyntax.d.ts.map +1 -0
- package/dist/engines/engines.d.ts +5 -0
- package/dist/engines/engines.d.ts.map +1 -0
- package/dist/engines/types.d.ts +21 -0
- package/dist/engines/types.d.ts.map +1 -0
- package/dist/engines/zeebe/ZeebeEngine.d.ts +21 -0
- package/dist/engines/zeebe/ZeebeEngine.d.ts.map +1 -0
- package/dist/index.cjs +2099 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2084 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/DataGateways.d.ts +21 -0
- package/dist/integration/DataGateways.d.ts.map +1 -0
- package/dist/integration/DataSimulation.d.ts +35 -0
- package/dist/integration/DataSimulation.d.ts.map +1 -0
- package/dist/integration/DataSimulationOverlays.d.ts +23 -0
- package/dist/integration/DataSimulationOverlays.d.ts.map +1 -0
- package/dist/integration/DataSimulationPanel.d.ts +14 -0
- package/dist/integration/DataSimulationPanel.d.ts.map +1 -0
- package/dist/integration/DataSimulationToggle.d.ts +19 -0
- package/dist/integration/DataSimulationToggle.d.ts.map +1 -0
- package/dist/integration/DataStartForm.d.ts +19 -0
- package/dist/integration/DataStartForm.d.ts.map +1 -0
- package/dist/integration/IoMappings.d.ts +11 -0
- package/dist/integration/IoMappings.d.ts.map +1 -0
- package/dist/integration/VariableUsageCollector.d.ts +11 -0
- package/dist/integration/VariableUsageCollector.d.ts.map +1 -0
- package/dist/integration/behaviors/DataContextPads.d.ts +29 -0
- package/dist/integration/behaviors/DataContextPads.d.ts.map +1 -0
- package/dist/integration/behaviors/DataGatewayBehaviors.d.ts +13 -0
- package/dist/integration/behaviors/DataGatewayBehaviors.d.ts.map +1 -0
- package/dist/integration/behaviors/DataGatewaySettings.d.ts +18 -0
- package/dist/integration/behaviors/DataGatewaySettings.d.ts.map +1 -0
- package/dist/integration/index.d.ts +7 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/tokenSimulation.d.ts +95 -0
- package/dist/integration/tokenSimulation.d.ts.map +1 -0
- package/dist/simulation/DataSimulationStore.d.ts +85 -0
- package/dist/simulation/DataSimulationStore.d.ts.map +1 -0
- package/dist/simulation/GatewayDecisionView.d.ts +10 -0
- package/dist/simulation/GatewayDecisionView.d.ts.map +1 -0
- package/dist/ui/DecisionCard.d.ts +8 -0
- package/dist/ui/DecisionCard.d.ts.map +1 -0
- package/dist/ui/OutcomeBadge.d.ts +6 -0
- package/dist/ui/OutcomeBadge.d.ts.map +1 -0
- package/dist/ui/SimpleStartForm.d.ts +16 -0
- package/dist/ui/SimpleStartForm.d.ts.map +1 -0
- package/dist/ui/SimpleStartFormRenderer.d.ts +6 -0
- package/dist/ui/SimpleStartFormRenderer.d.ts.map +1 -0
- package/dist/ui/StartDialog.d.ts +40 -0
- package/dist/ui/StartDialog.d.ts.map +1 -0
- package/dist/ui/VariablesPanel.d.ts +34 -0
- package/dist/ui/VariablesPanel.d.ts.map +1 -0
- package/dist/ui/startForm.d.ts +17 -0
- package/dist/ui/startForm.d.ts.map +1 -0
- package/dist/utils/badgePosition.d.ts +10 -0
- package/dist/utils/badgePosition.d.ts.map +1 -0
- package/dist/utils/diagramElements.d.ts +7 -0
- package/dist/utils/diagramElements.d.ts.map +1 -0
- package/dist/utils/dom.d.ts +5 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/moddle.d.ts +8 -0
- package/dist/utils/moddle.d.ts.map +1 -0
- package/dist/utils/objects.d.ts +3 -0
- package/dist/utils/objects.d.ts.map +1 -0
- package/dist/utils/popoverPlacement.d.ts +18 -0
- package/dist/utils/popoverPlacement.d.ts.map +1 -0
- package/dist/utils/shadow.d.ts +2 -0
- package/dist/utils/shadow.d.ts.map +1 -0
- package/dist/utils/variables.d.ts +5 -0
- package/dist/utils/variables.d.ts.map +1 -0
- package/package.json +80 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2099 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var feelin = require('feelin');
|
|
6
|
+
|
|
7
|
+
class GatewayRouter {
|
|
8
|
+
route(kind, outgoing, evaluateCondition) {
|
|
9
|
+
const conditional = outgoing.filter((flow) => !flow.isDefault);
|
|
10
|
+
const defaultFlow = outgoing.find((flow) => flow.isDefault);
|
|
11
|
+
const evaluations = [];
|
|
12
|
+
for (const flow of conditional) {
|
|
13
|
+
const alreadyDecided = kind === "exclusive" && evaluations.some((evaluation) => this.isDecisive(evaluation));
|
|
14
|
+
evaluations.push(alreadyDecided ? { flow, outcome: "skipped" } : this.evaluateFlow(flow, evaluateCondition));
|
|
15
|
+
}
|
|
16
|
+
const failed = evaluations.find((evaluation) => evaluation.outcome === "error");
|
|
17
|
+
if (failed) {
|
|
18
|
+
return this.stuck(
|
|
19
|
+
evaluations,
|
|
20
|
+
defaultFlow,
|
|
21
|
+
`Condition of "${failed.flow.name ?? failed.flow.id}" failed: ${failed.reason}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
const taken = evaluations.filter((evaluation) => evaluation.outcome === "taken");
|
|
25
|
+
if (taken.length) {
|
|
26
|
+
return this.withDefault(
|
|
27
|
+
evaluations,
|
|
28
|
+
defaultFlow,
|
|
29
|
+
"not-taken",
|
|
30
|
+
taken.map((evaluation) => evaluation.flow.id)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (defaultFlow) {
|
|
34
|
+
return this.withDefault(evaluations, defaultFlow, "taken", [defaultFlow.id]);
|
|
35
|
+
}
|
|
36
|
+
return this.stuck(evaluations, defaultFlow, "No condition is true and there is no default flow");
|
|
37
|
+
}
|
|
38
|
+
evaluateFlow(flow, evaluateCondition) {
|
|
39
|
+
if (flow.expression === void 0) {
|
|
40
|
+
return { flow, outcome: "error", reason: "Missing condition" };
|
|
41
|
+
}
|
|
42
|
+
const evaluation = evaluateCondition(flow.expression);
|
|
43
|
+
if (!evaluation.ok) {
|
|
44
|
+
return { flow, outcome: "error", reason: evaluation.reason };
|
|
45
|
+
}
|
|
46
|
+
if (typeof evaluation.value !== "boolean") {
|
|
47
|
+
return {
|
|
48
|
+
flow,
|
|
49
|
+
outcome: "error",
|
|
50
|
+
value: evaluation.value,
|
|
51
|
+
reason: `Expected a boolean but got ${this.describe(evaluation.value)}`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { flow, outcome: evaluation.value ? "taken" : "not-taken", value: evaluation.value };
|
|
55
|
+
}
|
|
56
|
+
isDecisive(evaluation) {
|
|
57
|
+
return evaluation.outcome === "taken" || evaluation.outcome === "error";
|
|
58
|
+
}
|
|
59
|
+
withDefault(evaluations, defaultFlow, defaultOutcome, takenFlowIds) {
|
|
60
|
+
const flows = defaultFlow ? [...evaluations, { flow: defaultFlow, outcome: defaultOutcome }] : evaluations;
|
|
61
|
+
return { flows, takenFlowIds };
|
|
62
|
+
}
|
|
63
|
+
stuck(evaluations, defaultFlow, stuckReason) {
|
|
64
|
+
return { ...this.withDefault(evaluations, defaultFlow, "skipped", []), stuckReason };
|
|
65
|
+
}
|
|
66
|
+
describe(value) {
|
|
67
|
+
if (value === null || value === void 0) return "null";
|
|
68
|
+
return `${typeof value} ${JSON.stringify(value)}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class ScenarioError extends Error {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(...arguments);
|
|
75
|
+
this.name = "ScenarioError";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function setVariable(variables, path, value) {
|
|
80
|
+
const [head, ...rest] = path.split(".");
|
|
81
|
+
if (!rest.length) {
|
|
82
|
+
return { ...variables, [head]: value };
|
|
83
|
+
}
|
|
84
|
+
const nested = variables[head];
|
|
85
|
+
const nestedVariables = isVariables(nested) ? nested : {};
|
|
86
|
+
return { ...variables, [head]: setVariable(nestedVariables, rest.join("."), value) };
|
|
87
|
+
}
|
|
88
|
+
function isVariables(value) {
|
|
89
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
90
|
+
}
|
|
91
|
+
function withoutKeys(variables, keys) {
|
|
92
|
+
return Object.fromEntries(Object.entries(variables).filter(([key]) => !keys.includes(key)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class ScenarioParser {
|
|
96
|
+
parse(input) {
|
|
97
|
+
const list = isVariables(input) ? input.scenarios : input;
|
|
98
|
+
if (!Array.isArray(list)) {
|
|
99
|
+
throw new ScenarioError('Expected an array of scenarios or an object with a "scenarios" array');
|
|
100
|
+
}
|
|
101
|
+
const scenarios = list.map((raw, index) => this.parseScenario(raw, index));
|
|
102
|
+
this.assertUniqueIds(scenarios);
|
|
103
|
+
return scenarios;
|
|
104
|
+
}
|
|
105
|
+
parseScenario(raw, index) {
|
|
106
|
+
if (!isVariables(raw)) {
|
|
107
|
+
throw new ScenarioError(`Scenario #${index + 1} must be an object`);
|
|
108
|
+
}
|
|
109
|
+
const { id, name, description, variables = {}, taskResults = {} } = raw;
|
|
110
|
+
const label = typeof id === "string" ? `"${id}"` : `#${index + 1}`;
|
|
111
|
+
if (typeof id !== "string" || !id) {
|
|
112
|
+
throw new ScenarioError(`Scenario ${label} needs a non-empty string "id"`);
|
|
113
|
+
}
|
|
114
|
+
if (name !== void 0 && typeof name !== "string") {
|
|
115
|
+
throw new ScenarioError(`Scenario ${label}: "name" must be a string`);
|
|
116
|
+
}
|
|
117
|
+
if (description !== void 0 && typeof description !== "string") {
|
|
118
|
+
throw new ScenarioError(`Scenario ${label}: "description" must be a string`);
|
|
119
|
+
}
|
|
120
|
+
if (!isVariables(variables)) {
|
|
121
|
+
throw new ScenarioError(`Scenario ${label}: "variables" must be an object`);
|
|
122
|
+
}
|
|
123
|
+
if (!isVariables(taskResults) || !Object.values(taskResults).every(isVariables)) {
|
|
124
|
+
throw new ScenarioError(`Scenario ${label}: "taskResults" must map element ids to objects`);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
id,
|
|
128
|
+
name: name ?? id,
|
|
129
|
+
...description === void 0 ? {} : { description },
|
|
130
|
+
variables,
|
|
131
|
+
taskResults
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
assertUniqueIds(scenarios) {
|
|
135
|
+
const seen = /* @__PURE__ */ new Set();
|
|
136
|
+
for (const { id } of scenarios) {
|
|
137
|
+
if (seen.has(id)) {
|
|
138
|
+
throw new ScenarioError(`Duplicate scenario id "${id}"`);
|
|
139
|
+
}
|
|
140
|
+
seen.add(id);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class StartFieldCodec {
|
|
146
|
+
parse(field, raw) {
|
|
147
|
+
if (typeof raw === "boolean") return { ok: true, value: raw };
|
|
148
|
+
const text = raw.trim();
|
|
149
|
+
if (!text) return { ok: true, value: void 0 };
|
|
150
|
+
switch (field.type) {
|
|
151
|
+
case "number": {
|
|
152
|
+
const value = Number(text);
|
|
153
|
+
return Number.isNaN(value) ? { ok: false, reason: `${field.name} must be a number` } : { ok: true, value };
|
|
154
|
+
}
|
|
155
|
+
case "json":
|
|
156
|
+
try {
|
|
157
|
+
return { ok: true, value: JSON.parse(text) };
|
|
158
|
+
} catch {
|
|
159
|
+
return { ok: false, reason: `${field.name} must be valid JSON` };
|
|
160
|
+
}
|
|
161
|
+
case "auto":
|
|
162
|
+
try {
|
|
163
|
+
return { ok: true, value: JSON.parse(text) };
|
|
164
|
+
} catch {
|
|
165
|
+
return { ok: true, value: raw };
|
|
166
|
+
}
|
|
167
|
+
default:
|
|
168
|
+
return { ok: true, value: raw };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
format(field, value) {
|
|
172
|
+
if (field.type === "boolean") return value === true;
|
|
173
|
+
if (value === void 0 || value === null) return "";
|
|
174
|
+
if (typeof value === "string" && field.type !== "json") return value;
|
|
175
|
+
return field.type === "number" ? String(value) : JSON.stringify(value);
|
|
176
|
+
}
|
|
177
|
+
apply(base, values) {
|
|
178
|
+
const variables = { ...base };
|
|
179
|
+
for (const [name, value] of Object.entries(values)) {
|
|
180
|
+
if (value === void 0) delete variables[name];
|
|
181
|
+
else variables[name] = value;
|
|
182
|
+
}
|
|
183
|
+
return variables;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function findExtension(element, type) {
|
|
188
|
+
const extensionElements = element.extensionElements;
|
|
189
|
+
return extensionElements?.values?.find((value) => value.$type === type);
|
|
190
|
+
}
|
|
191
|
+
function listProperty(element, property) {
|
|
192
|
+
const value = element?.[property];
|
|
193
|
+
return Array.isArray(value) ? value : [];
|
|
194
|
+
}
|
|
195
|
+
function readConditionExpression(sequenceFlow) {
|
|
196
|
+
const condition = sequenceFlow.conditionExpression;
|
|
197
|
+
if (!condition) return void 0;
|
|
198
|
+
return {
|
|
199
|
+
body: typeof condition.body === "string" ? condition.body : void 0,
|
|
200
|
+
language: typeof condition.language === "string" ? condition.language : void 0
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
class JuelError extends Error {
|
|
205
|
+
constructor() {
|
|
206
|
+
super(...arguments);
|
|
207
|
+
this.name = "JuelError";
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function hasOwn(object, key) {
|
|
212
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
213
|
+
}
|
|
214
|
+
function deepEqual(left, right) {
|
|
215
|
+
if (left === right) return true;
|
|
216
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
|
|
217
|
+
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
218
|
+
const leftKeys = Object.keys(left);
|
|
219
|
+
const rightKeys = Object.keys(right);
|
|
220
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
221
|
+
(key) => hasOwn(right, key) && deepEqual(left[key], right[key])
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
class JuelEvaluator {
|
|
226
|
+
constructor(variables) {
|
|
227
|
+
this.variables = variables;
|
|
228
|
+
}
|
|
229
|
+
evaluate(node) {
|
|
230
|
+
switch (node.type) {
|
|
231
|
+
case "literal":
|
|
232
|
+
return node.value;
|
|
233
|
+
case "identifier":
|
|
234
|
+
if (!hasOwn(this.variables, node.name)) {
|
|
235
|
+
throw new JuelError(`Unknown property used in expression: ${node.name}`);
|
|
236
|
+
}
|
|
237
|
+
return this.variables[node.name];
|
|
238
|
+
case "member":
|
|
239
|
+
return this.readMember(this.evaluate(node.object), this.evaluate(node.property));
|
|
240
|
+
case "unary":
|
|
241
|
+
return this.evaluateUnary(node.operator, this.evaluate(node.operand));
|
|
242
|
+
case "conditional":
|
|
243
|
+
return this.coerceToBoolean(this.evaluate(node.test)) ? this.evaluate(node.consequent) : this.evaluate(node.alternate);
|
|
244
|
+
case "binary":
|
|
245
|
+
return this.evaluateBinary(node);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
coerceToString(value) {
|
|
249
|
+
if (value === null || value === void 0) return "";
|
|
250
|
+
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
251
|
+
}
|
|
252
|
+
readMember(object, property) {
|
|
253
|
+
if (object === null || object === void 0) return null;
|
|
254
|
+
const key = Array.isArray(object) ? Number(property) : String(property);
|
|
255
|
+
return hasOwn(object, key) ? object[key] ?? null : null;
|
|
256
|
+
}
|
|
257
|
+
evaluateUnary(operator, operand) {
|
|
258
|
+
if (operator === "!") return !this.coerceToBoolean(operand);
|
|
259
|
+
if (operator === "-") return -this.coerceToNumber(operand);
|
|
260
|
+
return this.isEmpty(operand);
|
|
261
|
+
}
|
|
262
|
+
evaluateBinary(node) {
|
|
263
|
+
const { operator } = node;
|
|
264
|
+
if (operator === "&&") {
|
|
265
|
+
return this.coerceToBoolean(this.evaluate(node.left)) && this.coerceToBoolean(this.evaluate(node.right));
|
|
266
|
+
}
|
|
267
|
+
if (operator === "||") {
|
|
268
|
+
return this.coerceToBoolean(this.evaluate(node.left)) || this.coerceToBoolean(this.evaluate(node.right));
|
|
269
|
+
}
|
|
270
|
+
const left = this.evaluate(node.left);
|
|
271
|
+
const right = this.evaluate(node.right);
|
|
272
|
+
const eitherIsNull = this.isNull(left) || this.isNull(right);
|
|
273
|
+
const bothAreNull = this.isNull(left) && this.isNull(right);
|
|
274
|
+
switch (operator) {
|
|
275
|
+
case "==":
|
|
276
|
+
return this.areEqual(left, right);
|
|
277
|
+
case "!=":
|
|
278
|
+
return !this.areEqual(left, right);
|
|
279
|
+
case "<":
|
|
280
|
+
return eitherIsNull ? false : this.compare(left, right) < 0;
|
|
281
|
+
case ">":
|
|
282
|
+
return eitherIsNull ? false : this.compare(left, right) > 0;
|
|
283
|
+
case "<=":
|
|
284
|
+
return eitherIsNull ? bothAreNull : this.compare(left, right) <= 0;
|
|
285
|
+
case ">=":
|
|
286
|
+
return eitherIsNull ? bothAreNull : this.compare(left, right) >= 0;
|
|
287
|
+
case "+":
|
|
288
|
+
return this.coerceToNumber(left) + this.coerceToNumber(right);
|
|
289
|
+
case "-":
|
|
290
|
+
return this.coerceToNumber(left) - this.coerceToNumber(right);
|
|
291
|
+
case "*":
|
|
292
|
+
return this.coerceToNumber(left) * this.coerceToNumber(right);
|
|
293
|
+
case "/":
|
|
294
|
+
return this.coerceToNumber(left) / this.coerceToNumber(right);
|
|
295
|
+
default:
|
|
296
|
+
return this.coerceToNumber(left) % this.coerceToNumber(right);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
isNull(value) {
|
|
300
|
+
return value === null || value === void 0;
|
|
301
|
+
}
|
|
302
|
+
areEqual(left, right) {
|
|
303
|
+
if (left === right) return true;
|
|
304
|
+
if (this.isNull(left) || this.isNull(right)) return this.isNull(left) && this.isNull(right);
|
|
305
|
+
if (typeof left === "number" || typeof right === "number") {
|
|
306
|
+
return this.coerceToNumber(left) === this.coerceToNumber(right);
|
|
307
|
+
}
|
|
308
|
+
if (typeof left === "boolean" || typeof right === "boolean") {
|
|
309
|
+
return this.coerceToBoolean(left) === this.coerceToBoolean(right);
|
|
310
|
+
}
|
|
311
|
+
if (typeof left === "object" || typeof right === "object") return deepEqual(left, right);
|
|
312
|
+
return String(left) === String(right);
|
|
313
|
+
}
|
|
314
|
+
compare(left, right) {
|
|
315
|
+
if (typeof left === "string" && typeof right === "string") return left < right ? -1 : left > right ? 1 : 0;
|
|
316
|
+
return this.coerceToNumber(left) - this.coerceToNumber(right);
|
|
317
|
+
}
|
|
318
|
+
coerceToNumber(value) {
|
|
319
|
+
if (value === null || value === void 0 || value === "") return 0;
|
|
320
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
321
|
+
if (typeof value === "boolean" || Number.isNaN(number)) {
|
|
322
|
+
throw new JuelError(`Cannot coerce ${JSON.stringify(value)} to a number`);
|
|
323
|
+
}
|
|
324
|
+
return number;
|
|
325
|
+
}
|
|
326
|
+
coerceToBoolean(value) {
|
|
327
|
+
if (typeof value === "boolean") return value;
|
|
328
|
+
if (value === null || value === void 0 || value === "") return false;
|
|
329
|
+
if (typeof value === "string") return value.toLowerCase() === "true";
|
|
330
|
+
throw new JuelError(`Cannot coerce ${JSON.stringify(value)} to a boolean`);
|
|
331
|
+
}
|
|
332
|
+
isEmpty(value) {
|
|
333
|
+
if (value === null || value === void 0 || value === "") return true;
|
|
334
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
335
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const KEYWORD_OPERATORS = {
|
|
341
|
+
and: "&&",
|
|
342
|
+
or: "||",
|
|
343
|
+
not: "!",
|
|
344
|
+
eq: "==",
|
|
345
|
+
ne: "!=",
|
|
346
|
+
lt: "<",
|
|
347
|
+
gt: ">",
|
|
348
|
+
le: "<=",
|
|
349
|
+
ge: ">=",
|
|
350
|
+
div: "/",
|
|
351
|
+
mod: "%",
|
|
352
|
+
empty: "empty"
|
|
353
|
+
};
|
|
354
|
+
const SYMBOL_OPERATORS = [
|
|
355
|
+
"==",
|
|
356
|
+
"!=",
|
|
357
|
+
"<=",
|
|
358
|
+
">=",
|
|
359
|
+
"&&",
|
|
360
|
+
"||",
|
|
361
|
+
"<",
|
|
362
|
+
">",
|
|
363
|
+
"!",
|
|
364
|
+
"+",
|
|
365
|
+
"-",
|
|
366
|
+
"*",
|
|
367
|
+
"/",
|
|
368
|
+
"%",
|
|
369
|
+
"(",
|
|
370
|
+
")",
|
|
371
|
+
"[",
|
|
372
|
+
"]",
|
|
373
|
+
".",
|
|
374
|
+
"?",
|
|
375
|
+
":"
|
|
376
|
+
];
|
|
377
|
+
const BINARY_PRECEDENCE = [
|
|
378
|
+
["||"],
|
|
379
|
+
["&&"],
|
|
380
|
+
["==", "!="],
|
|
381
|
+
["<", ">", "<=", ">="],
|
|
382
|
+
["+", "-"],
|
|
383
|
+
["*", "/", "%"]
|
|
384
|
+
];
|
|
385
|
+
|
|
386
|
+
class JuelLexer {
|
|
387
|
+
tokenize(source) {
|
|
388
|
+
const tokens = [];
|
|
389
|
+
let index = 0;
|
|
390
|
+
while (index < source.length) {
|
|
391
|
+
const char = source[index];
|
|
392
|
+
if (/\s/.test(char)) {
|
|
393
|
+
index++;
|
|
394
|
+
} else if (/[0-9]/.test(char) || char === "." && /[0-9]/.test(source[index + 1] ?? "")) {
|
|
395
|
+
const match = /^[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?/.exec(source.slice(index));
|
|
396
|
+
tokens.push({ kind: "number", text: match[0], value: Number(match[0]) });
|
|
397
|
+
index += match[0].length;
|
|
398
|
+
} else if (char === "'" || char === '"') {
|
|
399
|
+
const { value, length } = this.readString(source, index);
|
|
400
|
+
tokens.push({ kind: "string", text: source.slice(index, index + length), value });
|
|
401
|
+
index += length;
|
|
402
|
+
} else if (/[A-Za-z_$]/.test(char)) {
|
|
403
|
+
const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(index));
|
|
404
|
+
const word = match[0];
|
|
405
|
+
const keywordOperator = hasOwn(KEYWORD_OPERATORS, word) ? KEYWORD_OPERATORS[word] : void 0;
|
|
406
|
+
tokens.push(keywordOperator ? { kind: "operator", text: keywordOperator } : { kind: "identifier", text: word });
|
|
407
|
+
index += word.length;
|
|
408
|
+
} else {
|
|
409
|
+
const operator = SYMBOL_OPERATORS.find((candidate) => source.startsWith(candidate, index));
|
|
410
|
+
if (!operator) throw new JuelError(`Unexpected character "${char}"`);
|
|
411
|
+
tokens.push({ kind: "operator", text: operator });
|
|
412
|
+
index += operator.length;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return tokens;
|
|
416
|
+
}
|
|
417
|
+
readString(source, start) {
|
|
418
|
+
const quote = source[start];
|
|
419
|
+
let value = "";
|
|
420
|
+
for (let index = start + 1; index < source.length; index++) {
|
|
421
|
+
const char = source[index];
|
|
422
|
+
if (char === "\\") {
|
|
423
|
+
value += source[index + 1] ?? "";
|
|
424
|
+
index++;
|
|
425
|
+
} else if (char === quote) {
|
|
426
|
+
return { value, length: index - start + 1 };
|
|
427
|
+
} else {
|
|
428
|
+
value += char;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
throw new JuelError("Unterminated string literal");
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
class JuelParser {
|
|
436
|
+
constructor(source) {
|
|
437
|
+
this.position = 0;
|
|
438
|
+
this.tokens = new JuelLexer().tokenize(source);
|
|
439
|
+
}
|
|
440
|
+
parse() {
|
|
441
|
+
const node = this.parseExpression();
|
|
442
|
+
const token = this.peek();
|
|
443
|
+
if (token) throw new JuelError(`Unexpected "${token.text}"`);
|
|
444
|
+
return node;
|
|
445
|
+
}
|
|
446
|
+
parseExpression() {
|
|
447
|
+
const test = this.parseBinary(0);
|
|
448
|
+
if (!this.accept("?")) return test;
|
|
449
|
+
const consequent = this.parseExpression();
|
|
450
|
+
this.expect(":");
|
|
451
|
+
const alternate = this.parseExpression();
|
|
452
|
+
return { type: "conditional", test, consequent, alternate };
|
|
453
|
+
}
|
|
454
|
+
parseBinary(level) {
|
|
455
|
+
if (level === BINARY_PRECEDENCE.length) return this.parseUnary();
|
|
456
|
+
let left = this.parseBinary(level + 1);
|
|
457
|
+
let operator = this.acceptAny(BINARY_PRECEDENCE[level]);
|
|
458
|
+
while (operator) {
|
|
459
|
+
const right = this.parseBinary(level + 1);
|
|
460
|
+
left = { type: "binary", operator, left, right };
|
|
461
|
+
operator = this.acceptAny(BINARY_PRECEDENCE[level]);
|
|
462
|
+
}
|
|
463
|
+
return left;
|
|
464
|
+
}
|
|
465
|
+
parseUnary() {
|
|
466
|
+
const operator = this.acceptAny(["!", "-", "empty"]);
|
|
467
|
+
if (operator) return { type: "unary", operator, operand: this.parseUnary() };
|
|
468
|
+
return this.parseMember();
|
|
469
|
+
}
|
|
470
|
+
parseMember() {
|
|
471
|
+
let node = this.parsePrimary();
|
|
472
|
+
for (; ; ) {
|
|
473
|
+
if (this.accept(".")) {
|
|
474
|
+
const property = this.next();
|
|
475
|
+
if (property?.kind !== "identifier") throw new JuelError('Expected a property name after "."');
|
|
476
|
+
node = { type: "member", object: node, property: { type: "literal", value: property.text } };
|
|
477
|
+
} else if (this.accept("[")) {
|
|
478
|
+
node = { type: "member", object: node, property: this.parseExpression() };
|
|
479
|
+
this.expect("]");
|
|
480
|
+
} else if (this.peek()?.text === "(") {
|
|
481
|
+
throw new JuelError("Method calls are not supported");
|
|
482
|
+
} else {
|
|
483
|
+
return node;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
parsePrimary() {
|
|
488
|
+
const token = this.next();
|
|
489
|
+
if (!token) throw new JuelError("Unexpected end of expression");
|
|
490
|
+
if (token.kind === "number" || token.kind === "string") return { type: "literal", value: token.value };
|
|
491
|
+
if (token.kind === "identifier") return this.identifierOrLiteral(token.text);
|
|
492
|
+
if (token.text === "(") {
|
|
493
|
+
const node = this.parseExpression();
|
|
494
|
+
this.expect(")");
|
|
495
|
+
return node;
|
|
496
|
+
}
|
|
497
|
+
throw new JuelError(`Unexpected "${token.text}"`);
|
|
498
|
+
}
|
|
499
|
+
identifierOrLiteral(name) {
|
|
500
|
+
if (name === "true") return { type: "literal", value: true };
|
|
501
|
+
if (name === "false") return { type: "literal", value: false };
|
|
502
|
+
if (name === "null") return { type: "literal", value: null };
|
|
503
|
+
return { type: "identifier", name };
|
|
504
|
+
}
|
|
505
|
+
peek() {
|
|
506
|
+
return this.tokens[this.position];
|
|
507
|
+
}
|
|
508
|
+
next() {
|
|
509
|
+
return this.tokens[this.position++];
|
|
510
|
+
}
|
|
511
|
+
accept(text) {
|
|
512
|
+
if (this.peek()?.kind !== "operator" || this.peek()?.text !== text) return false;
|
|
513
|
+
this.position++;
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
acceptAny(operators) {
|
|
517
|
+
return operators.find((operator) => this.accept(operator));
|
|
518
|
+
}
|
|
519
|
+
expect(text) {
|
|
520
|
+
if (!this.accept(text)) throw new JuelError(`Expected "${text}"`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
class JuelTemplate {
|
|
525
|
+
constructor(parts) {
|
|
526
|
+
this.parts = parts;
|
|
527
|
+
}
|
|
528
|
+
static parse(text) {
|
|
529
|
+
const parts = [];
|
|
530
|
+
let cursor = 0;
|
|
531
|
+
while (cursor < text.length) {
|
|
532
|
+
const start = JuelTemplate.findExpressionStart(text, cursor);
|
|
533
|
+
if (start === -1) {
|
|
534
|
+
parts.push(text.slice(cursor));
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
if (start > cursor) parts.push(text.slice(cursor, start));
|
|
538
|
+
const end = JuelTemplate.findExpressionEnd(text, start + 2);
|
|
539
|
+
parts.push(new JuelParser(text.slice(start + 2, end)).parse());
|
|
540
|
+
cursor = end + 1;
|
|
541
|
+
}
|
|
542
|
+
return new JuelTemplate(parts);
|
|
543
|
+
}
|
|
544
|
+
evaluate(variables) {
|
|
545
|
+
const evaluator = new JuelEvaluator(variables);
|
|
546
|
+
const [onlyPart] = this.parts;
|
|
547
|
+
if (this.parts.length === 1 && typeof onlyPart !== "string") {
|
|
548
|
+
return evaluator.evaluate(onlyPart);
|
|
549
|
+
}
|
|
550
|
+
return this.parts.map((part) => typeof part === "string" ? part : evaluator.coerceToString(evaluator.evaluate(part))).join("");
|
|
551
|
+
}
|
|
552
|
+
variableNames() {
|
|
553
|
+
const names = /* @__PURE__ */ new Set();
|
|
554
|
+
const visit = (node) => {
|
|
555
|
+
if (node.type === "identifier") names.add(node.name);
|
|
556
|
+
if (node.type === "member") {
|
|
557
|
+
visit(node.object);
|
|
558
|
+
visit(node.property);
|
|
559
|
+
}
|
|
560
|
+
if (node.type === "unary") visit(node.operand);
|
|
561
|
+
if (node.type === "binary") {
|
|
562
|
+
visit(node.left);
|
|
563
|
+
visit(node.right);
|
|
564
|
+
}
|
|
565
|
+
if (node.type === "conditional") {
|
|
566
|
+
visit(node.test);
|
|
567
|
+
visit(node.consequent);
|
|
568
|
+
visit(node.alternate);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
this.parts.forEach((part) => typeof part !== "string" && visit(part));
|
|
572
|
+
return [...names];
|
|
573
|
+
}
|
|
574
|
+
static findExpressionStart(text, from) {
|
|
575
|
+
const dollar = text.indexOf("${", from);
|
|
576
|
+
const hash = text.indexOf("#{", from);
|
|
577
|
+
if (dollar === -1) return hash;
|
|
578
|
+
if (hash === -1) return dollar;
|
|
579
|
+
return Math.min(dollar, hash);
|
|
580
|
+
}
|
|
581
|
+
static findExpressionEnd(text, from) {
|
|
582
|
+
let quote = null;
|
|
583
|
+
for (let index = from; index < text.length; index++) {
|
|
584
|
+
const char = text[index];
|
|
585
|
+
if (quote) {
|
|
586
|
+
if (char === "\\") index++;
|
|
587
|
+
else if (char === quote) quote = null;
|
|
588
|
+
} else if (char === "'" || char === '"') {
|
|
589
|
+
quote = char;
|
|
590
|
+
} else if (char === "}") {
|
|
591
|
+
return index;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
throw new JuelError('Unterminated expression, missing "}"');
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
class Camunda7Engine {
|
|
599
|
+
constructor() {
|
|
600
|
+
this.id = "camunda7";
|
|
601
|
+
this.label = "Camunda 7";
|
|
602
|
+
this.expressionLanguage = "JUEL";
|
|
603
|
+
this.taskResultPropagation = "always";
|
|
604
|
+
}
|
|
605
|
+
writeVariable(variables, target, value) {
|
|
606
|
+
return { ...variables, [target]: value };
|
|
607
|
+
}
|
|
608
|
+
readInputMappings(element) {
|
|
609
|
+
return this.readMappings(element, "inputParameters");
|
|
610
|
+
}
|
|
611
|
+
readOutputMappings(element) {
|
|
612
|
+
return this.readMappings(element, "outputParameters");
|
|
613
|
+
}
|
|
614
|
+
readCondition(sequenceFlow) {
|
|
615
|
+
const condition = readConditionExpression(sequenceFlow);
|
|
616
|
+
const isJuel = !condition?.language || condition.language.toLowerCase() === "juel";
|
|
617
|
+
return isJuel ? condition?.body?.trim() || void 0 : void 0;
|
|
618
|
+
}
|
|
619
|
+
canEvaluate(expression) {
|
|
620
|
+
try {
|
|
621
|
+
JuelTemplate.parse(expression);
|
|
622
|
+
return true;
|
|
623
|
+
} catch {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
evaluate(expression, variables) {
|
|
628
|
+
if (!expression) {
|
|
629
|
+
return { ok: true, value: null };
|
|
630
|
+
}
|
|
631
|
+
try {
|
|
632
|
+
return { ok: true, value: JuelTemplate.parse(expression).evaluate(variables) };
|
|
633
|
+
} catch (error) {
|
|
634
|
+
return { ok: false, reason: error.message };
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
readVariableNames(expression) {
|
|
638
|
+
try {
|
|
639
|
+
return JuelTemplate.parse(expression).variableNames();
|
|
640
|
+
} catch {
|
|
641
|
+
return [];
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
readMappings(element, property) {
|
|
645
|
+
const inputOutput = findExtension(element, "camunda:InputOutput");
|
|
646
|
+
return listProperty(inputOutput, property).filter((parameter) => typeof parameter.name === "string" && parameter.name && !parameter.definition).map((parameter) => ({
|
|
647
|
+
source: typeof parameter.value === "string" ? parameter.value : "",
|
|
648
|
+
target: parameter.name
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const EXPRESSION_PREFIX = "=";
|
|
654
|
+
class ZeebeEngine {
|
|
655
|
+
constructor() {
|
|
656
|
+
this.id = "zeebe";
|
|
657
|
+
this.label = "Zeebe";
|
|
658
|
+
this.expressionLanguage = "FEEL";
|
|
659
|
+
this.taskResultPropagation = "without-output-mappings";
|
|
660
|
+
}
|
|
661
|
+
writeVariable(variables, target, value) {
|
|
662
|
+
return setVariable(variables, target, value);
|
|
663
|
+
}
|
|
664
|
+
readInputMappings(element) {
|
|
665
|
+
return this.readMappings(element, "inputParameters");
|
|
666
|
+
}
|
|
667
|
+
readOutputMappings(element) {
|
|
668
|
+
return this.readMappings(element, "outputParameters");
|
|
669
|
+
}
|
|
670
|
+
readCondition(sequenceFlow) {
|
|
671
|
+
return readConditionExpression(sequenceFlow)?.body?.trim() || void 0;
|
|
672
|
+
}
|
|
673
|
+
canEvaluate(expression) {
|
|
674
|
+
return this.isFeel(expression) && this.parsesAsFeel(expression);
|
|
675
|
+
}
|
|
676
|
+
evaluate(expression, variables) {
|
|
677
|
+
if (!this.isFeel(expression)) {
|
|
678
|
+
return { ok: true, value: expression };
|
|
679
|
+
}
|
|
680
|
+
try {
|
|
681
|
+
const { value, warnings } = feelin.evaluate(this.feelBody(expression), variables);
|
|
682
|
+
const missingVariable = warnings.find((warning) => warning.type === "NO_VARIABLE_FOUND");
|
|
683
|
+
if (value === null && missingVariable) {
|
|
684
|
+
return { ok: false, reason: missingVariable.message };
|
|
685
|
+
}
|
|
686
|
+
return { ok: true, value: this.toVariableValue(value) };
|
|
687
|
+
} catch (error) {
|
|
688
|
+
return { ok: false, reason: `Invalid FEEL: ${error.message}` };
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
readVariableNames(expression) {
|
|
692
|
+
if (!this.isFeel(expression)) return [];
|
|
693
|
+
const body = this.feelBody(expression);
|
|
694
|
+
const read = /* @__PURE__ */ new Set();
|
|
695
|
+
const bound = /* @__PURE__ */ new Set();
|
|
696
|
+
feelin.parseExpression(body, {}, void 0).iterate({
|
|
697
|
+
enter(node) {
|
|
698
|
+
const text = body.slice(node.from, node.to);
|
|
699
|
+
if (node.name === "Name") bound.add(text);
|
|
700
|
+
if (node.name !== "VariableName") return;
|
|
701
|
+
const isCallee = node.node.parent?.name === "FunctionInvocation" && node.node.prevSibling === null;
|
|
702
|
+
if (!isCallee) read.add(text);
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
return [...read].filter((name) => !bound.has(name));
|
|
706
|
+
}
|
|
707
|
+
readMappings(element, property) {
|
|
708
|
+
const ioMapping = findExtension(element, "zeebe:IoMapping");
|
|
709
|
+
return listProperty(ioMapping, property).filter((parameter) => typeof parameter.target === "string" && parameter.target).map((parameter) => ({ source: String(parameter.source ?? ""), target: parameter.target }));
|
|
710
|
+
}
|
|
711
|
+
toVariableValue(value) {
|
|
712
|
+
if (value === void 0) return null;
|
|
713
|
+
return typeof value === "object" && value !== null ? JSON.parse(JSON.stringify(value)) : value;
|
|
714
|
+
}
|
|
715
|
+
parsesAsFeel(expression) {
|
|
716
|
+
try {
|
|
717
|
+
feelin.evaluate(this.feelBody(expression), {});
|
|
718
|
+
return true;
|
|
719
|
+
} catch {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
isFeel(expression) {
|
|
724
|
+
return expression.trimStart().startsWith(EXPRESSION_PREFIX);
|
|
725
|
+
}
|
|
726
|
+
feelBody(expression) {
|
|
727
|
+
return expression.trimStart().slice(EXPRESSION_PREFIX.length);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const zeebeEngine = new ZeebeEngine();
|
|
732
|
+
const camunda7Engine = new Camunda7Engine();
|
|
733
|
+
|
|
734
|
+
class EngineRegistry {
|
|
735
|
+
constructor() {
|
|
736
|
+
this.engines = {
|
|
737
|
+
zeebe: zeebeEngine,
|
|
738
|
+
camunda7: camunda7Engine
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
resolve(engine) {
|
|
742
|
+
if (typeof engine !== "string") return engine;
|
|
743
|
+
const adapter = this.engines[engine];
|
|
744
|
+
if (!adapter) {
|
|
745
|
+
throw new Error(`Unknown engine "${engine}", expected one of: ${Object.keys(this.engines).join(", ")}`);
|
|
746
|
+
}
|
|
747
|
+
return adapter;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
class DataSimulationStore {
|
|
752
|
+
constructor() {
|
|
753
|
+
this.engineLabel = "";
|
|
754
|
+
this.expressionLanguage = "";
|
|
755
|
+
this.scenarios = [];
|
|
756
|
+
this.selectedScenarioId = null;
|
|
757
|
+
this.startVariables = {};
|
|
758
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
759
|
+
this.selectedInstanceId = null;
|
|
760
|
+
this.log = [];
|
|
761
|
+
this.nextLogId = 1;
|
|
762
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
763
|
+
}
|
|
764
|
+
setEngine(label, expressionLanguage) {
|
|
765
|
+
this.engineLabel = label;
|
|
766
|
+
this.expressionLanguage = expressionLanguage;
|
|
767
|
+
this.emit();
|
|
768
|
+
}
|
|
769
|
+
setScenarios(scenarios) {
|
|
770
|
+
this.scenarios = scenarios;
|
|
771
|
+
this.selectScenario(scenarios[0]?.id ?? null);
|
|
772
|
+
}
|
|
773
|
+
selectScenario(scenarioId) {
|
|
774
|
+
const scenario = this.scenarios.find((candidate) => candidate.id === scenarioId);
|
|
775
|
+
this.selectedScenarioId = scenario?.id ?? null;
|
|
776
|
+
this.startVariables = scenario ? structuredClone(scenario.variables) : {};
|
|
777
|
+
this.emit();
|
|
778
|
+
}
|
|
779
|
+
setStartVariables(variables) {
|
|
780
|
+
this.startVariables = structuredClone(variables);
|
|
781
|
+
this.emit();
|
|
782
|
+
}
|
|
783
|
+
startInstance(id, processName) {
|
|
784
|
+
this.instances.set(id, {
|
|
785
|
+
id,
|
|
786
|
+
number: this.instances.size + 1,
|
|
787
|
+
processName,
|
|
788
|
+
scenarioId: this.selectedScenarioId,
|
|
789
|
+
status: "running",
|
|
790
|
+
variables: structuredClone(this.startVariables),
|
|
791
|
+
waiting: []
|
|
792
|
+
});
|
|
793
|
+
this.selectedInstanceId = id;
|
|
794
|
+
this.emit();
|
|
795
|
+
}
|
|
796
|
+
selectInstance(instanceId) {
|
|
797
|
+
if (!this.instances.has(instanceId)) return;
|
|
798
|
+
this.selectedInstanceId = instanceId;
|
|
799
|
+
this.emit();
|
|
800
|
+
}
|
|
801
|
+
completeInstance(id) {
|
|
802
|
+
this.updateInstance(id, (instance) => ({ ...instance, status: "completed", waiting: [] }));
|
|
803
|
+
}
|
|
804
|
+
hasInstance(id) {
|
|
805
|
+
return this.instances.has(id);
|
|
806
|
+
}
|
|
807
|
+
getTaskResult(instanceId, elementId) {
|
|
808
|
+
const scenarioId = this.instances.get(instanceId)?.scenarioId;
|
|
809
|
+
return this.scenarios.find((scenario) => scenario.id === scenarioId)?.taskResults[elementId];
|
|
810
|
+
}
|
|
811
|
+
getVariables(instanceId) {
|
|
812
|
+
return this.instances.get(instanceId)?.variables ?? {};
|
|
813
|
+
}
|
|
814
|
+
setVariables(instanceId, variables) {
|
|
815
|
+
this.updateInstance(instanceId, (instance) => ({ ...instance, variables: structuredClone(variables) }));
|
|
816
|
+
}
|
|
817
|
+
addWaiting(instanceId, waiting) {
|
|
818
|
+
this.updateInstance(instanceId, (instance) => ({ ...instance, waiting: [...instance.waiting, waiting] }));
|
|
819
|
+
}
|
|
820
|
+
removeWaiting(scopeId) {
|
|
821
|
+
const instance = [...this.instances.values()].find(
|
|
822
|
+
(candidate) => candidate.waiting.some((waiting) => waiting.scopeId === scopeId)
|
|
823
|
+
);
|
|
824
|
+
if (!instance) return;
|
|
825
|
+
this.updateInstance(instance.id, (current) => ({
|
|
826
|
+
...current,
|
|
827
|
+
waiting: current.waiting.filter((waiting) => waiting.scopeId !== scopeId)
|
|
828
|
+
}));
|
|
829
|
+
}
|
|
830
|
+
record(entry) {
|
|
831
|
+
this.log = [...this.log, { ...entry, id: this.nextLogId++ }];
|
|
832
|
+
this.emit();
|
|
833
|
+
}
|
|
834
|
+
reset() {
|
|
835
|
+
this.instances.clear();
|
|
836
|
+
this.selectedInstanceId = null;
|
|
837
|
+
this.log = [];
|
|
838
|
+
this.emit();
|
|
839
|
+
}
|
|
840
|
+
getSnapshot() {
|
|
841
|
+
return {
|
|
842
|
+
engineLabel: this.engineLabel,
|
|
843
|
+
expressionLanguage: this.expressionLanguage,
|
|
844
|
+
scenarios: this.scenarios,
|
|
845
|
+
selectedScenarioId: this.selectedScenarioId,
|
|
846
|
+
startVariables: this.startVariables,
|
|
847
|
+
instances: [...this.instances.values()].map((instance) => this.withStatus(instance)),
|
|
848
|
+
selectedInstanceId: this.selectedInstanceId,
|
|
849
|
+
log: this.log
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
subscribe(listener) {
|
|
853
|
+
this.listeners.add(listener);
|
|
854
|
+
return () => this.listeners.delete(listener);
|
|
855
|
+
}
|
|
856
|
+
updateInstance(id, update) {
|
|
857
|
+
const instance = this.instances.get(id);
|
|
858
|
+
if (!instance) return;
|
|
859
|
+
this.instances.set(id, update(instance));
|
|
860
|
+
this.emit();
|
|
861
|
+
}
|
|
862
|
+
emit() {
|
|
863
|
+
const snapshot = this.getSnapshot();
|
|
864
|
+
for (const listener of [...this.listeners]) listener(snapshot);
|
|
865
|
+
}
|
|
866
|
+
withStatus(instance) {
|
|
867
|
+
if (instance.status === "completed") return instance;
|
|
868
|
+
return { ...instance, status: instance.waiting.length ? "waiting" : "running" };
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
function h(tag, attributes = {}, ...children) {
|
|
873
|
+
const element = document.createElement(tag);
|
|
874
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
875
|
+
if (name === "className") element.className = value;
|
|
876
|
+
else element.setAttribute(name, value);
|
|
877
|
+
}
|
|
878
|
+
for (const child of children) {
|
|
879
|
+
if (child) element.append(child);
|
|
880
|
+
}
|
|
881
|
+
return element;
|
|
882
|
+
}
|
|
883
|
+
function formatValue(value) {
|
|
884
|
+
if (value === void 0) return "undefined";
|
|
885
|
+
return JSON.stringify(value) ?? String(value);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
class SimpleStartForm {
|
|
889
|
+
constructor(container, fields, values) {
|
|
890
|
+
this.fields = fields;
|
|
891
|
+
this.codec = new StartFieldCodec();
|
|
892
|
+
this.inputs = /* @__PURE__ */ new Map();
|
|
893
|
+
this.form = h("div", { className: "bds-form" });
|
|
894
|
+
for (const field of fields) {
|
|
895
|
+
const input = this.createInput(field);
|
|
896
|
+
this.inputs.set(field.name, input);
|
|
897
|
+
this.form.append(this.renderField(field, input));
|
|
898
|
+
}
|
|
899
|
+
for (const field of fields)
|
|
900
|
+
this.writeInput(this.inputs.get(field.name), this.codec.format(field, values[field.name]));
|
|
901
|
+
container.append(this.form);
|
|
902
|
+
}
|
|
903
|
+
readValues() {
|
|
904
|
+
const result = {};
|
|
905
|
+
for (const field of this.fields) {
|
|
906
|
+
const input = this.inputs.get(field.name);
|
|
907
|
+
const parsed = this.codec.parse(
|
|
908
|
+
field,
|
|
909
|
+
input.type === "checkbox" ? input.checked : input.value
|
|
910
|
+
);
|
|
911
|
+
if (!parsed.ok) return parsed;
|
|
912
|
+
result[field.name] = parsed.value;
|
|
913
|
+
}
|
|
914
|
+
return { ok: true, values: result };
|
|
915
|
+
}
|
|
916
|
+
focus() {
|
|
917
|
+
this.inputs.values().next().value?.focus();
|
|
918
|
+
}
|
|
919
|
+
destroy() {
|
|
920
|
+
this.form.remove();
|
|
921
|
+
}
|
|
922
|
+
renderField(field, input) {
|
|
923
|
+
const id = `bds-field-${field.name}`;
|
|
924
|
+
input.id = id;
|
|
925
|
+
const hint = h("span", { className: "bds-field-hint" }, `Used by ${field.usedBy.join(", ")}`);
|
|
926
|
+
if (field.type === "boolean") {
|
|
927
|
+
return h(
|
|
928
|
+
"div",
|
|
929
|
+
{ className: "bds-field bds-field--checkbox" },
|
|
930
|
+
h(
|
|
931
|
+
"label",
|
|
932
|
+
{ className: "bds-checkbox", for: id },
|
|
933
|
+
input,
|
|
934
|
+
h("span", { className: "bds-field-name" }, field.name)
|
|
935
|
+
),
|
|
936
|
+
hint
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
return h(
|
|
940
|
+
"div",
|
|
941
|
+
{ className: "bds-field" },
|
|
942
|
+
h("label", { className: "bds-field-name", for: id }, field.name),
|
|
943
|
+
input,
|
|
944
|
+
hint
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
createInput(field) {
|
|
948
|
+
if (field.type === "boolean") return h("input", { type: "checkbox", name: field.name });
|
|
949
|
+
if (field.type === "json") {
|
|
950
|
+
return h("textarea", { className: "bds-input bds-json", name: field.name, rows: "2", spellcheck: "false" });
|
|
951
|
+
}
|
|
952
|
+
const type = field.type === "number" ? "number" : "text";
|
|
953
|
+
return h("input", { className: "bds-input", type, name: field.name, step: "any", autocomplete: "off" });
|
|
954
|
+
}
|
|
955
|
+
writeInput(input, value) {
|
|
956
|
+
if (typeof value === "boolean") input.checked = value;
|
|
957
|
+
else input.value = value;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
class SimpleStartFormRenderer {
|
|
962
|
+
render(container, fields, values) {
|
|
963
|
+
return new SimpleStartForm(container, fields, values);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const FLOW_CHOICE_TYPES = ["bpmn:ExclusiveGateway", "bpmn:InclusiveGateway"];
|
|
968
|
+
const TRIGGER_TYPE = "bpmn:Event";
|
|
969
|
+
class DataContextPads {
|
|
970
|
+
constructor(contextPads, dataGateways, startForm, dataSimulation) {
|
|
971
|
+
this.dataGateways = dataGateways;
|
|
972
|
+
this.startForm = startForm;
|
|
973
|
+
this.dataSimulation = dataSimulation;
|
|
974
|
+
for (const { handler, type } of contextPads._handlers) {
|
|
975
|
+
if (FLOW_CHOICE_TYPES.includes(type)) this.hideOnDataDrivenGateways(handler);
|
|
976
|
+
if (type === TRIGGER_TYPE) this.openStartFormOnProcessStart(handler);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
hideOnDataDrivenGateways(handler) {
|
|
980
|
+
const createContextPads = handler.createContextPads.bind(handler);
|
|
981
|
+
handler.createContextPads = (element) => this.dataGateways.isDataDriven(element) ? void 0 : createContextPads(element);
|
|
982
|
+
}
|
|
983
|
+
openStartFormOnProcessStart(handler) {
|
|
984
|
+
const createContextPads = handler.createContextPads.bind(handler);
|
|
985
|
+
handler.createContextPads = (element) => {
|
|
986
|
+
const pads = createContextPads(element);
|
|
987
|
+
if (!this.dataSimulation.isEnabled() || !this.startForm.isProcessStart(element)) return pads;
|
|
988
|
+
return [].concat(pads).map(
|
|
989
|
+
(pad) => pad?.action ? { ...pad, action: (contexts) => this.startForm.open(element, () => pad.action(contexts)) } : pad
|
|
990
|
+
);
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
DataContextPads.$inject = ["contextPads", "dataGateways", "dataStartForm", "dataSimulation"];
|
|
995
|
+
|
|
996
|
+
class DataGatewayBehaviors {
|
|
997
|
+
constructor(exclusive, inclusive, dataGateways) {
|
|
998
|
+
this.dataGateways = dataGateways;
|
|
999
|
+
this.routeByData(exclusive, "exclusive");
|
|
1000
|
+
this.routeByData(inclusive, "inclusive");
|
|
1001
|
+
}
|
|
1002
|
+
routeByData(behavior, kind) {
|
|
1003
|
+
const exitByClick = behavior.exit.bind(behavior);
|
|
1004
|
+
behavior.exit = (context) => {
|
|
1005
|
+
if (this.dataGateways.isDataDriven(context.element)) {
|
|
1006
|
+
this.dataGateways.exit(context, kind);
|
|
1007
|
+
} else {
|
|
1008
|
+
this.dataGateways.recordClickDecision(context, kind);
|
|
1009
|
+
exitByClick(context);
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
DataGatewayBehaviors.$inject = ["exclusiveGatewayBehavior", "inclusiveGatewayBehavior", "dataGateways"];
|
|
1015
|
+
|
|
1016
|
+
class DataGatewaySettings {
|
|
1017
|
+
constructor(exclusive, inclusive, dataGateways) {
|
|
1018
|
+
this.dataGateways = dataGateways;
|
|
1019
|
+
exclusive.setSequenceFlow = this.onlyForClickGateways(exclusive.setSequenceFlow.bind(exclusive));
|
|
1020
|
+
inclusive._setGatewayDefaults = this.onlyForClickGateways(inclusive._setGatewayDefaults.bind(inclusive));
|
|
1021
|
+
inclusive.toggleSequenceFlow = this.onlyForClickGateways(inclusive.toggleSequenceFlow.bind(inclusive));
|
|
1022
|
+
}
|
|
1023
|
+
onlyForClickGateways(method) {
|
|
1024
|
+
return (gateway, ...rest) => {
|
|
1025
|
+
if (!this.dataGateways.isDataDriven(gateway)) method(gateway, ...rest);
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
DataGatewaySettings.$inject = ["exclusiveGatewaySettings", "inclusiveGatewaySettings", "dataGateways"];
|
|
1030
|
+
|
|
1031
|
+
function findProcessInstance(scope) {
|
|
1032
|
+
let current = scope;
|
|
1033
|
+
while (current.parent) current = current.parent;
|
|
1034
|
+
return current;
|
|
1035
|
+
}
|
|
1036
|
+
function elementName(element) {
|
|
1037
|
+
const name = element.businessObject.name;
|
|
1038
|
+
return typeof name === "string" && name.trim() ? name.trim() : element.id;
|
|
1039
|
+
}
|
|
1040
|
+
function is(element, type) {
|
|
1041
|
+
const businessObject = element.businessObject;
|
|
1042
|
+
return typeof businessObject?.$instanceOf === "function" && businessObject.$instanceOf(type);
|
|
1043
|
+
}
|
|
1044
|
+
function isGateway(element) {
|
|
1045
|
+
return element.type === "bpmn:ExclusiveGateway" || element.type === "bpmn:InclusiveGateway";
|
|
1046
|
+
}
|
|
1047
|
+
function gatewayOf(element) {
|
|
1048
|
+
if (isGateway(element)) return element.id;
|
|
1049
|
+
if (element.type === "bpmn:SequenceFlow" && element.source && isGateway(element.source)) return element.source.id;
|
|
1050
|
+
return void 0;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
class DataGateways {
|
|
1054
|
+
constructor(dataSimulation, store, simulator) {
|
|
1055
|
+
this.dataSimulation = dataSimulation;
|
|
1056
|
+
this.store = store;
|
|
1057
|
+
this.simulator = simulator;
|
|
1058
|
+
this.router = new GatewayRouter();
|
|
1059
|
+
}
|
|
1060
|
+
isDataDriven(gateway) {
|
|
1061
|
+
const engine = this.dataSimulation.getEngine();
|
|
1062
|
+
const outgoing = this.outgoingFlows(gateway);
|
|
1063
|
+
return this.dataSimulation.isEnabled() && outgoing.length > 1 && outgoing.filter((flow) => !flow.isDefault).every((flow) => flow.expression !== void 0 && engine.canEvaluate(flow.expression));
|
|
1064
|
+
}
|
|
1065
|
+
exit(context, kind) {
|
|
1066
|
+
const { element: gateway, scope } = context;
|
|
1067
|
+
const decision = this.decide(gateway, scope, kind);
|
|
1068
|
+
if (decision.stuckReason) {
|
|
1069
|
+
this.waitForRetry(gateway, scope);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
for (const flowId of decision.takenFlowIds) {
|
|
1073
|
+
const flow = this.sequenceFlows(gateway).find((candidate) => candidate.id === flowId);
|
|
1074
|
+
this.simulator.enter({ element: flow, scope: scope.parent });
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
recordClickDecision(context, kind) {
|
|
1078
|
+
if (!this.dataSimulation.isEnabled()) return;
|
|
1079
|
+
const { element: gateway, scope } = context;
|
|
1080
|
+
const { activeOutgoing } = this.simulator.getConfig(gateway);
|
|
1081
|
+
const chosen = [].concat(activeOutgoing ?? []);
|
|
1082
|
+
const outgoing = this.outgoingFlows(gateway);
|
|
1083
|
+
if (outgoing.length < 2 || !chosen.length) return;
|
|
1084
|
+
const flows = outgoing.map(
|
|
1085
|
+
(flow) => chosen.some((candidate) => candidate.id === flow.id) ? { flow, outcome: "taken", reason: "Chosen by click" } : { flow, outcome: "skipped", reason: "Not chosen by click" }
|
|
1086
|
+
);
|
|
1087
|
+
const decision = {
|
|
1088
|
+
flows,
|
|
1089
|
+
takenFlowIds: flows.filter((flow) => flow.outcome === "taken").map((flow) => flow.flow.id)
|
|
1090
|
+
};
|
|
1091
|
+
this.record(gateway, scope, kind, "click", decision, []);
|
|
1092
|
+
}
|
|
1093
|
+
decide(gateway, scope, kind) {
|
|
1094
|
+
const engine = this.dataSimulation.getEngine();
|
|
1095
|
+
const variables = this.dataSimulation.getVariables(scope);
|
|
1096
|
+
const outgoing = this.outgoingFlows(gateway);
|
|
1097
|
+
const decision = this.router.route(kind, outgoing, (expression) => engine.evaluate(expression, variables));
|
|
1098
|
+
const names = outgoing.flatMap((flow) => flow.expression ? engine.readVariableNames(flow.expression) : []);
|
|
1099
|
+
const inputs = [...new Set(names)].map((name) => ({ name, value: structuredClone(variables[name]) }));
|
|
1100
|
+
this.record(gateway, scope, kind, "data", decision, inputs);
|
|
1101
|
+
return decision;
|
|
1102
|
+
}
|
|
1103
|
+
record(gateway, scope, gatewayKind, chosenBy, decision, inputs) {
|
|
1104
|
+
this.store.record({
|
|
1105
|
+
kind: "decision",
|
|
1106
|
+
instanceId: findProcessInstance(scope).id,
|
|
1107
|
+
elementId: gateway.id,
|
|
1108
|
+
elementName: elementName(gateway),
|
|
1109
|
+
gatewayKind,
|
|
1110
|
+
chosenBy,
|
|
1111
|
+
decision,
|
|
1112
|
+
inputs
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
waitForRetry(gateway, scope) {
|
|
1116
|
+
const waitingScope = this.simulator.createScope({ element: gateway, parent: scope.parent, initiator: scope }).start();
|
|
1117
|
+
this.store.addWaiting(findProcessInstance(scope).id, {
|
|
1118
|
+
scopeId: waitingScope.id,
|
|
1119
|
+
gatewayId: gateway.id,
|
|
1120
|
+
gatewayName: elementName(gateway)
|
|
1121
|
+
});
|
|
1122
|
+
const retry = { element: gateway, type: "continue", interrupting: false, boundary: false };
|
|
1123
|
+
const subscription = this.simulator.subscribe(waitingScope, retry, (initiator) => {
|
|
1124
|
+
subscription.remove();
|
|
1125
|
+
this.store.removeWaiting(waitingScope.id);
|
|
1126
|
+
this.simulator.exit({ element: gateway, scope: waitingScope, initiator });
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
outgoingFlows(gateway) {
|
|
1130
|
+
const engine = this.dataSimulation.getEngine();
|
|
1131
|
+
const defaultFlow = gateway.businessObject.default;
|
|
1132
|
+
return this.sequenceFlows(gateway).map((flow) => {
|
|
1133
|
+
const name = flow.businessObject.name;
|
|
1134
|
+
return {
|
|
1135
|
+
id: flow.id,
|
|
1136
|
+
...typeof name === "string" && name ? { name } : {},
|
|
1137
|
+
expression: engine.readCondition(flow.businessObject),
|
|
1138
|
+
isDefault: flow.businessObject === defaultFlow
|
|
1139
|
+
};
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
sequenceFlows(gateway) {
|
|
1143
|
+
return (gateway.outgoing ?? []).filter((flow) => is(flow, "bpmn:SequenceFlow"));
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
DataGateways.$inject = ["dataSimulation", "dataSimulationStore", "simulator"];
|
|
1147
|
+
|
|
1148
|
+
class IoMappings {
|
|
1149
|
+
constructor(engine, store) {
|
|
1150
|
+
this.engine = engine;
|
|
1151
|
+
this.store = store;
|
|
1152
|
+
}
|
|
1153
|
+
apply(element, instanceId) {
|
|
1154
|
+
const inputs = this.engine.readInputMappings(element.businessObject);
|
|
1155
|
+
const outputs = this.engine.readOutputMappings(element.businessObject);
|
|
1156
|
+
const taskResult = this.store.getTaskResult(instanceId, element.id);
|
|
1157
|
+
if (!inputs.length && !outputs.length && !taskResult) return;
|
|
1158
|
+
const processVariables = this.store.getVariables(instanceId);
|
|
1159
|
+
const localVariables = this.evaluate(element, instanceId, inputs, {}, (current) => ({
|
|
1160
|
+
...processVariables,
|
|
1161
|
+
...current
|
|
1162
|
+
}));
|
|
1163
|
+
const context = { ...processVariables, ...localVariables, ...taskResult };
|
|
1164
|
+
const propagatesTaskResult = taskResult && (this.engine.taskResultPropagation === "always" || !outputs.length);
|
|
1165
|
+
const withTaskResult = propagatesTaskResult ? { ...processVariables, ...withoutKeys(taskResult, Object.keys(localVariables)) } : processVariables;
|
|
1166
|
+
this.store.setVariables(
|
|
1167
|
+
instanceId,
|
|
1168
|
+
this.evaluate(element, instanceId, outputs, withTaskResult, () => context)
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
evaluate(element, instanceId, mappings, target, contextOf) {
|
|
1172
|
+
let result = target;
|
|
1173
|
+
for (const mapping of mappings) {
|
|
1174
|
+
const evaluation = this.engine.evaluate(mapping.source, contextOf(result));
|
|
1175
|
+
if (evaluation.ok) {
|
|
1176
|
+
result = this.engine.writeVariable(result, mapping.target, evaluation.value);
|
|
1177
|
+
} else {
|
|
1178
|
+
this.store.record({
|
|
1179
|
+
kind: "mapping-issue",
|
|
1180
|
+
instanceId,
|
|
1181
|
+
elementId: element.id,
|
|
1182
|
+
elementName: elementName(element),
|
|
1183
|
+
target: mapping.target,
|
|
1184
|
+
reason: evaluation.reason
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return result;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
const TOGGLE_MODE_EVENT = "tokenSimulation.toggleMode";
|
|
1193
|
+
const RESET_SIMULATION_EVENT = "tokenSimulation.resetSimulation";
|
|
1194
|
+
const SCOPE_CREATE_EVENT = "tokenSimulation.simulator.createScope";
|
|
1195
|
+
const SCOPE_DESTROYED_EVENT = "tokenSimulation.simulator.destroyScope";
|
|
1196
|
+
const TRACE_EVENT = "tokenSimulation.simulator.trace";
|
|
1197
|
+
const DATA_TOGGLE_EVENT = "dataSimulation.toggle";
|
|
1198
|
+
|
|
1199
|
+
class DataSimulation {
|
|
1200
|
+
constructor(config, eventBus, store) {
|
|
1201
|
+
this.eventBus = eventBus;
|
|
1202
|
+
this.store = store;
|
|
1203
|
+
this.scenarioParser = new ScenarioParser();
|
|
1204
|
+
this.engine = new EngineRegistry().resolve(config?.engine ?? "zeebe");
|
|
1205
|
+
this.ioMappings = new IoMappings(this.engine, store);
|
|
1206
|
+
this.enabled = config?.enabled ?? true;
|
|
1207
|
+
this.store.setEngine(this.engine.label, this.engine.expressionLanguage);
|
|
1208
|
+
if (config?.scenarios !== void 0) this.setScenarios(config.scenarios);
|
|
1209
|
+
eventBus.on(SCOPE_CREATE_EVENT, ({ scope }) => this.onScopeCreated(scope));
|
|
1210
|
+
eventBus.on(SCOPE_DESTROYED_EVENT, ({ scope }) => {
|
|
1211
|
+
this.store.completeInstance(scope.id);
|
|
1212
|
+
this.store.removeWaiting(scope.id);
|
|
1213
|
+
});
|
|
1214
|
+
eventBus.on(TRACE_EVENT, (event) => {
|
|
1215
|
+
if (event.action === "exit") this.applyMappings(event.element, event.scope);
|
|
1216
|
+
});
|
|
1217
|
+
eventBus.on([RESET_SIMULATION_EVENT, TOGGLE_MODE_EVENT], () => this.store.reset());
|
|
1218
|
+
}
|
|
1219
|
+
getEngine() {
|
|
1220
|
+
return this.engine;
|
|
1221
|
+
}
|
|
1222
|
+
isEnabled() {
|
|
1223
|
+
return this.enabled;
|
|
1224
|
+
}
|
|
1225
|
+
setEnabled(enabled) {
|
|
1226
|
+
if (enabled === this.enabled) return;
|
|
1227
|
+
this.enabled = enabled;
|
|
1228
|
+
this.store.reset();
|
|
1229
|
+
this.eventBus.fire(DATA_TOGGLE_EVENT, { enabled });
|
|
1230
|
+
}
|
|
1231
|
+
setScenarios(input) {
|
|
1232
|
+
this.store.setScenarios(this.scenarioParser.parse(input));
|
|
1233
|
+
}
|
|
1234
|
+
selectScenario(scenarioId) {
|
|
1235
|
+
this.store.selectScenario(scenarioId);
|
|
1236
|
+
}
|
|
1237
|
+
setStartVariables(variables) {
|
|
1238
|
+
this.store.setStartVariables(variables);
|
|
1239
|
+
}
|
|
1240
|
+
selectInstance(instanceId) {
|
|
1241
|
+
this.store.selectInstance(instanceId);
|
|
1242
|
+
}
|
|
1243
|
+
setInstanceVariables(instanceId, variables) {
|
|
1244
|
+
this.store.setVariables(instanceId, variables);
|
|
1245
|
+
}
|
|
1246
|
+
getVariables(scope) {
|
|
1247
|
+
return this.store.getVariables(findProcessInstance(scope).id);
|
|
1248
|
+
}
|
|
1249
|
+
getSnapshot() {
|
|
1250
|
+
return this.store.getSnapshot();
|
|
1251
|
+
}
|
|
1252
|
+
subscribe(listener) {
|
|
1253
|
+
return this.store.subscribe(listener);
|
|
1254
|
+
}
|
|
1255
|
+
onScopeCreated(scope) {
|
|
1256
|
+
if (!this.enabled || scope.parent || !is(scope.element, "bpmn:Process") && !is(scope.element, "bpmn:Participant"))
|
|
1257
|
+
return;
|
|
1258
|
+
this.store.startInstance(scope.id, elementName(scope.element));
|
|
1259
|
+
}
|
|
1260
|
+
applyMappings(element, scope) {
|
|
1261
|
+
if (!is(element, "bpmn:FlowNode") || scope.failed || scope.canceled) return;
|
|
1262
|
+
const instanceId = findProcessInstance(scope).id;
|
|
1263
|
+
if (this.store.hasInstance(instanceId)) this.ioMappings.apply(element, instanceId);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
DataSimulation.$inject = ["config.dataSimulation", "eventBus", "dataSimulationStore"];
|
|
1267
|
+
|
|
1268
|
+
class GatewayDecisionView {
|
|
1269
|
+
constructor(snapshot) {
|
|
1270
|
+
this.snapshot = snapshot;
|
|
1271
|
+
this.decisions = this.latestDecisionPerGateway();
|
|
1272
|
+
const shownPerGateway = new Map(this.decisions.map((entry) => [entry.elementId, entry]));
|
|
1273
|
+
for (const entry of this.latestStuckDecisionPerGateway()) shownPerGateway.set(entry.elementId, entry);
|
|
1274
|
+
this.shown = [...shownPerGateway.values()];
|
|
1275
|
+
}
|
|
1276
|
+
latestDecisionPerGateway() {
|
|
1277
|
+
const { log, selectedInstanceId } = this.snapshot;
|
|
1278
|
+
const latest = /* @__PURE__ */ new Map();
|
|
1279
|
+
for (const entry of log) {
|
|
1280
|
+
if (entry.kind === "decision" && entry.instanceId === selectedInstanceId) latest.set(entry.elementId, entry);
|
|
1281
|
+
}
|
|
1282
|
+
return [...latest.values()];
|
|
1283
|
+
}
|
|
1284
|
+
latestStuckDecisionPerGateway() {
|
|
1285
|
+
const { instances, log } = this.snapshot;
|
|
1286
|
+
const latest = /* @__PURE__ */ new Map();
|
|
1287
|
+
for (const instance of instances) {
|
|
1288
|
+
for (const { gatewayId } of instance.waiting) {
|
|
1289
|
+
const decision = [...log].reverse().find(
|
|
1290
|
+
(entry) => entry.kind === "decision" && entry.instanceId === instance.id && entry.elementId === gatewayId
|
|
1291
|
+
);
|
|
1292
|
+
if (decision && (latest.get(gatewayId)?.id ?? 0) < decision.id) latest.set(gatewayId, decision);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
return [...latest.values()];
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
const OUTCOME_LABELS = {
|
|
1300
|
+
taken: { symbol: "\u2713", title: "Taken" },
|
|
1301
|
+
"not-taken": { symbol: "\u2717", title: "Condition is false" },
|
|
1302
|
+
error: { symbol: "!", title: "Condition could not be evaluated" },
|
|
1303
|
+
skipped: { symbol: "\u2013", title: "Not evaluated" }
|
|
1304
|
+
};
|
|
1305
|
+
const DEFAULT_FLOW_TITLES = {
|
|
1306
|
+
taken: "Default flow taken, no condition is true",
|
|
1307
|
+
"not-taken": "Default flow not needed"
|
|
1308
|
+
};
|
|
1309
|
+
class OutcomeBadge {
|
|
1310
|
+
constructor(outcome, detail, isDefault = false) {
|
|
1311
|
+
this.element = document.createElement("span");
|
|
1312
|
+
const title = isDefault && DEFAULT_FLOW_TITLES[outcome] || OUTCOME_LABELS[outcome].title;
|
|
1313
|
+
this.element.className = `bds-outcome bds-outcome--${outcome}`;
|
|
1314
|
+
this.element.textContent = OUTCOME_LABELS[outcome].symbol;
|
|
1315
|
+
this.element.title = detail ? `${title}: ${detail}` : title;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
class DecisionCard {
|
|
1320
|
+
constructor({ elementName, gatewayKind, chosenBy, decision, inputs }, onClose) {
|
|
1321
|
+
this.element = h(
|
|
1322
|
+
"div",
|
|
1323
|
+
{ className: `bds-decision${decision.stuckReason ? " bds-decision--stuck" : ""}`, role: "note" },
|
|
1324
|
+
h(
|
|
1325
|
+
"div",
|
|
1326
|
+
{ className: "bds-decision-title" },
|
|
1327
|
+
h("span", {}, elementName),
|
|
1328
|
+
h("span", { className: "bds-tag" }, chosenBy === "click" ? `${gatewayKind} \xB7 by click` : gatewayKind),
|
|
1329
|
+
onClose ? this.closeButton(onClose) : null
|
|
1330
|
+
),
|
|
1331
|
+
decision.stuckReason ? h(
|
|
1332
|
+
"p",
|
|
1333
|
+
{ className: "bds-error" },
|
|
1334
|
+
`${decision.stuckReason}. Change the variables in Process Data, then press \u25B6 on the gateway.`
|
|
1335
|
+
) : null,
|
|
1336
|
+
h(
|
|
1337
|
+
"ul",
|
|
1338
|
+
{ className: "bds-flows" },
|
|
1339
|
+
...decision.flows.map(
|
|
1340
|
+
({ flow, outcome, reason }) => h(
|
|
1341
|
+
"li",
|
|
1342
|
+
{ className: `bds-flow bds-flow--${outcome}` },
|
|
1343
|
+
new OutcomeBadge(outcome, reason, flow.isDefault).element,
|
|
1344
|
+
h("span", { className: "bds-flow-name" }, flow.name ?? flow.id),
|
|
1345
|
+
flow.isDefault ? h("span", { className: "bds-tag" }, "default") : flow.expression && h("code", {}, flow.expression)
|
|
1346
|
+
)
|
|
1347
|
+
)
|
|
1348
|
+
),
|
|
1349
|
+
inputs.length ? this.inputList(inputs) : null
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
closeButton(onClose) {
|
|
1353
|
+
const button = h(
|
|
1354
|
+
"button",
|
|
1355
|
+
{ className: "bds-icon-button bds-decision-close", type: "button", "aria-label": "Close" },
|
|
1356
|
+
"\xD7"
|
|
1357
|
+
);
|
|
1358
|
+
button.addEventListener("click", onClose);
|
|
1359
|
+
return button;
|
|
1360
|
+
}
|
|
1361
|
+
inputList(inputs) {
|
|
1362
|
+
return h(
|
|
1363
|
+
"dl",
|
|
1364
|
+
{ className: "bds-decision-inputs" },
|
|
1365
|
+
...inputs.flatMap(({ name, value }) => [
|
|
1366
|
+
h("dt", {}, name),
|
|
1367
|
+
h(
|
|
1368
|
+
"dd",
|
|
1369
|
+
{},
|
|
1370
|
+
value === void 0 ? h("span", { className: "bds-hint" }, "not set") : h("code", {}, formatValue(value))
|
|
1371
|
+
)
|
|
1372
|
+
])
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
function badgePosition(waypoints, distanceFromStart) {
|
|
1378
|
+
const [start, next] = waypoints;
|
|
1379
|
+
const length = Math.hypot(next.x - start.x, next.y - start.y) || 1;
|
|
1380
|
+
const distance = Math.min(distanceFromStart, length / 2);
|
|
1381
|
+
const x = start.x + (next.x - start.x) / length * distance;
|
|
1382
|
+
const y = start.y + (next.y - start.y) / length * distance;
|
|
1383
|
+
const minX = Math.min(...waypoints.map((point) => point.x));
|
|
1384
|
+
const minY = Math.min(...waypoints.map((point) => point.y));
|
|
1385
|
+
return { left: x - minX, top: y - minY };
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
const GAP$1 = 12;
|
|
1389
|
+
const MARGIN = 8;
|
|
1390
|
+
function placePopover(anchor, popover, bounds) {
|
|
1391
|
+
const below = anchor.y + anchor.height + GAP$1;
|
|
1392
|
+
const above = anchor.y - GAP$1 - popover.height;
|
|
1393
|
+
const fitsBelow = below + popover.height <= bounds.height - MARGIN;
|
|
1394
|
+
const fitsAbove = above >= MARGIN;
|
|
1395
|
+
const height = Math.min(popover.height, bounds.height - 2 * MARGIN);
|
|
1396
|
+
return {
|
|
1397
|
+
left: clamp(anchor.x + anchor.width / 2 - popover.width / 2, MARGIN, bounds.width - popover.width - MARGIN),
|
|
1398
|
+
top: fitsBelow ? below : fitsAbove ? above : clamp(below, MARGIN, bounds.height - height - MARGIN),
|
|
1399
|
+
maxHeight: height < popover.height ? height : void 0,
|
|
1400
|
+
hidden: !isInView(anchor, bounds)
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
function clamp(value, min, max) {
|
|
1404
|
+
return Math.max(min, Math.min(value, max));
|
|
1405
|
+
}
|
|
1406
|
+
function isInView(anchor, bounds) {
|
|
1407
|
+
return anchor.x + anchor.width > 0 && anchor.x < bounds.width && anchor.y + anchor.height > 0 && anchor.y < bounds.height;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
var componentStyles = ":host {\n all: initial;\n display: contents;\n}\n\n.bds-panel {\n position: absolute;\n top: 30%;\n right: 20px;\n bottom: 50px;\n z-index: 10000;\n display: flex;\n flex-direction: column;\n width: 300px;\n overflow: hidden;\n font-family: var(--bds-font);\n font-size: 13px;\n color: var(--bds-ink);\n background: var(--token-simulation-control-background, #f1f2f4);\n border-radius: var(--surface-border-radius, 4px);\n}\n\n.bds-panel[hidden] {\n display: none;\n}\n\n.bds-panel-header {\n display: flex;\n flex: 0 0 auto;\n align-items: center;\n gap: var(--bds-space-2);\n box-sizing: border-box;\n height: 30px;\n padding: 6px 8px;\n font-size: 16px;\n color: var(--token-simulation-control-surface, #fff);\n background: var(--token-simulation-primary, #0067cc);\n}\n\n.bds-panel-heading {\n flex: 1;\n margin: 0;\n font: inherit;\n text-align: center;\n}\n\n.bds-panel-close {\n display: inline-flex;\n align-items: center;\n padding: 0;\n color: inherit;\n background: none;\n border: none;\n cursor: pointer;\n}\n\n.bds-variables-icon svg,\n.bds-panel-close svg {\n width: 1em;\n height: 1em;\n fill: none;\n stroke: currentColor;\n stroke-width: 1.6;\n stroke-linecap: round;\n stroke-linejoin: round;\n}\n\n.bds-variables-icon {\n display: inline-flex;\n align-items: center;\n}\n\n.bds-panel-body {\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: var(--bds-space-2);\n margin: 7px 3px 7px 12px;\n padding: 5px 9px 5px 0;\n overflow-y: auto;\n}\n\n.bds-panel-engine {\n margin: 0;\n}\n\n.bds-panel .bds-section {\n padding: var(--bds-space-2);\n background: var(--token-simulation-control-surface, #fff);\n border-radius: var(--surface-border-radius, 4px);\n}\n\n.bds-panel-title {\n margin: 0;\n font-size: 14px;\n font-weight: 600;\n}\n\n.bds-engine {\n padding: 2px 8px;\n font-size: 11px;\n font-weight: 600;\n color: var(--bds-accent-ink);\n background: var(--bds-accent-soft);\n border-radius: var(--bds-radius-pill);\n}\n\n.bds-icon-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n margin-left: auto;\n width: 26px;\n height: 26px;\n padding: 0;\n color: var(--bds-muted);\n background: transparent;\n border: 1px solid transparent;\n border-radius: var(--bds-radius-sm);\n cursor: pointer;\n}\n\n.bds-icon-button svg {\n width: 16px;\n height: 16px;\n fill: none;\n stroke: currentColor;\n stroke-width: 1.5;\n stroke-linecap: round;\n stroke-linejoin: round;\n transition: transform var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-icon-button:hover {\n color: var(--bds-accent-ink);\n background: var(--bds-accent-soft);\n}\n\n.bds-section {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n}\n\n.bds-section[hidden] {\n display: none;\n}\n\n.bds-section-title,\n.bds-label {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n margin: 0;\n font-size: 12px;\n font-weight: 600;\n letter-spacing: 0.01em;\n color: var(--bds-muted);\n}\n\n.bds-section-title {\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n}\n\n.bds-hint {\n margin: 0;\n font-size: 12px;\n color: var(--bds-muted);\n}\n\n.bds-hint[hidden],\n.bds-error[hidden] {\n display: none;\n}\n\n.bds-error {\n margin: 0;\n font-size: 12px;\n color: var(--bds-danger);\n}\n\n.bds-input {\n box-sizing: border-box;\n width: 100%;\n padding: 6px 10px;\n font-family: inherit;\n font-size: 13px;\n font-weight: 400;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n transition:\n border-color var(--bds-motion-fast) var(--bds-ease),\n box-shadow var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-input:focus,\n.bds-input:focus-visible {\n outline: none;\n border-color: var(--bds-accent);\n box-shadow: 0 0 0 3px var(--bds-accent-soft);\n}\n\n.bds-input--invalid,\n.bds-input--invalid:focus {\n border-color: var(--bds-danger);\n box-shadow: 0 0 0 3px var(--bds-danger-soft);\n}\n\n.bds-json {\n min-height: 72px;\n font-family: var(--bds-font-mono);\n font-size: 12px;\n line-height: 1.5;\n resize: vertical;\n}\n\n.bds-instance-select[hidden] {\n display: none;\n}\n\n.bds-instance-select {\n padding: 4px 8px;\n font-size: 12px;\n}\n\n.bds-actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--bds-space-2);\n margin-top: var(--bds-space-2);\n}\n\n.bds-button {\n padding: 5px 12px;\n font-family: inherit;\n font-size: 12px;\n font-weight: 600;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n box-shadow: var(--bds-shadow-1);\n cursor: pointer;\n transition:\n background var(--bds-motion-fast) var(--bds-ease),\n border-color var(--bds-motion-fast) var(--bds-ease),\n color var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-button:hover {\n color: var(--bds-accent-ink);\n border-color: var(--bds-accent);\n background: var(--bds-accent-soft);\n}\n\n.bds-button--primary {\n color: var(--bds-on-accent);\n background: var(--bds-accent);\n border-color: var(--bds-accent);\n}\n\n.bds-button--primary:hover {\n color: var(--bds-on-accent);\n background: var(--bds-accent-ink);\n}\n\n.bds-button:focus-visible,\n.bds-icon-button:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px var(--bds-accent-soft);\n}\n\n.bds-status {\n margin: 0 0 var(--bds-space-1);\n font-size: 12px;\n font-weight: 600;\n}\n\n.bds-status--running {\n color: var(--bds-accent-ink);\n}\n\n.bds-status--completed {\n color: var(--bds-success);\n}\n\n.bds-status--waiting {\n color: var(--bds-danger);\n}\n\n.bds-variables {\n width: 100%;\n border-collapse: collapse;\n}\n\n.bds-variables th,\n.bds-variables td {\n padding: 4px 0;\n text-align: left;\n vertical-align: top;\n border-bottom: 1px solid var(--bds-line);\n}\n\n.bds-variables tr:last-child th,\n.bds-variables tr:last-child td {\n border-bottom: none;\n}\n\n.bds-variables th {\n width: 1%;\n padding-right: var(--bds-space-3);\n font-weight: 500;\n white-space: nowrap;\n}\n\n.bds-variables code,\n.bds-flow code {\n font-family: var(--bds-font-mono);\n font-size: 12px;\n overflow-wrap: anywhere;\n}\n\n.bds-log {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-2);\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.bds-log-entry {\n padding: var(--bds-space-2);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n}\n\n.bds-log-entry--issue {\n border-color: var(--bds-danger-soft);\n background: linear-gradient(var(--bds-danger-soft), var(--bds-danger-soft)), var(--bds-surface);\n}\n\n.bds-log-title {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--bds-space-2);\n margin-bottom: var(--bds-space-1);\n font-weight: 600;\n}\n\n.bds-tag {\n padding: 1px 6px;\n font-size: 11px;\n font-weight: 500;\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n border-radius: var(--bds-radius-pill);\n}\n\n.bds-flows {\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.bds-flow {\n display: grid;\n grid-template-columns: 18px 1fr;\n align-items: center;\n column-gap: var(--bds-space-2);\n row-gap: 2px;\n}\n\n.bds-flow code,\n.bds-flow .bds-tag {\n grid-column: 2;\n justify-self: start;\n}\n\n.bds-flow code {\n padding: 1px 4px;\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n border-radius: 4px;\n}\n\n.bds-flow--skipped,\n.bds-flow--not-taken {\n color: var(--bds-muted);\n}\n\n.bds-outcome {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: 18px;\n height: 18px;\n font-family: var(--bds-font);\n font-size: 11px;\n font-weight: 700;\n line-height: 1;\n border-radius: var(--bds-radius-pill);\n border: 1px solid transparent;\n cursor: default;\n}\n\n.bds-outcome--taken {\n color: var(--bds-on-accent);\n background: var(--bds-success);\n}\n\n.bds-outcome--not-taken {\n color: var(--bds-muted);\n background: var(--bds-surface);\n border-color: var(--bds-line);\n}\n\n.bds-outcome--error {\n color: var(--bds-on-accent);\n background: var(--bds-danger);\n}\n\n.bds-outcome--skipped {\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n}\n\n.bds-outcome--on-flow {\n display: flex;\n box-shadow: var(--bds-shadow-1);\n transform: translate(-50%, -50%);\n}\n\n.bds-popover {\n position: absolute;\n z-index: 100;\n overflow-y: auto;\n}\n\n.bds-popover[hidden] {\n display: none;\n}\n\n.bds-decision {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-2);\n box-sizing: border-box;\n width: 300px;\n padding: 12px;\n font-family: var(--bds-font);\n font-size: 12px;\n line-height: 1.4;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-md);\n box-shadow: var(--bds-shadow-3);\n}\n\n.bds-decision--stuck {\n border-color: var(--bds-danger);\n}\n\n.bds-decision-title {\n display: flex;\n align-items: center;\n gap: var(--bds-space-2);\n font-size: 13px;\n font-weight: 600;\n}\n\n.bds-decision-title .bds-tag {\n margin-left: auto;\n}\n\n.bds-decision-close {\n margin-left: 0;\n width: 22px;\n height: 22px;\n font-size: 16px;\n line-height: 1;\n}\n\n.bds-decision-inputs {\n display: grid;\n grid-template-columns: auto 1fr;\n gap: 2px var(--bds-space-3);\n margin: 0;\n padding-top: var(--bds-space-2);\n border-top: 1px solid var(--bds-line);\n}\n\n.bds-decision-inputs dt {\n font-family: var(--bds-font-mono);\n color: var(--bds-muted);\n}\n\n.bds-decision-inputs dd {\n margin: 0;\n overflow-wrap: anywhere;\n}\n\n.bds-decision-inputs code {\n font-family: var(--bds-font-mono);\n}\n\n.bds-dialog-backdrop {\n position: fixed;\n inset: 0;\n z-index: 10010;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: var(--bds-space-3);\n background: rgba(29, 29, 29, 0.24);\n}\n\n.bds-dialog {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-3);\n box-sizing: border-box;\n width: 420px;\n max-width: 100%;\n max-height: 100%;\n margin: 0;\n padding: 20px;\n font-family: var(--bds-font);\n font-size: 13px;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-lg);\n box-shadow: var(--bds-shadow-3);\n}\n\n.bds-dialog-content {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-3);\n min-height: 0;\n overflow-y: auto;\n}\n\n.bds-dialog-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--bds-space-2);\n}\n\n.bds-dialog .bds-actions {\n margin-top: 0;\n}\n\n.bds-form {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.bds-field {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n}\n\n.bds-field-name {\n font-family: var(--bds-font-mono);\n font-size: 12px;\n font-weight: 600;\n}\n\n.bds-field-hint {\n font-size: 11px;\n color: var(--bds-muted);\n}\n\n.bds-checkbox {\n display: inline-flex;\n align-items: center;\n gap: var(--bds-space-2);\n cursor: pointer;\n}\n\n.bds-checkbox input {\n width: 16px;\n height: 16px;\n margin: 0;\n accent-color: var(--bds-accent);\n}\n\n@media (prefers-reduced-motion: reduce) {\n * {\n transition-duration: 0.001ms !important;\n }\n}\n\n.bds-form .bds-json {\n min-height: 0;\n}\n";
|
|
1411
|
+
|
|
1412
|
+
let sharedSheet;
|
|
1413
|
+
function inShadow(...children) {
|
|
1414
|
+
const host = h("div", { className: "bds-host" });
|
|
1415
|
+
const root = host.attachShadow({ mode: "open" });
|
|
1416
|
+
adoptComponentStyles(root);
|
|
1417
|
+
root.append(...children);
|
|
1418
|
+
return host;
|
|
1419
|
+
}
|
|
1420
|
+
function adoptComponentStyles(root) {
|
|
1421
|
+
if ("adoptedStyleSheets" in root && "replaceSync" in CSSStyleSheet.prototype) {
|
|
1422
|
+
sharedSheet ?? (sharedSheet = createSheet());
|
|
1423
|
+
root.adoptedStyleSheets = [sharedSheet];
|
|
1424
|
+
} else {
|
|
1425
|
+
root.append(h("style", {}, componentStyles));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
function createSheet() {
|
|
1429
|
+
const sheet = new CSSStyleSheet();
|
|
1430
|
+
sheet.replaceSync(componentStyles);
|
|
1431
|
+
return sheet;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
const OUTCOME_OVERLAY = "bds-flow-outcome";
|
|
1435
|
+
const DECIDED_MARKER = "bds-gateway--decided";
|
|
1436
|
+
const STUCK_MARKER = "bds-gateway--stuck";
|
|
1437
|
+
const BADGE_DISTANCE = 38;
|
|
1438
|
+
const BADGE_MIN_SCALE = 1;
|
|
1439
|
+
class DataSimulationOverlays {
|
|
1440
|
+
constructor(eventBus, overlays, elementRegistry, canvas, dataSimulation) {
|
|
1441
|
+
this.overlays = overlays;
|
|
1442
|
+
this.elementRegistry = elementRegistry;
|
|
1443
|
+
this.canvas = canvas;
|
|
1444
|
+
this.pinnedGatewayIds = /* @__PURE__ */ new Set();
|
|
1445
|
+
this.markedGateways = [];
|
|
1446
|
+
this.popovers = [];
|
|
1447
|
+
this.popoverLayer = inShadow();
|
|
1448
|
+
this.renderedState = "";
|
|
1449
|
+
this.snapshot = dataSimulation.getSnapshot();
|
|
1450
|
+
const unsubscribe = dataSimulation.subscribe((snapshot) => {
|
|
1451
|
+
this.snapshot = snapshot;
|
|
1452
|
+
this.render();
|
|
1453
|
+
});
|
|
1454
|
+
eventBus.on("element.hover", ({ element }) => {
|
|
1455
|
+
this.hoveredGatewayId = gatewayOf(element);
|
|
1456
|
+
this.render();
|
|
1457
|
+
});
|
|
1458
|
+
eventBus.on("element.click", ({ element }) => {
|
|
1459
|
+
if (!isGateway(element)) return;
|
|
1460
|
+
if (!this.pinnedGatewayIds.delete(element.id)) this.pinnedGatewayIds.add(element.id);
|
|
1461
|
+
this.render();
|
|
1462
|
+
});
|
|
1463
|
+
eventBus.on(["canvas.viewbox.changed", "canvas.resized"], () => this.placePopovers());
|
|
1464
|
+
canvas.getContainer().append(this.popoverLayer);
|
|
1465
|
+
eventBus.on("diagram.destroy", () => {
|
|
1466
|
+
unsubscribe();
|
|
1467
|
+
this.popoverLayer.remove();
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
render() {
|
|
1471
|
+
const { decisions, shown } = new GatewayDecisionView(this.snapshot);
|
|
1472
|
+
const cards = shown.filter(
|
|
1473
|
+
({ elementId }) => elementId === this.hoveredGatewayId || this.pinnedGatewayIds.has(elementId)
|
|
1474
|
+
);
|
|
1475
|
+
const state = JSON.stringify([
|
|
1476
|
+
decisions.map((entry) => entry.id),
|
|
1477
|
+
shown.map((entry) => entry.id),
|
|
1478
|
+
cards.map((entry) => [entry.id, this.pinnedGatewayIds.has(entry.elementId)])
|
|
1479
|
+
]);
|
|
1480
|
+
if (state === this.renderedState) return;
|
|
1481
|
+
this.renderedState = state;
|
|
1482
|
+
this.overlays.remove({ type: OUTCOME_OVERLAY });
|
|
1483
|
+
this.unmarkGateways();
|
|
1484
|
+
for (const entry of decisions) this.showOutcomes(entry.decision);
|
|
1485
|
+
for (const entry of shown) this.markGateway(entry);
|
|
1486
|
+
this.showCards(cards);
|
|
1487
|
+
}
|
|
1488
|
+
markGateway({ elementId, decision }) {
|
|
1489
|
+
const gateway = this.elementRegistry.get(elementId);
|
|
1490
|
+
if (!gateway) return;
|
|
1491
|
+
this.canvas.addMarker(gateway, decision.stuckReason ? STUCK_MARKER : DECIDED_MARKER);
|
|
1492
|
+
this.markedGateways.push(gateway);
|
|
1493
|
+
}
|
|
1494
|
+
unmarkGateways() {
|
|
1495
|
+
for (const gateway of this.markedGateways) {
|
|
1496
|
+
this.canvas.removeMarker(gateway, DECIDED_MARKER);
|
|
1497
|
+
this.canvas.removeMarker(gateway, STUCK_MARKER);
|
|
1498
|
+
}
|
|
1499
|
+
this.markedGateways = [];
|
|
1500
|
+
}
|
|
1501
|
+
showOutcomes(decision) {
|
|
1502
|
+
for (const { flow, outcome, reason } of decision.flows) {
|
|
1503
|
+
const connection = this.elementRegistry.get(flow.id);
|
|
1504
|
+
if (!connection?.waypoints) continue;
|
|
1505
|
+
const badge = new OutcomeBadge(outcome, reason, flow.isDefault).element;
|
|
1506
|
+
badge.classList.add("bds-outcome--on-flow");
|
|
1507
|
+
this.overlays.add(connection, OUTCOME_OVERLAY, {
|
|
1508
|
+
position: badgePosition(connection.waypoints, BADGE_DISTANCE),
|
|
1509
|
+
scale: { min: BADGE_MIN_SCALE },
|
|
1510
|
+
html: inShadow(badge)
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
showCards(entries) {
|
|
1515
|
+
this.popovers = entries.flatMap((entry) => {
|
|
1516
|
+
const gateway = this.elementRegistry.get(entry.elementId);
|
|
1517
|
+
if (!gateway) return [];
|
|
1518
|
+
const close = () => {
|
|
1519
|
+
this.pinnedGatewayIds.delete(entry.elementId);
|
|
1520
|
+
this.render();
|
|
1521
|
+
};
|
|
1522
|
+
const card = new DecisionCard(entry, this.pinnedGatewayIds.has(entry.elementId) ? close : void 0).element;
|
|
1523
|
+
card.classList.add("bds-popover");
|
|
1524
|
+
card.dataset.elementId = entry.elementId;
|
|
1525
|
+
return [{ gateway, card }];
|
|
1526
|
+
});
|
|
1527
|
+
this.popoverLayer.shadowRoot.replaceChildren(...this.popovers.map(({ card }) => card));
|
|
1528
|
+
this.placePopovers();
|
|
1529
|
+
}
|
|
1530
|
+
placePopovers() {
|
|
1531
|
+
const container = this.canvas.getContainer();
|
|
1532
|
+
const bounds = { width: container.clientWidth, height: container.clientHeight };
|
|
1533
|
+
for (const { gateway, card } of this.popovers) {
|
|
1534
|
+
card.style.maxHeight = "";
|
|
1535
|
+
const { left, top, maxHeight, hidden } = placePopover(
|
|
1536
|
+
this.canvas.getAbsoluteBBox(gateway),
|
|
1537
|
+
{ width: card.offsetWidth, height: card.offsetHeight },
|
|
1538
|
+
bounds
|
|
1539
|
+
);
|
|
1540
|
+
card.hidden = hidden;
|
|
1541
|
+
card.style.left = `${left}px`;
|
|
1542
|
+
card.style.top = `${top}px`;
|
|
1543
|
+
card.style.maxHeight = maxHeight === void 0 ? "" : `${maxHeight}px`;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
DataSimulationOverlays.$inject = ["eventBus", "overlays", "elementRegistry", "canvas", "dataSimulation"];
|
|
1548
|
+
|
|
1549
|
+
const VARIABLES_ICON = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M5.5 2.5C4 2.5 4 3.5 4 5v1c0 1-.8 2-2 2 1.2 0 2 1 2 2v1c0 1.5 0 2.5 1.5 2.5M10.5 2.5c1.5 0 1.5 1 1.5 2.5v1c0 1 .8 2 2 2-1.2 0-2 1-2 2v1c0 1.5 0 2.5-1.5 2.5" /></svg>';
|
|
1550
|
+
const CLOSE_ICON = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" /></svg>';
|
|
1551
|
+
class VariablesPanel {
|
|
1552
|
+
constructor(actions) {
|
|
1553
|
+
this.actions = actions;
|
|
1554
|
+
this.paletteEntry = h("button", {
|
|
1555
|
+
className: "bts-entry bds-palette-entry",
|
|
1556
|
+
type: "button",
|
|
1557
|
+
title: "Toggle Process Data",
|
|
1558
|
+
"aria-label": "Toggle Process Data"
|
|
1559
|
+
});
|
|
1560
|
+
this.engineBadge = h("span", { className: "bds-engine" });
|
|
1561
|
+
this.closeButton = h("button", { className: "bds-panel-close", type: "button", "aria-label": "Close" });
|
|
1562
|
+
this.instanceTitle = h("h3", { className: "bds-section-title" }, "Instance");
|
|
1563
|
+
this.instancePicker = h("select", {
|
|
1564
|
+
className: "bds-input bds-instance-select",
|
|
1565
|
+
"aria-label": "Process instance"
|
|
1566
|
+
});
|
|
1567
|
+
this.instanceBody = h("div", { className: "bds-instance-body" });
|
|
1568
|
+
this.issueList = h("ol", { className: "bds-log" });
|
|
1569
|
+
this.issueSection = h(
|
|
1570
|
+
"section",
|
|
1571
|
+
{ className: "bds-section bds-issues" },
|
|
1572
|
+
h("h3", { className: "bds-section-title" }, "Issues"),
|
|
1573
|
+
this.issueList
|
|
1574
|
+
);
|
|
1575
|
+
this.shownInstances = "";
|
|
1576
|
+
this.paletteEntry.innerHTML = `<span class="bts-icon bds-variables-icon">${VARIABLES_ICON}</span>`;
|
|
1577
|
+
this.closeButton.innerHTML = CLOSE_ICON;
|
|
1578
|
+
const icon = h("span", { className: "bds-variables-icon" });
|
|
1579
|
+
icon.innerHTML = VARIABLES_ICON;
|
|
1580
|
+
this.element = h(
|
|
1581
|
+
"aside",
|
|
1582
|
+
{ className: "bds-panel", "aria-label": "Process Data" },
|
|
1583
|
+
h(
|
|
1584
|
+
"header",
|
|
1585
|
+
{ className: "bds-panel-header" },
|
|
1586
|
+
icon,
|
|
1587
|
+
h("h2", { className: "bds-panel-heading" }, "Process Data"),
|
|
1588
|
+
this.closeButton
|
|
1589
|
+
),
|
|
1590
|
+
h(
|
|
1591
|
+
"div",
|
|
1592
|
+
{ className: "bds-panel-body" },
|
|
1593
|
+
h("p", { className: "bds-panel-engine" }, this.engineBadge),
|
|
1594
|
+
h("section", { className: "bds-section bds-instance" }, this.instanceTitle, this.instanceBody),
|
|
1595
|
+
this.issueSection
|
|
1596
|
+
)
|
|
1597
|
+
);
|
|
1598
|
+
this.paletteEntry.addEventListener("click", () => this.toggle());
|
|
1599
|
+
this.closeButton.addEventListener("click", () => this.toggle(false));
|
|
1600
|
+
this.instancePicker.addEventListener("change", () => this.actions.selectInstance(this.instancePicker.value));
|
|
1601
|
+
this.toggle(false);
|
|
1602
|
+
}
|
|
1603
|
+
toggle(shown = this.element.hidden === true) {
|
|
1604
|
+
this.element.hidden = !shown;
|
|
1605
|
+
this.paletteEntry.classList.toggle("active", shown);
|
|
1606
|
+
}
|
|
1607
|
+
render(snapshot) {
|
|
1608
|
+
this.snapshot = snapshot;
|
|
1609
|
+
this.engineBadge.textContent = `${snapshot.engineLabel} \xB7 ${snapshot.expressionLanguage}`;
|
|
1610
|
+
this.renderInstance(snapshot);
|
|
1611
|
+
this.renderIssues(snapshot);
|
|
1612
|
+
}
|
|
1613
|
+
renderInstance({ instances, selectedInstanceId, scenarios }) {
|
|
1614
|
+
const editedInstance = instances.find((candidate) => candidate.id === this.editingInstanceId);
|
|
1615
|
+
if (editedInstance && editedInstance.status !== "completed" && editedInstance.id !== selectedInstanceId) {
|
|
1616
|
+
this.actions.selectInstance(editedInstance.id);
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
const instance = instances.find((candidate) => candidate.id === selectedInstanceId);
|
|
1620
|
+
this.renderInstancePicker(instances, selectedInstanceId, scenarios);
|
|
1621
|
+
if (this.editingInstanceId && this.editingInstanceId === instance?.id && instance.status !== "completed") return;
|
|
1622
|
+
this.editingInstanceId = void 0;
|
|
1623
|
+
this.instanceBody.replaceChildren(
|
|
1624
|
+
instance ? this.instanceView(instance) : h("p", { className: "bds-hint" }, "Press \u25B6 on a start event to start a process instance.")
|
|
1625
|
+
);
|
|
1626
|
+
}
|
|
1627
|
+
renderInstancePicker(instances, selectedInstanceId, scenarios) {
|
|
1628
|
+
const signature = JSON.stringify(instances.map((instance) => [instance.id, instance.status]));
|
|
1629
|
+
if (signature !== this.shownInstances) {
|
|
1630
|
+
this.shownInstances = signature;
|
|
1631
|
+
this.instancePicker.replaceChildren(
|
|
1632
|
+
...instances.map((instance) => {
|
|
1633
|
+
const scenarioName = scenarios.find((scenario) => scenario.id === instance.scenarioId)?.name ?? "no scenario";
|
|
1634
|
+
return h("option", { value: instance.id }, `#${instance.number} ${scenarioName} (${instance.status})`);
|
|
1635
|
+
})
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
this.instancePicker.value = selectedInstanceId ?? "";
|
|
1639
|
+
this.instancePicker.hidden = instances.length < 2;
|
|
1640
|
+
if (!this.instancePicker.isConnected) this.instanceTitle.after(this.instancePicker);
|
|
1641
|
+
}
|
|
1642
|
+
instanceView(instance) {
|
|
1643
|
+
const scenarioName = this.snapshot?.scenarios.find((scenario) => scenario.id === instance.scenarioId)?.name;
|
|
1644
|
+
const entries = Object.entries(instance.variables);
|
|
1645
|
+
const editButton = h("button", { className: "bds-button", type: "button" }, "Edit");
|
|
1646
|
+
editButton.addEventListener("click", () => this.editInstance(instance));
|
|
1647
|
+
return h(
|
|
1648
|
+
"div",
|
|
1649
|
+
{},
|
|
1650
|
+
h("p", { className: `bds-status bds-status--${instance.status}` }, this.describeStatus(instance)),
|
|
1651
|
+
scenarioName ? h("p", { className: "bds-hint" }, `Scenario: ${scenarioName}`) : null,
|
|
1652
|
+
entries.length ? h(
|
|
1653
|
+
"table",
|
|
1654
|
+
{ className: "bds-variables" },
|
|
1655
|
+
h(
|
|
1656
|
+
"tbody",
|
|
1657
|
+
{},
|
|
1658
|
+
...entries.map(
|
|
1659
|
+
([name, value]) => h("tr", {}, h("th", { scope: "row" }, name), h("td", {}, h("code", {}, formatValue(value))))
|
|
1660
|
+
)
|
|
1661
|
+
)
|
|
1662
|
+
) : h("p", { className: "bds-hint" }, "No variables yet."),
|
|
1663
|
+
h("p", { className: "bds-hint" }, "Hover a gateway to see why it took its flow, click it to keep the card open."),
|
|
1664
|
+
instance.status !== "completed" ? h("div", { className: "bds-actions" }, editButton) : null
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
editInstance(instance) {
|
|
1668
|
+
this.editingInstanceId = instance.id;
|
|
1669
|
+
const editor = h("textarea", {
|
|
1670
|
+
className: "bds-input bds-json bds-instance-editor",
|
|
1671
|
+
spellcheck: "false",
|
|
1672
|
+
rows: "8",
|
|
1673
|
+
"aria-label": "Instance variables (JSON)"
|
|
1674
|
+
});
|
|
1675
|
+
editor.value = JSON.stringify(instance.variables, null, 2);
|
|
1676
|
+
const error = h("p", { className: "bds-error", role: "alert" });
|
|
1677
|
+
this.showError(error, editor, "");
|
|
1678
|
+
const applyButton = h("button", { className: "bds-button bds-button--primary", type: "button" }, "Apply");
|
|
1679
|
+
const cancelButton = h("button", { className: "bds-button", type: "button" }, "Cancel");
|
|
1680
|
+
applyButton.addEventListener("click", () => {
|
|
1681
|
+
const parsed = this.parseVariables(editor.value);
|
|
1682
|
+
if (typeof parsed === "string") {
|
|
1683
|
+
this.showError(error, editor, parsed);
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
this.editingInstanceId = void 0;
|
|
1687
|
+
this.actions.setInstanceVariables(instance.id, parsed);
|
|
1688
|
+
});
|
|
1689
|
+
cancelButton.addEventListener("click", () => {
|
|
1690
|
+
this.editingInstanceId = void 0;
|
|
1691
|
+
if (this.snapshot) this.renderInstance(this.snapshot);
|
|
1692
|
+
});
|
|
1693
|
+
this.instanceBody.replaceChildren(editor, error, h("div", { className: "bds-actions" }, cancelButton, applyButton));
|
|
1694
|
+
editor.focus();
|
|
1695
|
+
}
|
|
1696
|
+
renderIssues({ log, selectedInstanceId }) {
|
|
1697
|
+
const issues = log.filter(
|
|
1698
|
+
(entry) => entry.kind === "mapping-issue" && entry.instanceId === selectedInstanceId
|
|
1699
|
+
);
|
|
1700
|
+
this.issueSection.hidden = !issues.length;
|
|
1701
|
+
this.issueList.replaceChildren(
|
|
1702
|
+
...issues.slice().reverse().map((issue) => this.renderMappingIssue(issue))
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
describeStatus({ processName, status, waiting }) {
|
|
1706
|
+
if (status !== "waiting") return `${processName} \xB7 ${status}`;
|
|
1707
|
+
return `${processName} \xB7 waiting at ${waiting.map((gateway) => gateway.gatewayName).join(", ")}`;
|
|
1708
|
+
}
|
|
1709
|
+
showError(error, input, message) {
|
|
1710
|
+
error.textContent = message;
|
|
1711
|
+
error.hidden = !message;
|
|
1712
|
+
input.classList.toggle("bds-input--invalid", Boolean(message));
|
|
1713
|
+
}
|
|
1714
|
+
renderMappingIssue({ elementName, target, reason }) {
|
|
1715
|
+
return h(
|
|
1716
|
+
"li",
|
|
1717
|
+
{ className: "bds-log-entry bds-log-entry--issue" },
|
|
1718
|
+
h("div", { className: "bds-log-title" }, elementName, h("span", { className: "bds-tag" }, "mapping")),
|
|
1719
|
+
h("p", { className: "bds-error" }, `${target}: ${reason}`)
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
parseVariables(text) {
|
|
1723
|
+
try {
|
|
1724
|
+
const value = JSON.parse(text || "{}");
|
|
1725
|
+
return isVariables(value) ? value : "Variables must be a JSON object";
|
|
1726
|
+
} catch (error) {
|
|
1727
|
+
return `Invalid JSON: ${error.message}`;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
const PALETTE_INDEX = 4;
|
|
1733
|
+
class DataSimulationPanel {
|
|
1734
|
+
constructor(eventBus, canvas, palette, dataSimulation) {
|
|
1735
|
+
this.dataSimulation = dataSimulation;
|
|
1736
|
+
this.panel = new VariablesPanel({
|
|
1737
|
+
selectInstance: (instanceId) => dataSimulation.selectInstance(instanceId),
|
|
1738
|
+
setInstanceVariables: (instanceId, variables) => dataSimulation.setInstanceVariables(instanceId, variables)
|
|
1739
|
+
});
|
|
1740
|
+
this.panel.render(dataSimulation.getSnapshot());
|
|
1741
|
+
const host = inShadow(this.panel.element);
|
|
1742
|
+
canvas.getContainer().append(host);
|
|
1743
|
+
palette.addEntry(this.panel.paletteEntry, PALETTE_INDEX);
|
|
1744
|
+
this.showPaletteEntry();
|
|
1745
|
+
const unsubscribe = dataSimulation.subscribe((snapshot) => this.panel.render(snapshot));
|
|
1746
|
+
eventBus.on(TOGGLE_MODE_EVENT, () => this.panel.toggle(false));
|
|
1747
|
+
eventBus.on(DATA_TOGGLE_EVENT, () => this.showPaletteEntry());
|
|
1748
|
+
eventBus.on("diagram.destroy", () => {
|
|
1749
|
+
unsubscribe();
|
|
1750
|
+
host.remove();
|
|
1751
|
+
this.panel.paletteEntry.remove();
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
showPaletteEntry() {
|
|
1755
|
+
this.panel.paletteEntry.hidden = !this.dataSimulation.isEnabled();
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
DataSimulationPanel.$inject = ["eventBus", "canvas", "tokenSimulationPalette", "dataSimulation"];
|
|
1759
|
+
|
|
1760
|
+
const LABEL = "Data Simulation";
|
|
1761
|
+
const GAP = 8;
|
|
1762
|
+
const TOGGLE_ON = '<svg viewBox="0 0 26 14" aria-hidden="true"><rect x="1" y="1" width="24" height="12" rx="6" /><circle cx="18" cy="7" r="3.5" /></svg>';
|
|
1763
|
+
const TOGGLE_OFF = '<svg viewBox="0 0 26 14" aria-hidden="true"><rect x="1" y="1" width="24" height="12" rx="6" /><circle cx="8" cy="7" r="3.5" /></svg>';
|
|
1764
|
+
class DataSimulationToggle {
|
|
1765
|
+
constructor(eventBus, canvas, toggleMode, dataSimulation) {
|
|
1766
|
+
this.canvas = canvas;
|
|
1767
|
+
this.dataSimulation = dataSimulation;
|
|
1768
|
+
this.button = h("button", { className: "bds-data-toggle", type: "button" });
|
|
1769
|
+
this.simulating = false;
|
|
1770
|
+
this.render();
|
|
1771
|
+
canvas.getContainer().append(this.button);
|
|
1772
|
+
this.button.addEventListener("click", () => dataSimulation.setEnabled(!dataSimulation.isEnabled()));
|
|
1773
|
+
eventBus.on(TOGGLE_MODE_EVENT, ({ active }) => {
|
|
1774
|
+
this.simulating = active;
|
|
1775
|
+
if (active) this.placeNextToTokenSimulationToggle();
|
|
1776
|
+
});
|
|
1777
|
+
eventBus.on(DATA_TOGGLE_EVENT, () => {
|
|
1778
|
+
this.render();
|
|
1779
|
+
if (!this.simulating) return;
|
|
1780
|
+
toggleMode.toggleMode(false);
|
|
1781
|
+
toggleMode.toggleMode(true);
|
|
1782
|
+
});
|
|
1783
|
+
eventBus.on("diagram.destroy", () => {
|
|
1784
|
+
this.tokenToggleObserver?.disconnect();
|
|
1785
|
+
this.button.remove();
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
render() {
|
|
1789
|
+
const enabled = this.dataSimulation.isEnabled();
|
|
1790
|
+
this.button.innerHTML = `${LABEL} <span class="bds-data-toggle-icon">${enabled ? TOGGLE_ON : TOGGLE_OFF}</span>`;
|
|
1791
|
+
this.button.classList.toggle("active", enabled);
|
|
1792
|
+
this.button.setAttribute("aria-pressed", String(enabled));
|
|
1793
|
+
}
|
|
1794
|
+
placeNextToTokenSimulationToggle() {
|
|
1795
|
+
const container = this.canvas.getContainer();
|
|
1796
|
+
const tokenToggle = container.querySelector(".bts-toggle-mode");
|
|
1797
|
+
if (!tokenToggle) return;
|
|
1798
|
+
const containerBox = container.getBoundingClientRect();
|
|
1799
|
+
const toggleBox = tokenToggle.getBoundingClientRect();
|
|
1800
|
+
const scale = containerBox.width / container.offsetWidth || 1;
|
|
1801
|
+
this.button.style.fontSize = getComputedStyle(tokenToggle).fontSize;
|
|
1802
|
+
this.button.style.left = `${(toggleBox.right - containerBox.left) / scale + GAP}px`;
|
|
1803
|
+
this.button.style.top = `${(toggleBox.top + toggleBox.height / 2 - containerBox.top) / scale - this.button.offsetHeight / 2}px`;
|
|
1804
|
+
this.observeTokenToggle(tokenToggle);
|
|
1805
|
+
}
|
|
1806
|
+
observeTokenToggle(tokenToggle) {
|
|
1807
|
+
if (this.tokenToggleObserver || typeof ResizeObserver !== "function") return;
|
|
1808
|
+
this.tokenToggleObserver = new ResizeObserver(() => this.placeNextToTokenSimulationToggle());
|
|
1809
|
+
this.tokenToggleObserver.observe(tokenToggle);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
DataSimulationToggle.$inject = ["eventBus", "canvas", "toggleMode", "dataSimulation"];
|
|
1813
|
+
|
|
1814
|
+
class StartFieldDeriver {
|
|
1815
|
+
derive(usages, { examples = [], taskResultNames = [] } = {}) {
|
|
1816
|
+
const written = /* @__PURE__ */ new Set([
|
|
1817
|
+
...usages.flatMap((usage) => usage.outputTargets.map((target) => this.topLevelName(target))),
|
|
1818
|
+
...taskResultNames
|
|
1819
|
+
]);
|
|
1820
|
+
const usedBy = /* @__PURE__ */ new Map();
|
|
1821
|
+
for (const usage of usages) {
|
|
1822
|
+
const localNames = new Set(usage.inputTargets.map((target) => this.topLevelName(target)));
|
|
1823
|
+
for (const name of [...usage.conditionReads, ...usage.inputReads, ...usage.outputReads]) {
|
|
1824
|
+
if (written.has(name) || localNames.has(name)) continue;
|
|
1825
|
+
if (!usedBy.has(name)) usedBy.set(name, /* @__PURE__ */ new Set());
|
|
1826
|
+
usedBy.get(name).add(usage.elementName);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
return [...usedBy.entries()].map(([name, elements]) => ({
|
|
1830
|
+
name,
|
|
1831
|
+
type: this.inferType(examples.map((example) => example[name]).find((value) => value !== void 0)),
|
|
1832
|
+
usedBy: [...elements]
|
|
1833
|
+
}));
|
|
1834
|
+
}
|
|
1835
|
+
topLevelName(path) {
|
|
1836
|
+
return path.split(".")[0];
|
|
1837
|
+
}
|
|
1838
|
+
inferType(example) {
|
|
1839
|
+
if (typeof example === "number") return "number";
|
|
1840
|
+
if (typeof example === "boolean") return "boolean";
|
|
1841
|
+
if (typeof example === "string") return "text";
|
|
1842
|
+
if (Array.isArray(example) || isVariables(example)) return "json";
|
|
1843
|
+
return "auto";
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
const NO_SCENARIO = "";
|
|
1848
|
+
class StartDialog {
|
|
1849
|
+
constructor(options) {
|
|
1850
|
+
this.options = options;
|
|
1851
|
+
this.codec = new StartFieldCodec();
|
|
1852
|
+
this.scenarioSelect = h("select", {
|
|
1853
|
+
className: "bds-input bds-scenario-select",
|
|
1854
|
+
"aria-label": "Scenario"
|
|
1855
|
+
});
|
|
1856
|
+
this.scenarioDescription = h("p", { className: "bds-hint" });
|
|
1857
|
+
this.formContainer = h("div", { className: "bds-dialog-form" });
|
|
1858
|
+
this.noFieldsHint = h("p", { className: "bds-hint" }, "The process reads no start variables.");
|
|
1859
|
+
this.error = h("p", { className: "bds-error", role: "alert" });
|
|
1860
|
+
this.cancelButton = h("button", { className: "bds-button", type: "button" }, "Cancel");
|
|
1861
|
+
this.startButton = h(
|
|
1862
|
+
"button",
|
|
1863
|
+
{ className: "bds-button bds-button--primary", type: "submit" },
|
|
1864
|
+
"Start instance"
|
|
1865
|
+
);
|
|
1866
|
+
this.fields = [];
|
|
1867
|
+
this.baseVariables = options.startVariables;
|
|
1868
|
+
this.scenarioSelect.append(
|
|
1869
|
+
h("option", { value: NO_SCENARIO }, "No scenario"),
|
|
1870
|
+
...options.scenarios.map((scenario) => h("option", { value: scenario.id }, scenario.name))
|
|
1871
|
+
);
|
|
1872
|
+
this.scenarioSelect.value = options.selectedScenarioId ?? NO_SCENARIO;
|
|
1873
|
+
this.error.hidden = true;
|
|
1874
|
+
this.form = this.createForm();
|
|
1875
|
+
this.backdrop = h("div", { className: "bds-dialog-backdrop" }, this.form);
|
|
1876
|
+
this.rendered = this.renderForm();
|
|
1877
|
+
this.listen();
|
|
1878
|
+
}
|
|
1879
|
+
open(container) {
|
|
1880
|
+
this.showScenarioDescription();
|
|
1881
|
+
container.append(this.backdrop);
|
|
1882
|
+
if (this.fields.length) this.rendered.focus();
|
|
1883
|
+
else this.startButton.focus();
|
|
1884
|
+
}
|
|
1885
|
+
close() {
|
|
1886
|
+
this.rendered.destroy();
|
|
1887
|
+
this.backdrop.remove();
|
|
1888
|
+
}
|
|
1889
|
+
createForm() {
|
|
1890
|
+
const titleId = `bds-start-title-${Math.random().toString(36).slice(2)}`;
|
|
1891
|
+
return h(
|
|
1892
|
+
"form",
|
|
1893
|
+
{ className: "bds-dialog", role: "dialog", "aria-modal": "true", "aria-labelledby": titleId },
|
|
1894
|
+
h(
|
|
1895
|
+
"header",
|
|
1896
|
+
{ className: "bds-dialog-header" },
|
|
1897
|
+
h("h2", { className: "bds-panel-title", id: titleId }, `Start \u201C${this.options.processName}\u201D`),
|
|
1898
|
+
h("span", { className: "bds-engine" }, this.options.engineLabel)
|
|
1899
|
+
),
|
|
1900
|
+
h(
|
|
1901
|
+
"div",
|
|
1902
|
+
{ className: "bds-dialog-content" },
|
|
1903
|
+
this.options.scenarios.length ? h(
|
|
1904
|
+
"section",
|
|
1905
|
+
{ className: "bds-section" },
|
|
1906
|
+
h("label", { className: "bds-label" }, "Scenario", this.scenarioSelect),
|
|
1907
|
+
this.scenarioDescription
|
|
1908
|
+
) : null,
|
|
1909
|
+
h(
|
|
1910
|
+
"section",
|
|
1911
|
+
{ className: "bds-section" },
|
|
1912
|
+
h("h3", { className: "bds-section-title" }, "Start variables"),
|
|
1913
|
+
this.formContainer,
|
|
1914
|
+
this.noFieldsHint
|
|
1915
|
+
),
|
|
1916
|
+
this.error
|
|
1917
|
+
),
|
|
1918
|
+
h("footer", { className: "bds-actions" }, this.cancelButton, this.startButton)
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
listen() {
|
|
1922
|
+
this.scenarioSelect.addEventListener("change", () => this.switchScenario());
|
|
1923
|
+
this.cancelButton.addEventListener("click", () => this.close());
|
|
1924
|
+
this.backdrop.addEventListener("mousedown", (event) => {
|
|
1925
|
+
if (event.target === this.backdrop) this.close();
|
|
1926
|
+
});
|
|
1927
|
+
this.backdrop.addEventListener("keydown", (event) => {
|
|
1928
|
+
event.stopPropagation();
|
|
1929
|
+
if (event.key === "Escape") this.close();
|
|
1930
|
+
});
|
|
1931
|
+
this.form.addEventListener("submit", (event) => {
|
|
1932
|
+
event.preventDefault();
|
|
1933
|
+
this.submit();
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
selectedScenarioId() {
|
|
1937
|
+
return this.scenarioSelect.value || null;
|
|
1938
|
+
}
|
|
1939
|
+
selectedScenario() {
|
|
1940
|
+
return this.options.scenarios.find((scenario) => scenario.id === this.scenarioSelect.value);
|
|
1941
|
+
}
|
|
1942
|
+
renderForm() {
|
|
1943
|
+
this.fields = this.options.fieldsFor(this.selectedScenarioId());
|
|
1944
|
+
this.noFieldsHint.hidden = this.fields.length > 0;
|
|
1945
|
+
return this.options.renderer.render(this.formContainer, this.fields, this.baseVariables);
|
|
1946
|
+
}
|
|
1947
|
+
switchScenario() {
|
|
1948
|
+
this.baseVariables = this.selectedScenario()?.variables ?? {};
|
|
1949
|
+
this.rendered.destroy();
|
|
1950
|
+
this.rendered = this.renderForm();
|
|
1951
|
+
this.showScenarioDescription();
|
|
1952
|
+
}
|
|
1953
|
+
showScenarioDescription() {
|
|
1954
|
+
const description = this.selectedScenario()?.description ?? "";
|
|
1955
|
+
this.scenarioDescription.textContent = description;
|
|
1956
|
+
this.scenarioDescription.hidden = !description;
|
|
1957
|
+
}
|
|
1958
|
+
submit() {
|
|
1959
|
+
const values = this.rendered.readValues();
|
|
1960
|
+
if (!values.ok) {
|
|
1961
|
+
this.error.textContent = values.reason;
|
|
1962
|
+
this.error.hidden = false;
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
this.close();
|
|
1966
|
+
this.options.onStart(this.selectedScenarioId(), this.codec.apply(this.baseVariables, values.values));
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
class VariableUsageCollector {
|
|
1971
|
+
constructor(engine) {
|
|
1972
|
+
this.engine = engine;
|
|
1973
|
+
}
|
|
1974
|
+
collect(container) {
|
|
1975
|
+
const usages = [];
|
|
1976
|
+
const visit = (element) => {
|
|
1977
|
+
if (element.type === "label") return;
|
|
1978
|
+
const usage = this.usageOf(element);
|
|
1979
|
+
if (usage) usages.push(usage);
|
|
1980
|
+
element.children?.forEach(visit);
|
|
1981
|
+
};
|
|
1982
|
+
container.children?.forEach(visit);
|
|
1983
|
+
return usages;
|
|
1984
|
+
}
|
|
1985
|
+
usageOf(element) {
|
|
1986
|
+
const businessObject = element.businessObject;
|
|
1987
|
+
if (is(element, "bpmn:SequenceFlow")) {
|
|
1988
|
+
const condition = this.engine.readCondition(businessObject);
|
|
1989
|
+
if (!condition) return void 0;
|
|
1990
|
+
return this.usage(element.source ?? element, { conditionReads: this.engine.readVariableNames(condition) });
|
|
1991
|
+
}
|
|
1992
|
+
if (!is(element, "bpmn:FlowNode")) return void 0;
|
|
1993
|
+
const inputs = this.engine.readInputMappings(businessObject);
|
|
1994
|
+
const outputs = this.engine.readOutputMappings(businessObject);
|
|
1995
|
+
return this.usage(element, {
|
|
1996
|
+
inputReads: inputs.flatMap((mapping) => this.engine.readVariableNames(mapping.source)),
|
|
1997
|
+
inputTargets: inputs.map((mapping) => mapping.target),
|
|
1998
|
+
outputReads: outputs.flatMap((mapping) => this.engine.readVariableNames(mapping.source)),
|
|
1999
|
+
outputTargets: outputs.map((mapping) => mapping.target)
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
usage(element, reads) {
|
|
2003
|
+
return {
|
|
2004
|
+
elementName: elementName(element),
|
|
2005
|
+
conditionReads: [],
|
|
2006
|
+
inputReads: [],
|
|
2007
|
+
inputTargets: [],
|
|
2008
|
+
outputReads: [],
|
|
2009
|
+
outputTargets: [],
|
|
2010
|
+
...reads
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
class DataStartForm {
|
|
2016
|
+
constructor(config, eventBus, dataSimulation, store) {
|
|
2017
|
+
this.store = store;
|
|
2018
|
+
this.fieldDeriver = new StartFieldDeriver();
|
|
2019
|
+
this.renderer = config?.startFormRenderer ?? new SimpleStartFormRenderer();
|
|
2020
|
+
this.usageCollector = new VariableUsageCollector(dataSimulation.getEngine());
|
|
2021
|
+
eventBus.on(TOGGLE_MODE_EVENT, () => this.closeDialog());
|
|
2022
|
+
eventBus.on("diagram.destroy", () => {
|
|
2023
|
+
this.closeDialog();
|
|
2024
|
+
this.dialogHost?.remove();
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
isProcessStart(element) {
|
|
2028
|
+
return is(element, "bpmn:StartEvent") && Boolean(element.parent) && (is(element.parent, "bpmn:Process") || is(element.parent, "bpmn:Participant"));
|
|
2029
|
+
}
|
|
2030
|
+
fieldsFor(startEvent, scenarioId) {
|
|
2031
|
+
const snapshot = this.store.getSnapshot();
|
|
2032
|
+
const examples = [snapshot.startVariables, ...snapshot.scenarios.map((scenario) => scenario.variables)];
|
|
2033
|
+
const taskResults = snapshot.scenarios.find((scenario) => scenario.id === scenarioId)?.taskResults ?? {};
|
|
2034
|
+
const taskResultNames = Object.values(taskResults).flatMap((result) => Object.keys(result));
|
|
2035
|
+
return this.fieldDeriver.derive(this.usageCollector.collect(startEvent.parent), { examples, taskResultNames });
|
|
2036
|
+
}
|
|
2037
|
+
open(startEvent, start) {
|
|
2038
|
+
this.closeDialog();
|
|
2039
|
+
const snapshot = this.store.getSnapshot();
|
|
2040
|
+
this.dialogHost ?? (this.dialogHost = document.body.appendChild(inShadow()));
|
|
2041
|
+
this.dialog = new StartDialog({
|
|
2042
|
+
processName: elementName(startEvent.parent),
|
|
2043
|
+
engineLabel: `${snapshot.engineLabel} \xB7 ${snapshot.expressionLanguage}`,
|
|
2044
|
+
scenarios: snapshot.scenarios,
|
|
2045
|
+
selectedScenarioId: snapshot.selectedScenarioId,
|
|
2046
|
+
startVariables: snapshot.startVariables,
|
|
2047
|
+
fieldsFor: (scenarioId) => this.fieldsFor(startEvent, scenarioId),
|
|
2048
|
+
renderer: this.renderer,
|
|
2049
|
+
onStart: (scenarioId, variables) => {
|
|
2050
|
+
this.dialog = void 0;
|
|
2051
|
+
this.store.selectScenario(scenarioId);
|
|
2052
|
+
this.store.setStartVariables(variables);
|
|
2053
|
+
start();
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
this.dialog.open(this.dialogHost.shadowRoot);
|
|
2057
|
+
}
|
|
2058
|
+
closeDialog() {
|
|
2059
|
+
this.dialog?.close();
|
|
2060
|
+
this.dialog = void 0;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
DataStartForm.$inject = ["config.dataSimulation", "eventBus", "dataSimulation", "dataSimulationStore"];
|
|
2064
|
+
|
|
2065
|
+
const DataSimulationModule = {
|
|
2066
|
+
__init__: [
|
|
2067
|
+
"dataSimulation",
|
|
2068
|
+
"dataSimulationOverlays",
|
|
2069
|
+
"dataSimulationPanel",
|
|
2070
|
+
"dataSimulationToggle",
|
|
2071
|
+
"dataGatewayBehaviors",
|
|
2072
|
+
"dataGatewaySettings",
|
|
2073
|
+
"dataContextPads"
|
|
2074
|
+
],
|
|
2075
|
+
dataSimulationStore: ["type", DataSimulationStore],
|
|
2076
|
+
dataSimulation: ["type", DataSimulation],
|
|
2077
|
+
dataSimulationOverlays: ["type", DataSimulationOverlays],
|
|
2078
|
+
dataSimulationPanel: ["type", DataSimulationPanel],
|
|
2079
|
+
dataSimulationToggle: ["type", DataSimulationToggle],
|
|
2080
|
+
dataGateways: ["type", DataGateways],
|
|
2081
|
+
dataStartForm: ["type", DataStartForm],
|
|
2082
|
+
dataGatewayBehaviors: ["type", DataGatewayBehaviors],
|
|
2083
|
+
dataGatewaySettings: ["type", DataGatewaySettings],
|
|
2084
|
+
dataContextPads: ["type", DataContextPads]
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
exports.Camunda7Engine = Camunda7Engine;
|
|
2088
|
+
exports.DataSimulationStore = DataSimulationStore;
|
|
2089
|
+
exports.EngineRegistry = EngineRegistry;
|
|
2090
|
+
exports.GatewayRouter = GatewayRouter;
|
|
2091
|
+
exports.ScenarioError = ScenarioError;
|
|
2092
|
+
exports.ScenarioParser = ScenarioParser;
|
|
2093
|
+
exports.SimpleStartFormRenderer = SimpleStartFormRenderer;
|
|
2094
|
+
exports.StartFieldCodec = StartFieldCodec;
|
|
2095
|
+
exports.ZeebeEngine = ZeebeEngine;
|
|
2096
|
+
exports.camunda7Engine = camunda7Engine;
|
|
2097
|
+
exports.default = DataSimulationModule;
|
|
2098
|
+
exports.zeebeEngine = zeebeEngine;
|
|
2099
|
+
//# sourceMappingURL=index.cjs.map
|