@rotorsoft/act-diagram 1.1.8 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/format.d.ts.map +1 -1
- package/dist/@types/cli/markdown.d.ts.map +1 -1
- package/dist/@types/client/components/Diagram.d.ts.map +1 -1
- package/dist/@types/client/lib/build-model.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/mock-builders.d.ts.map +1 -1
- package/dist/@types/client/lib/navigate.d.ts.map +1 -1
- package/dist/@types/client/types/domain-model.d.ts +2 -0
- package/dist/@types/client/types/domain-model.d.ts.map +1 -1
- package/dist/cli/act.js +34 -17
- package/dist/cli/act.js.map +1 -1
- package/dist/index.cjs +39 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -308,10 +308,15 @@ function build_state(model, st) {
|
|
|
308
308
|
for (const action_name of Object.keys(raw_actions)) {
|
|
309
309
|
if (action_name.startsWith("__emits_")) continue;
|
|
310
310
|
const emits = raw_actions[`__emits_${action_name}`] ?? [];
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
);
|
|
314
|
-
action_nodes.push({
|
|
311
|
+
const describe = (rule) => rule.description ?? "";
|
|
312
|
+
const invariants = (st.given?.[action_name] ?? []).map(describe);
|
|
313
|
+
const preconditions = (st.requires?.[action_name] ?? []).map(describe);
|
|
314
|
+
action_nodes.push({
|
|
315
|
+
name: action_name,
|
|
316
|
+
emits,
|
|
317
|
+
invariants,
|
|
318
|
+
...preconditions.length ? { preconditions } : {}
|
|
319
|
+
});
|
|
315
320
|
}
|
|
316
321
|
const node = {
|
|
317
322
|
name: domain_name,
|
|
@@ -625,6 +630,7 @@ function mock_state(entry, on_build) {
|
|
|
625
630
|
events: {},
|
|
626
631
|
actions: {},
|
|
627
632
|
given: {},
|
|
633
|
+
requires: {},
|
|
628
634
|
patches: /* @__PURE__ */ new Set(),
|
|
629
635
|
_tag: "State"
|
|
630
636
|
};
|
|
@@ -632,20 +638,21 @@ function mock_state(entry, on_build) {
|
|
|
632
638
|
on(action_entry) {
|
|
633
639
|
const action_name = Object.keys(action_entry)[0];
|
|
634
640
|
info.actions[action_name] = action_entry[action_name];
|
|
641
|
+
const emit = (handler) => {
|
|
642
|
+
attach_emit(info, action_name, handler);
|
|
643
|
+
return action_builder(action_name);
|
|
644
|
+
};
|
|
645
|
+
const requires = (rules) => {
|
|
646
|
+
if (rules) info.requires[action_name] = rules;
|
|
647
|
+
return { emit };
|
|
648
|
+
};
|
|
635
649
|
return {
|
|
636
650
|
given(rules) {
|
|
637
651
|
if (rules) info.given[action_name] = rules;
|
|
638
|
-
return {
|
|
639
|
-
emit(handler) {
|
|
640
|
-
attach_emit(info, action_name, handler);
|
|
641
|
-
return action_builder(action_name);
|
|
642
|
-
}
|
|
643
|
-
};
|
|
652
|
+
return { requires, emit };
|
|
644
653
|
},
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
return action_builder(action_name);
|
|
648
|
-
}
|
|
654
|
+
requires,
|
|
655
|
+
emit
|
|
649
656
|
};
|
|
650
657
|
},
|
|
651
658
|
snap: () => action_builder(_currentAction),
|
|
@@ -1231,11 +1238,13 @@ function build_patterns(esc, type) {
|
|
|
1231
1238
|
];
|
|
1232
1239
|
const guard_patterns = [
|
|
1233
1240
|
// Guard definition — prefer jumping to the declaration
|
|
1234
|
-
new RegExp(
|
|
1241
|
+
new RegExp(
|
|
1242
|
+
`(?:const|let|var)\\s+(${esc})\\s*(?::\\s*(?:Invariant|Precondition)\\b[^=]*)?\\s*=`
|
|
1243
|
+
),
|
|
1235
1244
|
new RegExp(`rule\\(\\s*["'\`](${esc})["'\`]`),
|
|
1236
1245
|
new RegExp(`description:\\s*["'\`](${esc})["'\`]`),
|
|
1237
|
-
// .given() usage in the state builder — last resort
|
|
1238
|
-
new RegExp(`\\.given\\([\\s\\S]*?(${esc})`)
|
|
1246
|
+
// .given() or .requires() usage in the state builder — last resort
|
|
1247
|
+
new RegExp(`\\.(?:given|requires)\\([\\s\\S]*?(${esc})`)
|
|
1239
1248
|
];
|
|
1240
1249
|
const slice_patterns = [
|
|
1241
1250
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*slice\\s*\\(`)
|
|
@@ -1516,6 +1525,10 @@ import {
|
|
|
1516
1525
|
import { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "react";
|
|
1517
1526
|
|
|
1518
1527
|
// src/client/lib/layout.ts
|
|
1528
|
+
function rules_of(action) {
|
|
1529
|
+
const rules = [...action.invariants, ...action.preconditions ?? []];
|
|
1530
|
+
return rules.length ? rules : void 0;
|
|
1531
|
+
}
|
|
1519
1532
|
var W = 100;
|
|
1520
1533
|
var H = 36;
|
|
1521
1534
|
var STATE_W = 80;
|
|
@@ -1597,8 +1610,8 @@ function place_chain(measure, rDef, reactionY, rX, triggered_from_x, triggered_f
|
|
|
1597
1610
|
pos: dap,
|
|
1598
1611
|
type: "action",
|
|
1599
1612
|
label: row.an,
|
|
1600
|
-
sub: dispatched_action && dispatched_action
|
|
1601
|
-
guards: dispatched_action
|
|
1613
|
+
sub: dispatched_action && rules_of(dispatched_action) ? "guarded" : void 0,
|
|
1614
|
+
guards: dispatched_action ? rules_of(dispatched_action) : void 0,
|
|
1602
1615
|
file: row.target_state?.file,
|
|
1603
1616
|
emits: dispatched_action?.emits
|
|
1604
1617
|
});
|
|
@@ -1918,8 +1931,8 @@ function compute_layout(view_model) {
|
|
|
1918
1931
|
pos: { x: cx, y: actY },
|
|
1919
1932
|
type: "action",
|
|
1920
1933
|
label: action.name,
|
|
1921
|
-
sub: action
|
|
1922
|
-
guards: action
|
|
1934
|
+
sub: rules_of(action) ? "guarded" : void 0,
|
|
1935
|
+
guards: rules_of(action),
|
|
1923
1936
|
file: action_file_map.get(action.name) ?? st.file,
|
|
1924
1937
|
emits: action.emits
|
|
1925
1938
|
});
|
|
@@ -2064,8 +2077,8 @@ function compute_layout(view_model) {
|
|
|
2064
2077
|
pos: { x: cx, y: actY },
|
|
2065
2078
|
type: "action",
|
|
2066
2079
|
label: action.name,
|
|
2067
|
-
sub: action
|
|
2068
|
-
guards: action
|
|
2080
|
+
sub: rules_of(action) ? "guarded" : void 0,
|
|
2081
|
+
guards: rules_of(action),
|
|
2069
2082
|
emits: action.emits
|
|
2070
2083
|
});
|
|
2071
2084
|
for (const en of action.emits) {
|
|
@@ -2183,6 +2196,8 @@ function formatModelTree(model) {
|
|
|
2183
2196
|
let line = ` ${a.name} \u2192 [${a.emits.join(", ")}]`;
|
|
2184
2197
|
if (a.invariants.length)
|
|
2185
2198
|
line += ` guards: [${a.invariants.join(", ")}]`;
|
|
2199
|
+
if (a.preconditions?.length)
|
|
2200
|
+
line += ` requires: [${a.preconditions.join(", ")}]`;
|
|
2186
2201
|
lines.push(line);
|
|
2187
2202
|
}
|
|
2188
2203
|
}
|
|
@@ -2433,7 +2448,7 @@ function Diagram({
|
|
|
2433
2448
|
title: "@rotorsoft/act-diagram version",
|
|
2434
2449
|
children: [
|
|
2435
2450
|
"v",
|
|
2436
|
-
"1.
|
|
2451
|
+
"1.2.0"
|
|
2437
2452
|
]
|
|
2438
2453
|
}
|
|
2439
2454
|
)
|