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