@rotorsoft/act-diagram 0.3.10 → 1.0.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 +117 -152
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/colors.d.ts +19 -0
- package/dist/@types/cli/colors.d.ts.map +1 -0
- package/dist/@types/cli/contract-index.d.ts +57 -0
- package/dist/@types/cli/contract-index.d.ts.map +1 -0
- package/dist/@types/cli/format.d.ts +22 -0
- package/dist/@types/cli/format.d.ts.map +1 -0
- package/dist/@types/cli/index.d.ts +32 -0
- package/dist/@types/cli/index.d.ts.map +1 -0
- package/dist/@types/cli/json-schema.d.ts +13 -0
- package/dist/@types/cli/json-schema.d.ts.map +1 -0
- package/dist/@types/cli/load-project.d.ts +15 -0
- package/dist/@types/cli/load-project.d.ts.map +1 -0
- package/dist/@types/cli/markdown.d.ts +3 -0
- package/dist/@types/cli/markdown.d.ts.map +1 -0
- package/dist/@types/cli/open-editor.d.ts +23 -0
- package/dist/@types/cli/open-editor.d.ts.map +1 -0
- package/dist/@types/cli/repl.d.ts +3 -0
- package/dist/@types/cli/repl.d.ts.map +1 -0
- package/dist/@types/cli/vim-keys.d.ts +34 -0
- package/dist/@types/cli/vim-keys.d.ts.map +1 -0
- 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 +6 -0
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/schema-extract.d.ts +37 -0
- package/dist/@types/client/lib/schema-extract.d.ts.map +1 -0
- package/dist/@types/client/types/domain-model.d.ts +15 -0
- package/dist/@types/client/types/domain-model.d.ts.map +1 -1
- package/dist/cli/act.js +3324 -0
- package/dist/cli/act.js.map +1 -0
- package/dist/index.cjs +413 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +413 -39
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2 -2
- package/package.json +14 -8
package/dist/index.js
CHANGED
|
@@ -4,6 +4,280 @@ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2
|
|
|
4
4
|
// src/client/lib/evaluate.ts
|
|
5
5
|
import { transform } from "sucrase";
|
|
6
6
|
|
|
7
|
+
// src/client/lib/schema-extract.ts
|
|
8
|
+
var isWS = (c) => c === " " || c === " " || c === "\n" || c === "\r";
|
|
9
|
+
var isIdent = (c) => !!c && /[\w$]/.test(c);
|
|
10
|
+
function skipTrivia(src, from) {
|
|
11
|
+
let i = from;
|
|
12
|
+
while (i < src.length) {
|
|
13
|
+
const c = src[i];
|
|
14
|
+
if (isWS(c)) {
|
|
15
|
+
i++;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
19
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
23
|
+
i += 2;
|
|
24
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
25
|
+
i++;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
return i;
|
|
31
|
+
}
|
|
32
|
+
function readValue(src, start) {
|
|
33
|
+
let i = start;
|
|
34
|
+
let depth = 0;
|
|
35
|
+
while (i < src.length) {
|
|
36
|
+
const c = src[i];
|
|
37
|
+
if (c === '"' || c === "'") {
|
|
38
|
+
const q = c;
|
|
39
|
+
i++;
|
|
40
|
+
while (i < src.length && src[i] !== q) {
|
|
41
|
+
if (src[i] === "\\") {
|
|
42
|
+
i += 2;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
i++;
|
|
46
|
+
}
|
|
47
|
+
i++;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (c === "`") {
|
|
51
|
+
i++;
|
|
52
|
+
while (i < src.length && src[i] !== "`") {
|
|
53
|
+
if (src[i] === "\\") {
|
|
54
|
+
i += 2;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (src[i] === "$" && src[i + 1] === "{") {
|
|
58
|
+
let td = 1;
|
|
59
|
+
i += 2;
|
|
60
|
+
while (i < src.length && td > 0) {
|
|
61
|
+
if (src[i] === "{") td++;
|
|
62
|
+
else if (src[i] === "}") td--;
|
|
63
|
+
if (td > 0) i++;
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
i++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
74
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
78
|
+
i += 2;
|
|
79
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (c === "(" || c === "{" || c === "[") {
|
|
84
|
+
depth++;
|
|
85
|
+
i++;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (c === ")" || c === "]") {
|
|
89
|
+
depth--;
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (c === "}") {
|
|
94
|
+
if (depth === 0) return i;
|
|
95
|
+
depth--;
|
|
96
|
+
i++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (c === "," && depth === 0) return i;
|
|
100
|
+
i++;
|
|
101
|
+
}
|
|
102
|
+
return i;
|
|
103
|
+
}
|
|
104
|
+
function parseObjectLiteral(src, startBrace) {
|
|
105
|
+
const entries = [];
|
|
106
|
+
let i = startBrace + 1;
|
|
107
|
+
while (i < src.length) {
|
|
108
|
+
i = skipTrivia(src, i);
|
|
109
|
+
if (src[i] === "}") return { entries, endBrace: i };
|
|
110
|
+
let key = "";
|
|
111
|
+
let keyStart = i;
|
|
112
|
+
let keyEnd = i;
|
|
113
|
+
let keyWasIdentifier = false;
|
|
114
|
+
if (src[i] === '"' || src[i] === "'") {
|
|
115
|
+
const q = src[i];
|
|
116
|
+
keyStart = ++i;
|
|
117
|
+
while (i < src.length && src[i] !== q) {
|
|
118
|
+
if (src[i] === "\\") {
|
|
119
|
+
i += 2;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
i++;
|
|
123
|
+
}
|
|
124
|
+
key = src.slice(keyStart, i);
|
|
125
|
+
keyEnd = i;
|
|
126
|
+
i++;
|
|
127
|
+
} else if (isIdent(src[i])) {
|
|
128
|
+
keyStart = i;
|
|
129
|
+
while (isIdent(src[i])) i++;
|
|
130
|
+
key = src.slice(keyStart, i);
|
|
131
|
+
keyEnd = i;
|
|
132
|
+
keyWasIdentifier = true;
|
|
133
|
+
} else {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
i = skipTrivia(src, i);
|
|
137
|
+
if (src[i] !== ":") {
|
|
138
|
+
if (keyWasIdentifier) {
|
|
139
|
+
entries.push({ key, valueStart: keyStart, valueEnd: keyEnd });
|
|
140
|
+
}
|
|
141
|
+
while (i < src.length && src[i] !== "," && src[i] !== "}") i++;
|
|
142
|
+
if (src[i] === ",") i++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
i++;
|
|
146
|
+
i = skipTrivia(src, i);
|
|
147
|
+
const valueStart = i;
|
|
148
|
+
const valueEnd = readValue(src, i);
|
|
149
|
+
entries.push({ key, valueStart, valueEnd });
|
|
150
|
+
i = valueEnd;
|
|
151
|
+
if (src[i] === ",") i++;
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
function readTopLevelExpression(src, start) {
|
|
156
|
+
let i = start;
|
|
157
|
+
let depth = 0;
|
|
158
|
+
while (i < src.length) {
|
|
159
|
+
const c = src[i];
|
|
160
|
+
if (c === '"' || c === "'") {
|
|
161
|
+
const q = c;
|
|
162
|
+
i++;
|
|
163
|
+
while (i < src.length && src[i] !== q) {
|
|
164
|
+
if (src[i] === "\\") {
|
|
165
|
+
i += 2;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
i++;
|
|
169
|
+
}
|
|
170
|
+
i++;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (c === "`") {
|
|
174
|
+
i++;
|
|
175
|
+
while (i < src.length && src[i] !== "`") {
|
|
176
|
+
if (src[i] === "\\") {
|
|
177
|
+
i += 2;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (src[i] === "$" && src[i + 1] === "{") {
|
|
181
|
+
let td = 1;
|
|
182
|
+
i += 2;
|
|
183
|
+
while (i < src.length && td > 0) {
|
|
184
|
+
if (src[i] === "{") td++;
|
|
185
|
+
else if (src[i] === "}") td--;
|
|
186
|
+
if (td > 0) i++;
|
|
187
|
+
}
|
|
188
|
+
i++;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
i++;
|
|
192
|
+
}
|
|
193
|
+
i++;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
197
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
201
|
+
i += 2;
|
|
202
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
203
|
+
i++;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (c === "(" || c === "{" || c === "[") {
|
|
207
|
+
depth++;
|
|
208
|
+
i++;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (c === ")" || c === "}" || c === "]") {
|
|
212
|
+
depth--;
|
|
213
|
+
i++;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (c === ";" && depth === 0) return i;
|
|
217
|
+
i++;
|
|
218
|
+
}
|
|
219
|
+
return i;
|
|
220
|
+
}
|
|
221
|
+
function extractIdentifierAssignments(src) {
|
|
222
|
+
const out = /* @__PURE__ */ new Map();
|
|
223
|
+
const re = /(?:^|[^\w$])(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n;]{1,256})?=\s*/gm;
|
|
224
|
+
let m;
|
|
225
|
+
while ((m = re.exec(src)) !== null) {
|
|
226
|
+
const ident = m[1];
|
|
227
|
+
if (out.has(ident)) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const start = m.index + m[0].length;
|
|
231
|
+
const end = readTopLevelExpression(src, start);
|
|
232
|
+
const text = src.slice(start, end).trim();
|
|
233
|
+
if (text) out.set(ident, text);
|
|
234
|
+
re.lastIndex = end;
|
|
235
|
+
}
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
function findIdentifierObjectLiteral(src, ident) {
|
|
239
|
+
const re = new RegExp(
|
|
240
|
+
`(?:^|[^\\w$])(?:const|let|var)\\s+${ident}\\b\\s*(?::[^=\\n;]+)?=\\s*`,
|
|
241
|
+
"m"
|
|
242
|
+
);
|
|
243
|
+
const m = re.exec(src);
|
|
244
|
+
if (!m) return -1;
|
|
245
|
+
const after = m.index + m[0].length;
|
|
246
|
+
const skipped = skipTrivia(src, after);
|
|
247
|
+
return src[skipped] === "{" ? skipped : -1;
|
|
248
|
+
}
|
|
249
|
+
var BARE_IDENT_RE = /^[A-Za-z_$][\w$]*$/;
|
|
250
|
+
function extractSchemasFromSource(src, eventNames, external) {
|
|
251
|
+
const out = /* @__PURE__ */ new Map();
|
|
252
|
+
if (!src || eventNames.size === 0) return out;
|
|
253
|
+
const localIdents = extractIdentifierAssignments(src);
|
|
254
|
+
const deref = (text) => BARE_IDENT_RE.test(text) ? localIdents.get(text) ?? external?.get(text) ?? text : text;
|
|
255
|
+
const emitsRe = /\.emits\s*\(/g;
|
|
256
|
+
let m;
|
|
257
|
+
while ((m = emitsRe.exec(src)) !== null) {
|
|
258
|
+
let i = skipTrivia(src, emitsRe.lastIndex);
|
|
259
|
+
if (isIdent(src[i])) {
|
|
260
|
+
const start = i;
|
|
261
|
+
while (isIdent(src[i])) i++;
|
|
262
|
+
const ident = src.slice(start, i);
|
|
263
|
+
const objStart = findIdentifierObjectLiteral(src, ident);
|
|
264
|
+
if (objStart < 0) continue;
|
|
265
|
+
i = objStart;
|
|
266
|
+
}
|
|
267
|
+
if (src[i] !== "{") continue;
|
|
268
|
+
const parsed = parseObjectLiteral(src, i);
|
|
269
|
+
if (!parsed) continue;
|
|
270
|
+
for (const e of parsed.entries) {
|
|
271
|
+
if (!eventNames.has(e.key)) continue;
|
|
272
|
+
const raw = src.slice(e.valueStart, e.valueEnd).trim();
|
|
273
|
+
const text = deref(raw);
|
|
274
|
+
if (text) out.set(e.key, text);
|
|
275
|
+
}
|
|
276
|
+
emitsRe.lastIndex = Math.max(emitsRe.lastIndex, parsed.endBrace + 1);
|
|
277
|
+
}
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
|
|
7
281
|
// src/client/lib/build-model.ts
|
|
8
282
|
var _stateIdx = 0;
|
|
9
283
|
function buildState(model, st) {
|
|
@@ -24,7 +298,10 @@ function buildState(model, st) {
|
|
|
24
298
|
for (const eventName of Object.keys(events)) {
|
|
25
299
|
eventNodes.push({
|
|
26
300
|
name: eventName,
|
|
27
|
-
hasCustomPatch: st.patches?.has(eventName) ?? false
|
|
301
|
+
hasCustomPatch: st.patches?.has(eventName) ?? false,
|
|
302
|
+
// Stash the runtime Zod schema so the JSON Schema exporter can
|
|
303
|
+
// call `z.toJSONSchema(zod)` later without re-running the parser.
|
|
304
|
+
zod: events[eventName]
|
|
28
305
|
});
|
|
29
306
|
}
|
|
30
307
|
const actionNodes = [];
|
|
@@ -145,13 +422,17 @@ function buildModel(result, files, expectedSlices) {
|
|
|
145
422
|
for (const p of s.projections ?? []) {
|
|
146
423
|
if (p && p._tag === "Projection") projNames.push(p.target);
|
|
147
424
|
}
|
|
425
|
+
const sliceFile = s._sourceFile;
|
|
148
426
|
model.slices.push({
|
|
149
427
|
name: sliceName,
|
|
150
428
|
states: sliceStateKeys,
|
|
151
429
|
stateVars: sliceStateKeys,
|
|
152
430
|
projections: projNames,
|
|
153
|
-
reactions: s.reactions ?? []
|
|
154
|
-
|
|
431
|
+
reactions: (s.reactions ?? []).map((r) => ({
|
|
432
|
+
...r,
|
|
433
|
+
file: r.file ?? sliceFile
|
|
434
|
+
})),
|
|
435
|
+
file: sliceFile,
|
|
155
436
|
error: errors.length > 0 ? errors.join("; ") : void 0
|
|
156
437
|
});
|
|
157
438
|
} catch (e) {
|
|
@@ -180,11 +461,30 @@ function buildModel(result, files, expectedSlices) {
|
|
|
180
461
|
});
|
|
181
462
|
}
|
|
182
463
|
}
|
|
464
|
+
const sourceByPath = /* @__PURE__ */ new Map();
|
|
465
|
+
const externalIdents = /* @__PURE__ */ new Map();
|
|
466
|
+
for (const f of files) {
|
|
467
|
+
sourceByPath.set(f.path, f.content);
|
|
468
|
+
for (const [ident, expr] of extractIdentifierAssignments(f.content)) {
|
|
469
|
+
if (!externalIdents.has(ident)) externalIdents.set(ident, expr);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
for (const stNode of model.states) {
|
|
473
|
+
if (!stNode.file) continue;
|
|
474
|
+
const src = sourceByPath.get(stNode.file);
|
|
475
|
+
const names = new Set(stNode.events.map((e) => e.name));
|
|
476
|
+
if (names.size === 0) continue;
|
|
477
|
+
const schemas = extractSchemasFromSource(src, names, externalIdents);
|
|
478
|
+
for (const ev of stNode.events) {
|
|
479
|
+
ev.schema = schemas.get(ev.name);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
183
482
|
for (const p of rawProjections) {
|
|
184
483
|
model.projections.push({
|
|
185
484
|
name: p.target,
|
|
186
485
|
varName: p.target,
|
|
187
|
-
handles: p.handles
|
|
486
|
+
handles: p.handles,
|
|
487
|
+
file: p._sourceFile
|
|
188
488
|
});
|
|
189
489
|
}
|
|
190
490
|
const statesInSlices = new Set(model.slices.flatMap((s) => s.states));
|
|
@@ -203,8 +503,9 @@ function buildModel(result, files, expectedSlices) {
|
|
|
203
503
|
projections: model.projections.map((p) => p.name),
|
|
204
504
|
states: model.states.map((s) => s.name)
|
|
205
505
|
};
|
|
506
|
+
const actFile = a._sourceFile;
|
|
206
507
|
for (const r of a.reactions ?? []) {
|
|
207
|
-
model.reactions.push(r);
|
|
508
|
+
model.reactions.push({ ...r, file: r.file ?? actFile });
|
|
208
509
|
}
|
|
209
510
|
const entryPath = a._sourceFile ?? "app.ts";
|
|
210
511
|
const actSliceNames = new Set(
|
|
@@ -1185,7 +1486,7 @@ function measureChain(rDef, lookup, visited, allStates) {
|
|
|
1185
1486
|
}
|
|
1186
1487
|
return { groupH: Math.max(H, dispatchBlockH), dispatchBlockH, rows };
|
|
1187
1488
|
}
|
|
1188
|
-
function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY, ns, es, sliceName, lookup, eventProjections, eventReactions, sliceRightXRef) {
|
|
1489
|
+
function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY, ns, es, sliceName, lookup, eventProjections, eventReactions, eventSchemas, sliceRightXRef) {
|
|
1189
1490
|
const dispatchBaseX = rX + W + GAP;
|
|
1190
1491
|
const rp = { x: rX, y: reactionY };
|
|
1191
1492
|
ns.push({
|
|
@@ -1216,7 +1517,8 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1216
1517
|
label: row.an,
|
|
1217
1518
|
sub: dispatchedAction && dispatchedAction.invariants.length > 0 ? "guarded" : void 0,
|
|
1218
1519
|
guards: dispatchedAction && dispatchedAction.invariants.length > 0 ? dispatchedAction.invariants : void 0,
|
|
1219
|
-
file: row.targetState?.file
|
|
1520
|
+
file: row.targetState?.file,
|
|
1521
|
+
emits: dispatchedAction?.emits
|
|
1220
1522
|
});
|
|
1221
1523
|
es.push({
|
|
1222
1524
|
from: { x: rp.x + W, y: rp.y + H / 2 },
|
|
@@ -1247,7 +1549,8 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1247
1549
|
label: emit.name,
|
|
1248
1550
|
file: row.targetState?.file,
|
|
1249
1551
|
projections: eventProjections.get(emit.name),
|
|
1250
|
-
reactions: eventReactions.get(emit.name)
|
|
1552
|
+
reactions: eventReactions.get(emit.name),
|
|
1553
|
+
schema: eventSchemas.get(emit.name)
|
|
1251
1554
|
});
|
|
1252
1555
|
if (emit.subChain && emit.subReaction) {
|
|
1253
1556
|
const subRX = evtX + W + GAP * 3;
|
|
@@ -1265,6 +1568,7 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1265
1568
|
lookup,
|
|
1266
1569
|
eventProjections,
|
|
1267
1570
|
eventReactions,
|
|
1571
|
+
eventSchemas,
|
|
1268
1572
|
sliceRightXRef
|
|
1269
1573
|
);
|
|
1270
1574
|
}
|
|
@@ -1286,6 +1590,18 @@ function computeLayout(viewModel) {
|
|
|
1286
1590
|
}
|
|
1287
1591
|
const eventProjections = /* @__PURE__ */ new Map();
|
|
1288
1592
|
const eventReactions = /* @__PURE__ */ new Map();
|
|
1593
|
+
const eventSchemas = /* @__PURE__ */ new Map();
|
|
1594
|
+
for (const s of viewModel.states) {
|
|
1595
|
+
for (const e of s.events) {
|
|
1596
|
+
if (e.schema && !eventSchemas.has(e.name)) {
|
|
1597
|
+
eventSchemas.set(e.name, e.schema);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
const projectionHandles = /* @__PURE__ */ new Map();
|
|
1602
|
+
for (const proj of viewModel.projections) {
|
|
1603
|
+
projectionHandles.set(proj.name, proj.handles);
|
|
1604
|
+
}
|
|
1289
1605
|
for (const slice of viewModel.slices) {
|
|
1290
1606
|
for (const r of slice.reactions) {
|
|
1291
1607
|
const list = eventReactions.get(r.event) ?? [];
|
|
@@ -1451,7 +1767,8 @@ function computeLayout(viewModel) {
|
|
|
1451
1767
|
label: en,
|
|
1452
1768
|
file: eventFileMap.get(en) ?? st.file,
|
|
1453
1769
|
projections: eventProjections.get(en),
|
|
1454
|
-
reactions: eventReactions.get(en)
|
|
1770
|
+
reactions: eventReactions.get(en),
|
|
1771
|
+
schema: eventSchemas.get(en)
|
|
1455
1772
|
});
|
|
1456
1773
|
eventYMap.set(en, evtY);
|
|
1457
1774
|
for (const { chain, reaction: chainReaction } of chains) {
|
|
@@ -1473,6 +1790,7 @@ function computeLayout(viewModel) {
|
|
|
1473
1790
|
sliceReactionByEvent,
|
|
1474
1791
|
eventProjections,
|
|
1475
1792
|
eventReactions,
|
|
1793
|
+
eventSchemas,
|
|
1476
1794
|
sliceRightXRef
|
|
1477
1795
|
);
|
|
1478
1796
|
for (let ni = chainStartIdx; ni < ns.length; ni++) {
|
|
@@ -1494,7 +1812,8 @@ function computeLayout(viewModel) {
|
|
|
1494
1812
|
key: `p:${pn}:${slice.name}`,
|
|
1495
1813
|
pos: { x: eventColX, y: evtY },
|
|
1496
1814
|
type: "projection",
|
|
1497
|
-
label: pn
|
|
1815
|
+
label: pn,
|
|
1816
|
+
handles: projectionHandles.get(pn)
|
|
1498
1817
|
});
|
|
1499
1818
|
evtY += H + GAP / 2;
|
|
1500
1819
|
}
|
|
@@ -1519,7 +1838,8 @@ function computeLayout(viewModel) {
|
|
|
1519
1838
|
label: action.name,
|
|
1520
1839
|
sub: action.invariants.length > 0 ? "guarded" : void 0,
|
|
1521
1840
|
guards: action.invariants.length > 0 ? action.invariants : void 0,
|
|
1522
|
-
file: actionFileMap.get(action.name) ?? st.file
|
|
1841
|
+
file: actionFileMap.get(action.name) ?? st.file,
|
|
1842
|
+
emits: action.emits
|
|
1523
1843
|
});
|
|
1524
1844
|
for (const en of action.emits) {
|
|
1525
1845
|
const ey = eventYMap.get(en);
|
|
@@ -1625,7 +1945,8 @@ function computeLayout(viewModel) {
|
|
|
1625
1945
|
type: "event",
|
|
1626
1946
|
label: en,
|
|
1627
1947
|
projections: eventProjections.get(en),
|
|
1628
|
-
reactions: eventReactions.get(en)
|
|
1948
|
+
reactions: eventReactions.get(en),
|
|
1949
|
+
schema: eventSchemas.get(en)
|
|
1629
1950
|
});
|
|
1630
1951
|
eventYMap.set(en, evtY);
|
|
1631
1952
|
evtY += H + GAP / 2;
|
|
@@ -1638,7 +1959,8 @@ function computeLayout(viewModel) {
|
|
|
1638
1959
|
type: "event",
|
|
1639
1960
|
label: en,
|
|
1640
1961
|
projections: eventProjections.get(en),
|
|
1641
|
-
reactions: eventReactions.get(en)
|
|
1962
|
+
reactions: eventReactions.get(en),
|
|
1963
|
+
schema: eventSchemas.get(en)
|
|
1642
1964
|
});
|
|
1643
1965
|
eventYMap.set(en, evtY);
|
|
1644
1966
|
evtY += H + GAP / 2;
|
|
@@ -1661,7 +1983,8 @@ function computeLayout(viewModel) {
|
|
|
1661
1983
|
type: "action",
|
|
1662
1984
|
label: action.name,
|
|
1663
1985
|
sub: action.invariants.length > 0 ? "guarded" : void 0,
|
|
1664
|
-
guards: action.invariants.length > 0 ? action.invariants : void 0
|
|
1986
|
+
guards: action.invariants.length > 0 ? action.invariants : void 0,
|
|
1987
|
+
emits: action.emits
|
|
1665
1988
|
});
|
|
1666
1989
|
for (const en of action.emits) {
|
|
1667
1990
|
const ey = eventYMap.get(en);
|
|
@@ -1822,9 +2145,15 @@ function Diagram({
|
|
|
1822
2145
|
onFixWithAi,
|
|
1823
2146
|
toolbarExtra
|
|
1824
2147
|
}) {
|
|
1825
|
-
const [tip, setTip] = useState2(
|
|
1826
|
-
|
|
1827
|
-
|
|
2148
|
+
const [tip, setTip] = useState2(null);
|
|
2149
|
+
const KIND_TEXT = {
|
|
2150
|
+
event: "text-orange-300",
|
|
2151
|
+
action: "text-blue-300",
|
|
2152
|
+
state: "text-yellow-300",
|
|
2153
|
+
projection: "text-emerald-300",
|
|
2154
|
+
reaction: "text-fuchsia-300",
|
|
2155
|
+
error: "text-red-300"
|
|
2156
|
+
};
|
|
1828
2157
|
const [activeTab, setActiveTab] = useState2(0);
|
|
1829
2158
|
const [showTree, setShowTree] = useState2(false);
|
|
1830
2159
|
const [showWarnings, setShowWarnings] = useState2(false);
|
|
@@ -2014,7 +2343,18 @@ function Diagram({
|
|
|
2014
2343
|
]
|
|
2015
2344
|
}
|
|
2016
2345
|
),
|
|
2017
|
-
toolbarExtra
|
|
2346
|
+
toolbarExtra,
|
|
2347
|
+
/* @__PURE__ */ jsxs2(
|
|
2348
|
+
"span",
|
|
2349
|
+
{
|
|
2350
|
+
className: "select-none font-mono text-[9px] text-zinc-600",
|
|
2351
|
+
title: "@rotorsoft/act-diagram version",
|
|
2352
|
+
children: [
|
|
2353
|
+
"v",
|
|
2354
|
+
"0.4.0"
|
|
2355
|
+
]
|
|
2356
|
+
}
|
|
2357
|
+
)
|
|
2018
2358
|
] })
|
|
2019
2359
|
] }),
|
|
2020
2360
|
model.entries.length > 1 && /* @__PURE__ */ jsx2("div", { className: "flex gap-px border-b border-zinc-800 bg-zinc-900", children: model.entries.map((e, i) => /* @__PURE__ */ jsx2(
|
|
@@ -2258,17 +2598,28 @@ ${prompt}`);
|
|
|
2258
2598
|
className: "cursor-pointer",
|
|
2259
2599
|
onClick: () => onClickElement?.(n.label, n.type, n.file),
|
|
2260
2600
|
onMouseEnter: (ev) => {
|
|
2261
|
-
const
|
|
2601
|
+
const sections = [];
|
|
2602
|
+
if (n.emits?.length)
|
|
2603
|
+
sections.push({ label: "Emits", items: n.emits });
|
|
2604
|
+
if (n.handles?.length)
|
|
2605
|
+
sections.push({ label: "Handles", items: n.handles });
|
|
2262
2606
|
if (n.guards?.length)
|
|
2263
|
-
|
|
2607
|
+
sections.push({ label: "Guards", items: n.guards });
|
|
2264
2608
|
if (n.reactions?.length)
|
|
2265
|
-
|
|
2609
|
+
sections.push({ label: "Reactions", items: n.reactions });
|
|
2266
2610
|
if (n.projections?.length)
|
|
2267
|
-
|
|
2611
|
+
sections.push({
|
|
2612
|
+
label: "Projections",
|
|
2613
|
+
items: n.projections
|
|
2614
|
+
});
|
|
2268
2615
|
setTip({
|
|
2269
2616
|
x: ev.clientX,
|
|
2270
2617
|
y: ev.clientY,
|
|
2271
|
-
|
|
2618
|
+
kind: n.type,
|
|
2619
|
+
title: n.label,
|
|
2620
|
+
schema: n.schema,
|
|
2621
|
+
sections,
|
|
2622
|
+
file: n.file
|
|
2272
2623
|
});
|
|
2273
2624
|
},
|
|
2274
2625
|
onMouseLeave: () => setTip(null),
|
|
@@ -2488,25 +2839,48 @@ ${prompt}`);
|
|
|
2488
2839
|
] }) })
|
|
2489
2840
|
}
|
|
2490
2841
|
),
|
|
2491
|
-
tip && /* @__PURE__ */
|
|
2842
|
+
tip && /* @__PURE__ */ jsxs2(
|
|
2492
2843
|
"div",
|
|
2493
2844
|
{
|
|
2494
|
-
className: "pointer-events-none fixed z-50 max-w-
|
|
2845
|
+
className: "pointer-events-none fixed z-50 max-w-sm rounded-lg border border-zinc-700 bg-zinc-900 px-3 py-2 shadow-2xl",
|
|
2495
2846
|
style: { left: tip.x + 14, top: tip.y - 12 },
|
|
2496
|
-
children:
|
|
2497
|
-
"
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
/* @__PURE__ */ jsxs2(
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2847
|
+
children: [
|
|
2848
|
+
tip.t && tip.t.split("\n").map((line, i) => /* @__PURE__ */ jsx2(
|
|
2849
|
+
"div",
|
|
2850
|
+
{
|
|
2851
|
+
className: i === 0 ? "text-[11px] font-medium text-zinc-200" : "mt-0.5 text-[9px] text-zinc-400",
|
|
2852
|
+
children: i > 0 && line.includes(":") ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
2853
|
+
/* @__PURE__ */ jsxs2("span", { className: "text-zinc-500", children: [
|
|
2854
|
+
line.split(":")[0],
|
|
2855
|
+
":"
|
|
2856
|
+
] }),
|
|
2857
|
+
/* @__PURE__ */ jsx2("span", { className: "text-zinc-300", children: line.slice(line.indexOf(":") + 1) })
|
|
2858
|
+
] }) : line
|
|
2859
|
+
},
|
|
2860
|
+
i
|
|
2861
|
+
)),
|
|
2862
|
+
tip.title && tip.kind && /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
2863
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-baseline gap-1.5", children: [
|
|
2864
|
+
/* @__PURE__ */ jsx2(
|
|
2865
|
+
"span",
|
|
2866
|
+
{
|
|
2867
|
+
className: `text-[9px] font-medium uppercase tracking-wide ${KIND_TEXT[tip.kind]}`,
|
|
2868
|
+
children: tip.kind
|
|
2869
|
+
}
|
|
2870
|
+
),
|
|
2871
|
+
/* @__PURE__ */ jsx2("span", { className: "text-[12px] font-semibold text-zinc-100", children: tip.title })
|
|
2872
|
+
] }),
|
|
2873
|
+
tip.schema && /* @__PURE__ */ jsxs2("div", { className: "mt-1.5", children: [
|
|
2874
|
+
/* @__PURE__ */ jsx2("div", { className: "text-[9px] uppercase tracking-wide text-zinc-500", children: "Schema" }),
|
|
2875
|
+
/* @__PURE__ */ jsx2("pre", { className: "mt-0.5 max-h-48 overflow-auto rounded border border-zinc-800 bg-zinc-950 px-2 py-1 font-mono text-[10px] leading-snug text-zinc-300 whitespace-pre", children: tip.schema })
|
|
2876
|
+
] }),
|
|
2877
|
+
tip.sections && tip.sections.length > 0 && /* @__PURE__ */ jsx2("table", { className: "mt-1.5 w-full text-[10px] leading-snug", children: /* @__PURE__ */ jsx2("tbody", { children: tip.sections.map((s) => /* @__PURE__ */ jsxs2("tr", { children: [
|
|
2878
|
+
/* @__PURE__ */ jsx2("td", { className: "w-[68px] shrink-0 pr-2 align-top text-zinc-500", children: s.label }),
|
|
2879
|
+
/* @__PURE__ */ jsx2("td", { className: "align-top text-zinc-300", children: s.items.join(", ") })
|
|
2880
|
+
] }, s.label)) }) }),
|
|
2881
|
+
tip.file && /* @__PURE__ */ jsx2("div", { className: "mt-1.5 border-t border-zinc-800 pt-1 text-[9px] text-zinc-500", children: tip.file })
|
|
2882
|
+
] })
|
|
2883
|
+
]
|
|
2510
2884
|
}
|
|
2511
2885
|
)
|
|
2512
2886
|
] });
|