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