@rotorsoft/act-diagram 1.0.0 → 1.0.2
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/colors.d.ts +1 -1
- package/dist/@types/cli/colors.d.ts.map +1 -1
- package/dist/@types/cli/contract-index.d.ts +6 -6
- package/dist/@types/cli/contract-index.d.ts.map +1 -1
- package/dist/@types/cli/format.d.ts +9 -9
- package/dist/@types/cli/format.d.ts.map +1 -1
- package/dist/@types/cli/index.d.ts +9 -9
- package/dist/@types/cli/index.d.ts.map +1 -1
- package/dist/@types/cli/json-schema.d.ts +1 -1
- package/dist/@types/cli/json-schema.d.ts.map +1 -1
- package/dist/@types/cli/load-project.d.ts +3 -3
- package/dist/@types/cli/load-project.d.ts.map +1 -1
- package/dist/@types/cli/markdown.d.ts +1 -1
- package/dist/@types/cli/markdown.d.ts.map +1 -1
- package/dist/@types/cli/open-editor.d.ts +4 -4
- package/dist/@types/cli/open-editor.d.ts.map +1 -1
- package/dist/@types/cli/repl.d.ts +1 -1
- package/dist/@types/cli/repl.d.ts.map +1 -1
- package/dist/@types/cli/vim-keys.d.ts +1 -1
- package/dist/@types/cli/vim-keys.d.ts.map +1 -1
- package/dist/@types/client/components/ActDiagram.d.ts +1 -1
- package/dist/@types/client/components/ActDiagram.d.ts.map +1 -1
- package/dist/@types/client/components/AiBar.d.ts +1 -1
- package/dist/@types/client/components/AiBar.d.ts.map +1 -1
- package/dist/@types/client/components/CodePreview.d.ts +2 -2
- package/dist/@types/client/components/CodePreview.d.ts.map +1 -1
- package/dist/@types/client/components/Diagram.d.ts +1 -1
- package/dist/@types/client/components/Diagram.d.ts.map +1 -1
- package/dist/@types/client/components/Logo.d.ts +1 -1
- package/dist/@types/client/components/Logo.d.ts.map +1 -1
- package/dist/@types/client/components/Tooltip.d.ts +1 -1
- package/dist/@types/client/components/Tooltip.d.ts.map +1 -1
- package/dist/@types/client/lib/build-model.d.ts +2 -2
- package/dist/@types/client/lib/build-model.d.ts.map +1 -1
- package/dist/@types/client/lib/evaluate.d.ts +2 -2
- package/dist/@types/client/lib/evaluate.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts +1 -1
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/mock-builders.d.ts +6 -6
- package/dist/@types/client/lib/mock-builders.d.ts.map +1 -1
- package/dist/@types/client/lib/navigate.d.ts +1 -1
- package/dist/@types/client/lib/navigate.d.ts.map +1 -1
- package/dist/@types/client/lib/schema-extract.d.ts +4 -4
- package/dist/@types/client/lib/schema-extract.d.ts.map +1 -1
- package/dist/@types/client/lib/sort.d.ts +1 -1
- package/dist/@types/client/lib/sort.d.ts.map +1 -1
- package/dist/@types/client/lib/strip-fences.d.ts +3 -3
- package/dist/@types/client/lib/strip-fences.d.ts.map +1 -1
- package/dist/@types/index.d.ts +0 -6
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cli/act.js +1515 -1310
- package/dist/cli/act.js.map +1 -1
- package/dist/index.cjs +640 -704
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +640 -696
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -25,15 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
Diagram: () => Diagram,
|
|
26
26
|
Logo: () => Logo,
|
|
27
27
|
Tooltip: () => Tooltip,
|
|
28
|
-
buildModel: () => buildModel,
|
|
29
|
-
computeLayout: () => computeLayout,
|
|
30
|
-
deriveProjectName: () => deriveProjectName,
|
|
31
28
|
emptyModel: () => emptyModel2,
|
|
32
|
-
extractModel: () => extractModel,
|
|
33
|
-
navigateToCode: () => navigateToCode,
|
|
34
|
-
parseMultiFileResponse: () => parseMultiFileResponse,
|
|
35
|
-
stripFences: () => stripFences,
|
|
36
|
-
topoSort: () => topoSort,
|
|
37
29
|
validate: () => validate
|
|
38
30
|
});
|
|
39
31
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -45,13 +37,13 @@ var import_react3 = require("react");
|
|
|
45
37
|
var import_sucrase = require("sucrase");
|
|
46
38
|
|
|
47
39
|
// src/client/lib/schema-extract.ts
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
function
|
|
40
|
+
var is_w_s = (c) => c === " " || c === " " || c === "\n" || c === "\r";
|
|
41
|
+
var is_ident = (c) => !!c && /[\w$]/.test(c);
|
|
42
|
+
function skip_trivia(src, from) {
|
|
51
43
|
let i = from;
|
|
52
44
|
while (i < src.length) {
|
|
53
45
|
const c = src[i];
|
|
54
|
-
if (
|
|
46
|
+
if (is_w_s(c)) {
|
|
55
47
|
i++;
|
|
56
48
|
continue;
|
|
57
49
|
}
|
|
@@ -69,7 +61,7 @@ function skipTrivia(src, from) {
|
|
|
69
61
|
}
|
|
70
62
|
return i;
|
|
71
63
|
}
|
|
72
|
-
function
|
|
64
|
+
function read_value(src, start) {
|
|
73
65
|
let i = start;
|
|
74
66
|
let depth = 0;
|
|
75
67
|
while (i < src.length) {
|
|
@@ -141,19 +133,19 @@ function readValue(src, start) {
|
|
|
141
133
|
}
|
|
142
134
|
return i;
|
|
143
135
|
}
|
|
144
|
-
function
|
|
136
|
+
function parse_object_literal(src, start_brace) {
|
|
145
137
|
const entries = [];
|
|
146
|
-
let i =
|
|
138
|
+
let i = start_brace + 1;
|
|
147
139
|
while (i < src.length) {
|
|
148
|
-
i =
|
|
149
|
-
if (src[i] === "}") return { entries,
|
|
140
|
+
i = skip_trivia(src, i);
|
|
141
|
+
if (src[i] === "}") return { entries, end_brace: i };
|
|
150
142
|
let key = "";
|
|
151
|
-
let
|
|
152
|
-
let
|
|
153
|
-
let
|
|
143
|
+
let key_start = i;
|
|
144
|
+
let key_end = i;
|
|
145
|
+
let key_was_identifier = false;
|
|
154
146
|
if (src[i] === '"' || src[i] === "'") {
|
|
155
147
|
const q = src[i];
|
|
156
|
-
|
|
148
|
+
key_start = ++i;
|
|
157
149
|
while (i < src.length && src[i] !== q) {
|
|
158
150
|
if (src[i] === "\\") {
|
|
159
151
|
i += 2;
|
|
@@ -161,38 +153,38 @@ function parseObjectLiteral(src, startBrace) {
|
|
|
161
153
|
}
|
|
162
154
|
i++;
|
|
163
155
|
}
|
|
164
|
-
key = src.slice(
|
|
165
|
-
|
|
156
|
+
key = src.slice(key_start, i);
|
|
157
|
+
key_end = i;
|
|
166
158
|
i++;
|
|
167
|
-
} else if (
|
|
168
|
-
|
|
169
|
-
while (
|
|
170
|
-
key = src.slice(
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
} else if (is_ident(src[i])) {
|
|
160
|
+
key_start = i;
|
|
161
|
+
while (is_ident(src[i])) i++;
|
|
162
|
+
key = src.slice(key_start, i);
|
|
163
|
+
key_end = i;
|
|
164
|
+
key_was_identifier = true;
|
|
173
165
|
} else {
|
|
174
166
|
return null;
|
|
175
167
|
}
|
|
176
|
-
i =
|
|
168
|
+
i = skip_trivia(src, i);
|
|
177
169
|
if (src[i] !== ":") {
|
|
178
|
-
if (
|
|
179
|
-
entries.push({ key,
|
|
170
|
+
if (key_was_identifier) {
|
|
171
|
+
entries.push({ key, value_start: key_start, value_end: key_end });
|
|
180
172
|
}
|
|
181
173
|
while (i < src.length && src[i] !== "," && src[i] !== "}") i++;
|
|
182
174
|
if (src[i] === ",") i++;
|
|
183
175
|
continue;
|
|
184
176
|
}
|
|
185
177
|
i++;
|
|
186
|
-
i =
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
entries.push({ key,
|
|
190
|
-
i =
|
|
178
|
+
i = skip_trivia(src, i);
|
|
179
|
+
const value_start = i;
|
|
180
|
+
const value_end = read_value(src, i);
|
|
181
|
+
entries.push({ key, value_start, value_end });
|
|
182
|
+
i = value_end;
|
|
191
183
|
if (src[i] === ",") i++;
|
|
192
184
|
}
|
|
193
185
|
return null;
|
|
194
186
|
}
|
|
195
|
-
function
|
|
187
|
+
function read_top_level_expression(src, start) {
|
|
196
188
|
let i = start;
|
|
197
189
|
let depth = 0;
|
|
198
190
|
while (i < src.length) {
|
|
@@ -258,7 +250,7 @@ function readTopLevelExpression(src, start) {
|
|
|
258
250
|
}
|
|
259
251
|
return i;
|
|
260
252
|
}
|
|
261
|
-
function
|
|
253
|
+
function extract_identifier_assignments(src) {
|
|
262
254
|
const out = /* @__PURE__ */ new Map();
|
|
263
255
|
const re = /(?:^|[^\w$])(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n;]{1,256})?=\s*/gm;
|
|
264
256
|
let m;
|
|
@@ -268,14 +260,14 @@ function extractIdentifierAssignments(src) {
|
|
|
268
260
|
continue;
|
|
269
261
|
}
|
|
270
262
|
const start = m.index + m[0].length;
|
|
271
|
-
const end =
|
|
263
|
+
const end = read_top_level_expression(src, start);
|
|
272
264
|
const text = src.slice(start, end).trim();
|
|
273
265
|
if (text) out.set(ident, text);
|
|
274
266
|
re.lastIndex = end;
|
|
275
267
|
}
|
|
276
268
|
return out;
|
|
277
269
|
}
|
|
278
|
-
function
|
|
270
|
+
function find_identifier_object_literal(src, ident) {
|
|
279
271
|
const re = new RegExp(
|
|
280
272
|
`(?:^|[^\\w$])(?:const|let|var)\\s+${ident}\\b\\s*(?::[^=\\n;]+)?=\\s*`,
|
|
281
273
|
"m"
|
|
@@ -283,112 +275,112 @@ function findIdentifierObjectLiteral(src, ident) {
|
|
|
283
275
|
const m = re.exec(src);
|
|
284
276
|
if (!m) return -1;
|
|
285
277
|
const after = m.index + m[0].length;
|
|
286
|
-
const skipped =
|
|
278
|
+
const skipped = skip_trivia(src, after);
|
|
287
279
|
return src[skipped] === "{" ? skipped : -1;
|
|
288
280
|
}
|
|
289
281
|
var BARE_IDENT_RE = /^[A-Za-z_$][\w$]*$/;
|
|
290
|
-
function
|
|
282
|
+
function extract_schemas_from_source(src, event_names, external) {
|
|
291
283
|
const out = /* @__PURE__ */ new Map();
|
|
292
|
-
if (!src ||
|
|
293
|
-
const
|
|
294
|
-
const deref = (text) => BARE_IDENT_RE.test(text) ?
|
|
295
|
-
const
|
|
284
|
+
if (!src || event_names.size === 0) return out;
|
|
285
|
+
const local_idents = extract_identifier_assignments(src);
|
|
286
|
+
const deref = (text) => BARE_IDENT_RE.test(text) ? local_idents.get(text) ?? external?.get(text) ?? text : text;
|
|
287
|
+
const emits_re = /\.emits\s*\(/g;
|
|
296
288
|
let m;
|
|
297
|
-
while ((m =
|
|
298
|
-
let i =
|
|
299
|
-
if (
|
|
289
|
+
while ((m = emits_re.exec(src)) !== null) {
|
|
290
|
+
let i = skip_trivia(src, emits_re.lastIndex);
|
|
291
|
+
if (is_ident(src[i])) {
|
|
300
292
|
const start = i;
|
|
301
|
-
while (
|
|
293
|
+
while (is_ident(src[i])) i++;
|
|
302
294
|
const ident = src.slice(start, i);
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
i =
|
|
295
|
+
const obj_start = find_identifier_object_literal(src, ident);
|
|
296
|
+
if (obj_start < 0) continue;
|
|
297
|
+
i = obj_start;
|
|
306
298
|
}
|
|
307
299
|
if (src[i] !== "{") continue;
|
|
308
|
-
const parsed =
|
|
300
|
+
const parsed = parse_object_literal(src, i);
|
|
309
301
|
if (!parsed) continue;
|
|
310
302
|
for (const e of parsed.entries) {
|
|
311
|
-
if (!
|
|
312
|
-
const raw = src.slice(e.
|
|
303
|
+
if (!event_names.has(e.key)) continue;
|
|
304
|
+
const raw = src.slice(e.value_start, e.value_end).trim();
|
|
313
305
|
const text = deref(raw);
|
|
314
306
|
if (text) out.set(e.key, text);
|
|
315
307
|
}
|
|
316
|
-
|
|
308
|
+
emits_re.lastIndex = Math.max(emits_re.lastIndex, parsed.end_brace + 1);
|
|
317
309
|
}
|
|
318
310
|
return out;
|
|
319
311
|
}
|
|
320
312
|
|
|
321
313
|
// src/client/lib/build-model.ts
|
|
322
314
|
var _stateIdx = 0;
|
|
323
|
-
function
|
|
315
|
+
function build_state(model, st) {
|
|
324
316
|
const events = st.events ?? {};
|
|
325
317
|
for (const [name, schema] of Object.entries(events)) {
|
|
326
318
|
if (schema === void 0)
|
|
327
319
|
return { error: `Event "${name}" has undefined schema` };
|
|
328
320
|
}
|
|
329
|
-
const
|
|
330
|
-
for (const [name, schema] of Object.entries(
|
|
321
|
+
const raw_actions = st.actions ?? {};
|
|
322
|
+
for (const [name, schema] of Object.entries(raw_actions)) {
|
|
331
323
|
if (name.startsWith("__emits_")) continue;
|
|
332
324
|
if (schema === void 0)
|
|
333
325
|
return { error: `Action "${name}" has undefined schema` };
|
|
334
326
|
}
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
for (const
|
|
339
|
-
|
|
340
|
-
name:
|
|
341
|
-
hasCustomPatch: st.patches?.has(
|
|
327
|
+
const domain_name = st.name;
|
|
328
|
+
const unique_key = `${domain_name}:${_stateIdx++}`;
|
|
329
|
+
const event_nodes = [];
|
|
330
|
+
for (const event_name of Object.keys(events)) {
|
|
331
|
+
event_nodes.push({
|
|
332
|
+
name: event_name,
|
|
333
|
+
hasCustomPatch: st.patches?.has(event_name) ?? false,
|
|
342
334
|
// Stash the runtime Zod schema so the JSON Schema exporter can
|
|
343
335
|
// call `z.toJSONSchema(zod)` later without re-running the parser.
|
|
344
|
-
zod: events[
|
|
336
|
+
zod: events[event_name]
|
|
345
337
|
});
|
|
346
338
|
}
|
|
347
|
-
const
|
|
348
|
-
for (const
|
|
349
|
-
if (
|
|
350
|
-
const emits =
|
|
351
|
-
const invariants = (st.given?.[
|
|
339
|
+
const action_nodes = [];
|
|
340
|
+
for (const action_name of Object.keys(raw_actions)) {
|
|
341
|
+
if (action_name.startsWith("__emits_")) continue;
|
|
342
|
+
const emits = raw_actions[`__emits_${action_name}`] ?? [];
|
|
343
|
+
const invariants = (st.given?.[action_name] ?? []).map(
|
|
352
344
|
(inv) => inv.description ?? ""
|
|
353
345
|
);
|
|
354
|
-
|
|
346
|
+
action_nodes.push({ name: action_name, emits, invariants });
|
|
355
347
|
}
|
|
356
348
|
const node = {
|
|
357
|
-
name:
|
|
358
|
-
varName:
|
|
359
|
-
events:
|
|
360
|
-
actions:
|
|
349
|
+
name: domain_name,
|
|
350
|
+
varName: unique_key,
|
|
351
|
+
events: event_nodes,
|
|
352
|
+
actions: action_nodes,
|
|
361
353
|
file: st._sourceFile
|
|
362
354
|
};
|
|
363
355
|
model.states.push(node);
|
|
364
|
-
st._modelKey =
|
|
365
|
-
return { key:
|
|
356
|
+
st._modelKey = unique_key;
|
|
357
|
+
return { key: unique_key, node };
|
|
366
358
|
}
|
|
367
|
-
function
|
|
359
|
+
function fixup_reactions(reactions, files, source_file) {
|
|
368
360
|
const fallbacks = reactions.filter((r) => r.handlerName.startsWith("on "));
|
|
369
361
|
if (fallbacks.length === 0) return;
|
|
370
|
-
const src =
|
|
362
|
+
const src = source_file ? files.find((f) => f.path === source_file)?.content : files.map((f) => f.content).join("\n");
|
|
371
363
|
if (!src) return;
|
|
372
|
-
const
|
|
364
|
+
const do_re = /\.on\(\s*["'`](\w+)["'`]\s*\)\s*\.do\(\s*(?:async\s+)?(?:function\s+(\w+)|(?:\w+\.)?(\w+))?/g;
|
|
373
365
|
let dm;
|
|
374
|
-
while ((dm =
|
|
375
|
-
const
|
|
366
|
+
while ((dm = do_re.exec(src)) !== null) {
|
|
367
|
+
const event_name = dm[1];
|
|
376
368
|
const handlerName = dm[2] || dm[3];
|
|
377
369
|
if (!handlerName) continue;
|
|
378
370
|
const r = fallbacks.find(
|
|
379
|
-
(r2) => r2.event ===
|
|
371
|
+
(r2) => r2.event === event_name && r2.handlerName === `on ${event_name}`
|
|
380
372
|
);
|
|
381
373
|
if (r) r.handlerName = handlerName;
|
|
382
374
|
}
|
|
383
375
|
}
|
|
384
|
-
function
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
const
|
|
376
|
+
function build_model(result, files, expected_slices) {
|
|
377
|
+
const raw_states = result.states.filter((s) => s && s._tag === "State");
|
|
378
|
+
const raw_slices = result.slices.filter((s) => s && s._tag === "Slice");
|
|
379
|
+
const raw_projections = result.projections.filter(
|
|
388
380
|
(p) => p && p._tag === "Projection"
|
|
389
381
|
);
|
|
390
|
-
const
|
|
391
|
-
const
|
|
382
|
+
const raw_acts = result.acts.filter((a) => a && a._tag === "Act");
|
|
383
|
+
const state_by_ref = /* @__PURE__ */ new Map();
|
|
392
384
|
const model = {
|
|
393
385
|
entries: [],
|
|
394
386
|
states: [],
|
|
@@ -396,89 +388,89 @@ function buildModel(result, files, expectedSlices) {
|
|
|
396
388
|
projections: [],
|
|
397
389
|
reactions: []
|
|
398
390
|
};
|
|
399
|
-
for (const st of
|
|
400
|
-
if (
|
|
391
|
+
for (const st of raw_states) {
|
|
392
|
+
if (state_by_ref.has(st)) continue;
|
|
401
393
|
try {
|
|
402
|
-
|
|
394
|
+
state_by_ref.set(st, build_state(model, st));
|
|
403
395
|
} catch (e) {
|
|
404
|
-
|
|
396
|
+
state_by_ref.set(st, {
|
|
405
397
|
error: e instanceof Error ? e.message : String(e)
|
|
406
398
|
});
|
|
407
399
|
}
|
|
408
400
|
}
|
|
409
|
-
for (const a of
|
|
401
|
+
for (const a of raw_acts) {
|
|
410
402
|
for (const st of a.states ?? []) {
|
|
411
|
-
if (!st || st._tag !== "State" ||
|
|
403
|
+
if (!st || st._tag !== "State" || state_by_ref.has(st)) continue;
|
|
412
404
|
try {
|
|
413
|
-
|
|
405
|
+
state_by_ref.set(st, build_state(model, st));
|
|
414
406
|
} catch (e) {
|
|
415
|
-
|
|
407
|
+
state_by_ref.set(st, {
|
|
416
408
|
error: e instanceof Error ? e.message : String(e)
|
|
417
409
|
});
|
|
418
410
|
}
|
|
419
411
|
}
|
|
420
412
|
}
|
|
421
|
-
const
|
|
422
|
-
for (const s of
|
|
423
|
-
const
|
|
424
|
-
|
|
413
|
+
const built_slice_names = /* @__PURE__ */ new Set();
|
|
414
|
+
for (const s of raw_slices) {
|
|
415
|
+
const slice_name = s._varName ?? "slice";
|
|
416
|
+
built_slice_names.add(slice_name);
|
|
425
417
|
try {
|
|
426
418
|
try {
|
|
427
|
-
|
|
419
|
+
fixup_reactions(s.reactions, files);
|
|
428
420
|
} catch {
|
|
429
421
|
}
|
|
430
|
-
const
|
|
422
|
+
const slice_state_keys = [];
|
|
431
423
|
const errors = [];
|
|
432
424
|
for (const st of s.states ?? []) {
|
|
433
425
|
if (!st || typeof st !== "object") {
|
|
434
|
-
const fileErr = [...result.
|
|
426
|
+
const fileErr = [...result.file_errors.values()][0];
|
|
435
427
|
errors.push(fileErr ?? "Missing state (broken import)");
|
|
436
428
|
continue;
|
|
437
429
|
}
|
|
438
|
-
const built =
|
|
430
|
+
const built = state_by_ref.get(st);
|
|
439
431
|
if (built) {
|
|
440
432
|
if ("error" in built) {
|
|
441
433
|
errors.push(built.error);
|
|
442
434
|
} else {
|
|
443
|
-
|
|
435
|
+
slice_state_keys.push(built.key);
|
|
444
436
|
}
|
|
445
437
|
} else {
|
|
446
438
|
try {
|
|
447
|
-
const result2 =
|
|
448
|
-
|
|
439
|
+
const result2 = build_state(model, st);
|
|
440
|
+
state_by_ref.set(st, result2);
|
|
449
441
|
if ("error" in result2) {
|
|
450
442
|
errors.push(result2.error);
|
|
451
443
|
} else {
|
|
452
|
-
|
|
444
|
+
slice_state_keys.push(result2.key);
|
|
453
445
|
}
|
|
454
446
|
} catch (e) {
|
|
455
447
|
const msg = e instanceof Error ? e.message : String(e);
|
|
456
|
-
|
|
448
|
+
state_by_ref.set(st, { error: msg });
|
|
457
449
|
errors.push(msg);
|
|
458
450
|
}
|
|
459
451
|
}
|
|
460
452
|
}
|
|
461
|
-
const
|
|
453
|
+
const proj_names = [];
|
|
462
454
|
for (const p of s.projections ?? []) {
|
|
463
|
-
if (p && p._tag === "Projection")
|
|
455
|
+
if (p && p._tag === "Projection") proj_names.push(p.target);
|
|
464
456
|
}
|
|
465
|
-
const
|
|
457
|
+
const slice_file = s._sourceFile;
|
|
466
458
|
model.slices.push({
|
|
467
|
-
name:
|
|
468
|
-
states:
|
|
469
|
-
stateVars:
|
|
470
|
-
projections:
|
|
459
|
+
name: slice_name,
|
|
460
|
+
states: slice_state_keys,
|
|
461
|
+
stateVars: slice_state_keys,
|
|
462
|
+
projections: proj_names,
|
|
471
463
|
reactions: (s.reactions ?? []).map((r) => ({
|
|
472
464
|
...r,
|
|
473
|
-
file: r.file ??
|
|
465
|
+
file: r.file ?? slice_file
|
|
474
466
|
})),
|
|
475
|
-
file:
|
|
467
|
+
file: slice_file,
|
|
476
468
|
error: errors.length > 0 ? errors.join("; ") : void 0
|
|
477
469
|
});
|
|
478
470
|
} catch (e) {
|
|
479
471
|
const msg = e instanceof Error ? e.message : String(e);
|
|
480
472
|
model.slices.push({
|
|
481
|
-
name:
|
|
473
|
+
name: slice_name,
|
|
482
474
|
states: [],
|
|
483
475
|
stateVars: [],
|
|
484
476
|
projections: [],
|
|
@@ -488,38 +480,38 @@ function buildModel(result, files, expectedSlices) {
|
|
|
488
480
|
});
|
|
489
481
|
}
|
|
490
482
|
}
|
|
491
|
-
for (const [name,
|
|
492
|
-
if (!
|
|
483
|
+
for (const [name, file_path] of expected_slices) {
|
|
484
|
+
if (!built_slice_names.has(name)) {
|
|
493
485
|
model.slices.push({
|
|
494
486
|
name,
|
|
495
487
|
states: [],
|
|
496
488
|
stateVars: [],
|
|
497
489
|
projections: [],
|
|
498
490
|
reactions: [],
|
|
499
|
-
error: result.
|
|
500
|
-
file:
|
|
491
|
+
error: result.file_errors.get(file_path) ?? result.error ?? "Failed to build slice",
|
|
492
|
+
file: file_path
|
|
501
493
|
});
|
|
502
494
|
}
|
|
503
495
|
}
|
|
504
|
-
const
|
|
505
|
-
const
|
|
496
|
+
const source_by_path = /* @__PURE__ */ new Map();
|
|
497
|
+
const external_idents = /* @__PURE__ */ new Map();
|
|
506
498
|
for (const f of files) {
|
|
507
|
-
|
|
508
|
-
for (const [ident, expr] of
|
|
509
|
-
if (!
|
|
499
|
+
source_by_path.set(f.path, f.content);
|
|
500
|
+
for (const [ident, expr] of extract_identifier_assignments(f.content)) {
|
|
501
|
+
if (!external_idents.has(ident)) external_idents.set(ident, expr);
|
|
510
502
|
}
|
|
511
503
|
}
|
|
512
|
-
for (const
|
|
513
|
-
if (!
|
|
514
|
-
const src =
|
|
515
|
-
const names = new Set(
|
|
504
|
+
for (const st_node of model.states) {
|
|
505
|
+
if (!st_node.file) continue;
|
|
506
|
+
const src = source_by_path.get(st_node.file);
|
|
507
|
+
const names = new Set(st_node.events.map((e) => e.name));
|
|
516
508
|
if (names.size === 0) continue;
|
|
517
|
-
const schemas =
|
|
518
|
-
for (const ev of
|
|
509
|
+
const schemas = extract_schemas_from_source(src, names, external_idents);
|
|
510
|
+
for (const ev of st_node.events) {
|
|
519
511
|
ev.schema = schemas.get(ev.name);
|
|
520
512
|
}
|
|
521
513
|
}
|
|
522
|
-
for (const p of
|
|
514
|
+
for (const p of raw_projections) {
|
|
523
515
|
model.projections.push({
|
|
524
516
|
name: p.target,
|
|
525
517
|
varName: p.target,
|
|
@@ -527,11 +519,11 @@ function buildModel(result, files, expectedSlices) {
|
|
|
527
519
|
file: p._sourceFile
|
|
528
520
|
});
|
|
529
521
|
}
|
|
530
|
-
const
|
|
531
|
-
const
|
|
532
|
-
for (const a of
|
|
522
|
+
const states_in_slices = new Set(model.slices.flatMap((s) => s.states));
|
|
523
|
+
const global_state_keys = model.states.filter((s) => !states_in_slices.has(s.varName)).map((s) => s.varName);
|
|
524
|
+
for (const a of raw_acts) {
|
|
533
525
|
try {
|
|
534
|
-
|
|
526
|
+
fixup_reactions(
|
|
535
527
|
a.reactions ?? [],
|
|
536
528
|
files,
|
|
537
529
|
a._sourceFile
|
|
@@ -543,53 +535,55 @@ function buildModel(result, files, expectedSlices) {
|
|
|
543
535
|
projections: model.projections.map((p) => p.name),
|
|
544
536
|
states: model.states.map((s) => s.name)
|
|
545
537
|
};
|
|
546
|
-
const
|
|
538
|
+
const act_file = a._sourceFile;
|
|
547
539
|
for (const r of a.reactions ?? []) {
|
|
548
|
-
model.reactions.push({ ...r, file: r.file ??
|
|
540
|
+
model.reactions.push({ ...r, file: r.file ?? act_file });
|
|
549
541
|
}
|
|
550
|
-
const
|
|
551
|
-
const
|
|
542
|
+
const entry_path = a._sourceFile ?? "app.ts";
|
|
543
|
+
const act_slice_names = new Set(
|
|
552
544
|
(a.slices ?? []).filter((s) => s != null).map((s) => s._varName ?? "").filter(Boolean)
|
|
553
545
|
);
|
|
554
546
|
for (const sl of model.slices) {
|
|
555
|
-
if (sl.error && !
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
|
|
547
|
+
if (sl.error && !act_slice_names.has(sl.name)) {
|
|
548
|
+
const act_src = files.find((f) => f.path === entry_path)?.content ?? "";
|
|
549
|
+
if (act_src.includes(sl.name)) {
|
|
550
|
+
act_slice_names.add(sl.name);
|
|
559
551
|
}
|
|
560
552
|
}
|
|
561
553
|
}
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
554
|
+
const entry_slices = model.slices.filter(
|
|
555
|
+
(s) => act_slice_names.has(s.name)
|
|
556
|
+
);
|
|
557
|
+
const slice_state_keys = new Set(entry_slices.flatMap((s) => s.states));
|
|
558
|
+
const act_state_keys = /* @__PURE__ */ new Set();
|
|
565
559
|
for (const s of a.states ?? []) {
|
|
566
560
|
try {
|
|
567
561
|
if (s && s._tag === "State") {
|
|
568
|
-
|
|
562
|
+
act_state_keys.add(s._modelKey ?? s.name);
|
|
569
563
|
}
|
|
570
564
|
} catch {
|
|
571
565
|
}
|
|
572
566
|
}
|
|
573
|
-
const
|
|
574
|
-
const
|
|
567
|
+
const all_state_keys = /* @__PURE__ */ new Set([...act_state_keys, ...slice_state_keys]);
|
|
568
|
+
const act_proj_names = new Set(
|
|
575
569
|
(a.projections ?? []).filter((p) => p && p._tag === "Projection").map((p) => p.target)
|
|
576
570
|
);
|
|
577
|
-
for (const sl of
|
|
578
|
-
for (const pn of sl.projections)
|
|
571
|
+
for (const sl of entry_slices) {
|
|
572
|
+
for (const pn of sl.projections) act_proj_names.add(pn);
|
|
579
573
|
}
|
|
580
574
|
model.entries.push({
|
|
581
|
-
path:
|
|
582
|
-
states: model.states.filter((s) =>
|
|
583
|
-
slices:
|
|
584
|
-
projections: model.projections.filter((p) =>
|
|
575
|
+
path: entry_path,
|
|
576
|
+
states: model.states.filter((s) => all_state_keys.has(s.varName)),
|
|
577
|
+
slices: entry_slices,
|
|
578
|
+
projections: model.projections.filter((p) => act_proj_names.has(p.name)),
|
|
585
579
|
reactions: a.reactions ?? []
|
|
586
580
|
});
|
|
587
581
|
}
|
|
588
|
-
if (
|
|
582
|
+
if (global_state_keys.length > 0 || model.reactions.length > 0) {
|
|
589
583
|
model.slices.push({
|
|
590
584
|
name: "global",
|
|
591
|
-
states:
|
|
592
|
-
stateVars:
|
|
585
|
+
states: global_state_keys,
|
|
586
|
+
stateVars: global_state_keys,
|
|
593
587
|
projections: model.projections.map((p) => p.name),
|
|
594
588
|
reactions: model.reactions
|
|
595
589
|
});
|
|
@@ -611,42 +605,42 @@ function buildModel(result, files, expectedSlices) {
|
|
|
611
605
|
|
|
612
606
|
// src/client/lib/mock-builders.ts
|
|
613
607
|
var import_zod = require("zod");
|
|
614
|
-
function
|
|
608
|
+
function proxy_target() {
|
|
615
609
|
}
|
|
616
|
-
function
|
|
610
|
+
function attach_emit(info, action_name, handler) {
|
|
617
611
|
const emits = [];
|
|
618
612
|
if (typeof handler === "string") {
|
|
619
613
|
emits.push(handler);
|
|
620
614
|
} else if (typeof handler === "function") {
|
|
621
615
|
const src = String(handler);
|
|
622
|
-
for (const
|
|
623
|
-
if (src.includes(`"${
|
|
624
|
-
emits.push(
|
|
616
|
+
for (const event_name of Object.keys(info.events)) {
|
|
617
|
+
if (src.includes(`"${event_name}"`) || src.includes(`'${event_name}'`) || src.includes(`\`${event_name}\``)) {
|
|
618
|
+
emits.push(event_name);
|
|
625
619
|
}
|
|
626
620
|
}
|
|
627
621
|
if (emits.length === 0) {
|
|
628
622
|
try {
|
|
629
|
-
const
|
|
623
|
+
const deep_proxy = new Proxy(
|
|
630
624
|
{},
|
|
631
625
|
{
|
|
632
|
-
get: () =>
|
|
626
|
+
get: () => deep_proxy,
|
|
633
627
|
has: () => true
|
|
634
628
|
}
|
|
635
629
|
);
|
|
636
|
-
const
|
|
637
|
-
get: () =>
|
|
638
|
-
apply: () =>
|
|
630
|
+
const proxy_fn = new Proxy(proxy_target, {
|
|
631
|
+
get: () => deep_proxy,
|
|
632
|
+
apply: () => deep_proxy
|
|
639
633
|
});
|
|
640
|
-
const
|
|
634
|
+
const dummy_arg = new Proxy(
|
|
641
635
|
{},
|
|
642
636
|
{
|
|
643
637
|
get: (_t, prop) => {
|
|
644
|
-
if (typeof prop === "string") return
|
|
638
|
+
if (typeof prop === "string") return proxy_fn;
|
|
645
639
|
return void 0;
|
|
646
640
|
}
|
|
647
641
|
}
|
|
648
642
|
);
|
|
649
|
-
const result = handler(
|
|
643
|
+
const result = handler(dummy_arg, dummy_arg, dummy_arg);
|
|
650
644
|
if (Array.isArray(result) && typeof result[0] === "string") {
|
|
651
645
|
emits.push(result[0]);
|
|
652
646
|
}
|
|
@@ -654,9 +648,9 @@ function attachEmit(info, actionName, handler) {
|
|
|
654
648
|
}
|
|
655
649
|
}
|
|
656
650
|
}
|
|
657
|
-
info.actions[`__emits_${
|
|
651
|
+
info.actions[`__emits_${action_name}`] = emits;
|
|
658
652
|
}
|
|
659
|
-
function
|
|
653
|
+
function mock_state(entry, on_build) {
|
|
660
654
|
const name = Object.keys(entry)[0];
|
|
661
655
|
const info = {
|
|
662
656
|
name,
|
|
@@ -666,29 +660,29 @@ function mockState(entry, onBuild) {
|
|
|
666
660
|
patches: /* @__PURE__ */ new Set(),
|
|
667
661
|
_tag: "State"
|
|
668
662
|
};
|
|
669
|
-
const
|
|
670
|
-
on(
|
|
671
|
-
const
|
|
672
|
-
info.actions[
|
|
663
|
+
const action_builder = (_currentAction) => ({
|
|
664
|
+
on(action_entry) {
|
|
665
|
+
const action_name = Object.keys(action_entry)[0];
|
|
666
|
+
info.actions[action_name] = action_entry[action_name];
|
|
673
667
|
return {
|
|
674
668
|
given(rules) {
|
|
675
|
-
if (rules) info.given[
|
|
669
|
+
if (rules) info.given[action_name] = rules;
|
|
676
670
|
return {
|
|
677
671
|
emit(handler) {
|
|
678
|
-
|
|
679
|
-
return
|
|
672
|
+
attach_emit(info, action_name, handler);
|
|
673
|
+
return action_builder(action_name);
|
|
680
674
|
}
|
|
681
675
|
};
|
|
682
676
|
},
|
|
683
677
|
emit(handler) {
|
|
684
|
-
|
|
685
|
-
return
|
|
678
|
+
attach_emit(info, action_name, handler);
|
|
679
|
+
return action_builder(action_name);
|
|
686
680
|
}
|
|
687
681
|
};
|
|
688
682
|
},
|
|
689
|
-
snap: () =>
|
|
683
|
+
snap: () => action_builder(_currentAction),
|
|
690
684
|
build: () => {
|
|
691
|
-
|
|
685
|
+
on_build?.(info);
|
|
692
686
|
return info;
|
|
693
687
|
}
|
|
694
688
|
});
|
|
@@ -698,36 +692,36 @@ function mockState(entry, onBuild) {
|
|
|
698
692
|
emits(events) {
|
|
699
693
|
info.events = events ?? {};
|
|
700
694
|
return {
|
|
701
|
-
...
|
|
695
|
+
...action_builder(),
|
|
702
696
|
patch(patches) {
|
|
703
697
|
if (patches)
|
|
704
698
|
for (const k of Object.keys(patches)) info.patches.add(k);
|
|
705
|
-
return
|
|
699
|
+
return action_builder();
|
|
706
700
|
}
|
|
707
701
|
};
|
|
708
702
|
}
|
|
709
703
|
})
|
|
710
704
|
};
|
|
711
705
|
}
|
|
712
|
-
function
|
|
706
|
+
function capture_dispatches(handler) {
|
|
713
707
|
const dispatches = [];
|
|
714
708
|
if (typeof handler !== "function") return dispatches;
|
|
715
709
|
try {
|
|
716
|
-
const
|
|
717
|
-
const
|
|
718
|
-
do: (
|
|
719
|
-
if (typeof
|
|
720
|
-
dispatches.push(
|
|
710
|
+
const safe_proxy = () => new Proxy({}, { get: () => "" });
|
|
711
|
+
const mock_app = {
|
|
712
|
+
do: (action_name) => {
|
|
713
|
+
if (typeof action_name === "string" && !dispatches.includes(action_name))
|
|
714
|
+
dispatches.push(action_name);
|
|
721
715
|
return Promise.resolve([]);
|
|
722
716
|
},
|
|
723
|
-
load: () => Promise.resolve({ state:
|
|
717
|
+
load: () => Promise.resolve({ state: safe_proxy(), version: 0 }),
|
|
724
718
|
query: () => Promise.resolve({ count: 0 }),
|
|
725
719
|
query_array: () => Promise.resolve([])
|
|
726
720
|
};
|
|
727
|
-
const
|
|
721
|
+
const mock_event = new Proxy({}, {
|
|
728
722
|
get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
|
|
729
723
|
});
|
|
730
|
-
const result = handler(
|
|
724
|
+
const result = handler(mock_event, "mock", mock_app);
|
|
731
725
|
if (result && typeof result.catch === "function") {
|
|
732
726
|
result.catch(() => {
|
|
733
727
|
});
|
|
@@ -744,7 +738,7 @@ function captureDispatches(handler) {
|
|
|
744
738
|
}
|
|
745
739
|
return dispatches;
|
|
746
740
|
}
|
|
747
|
-
function
|
|
741
|
+
function mock_slice(on_build) {
|
|
748
742
|
const info = {
|
|
749
743
|
_tag: "Slice",
|
|
750
744
|
states: [],
|
|
@@ -760,13 +754,13 @@ function mockSlice(onBuild) {
|
|
|
760
754
|
if (p) info.projections.push(p);
|
|
761
755
|
return builder;
|
|
762
756
|
},
|
|
763
|
-
on(
|
|
757
|
+
on(event_name) {
|
|
764
758
|
return {
|
|
765
759
|
do(handler) {
|
|
766
|
-
const dispatches =
|
|
760
|
+
const dispatches = capture_dispatches(handler);
|
|
767
761
|
const reaction = {
|
|
768
|
-
event:
|
|
769
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
762
|
+
event: event_name,
|
|
763
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
770
764
|
dispatches
|
|
771
765
|
};
|
|
772
766
|
info.reactions.push(reaction);
|
|
@@ -780,22 +774,22 @@ function mockSlice(onBuild) {
|
|
|
780
774
|
};
|
|
781
775
|
},
|
|
782
776
|
build: () => {
|
|
783
|
-
|
|
777
|
+
on_build?.(info);
|
|
784
778
|
return info;
|
|
785
779
|
}
|
|
786
780
|
};
|
|
787
781
|
return builder;
|
|
788
782
|
}
|
|
789
|
-
function
|
|
783
|
+
function mock_projection(target, on_build) {
|
|
790
784
|
const info = {
|
|
791
785
|
_tag: "Projection",
|
|
792
786
|
target: target || "projection",
|
|
793
787
|
handles: []
|
|
794
788
|
};
|
|
795
789
|
const builder = {
|
|
796
|
-
on(
|
|
797
|
-
const
|
|
798
|
-
info.handles.push(
|
|
790
|
+
on(event_entry) {
|
|
791
|
+
const event_name = Object.keys(event_entry)[0];
|
|
792
|
+
info.handles.push(event_name);
|
|
799
793
|
return {
|
|
800
794
|
do() {
|
|
801
795
|
return {
|
|
@@ -809,13 +803,13 @@ function mockProjection(target, onBuild) {
|
|
|
809
803
|
};
|
|
810
804
|
},
|
|
811
805
|
build: () => {
|
|
812
|
-
|
|
806
|
+
on_build?.(info);
|
|
813
807
|
return info;
|
|
814
808
|
}
|
|
815
809
|
};
|
|
816
810
|
return builder;
|
|
817
811
|
}
|
|
818
|
-
function
|
|
812
|
+
function mock_act(on_build) {
|
|
819
813
|
const info = {
|
|
820
814
|
_tag: "Act",
|
|
821
815
|
states: [],
|
|
@@ -837,13 +831,13 @@ function mockAct(onBuild) {
|
|
|
837
831
|
return builder;
|
|
838
832
|
},
|
|
839
833
|
withActor: () => builder,
|
|
840
|
-
on(
|
|
834
|
+
on(event_name) {
|
|
841
835
|
return {
|
|
842
836
|
do(handler) {
|
|
843
|
-
const dispatches =
|
|
837
|
+
const dispatches = capture_dispatches(handler);
|
|
844
838
|
const reaction = {
|
|
845
|
-
event:
|
|
846
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
839
|
+
event: event_name,
|
|
840
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
847
841
|
dispatches
|
|
848
842
|
};
|
|
849
843
|
info.reactions.push(reaction);
|
|
@@ -857,10 +851,10 @@ function mockAct(onBuild) {
|
|
|
857
851
|
};
|
|
858
852
|
},
|
|
859
853
|
build: () => {
|
|
860
|
-
const noop = () =>
|
|
861
|
-
const
|
|
854
|
+
const noop = () => act_stub;
|
|
855
|
+
const act_stub = {
|
|
862
856
|
...info,
|
|
863
|
-
on: () =>
|
|
857
|
+
on: () => act_stub,
|
|
864
858
|
do: () => Promise.resolve([]),
|
|
865
859
|
load: () => Promise.resolve({}),
|
|
866
860
|
drain: () => Promise.resolve(),
|
|
@@ -869,8 +863,8 @@ function mockAct(onBuild) {
|
|
|
869
863
|
start_correlations: noop,
|
|
870
864
|
query_array: () => Promise.resolve([])
|
|
871
865
|
};
|
|
872
|
-
|
|
873
|
-
return
|
|
866
|
+
on_build?.(act_stub);
|
|
867
|
+
return act_stub;
|
|
874
868
|
}
|
|
875
869
|
};
|
|
876
870
|
return builder;
|
|
@@ -881,13 +875,13 @@ var InvariantError = class extends Error {
|
|
|
881
875
|
this.name = "InvariantError";
|
|
882
876
|
}
|
|
883
877
|
};
|
|
884
|
-
var
|
|
878
|
+
var crypto_mock = { randomUUID: () => "mock-uuid" };
|
|
885
879
|
var MODULES = {
|
|
886
880
|
"@rotorsoft/act": {
|
|
887
|
-
state:
|
|
888
|
-
slice:
|
|
889
|
-
projection:
|
|
890
|
-
act:
|
|
881
|
+
state: mock_state,
|
|
882
|
+
slice: mock_slice,
|
|
883
|
+
projection: mock_projection,
|
|
884
|
+
act: mock_act,
|
|
891
885
|
store: () => ({
|
|
892
886
|
seed: () => Promise.resolve(),
|
|
893
887
|
drop: () => Promise.resolve(),
|
|
@@ -900,10 +894,10 @@ var MODULES = {
|
|
|
900
894
|
InvariantError
|
|
901
895
|
},
|
|
902
896
|
zod: { z: import_zod.z, ...import_zod.z },
|
|
903
|
-
crypto:
|
|
904
|
-
"node:crypto":
|
|
897
|
+
crypto: crypto_mock,
|
|
898
|
+
"node:crypto": crypto_mock
|
|
905
899
|
};
|
|
906
|
-
function
|
|
900
|
+
function unknown_module_proxy() {
|
|
907
901
|
const handler = {
|
|
908
902
|
get(_target, prop) {
|
|
909
903
|
if (prop === Symbol.toPrimitive) return () => "";
|
|
@@ -920,62 +914,62 @@ function unknownModuleProxy() {
|
|
|
920
914
|
return true;
|
|
921
915
|
}
|
|
922
916
|
};
|
|
923
|
-
const proxy = new Proxy(
|
|
917
|
+
const proxy = new Proxy(proxy_target, handler);
|
|
924
918
|
return proxy;
|
|
925
919
|
}
|
|
926
920
|
|
|
927
921
|
// src/client/lib/sort.ts
|
|
928
|
-
function
|
|
929
|
-
if (
|
|
922
|
+
function topo_sort(ts_files) {
|
|
923
|
+
if (ts_files.length <= 1) return ts_files;
|
|
930
924
|
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
931
|
-
const
|
|
932
|
-
for (const f of
|
|
933
|
-
|
|
925
|
+
const by_key = /* @__PURE__ */ new Map();
|
|
926
|
+
for (const f of ts_files) {
|
|
927
|
+
by_key.set(strip(f.path), f);
|
|
934
928
|
}
|
|
935
929
|
const deps = /* @__PURE__ */ new Map();
|
|
936
|
-
for (const f of
|
|
930
|
+
for (const f of ts_files) {
|
|
937
931
|
const key = strip(f.path);
|
|
938
|
-
const
|
|
939
|
-
deps.set(key,
|
|
940
|
-
const
|
|
932
|
+
const file_deps = /* @__PURE__ */ new Set();
|
|
933
|
+
deps.set(key, file_deps);
|
|
934
|
+
const from_re = /from\s+["']([^"']+)["']/g;
|
|
941
935
|
let m;
|
|
942
|
-
while ((m =
|
|
936
|
+
while ((m = from_re.exec(f.content)) !== null) {
|
|
943
937
|
const imp = m[1];
|
|
944
|
-
const resolved = resolve(imp, key,
|
|
945
|
-
if (resolved &&
|
|
938
|
+
const resolved = resolve(imp, key, by_key);
|
|
939
|
+
if (resolved && by_key.has(resolved)) file_deps.add(resolved);
|
|
946
940
|
}
|
|
947
941
|
}
|
|
948
|
-
const
|
|
949
|
-
for (const f of
|
|
950
|
-
for (const [,
|
|
951
|
-
for (const dep of
|
|
952
|
-
|
|
942
|
+
const in_degree = /* @__PURE__ */ new Map();
|
|
943
|
+
for (const f of ts_files) in_degree.set(strip(f.path), 0);
|
|
944
|
+
for (const [, file_deps] of deps) {
|
|
945
|
+
for (const dep of file_deps) {
|
|
946
|
+
in_degree.set(dep, in_degree.get(dep) + 1);
|
|
953
947
|
}
|
|
954
948
|
}
|
|
955
949
|
const queue = [];
|
|
956
|
-
for (const [key, _deg] of
|
|
950
|
+
for (const [key, _deg] of in_degree) {
|
|
957
951
|
if (deps.get(key)?.size === 0) queue.push(key);
|
|
958
952
|
}
|
|
959
953
|
const order = [];
|
|
960
954
|
while (queue.length > 0) {
|
|
961
955
|
const key = queue.shift();
|
|
962
956
|
order.push(key);
|
|
963
|
-
for (const [other,
|
|
964
|
-
if (
|
|
965
|
-
|
|
966
|
-
if (
|
|
957
|
+
for (const [other, file_deps] of deps) {
|
|
958
|
+
if (file_deps.has(key)) {
|
|
959
|
+
file_deps.delete(key);
|
|
960
|
+
if (file_deps.size === 0) queue.push(other);
|
|
967
961
|
}
|
|
968
962
|
}
|
|
969
963
|
}
|
|
970
|
-
for (const f of
|
|
964
|
+
for (const f of ts_files) {
|
|
971
965
|
const key = strip(f.path);
|
|
972
966
|
if (!order.includes(key)) order.push(key);
|
|
973
967
|
}
|
|
974
|
-
return order.map((k) =>
|
|
968
|
+
return order.map((k) => by_key.get(k)).filter(Boolean);
|
|
975
969
|
}
|
|
976
|
-
function resolve(imp,
|
|
970
|
+
function resolve(imp, from_path, by_key) {
|
|
977
971
|
if (imp.startsWith(".")) {
|
|
978
|
-
const dir =
|
|
972
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
979
973
|
const parts = (dir ? dir + "/" + imp : imp).split("/");
|
|
980
974
|
const resolved = [];
|
|
981
975
|
for (const p of parts) {
|
|
@@ -986,23 +980,23 @@ function resolve(imp, fromPath, byKey) {
|
|
|
986
980
|
return resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
987
981
|
}
|
|
988
982
|
if (imp.startsWith("@") && !imp.startsWith("@rotorsoft/")) {
|
|
989
|
-
const
|
|
990
|
-
if (
|
|
983
|
+
const pkg_name = imp.split("/")[1];
|
|
984
|
+
if (pkg_name) {
|
|
991
985
|
for (const candidate of [
|
|
992
|
-
`packages/${
|
|
993
|
-
`${
|
|
994
|
-
`${
|
|
986
|
+
`packages/${pkg_name}/src/index`,
|
|
987
|
+
`${pkg_name}/src/index`,
|
|
988
|
+
`${pkg_name}/index`
|
|
995
989
|
]) {
|
|
996
|
-
if (
|
|
990
|
+
if (by_key?.has(candidate)) return candidate;
|
|
997
991
|
}
|
|
998
|
-
return `packages/${
|
|
992
|
+
return `packages/${pkg_name}/src/index`;
|
|
999
993
|
}
|
|
1000
994
|
}
|
|
1001
995
|
return void 0;
|
|
1002
996
|
}
|
|
1003
997
|
|
|
1004
998
|
// src/client/lib/evaluate.ts
|
|
1005
|
-
var
|
|
999
|
+
var strip_non_code = (src, level = "full") => {
|
|
1006
1000
|
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
1007
1001
|
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`\\])*`/g, blank);
|
|
1008
1002
|
if (level === "full") {
|
|
@@ -1010,7 +1004,7 @@ var stripNonCode = (src, level = "full") => {
|
|
|
1010
1004
|
}
|
|
1011
1005
|
return result;
|
|
1012
1006
|
};
|
|
1013
|
-
var
|
|
1007
|
+
var is_source_file = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
|
|
1014
1008
|
function transpile(code) {
|
|
1015
1009
|
try {
|
|
1016
1010
|
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
@@ -1032,8 +1026,8 @@ function execute(files) {
|
|
|
1032
1026
|
projections: [],
|
|
1033
1027
|
acts: [],
|
|
1034
1028
|
error: void 0,
|
|
1035
|
-
|
|
1036
|
-
|
|
1029
|
+
file_errors: /* @__PURE__ */ new Map(),
|
|
1030
|
+
expected_slices: /* @__PURE__ */ new Map()
|
|
1037
1031
|
};
|
|
1038
1032
|
try {
|
|
1039
1033
|
const __built__ = {
|
|
@@ -1047,24 +1041,24 @@ function execute(files) {
|
|
|
1047
1041
|
info._sourceFile = _currentFile;
|
|
1048
1042
|
__built__[type + "s"].push(info);
|
|
1049
1043
|
};
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1044
|
+
const act_module = { ...MODULES["@rotorsoft/act"] };
|
|
1045
|
+
act_module.state = (entry) => MODULES["@rotorsoft/act"].state(entry, capture("state"));
|
|
1046
|
+
act_module.slice = () => MODULES["@rotorsoft/act"].slice(capture("slice"));
|
|
1047
|
+
act_module.projection = (target) => MODULES["@rotorsoft/act"].projection(
|
|
1054
1048
|
target,
|
|
1055
1049
|
capture("projection")
|
|
1056
1050
|
);
|
|
1057
|
-
|
|
1058
|
-
const
|
|
1051
|
+
act_module.act = () => MODULES["@rotorsoft/act"].act(capture("act"));
|
|
1052
|
+
const pkg_modules = {
|
|
1059
1053
|
...MODULES,
|
|
1060
|
-
"@rotorsoft/act":
|
|
1054
|
+
"@rotorsoft/act": act_module
|
|
1061
1055
|
};
|
|
1062
|
-
const
|
|
1056
|
+
const file_exports = /* @__PURE__ */ new Map();
|
|
1063
1057
|
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
1064
|
-
const
|
|
1065
|
-
if (
|
|
1058
|
+
const resolve_module = (mod, from_path) => {
|
|
1059
|
+
if (pkg_modules[mod]) return pkg_modules[mod];
|
|
1066
1060
|
if (mod.startsWith(".")) {
|
|
1067
|
-
const dir =
|
|
1061
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
1068
1062
|
const parts = (dir ? dir + "/" + mod : mod).split("/");
|
|
1069
1063
|
const resolved = [];
|
|
1070
1064
|
for (const p of parts) {
|
|
@@ -1073,43 +1067,44 @@ function execute(files) {
|
|
|
1073
1067
|
else resolved.push(p);
|
|
1074
1068
|
}
|
|
1075
1069
|
const rp = resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1076
|
-
return
|
|
1070
|
+
return file_exports.get(rp) ?? file_exports.get(rp + "/index") ?? {};
|
|
1077
1071
|
}
|
|
1078
1072
|
if (mod.startsWith("@") && !mod.startsWith("@rotorsoft/")) {
|
|
1079
|
-
const
|
|
1080
|
-
const
|
|
1081
|
-
if (
|
|
1082
|
-
const suffix =
|
|
1083
|
-
return
|
|
1073
|
+
const pkg_name = mod.split("/")[1];
|
|
1074
|
+
const sub_path = mod.split("/").slice(2).join("/");
|
|
1075
|
+
if (pkg_name) {
|
|
1076
|
+
const suffix = sub_path ? `/${sub_path.replace(/\.js$/, "")}` : "/src/index";
|
|
1077
|
+
return file_exports.get(`packages/${pkg_name}${suffix}`) ?? file_exports.get(`${pkg_name}${suffix}`) ?? file_exports.get(`packages/${pkg_name}/src/index`) ?? file_exports.get(`${pkg_name}/src/index`) ?? file_exports.get(`${pkg_name}/index`) ?? file_exports.get(pkg_name) ?? unknown_module_proxy();
|
|
1084
1078
|
}
|
|
1085
1079
|
}
|
|
1086
|
-
return
|
|
1080
|
+
return unknown_module_proxy();
|
|
1087
1081
|
};
|
|
1088
|
-
const sorted =
|
|
1082
|
+
const sorted = topo_sort(files.filter(is_source_file));
|
|
1089
1083
|
for (const file of sorted) {
|
|
1090
1084
|
_currentFile = file.path;
|
|
1091
1085
|
const js = transpile(file.content);
|
|
1092
1086
|
const key = strip(file.path);
|
|
1093
1087
|
const fileExp = {};
|
|
1094
|
-
|
|
1095
|
-
const
|
|
1096
|
-
const
|
|
1088
|
+
file_exports.set(key, fileExp);
|
|
1089
|
+
const slice_names_in_act = [];
|
|
1090
|
+
const ws_re = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
1097
1091
|
let wsm;
|
|
1098
|
-
const
|
|
1099
|
-
while ((wsm =
|
|
1100
|
-
if (!
|
|
1092
|
+
const code_only = strip_non_code(js);
|
|
1093
|
+
while ((wsm = ws_re.exec(code_only)) !== null) {
|
|
1094
|
+
if (!slice_names_in_act.includes(wsm[1]))
|
|
1095
|
+
slice_names_in_act.push(wsm[1]);
|
|
1101
1096
|
}
|
|
1102
|
-
for (const m of
|
|
1097
|
+
for (const m of code_only.matchAll(
|
|
1103
1098
|
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
1104
1099
|
)) {
|
|
1105
|
-
result.
|
|
1100
|
+
result.expected_slices.set(m[1], file.path);
|
|
1106
1101
|
}
|
|
1107
|
-
const
|
|
1108
|
-
(mod) =>
|
|
1102
|
+
const file_require = Object.assign(
|
|
1103
|
+
(mod) => resolve_module(mod, key),
|
|
1109
1104
|
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
1110
1105
|
);
|
|
1111
1106
|
try {
|
|
1112
|
-
const
|
|
1107
|
+
const clean_js = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
1113
1108
|
const fn = new Function(
|
|
1114
1109
|
// lgtm[js/code-injection]
|
|
1115
1110
|
"require",
|
|
@@ -1122,21 +1117,21 @@ function execute(files) {
|
|
|
1122
1117
|
var process = { env: {}, cwd: function() { return "/"; }, exit: function() {}, on: function() {}, off: function() {} };
|
|
1123
1118
|
var Buffer = { from: function() { return ""; } };
|
|
1124
1119
|
var console = { log: function() {}, error: function() {}, warn: function() {}, info: function() {}, debug: function() {} };
|
|
1125
|
-
${
|
|
1120
|
+
${clean_js}
|
|
1126
1121
|
`
|
|
1127
1122
|
);
|
|
1128
|
-
fn(
|
|
1123
|
+
fn(file_require, fileExp, { exports: fileExp });
|
|
1129
1124
|
} catch (evalErr) {
|
|
1130
1125
|
const errMsg = evalErr instanceof Error ? evalErr.message : String(evalErr);
|
|
1131
|
-
result.
|
|
1132
|
-
}
|
|
1133
|
-
if (
|
|
1134
|
-
for (const
|
|
1135
|
-
if (
|
|
1136
|
-
const
|
|
1137
|
-
for (let ai = 0; ai < Math.min(
|
|
1138
|
-
if (
|
|
1139
|
-
|
|
1126
|
+
result.file_errors.set(file.path, errMsg);
|
|
1127
|
+
}
|
|
1128
|
+
if (slice_names_in_act.length > 0) {
|
|
1129
|
+
for (const act_obj of __built__.acts) {
|
|
1130
|
+
if (act_obj._sourceFile !== file.path) continue;
|
|
1131
|
+
const act_slices = act_obj.slices;
|
|
1132
|
+
for (let ai = 0; ai < Math.min(slice_names_in_act.length, act_slices.length); ai++) {
|
|
1133
|
+
if (act_slices[ai]) {
|
|
1134
|
+
act_slices[ai]._varName = slice_names_in_act[ai];
|
|
1140
1135
|
}
|
|
1141
1136
|
}
|
|
1142
1137
|
}
|
|
@@ -1151,29 +1146,29 @@ function execute(files) {
|
|
|
1151
1146
|
}
|
|
1152
1147
|
return result;
|
|
1153
1148
|
}
|
|
1154
|
-
function
|
|
1149
|
+
function extract_model(files) {
|
|
1155
1150
|
const result = execute(files);
|
|
1156
|
-
return
|
|
1151
|
+
return build_model(result, files, result.expected_slices);
|
|
1157
1152
|
}
|
|
1158
1153
|
|
|
1159
1154
|
// src/client/lib/navigate.ts
|
|
1160
|
-
function
|
|
1155
|
+
function position_at(content, index) {
|
|
1161
1156
|
const before = content.slice(0, index);
|
|
1162
1157
|
const line = before.split("\n").length;
|
|
1163
|
-
const
|
|
1164
|
-
const col = index - (
|
|
1158
|
+
const last_nl = before.lastIndexOf("\n");
|
|
1159
|
+
const col = index - (last_nl >= 0 ? last_nl : 0);
|
|
1165
1160
|
return { line, col };
|
|
1166
1161
|
}
|
|
1167
|
-
function
|
|
1168
|
-
const
|
|
1169
|
-
const
|
|
1170
|
-
const
|
|
1162
|
+
function build_patterns(esc, type) {
|
|
1163
|
+
const state_patterns = [new RegExp(`state\\(\\s*\\{\\s*(${esc})\\s*[}:,]`)];
|
|
1164
|
+
const action_patterns = [new RegExp(`\\.on\\(\\s*\\{\\s*(${esc})\\s*[},:]`)];
|
|
1165
|
+
const event_patterns = [
|
|
1171
1166
|
// Match event name inside .emits({ EventName: ... }) — inline declaration
|
|
1172
1167
|
new RegExp(`\\.emits\\([\\s\\S]*?(${esc})\\s*:`),
|
|
1173
1168
|
// Match event name as key in a schema object: EventName: z.object(...)
|
|
1174
1169
|
new RegExp(`(${esc})\\s*:\\s*z\\.object\\(`)
|
|
1175
1170
|
];
|
|
1176
|
-
const
|
|
1171
|
+
const reaction_patterns = [
|
|
1177
1172
|
// .do(handlerName) or .do(module.handlerName) — handler declaration in builder
|
|
1178
1173
|
new RegExp(`\\.do\\(\\s*(?:\\w+\\.)?(${esc})\\b`),
|
|
1179
1174
|
// inline function in .do()
|
|
@@ -1183,11 +1178,11 @@ function buildPatterns(esc, type) {
|
|
|
1183
1178
|
// Fallback: function definition
|
|
1184
1179
|
new RegExp(`(?:export\\s+)?async\\s+function\\s+(${esc})\\s*\\(`)
|
|
1185
1180
|
];
|
|
1186
|
-
const
|
|
1181
|
+
const projection_patterns = [
|
|
1187
1182
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*projection\\s*\\(`),
|
|
1188
1183
|
new RegExp(`projection\\(\\s*["'\`](${esc})["'\`]`)
|
|
1189
1184
|
];
|
|
1190
|
-
const
|
|
1185
|
+
const guard_patterns = [
|
|
1191
1186
|
// Guard definition — prefer jumping to the declaration
|
|
1192
1187
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*(?::\\s*Invariant)?\\s*=`),
|
|
1193
1188
|
new RegExp(`rule\\(\\s*["'\`](${esc})["'\`]`),
|
|
@@ -1195,7 +1190,7 @@ function buildPatterns(esc, type) {
|
|
|
1195
1190
|
// .given() usage in the state builder — last resort
|
|
1196
1191
|
new RegExp(`\\.given\\([\\s\\S]*?(${esc})`)
|
|
1197
1192
|
];
|
|
1198
|
-
const
|
|
1193
|
+
const slice_patterns = [
|
|
1199
1194
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*slice\\s*\\(`)
|
|
1200
1195
|
];
|
|
1201
1196
|
const generic = [
|
|
@@ -1207,36 +1202,36 @@ function buildPatterns(esc, type) {
|
|
|
1207
1202
|
];
|
|
1208
1203
|
switch (type) {
|
|
1209
1204
|
case "state":
|
|
1210
|
-
return [...
|
|
1205
|
+
return [...state_patterns, ...generic];
|
|
1211
1206
|
case "action":
|
|
1212
|
-
return [...
|
|
1207
|
+
return [...action_patterns, ...generic];
|
|
1213
1208
|
case "event":
|
|
1214
|
-
return [...
|
|
1209
|
+
return [...event_patterns, ...generic];
|
|
1215
1210
|
case "reaction":
|
|
1216
|
-
return [...
|
|
1211
|
+
return [...reaction_patterns, ...generic];
|
|
1217
1212
|
case "projection":
|
|
1218
|
-
return [...
|
|
1213
|
+
return [...projection_patterns, ...generic];
|
|
1219
1214
|
case "guard":
|
|
1220
|
-
return [...
|
|
1215
|
+
return [...guard_patterns, ...generic];
|
|
1221
1216
|
default:
|
|
1222
1217
|
return [
|
|
1223
|
-
...
|
|
1224
|
-
...
|
|
1225
|
-
...
|
|
1226
|
-
...
|
|
1227
|
-
...
|
|
1228
|
-
...
|
|
1229
|
-
...
|
|
1218
|
+
...slice_patterns,
|
|
1219
|
+
...state_patterns,
|
|
1220
|
+
...action_patterns,
|
|
1221
|
+
...event_patterns,
|
|
1222
|
+
...reaction_patterns,
|
|
1223
|
+
...projection_patterns,
|
|
1224
|
+
...guard_patterns,
|
|
1230
1225
|
...generic
|
|
1231
1226
|
];
|
|
1232
1227
|
}
|
|
1233
1228
|
}
|
|
1234
|
-
function
|
|
1229
|
+
function navigate_to_code(files, name, type, target_file) {
|
|
1235
1230
|
const stripped = /* @__PURE__ */ new Map();
|
|
1236
1231
|
const code = (f) => {
|
|
1237
1232
|
let c = stripped.get(f.path);
|
|
1238
1233
|
if (c === void 0) {
|
|
1239
|
-
c =
|
|
1234
|
+
c = strip_non_code(f.content, "nav");
|
|
1240
1235
|
stripped.set(f.path, c);
|
|
1241
1236
|
}
|
|
1242
1237
|
return c;
|
|
@@ -1244,122 +1239,122 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1244
1239
|
if (type === "file") {
|
|
1245
1240
|
const file = files.find((f) => f.path === name || f.path.endsWith(name));
|
|
1246
1241
|
if (file) {
|
|
1247
|
-
const
|
|
1248
|
-
if (
|
|
1249
|
-
const { line, col } =
|
|
1242
|
+
const act_match = /\bact\s*\(\s*\)/.exec(code(file));
|
|
1243
|
+
if (act_match) {
|
|
1244
|
+
const { line, col } = position_at(file.content, act_match.index);
|
|
1250
1245
|
return { file: file.path, line, col };
|
|
1251
1246
|
}
|
|
1252
1247
|
return { file: file.path, line: 1, col: 1 };
|
|
1253
1248
|
}
|
|
1254
1249
|
return void 0;
|
|
1255
1250
|
}
|
|
1256
|
-
if (
|
|
1257
|
-
const file = files.find((f) => f.path ===
|
|
1251
|
+
if (target_file) {
|
|
1252
|
+
const file = files.find((f) => f.path === target_file);
|
|
1258
1253
|
if (file) {
|
|
1259
1254
|
const c = code(file);
|
|
1260
1255
|
const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1261
1256
|
if (type === "event") {
|
|
1262
|
-
const
|
|
1257
|
+
const emits_block_re = new RegExp(
|
|
1263
1258
|
`\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
|
|
1264
1259
|
);
|
|
1265
|
-
const
|
|
1266
|
-
if (
|
|
1267
|
-
const
|
|
1268
|
-
const { line, col } =
|
|
1260
|
+
const block_match = emits_block_re.exec(c);
|
|
1261
|
+
if (block_match) {
|
|
1262
|
+
const name_idx = block_match.index + block_match[0].lastIndexOf(name);
|
|
1263
|
+
const { line, col } = position_at(file.content, name_idx);
|
|
1269
1264
|
return { file: file.path, line, col };
|
|
1270
1265
|
}
|
|
1271
|
-
const
|
|
1272
|
-
if (
|
|
1273
|
-
const
|
|
1274
|
-
if (
|
|
1275
|
-
const { line, col } =
|
|
1266
|
+
const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
1267
|
+
if (name_re2.exec(c)) {
|
|
1268
|
+
const emits_match = /\.emits\s*\(/.exec(c);
|
|
1269
|
+
if (emits_match) {
|
|
1270
|
+
const { line, col } = position_at(
|
|
1276
1271
|
file.content,
|
|
1277
|
-
|
|
1272
|
+
emits_match.index + 1
|
|
1278
1273
|
);
|
|
1279
1274
|
return { file: file.path, line, col };
|
|
1280
1275
|
}
|
|
1281
1276
|
}
|
|
1282
1277
|
}
|
|
1283
1278
|
if (type === "guard") {
|
|
1284
|
-
const
|
|
1285
|
-
const
|
|
1286
|
-
if (
|
|
1287
|
-
const before = c.slice(0,
|
|
1288
|
-
const
|
|
1289
|
-
let
|
|
1279
|
+
const desc_re = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
|
|
1280
|
+
const desc_match = desc_re.exec(c);
|
|
1281
|
+
if (desc_match) {
|
|
1282
|
+
const before = c.slice(0, desc_match.index);
|
|
1283
|
+
const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1284
|
+
let last_decl = null;
|
|
1290
1285
|
let m;
|
|
1291
|
-
while ((m =
|
|
1292
|
-
|
|
1286
|
+
while ((m = decl_re.exec(before)) !== null) {
|
|
1287
|
+
last_decl = m;
|
|
1293
1288
|
}
|
|
1294
|
-
if (
|
|
1295
|
-
const
|
|
1296
|
-
const { line: line2, col: col2 } =
|
|
1289
|
+
if (last_decl) {
|
|
1290
|
+
const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
|
|
1291
|
+
const { line: line2, col: col2 } = position_at(file.content, name_idx);
|
|
1297
1292
|
return { file: file.path, line: line2, col: col2 };
|
|
1298
1293
|
}
|
|
1299
|
-
const { line, col } =
|
|
1294
|
+
const { line, col } = position_at(file.content, desc_match.index);
|
|
1300
1295
|
return { file: file.path, line, col };
|
|
1301
1296
|
}
|
|
1302
1297
|
}
|
|
1303
1298
|
if (type === "action") {
|
|
1304
|
-
const
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
|
|
1308
|
-
const match2 =
|
|
1299
|
+
const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
1300
|
+
const block_start = c.indexOf(".on(");
|
|
1301
|
+
if (block_start >= 0) {
|
|
1302
|
+
name_re2.lastIndex = block_start;
|
|
1303
|
+
const match2 = name_re2.exec(c);
|
|
1309
1304
|
if (match2) {
|
|
1310
|
-
const { line, col } =
|
|
1305
|
+
const { line, col } = position_at(file.content, match2.index);
|
|
1311
1306
|
return { file: file.path, line, col };
|
|
1312
1307
|
}
|
|
1313
1308
|
}
|
|
1314
1309
|
}
|
|
1315
|
-
const
|
|
1316
|
-
const match =
|
|
1310
|
+
const name_re = new RegExp(`\\b${esc2}\\b`);
|
|
1311
|
+
const match = name_re.exec(c);
|
|
1317
1312
|
if (match) {
|
|
1318
|
-
const { line, col } =
|
|
1313
|
+
const { line, col } = position_at(file.content, match.index);
|
|
1319
1314
|
return { file: file.path, line, col };
|
|
1320
1315
|
}
|
|
1321
1316
|
}
|
|
1322
1317
|
return void 0;
|
|
1323
1318
|
}
|
|
1324
1319
|
const esc = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1325
|
-
const
|
|
1326
|
-
const
|
|
1327
|
-
(a, b) => (
|
|
1320
|
+
const is_test_file = (p) => /(?:\.spec\.|\.test\.|__tests__)/.test(p) || /\/test\//.test(p);
|
|
1321
|
+
const sorted_files = [...files].sort(
|
|
1322
|
+
(a, b) => (is_test_file(a.path) ? 1 : 0) - (is_test_file(b.path) ? 1 : 0)
|
|
1328
1323
|
);
|
|
1329
1324
|
if (type === "guard") {
|
|
1330
|
-
const
|
|
1331
|
-
for (const f of
|
|
1325
|
+
const desc_re = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
|
|
1326
|
+
for (const f of sorted_files) {
|
|
1332
1327
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1333
1328
|
const c = code(f);
|
|
1334
|
-
const
|
|
1335
|
-
if (
|
|
1336
|
-
const before = c.slice(0,
|
|
1337
|
-
const
|
|
1338
|
-
let
|
|
1329
|
+
const desc_match = desc_re.exec(c);
|
|
1330
|
+
if (desc_match) {
|
|
1331
|
+
const before = c.slice(0, desc_match.index);
|
|
1332
|
+
const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1333
|
+
let last_decl = null;
|
|
1339
1334
|
let m;
|
|
1340
|
-
while ((m =
|
|
1341
|
-
if (
|
|
1342
|
-
const
|
|
1343
|
-
const { line: line2, col: col2 } =
|
|
1335
|
+
while ((m = decl_re.exec(before)) !== null) last_decl = m;
|
|
1336
|
+
if (last_decl) {
|
|
1337
|
+
const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
|
|
1338
|
+
const { line: line2, col: col2 } = position_at(f.content, name_idx);
|
|
1344
1339
|
return { file: f.path, line: line2, col: col2 };
|
|
1345
1340
|
}
|
|
1346
|
-
const { line, col } =
|
|
1341
|
+
const { line, col } = position_at(f.content, desc_match.index);
|
|
1347
1342
|
return { file: f.path, line, col };
|
|
1348
1343
|
}
|
|
1349
1344
|
}
|
|
1350
1345
|
}
|
|
1351
|
-
const patterns =
|
|
1346
|
+
const patterns = build_patterns(esc, type);
|
|
1352
1347
|
for (const re of patterns) {
|
|
1353
|
-
for (const f of
|
|
1348
|
+
for (const f of sorted_files) {
|
|
1354
1349
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1355
1350
|
const c = code(f);
|
|
1356
|
-
const
|
|
1351
|
+
const global_re = new RegExp(re.source, re.flags + "g");
|
|
1357
1352
|
let match;
|
|
1358
|
-
while ((match =
|
|
1359
|
-
const
|
|
1360
|
-
const
|
|
1361
|
-
const
|
|
1362
|
-
const { line, col } =
|
|
1353
|
+
while ((match = global_re.exec(c)) !== null) {
|
|
1354
|
+
const match_text = match[0];
|
|
1355
|
+
const name_offset_in_match = match_text.lastIndexOf(name);
|
|
1356
|
+
const name_start = match.index + Math.max(0, name_offset_in_match);
|
|
1357
|
+
const { line, col } = position_at(f.content, name_start);
|
|
1363
1358
|
return { file: f.path, line, col };
|
|
1364
1359
|
}
|
|
1365
1360
|
}
|
|
@@ -1483,63 +1478,63 @@ var COLORS = {
|
|
|
1483
1478
|
reaction: { bg: "#7e22ce", border: "#a855f7", text: "#d8b4fe" },
|
|
1484
1479
|
projection: { bg: "#15803d", border: "#22c55e", text: "#bbf7d0" }
|
|
1485
1480
|
};
|
|
1486
|
-
function
|
|
1481
|
+
function measure_chain(rDef, lookup, visited, all_states) {
|
|
1487
1482
|
const rows = [];
|
|
1488
|
-
let
|
|
1483
|
+
let dispatch_block_h = 0;
|
|
1489
1484
|
for (const an of rDef.dispatches) {
|
|
1490
|
-
const
|
|
1491
|
-
const
|
|
1485
|
+
const target_action = all_states.flatMap((s) => s.actions).find((a) => a.name === an);
|
|
1486
|
+
const target_state = all_states.find(
|
|
1492
1487
|
(s) => s.actions.some((a) => a.name === an)
|
|
1493
1488
|
);
|
|
1494
|
-
const
|
|
1495
|
-
const
|
|
1489
|
+
const emit_names = target_action?.emits ?? [];
|
|
1490
|
+
const emit_infos = [];
|
|
1496
1491
|
let emitsH = 0;
|
|
1497
|
-
for (const en of
|
|
1492
|
+
for (const en of emit_names) {
|
|
1498
1493
|
const subR = lookup.get(en);
|
|
1499
1494
|
let eventH = H;
|
|
1500
|
-
let
|
|
1495
|
+
let sub_chain;
|
|
1501
1496
|
if (subR && !visited.has(subR.handlerName)) {
|
|
1502
1497
|
visited.add(subR.handlerName);
|
|
1503
|
-
|
|
1504
|
-
eventH = Math.max(H,
|
|
1498
|
+
sub_chain = measure_chain(subR, lookup, visited, all_states);
|
|
1499
|
+
eventH = Math.max(H, sub_chain.groupH);
|
|
1505
1500
|
}
|
|
1506
|
-
|
|
1501
|
+
emit_infos.push({
|
|
1507
1502
|
name: en,
|
|
1508
1503
|
h: eventH,
|
|
1509
|
-
|
|
1510
|
-
|
|
1504
|
+
sub_chain,
|
|
1505
|
+
sub_reaction: subR && sub_chain ? subR : void 0
|
|
1511
1506
|
});
|
|
1512
1507
|
emitsH += eventH;
|
|
1513
1508
|
}
|
|
1514
|
-
const rowH = Math.max(H,
|
|
1515
|
-
rows.push({ an, rowH,
|
|
1516
|
-
if (
|
|
1517
|
-
|
|
1509
|
+
const rowH = Math.max(H, target_state ? STATE_H : 0, emitsH || H);
|
|
1510
|
+
rows.push({ an, rowH, emit_infos, emitsH, target_state });
|
|
1511
|
+
if (dispatch_block_h > 0) dispatch_block_h += GAP / 2;
|
|
1512
|
+
dispatch_block_h += rowH;
|
|
1518
1513
|
}
|
|
1519
|
-
return { groupH: Math.max(H,
|
|
1514
|
+
return { groupH: Math.max(H, dispatch_block_h), dispatch_block_h, rows };
|
|
1520
1515
|
}
|
|
1521
|
-
function
|
|
1522
|
-
const
|
|
1516
|
+
function place_chain(measure, rDef, reactionY, rX, triggered_from_x, triggered_from_y, ns, es, slice_name, lookup, event_projections, event_reactions, event_schemas, slice_right_x_ref) {
|
|
1517
|
+
const dispatch_base_x = rX + W + GAP;
|
|
1523
1518
|
const rp = { x: rX, y: reactionY };
|
|
1524
1519
|
ns.push({
|
|
1525
|
-
key: `r:${rDef.handlerName}:${
|
|
1520
|
+
key: `r:${rDef.handlerName}:${slice_name}`,
|
|
1526
1521
|
pos: rp,
|
|
1527
1522
|
type: "reaction",
|
|
1528
1523
|
label: rDef.handlerName
|
|
1529
1524
|
});
|
|
1530
1525
|
es.push({
|
|
1531
|
-
from: { x:
|
|
1526
|
+
from: { x: triggered_from_x, y: triggered_from_y },
|
|
1532
1527
|
to: { x: rp.x, y: rp.y + H / 2 },
|
|
1533
1528
|
color: COLORS.reaction.border,
|
|
1534
1529
|
dash: true
|
|
1535
1530
|
});
|
|
1536
|
-
const
|
|
1537
|
-
let dispatchY =
|
|
1531
|
+
const reaction_center_y = reactionY + H / 2;
|
|
1532
|
+
let dispatchY = reaction_center_y - measure.dispatch_block_h / 2;
|
|
1538
1533
|
for (const row of measure.rows) {
|
|
1539
|
-
const
|
|
1540
|
-
let nextX =
|
|
1541
|
-
const dap = { x: nextX, y:
|
|
1542
|
-
const
|
|
1534
|
+
const row_center_y = dispatchY + row.rowH / 2;
|
|
1535
|
+
let nextX = dispatch_base_x;
|
|
1536
|
+
const dap = { x: nextX, y: row_center_y - H / 2 };
|
|
1537
|
+
const dispatched_action = row.target_state?.actions.find(
|
|
1543
1538
|
(a) => a.name === row.an
|
|
1544
1539
|
);
|
|
1545
1540
|
ns.push({
|
|
@@ -1547,10 +1542,10 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1547
1542
|
pos: dap,
|
|
1548
1543
|
type: "action",
|
|
1549
1544
|
label: row.an,
|
|
1550
|
-
sub:
|
|
1551
|
-
guards:
|
|
1552
|
-
file: row.
|
|
1553
|
-
emits:
|
|
1545
|
+
sub: dispatched_action && dispatched_action.invariants.length > 0 ? "guarded" : void 0,
|
|
1546
|
+
guards: dispatched_action && dispatched_action.invariants.length > 0 ? dispatched_action.invariants : void 0,
|
|
1547
|
+
file: row.target_state?.file,
|
|
1548
|
+
emits: dispatched_action?.emits
|
|
1554
1549
|
});
|
|
1555
1550
|
es.push({
|
|
1556
1551
|
from: { x: rp.x + W, y: rp.y + H / 2 },
|
|
@@ -1559,106 +1554,106 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1559
1554
|
dash: true
|
|
1560
1555
|
});
|
|
1561
1556
|
nextX += W + GAP;
|
|
1562
|
-
if (row.
|
|
1557
|
+
if (row.target_state) {
|
|
1563
1558
|
ns.push({
|
|
1564
|
-
key: `s:${row.
|
|
1565
|
-
pos: { x: nextX, y:
|
|
1559
|
+
key: `s:${row.target_state.name}:dispatched:${rDef.handlerName}:${row.an}`,
|
|
1560
|
+
pos: { x: nextX, y: row_center_y - STATE_H / 2 },
|
|
1566
1561
|
type: "state",
|
|
1567
|
-
label: row.
|
|
1568
|
-
file: row.
|
|
1562
|
+
label: row.target_state.name,
|
|
1563
|
+
file: row.target_state.file
|
|
1569
1564
|
});
|
|
1570
1565
|
nextX += STATE_W + GAP;
|
|
1571
1566
|
}
|
|
1572
1567
|
const evtX = nextX;
|
|
1573
|
-
const nEvents = row.
|
|
1574
|
-
const
|
|
1575
|
-
let emitY =
|
|
1576
|
-
for (const emit of row.
|
|
1568
|
+
const nEvents = row.emit_infos.length;
|
|
1569
|
+
const events_only_h = nEvents * H + (nEvents - 1) * (GAP / 2);
|
|
1570
|
+
let emitY = row_center_y - events_only_h / 2;
|
|
1571
|
+
for (const emit of row.emit_infos) {
|
|
1577
1572
|
ns.push({
|
|
1578
1573
|
key: `e:${emit.name}:dispatched:${rDef.handlerName}:${row.an}`,
|
|
1579
1574
|
pos: { x: evtX, y: emitY },
|
|
1580
1575
|
type: "event",
|
|
1581
1576
|
label: emit.name,
|
|
1582
|
-
file: row.
|
|
1583
|
-
projections:
|
|
1584
|
-
reactions:
|
|
1585
|
-
schema:
|
|
1577
|
+
file: row.target_state?.file,
|
|
1578
|
+
projections: event_projections.get(emit.name),
|
|
1579
|
+
reactions: event_reactions.get(emit.name),
|
|
1580
|
+
schema: event_schemas.get(emit.name)
|
|
1586
1581
|
});
|
|
1587
|
-
if (emit.
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
emit.
|
|
1591
|
-
emit.
|
|
1582
|
+
if (emit.sub_chain && emit.sub_reaction) {
|
|
1583
|
+
const sub_r_x = evtX + W + GAP * 3;
|
|
1584
|
+
place_chain(
|
|
1585
|
+
emit.sub_chain,
|
|
1586
|
+
emit.sub_reaction,
|
|
1592
1587
|
emitY,
|
|
1593
1588
|
// reaction aligns with emit
|
|
1594
|
-
|
|
1589
|
+
sub_r_x,
|
|
1595
1590
|
evtX + W,
|
|
1596
1591
|
emitY + H / 2,
|
|
1597
1592
|
ns,
|
|
1598
1593
|
es,
|
|
1599
|
-
|
|
1594
|
+
slice_name,
|
|
1600
1595
|
lookup,
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1596
|
+
event_projections,
|
|
1597
|
+
event_reactions,
|
|
1598
|
+
event_schemas,
|
|
1599
|
+
slice_right_x_ref
|
|
1605
1600
|
);
|
|
1606
1601
|
}
|
|
1607
1602
|
emitY += H + GAP / 2;
|
|
1608
1603
|
}
|
|
1609
|
-
if (row.
|
|
1610
|
-
|
|
1604
|
+
if (row.emit_infos.length > 0) nextX = evtX + W + GAP;
|
|
1605
|
+
slice_right_x_ref.value = Math.max(slice_right_x_ref.value, nextX);
|
|
1611
1606
|
dispatchY += row.rowH + GAP / 2;
|
|
1612
1607
|
}
|
|
1613
1608
|
}
|
|
1614
|
-
function
|
|
1609
|
+
function compute_layout(view_model) {
|
|
1615
1610
|
const ns = [];
|
|
1616
1611
|
const es = [];
|
|
1617
1612
|
const boxes = [];
|
|
1618
1613
|
const sv = /* @__PURE__ */ new Map();
|
|
1619
|
-
for (const s of
|
|
1614
|
+
for (const s of view_model.states) {
|
|
1620
1615
|
sv.set(s.varName, s);
|
|
1621
1616
|
sv.set(s.name, s);
|
|
1622
1617
|
}
|
|
1623
|
-
const
|
|
1624
|
-
const
|
|
1625
|
-
const
|
|
1626
|
-
for (const s of
|
|
1618
|
+
const event_projections = /* @__PURE__ */ new Map();
|
|
1619
|
+
const event_reactions = /* @__PURE__ */ new Map();
|
|
1620
|
+
const event_schemas = /* @__PURE__ */ new Map();
|
|
1621
|
+
for (const s of view_model.states) {
|
|
1627
1622
|
for (const e of s.events) {
|
|
1628
|
-
if (e.schema && !
|
|
1629
|
-
|
|
1623
|
+
if (e.schema && !event_schemas.has(e.name)) {
|
|
1624
|
+
event_schemas.set(e.name, e.schema);
|
|
1630
1625
|
}
|
|
1631
1626
|
}
|
|
1632
1627
|
}
|
|
1633
|
-
const
|
|
1634
|
-
for (const proj of
|
|
1635
|
-
|
|
1628
|
+
const projection_handles = /* @__PURE__ */ new Map();
|
|
1629
|
+
for (const proj of view_model.projections) {
|
|
1630
|
+
projection_handles.set(proj.name, proj.handles);
|
|
1636
1631
|
}
|
|
1637
|
-
for (const slice of
|
|
1632
|
+
for (const slice of view_model.slices) {
|
|
1638
1633
|
for (const r of slice.reactions) {
|
|
1639
|
-
const list =
|
|
1634
|
+
const list = event_reactions.get(r.event) ?? [];
|
|
1640
1635
|
list.push(r.handlerName);
|
|
1641
|
-
|
|
1636
|
+
event_reactions.set(r.event, list);
|
|
1642
1637
|
}
|
|
1643
1638
|
}
|
|
1644
|
-
for (const r of
|
|
1645
|
-
const list =
|
|
1639
|
+
for (const r of view_model.reactions) {
|
|
1640
|
+
const list = event_reactions.get(r.event) ?? [];
|
|
1646
1641
|
list.push(r.handlerName);
|
|
1647
|
-
|
|
1642
|
+
event_reactions.set(r.event, list);
|
|
1648
1643
|
}
|
|
1649
|
-
for (const proj of
|
|
1644
|
+
for (const proj of view_model.projections) {
|
|
1650
1645
|
for (const en of proj.handles) {
|
|
1651
|
-
const list =
|
|
1646
|
+
const list = event_projections.get(en) ?? [];
|
|
1652
1647
|
list.push(proj.name);
|
|
1653
|
-
|
|
1648
|
+
event_projections.set(en, list);
|
|
1654
1649
|
}
|
|
1655
1650
|
}
|
|
1656
1651
|
let cx = PAD;
|
|
1657
1652
|
let globalY = 0;
|
|
1658
|
-
const
|
|
1653
|
+
const sorted_slices = [...view_model.slices].sort(
|
|
1659
1654
|
(a, b) => a.name.localeCompare(b.name)
|
|
1660
1655
|
);
|
|
1661
|
-
for (const slice of
|
|
1656
|
+
for (const slice of sorted_slices) {
|
|
1662
1657
|
if (slice.error && slice.states.length === 0) {
|
|
1663
1658
|
const sx2 = PAD;
|
|
1664
1659
|
const errorW = Math.max(300, slice.error.length * 5);
|
|
@@ -1678,181 +1673,181 @@ function computeLayout(viewModel) {
|
|
|
1678
1673
|
cx = PAD;
|
|
1679
1674
|
const sx = cx;
|
|
1680
1675
|
cx += SLICE_PAD + GAP;
|
|
1681
|
-
const
|
|
1682
|
-
const
|
|
1683
|
-
const
|
|
1684
|
-
const
|
|
1685
|
-
for (const st of
|
|
1676
|
+
const event_file_map = /* @__PURE__ */ new Map();
|
|
1677
|
+
const action_file_map = /* @__PURE__ */ new Map();
|
|
1678
|
+
const raw_parts = slice.stateVars.map((v) => sv.get(v)).filter(Boolean);
|
|
1679
|
+
const merged_by_name = /* @__PURE__ */ new Map();
|
|
1680
|
+
for (const st of raw_parts) {
|
|
1686
1681
|
for (const e of st.events) {
|
|
1687
|
-
if (st.file)
|
|
1682
|
+
if (st.file) event_file_map.set(e.name, st.file);
|
|
1688
1683
|
}
|
|
1689
1684
|
for (const a of st.actions) {
|
|
1690
|
-
if (st.file)
|
|
1685
|
+
if (st.file) action_file_map.set(a.name, st.file);
|
|
1691
1686
|
}
|
|
1692
|
-
const existing =
|
|
1687
|
+
const existing = merged_by_name.get(st.name);
|
|
1693
1688
|
if (existing) {
|
|
1694
|
-
const
|
|
1689
|
+
const action_names = new Set(existing.actions.map((a) => a.name));
|
|
1695
1690
|
for (const a of st.actions) {
|
|
1696
|
-
if (!
|
|
1691
|
+
if (!action_names.has(a.name)) existing.actions.push(a);
|
|
1697
1692
|
}
|
|
1698
|
-
const
|
|
1693
|
+
const event_names = new Set(existing.events.map((e) => e.name));
|
|
1699
1694
|
for (const e of st.events) {
|
|
1700
|
-
if (!
|
|
1695
|
+
if (!event_names.has(e.name)) existing.events.push(e);
|
|
1701
1696
|
}
|
|
1702
1697
|
} else {
|
|
1703
|
-
|
|
1698
|
+
merged_by_name.set(st.name, {
|
|
1704
1699
|
...st,
|
|
1705
1700
|
actions: [...st.actions],
|
|
1706
1701
|
events: [...st.events]
|
|
1707
1702
|
});
|
|
1708
1703
|
}
|
|
1709
1704
|
}
|
|
1710
|
-
const parts = [...
|
|
1705
|
+
const parts = [...merged_by_name.values()];
|
|
1711
1706
|
let y = SLICE_INNER;
|
|
1712
|
-
let
|
|
1713
|
-
const
|
|
1714
|
-
const
|
|
1715
|
-
const
|
|
1707
|
+
let slice_right_x = cx;
|
|
1708
|
+
const slice_node_start = ns.length;
|
|
1709
|
+
const slice_edge_start = es.length;
|
|
1710
|
+
const slice_reactions_by_event = /* @__PURE__ */ new Map();
|
|
1716
1711
|
for (const r of slice.reactions) {
|
|
1717
|
-
const list =
|
|
1712
|
+
const list = slice_reactions_by_event.get(r.event) ?? [];
|
|
1718
1713
|
list.push(r);
|
|
1719
|
-
|
|
1714
|
+
slice_reactions_by_event.set(r.event, list);
|
|
1720
1715
|
}
|
|
1721
|
-
const
|
|
1722
|
-
for (const [event, reactions] of
|
|
1723
|
-
|
|
1716
|
+
const slice_reaction_by_event = /* @__PURE__ */ new Map();
|
|
1717
|
+
for (const [event, reactions] of slice_reactions_by_event) {
|
|
1718
|
+
slice_reaction_by_event.set(event, reactions[0]);
|
|
1724
1719
|
}
|
|
1725
|
-
const
|
|
1726
|
-
const
|
|
1727
|
-
let
|
|
1720
|
+
const visited_events = /* @__PURE__ */ new Set();
|
|
1721
|
+
const visited_reactions = /* @__PURE__ */ new Set();
|
|
1722
|
+
let part_idx = 0;
|
|
1728
1723
|
for (const st of parts) {
|
|
1729
|
-
if (
|
|
1730
|
-
const
|
|
1731
|
-
const
|
|
1732
|
-
const
|
|
1733
|
-
const
|
|
1724
|
+
if (part_idx > 0) y += GAP * 2;
|
|
1725
|
+
const state_col_x = cx + W + GAP;
|
|
1726
|
+
const event_col_x = state_col_x + STATE_W + GAP;
|
|
1727
|
+
const event_rows = [];
|
|
1728
|
+
const action_emitted = /* @__PURE__ */ new Set();
|
|
1734
1729
|
for (const action of st.actions) {
|
|
1735
1730
|
for (const en of action.emits) {
|
|
1736
|
-
|
|
1731
|
+
action_emitted.add(en);
|
|
1737
1732
|
}
|
|
1738
1733
|
}
|
|
1739
1734
|
for (const ev of st.events) {
|
|
1740
|
-
if (!
|
|
1741
|
-
|
|
1735
|
+
if (!action_emitted.has(ev.name)) {
|
|
1736
|
+
event_rows.push({ event_name: ev.name, action_name: "" });
|
|
1742
1737
|
}
|
|
1743
1738
|
}
|
|
1744
1739
|
for (const action of st.actions) {
|
|
1745
1740
|
for (const en of action.emits) {
|
|
1746
|
-
|
|
1741
|
+
event_rows.push({ event_name: en, action_name: action.name });
|
|
1747
1742
|
}
|
|
1748
1743
|
}
|
|
1749
|
-
const
|
|
1750
|
-
let
|
|
1751
|
-
for (const {
|
|
1744
|
+
const measured_events = [];
|
|
1745
|
+
let evt_block_h = 0;
|
|
1746
|
+
for (const { event_name: en, action_name } of event_rows) {
|
|
1752
1747
|
const chains = [];
|
|
1753
|
-
if (!
|
|
1754
|
-
const rDefs =
|
|
1748
|
+
if (!visited_events.has(en)) {
|
|
1749
|
+
const rDefs = slice_reactions_by_event.get(en) ?? [];
|
|
1755
1750
|
for (const rDef of rDefs) {
|
|
1756
|
-
if (
|
|
1757
|
-
|
|
1758
|
-
const chain =
|
|
1751
|
+
if (visited_reactions.has(rDef.handlerName)) continue;
|
|
1752
|
+
visited_reactions.add(rDef.handlerName);
|
|
1753
|
+
const chain = measure_chain(
|
|
1759
1754
|
rDef,
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1755
|
+
slice_reaction_by_event,
|
|
1756
|
+
visited_reactions,
|
|
1757
|
+
view_model.states
|
|
1763
1758
|
);
|
|
1764
1759
|
chains.push({ chain, reaction: rDef });
|
|
1765
1760
|
}
|
|
1766
|
-
if (rDefs.length > 0)
|
|
1761
|
+
if (rDefs.length > 0) visited_events.add(en);
|
|
1767
1762
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1763
|
+
measured_events.push({
|
|
1764
|
+
event_name: en,
|
|
1765
|
+
action_name,
|
|
1771
1766
|
h: H,
|
|
1772
1767
|
chains
|
|
1773
1768
|
});
|
|
1774
|
-
if (
|
|
1775
|
-
|
|
1769
|
+
if (evt_block_h > 0) evt_block_h += GAP / 2;
|
|
1770
|
+
evt_block_h += H;
|
|
1776
1771
|
}
|
|
1777
|
-
if (
|
|
1772
|
+
if (evt_block_h === 0) evt_block_h = H;
|
|
1778
1773
|
const nActs = st.actions.length;
|
|
1779
|
-
const
|
|
1780
|
-
const
|
|
1781
|
-
const
|
|
1774
|
+
const act_block_h = nActs * H + (nActs - 1) * (GAP / 2);
|
|
1775
|
+
const primary_block_h = Math.max(evt_block_h, act_block_h, STATE_H);
|
|
1776
|
+
const st_center_y = y + primary_block_h / 2;
|
|
1782
1777
|
ns.push({
|
|
1783
1778
|
key: `s:${st.name}:${slice.name}`,
|
|
1784
|
-
pos: { x:
|
|
1779
|
+
pos: { x: state_col_x, y: st_center_y - STATE_H / 2 },
|
|
1785
1780
|
type: "state",
|
|
1786
1781
|
label: st.name,
|
|
1787
1782
|
file: st.file
|
|
1788
1783
|
});
|
|
1789
|
-
const
|
|
1790
|
-
let evtY =
|
|
1791
|
-
let
|
|
1792
|
-
const
|
|
1793
|
-
for (let ei = 0; ei <
|
|
1794
|
-
const {
|
|
1784
|
+
const slice_right_x_ref = { value: slice_right_x };
|
|
1785
|
+
let evtY = st_center_y - evt_block_h / 2;
|
|
1786
|
+
let chain_watermark = -Infinity;
|
|
1787
|
+
const event_y_map = /* @__PURE__ */ new Map();
|
|
1788
|
+
for (let ei = 0; ei < measured_events.length; ei++) {
|
|
1789
|
+
const { event_name: en, action_name, chains } = measured_events[ei];
|
|
1795
1790
|
ns.push({
|
|
1796
|
-
key: `e:${en}:${slice.name}:${
|
|
1797
|
-
pos: { x:
|
|
1791
|
+
key: `e:${en}:${slice.name}:${action_name}`,
|
|
1792
|
+
pos: { x: event_col_x, y: evtY },
|
|
1798
1793
|
type: "event",
|
|
1799
1794
|
label: en,
|
|
1800
|
-
file:
|
|
1801
|
-
projections:
|
|
1802
|
-
reactions:
|
|
1803
|
-
schema:
|
|
1795
|
+
file: event_file_map.get(en) ?? st.file,
|
|
1796
|
+
projections: event_projections.get(en),
|
|
1797
|
+
reactions: event_reactions.get(en),
|
|
1798
|
+
schema: event_schemas.get(en)
|
|
1804
1799
|
});
|
|
1805
|
-
|
|
1806
|
-
for (const { chain, reaction:
|
|
1807
|
-
const rX =
|
|
1808
|
-
const
|
|
1809
|
-
const reactionY = Math.max(evtY,
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1800
|
+
event_y_map.set(en, evtY);
|
|
1801
|
+
for (const { chain, reaction: chain_reaction } of chains) {
|
|
1802
|
+
const rX = event_col_x + W + GAP * 3;
|
|
1803
|
+
const min_reaction_y = chain_watermark + chain.dispatch_block_h / 2 - H / 2;
|
|
1804
|
+
const reactionY = Math.max(evtY, min_reaction_y);
|
|
1805
|
+
const chain_start_idx = ns.length;
|
|
1806
|
+
place_chain(
|
|
1812
1807
|
chain,
|
|
1813
|
-
|
|
1808
|
+
chain_reaction,
|
|
1814
1809
|
reactionY,
|
|
1815
1810
|
rX,
|
|
1816
|
-
|
|
1811
|
+
event_col_x + W,
|
|
1817
1812
|
evtY + H / 2,
|
|
1818
1813
|
// arrow always from event center
|
|
1819
1814
|
ns,
|
|
1820
1815
|
es,
|
|
1821
1816
|
slice.name,
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1817
|
+
slice_reaction_by_event,
|
|
1818
|
+
event_projections,
|
|
1819
|
+
event_reactions,
|
|
1820
|
+
event_schemas,
|
|
1821
|
+
slice_right_x_ref
|
|
1827
1822
|
);
|
|
1828
|
-
for (let ni =
|
|
1823
|
+
for (let ni = chain_start_idx; ni < ns.length; ni++) {
|
|
1829
1824
|
const n = ns[ni];
|
|
1830
1825
|
const nh = n.type === "state" ? STATE_H : H;
|
|
1831
|
-
|
|
1826
|
+
chain_watermark = Math.max(chain_watermark, n.pos.y + nh + GAP / 2);
|
|
1832
1827
|
}
|
|
1833
1828
|
}
|
|
1834
1829
|
evtY += H + GAP / 2;
|
|
1835
1830
|
}
|
|
1836
|
-
const
|
|
1837
|
-
for (const me of
|
|
1838
|
-
const projs =
|
|
1831
|
+
const seen_proj = /* @__PURE__ */ new Set();
|
|
1832
|
+
for (const me of measured_events) {
|
|
1833
|
+
const projs = event_projections.get(me.event_name);
|
|
1839
1834
|
if (!projs) continue;
|
|
1840
1835
|
for (const pn of projs) {
|
|
1841
|
-
if (
|
|
1842
|
-
|
|
1836
|
+
if (seen_proj.has(pn)) continue;
|
|
1837
|
+
seen_proj.add(pn);
|
|
1843
1838
|
ns.push({
|
|
1844
1839
|
key: `p:${pn}:${slice.name}`,
|
|
1845
|
-
pos: { x:
|
|
1840
|
+
pos: { x: event_col_x, y: evtY },
|
|
1846
1841
|
type: "projection",
|
|
1847
1842
|
label: pn,
|
|
1848
|
-
handles:
|
|
1843
|
+
handles: projection_handles.get(pn)
|
|
1849
1844
|
});
|
|
1850
1845
|
evtY += H + GAP / 2;
|
|
1851
1846
|
}
|
|
1852
1847
|
}
|
|
1853
|
-
|
|
1854
|
-
let actY =
|
|
1855
|
-
const
|
|
1848
|
+
slice_right_x = slice_right_x_ref.value;
|
|
1849
|
+
let actY = st_center_y - act_block_h / 2;
|
|
1850
|
+
const action_colors = [
|
|
1856
1851
|
"#60a5fa",
|
|
1857
1852
|
"#f97316",
|
|
1858
1853
|
"#a78bfa",
|
|
@@ -1860,9 +1855,9 @@ function computeLayout(viewModel) {
|
|
|
1860
1855
|
"#fb7185",
|
|
1861
1856
|
"#fbbf24"
|
|
1862
1857
|
];
|
|
1863
|
-
let
|
|
1858
|
+
let action_idx = 0;
|
|
1864
1859
|
for (const action of st.actions) {
|
|
1865
|
-
const color =
|
|
1860
|
+
const color = action_colors[action_idx % action_colors.length];
|
|
1866
1861
|
ns.push({
|
|
1867
1862
|
key: `a:${action.name}:${slice.name}`,
|
|
1868
1863
|
pos: { x: cx, y: actY },
|
|
@@ -1870,32 +1865,32 @@ function computeLayout(viewModel) {
|
|
|
1870
1865
|
label: action.name,
|
|
1871
1866
|
sub: action.invariants.length > 0 ? "guarded" : void 0,
|
|
1872
1867
|
guards: action.invariants.length > 0 ? action.invariants : void 0,
|
|
1873
|
-
file:
|
|
1868
|
+
file: action_file_map.get(action.name) ?? st.file,
|
|
1874
1869
|
emits: action.emits
|
|
1875
1870
|
});
|
|
1876
1871
|
for (const en of action.emits) {
|
|
1877
|
-
const ey =
|
|
1872
|
+
const ey = event_y_map.get(en);
|
|
1878
1873
|
es.push({
|
|
1879
1874
|
from: { x: cx + W, y: actY + H / 2 },
|
|
1880
|
-
to: { x:
|
|
1875
|
+
to: { x: event_col_x, y: ey + H / 2 },
|
|
1881
1876
|
color,
|
|
1882
1877
|
dash: false
|
|
1883
1878
|
});
|
|
1884
1879
|
}
|
|
1885
1880
|
actY += H + GAP / 2;
|
|
1886
|
-
|
|
1881
|
+
action_idx++;
|
|
1887
1882
|
}
|
|
1888
|
-
const
|
|
1889
|
-
y +
|
|
1883
|
+
const content_bottom_y = Math.max(
|
|
1884
|
+
y + primary_block_h,
|
|
1890
1885
|
evtY,
|
|
1891
|
-
|
|
1886
|
+
chain_watermark > -Infinity ? chain_watermark : 0
|
|
1892
1887
|
);
|
|
1893
|
-
y =
|
|
1894
|
-
|
|
1888
|
+
y = content_bottom_y + GAP / 2;
|
|
1889
|
+
part_idx++;
|
|
1895
1890
|
}
|
|
1896
1891
|
for (const r of slice.reactions) {
|
|
1897
|
-
if (
|
|
1898
|
-
const rX =
|
|
1892
|
+
if (visited_reactions.has(r.handlerName)) continue;
|
|
1893
|
+
const rX = slice_right_x + GAP * 2;
|
|
1899
1894
|
const rp = { x: rX, y };
|
|
1900
1895
|
ns.push({
|
|
1901
1896
|
key: `r:${r.handlerName}:${slice.name}`,
|
|
@@ -1903,7 +1898,7 @@ function computeLayout(viewModel) {
|
|
|
1903
1898
|
type: "reaction",
|
|
1904
1899
|
label: r.handlerName
|
|
1905
1900
|
});
|
|
1906
|
-
|
|
1901
|
+
slice_right_x = Math.max(slice_right_x, rX + W + GAP);
|
|
1907
1902
|
y += H + GAP / 2;
|
|
1908
1903
|
}
|
|
1909
1904
|
const bbox = {
|
|
@@ -1912,7 +1907,7 @@ function computeLayout(viewModel) {
|
|
|
1912
1907
|
maxX: -Infinity,
|
|
1913
1908
|
maxY: -Infinity
|
|
1914
1909
|
};
|
|
1915
|
-
for (let ni =
|
|
1910
|
+
for (let ni = slice_node_start; ni < ns.length; ni++) {
|
|
1916
1911
|
const n = ns[ni];
|
|
1917
1912
|
const nw = n.type === "state" ? STATE_W : W;
|
|
1918
1913
|
const nh = n.type === "state" ? STATE_H : H;
|
|
@@ -1930,10 +1925,10 @@ function computeLayout(viewModel) {
|
|
|
1930
1925
|
const contentH = bbox.maxY - bbox.minY;
|
|
1931
1926
|
const boxH = contentH + SLICE_INNER * 2;
|
|
1932
1927
|
const dy = globalY - bbox.minY + SLICE_INNER;
|
|
1933
|
-
for (let ni =
|
|
1928
|
+
for (let ni = slice_node_start; ni < ns.length; ni++) {
|
|
1934
1929
|
ns[ni].pos.y += dy;
|
|
1935
1930
|
}
|
|
1936
|
-
for (let ei =
|
|
1931
|
+
for (let ei = slice_edge_start; ei < es.length; ei++) {
|
|
1937
1932
|
es[ei].from.y += dy;
|
|
1938
1933
|
es[ei].to.y += dy;
|
|
1939
1934
|
}
|
|
@@ -1948,57 +1943,57 @@ function computeLayout(viewModel) {
|
|
|
1948
1943
|
globalY += boxH + SLICE_GAP;
|
|
1949
1944
|
}
|
|
1950
1945
|
cx = PAD;
|
|
1951
|
-
const claimed = new Set(
|
|
1952
|
-
const
|
|
1953
|
-
for (const st of
|
|
1954
|
-
const
|
|
1955
|
-
const
|
|
1956
|
-
const
|
|
1957
|
-
const
|
|
1958
|
-
const nEvents =
|
|
1959
|
-
const
|
|
1946
|
+
const claimed = new Set(sorted_slices.flatMap((sl) => sl.stateVars));
|
|
1947
|
+
const standalone_states = [...view_model.states].filter((s) => !claimed.has(s.varName)).sort((a, b) => a.name.localeCompare(b.name));
|
|
1948
|
+
for (const st of standalone_states) {
|
|
1949
|
+
const state_col_x = cx + W + GAP;
|
|
1950
|
+
const event_col_x = state_col_x + STATE_W + GAP;
|
|
1951
|
+
const action_emitted_events = new Set(st.actions.flatMap((a) => a.emits));
|
|
1952
|
+
const orphan_events = st.events.map((e) => e.name).filter((en) => !action_emitted_events.has(en));
|
|
1953
|
+
const nEvents = action_emitted_events.size + orphan_events.length;
|
|
1954
|
+
const evt_block_h = Math.max(nEvents, 1) * H + (Math.max(nEvents, 1) - 1) * (GAP / 2);
|
|
1960
1955
|
const nActs = st.actions.length;
|
|
1961
|
-
const
|
|
1962
|
-
const blockH = Math.max(
|
|
1963
|
-
const
|
|
1956
|
+
const act_block_h = nActs * H + (nActs - 1) * (GAP / 2);
|
|
1957
|
+
const blockH = Math.max(evt_block_h, act_block_h, STATE_H);
|
|
1958
|
+
const st_center_y = globalY + blockH / 2;
|
|
1964
1959
|
ns.push({
|
|
1965
1960
|
key: `s:${st.name}:standalone`,
|
|
1966
|
-
pos: { x:
|
|
1961
|
+
pos: { x: state_col_x, y: st_center_y - STATE_H / 2 },
|
|
1967
1962
|
type: "state",
|
|
1968
1963
|
label: st.name
|
|
1969
1964
|
});
|
|
1970
|
-
let evtY =
|
|
1971
|
-
const
|
|
1965
|
+
let evtY = st_center_y - evt_block_h / 2;
|
|
1966
|
+
const event_y_map = /* @__PURE__ */ new Map();
|
|
1972
1967
|
for (const action of st.actions) {
|
|
1973
1968
|
for (const en of action.emits) {
|
|
1974
1969
|
ns.push({
|
|
1975
1970
|
key: `e:${en}:standalone`,
|
|
1976
|
-
pos: { x:
|
|
1971
|
+
pos: { x: event_col_x, y: evtY },
|
|
1977
1972
|
type: "event",
|
|
1978
1973
|
label: en,
|
|
1979
|
-
projections:
|
|
1980
|
-
reactions:
|
|
1981
|
-
schema:
|
|
1974
|
+
projections: event_projections.get(en),
|
|
1975
|
+
reactions: event_reactions.get(en),
|
|
1976
|
+
schema: event_schemas.get(en)
|
|
1982
1977
|
});
|
|
1983
|
-
|
|
1978
|
+
event_y_map.set(en, evtY);
|
|
1984
1979
|
evtY += H + GAP / 2;
|
|
1985
1980
|
}
|
|
1986
1981
|
}
|
|
1987
|
-
for (const en of
|
|
1982
|
+
for (const en of orphan_events) {
|
|
1988
1983
|
ns.push({
|
|
1989
1984
|
key: `e:${en}:standalone`,
|
|
1990
|
-
pos: { x:
|
|
1985
|
+
pos: { x: event_col_x, y: evtY },
|
|
1991
1986
|
type: "event",
|
|
1992
1987
|
label: en,
|
|
1993
|
-
projections:
|
|
1994
|
-
reactions:
|
|
1995
|
-
schema:
|
|
1988
|
+
projections: event_projections.get(en),
|
|
1989
|
+
reactions: event_reactions.get(en),
|
|
1990
|
+
schema: event_schemas.get(en)
|
|
1996
1991
|
});
|
|
1997
|
-
|
|
1992
|
+
event_y_map.set(en, evtY);
|
|
1998
1993
|
evtY += H + GAP / 2;
|
|
1999
1994
|
}
|
|
2000
|
-
let actY =
|
|
2001
|
-
const
|
|
1995
|
+
let actY = st_center_y - act_block_h / 2;
|
|
1996
|
+
const standalone_colors = [
|
|
2002
1997
|
"#60a5fa",
|
|
2003
1998
|
"#f97316",
|
|
2004
1999
|
"#a78bfa",
|
|
@@ -2008,7 +2003,7 @@ function computeLayout(viewModel) {
|
|
|
2008
2003
|
];
|
|
2009
2004
|
let aIdx = 0;
|
|
2010
2005
|
for (const action of st.actions) {
|
|
2011
|
-
const aColor =
|
|
2006
|
+
const aColor = standalone_colors[aIdx % standalone_colors.length];
|
|
2012
2007
|
ns.push({
|
|
2013
2008
|
key: `a:${action.name}:standalone`,
|
|
2014
2009
|
pos: { x: cx, y: actY },
|
|
@@ -2019,10 +2014,10 @@ function computeLayout(viewModel) {
|
|
|
2019
2014
|
emits: action.emits
|
|
2020
2015
|
});
|
|
2021
2016
|
for (const en of action.emits) {
|
|
2022
|
-
const ey =
|
|
2017
|
+
const ey = event_y_map.get(en);
|
|
2023
2018
|
es.push({
|
|
2024
2019
|
from: { x: cx + W, y: actY + H / 2 },
|
|
2025
|
-
to: { x:
|
|
2020
|
+
to: { x: event_col_x, y: ey + H / 2 },
|
|
2026
2021
|
color: aColor,
|
|
2027
2022
|
dash: false
|
|
2028
2023
|
});
|
|
@@ -2032,15 +2027,15 @@ function computeLayout(viewModel) {
|
|
|
2032
2027
|
}
|
|
2033
2028
|
globalY += blockH + GAP * 2;
|
|
2034
2029
|
}
|
|
2035
|
-
if (
|
|
2036
|
-
const
|
|
2037
|
-
for (const r of
|
|
2038
|
-
const
|
|
2030
|
+
if (view_model.reactions.length > 0) {
|
|
2031
|
+
const reaction_y_by_event = /* @__PURE__ */ new Map();
|
|
2032
|
+
for (const r of view_model.reactions) {
|
|
2033
|
+
const trig_node = ns.find(
|
|
2039
2034
|
(n) => n.type === "event" && n.label === r.event
|
|
2040
2035
|
);
|
|
2041
|
-
const baseY =
|
|
2042
|
-
const rY =
|
|
2043
|
-
const rX =
|
|
2036
|
+
const baseY = trig_node ? trig_node.pos.y : globalY;
|
|
2037
|
+
const rY = reaction_y_by_event.get(r.event) ?? baseY;
|
|
2038
|
+
const rX = trig_node ? trig_node.pos.x + W + GAP * 3 : cx + W * 3 + GAP * 4;
|
|
2044
2039
|
const rp = { x: rX, y: rY };
|
|
2045
2040
|
ns.push({
|
|
2046
2041
|
key: `r:${r.handlerName}:standalone`,
|
|
@@ -2048,15 +2043,15 @@ function computeLayout(viewModel) {
|
|
|
2048
2043
|
type: "reaction",
|
|
2049
2044
|
label: r.handlerName
|
|
2050
2045
|
});
|
|
2051
|
-
if (
|
|
2046
|
+
if (trig_node) {
|
|
2052
2047
|
es.push({
|
|
2053
|
-
from: { x:
|
|
2048
|
+
from: { x: trig_node.pos.x + W, y: trig_node.pos.y + H / 2 },
|
|
2054
2049
|
to: { x: rp.x, y: rp.y + H / 2 },
|
|
2055
2050
|
color: COLORS.reaction.border,
|
|
2056
2051
|
dash: true
|
|
2057
2052
|
});
|
|
2058
2053
|
}
|
|
2059
|
-
|
|
2054
|
+
reaction_y_by_event.set(r.event, rY + H + GAP / 2);
|
|
2060
2055
|
globalY = Math.max(globalY, rY + H + GAP);
|
|
2061
2056
|
}
|
|
2062
2057
|
}
|
|
@@ -2120,10 +2115,10 @@ function splitLabel(label, maxChars = 16) {
|
|
|
2120
2115
|
function formatModelTree(model) {
|
|
2121
2116
|
const lines = [];
|
|
2122
2117
|
for (const entry of model.entries) {
|
|
2123
|
-
const
|
|
2118
|
+
const sorted_slices = [...entry.slices].sort(
|
|
2124
2119
|
(a, b) => a.name.localeCompare(b.name)
|
|
2125
2120
|
);
|
|
2126
|
-
for (const sl of
|
|
2121
|
+
for (const sl of sorted_slices) {
|
|
2127
2122
|
lines.push(`Slice: ${sl.name}`);
|
|
2128
2123
|
for (const stKey of sl.stateVars) {
|
|
2129
2124
|
const st = entry.states.find((s) => s.varName === stKey);
|
|
@@ -2145,9 +2140,9 @@ function formatModelTree(model) {
|
|
|
2145
2140
|
for (const p of entry.projections) {
|
|
2146
2141
|
lines.push(`Projection: ${p.name} [${p.handles.join(", ")}]`);
|
|
2147
2142
|
}
|
|
2148
|
-
const
|
|
2143
|
+
const slice_state_keys = new Set(entry.slices.flatMap((sl) => sl.stateVars));
|
|
2149
2144
|
for (const st of entry.states.filter(
|
|
2150
|
-
(s) => !
|
|
2145
|
+
(s) => !slice_state_keys.has(s.varName)
|
|
2151
2146
|
)) {
|
|
2152
2147
|
lines.push(`State: ${st.name}`);
|
|
2153
2148
|
for (const a of st.actions) {
|
|
@@ -2193,7 +2188,7 @@ function Diagram({
|
|
|
2193
2188
|
const [pan, setPan] = (0, import_react2.useState)({ x: 0, y: 0 });
|
|
2194
2189
|
const [zoom, setZoom] = (0, import_react2.useState)(1);
|
|
2195
2190
|
const entry = model.entries[activeTab];
|
|
2196
|
-
const
|
|
2191
|
+
const view_model = entry ? {
|
|
2197
2192
|
...model,
|
|
2198
2193
|
entries: [entry],
|
|
2199
2194
|
states: entry.states,
|
|
@@ -2272,7 +2267,7 @@ function Diagram({
|
|
|
2272
2267
|
const { ns, es, boxes, minX, minY, width, height, layoutError } = (0, import_react2.useMemo)(() => {
|
|
2273
2268
|
try {
|
|
2274
2269
|
return {
|
|
2275
|
-
...
|
|
2270
|
+
...compute_layout(view_model),
|
|
2276
2271
|
layoutError: void 0
|
|
2277
2272
|
};
|
|
2278
2273
|
} catch (e) {
|
|
@@ -2288,7 +2283,7 @@ function Diagram({
|
|
|
2288
2283
|
layoutError: msg
|
|
2289
2284
|
};
|
|
2290
2285
|
}
|
|
2291
|
-
}, [
|
|
2286
|
+
}, [view_model]);
|
|
2292
2287
|
const fitTransform = (0, import_react2.useCallback)(() => {
|
|
2293
2288
|
const el = svgContainerRef.current;
|
|
2294
2289
|
const cw = el?.clientWidth || 800;
|
|
@@ -2316,7 +2311,7 @@ function Diagram({
|
|
|
2316
2311
|
layoutError
|
|
2317
2312
|
] });
|
|
2318
2313
|
}
|
|
2319
|
-
if (
|
|
2314
|
+
if (view_model.states.length === 0 && view_model.projections.length === 0) {
|
|
2320
2315
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex h-full items-center justify-center text-xs text-zinc-600", children: "Nothing to diagram here" });
|
|
2321
2316
|
}
|
|
2322
2317
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "relative flex h-full flex-col bg-zinc-950", children: [
|
|
@@ -2383,7 +2378,7 @@ function Diagram({
|
|
|
2383
2378
|
title: "@rotorsoft/act-diagram version",
|
|
2384
2379
|
children: [
|
|
2385
2380
|
"v",
|
|
2386
|
-
"0.
|
|
2381
|
+
"1.0.1"
|
|
2387
2382
|
]
|
|
2388
2383
|
}
|
|
2389
2384
|
)
|
|
@@ -2413,7 +2408,7 @@ function Diagram({
|
|
|
2413
2408
|
}
|
|
2414
2409
|
)
|
|
2415
2410
|
] }),
|
|
2416
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { className: "flex-1 overflow-auto whitespace-pre px-3 py-2 font-mono text-[10px] leading-relaxed text-zinc-400 select-all", children: formatModelTree(
|
|
2411
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { className: "flex-1 overflow-auto whitespace-pre px-3 py-2 font-mono text-[10px] leading-relaxed text-zinc-400 select-all", children: formatModelTree(view_model) })
|
|
2417
2412
|
] }),
|
|
2418
2413
|
showWarnings && warnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex max-h-[30%] flex-col border-b border-zinc-800 bg-zinc-950", children: [
|
|
2419
2414
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center justify-between border-b border-zinc-800 bg-zinc-900 px-3 py-1", children: [
|
|
@@ -2937,7 +2932,7 @@ function useExtractModel(files) {
|
|
|
2937
2932
|
return;
|
|
2938
2933
|
}
|
|
2939
2934
|
const timer = setTimeout(() => {
|
|
2940
|
-
const { model, error } =
|
|
2935
|
+
const { model, error } = extract_model(files);
|
|
2941
2936
|
const warnings = validate(model);
|
|
2942
2937
|
const hasErrors = !!error || model.slices.some((s) => !!s.error);
|
|
2943
2938
|
if (!hasErrors) {
|
|
@@ -2998,7 +2993,7 @@ function ActDiagram({
|
|
|
2998
2993
|
const handleClick = (0, import_react3.useCallback)(
|
|
2999
2994
|
(name, type, file) => {
|
|
3000
2995
|
if (!onNavigate) return;
|
|
3001
|
-
const result =
|
|
2996
|
+
const result = navigate_to_code(files, name, type, file);
|
|
3002
2997
|
if (result) onNavigate(result.file, result.line, result.col, type);
|
|
3003
2998
|
},
|
|
3004
2999
|
[files, onNavigate]
|
|
@@ -3185,57 +3180,6 @@ function Tooltip({
|
|
|
3185
3180
|
);
|
|
3186
3181
|
}
|
|
3187
3182
|
|
|
3188
|
-
// src/client/lib/strip-fences.ts
|
|
3189
|
-
function parseMultiFileResponse(raw) {
|
|
3190
|
-
const files = [];
|
|
3191
|
-
const re = /```(?:typescript|ts):([^\n]+)\n([\s\S]*?)```/g;
|
|
3192
|
-
let m;
|
|
3193
|
-
while ((m = re.exec(raw)) !== null) {
|
|
3194
|
-
const path = m[1].trim();
|
|
3195
|
-
const content = m[2].trim();
|
|
3196
|
-
if (path && content) {
|
|
3197
|
-
files.push({ path, content });
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
if (files.length === 0) {
|
|
3201
|
-
const code = stripFences(raw);
|
|
3202
|
-
if (code.trim()) {
|
|
3203
|
-
files.push({ path: "src/app.ts", content: code });
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
return files;
|
|
3207
|
-
}
|
|
3208
|
-
function stripFences(code) {
|
|
3209
|
-
let result = code.replace(/```(?:typescript|ts)?\s*\n/g, "");
|
|
3210
|
-
result = result.replace(/\n?```\s*$/g, "");
|
|
3211
|
-
result = result.replace(
|
|
3212
|
-
/^[\s\S]*?(?=\/\*\*|\/\/|import\b|export\b|const\b|let\b|var\b|type\b|interface\b|function\b)/,
|
|
3213
|
-
""
|
|
3214
|
-
);
|
|
3215
|
-
const lines = result.split("\n");
|
|
3216
|
-
let lastCodeLine = lines.length - 1;
|
|
3217
|
-
while (lastCodeLine > 0) {
|
|
3218
|
-
const trimmed = lines[lastCodeLine].trim();
|
|
3219
|
-
if (trimmed && /[;{})\]:]$|^\s*\/\/|^\s*\*\/|^\s*\*|^$/.test(trimmed))
|
|
3220
|
-
break;
|
|
3221
|
-
lastCodeLine--;
|
|
3222
|
-
}
|
|
3223
|
-
if (lastCodeLine < lines.length - 1) {
|
|
3224
|
-
result = lines.slice(0, lastCodeLine + 1).join("\n");
|
|
3225
|
-
}
|
|
3226
|
-
return result.trim();
|
|
3227
|
-
}
|
|
3228
|
-
function deriveProjectName(prompt, code) {
|
|
3229
|
-
if (code) {
|
|
3230
|
-
const actMatch = code.match(/(?:const|let|var)\s+(\w+)\s*=\s*act\s*\(/);
|
|
3231
|
-
if (actMatch) return actMatch[1];
|
|
3232
|
-
const stateMatch = code.match(/state\(\s*\{\s*(\w+)/);
|
|
3233
|
-
if (stateMatch) return stateMatch[1] + " App";
|
|
3234
|
-
}
|
|
3235
|
-
const words = prompt.replace(/[^\w\s]/g, "").split(/\s+/).filter((w) => w.length > 2).slice(0, 3);
|
|
3236
|
-
return words.length > 0 ? words.map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(" ") : "Generated App";
|
|
3237
|
-
}
|
|
3238
|
-
|
|
3239
3183
|
// src/client/types/domain-model.ts
|
|
3240
3184
|
function emptyModel2() {
|
|
3241
3185
|
return {
|
|
@@ -3254,15 +3198,7 @@ function emptyModel2() {
|
|
|
3254
3198
|
Diagram,
|
|
3255
3199
|
Logo,
|
|
3256
3200
|
Tooltip,
|
|
3257
|
-
buildModel,
|
|
3258
|
-
computeLayout,
|
|
3259
|
-
deriveProjectName,
|
|
3260
3201
|
emptyModel,
|
|
3261
|
-
extractModel,
|
|
3262
|
-
navigateToCode,
|
|
3263
|
-
parseMultiFileResponse,
|
|
3264
|
-
stripFences,
|
|
3265
|
-
topoSort,
|
|
3266
3202
|
validate
|
|
3267
3203
|
});
|
|
3268
3204
|
//# sourceMappingURL=index.cjs.map
|