@rotorsoft/act-diagram 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/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 +12 -12
package/dist/index.js
CHANGED
|
@@ -5,13 +5,13 @@ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2
|
|
|
5
5
|
import { transform } from "sucrase";
|
|
6
6
|
|
|
7
7
|
// src/client/lib/schema-extract.ts
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
function
|
|
8
|
+
var is_w_s = (c) => c === " " || c === " " || c === "\n" || c === "\r";
|
|
9
|
+
var is_ident = (c) => !!c && /[\w$]/.test(c);
|
|
10
|
+
function skip_trivia(src, from) {
|
|
11
11
|
let i = from;
|
|
12
12
|
while (i < src.length) {
|
|
13
13
|
const c = src[i];
|
|
14
|
-
if (
|
|
14
|
+
if (is_w_s(c)) {
|
|
15
15
|
i++;
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
@@ -29,7 +29,7 @@ function skipTrivia(src, from) {
|
|
|
29
29
|
}
|
|
30
30
|
return i;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function read_value(src, start) {
|
|
33
33
|
let i = start;
|
|
34
34
|
let depth = 0;
|
|
35
35
|
while (i < src.length) {
|
|
@@ -101,19 +101,19 @@ function readValue(src, start) {
|
|
|
101
101
|
}
|
|
102
102
|
return i;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function parse_object_literal(src, start_brace) {
|
|
105
105
|
const entries = [];
|
|
106
|
-
let i =
|
|
106
|
+
let i = start_brace + 1;
|
|
107
107
|
while (i < src.length) {
|
|
108
|
-
i =
|
|
109
|
-
if (src[i] === "}") return { entries,
|
|
108
|
+
i = skip_trivia(src, i);
|
|
109
|
+
if (src[i] === "}") return { entries, end_brace: i };
|
|
110
110
|
let key = "";
|
|
111
|
-
let
|
|
112
|
-
let
|
|
113
|
-
let
|
|
111
|
+
let key_start = i;
|
|
112
|
+
let key_end = i;
|
|
113
|
+
let key_was_identifier = false;
|
|
114
114
|
if (src[i] === '"' || src[i] === "'") {
|
|
115
115
|
const q = src[i];
|
|
116
|
-
|
|
116
|
+
key_start = ++i;
|
|
117
117
|
while (i < src.length && src[i] !== q) {
|
|
118
118
|
if (src[i] === "\\") {
|
|
119
119
|
i += 2;
|
|
@@ -121,38 +121,38 @@ function parseObjectLiteral(src, startBrace) {
|
|
|
121
121
|
}
|
|
122
122
|
i++;
|
|
123
123
|
}
|
|
124
|
-
key = src.slice(
|
|
125
|
-
|
|
124
|
+
key = src.slice(key_start, i);
|
|
125
|
+
key_end = i;
|
|
126
126
|
i++;
|
|
127
|
-
} else if (
|
|
128
|
-
|
|
129
|
-
while (
|
|
130
|
-
key = src.slice(
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
} else if (is_ident(src[i])) {
|
|
128
|
+
key_start = i;
|
|
129
|
+
while (is_ident(src[i])) i++;
|
|
130
|
+
key = src.slice(key_start, i);
|
|
131
|
+
key_end = i;
|
|
132
|
+
key_was_identifier = true;
|
|
133
133
|
} else {
|
|
134
134
|
return null;
|
|
135
135
|
}
|
|
136
|
-
i =
|
|
136
|
+
i = skip_trivia(src, i);
|
|
137
137
|
if (src[i] !== ":") {
|
|
138
|
-
if (
|
|
139
|
-
entries.push({ key,
|
|
138
|
+
if (key_was_identifier) {
|
|
139
|
+
entries.push({ key, value_start: key_start, value_end: key_end });
|
|
140
140
|
}
|
|
141
141
|
while (i < src.length && src[i] !== "," && src[i] !== "}") i++;
|
|
142
142
|
if (src[i] === ",") i++;
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
i++;
|
|
146
|
-
i =
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
entries.push({ key,
|
|
150
|
-
i =
|
|
146
|
+
i = skip_trivia(src, i);
|
|
147
|
+
const value_start = i;
|
|
148
|
+
const value_end = read_value(src, i);
|
|
149
|
+
entries.push({ key, value_start, value_end });
|
|
150
|
+
i = value_end;
|
|
151
151
|
if (src[i] === ",") i++;
|
|
152
152
|
}
|
|
153
153
|
return null;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function read_top_level_expression(src, start) {
|
|
156
156
|
let i = start;
|
|
157
157
|
let depth = 0;
|
|
158
158
|
while (i < src.length) {
|
|
@@ -218,7 +218,7 @@ function readTopLevelExpression(src, start) {
|
|
|
218
218
|
}
|
|
219
219
|
return i;
|
|
220
220
|
}
|
|
221
|
-
function
|
|
221
|
+
function extract_identifier_assignments(src) {
|
|
222
222
|
const out = /* @__PURE__ */ new Map();
|
|
223
223
|
const re = /(?:^|[^\w$])(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n;]{1,256})?=\s*/gm;
|
|
224
224
|
let m;
|
|
@@ -228,14 +228,14 @@ function extractIdentifierAssignments(src) {
|
|
|
228
228
|
continue;
|
|
229
229
|
}
|
|
230
230
|
const start = m.index + m[0].length;
|
|
231
|
-
const end =
|
|
231
|
+
const end = read_top_level_expression(src, start);
|
|
232
232
|
const text = src.slice(start, end).trim();
|
|
233
233
|
if (text) out.set(ident, text);
|
|
234
234
|
re.lastIndex = end;
|
|
235
235
|
}
|
|
236
236
|
return out;
|
|
237
237
|
}
|
|
238
|
-
function
|
|
238
|
+
function find_identifier_object_literal(src, ident) {
|
|
239
239
|
const re = new RegExp(
|
|
240
240
|
`(?:^|[^\\w$])(?:const|let|var)\\s+${ident}\\b\\s*(?::[^=\\n;]+)?=\\s*`,
|
|
241
241
|
"m"
|
|
@@ -243,112 +243,112 @@ function findIdentifierObjectLiteral(src, ident) {
|
|
|
243
243
|
const m = re.exec(src);
|
|
244
244
|
if (!m) return -1;
|
|
245
245
|
const after = m.index + m[0].length;
|
|
246
|
-
const skipped =
|
|
246
|
+
const skipped = skip_trivia(src, after);
|
|
247
247
|
return src[skipped] === "{" ? skipped : -1;
|
|
248
248
|
}
|
|
249
249
|
var BARE_IDENT_RE = /^[A-Za-z_$][\w$]*$/;
|
|
250
|
-
function
|
|
250
|
+
function extract_schemas_from_source(src, event_names, external) {
|
|
251
251
|
const out = /* @__PURE__ */ new Map();
|
|
252
|
-
if (!src ||
|
|
253
|
-
const
|
|
254
|
-
const deref = (text) => BARE_IDENT_RE.test(text) ?
|
|
255
|
-
const
|
|
252
|
+
if (!src || event_names.size === 0) return out;
|
|
253
|
+
const local_idents = extract_identifier_assignments(src);
|
|
254
|
+
const deref = (text) => BARE_IDENT_RE.test(text) ? local_idents.get(text) ?? external?.get(text) ?? text : text;
|
|
255
|
+
const emits_re = /\.emits\s*\(/g;
|
|
256
256
|
let m;
|
|
257
|
-
while ((m =
|
|
258
|
-
let i =
|
|
259
|
-
if (
|
|
257
|
+
while ((m = emits_re.exec(src)) !== null) {
|
|
258
|
+
let i = skip_trivia(src, emits_re.lastIndex);
|
|
259
|
+
if (is_ident(src[i])) {
|
|
260
260
|
const start = i;
|
|
261
|
-
while (
|
|
261
|
+
while (is_ident(src[i])) i++;
|
|
262
262
|
const ident = src.slice(start, i);
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
i =
|
|
263
|
+
const obj_start = find_identifier_object_literal(src, ident);
|
|
264
|
+
if (obj_start < 0) continue;
|
|
265
|
+
i = obj_start;
|
|
266
266
|
}
|
|
267
267
|
if (src[i] !== "{") continue;
|
|
268
|
-
const parsed =
|
|
268
|
+
const parsed = parse_object_literal(src, i);
|
|
269
269
|
if (!parsed) continue;
|
|
270
270
|
for (const e of parsed.entries) {
|
|
271
|
-
if (!
|
|
272
|
-
const raw = src.slice(e.
|
|
271
|
+
if (!event_names.has(e.key)) continue;
|
|
272
|
+
const raw = src.slice(e.value_start, e.value_end).trim();
|
|
273
273
|
const text = deref(raw);
|
|
274
274
|
if (text) out.set(e.key, text);
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
emits_re.lastIndex = Math.max(emits_re.lastIndex, parsed.end_brace + 1);
|
|
277
277
|
}
|
|
278
278
|
return out;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// src/client/lib/build-model.ts
|
|
282
282
|
var _stateIdx = 0;
|
|
283
|
-
function
|
|
283
|
+
function build_state(model, st) {
|
|
284
284
|
const events = st.events ?? {};
|
|
285
285
|
for (const [name, schema] of Object.entries(events)) {
|
|
286
286
|
if (schema === void 0)
|
|
287
287
|
return { error: `Event "${name}" has undefined schema` };
|
|
288
288
|
}
|
|
289
|
-
const
|
|
290
|
-
for (const [name, schema] of Object.entries(
|
|
289
|
+
const raw_actions = st.actions ?? {};
|
|
290
|
+
for (const [name, schema] of Object.entries(raw_actions)) {
|
|
291
291
|
if (name.startsWith("__emits_")) continue;
|
|
292
292
|
if (schema === void 0)
|
|
293
293
|
return { error: `Action "${name}" has undefined schema` };
|
|
294
294
|
}
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
for (const
|
|
299
|
-
|
|
300
|
-
name:
|
|
301
|
-
hasCustomPatch: st.patches?.has(
|
|
295
|
+
const domain_name = st.name;
|
|
296
|
+
const unique_key = `${domain_name}:${_stateIdx++}`;
|
|
297
|
+
const event_nodes = [];
|
|
298
|
+
for (const event_name of Object.keys(events)) {
|
|
299
|
+
event_nodes.push({
|
|
300
|
+
name: event_name,
|
|
301
|
+
hasCustomPatch: st.patches?.has(event_name) ?? false,
|
|
302
302
|
// Stash the runtime Zod schema so the JSON Schema exporter can
|
|
303
303
|
// call `z.toJSONSchema(zod)` later without re-running the parser.
|
|
304
|
-
zod: events[
|
|
304
|
+
zod: events[event_name]
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
const
|
|
308
|
-
for (const
|
|
309
|
-
if (
|
|
310
|
-
const emits =
|
|
311
|
-
const invariants = (st.given?.[
|
|
307
|
+
const action_nodes = [];
|
|
308
|
+
for (const action_name of Object.keys(raw_actions)) {
|
|
309
|
+
if (action_name.startsWith("__emits_")) continue;
|
|
310
|
+
const emits = raw_actions[`__emits_${action_name}`] ?? [];
|
|
311
|
+
const invariants = (st.given?.[action_name] ?? []).map(
|
|
312
312
|
(inv) => inv.description ?? ""
|
|
313
313
|
);
|
|
314
|
-
|
|
314
|
+
action_nodes.push({ name: action_name, emits, invariants });
|
|
315
315
|
}
|
|
316
316
|
const node = {
|
|
317
|
-
name:
|
|
318
|
-
varName:
|
|
319
|
-
events:
|
|
320
|
-
actions:
|
|
317
|
+
name: domain_name,
|
|
318
|
+
varName: unique_key,
|
|
319
|
+
events: event_nodes,
|
|
320
|
+
actions: action_nodes,
|
|
321
321
|
file: st._sourceFile
|
|
322
322
|
};
|
|
323
323
|
model.states.push(node);
|
|
324
|
-
st._modelKey =
|
|
325
|
-
return { key:
|
|
324
|
+
st._modelKey = unique_key;
|
|
325
|
+
return { key: unique_key, node };
|
|
326
326
|
}
|
|
327
|
-
function
|
|
327
|
+
function fixup_reactions(reactions, files, source_file) {
|
|
328
328
|
const fallbacks = reactions.filter((r) => r.handlerName.startsWith("on "));
|
|
329
329
|
if (fallbacks.length === 0) return;
|
|
330
|
-
const src =
|
|
330
|
+
const src = source_file ? files.find((f) => f.path === source_file)?.content : files.map((f) => f.content).join("\n");
|
|
331
331
|
if (!src) return;
|
|
332
|
-
const
|
|
332
|
+
const do_re = /\.on\(\s*["'`](\w+)["'`]\s*\)\s*\.do\(\s*(?:async\s+)?(?:function\s+(\w+)|(?:\w+\.)?(\w+))?/g;
|
|
333
333
|
let dm;
|
|
334
|
-
while ((dm =
|
|
335
|
-
const
|
|
334
|
+
while ((dm = do_re.exec(src)) !== null) {
|
|
335
|
+
const event_name = dm[1];
|
|
336
336
|
const handlerName = dm[2] || dm[3];
|
|
337
337
|
if (!handlerName) continue;
|
|
338
338
|
const r = fallbacks.find(
|
|
339
|
-
(r2) => r2.event ===
|
|
339
|
+
(r2) => r2.event === event_name && r2.handlerName === `on ${event_name}`
|
|
340
340
|
);
|
|
341
341
|
if (r) r.handlerName = handlerName;
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
-
function
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
const
|
|
344
|
+
function build_model(result, files, expected_slices) {
|
|
345
|
+
const raw_states = result.states.filter((s) => s && s._tag === "State");
|
|
346
|
+
const raw_slices = result.slices.filter((s) => s && s._tag === "Slice");
|
|
347
|
+
const raw_projections = result.projections.filter(
|
|
348
348
|
(p) => p && p._tag === "Projection"
|
|
349
349
|
);
|
|
350
|
-
const
|
|
351
|
-
const
|
|
350
|
+
const raw_acts = result.acts.filter((a) => a && a._tag === "Act");
|
|
351
|
+
const state_by_ref = /* @__PURE__ */ new Map();
|
|
352
352
|
const model = {
|
|
353
353
|
entries: [],
|
|
354
354
|
states: [],
|
|
@@ -356,89 +356,89 @@ function buildModel(result, files, expectedSlices) {
|
|
|
356
356
|
projections: [],
|
|
357
357
|
reactions: []
|
|
358
358
|
};
|
|
359
|
-
for (const st of
|
|
360
|
-
if (
|
|
359
|
+
for (const st of raw_states) {
|
|
360
|
+
if (state_by_ref.has(st)) continue;
|
|
361
361
|
try {
|
|
362
|
-
|
|
362
|
+
state_by_ref.set(st, build_state(model, st));
|
|
363
363
|
} catch (e) {
|
|
364
|
-
|
|
364
|
+
state_by_ref.set(st, {
|
|
365
365
|
error: e instanceof Error ? e.message : String(e)
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
-
for (const a of
|
|
369
|
+
for (const a of raw_acts) {
|
|
370
370
|
for (const st of a.states ?? []) {
|
|
371
|
-
if (!st || st._tag !== "State" ||
|
|
371
|
+
if (!st || st._tag !== "State" || state_by_ref.has(st)) continue;
|
|
372
372
|
try {
|
|
373
|
-
|
|
373
|
+
state_by_ref.set(st, build_state(model, st));
|
|
374
374
|
} catch (e) {
|
|
375
|
-
|
|
375
|
+
state_by_ref.set(st, {
|
|
376
376
|
error: e instanceof Error ? e.message : String(e)
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
const
|
|
382
|
-
for (const s of
|
|
383
|
-
const
|
|
384
|
-
|
|
381
|
+
const built_slice_names = /* @__PURE__ */ new Set();
|
|
382
|
+
for (const s of raw_slices) {
|
|
383
|
+
const slice_name = s._varName ?? "slice";
|
|
384
|
+
built_slice_names.add(slice_name);
|
|
385
385
|
try {
|
|
386
386
|
try {
|
|
387
|
-
|
|
387
|
+
fixup_reactions(s.reactions, files);
|
|
388
388
|
} catch {
|
|
389
389
|
}
|
|
390
|
-
const
|
|
390
|
+
const slice_state_keys = [];
|
|
391
391
|
const errors = [];
|
|
392
392
|
for (const st of s.states ?? []) {
|
|
393
393
|
if (!st || typeof st !== "object") {
|
|
394
|
-
const fileErr = [...result.
|
|
394
|
+
const fileErr = [...result.file_errors.values()][0];
|
|
395
395
|
errors.push(fileErr ?? "Missing state (broken import)");
|
|
396
396
|
continue;
|
|
397
397
|
}
|
|
398
|
-
const built =
|
|
398
|
+
const built = state_by_ref.get(st);
|
|
399
399
|
if (built) {
|
|
400
400
|
if ("error" in built) {
|
|
401
401
|
errors.push(built.error);
|
|
402
402
|
} else {
|
|
403
|
-
|
|
403
|
+
slice_state_keys.push(built.key);
|
|
404
404
|
}
|
|
405
405
|
} else {
|
|
406
406
|
try {
|
|
407
|
-
const result2 =
|
|
408
|
-
|
|
407
|
+
const result2 = build_state(model, st);
|
|
408
|
+
state_by_ref.set(st, result2);
|
|
409
409
|
if ("error" in result2) {
|
|
410
410
|
errors.push(result2.error);
|
|
411
411
|
} else {
|
|
412
|
-
|
|
412
|
+
slice_state_keys.push(result2.key);
|
|
413
413
|
}
|
|
414
414
|
} catch (e) {
|
|
415
415
|
const msg = e instanceof Error ? e.message : String(e);
|
|
416
|
-
|
|
416
|
+
state_by_ref.set(st, { error: msg });
|
|
417
417
|
errors.push(msg);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
|
-
const
|
|
421
|
+
const proj_names = [];
|
|
422
422
|
for (const p of s.projections ?? []) {
|
|
423
|
-
if (p && p._tag === "Projection")
|
|
423
|
+
if (p && p._tag === "Projection") proj_names.push(p.target);
|
|
424
424
|
}
|
|
425
|
-
const
|
|
425
|
+
const slice_file = s._sourceFile;
|
|
426
426
|
model.slices.push({
|
|
427
|
-
name:
|
|
428
|
-
states:
|
|
429
|
-
stateVars:
|
|
430
|
-
projections:
|
|
427
|
+
name: slice_name,
|
|
428
|
+
states: slice_state_keys,
|
|
429
|
+
stateVars: slice_state_keys,
|
|
430
|
+
projections: proj_names,
|
|
431
431
|
reactions: (s.reactions ?? []).map((r) => ({
|
|
432
432
|
...r,
|
|
433
|
-
file: r.file ??
|
|
433
|
+
file: r.file ?? slice_file
|
|
434
434
|
})),
|
|
435
|
-
file:
|
|
435
|
+
file: slice_file,
|
|
436
436
|
error: errors.length > 0 ? errors.join("; ") : void 0
|
|
437
437
|
});
|
|
438
438
|
} catch (e) {
|
|
439
439
|
const msg = e instanceof Error ? e.message : String(e);
|
|
440
440
|
model.slices.push({
|
|
441
|
-
name:
|
|
441
|
+
name: slice_name,
|
|
442
442
|
states: [],
|
|
443
443
|
stateVars: [],
|
|
444
444
|
projections: [],
|
|
@@ -448,38 +448,38 @@ function buildModel(result, files, expectedSlices) {
|
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
for (const [name,
|
|
452
|
-
if (!
|
|
451
|
+
for (const [name, file_path] of expected_slices) {
|
|
452
|
+
if (!built_slice_names.has(name)) {
|
|
453
453
|
model.slices.push({
|
|
454
454
|
name,
|
|
455
455
|
states: [],
|
|
456
456
|
stateVars: [],
|
|
457
457
|
projections: [],
|
|
458
458
|
reactions: [],
|
|
459
|
-
error: result.
|
|
460
|
-
file:
|
|
459
|
+
error: result.file_errors.get(file_path) ?? result.error ?? "Failed to build slice",
|
|
460
|
+
file: file_path
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
const
|
|
465
|
-
const
|
|
464
|
+
const source_by_path = /* @__PURE__ */ new Map();
|
|
465
|
+
const external_idents = /* @__PURE__ */ new Map();
|
|
466
466
|
for (const f of files) {
|
|
467
|
-
|
|
468
|
-
for (const [ident, expr] of
|
|
469
|
-
if (!
|
|
467
|
+
source_by_path.set(f.path, f.content);
|
|
468
|
+
for (const [ident, expr] of extract_identifier_assignments(f.content)) {
|
|
469
|
+
if (!external_idents.has(ident)) external_idents.set(ident, expr);
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
for (const
|
|
473
|
-
if (!
|
|
474
|
-
const src =
|
|
475
|
-
const names = new Set(
|
|
472
|
+
for (const st_node of model.states) {
|
|
473
|
+
if (!st_node.file) continue;
|
|
474
|
+
const src = source_by_path.get(st_node.file);
|
|
475
|
+
const names = new Set(st_node.events.map((e) => e.name));
|
|
476
476
|
if (names.size === 0) continue;
|
|
477
|
-
const schemas =
|
|
478
|
-
for (const ev of
|
|
477
|
+
const schemas = extract_schemas_from_source(src, names, external_idents);
|
|
478
|
+
for (const ev of st_node.events) {
|
|
479
479
|
ev.schema = schemas.get(ev.name);
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
|
-
for (const p of
|
|
482
|
+
for (const p of raw_projections) {
|
|
483
483
|
model.projections.push({
|
|
484
484
|
name: p.target,
|
|
485
485
|
varName: p.target,
|
|
@@ -487,11 +487,11 @@ function buildModel(result, files, expectedSlices) {
|
|
|
487
487
|
file: p._sourceFile
|
|
488
488
|
});
|
|
489
489
|
}
|
|
490
|
-
const
|
|
491
|
-
const
|
|
492
|
-
for (const a of
|
|
490
|
+
const states_in_slices = new Set(model.slices.flatMap((s) => s.states));
|
|
491
|
+
const global_state_keys = model.states.filter((s) => !states_in_slices.has(s.varName)).map((s) => s.varName);
|
|
492
|
+
for (const a of raw_acts) {
|
|
493
493
|
try {
|
|
494
|
-
|
|
494
|
+
fixup_reactions(
|
|
495
495
|
a.reactions ?? [],
|
|
496
496
|
files,
|
|
497
497
|
a._sourceFile
|
|
@@ -503,53 +503,55 @@ function buildModel(result, files, expectedSlices) {
|
|
|
503
503
|
projections: model.projections.map((p) => p.name),
|
|
504
504
|
states: model.states.map((s) => s.name)
|
|
505
505
|
};
|
|
506
|
-
const
|
|
506
|
+
const act_file = a._sourceFile;
|
|
507
507
|
for (const r of a.reactions ?? []) {
|
|
508
|
-
model.reactions.push({ ...r, file: r.file ??
|
|
508
|
+
model.reactions.push({ ...r, file: r.file ?? act_file });
|
|
509
509
|
}
|
|
510
|
-
const
|
|
511
|
-
const
|
|
510
|
+
const entry_path = a._sourceFile ?? "app.ts";
|
|
511
|
+
const act_slice_names = new Set(
|
|
512
512
|
(a.slices ?? []).filter((s) => s != null).map((s) => s._varName ?? "").filter(Boolean)
|
|
513
513
|
);
|
|
514
514
|
for (const sl of model.slices) {
|
|
515
|
-
if (sl.error && !
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
|
|
515
|
+
if (sl.error && !act_slice_names.has(sl.name)) {
|
|
516
|
+
const act_src = files.find((f) => f.path === entry_path)?.content ?? "";
|
|
517
|
+
if (act_src.includes(sl.name)) {
|
|
518
|
+
act_slice_names.add(sl.name);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
const entry_slices = model.slices.filter(
|
|
523
|
+
(s) => act_slice_names.has(s.name)
|
|
524
|
+
);
|
|
525
|
+
const slice_state_keys = new Set(entry_slices.flatMap((s) => s.states));
|
|
526
|
+
const act_state_keys = /* @__PURE__ */ new Set();
|
|
525
527
|
for (const s of a.states ?? []) {
|
|
526
528
|
try {
|
|
527
529
|
if (s && s._tag === "State") {
|
|
528
|
-
|
|
530
|
+
act_state_keys.add(s._modelKey ?? s.name);
|
|
529
531
|
}
|
|
530
532
|
} catch {
|
|
531
533
|
}
|
|
532
534
|
}
|
|
533
|
-
const
|
|
534
|
-
const
|
|
535
|
+
const all_state_keys = /* @__PURE__ */ new Set([...act_state_keys, ...slice_state_keys]);
|
|
536
|
+
const act_proj_names = new Set(
|
|
535
537
|
(a.projections ?? []).filter((p) => p && p._tag === "Projection").map((p) => p.target)
|
|
536
538
|
);
|
|
537
|
-
for (const sl of
|
|
538
|
-
for (const pn of sl.projections)
|
|
539
|
+
for (const sl of entry_slices) {
|
|
540
|
+
for (const pn of sl.projections) act_proj_names.add(pn);
|
|
539
541
|
}
|
|
540
542
|
model.entries.push({
|
|
541
|
-
path:
|
|
542
|
-
states: model.states.filter((s) =>
|
|
543
|
-
slices:
|
|
544
|
-
projections: model.projections.filter((p) =>
|
|
543
|
+
path: entry_path,
|
|
544
|
+
states: model.states.filter((s) => all_state_keys.has(s.varName)),
|
|
545
|
+
slices: entry_slices,
|
|
546
|
+
projections: model.projections.filter((p) => act_proj_names.has(p.name)),
|
|
545
547
|
reactions: a.reactions ?? []
|
|
546
548
|
});
|
|
547
549
|
}
|
|
548
|
-
if (
|
|
550
|
+
if (global_state_keys.length > 0 || model.reactions.length > 0) {
|
|
549
551
|
model.slices.push({
|
|
550
552
|
name: "global",
|
|
551
|
-
states:
|
|
552
|
-
stateVars:
|
|
553
|
+
states: global_state_keys,
|
|
554
|
+
stateVars: global_state_keys,
|
|
553
555
|
projections: model.projections.map((p) => p.name),
|
|
554
556
|
reactions: model.reactions
|
|
555
557
|
});
|
|
@@ -571,42 +573,42 @@ function buildModel(result, files, expectedSlices) {
|
|
|
571
573
|
|
|
572
574
|
// src/client/lib/mock-builders.ts
|
|
573
575
|
import { z } from "zod";
|
|
574
|
-
function
|
|
576
|
+
function proxy_target() {
|
|
575
577
|
}
|
|
576
|
-
function
|
|
578
|
+
function attach_emit(info, action_name, handler) {
|
|
577
579
|
const emits = [];
|
|
578
580
|
if (typeof handler === "string") {
|
|
579
581
|
emits.push(handler);
|
|
580
582
|
} else if (typeof handler === "function") {
|
|
581
583
|
const src = String(handler);
|
|
582
|
-
for (const
|
|
583
|
-
if (src.includes(`"${
|
|
584
|
-
emits.push(
|
|
584
|
+
for (const event_name of Object.keys(info.events)) {
|
|
585
|
+
if (src.includes(`"${event_name}"`) || src.includes(`'${event_name}'`) || src.includes(`\`${event_name}\``)) {
|
|
586
|
+
emits.push(event_name);
|
|
585
587
|
}
|
|
586
588
|
}
|
|
587
589
|
if (emits.length === 0) {
|
|
588
590
|
try {
|
|
589
|
-
const
|
|
591
|
+
const deep_proxy = new Proxy(
|
|
590
592
|
{},
|
|
591
593
|
{
|
|
592
|
-
get: () =>
|
|
594
|
+
get: () => deep_proxy,
|
|
593
595
|
has: () => true
|
|
594
596
|
}
|
|
595
597
|
);
|
|
596
|
-
const
|
|
597
|
-
get: () =>
|
|
598
|
-
apply: () =>
|
|
598
|
+
const proxy_fn = new Proxy(proxy_target, {
|
|
599
|
+
get: () => deep_proxy,
|
|
600
|
+
apply: () => deep_proxy
|
|
599
601
|
});
|
|
600
|
-
const
|
|
602
|
+
const dummy_arg = new Proxy(
|
|
601
603
|
{},
|
|
602
604
|
{
|
|
603
605
|
get: (_t, prop) => {
|
|
604
|
-
if (typeof prop === "string") return
|
|
606
|
+
if (typeof prop === "string") return proxy_fn;
|
|
605
607
|
return void 0;
|
|
606
608
|
}
|
|
607
609
|
}
|
|
608
610
|
);
|
|
609
|
-
const result = handler(
|
|
611
|
+
const result = handler(dummy_arg, dummy_arg, dummy_arg);
|
|
610
612
|
if (Array.isArray(result) && typeof result[0] === "string") {
|
|
611
613
|
emits.push(result[0]);
|
|
612
614
|
}
|
|
@@ -614,9 +616,9 @@ function attachEmit(info, actionName, handler) {
|
|
|
614
616
|
}
|
|
615
617
|
}
|
|
616
618
|
}
|
|
617
|
-
info.actions[`__emits_${
|
|
619
|
+
info.actions[`__emits_${action_name}`] = emits;
|
|
618
620
|
}
|
|
619
|
-
function
|
|
621
|
+
function mock_state(entry, on_build) {
|
|
620
622
|
const name = Object.keys(entry)[0];
|
|
621
623
|
const info = {
|
|
622
624
|
name,
|
|
@@ -626,29 +628,29 @@ function mockState(entry, onBuild) {
|
|
|
626
628
|
patches: /* @__PURE__ */ new Set(),
|
|
627
629
|
_tag: "State"
|
|
628
630
|
};
|
|
629
|
-
const
|
|
630
|
-
on(
|
|
631
|
-
const
|
|
632
|
-
info.actions[
|
|
631
|
+
const action_builder = (_currentAction) => ({
|
|
632
|
+
on(action_entry) {
|
|
633
|
+
const action_name = Object.keys(action_entry)[0];
|
|
634
|
+
info.actions[action_name] = action_entry[action_name];
|
|
633
635
|
return {
|
|
634
636
|
given(rules) {
|
|
635
|
-
if (rules) info.given[
|
|
637
|
+
if (rules) info.given[action_name] = rules;
|
|
636
638
|
return {
|
|
637
639
|
emit(handler) {
|
|
638
|
-
|
|
639
|
-
return
|
|
640
|
+
attach_emit(info, action_name, handler);
|
|
641
|
+
return action_builder(action_name);
|
|
640
642
|
}
|
|
641
643
|
};
|
|
642
644
|
},
|
|
643
645
|
emit(handler) {
|
|
644
|
-
|
|
645
|
-
return
|
|
646
|
+
attach_emit(info, action_name, handler);
|
|
647
|
+
return action_builder(action_name);
|
|
646
648
|
}
|
|
647
649
|
};
|
|
648
650
|
},
|
|
649
|
-
snap: () =>
|
|
651
|
+
snap: () => action_builder(_currentAction),
|
|
650
652
|
build: () => {
|
|
651
|
-
|
|
653
|
+
on_build?.(info);
|
|
652
654
|
return info;
|
|
653
655
|
}
|
|
654
656
|
});
|
|
@@ -658,36 +660,36 @@ function mockState(entry, onBuild) {
|
|
|
658
660
|
emits(events) {
|
|
659
661
|
info.events = events ?? {};
|
|
660
662
|
return {
|
|
661
|
-
...
|
|
663
|
+
...action_builder(),
|
|
662
664
|
patch(patches) {
|
|
663
665
|
if (patches)
|
|
664
666
|
for (const k of Object.keys(patches)) info.patches.add(k);
|
|
665
|
-
return
|
|
667
|
+
return action_builder();
|
|
666
668
|
}
|
|
667
669
|
};
|
|
668
670
|
}
|
|
669
671
|
})
|
|
670
672
|
};
|
|
671
673
|
}
|
|
672
|
-
function
|
|
674
|
+
function capture_dispatches(handler) {
|
|
673
675
|
const dispatches = [];
|
|
674
676
|
if (typeof handler !== "function") return dispatches;
|
|
675
677
|
try {
|
|
676
|
-
const
|
|
677
|
-
const
|
|
678
|
-
do: (
|
|
679
|
-
if (typeof
|
|
680
|
-
dispatches.push(
|
|
678
|
+
const safe_proxy = () => new Proxy({}, { get: () => "" });
|
|
679
|
+
const mock_app = {
|
|
680
|
+
do: (action_name) => {
|
|
681
|
+
if (typeof action_name === "string" && !dispatches.includes(action_name))
|
|
682
|
+
dispatches.push(action_name);
|
|
681
683
|
return Promise.resolve([]);
|
|
682
684
|
},
|
|
683
|
-
load: () => Promise.resolve({ state:
|
|
685
|
+
load: () => Promise.resolve({ state: safe_proxy(), version: 0 }),
|
|
684
686
|
query: () => Promise.resolve({ count: 0 }),
|
|
685
687
|
query_array: () => Promise.resolve([])
|
|
686
688
|
};
|
|
687
|
-
const
|
|
689
|
+
const mock_event = new Proxy({}, {
|
|
688
690
|
get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
|
|
689
691
|
});
|
|
690
|
-
const result = handler(
|
|
692
|
+
const result = handler(mock_event, "mock", mock_app);
|
|
691
693
|
if (result && typeof result.catch === "function") {
|
|
692
694
|
result.catch(() => {
|
|
693
695
|
});
|
|
@@ -704,7 +706,7 @@ function captureDispatches(handler) {
|
|
|
704
706
|
}
|
|
705
707
|
return dispatches;
|
|
706
708
|
}
|
|
707
|
-
function
|
|
709
|
+
function mock_slice(on_build) {
|
|
708
710
|
const info = {
|
|
709
711
|
_tag: "Slice",
|
|
710
712
|
states: [],
|
|
@@ -720,13 +722,13 @@ function mockSlice(onBuild) {
|
|
|
720
722
|
if (p) info.projections.push(p);
|
|
721
723
|
return builder;
|
|
722
724
|
},
|
|
723
|
-
on(
|
|
725
|
+
on(event_name) {
|
|
724
726
|
return {
|
|
725
727
|
do(handler) {
|
|
726
|
-
const dispatches =
|
|
728
|
+
const dispatches = capture_dispatches(handler);
|
|
727
729
|
const reaction = {
|
|
728
|
-
event:
|
|
729
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
730
|
+
event: event_name,
|
|
731
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
730
732
|
dispatches
|
|
731
733
|
};
|
|
732
734
|
info.reactions.push(reaction);
|
|
@@ -740,22 +742,22 @@ function mockSlice(onBuild) {
|
|
|
740
742
|
};
|
|
741
743
|
},
|
|
742
744
|
build: () => {
|
|
743
|
-
|
|
745
|
+
on_build?.(info);
|
|
744
746
|
return info;
|
|
745
747
|
}
|
|
746
748
|
};
|
|
747
749
|
return builder;
|
|
748
750
|
}
|
|
749
|
-
function
|
|
751
|
+
function mock_projection(target, on_build) {
|
|
750
752
|
const info = {
|
|
751
753
|
_tag: "Projection",
|
|
752
754
|
target: target || "projection",
|
|
753
755
|
handles: []
|
|
754
756
|
};
|
|
755
757
|
const builder = {
|
|
756
|
-
on(
|
|
757
|
-
const
|
|
758
|
-
info.handles.push(
|
|
758
|
+
on(event_entry) {
|
|
759
|
+
const event_name = Object.keys(event_entry)[0];
|
|
760
|
+
info.handles.push(event_name);
|
|
759
761
|
return {
|
|
760
762
|
do() {
|
|
761
763
|
return {
|
|
@@ -769,13 +771,13 @@ function mockProjection(target, onBuild) {
|
|
|
769
771
|
};
|
|
770
772
|
},
|
|
771
773
|
build: () => {
|
|
772
|
-
|
|
774
|
+
on_build?.(info);
|
|
773
775
|
return info;
|
|
774
776
|
}
|
|
775
777
|
};
|
|
776
778
|
return builder;
|
|
777
779
|
}
|
|
778
|
-
function
|
|
780
|
+
function mock_act(on_build) {
|
|
779
781
|
const info = {
|
|
780
782
|
_tag: "Act",
|
|
781
783
|
states: [],
|
|
@@ -797,13 +799,13 @@ function mockAct(onBuild) {
|
|
|
797
799
|
return builder;
|
|
798
800
|
},
|
|
799
801
|
withActor: () => builder,
|
|
800
|
-
on(
|
|
802
|
+
on(event_name) {
|
|
801
803
|
return {
|
|
802
804
|
do(handler) {
|
|
803
|
-
const dispatches =
|
|
805
|
+
const dispatches = capture_dispatches(handler);
|
|
804
806
|
const reaction = {
|
|
805
|
-
event:
|
|
806
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
807
|
+
event: event_name,
|
|
808
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
807
809
|
dispatches
|
|
808
810
|
};
|
|
809
811
|
info.reactions.push(reaction);
|
|
@@ -817,10 +819,10 @@ function mockAct(onBuild) {
|
|
|
817
819
|
};
|
|
818
820
|
},
|
|
819
821
|
build: () => {
|
|
820
|
-
const noop = () =>
|
|
821
|
-
const
|
|
822
|
+
const noop = () => act_stub;
|
|
823
|
+
const act_stub = {
|
|
822
824
|
...info,
|
|
823
|
-
on: () =>
|
|
825
|
+
on: () => act_stub,
|
|
824
826
|
do: () => Promise.resolve([]),
|
|
825
827
|
load: () => Promise.resolve({}),
|
|
826
828
|
drain: () => Promise.resolve(),
|
|
@@ -829,8 +831,8 @@ function mockAct(onBuild) {
|
|
|
829
831
|
start_correlations: noop,
|
|
830
832
|
query_array: () => Promise.resolve([])
|
|
831
833
|
};
|
|
832
|
-
|
|
833
|
-
return
|
|
834
|
+
on_build?.(act_stub);
|
|
835
|
+
return act_stub;
|
|
834
836
|
}
|
|
835
837
|
};
|
|
836
838
|
return builder;
|
|
@@ -841,13 +843,13 @@ var InvariantError = class extends Error {
|
|
|
841
843
|
this.name = "InvariantError";
|
|
842
844
|
}
|
|
843
845
|
};
|
|
844
|
-
var
|
|
846
|
+
var crypto_mock = { randomUUID: () => "mock-uuid" };
|
|
845
847
|
var MODULES = {
|
|
846
848
|
"@rotorsoft/act": {
|
|
847
|
-
state:
|
|
848
|
-
slice:
|
|
849
|
-
projection:
|
|
850
|
-
act:
|
|
849
|
+
state: mock_state,
|
|
850
|
+
slice: mock_slice,
|
|
851
|
+
projection: mock_projection,
|
|
852
|
+
act: mock_act,
|
|
851
853
|
store: () => ({
|
|
852
854
|
seed: () => Promise.resolve(),
|
|
853
855
|
drop: () => Promise.resolve(),
|
|
@@ -860,10 +862,10 @@ var MODULES = {
|
|
|
860
862
|
InvariantError
|
|
861
863
|
},
|
|
862
864
|
zod: { z, ...z },
|
|
863
|
-
crypto:
|
|
864
|
-
"node:crypto":
|
|
865
|
+
crypto: crypto_mock,
|
|
866
|
+
"node:crypto": crypto_mock
|
|
865
867
|
};
|
|
866
|
-
function
|
|
868
|
+
function unknown_module_proxy() {
|
|
867
869
|
const handler = {
|
|
868
870
|
get(_target, prop) {
|
|
869
871
|
if (prop === Symbol.toPrimitive) return () => "";
|
|
@@ -880,62 +882,62 @@ function unknownModuleProxy() {
|
|
|
880
882
|
return true;
|
|
881
883
|
}
|
|
882
884
|
};
|
|
883
|
-
const proxy = new Proxy(
|
|
885
|
+
const proxy = new Proxy(proxy_target, handler);
|
|
884
886
|
return proxy;
|
|
885
887
|
}
|
|
886
888
|
|
|
887
889
|
// src/client/lib/sort.ts
|
|
888
|
-
function
|
|
889
|
-
if (
|
|
890
|
+
function topo_sort(ts_files) {
|
|
891
|
+
if (ts_files.length <= 1) return ts_files;
|
|
890
892
|
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
891
|
-
const
|
|
892
|
-
for (const f of
|
|
893
|
-
|
|
893
|
+
const by_key = /* @__PURE__ */ new Map();
|
|
894
|
+
for (const f of ts_files) {
|
|
895
|
+
by_key.set(strip(f.path), f);
|
|
894
896
|
}
|
|
895
897
|
const deps = /* @__PURE__ */ new Map();
|
|
896
|
-
for (const f of
|
|
898
|
+
for (const f of ts_files) {
|
|
897
899
|
const key = strip(f.path);
|
|
898
|
-
const
|
|
899
|
-
deps.set(key,
|
|
900
|
-
const
|
|
900
|
+
const file_deps = /* @__PURE__ */ new Set();
|
|
901
|
+
deps.set(key, file_deps);
|
|
902
|
+
const from_re = /from\s+["']([^"']+)["']/g;
|
|
901
903
|
let m;
|
|
902
|
-
while ((m =
|
|
904
|
+
while ((m = from_re.exec(f.content)) !== null) {
|
|
903
905
|
const imp = m[1];
|
|
904
|
-
const resolved = resolve(imp, key,
|
|
905
|
-
if (resolved &&
|
|
906
|
+
const resolved = resolve(imp, key, by_key);
|
|
907
|
+
if (resolved && by_key.has(resolved)) file_deps.add(resolved);
|
|
906
908
|
}
|
|
907
909
|
}
|
|
908
|
-
const
|
|
909
|
-
for (const f of
|
|
910
|
-
for (const [,
|
|
911
|
-
for (const dep of
|
|
912
|
-
|
|
910
|
+
const in_degree = /* @__PURE__ */ new Map();
|
|
911
|
+
for (const f of ts_files) in_degree.set(strip(f.path), 0);
|
|
912
|
+
for (const [, file_deps] of deps) {
|
|
913
|
+
for (const dep of file_deps) {
|
|
914
|
+
in_degree.set(dep, in_degree.get(dep) + 1);
|
|
913
915
|
}
|
|
914
916
|
}
|
|
915
917
|
const queue = [];
|
|
916
|
-
for (const [key, _deg] of
|
|
918
|
+
for (const [key, _deg] of in_degree) {
|
|
917
919
|
if (deps.get(key)?.size === 0) queue.push(key);
|
|
918
920
|
}
|
|
919
921
|
const order = [];
|
|
920
922
|
while (queue.length > 0) {
|
|
921
923
|
const key = queue.shift();
|
|
922
924
|
order.push(key);
|
|
923
|
-
for (const [other,
|
|
924
|
-
if (
|
|
925
|
-
|
|
926
|
-
if (
|
|
925
|
+
for (const [other, file_deps] of deps) {
|
|
926
|
+
if (file_deps.has(key)) {
|
|
927
|
+
file_deps.delete(key);
|
|
928
|
+
if (file_deps.size === 0) queue.push(other);
|
|
927
929
|
}
|
|
928
930
|
}
|
|
929
931
|
}
|
|
930
|
-
for (const f of
|
|
932
|
+
for (const f of ts_files) {
|
|
931
933
|
const key = strip(f.path);
|
|
932
934
|
if (!order.includes(key)) order.push(key);
|
|
933
935
|
}
|
|
934
|
-
return order.map((k) =>
|
|
936
|
+
return order.map((k) => by_key.get(k)).filter(Boolean);
|
|
935
937
|
}
|
|
936
|
-
function resolve(imp,
|
|
938
|
+
function resolve(imp, from_path, by_key) {
|
|
937
939
|
if (imp.startsWith(".")) {
|
|
938
|
-
const dir =
|
|
940
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
939
941
|
const parts = (dir ? dir + "/" + imp : imp).split("/");
|
|
940
942
|
const resolved = [];
|
|
941
943
|
for (const p of parts) {
|
|
@@ -946,23 +948,23 @@ function resolve(imp, fromPath, byKey) {
|
|
|
946
948
|
return resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
947
949
|
}
|
|
948
950
|
if (imp.startsWith("@") && !imp.startsWith("@rotorsoft/")) {
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
951
|
+
const pkg_name = imp.split("/")[1];
|
|
952
|
+
if (pkg_name) {
|
|
951
953
|
for (const candidate of [
|
|
952
|
-
`packages/${
|
|
953
|
-
`${
|
|
954
|
-
`${
|
|
954
|
+
`packages/${pkg_name}/src/index`,
|
|
955
|
+
`${pkg_name}/src/index`,
|
|
956
|
+
`${pkg_name}/index`
|
|
955
957
|
]) {
|
|
956
|
-
if (
|
|
958
|
+
if (by_key?.has(candidate)) return candidate;
|
|
957
959
|
}
|
|
958
|
-
return `packages/${
|
|
960
|
+
return `packages/${pkg_name}/src/index`;
|
|
959
961
|
}
|
|
960
962
|
}
|
|
961
963
|
return void 0;
|
|
962
964
|
}
|
|
963
965
|
|
|
964
966
|
// src/client/lib/evaluate.ts
|
|
965
|
-
var
|
|
967
|
+
var strip_non_code = (src, level = "full") => {
|
|
966
968
|
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
967
969
|
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`\\])*`/g, blank);
|
|
968
970
|
if (level === "full") {
|
|
@@ -970,7 +972,7 @@ var stripNonCode = (src, level = "full") => {
|
|
|
970
972
|
}
|
|
971
973
|
return result;
|
|
972
974
|
};
|
|
973
|
-
var
|
|
975
|
+
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/");
|
|
974
976
|
function transpile(code) {
|
|
975
977
|
try {
|
|
976
978
|
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
@@ -992,8 +994,8 @@ function execute(files) {
|
|
|
992
994
|
projections: [],
|
|
993
995
|
acts: [],
|
|
994
996
|
error: void 0,
|
|
995
|
-
|
|
996
|
-
|
|
997
|
+
file_errors: /* @__PURE__ */ new Map(),
|
|
998
|
+
expected_slices: /* @__PURE__ */ new Map()
|
|
997
999
|
};
|
|
998
1000
|
try {
|
|
999
1001
|
const __built__ = {
|
|
@@ -1007,24 +1009,24 @@ function execute(files) {
|
|
|
1007
1009
|
info._sourceFile = _currentFile;
|
|
1008
1010
|
__built__[type + "s"].push(info);
|
|
1009
1011
|
};
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1012
|
+
const act_module = { ...MODULES["@rotorsoft/act"] };
|
|
1013
|
+
act_module.state = (entry) => MODULES["@rotorsoft/act"].state(entry, capture("state"));
|
|
1014
|
+
act_module.slice = () => MODULES["@rotorsoft/act"].slice(capture("slice"));
|
|
1015
|
+
act_module.projection = (target) => MODULES["@rotorsoft/act"].projection(
|
|
1014
1016
|
target,
|
|
1015
1017
|
capture("projection")
|
|
1016
1018
|
);
|
|
1017
|
-
|
|
1018
|
-
const
|
|
1019
|
+
act_module.act = () => MODULES["@rotorsoft/act"].act(capture("act"));
|
|
1020
|
+
const pkg_modules = {
|
|
1019
1021
|
...MODULES,
|
|
1020
|
-
"@rotorsoft/act":
|
|
1022
|
+
"@rotorsoft/act": act_module
|
|
1021
1023
|
};
|
|
1022
|
-
const
|
|
1024
|
+
const file_exports = /* @__PURE__ */ new Map();
|
|
1023
1025
|
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
1024
|
-
const
|
|
1025
|
-
if (
|
|
1026
|
+
const resolve_module = (mod, from_path) => {
|
|
1027
|
+
if (pkg_modules[mod]) return pkg_modules[mod];
|
|
1026
1028
|
if (mod.startsWith(".")) {
|
|
1027
|
-
const dir =
|
|
1029
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
1028
1030
|
const parts = (dir ? dir + "/" + mod : mod).split("/");
|
|
1029
1031
|
const resolved = [];
|
|
1030
1032
|
for (const p of parts) {
|
|
@@ -1033,43 +1035,44 @@ function execute(files) {
|
|
|
1033
1035
|
else resolved.push(p);
|
|
1034
1036
|
}
|
|
1035
1037
|
const rp = resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1036
|
-
return
|
|
1038
|
+
return file_exports.get(rp) ?? file_exports.get(rp + "/index") ?? {};
|
|
1037
1039
|
}
|
|
1038
1040
|
if (mod.startsWith("@") && !mod.startsWith("@rotorsoft/")) {
|
|
1039
|
-
const
|
|
1040
|
-
const
|
|
1041
|
-
if (
|
|
1042
|
-
const suffix =
|
|
1043
|
-
return
|
|
1041
|
+
const pkg_name = mod.split("/")[1];
|
|
1042
|
+
const sub_path = mod.split("/").slice(2).join("/");
|
|
1043
|
+
if (pkg_name) {
|
|
1044
|
+
const suffix = sub_path ? `/${sub_path.replace(/\.js$/, "")}` : "/src/index";
|
|
1045
|
+
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();
|
|
1044
1046
|
}
|
|
1045
1047
|
}
|
|
1046
|
-
return
|
|
1048
|
+
return unknown_module_proxy();
|
|
1047
1049
|
};
|
|
1048
|
-
const sorted =
|
|
1050
|
+
const sorted = topo_sort(files.filter(is_source_file));
|
|
1049
1051
|
for (const file of sorted) {
|
|
1050
1052
|
_currentFile = file.path;
|
|
1051
1053
|
const js = transpile(file.content);
|
|
1052
1054
|
const key = strip(file.path);
|
|
1053
1055
|
const fileExp = {};
|
|
1054
|
-
|
|
1055
|
-
const
|
|
1056
|
-
const
|
|
1056
|
+
file_exports.set(key, fileExp);
|
|
1057
|
+
const slice_names_in_act = [];
|
|
1058
|
+
const ws_re = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
1057
1059
|
let wsm;
|
|
1058
|
-
const
|
|
1059
|
-
while ((wsm =
|
|
1060
|
-
if (!
|
|
1060
|
+
const code_only = strip_non_code(js);
|
|
1061
|
+
while ((wsm = ws_re.exec(code_only)) !== null) {
|
|
1062
|
+
if (!slice_names_in_act.includes(wsm[1]))
|
|
1063
|
+
slice_names_in_act.push(wsm[1]);
|
|
1061
1064
|
}
|
|
1062
|
-
for (const m of
|
|
1065
|
+
for (const m of code_only.matchAll(
|
|
1063
1066
|
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
1064
1067
|
)) {
|
|
1065
|
-
result.
|
|
1068
|
+
result.expected_slices.set(m[1], file.path);
|
|
1066
1069
|
}
|
|
1067
|
-
const
|
|
1068
|
-
(mod) =>
|
|
1070
|
+
const file_require = Object.assign(
|
|
1071
|
+
(mod) => resolve_module(mod, key),
|
|
1069
1072
|
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
1070
1073
|
);
|
|
1071
1074
|
try {
|
|
1072
|
-
const
|
|
1075
|
+
const clean_js = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
1073
1076
|
const fn = new Function(
|
|
1074
1077
|
// lgtm[js/code-injection]
|
|
1075
1078
|
"require",
|
|
@@ -1082,21 +1085,21 @@ function execute(files) {
|
|
|
1082
1085
|
var process = { env: {}, cwd: function() { return "/"; }, exit: function() {}, on: function() {}, off: function() {} };
|
|
1083
1086
|
var Buffer = { from: function() { return ""; } };
|
|
1084
1087
|
var console = { log: function() {}, error: function() {}, warn: function() {}, info: function() {}, debug: function() {} };
|
|
1085
|
-
${
|
|
1088
|
+
${clean_js}
|
|
1086
1089
|
`
|
|
1087
1090
|
);
|
|
1088
|
-
fn(
|
|
1091
|
+
fn(file_require, fileExp, { exports: fileExp });
|
|
1089
1092
|
} catch (evalErr) {
|
|
1090
1093
|
const errMsg = evalErr instanceof Error ? evalErr.message : String(evalErr);
|
|
1091
|
-
result.
|
|
1092
|
-
}
|
|
1093
|
-
if (
|
|
1094
|
-
for (const
|
|
1095
|
-
if (
|
|
1096
|
-
const
|
|
1097
|
-
for (let ai = 0; ai < Math.min(
|
|
1098
|
-
if (
|
|
1099
|
-
|
|
1094
|
+
result.file_errors.set(file.path, errMsg);
|
|
1095
|
+
}
|
|
1096
|
+
if (slice_names_in_act.length > 0) {
|
|
1097
|
+
for (const act_obj of __built__.acts) {
|
|
1098
|
+
if (act_obj._sourceFile !== file.path) continue;
|
|
1099
|
+
const act_slices = act_obj.slices;
|
|
1100
|
+
for (let ai = 0; ai < Math.min(slice_names_in_act.length, act_slices.length); ai++) {
|
|
1101
|
+
if (act_slices[ai]) {
|
|
1102
|
+
act_slices[ai]._varName = slice_names_in_act[ai];
|
|
1100
1103
|
}
|
|
1101
1104
|
}
|
|
1102
1105
|
}
|
|
@@ -1111,29 +1114,29 @@ function execute(files) {
|
|
|
1111
1114
|
}
|
|
1112
1115
|
return result;
|
|
1113
1116
|
}
|
|
1114
|
-
function
|
|
1117
|
+
function extract_model(files) {
|
|
1115
1118
|
const result = execute(files);
|
|
1116
|
-
return
|
|
1119
|
+
return build_model(result, files, result.expected_slices);
|
|
1117
1120
|
}
|
|
1118
1121
|
|
|
1119
1122
|
// src/client/lib/navigate.ts
|
|
1120
|
-
function
|
|
1123
|
+
function position_at(content, index) {
|
|
1121
1124
|
const before = content.slice(0, index);
|
|
1122
1125
|
const line = before.split("\n").length;
|
|
1123
|
-
const
|
|
1124
|
-
const col = index - (
|
|
1126
|
+
const last_nl = before.lastIndexOf("\n");
|
|
1127
|
+
const col = index - (last_nl >= 0 ? last_nl : 0);
|
|
1125
1128
|
return { line, col };
|
|
1126
1129
|
}
|
|
1127
|
-
function
|
|
1128
|
-
const
|
|
1129
|
-
const
|
|
1130
|
-
const
|
|
1130
|
+
function build_patterns(esc, type) {
|
|
1131
|
+
const state_patterns = [new RegExp(`state\\(\\s*\\{\\s*(${esc})\\s*[}:,]`)];
|
|
1132
|
+
const action_patterns = [new RegExp(`\\.on\\(\\s*\\{\\s*(${esc})\\s*[},:]`)];
|
|
1133
|
+
const event_patterns = [
|
|
1131
1134
|
// Match event name inside .emits({ EventName: ... }) — inline declaration
|
|
1132
1135
|
new RegExp(`\\.emits\\([\\s\\S]*?(${esc})\\s*:`),
|
|
1133
1136
|
// Match event name as key in a schema object: EventName: z.object(...)
|
|
1134
1137
|
new RegExp(`(${esc})\\s*:\\s*z\\.object\\(`)
|
|
1135
1138
|
];
|
|
1136
|
-
const
|
|
1139
|
+
const reaction_patterns = [
|
|
1137
1140
|
// .do(handlerName) or .do(module.handlerName) — handler declaration in builder
|
|
1138
1141
|
new RegExp(`\\.do\\(\\s*(?:\\w+\\.)?(${esc})\\b`),
|
|
1139
1142
|
// inline function in .do()
|
|
@@ -1143,11 +1146,11 @@ function buildPatterns(esc, type) {
|
|
|
1143
1146
|
// Fallback: function definition
|
|
1144
1147
|
new RegExp(`(?:export\\s+)?async\\s+function\\s+(${esc})\\s*\\(`)
|
|
1145
1148
|
];
|
|
1146
|
-
const
|
|
1149
|
+
const projection_patterns = [
|
|
1147
1150
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*projection\\s*\\(`),
|
|
1148
1151
|
new RegExp(`projection\\(\\s*["'\`](${esc})["'\`]`)
|
|
1149
1152
|
];
|
|
1150
|
-
const
|
|
1153
|
+
const guard_patterns = [
|
|
1151
1154
|
// Guard definition — prefer jumping to the declaration
|
|
1152
1155
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*(?::\\s*Invariant)?\\s*=`),
|
|
1153
1156
|
new RegExp(`rule\\(\\s*["'\`](${esc})["'\`]`),
|
|
@@ -1155,7 +1158,7 @@ function buildPatterns(esc, type) {
|
|
|
1155
1158
|
// .given() usage in the state builder — last resort
|
|
1156
1159
|
new RegExp(`\\.given\\([\\s\\S]*?(${esc})`)
|
|
1157
1160
|
];
|
|
1158
|
-
const
|
|
1161
|
+
const slice_patterns = [
|
|
1159
1162
|
new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*slice\\s*\\(`)
|
|
1160
1163
|
];
|
|
1161
1164
|
const generic = [
|
|
@@ -1167,36 +1170,36 @@ function buildPatterns(esc, type) {
|
|
|
1167
1170
|
];
|
|
1168
1171
|
switch (type) {
|
|
1169
1172
|
case "state":
|
|
1170
|
-
return [...
|
|
1173
|
+
return [...state_patterns, ...generic];
|
|
1171
1174
|
case "action":
|
|
1172
|
-
return [...
|
|
1175
|
+
return [...action_patterns, ...generic];
|
|
1173
1176
|
case "event":
|
|
1174
|
-
return [...
|
|
1177
|
+
return [...event_patterns, ...generic];
|
|
1175
1178
|
case "reaction":
|
|
1176
|
-
return [...
|
|
1179
|
+
return [...reaction_patterns, ...generic];
|
|
1177
1180
|
case "projection":
|
|
1178
|
-
return [...
|
|
1181
|
+
return [...projection_patterns, ...generic];
|
|
1179
1182
|
case "guard":
|
|
1180
|
-
return [...
|
|
1183
|
+
return [...guard_patterns, ...generic];
|
|
1181
1184
|
default:
|
|
1182
1185
|
return [
|
|
1183
|
-
...
|
|
1184
|
-
...
|
|
1185
|
-
...
|
|
1186
|
-
...
|
|
1187
|
-
...
|
|
1188
|
-
...
|
|
1189
|
-
...
|
|
1186
|
+
...slice_patterns,
|
|
1187
|
+
...state_patterns,
|
|
1188
|
+
...action_patterns,
|
|
1189
|
+
...event_patterns,
|
|
1190
|
+
...reaction_patterns,
|
|
1191
|
+
...projection_patterns,
|
|
1192
|
+
...guard_patterns,
|
|
1190
1193
|
...generic
|
|
1191
1194
|
];
|
|
1192
1195
|
}
|
|
1193
1196
|
}
|
|
1194
|
-
function
|
|
1197
|
+
function navigate_to_code(files, name, type, target_file) {
|
|
1195
1198
|
const stripped = /* @__PURE__ */ new Map();
|
|
1196
1199
|
const code = (f) => {
|
|
1197
1200
|
let c = stripped.get(f.path);
|
|
1198
1201
|
if (c === void 0) {
|
|
1199
|
-
c =
|
|
1202
|
+
c = strip_non_code(f.content, "nav");
|
|
1200
1203
|
stripped.set(f.path, c);
|
|
1201
1204
|
}
|
|
1202
1205
|
return c;
|
|
@@ -1204,122 +1207,122 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1204
1207
|
if (type === "file") {
|
|
1205
1208
|
const file = files.find((f) => f.path === name || f.path.endsWith(name));
|
|
1206
1209
|
if (file) {
|
|
1207
|
-
const
|
|
1208
|
-
if (
|
|
1209
|
-
const { line, col } =
|
|
1210
|
+
const act_match = /\bact\s*\(\s*\)/.exec(code(file));
|
|
1211
|
+
if (act_match) {
|
|
1212
|
+
const { line, col } = position_at(file.content, act_match.index);
|
|
1210
1213
|
return { file: file.path, line, col };
|
|
1211
1214
|
}
|
|
1212
1215
|
return { file: file.path, line: 1, col: 1 };
|
|
1213
1216
|
}
|
|
1214
1217
|
return void 0;
|
|
1215
1218
|
}
|
|
1216
|
-
if (
|
|
1217
|
-
const file = files.find((f) => f.path ===
|
|
1219
|
+
if (target_file) {
|
|
1220
|
+
const file = files.find((f) => f.path === target_file);
|
|
1218
1221
|
if (file) {
|
|
1219
1222
|
const c = code(file);
|
|
1220
1223
|
const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1221
1224
|
if (type === "event") {
|
|
1222
|
-
const
|
|
1225
|
+
const emits_block_re = new RegExp(
|
|
1223
1226
|
`\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
|
|
1224
1227
|
);
|
|
1225
|
-
const
|
|
1226
|
-
if (
|
|
1227
|
-
const
|
|
1228
|
-
const { line, col } =
|
|
1228
|
+
const block_match = emits_block_re.exec(c);
|
|
1229
|
+
if (block_match) {
|
|
1230
|
+
const name_idx = block_match.index + block_match[0].lastIndexOf(name);
|
|
1231
|
+
const { line, col } = position_at(file.content, name_idx);
|
|
1229
1232
|
return { file: file.path, line, col };
|
|
1230
1233
|
}
|
|
1231
|
-
const
|
|
1232
|
-
if (
|
|
1233
|
-
const
|
|
1234
|
-
if (
|
|
1235
|
-
const { line, col } =
|
|
1234
|
+
const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
1235
|
+
if (name_re2.exec(c)) {
|
|
1236
|
+
const emits_match = /\.emits\s*\(/.exec(c);
|
|
1237
|
+
if (emits_match) {
|
|
1238
|
+
const { line, col } = position_at(
|
|
1236
1239
|
file.content,
|
|
1237
|
-
|
|
1240
|
+
emits_match.index + 1
|
|
1238
1241
|
);
|
|
1239
1242
|
return { file: file.path, line, col };
|
|
1240
1243
|
}
|
|
1241
1244
|
}
|
|
1242
1245
|
}
|
|
1243
1246
|
if (type === "guard") {
|
|
1244
|
-
const
|
|
1245
|
-
const
|
|
1246
|
-
if (
|
|
1247
|
-
const before = c.slice(0,
|
|
1248
|
-
const
|
|
1249
|
-
let
|
|
1247
|
+
const desc_re = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
|
|
1248
|
+
const desc_match = desc_re.exec(c);
|
|
1249
|
+
if (desc_match) {
|
|
1250
|
+
const before = c.slice(0, desc_match.index);
|
|
1251
|
+
const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1252
|
+
let last_decl = null;
|
|
1250
1253
|
let m;
|
|
1251
|
-
while ((m =
|
|
1252
|
-
|
|
1254
|
+
while ((m = decl_re.exec(before)) !== null) {
|
|
1255
|
+
last_decl = m;
|
|
1253
1256
|
}
|
|
1254
|
-
if (
|
|
1255
|
-
const
|
|
1256
|
-
const { line: line2, col: col2 } =
|
|
1257
|
+
if (last_decl) {
|
|
1258
|
+
const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
|
|
1259
|
+
const { line: line2, col: col2 } = position_at(file.content, name_idx);
|
|
1257
1260
|
return { file: file.path, line: line2, col: col2 };
|
|
1258
1261
|
}
|
|
1259
|
-
const { line, col } =
|
|
1262
|
+
const { line, col } = position_at(file.content, desc_match.index);
|
|
1260
1263
|
return { file: file.path, line, col };
|
|
1261
1264
|
}
|
|
1262
1265
|
}
|
|
1263
1266
|
if (type === "action") {
|
|
1264
|
-
const
|
|
1265
|
-
const
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
const match2 =
|
|
1267
|
+
const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
1268
|
+
const block_start = c.indexOf(".on(");
|
|
1269
|
+
if (block_start >= 0) {
|
|
1270
|
+
name_re2.lastIndex = block_start;
|
|
1271
|
+
const match2 = name_re2.exec(c);
|
|
1269
1272
|
if (match2) {
|
|
1270
|
-
const { line, col } =
|
|
1273
|
+
const { line, col } = position_at(file.content, match2.index);
|
|
1271
1274
|
return { file: file.path, line, col };
|
|
1272
1275
|
}
|
|
1273
1276
|
}
|
|
1274
1277
|
}
|
|
1275
|
-
const
|
|
1276
|
-
const match =
|
|
1278
|
+
const name_re = new RegExp(`\\b${esc2}\\b`);
|
|
1279
|
+
const match = name_re.exec(c);
|
|
1277
1280
|
if (match) {
|
|
1278
|
-
const { line, col } =
|
|
1281
|
+
const { line, col } = position_at(file.content, match.index);
|
|
1279
1282
|
return { file: file.path, line, col };
|
|
1280
1283
|
}
|
|
1281
1284
|
}
|
|
1282
1285
|
return void 0;
|
|
1283
1286
|
}
|
|
1284
1287
|
const esc = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1285
|
-
const
|
|
1286
|
-
const
|
|
1287
|
-
(a, b) => (
|
|
1288
|
+
const is_test_file = (p) => /(?:\.spec\.|\.test\.|__tests__)/.test(p) || /\/test\//.test(p);
|
|
1289
|
+
const sorted_files = [...files].sort(
|
|
1290
|
+
(a, b) => (is_test_file(a.path) ? 1 : 0) - (is_test_file(b.path) ? 1 : 0)
|
|
1288
1291
|
);
|
|
1289
1292
|
if (type === "guard") {
|
|
1290
|
-
const
|
|
1291
|
-
for (const f of
|
|
1293
|
+
const desc_re = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
|
|
1294
|
+
for (const f of sorted_files) {
|
|
1292
1295
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1293
1296
|
const c = code(f);
|
|
1294
|
-
const
|
|
1295
|
-
if (
|
|
1296
|
-
const before = c.slice(0,
|
|
1297
|
-
const
|
|
1298
|
-
let
|
|
1297
|
+
const desc_match = desc_re.exec(c);
|
|
1298
|
+
if (desc_match) {
|
|
1299
|
+
const before = c.slice(0, desc_match.index);
|
|
1300
|
+
const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1301
|
+
let last_decl = null;
|
|
1299
1302
|
let m;
|
|
1300
|
-
while ((m =
|
|
1301
|
-
if (
|
|
1302
|
-
const
|
|
1303
|
-
const { line: line2, col: col2 } =
|
|
1303
|
+
while ((m = decl_re.exec(before)) !== null) last_decl = m;
|
|
1304
|
+
if (last_decl) {
|
|
1305
|
+
const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
|
|
1306
|
+
const { line: line2, col: col2 } = position_at(f.content, name_idx);
|
|
1304
1307
|
return { file: f.path, line: line2, col: col2 };
|
|
1305
1308
|
}
|
|
1306
|
-
const { line, col } =
|
|
1309
|
+
const { line, col } = position_at(f.content, desc_match.index);
|
|
1307
1310
|
return { file: f.path, line, col };
|
|
1308
1311
|
}
|
|
1309
1312
|
}
|
|
1310
1313
|
}
|
|
1311
|
-
const patterns =
|
|
1314
|
+
const patterns = build_patterns(esc, type);
|
|
1312
1315
|
for (const re of patterns) {
|
|
1313
|
-
for (const f of
|
|
1316
|
+
for (const f of sorted_files) {
|
|
1314
1317
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1315
1318
|
const c = code(f);
|
|
1316
|
-
const
|
|
1319
|
+
const global_re = new RegExp(re.source, re.flags + "g");
|
|
1317
1320
|
let match;
|
|
1318
|
-
while ((match =
|
|
1319
|
-
const
|
|
1320
|
-
const
|
|
1321
|
-
const
|
|
1322
|
-
const { line, col } =
|
|
1321
|
+
while ((match = global_re.exec(c)) !== null) {
|
|
1322
|
+
const match_text = match[0];
|
|
1323
|
+
const name_offset_in_match = match_text.lastIndexOf(name);
|
|
1324
|
+
const name_start = match.index + Math.max(0, name_offset_in_match);
|
|
1325
|
+
const { line, col } = position_at(f.content, name_start);
|
|
1323
1326
|
return { file: f.path, line, col };
|
|
1324
1327
|
}
|
|
1325
1328
|
}
|
|
@@ -1451,63 +1454,63 @@ var COLORS = {
|
|
|
1451
1454
|
reaction: { bg: "#7e22ce", border: "#a855f7", text: "#d8b4fe" },
|
|
1452
1455
|
projection: { bg: "#15803d", border: "#22c55e", text: "#bbf7d0" }
|
|
1453
1456
|
};
|
|
1454
|
-
function
|
|
1457
|
+
function measure_chain(rDef, lookup, visited, all_states) {
|
|
1455
1458
|
const rows = [];
|
|
1456
|
-
let
|
|
1459
|
+
let dispatch_block_h = 0;
|
|
1457
1460
|
for (const an of rDef.dispatches) {
|
|
1458
|
-
const
|
|
1459
|
-
const
|
|
1461
|
+
const target_action = all_states.flatMap((s) => s.actions).find((a) => a.name === an);
|
|
1462
|
+
const target_state = all_states.find(
|
|
1460
1463
|
(s) => s.actions.some((a) => a.name === an)
|
|
1461
1464
|
);
|
|
1462
|
-
const
|
|
1463
|
-
const
|
|
1465
|
+
const emit_names = target_action?.emits ?? [];
|
|
1466
|
+
const emit_infos = [];
|
|
1464
1467
|
let emitsH = 0;
|
|
1465
|
-
for (const en of
|
|
1468
|
+
for (const en of emit_names) {
|
|
1466
1469
|
const subR = lookup.get(en);
|
|
1467
1470
|
let eventH = H;
|
|
1468
|
-
let
|
|
1471
|
+
let sub_chain;
|
|
1469
1472
|
if (subR && !visited.has(subR.handlerName)) {
|
|
1470
1473
|
visited.add(subR.handlerName);
|
|
1471
|
-
|
|
1472
|
-
eventH = Math.max(H,
|
|
1474
|
+
sub_chain = measure_chain(subR, lookup, visited, all_states);
|
|
1475
|
+
eventH = Math.max(H, sub_chain.groupH);
|
|
1473
1476
|
}
|
|
1474
|
-
|
|
1477
|
+
emit_infos.push({
|
|
1475
1478
|
name: en,
|
|
1476
1479
|
h: eventH,
|
|
1477
|
-
|
|
1478
|
-
|
|
1480
|
+
sub_chain,
|
|
1481
|
+
sub_reaction: subR && sub_chain ? subR : void 0
|
|
1479
1482
|
});
|
|
1480
1483
|
emitsH += eventH;
|
|
1481
1484
|
}
|
|
1482
|
-
const rowH = Math.max(H,
|
|
1483
|
-
rows.push({ an, rowH,
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1485
|
+
const rowH = Math.max(H, target_state ? STATE_H : 0, emitsH || H);
|
|
1486
|
+
rows.push({ an, rowH, emit_infos, emitsH, target_state });
|
|
1487
|
+
if (dispatch_block_h > 0) dispatch_block_h += GAP / 2;
|
|
1488
|
+
dispatch_block_h += rowH;
|
|
1486
1489
|
}
|
|
1487
|
-
return { groupH: Math.max(H,
|
|
1490
|
+
return { groupH: Math.max(H, dispatch_block_h), dispatch_block_h, rows };
|
|
1488
1491
|
}
|
|
1489
|
-
function
|
|
1490
|
-
const
|
|
1492
|
+
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) {
|
|
1493
|
+
const dispatch_base_x = rX + W + GAP;
|
|
1491
1494
|
const rp = { x: rX, y: reactionY };
|
|
1492
1495
|
ns.push({
|
|
1493
|
-
key: `r:${rDef.handlerName}:${
|
|
1496
|
+
key: `r:${rDef.handlerName}:${slice_name}`,
|
|
1494
1497
|
pos: rp,
|
|
1495
1498
|
type: "reaction",
|
|
1496
1499
|
label: rDef.handlerName
|
|
1497
1500
|
});
|
|
1498
1501
|
es.push({
|
|
1499
|
-
from: { x:
|
|
1502
|
+
from: { x: triggered_from_x, y: triggered_from_y },
|
|
1500
1503
|
to: { x: rp.x, y: rp.y + H / 2 },
|
|
1501
1504
|
color: COLORS.reaction.border,
|
|
1502
1505
|
dash: true
|
|
1503
1506
|
});
|
|
1504
|
-
const
|
|
1505
|
-
let dispatchY =
|
|
1507
|
+
const reaction_center_y = reactionY + H / 2;
|
|
1508
|
+
let dispatchY = reaction_center_y - measure.dispatch_block_h / 2;
|
|
1506
1509
|
for (const row of measure.rows) {
|
|
1507
|
-
const
|
|
1508
|
-
let nextX =
|
|
1509
|
-
const dap = { x: nextX, y:
|
|
1510
|
-
const
|
|
1510
|
+
const row_center_y = dispatchY + row.rowH / 2;
|
|
1511
|
+
let nextX = dispatch_base_x;
|
|
1512
|
+
const dap = { x: nextX, y: row_center_y - H / 2 };
|
|
1513
|
+
const dispatched_action = row.target_state?.actions.find(
|
|
1511
1514
|
(a) => a.name === row.an
|
|
1512
1515
|
);
|
|
1513
1516
|
ns.push({
|
|
@@ -1515,10 +1518,10 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1515
1518
|
pos: dap,
|
|
1516
1519
|
type: "action",
|
|
1517
1520
|
label: row.an,
|
|
1518
|
-
sub:
|
|
1519
|
-
guards:
|
|
1520
|
-
file: row.
|
|
1521
|
-
emits:
|
|
1521
|
+
sub: dispatched_action && dispatched_action.invariants.length > 0 ? "guarded" : void 0,
|
|
1522
|
+
guards: dispatched_action && dispatched_action.invariants.length > 0 ? dispatched_action.invariants : void 0,
|
|
1523
|
+
file: row.target_state?.file,
|
|
1524
|
+
emits: dispatched_action?.emits
|
|
1522
1525
|
});
|
|
1523
1526
|
es.push({
|
|
1524
1527
|
from: { x: rp.x + W, y: rp.y + H / 2 },
|
|
@@ -1527,106 +1530,106 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
|
|
|
1527
1530
|
dash: true
|
|
1528
1531
|
});
|
|
1529
1532
|
nextX += W + GAP;
|
|
1530
|
-
if (row.
|
|
1533
|
+
if (row.target_state) {
|
|
1531
1534
|
ns.push({
|
|
1532
|
-
key: `s:${row.
|
|
1533
|
-
pos: { x: nextX, y:
|
|
1535
|
+
key: `s:${row.target_state.name}:dispatched:${rDef.handlerName}:${row.an}`,
|
|
1536
|
+
pos: { x: nextX, y: row_center_y - STATE_H / 2 },
|
|
1534
1537
|
type: "state",
|
|
1535
|
-
label: row.
|
|
1536
|
-
file: row.
|
|
1538
|
+
label: row.target_state.name,
|
|
1539
|
+
file: row.target_state.file
|
|
1537
1540
|
});
|
|
1538
1541
|
nextX += STATE_W + GAP;
|
|
1539
1542
|
}
|
|
1540
1543
|
const evtX = nextX;
|
|
1541
|
-
const nEvents = row.
|
|
1542
|
-
const
|
|
1543
|
-
let emitY =
|
|
1544
|
-
for (const emit of row.
|
|
1544
|
+
const nEvents = row.emit_infos.length;
|
|
1545
|
+
const events_only_h = nEvents * H + (nEvents - 1) * (GAP / 2);
|
|
1546
|
+
let emitY = row_center_y - events_only_h / 2;
|
|
1547
|
+
for (const emit of row.emit_infos) {
|
|
1545
1548
|
ns.push({
|
|
1546
1549
|
key: `e:${emit.name}:dispatched:${rDef.handlerName}:${row.an}`,
|
|
1547
1550
|
pos: { x: evtX, y: emitY },
|
|
1548
1551
|
type: "event",
|
|
1549
1552
|
label: emit.name,
|
|
1550
|
-
file: row.
|
|
1551
|
-
projections:
|
|
1552
|
-
reactions:
|
|
1553
|
-
schema:
|
|
1553
|
+
file: row.target_state?.file,
|
|
1554
|
+
projections: event_projections.get(emit.name),
|
|
1555
|
+
reactions: event_reactions.get(emit.name),
|
|
1556
|
+
schema: event_schemas.get(emit.name)
|
|
1554
1557
|
});
|
|
1555
|
-
if (emit.
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
emit.
|
|
1559
|
-
emit.
|
|
1558
|
+
if (emit.sub_chain && emit.sub_reaction) {
|
|
1559
|
+
const sub_r_x = evtX + W + GAP * 3;
|
|
1560
|
+
place_chain(
|
|
1561
|
+
emit.sub_chain,
|
|
1562
|
+
emit.sub_reaction,
|
|
1560
1563
|
emitY,
|
|
1561
1564
|
// reaction aligns with emit
|
|
1562
|
-
|
|
1565
|
+
sub_r_x,
|
|
1563
1566
|
evtX + W,
|
|
1564
1567
|
emitY + H / 2,
|
|
1565
1568
|
ns,
|
|
1566
1569
|
es,
|
|
1567
|
-
|
|
1570
|
+
slice_name,
|
|
1568
1571
|
lookup,
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1572
|
+
event_projections,
|
|
1573
|
+
event_reactions,
|
|
1574
|
+
event_schemas,
|
|
1575
|
+
slice_right_x_ref
|
|
1573
1576
|
);
|
|
1574
1577
|
}
|
|
1575
1578
|
emitY += H + GAP / 2;
|
|
1576
1579
|
}
|
|
1577
|
-
if (row.
|
|
1578
|
-
|
|
1580
|
+
if (row.emit_infos.length > 0) nextX = evtX + W + GAP;
|
|
1581
|
+
slice_right_x_ref.value = Math.max(slice_right_x_ref.value, nextX);
|
|
1579
1582
|
dispatchY += row.rowH + GAP / 2;
|
|
1580
1583
|
}
|
|
1581
1584
|
}
|
|
1582
|
-
function
|
|
1585
|
+
function compute_layout(view_model) {
|
|
1583
1586
|
const ns = [];
|
|
1584
1587
|
const es = [];
|
|
1585
1588
|
const boxes = [];
|
|
1586
1589
|
const sv = /* @__PURE__ */ new Map();
|
|
1587
|
-
for (const s of
|
|
1590
|
+
for (const s of view_model.states) {
|
|
1588
1591
|
sv.set(s.varName, s);
|
|
1589
1592
|
sv.set(s.name, s);
|
|
1590
1593
|
}
|
|
1591
|
-
const
|
|
1592
|
-
const
|
|
1593
|
-
const
|
|
1594
|
-
for (const s of
|
|
1594
|
+
const event_projections = /* @__PURE__ */ new Map();
|
|
1595
|
+
const event_reactions = /* @__PURE__ */ new Map();
|
|
1596
|
+
const event_schemas = /* @__PURE__ */ new Map();
|
|
1597
|
+
for (const s of view_model.states) {
|
|
1595
1598
|
for (const e of s.events) {
|
|
1596
|
-
if (e.schema && !
|
|
1597
|
-
|
|
1599
|
+
if (e.schema && !event_schemas.has(e.name)) {
|
|
1600
|
+
event_schemas.set(e.name, e.schema);
|
|
1598
1601
|
}
|
|
1599
1602
|
}
|
|
1600
1603
|
}
|
|
1601
|
-
const
|
|
1602
|
-
for (const proj of
|
|
1603
|
-
|
|
1604
|
+
const projection_handles = /* @__PURE__ */ new Map();
|
|
1605
|
+
for (const proj of view_model.projections) {
|
|
1606
|
+
projection_handles.set(proj.name, proj.handles);
|
|
1604
1607
|
}
|
|
1605
|
-
for (const slice of
|
|
1608
|
+
for (const slice of view_model.slices) {
|
|
1606
1609
|
for (const r of slice.reactions) {
|
|
1607
|
-
const list =
|
|
1610
|
+
const list = event_reactions.get(r.event) ?? [];
|
|
1608
1611
|
list.push(r.handlerName);
|
|
1609
|
-
|
|
1612
|
+
event_reactions.set(r.event, list);
|
|
1610
1613
|
}
|
|
1611
1614
|
}
|
|
1612
|
-
for (const r of
|
|
1613
|
-
const list =
|
|
1615
|
+
for (const r of view_model.reactions) {
|
|
1616
|
+
const list = event_reactions.get(r.event) ?? [];
|
|
1614
1617
|
list.push(r.handlerName);
|
|
1615
|
-
|
|
1618
|
+
event_reactions.set(r.event, list);
|
|
1616
1619
|
}
|
|
1617
|
-
for (const proj of
|
|
1620
|
+
for (const proj of view_model.projections) {
|
|
1618
1621
|
for (const en of proj.handles) {
|
|
1619
|
-
const list =
|
|
1622
|
+
const list = event_projections.get(en) ?? [];
|
|
1620
1623
|
list.push(proj.name);
|
|
1621
|
-
|
|
1624
|
+
event_projections.set(en, list);
|
|
1622
1625
|
}
|
|
1623
1626
|
}
|
|
1624
1627
|
let cx = PAD;
|
|
1625
1628
|
let globalY = 0;
|
|
1626
|
-
const
|
|
1629
|
+
const sorted_slices = [...view_model.slices].sort(
|
|
1627
1630
|
(a, b) => a.name.localeCompare(b.name)
|
|
1628
1631
|
);
|
|
1629
|
-
for (const slice of
|
|
1632
|
+
for (const slice of sorted_slices) {
|
|
1630
1633
|
if (slice.error && slice.states.length === 0) {
|
|
1631
1634
|
const sx2 = PAD;
|
|
1632
1635
|
const errorW = Math.max(300, slice.error.length * 5);
|
|
@@ -1646,181 +1649,181 @@ function computeLayout(viewModel) {
|
|
|
1646
1649
|
cx = PAD;
|
|
1647
1650
|
const sx = cx;
|
|
1648
1651
|
cx += SLICE_PAD + GAP;
|
|
1649
|
-
const
|
|
1650
|
-
const
|
|
1651
|
-
const
|
|
1652
|
-
const
|
|
1653
|
-
for (const st of
|
|
1652
|
+
const event_file_map = /* @__PURE__ */ new Map();
|
|
1653
|
+
const action_file_map = /* @__PURE__ */ new Map();
|
|
1654
|
+
const raw_parts = slice.stateVars.map((v) => sv.get(v)).filter(Boolean);
|
|
1655
|
+
const merged_by_name = /* @__PURE__ */ new Map();
|
|
1656
|
+
for (const st of raw_parts) {
|
|
1654
1657
|
for (const e of st.events) {
|
|
1655
|
-
if (st.file)
|
|
1658
|
+
if (st.file) event_file_map.set(e.name, st.file);
|
|
1656
1659
|
}
|
|
1657
1660
|
for (const a of st.actions) {
|
|
1658
|
-
if (st.file)
|
|
1661
|
+
if (st.file) action_file_map.set(a.name, st.file);
|
|
1659
1662
|
}
|
|
1660
|
-
const existing =
|
|
1663
|
+
const existing = merged_by_name.get(st.name);
|
|
1661
1664
|
if (existing) {
|
|
1662
|
-
const
|
|
1665
|
+
const action_names = new Set(existing.actions.map((a) => a.name));
|
|
1663
1666
|
for (const a of st.actions) {
|
|
1664
|
-
if (!
|
|
1667
|
+
if (!action_names.has(a.name)) existing.actions.push(a);
|
|
1665
1668
|
}
|
|
1666
|
-
const
|
|
1669
|
+
const event_names = new Set(existing.events.map((e) => e.name));
|
|
1667
1670
|
for (const e of st.events) {
|
|
1668
|
-
if (!
|
|
1671
|
+
if (!event_names.has(e.name)) existing.events.push(e);
|
|
1669
1672
|
}
|
|
1670
1673
|
} else {
|
|
1671
|
-
|
|
1674
|
+
merged_by_name.set(st.name, {
|
|
1672
1675
|
...st,
|
|
1673
1676
|
actions: [...st.actions],
|
|
1674
1677
|
events: [...st.events]
|
|
1675
1678
|
});
|
|
1676
1679
|
}
|
|
1677
1680
|
}
|
|
1678
|
-
const parts = [...
|
|
1681
|
+
const parts = [...merged_by_name.values()];
|
|
1679
1682
|
let y = SLICE_INNER;
|
|
1680
|
-
let
|
|
1681
|
-
const
|
|
1682
|
-
const
|
|
1683
|
-
const
|
|
1683
|
+
let slice_right_x = cx;
|
|
1684
|
+
const slice_node_start = ns.length;
|
|
1685
|
+
const slice_edge_start = es.length;
|
|
1686
|
+
const slice_reactions_by_event = /* @__PURE__ */ new Map();
|
|
1684
1687
|
for (const r of slice.reactions) {
|
|
1685
|
-
const list =
|
|
1688
|
+
const list = slice_reactions_by_event.get(r.event) ?? [];
|
|
1686
1689
|
list.push(r);
|
|
1687
|
-
|
|
1690
|
+
slice_reactions_by_event.set(r.event, list);
|
|
1688
1691
|
}
|
|
1689
|
-
const
|
|
1690
|
-
for (const [event, reactions] of
|
|
1691
|
-
|
|
1692
|
+
const slice_reaction_by_event = /* @__PURE__ */ new Map();
|
|
1693
|
+
for (const [event, reactions] of slice_reactions_by_event) {
|
|
1694
|
+
slice_reaction_by_event.set(event, reactions[0]);
|
|
1692
1695
|
}
|
|
1693
|
-
const
|
|
1694
|
-
const
|
|
1695
|
-
let
|
|
1696
|
+
const visited_events = /* @__PURE__ */ new Set();
|
|
1697
|
+
const visited_reactions = /* @__PURE__ */ new Set();
|
|
1698
|
+
let part_idx = 0;
|
|
1696
1699
|
for (const st of parts) {
|
|
1697
|
-
if (
|
|
1698
|
-
const
|
|
1699
|
-
const
|
|
1700
|
-
const
|
|
1701
|
-
const
|
|
1700
|
+
if (part_idx > 0) y += GAP * 2;
|
|
1701
|
+
const state_col_x = cx + W + GAP;
|
|
1702
|
+
const event_col_x = state_col_x + STATE_W + GAP;
|
|
1703
|
+
const event_rows = [];
|
|
1704
|
+
const action_emitted = /* @__PURE__ */ new Set();
|
|
1702
1705
|
for (const action of st.actions) {
|
|
1703
1706
|
for (const en of action.emits) {
|
|
1704
|
-
|
|
1707
|
+
action_emitted.add(en);
|
|
1705
1708
|
}
|
|
1706
1709
|
}
|
|
1707
1710
|
for (const ev of st.events) {
|
|
1708
|
-
if (!
|
|
1709
|
-
|
|
1711
|
+
if (!action_emitted.has(ev.name)) {
|
|
1712
|
+
event_rows.push({ event_name: ev.name, action_name: "" });
|
|
1710
1713
|
}
|
|
1711
1714
|
}
|
|
1712
1715
|
for (const action of st.actions) {
|
|
1713
1716
|
for (const en of action.emits) {
|
|
1714
|
-
|
|
1717
|
+
event_rows.push({ event_name: en, action_name: action.name });
|
|
1715
1718
|
}
|
|
1716
1719
|
}
|
|
1717
|
-
const
|
|
1718
|
-
let
|
|
1719
|
-
for (const {
|
|
1720
|
+
const measured_events = [];
|
|
1721
|
+
let evt_block_h = 0;
|
|
1722
|
+
for (const { event_name: en, action_name } of event_rows) {
|
|
1720
1723
|
const chains = [];
|
|
1721
|
-
if (!
|
|
1722
|
-
const rDefs =
|
|
1724
|
+
if (!visited_events.has(en)) {
|
|
1725
|
+
const rDefs = slice_reactions_by_event.get(en) ?? [];
|
|
1723
1726
|
for (const rDef of rDefs) {
|
|
1724
|
-
if (
|
|
1725
|
-
|
|
1726
|
-
const chain =
|
|
1727
|
+
if (visited_reactions.has(rDef.handlerName)) continue;
|
|
1728
|
+
visited_reactions.add(rDef.handlerName);
|
|
1729
|
+
const chain = measure_chain(
|
|
1727
1730
|
rDef,
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
+
slice_reaction_by_event,
|
|
1732
|
+
visited_reactions,
|
|
1733
|
+
view_model.states
|
|
1731
1734
|
);
|
|
1732
1735
|
chains.push({ chain, reaction: rDef });
|
|
1733
1736
|
}
|
|
1734
|
-
if (rDefs.length > 0)
|
|
1737
|
+
if (rDefs.length > 0) visited_events.add(en);
|
|
1735
1738
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
+
measured_events.push({
|
|
1740
|
+
event_name: en,
|
|
1741
|
+
action_name,
|
|
1739
1742
|
h: H,
|
|
1740
1743
|
chains
|
|
1741
1744
|
});
|
|
1742
|
-
if (
|
|
1743
|
-
|
|
1745
|
+
if (evt_block_h > 0) evt_block_h += GAP / 2;
|
|
1746
|
+
evt_block_h += H;
|
|
1744
1747
|
}
|
|
1745
|
-
if (
|
|
1748
|
+
if (evt_block_h === 0) evt_block_h = H;
|
|
1746
1749
|
const nActs = st.actions.length;
|
|
1747
|
-
const
|
|
1748
|
-
const
|
|
1749
|
-
const
|
|
1750
|
+
const act_block_h = nActs * H + (nActs - 1) * (GAP / 2);
|
|
1751
|
+
const primary_block_h = Math.max(evt_block_h, act_block_h, STATE_H);
|
|
1752
|
+
const st_center_y = y + primary_block_h / 2;
|
|
1750
1753
|
ns.push({
|
|
1751
1754
|
key: `s:${st.name}:${slice.name}`,
|
|
1752
|
-
pos: { x:
|
|
1755
|
+
pos: { x: state_col_x, y: st_center_y - STATE_H / 2 },
|
|
1753
1756
|
type: "state",
|
|
1754
1757
|
label: st.name,
|
|
1755
1758
|
file: st.file
|
|
1756
1759
|
});
|
|
1757
|
-
const
|
|
1758
|
-
let evtY =
|
|
1759
|
-
let
|
|
1760
|
-
const
|
|
1761
|
-
for (let ei = 0; ei <
|
|
1762
|
-
const {
|
|
1760
|
+
const slice_right_x_ref = { value: slice_right_x };
|
|
1761
|
+
let evtY = st_center_y - evt_block_h / 2;
|
|
1762
|
+
let chain_watermark = -Infinity;
|
|
1763
|
+
const event_y_map = /* @__PURE__ */ new Map();
|
|
1764
|
+
for (let ei = 0; ei < measured_events.length; ei++) {
|
|
1765
|
+
const { event_name: en, action_name, chains } = measured_events[ei];
|
|
1763
1766
|
ns.push({
|
|
1764
|
-
key: `e:${en}:${slice.name}:${
|
|
1765
|
-
pos: { x:
|
|
1767
|
+
key: `e:${en}:${slice.name}:${action_name}`,
|
|
1768
|
+
pos: { x: event_col_x, y: evtY },
|
|
1766
1769
|
type: "event",
|
|
1767
1770
|
label: en,
|
|
1768
|
-
file:
|
|
1769
|
-
projections:
|
|
1770
|
-
reactions:
|
|
1771
|
-
schema:
|
|
1771
|
+
file: event_file_map.get(en) ?? st.file,
|
|
1772
|
+
projections: event_projections.get(en),
|
|
1773
|
+
reactions: event_reactions.get(en),
|
|
1774
|
+
schema: event_schemas.get(en)
|
|
1772
1775
|
});
|
|
1773
|
-
|
|
1774
|
-
for (const { chain, reaction:
|
|
1775
|
-
const rX =
|
|
1776
|
-
const
|
|
1777
|
-
const reactionY = Math.max(evtY,
|
|
1778
|
-
const
|
|
1779
|
-
|
|
1776
|
+
event_y_map.set(en, evtY);
|
|
1777
|
+
for (const { chain, reaction: chain_reaction } of chains) {
|
|
1778
|
+
const rX = event_col_x + W + GAP * 3;
|
|
1779
|
+
const min_reaction_y = chain_watermark + chain.dispatch_block_h / 2 - H / 2;
|
|
1780
|
+
const reactionY = Math.max(evtY, min_reaction_y);
|
|
1781
|
+
const chain_start_idx = ns.length;
|
|
1782
|
+
place_chain(
|
|
1780
1783
|
chain,
|
|
1781
|
-
|
|
1784
|
+
chain_reaction,
|
|
1782
1785
|
reactionY,
|
|
1783
1786
|
rX,
|
|
1784
|
-
|
|
1787
|
+
event_col_x + W,
|
|
1785
1788
|
evtY + H / 2,
|
|
1786
1789
|
// arrow always from event center
|
|
1787
1790
|
ns,
|
|
1788
1791
|
es,
|
|
1789
1792
|
slice.name,
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1793
|
+
slice_reaction_by_event,
|
|
1794
|
+
event_projections,
|
|
1795
|
+
event_reactions,
|
|
1796
|
+
event_schemas,
|
|
1797
|
+
slice_right_x_ref
|
|
1795
1798
|
);
|
|
1796
|
-
for (let ni =
|
|
1799
|
+
for (let ni = chain_start_idx; ni < ns.length; ni++) {
|
|
1797
1800
|
const n = ns[ni];
|
|
1798
1801
|
const nh = n.type === "state" ? STATE_H : H;
|
|
1799
|
-
|
|
1802
|
+
chain_watermark = Math.max(chain_watermark, n.pos.y + nh + GAP / 2);
|
|
1800
1803
|
}
|
|
1801
1804
|
}
|
|
1802
1805
|
evtY += H + GAP / 2;
|
|
1803
1806
|
}
|
|
1804
|
-
const
|
|
1805
|
-
for (const me of
|
|
1806
|
-
const projs =
|
|
1807
|
+
const seen_proj = /* @__PURE__ */ new Set();
|
|
1808
|
+
for (const me of measured_events) {
|
|
1809
|
+
const projs = event_projections.get(me.event_name);
|
|
1807
1810
|
if (!projs) continue;
|
|
1808
1811
|
for (const pn of projs) {
|
|
1809
|
-
if (
|
|
1810
|
-
|
|
1812
|
+
if (seen_proj.has(pn)) continue;
|
|
1813
|
+
seen_proj.add(pn);
|
|
1811
1814
|
ns.push({
|
|
1812
1815
|
key: `p:${pn}:${slice.name}`,
|
|
1813
|
-
pos: { x:
|
|
1816
|
+
pos: { x: event_col_x, y: evtY },
|
|
1814
1817
|
type: "projection",
|
|
1815
1818
|
label: pn,
|
|
1816
|
-
handles:
|
|
1819
|
+
handles: projection_handles.get(pn)
|
|
1817
1820
|
});
|
|
1818
1821
|
evtY += H + GAP / 2;
|
|
1819
1822
|
}
|
|
1820
1823
|
}
|
|
1821
|
-
|
|
1822
|
-
let actY =
|
|
1823
|
-
const
|
|
1824
|
+
slice_right_x = slice_right_x_ref.value;
|
|
1825
|
+
let actY = st_center_y - act_block_h / 2;
|
|
1826
|
+
const action_colors = [
|
|
1824
1827
|
"#60a5fa",
|
|
1825
1828
|
"#f97316",
|
|
1826
1829
|
"#a78bfa",
|
|
@@ -1828,9 +1831,9 @@ function computeLayout(viewModel) {
|
|
|
1828
1831
|
"#fb7185",
|
|
1829
1832
|
"#fbbf24"
|
|
1830
1833
|
];
|
|
1831
|
-
let
|
|
1834
|
+
let action_idx = 0;
|
|
1832
1835
|
for (const action of st.actions) {
|
|
1833
|
-
const color =
|
|
1836
|
+
const color = action_colors[action_idx % action_colors.length];
|
|
1834
1837
|
ns.push({
|
|
1835
1838
|
key: `a:${action.name}:${slice.name}`,
|
|
1836
1839
|
pos: { x: cx, y: actY },
|
|
@@ -1838,32 +1841,32 @@ function computeLayout(viewModel) {
|
|
|
1838
1841
|
label: action.name,
|
|
1839
1842
|
sub: action.invariants.length > 0 ? "guarded" : void 0,
|
|
1840
1843
|
guards: action.invariants.length > 0 ? action.invariants : void 0,
|
|
1841
|
-
file:
|
|
1844
|
+
file: action_file_map.get(action.name) ?? st.file,
|
|
1842
1845
|
emits: action.emits
|
|
1843
1846
|
});
|
|
1844
1847
|
for (const en of action.emits) {
|
|
1845
|
-
const ey =
|
|
1848
|
+
const ey = event_y_map.get(en);
|
|
1846
1849
|
es.push({
|
|
1847
1850
|
from: { x: cx + W, y: actY + H / 2 },
|
|
1848
|
-
to: { x:
|
|
1851
|
+
to: { x: event_col_x, y: ey + H / 2 },
|
|
1849
1852
|
color,
|
|
1850
1853
|
dash: false
|
|
1851
1854
|
});
|
|
1852
1855
|
}
|
|
1853
1856
|
actY += H + GAP / 2;
|
|
1854
|
-
|
|
1857
|
+
action_idx++;
|
|
1855
1858
|
}
|
|
1856
|
-
const
|
|
1857
|
-
y +
|
|
1859
|
+
const content_bottom_y = Math.max(
|
|
1860
|
+
y + primary_block_h,
|
|
1858
1861
|
evtY,
|
|
1859
|
-
|
|
1862
|
+
chain_watermark > -Infinity ? chain_watermark : 0
|
|
1860
1863
|
);
|
|
1861
|
-
y =
|
|
1862
|
-
|
|
1864
|
+
y = content_bottom_y + GAP / 2;
|
|
1865
|
+
part_idx++;
|
|
1863
1866
|
}
|
|
1864
1867
|
for (const r of slice.reactions) {
|
|
1865
|
-
if (
|
|
1866
|
-
const rX =
|
|
1868
|
+
if (visited_reactions.has(r.handlerName)) continue;
|
|
1869
|
+
const rX = slice_right_x + GAP * 2;
|
|
1867
1870
|
const rp = { x: rX, y };
|
|
1868
1871
|
ns.push({
|
|
1869
1872
|
key: `r:${r.handlerName}:${slice.name}`,
|
|
@@ -1871,7 +1874,7 @@ function computeLayout(viewModel) {
|
|
|
1871
1874
|
type: "reaction",
|
|
1872
1875
|
label: r.handlerName
|
|
1873
1876
|
});
|
|
1874
|
-
|
|
1877
|
+
slice_right_x = Math.max(slice_right_x, rX + W + GAP);
|
|
1875
1878
|
y += H + GAP / 2;
|
|
1876
1879
|
}
|
|
1877
1880
|
const bbox = {
|
|
@@ -1880,7 +1883,7 @@ function computeLayout(viewModel) {
|
|
|
1880
1883
|
maxX: -Infinity,
|
|
1881
1884
|
maxY: -Infinity
|
|
1882
1885
|
};
|
|
1883
|
-
for (let ni =
|
|
1886
|
+
for (let ni = slice_node_start; ni < ns.length; ni++) {
|
|
1884
1887
|
const n = ns[ni];
|
|
1885
1888
|
const nw = n.type === "state" ? STATE_W : W;
|
|
1886
1889
|
const nh = n.type === "state" ? STATE_H : H;
|
|
@@ -1898,10 +1901,10 @@ function computeLayout(viewModel) {
|
|
|
1898
1901
|
const contentH = bbox.maxY - bbox.minY;
|
|
1899
1902
|
const boxH = contentH + SLICE_INNER * 2;
|
|
1900
1903
|
const dy = globalY - bbox.minY + SLICE_INNER;
|
|
1901
|
-
for (let ni =
|
|
1904
|
+
for (let ni = slice_node_start; ni < ns.length; ni++) {
|
|
1902
1905
|
ns[ni].pos.y += dy;
|
|
1903
1906
|
}
|
|
1904
|
-
for (let ei =
|
|
1907
|
+
for (let ei = slice_edge_start; ei < es.length; ei++) {
|
|
1905
1908
|
es[ei].from.y += dy;
|
|
1906
1909
|
es[ei].to.y += dy;
|
|
1907
1910
|
}
|
|
@@ -1916,57 +1919,57 @@ function computeLayout(viewModel) {
|
|
|
1916
1919
|
globalY += boxH + SLICE_GAP;
|
|
1917
1920
|
}
|
|
1918
1921
|
cx = PAD;
|
|
1919
|
-
const claimed = new Set(
|
|
1920
|
-
const
|
|
1921
|
-
for (const st of
|
|
1922
|
-
const
|
|
1923
|
-
const
|
|
1924
|
-
const
|
|
1925
|
-
const
|
|
1926
|
-
const nEvents =
|
|
1927
|
-
const
|
|
1922
|
+
const claimed = new Set(sorted_slices.flatMap((sl) => sl.stateVars));
|
|
1923
|
+
const standalone_states = [...view_model.states].filter((s) => !claimed.has(s.varName)).sort((a, b) => a.name.localeCompare(b.name));
|
|
1924
|
+
for (const st of standalone_states) {
|
|
1925
|
+
const state_col_x = cx + W + GAP;
|
|
1926
|
+
const event_col_x = state_col_x + STATE_W + GAP;
|
|
1927
|
+
const action_emitted_events = new Set(st.actions.flatMap((a) => a.emits));
|
|
1928
|
+
const orphan_events = st.events.map((e) => e.name).filter((en) => !action_emitted_events.has(en));
|
|
1929
|
+
const nEvents = action_emitted_events.size + orphan_events.length;
|
|
1930
|
+
const evt_block_h = Math.max(nEvents, 1) * H + (Math.max(nEvents, 1) - 1) * (GAP / 2);
|
|
1928
1931
|
const nActs = st.actions.length;
|
|
1929
|
-
const
|
|
1930
|
-
const blockH = Math.max(
|
|
1931
|
-
const
|
|
1932
|
+
const act_block_h = nActs * H + (nActs - 1) * (GAP / 2);
|
|
1933
|
+
const blockH = Math.max(evt_block_h, act_block_h, STATE_H);
|
|
1934
|
+
const st_center_y = globalY + blockH / 2;
|
|
1932
1935
|
ns.push({
|
|
1933
1936
|
key: `s:${st.name}:standalone`,
|
|
1934
|
-
pos: { x:
|
|
1937
|
+
pos: { x: state_col_x, y: st_center_y - STATE_H / 2 },
|
|
1935
1938
|
type: "state",
|
|
1936
1939
|
label: st.name
|
|
1937
1940
|
});
|
|
1938
|
-
let evtY =
|
|
1939
|
-
const
|
|
1941
|
+
let evtY = st_center_y - evt_block_h / 2;
|
|
1942
|
+
const event_y_map = /* @__PURE__ */ new Map();
|
|
1940
1943
|
for (const action of st.actions) {
|
|
1941
1944
|
for (const en of action.emits) {
|
|
1942
1945
|
ns.push({
|
|
1943
1946
|
key: `e:${en}:standalone`,
|
|
1944
|
-
pos: { x:
|
|
1947
|
+
pos: { x: event_col_x, y: evtY },
|
|
1945
1948
|
type: "event",
|
|
1946
1949
|
label: en,
|
|
1947
|
-
projections:
|
|
1948
|
-
reactions:
|
|
1949
|
-
schema:
|
|
1950
|
+
projections: event_projections.get(en),
|
|
1951
|
+
reactions: event_reactions.get(en),
|
|
1952
|
+
schema: event_schemas.get(en)
|
|
1950
1953
|
});
|
|
1951
|
-
|
|
1954
|
+
event_y_map.set(en, evtY);
|
|
1952
1955
|
evtY += H + GAP / 2;
|
|
1953
1956
|
}
|
|
1954
1957
|
}
|
|
1955
|
-
for (const en of
|
|
1958
|
+
for (const en of orphan_events) {
|
|
1956
1959
|
ns.push({
|
|
1957
1960
|
key: `e:${en}:standalone`,
|
|
1958
|
-
pos: { x:
|
|
1961
|
+
pos: { x: event_col_x, y: evtY },
|
|
1959
1962
|
type: "event",
|
|
1960
1963
|
label: en,
|
|
1961
|
-
projections:
|
|
1962
|
-
reactions:
|
|
1963
|
-
schema:
|
|
1964
|
+
projections: event_projections.get(en),
|
|
1965
|
+
reactions: event_reactions.get(en),
|
|
1966
|
+
schema: event_schemas.get(en)
|
|
1964
1967
|
});
|
|
1965
|
-
|
|
1968
|
+
event_y_map.set(en, evtY);
|
|
1966
1969
|
evtY += H + GAP / 2;
|
|
1967
1970
|
}
|
|
1968
|
-
let actY =
|
|
1969
|
-
const
|
|
1971
|
+
let actY = st_center_y - act_block_h / 2;
|
|
1972
|
+
const standalone_colors = [
|
|
1970
1973
|
"#60a5fa",
|
|
1971
1974
|
"#f97316",
|
|
1972
1975
|
"#a78bfa",
|
|
@@ -1976,7 +1979,7 @@ function computeLayout(viewModel) {
|
|
|
1976
1979
|
];
|
|
1977
1980
|
let aIdx = 0;
|
|
1978
1981
|
for (const action of st.actions) {
|
|
1979
|
-
const aColor =
|
|
1982
|
+
const aColor = standalone_colors[aIdx % standalone_colors.length];
|
|
1980
1983
|
ns.push({
|
|
1981
1984
|
key: `a:${action.name}:standalone`,
|
|
1982
1985
|
pos: { x: cx, y: actY },
|
|
@@ -1987,10 +1990,10 @@ function computeLayout(viewModel) {
|
|
|
1987
1990
|
emits: action.emits
|
|
1988
1991
|
});
|
|
1989
1992
|
for (const en of action.emits) {
|
|
1990
|
-
const ey =
|
|
1993
|
+
const ey = event_y_map.get(en);
|
|
1991
1994
|
es.push({
|
|
1992
1995
|
from: { x: cx + W, y: actY + H / 2 },
|
|
1993
|
-
to: { x:
|
|
1996
|
+
to: { x: event_col_x, y: ey + H / 2 },
|
|
1994
1997
|
color: aColor,
|
|
1995
1998
|
dash: false
|
|
1996
1999
|
});
|
|
@@ -2000,15 +2003,15 @@ function computeLayout(viewModel) {
|
|
|
2000
2003
|
}
|
|
2001
2004
|
globalY += blockH + GAP * 2;
|
|
2002
2005
|
}
|
|
2003
|
-
if (
|
|
2004
|
-
const
|
|
2005
|
-
for (const r of
|
|
2006
|
-
const
|
|
2006
|
+
if (view_model.reactions.length > 0) {
|
|
2007
|
+
const reaction_y_by_event = /* @__PURE__ */ new Map();
|
|
2008
|
+
for (const r of view_model.reactions) {
|
|
2009
|
+
const trig_node = ns.find(
|
|
2007
2010
|
(n) => n.type === "event" && n.label === r.event
|
|
2008
2011
|
);
|
|
2009
|
-
const baseY =
|
|
2010
|
-
const rY =
|
|
2011
|
-
const rX =
|
|
2012
|
+
const baseY = trig_node ? trig_node.pos.y : globalY;
|
|
2013
|
+
const rY = reaction_y_by_event.get(r.event) ?? baseY;
|
|
2014
|
+
const rX = trig_node ? trig_node.pos.x + W + GAP * 3 : cx + W * 3 + GAP * 4;
|
|
2012
2015
|
const rp = { x: rX, y: rY };
|
|
2013
2016
|
ns.push({
|
|
2014
2017
|
key: `r:${r.handlerName}:standalone`,
|
|
@@ -2016,15 +2019,15 @@ function computeLayout(viewModel) {
|
|
|
2016
2019
|
type: "reaction",
|
|
2017
2020
|
label: r.handlerName
|
|
2018
2021
|
});
|
|
2019
|
-
if (
|
|
2022
|
+
if (trig_node) {
|
|
2020
2023
|
es.push({
|
|
2021
|
-
from: { x:
|
|
2024
|
+
from: { x: trig_node.pos.x + W, y: trig_node.pos.y + H / 2 },
|
|
2022
2025
|
to: { x: rp.x, y: rp.y + H / 2 },
|
|
2023
2026
|
color: COLORS.reaction.border,
|
|
2024
2027
|
dash: true
|
|
2025
2028
|
});
|
|
2026
2029
|
}
|
|
2027
|
-
|
|
2030
|
+
reaction_y_by_event.set(r.event, rY + H + GAP / 2);
|
|
2028
2031
|
globalY = Math.max(globalY, rY + H + GAP);
|
|
2029
2032
|
}
|
|
2030
2033
|
}
|
|
@@ -2088,10 +2091,10 @@ function splitLabel(label, maxChars = 16) {
|
|
|
2088
2091
|
function formatModelTree(model) {
|
|
2089
2092
|
const lines = [];
|
|
2090
2093
|
for (const entry of model.entries) {
|
|
2091
|
-
const
|
|
2094
|
+
const sorted_slices = [...entry.slices].sort(
|
|
2092
2095
|
(a, b) => a.name.localeCompare(b.name)
|
|
2093
2096
|
);
|
|
2094
|
-
for (const sl of
|
|
2097
|
+
for (const sl of sorted_slices) {
|
|
2095
2098
|
lines.push(`Slice: ${sl.name}`);
|
|
2096
2099
|
for (const stKey of sl.stateVars) {
|
|
2097
2100
|
const st = entry.states.find((s) => s.varName === stKey);
|
|
@@ -2113,9 +2116,9 @@ function formatModelTree(model) {
|
|
|
2113
2116
|
for (const p of entry.projections) {
|
|
2114
2117
|
lines.push(`Projection: ${p.name} [${p.handles.join(", ")}]`);
|
|
2115
2118
|
}
|
|
2116
|
-
const
|
|
2119
|
+
const slice_state_keys = new Set(entry.slices.flatMap((sl) => sl.stateVars));
|
|
2117
2120
|
for (const st of entry.states.filter(
|
|
2118
|
-
(s) => !
|
|
2121
|
+
(s) => !slice_state_keys.has(s.varName)
|
|
2119
2122
|
)) {
|
|
2120
2123
|
lines.push(`State: ${st.name}`);
|
|
2121
2124
|
for (const a of st.actions) {
|
|
@@ -2161,7 +2164,7 @@ function Diagram({
|
|
|
2161
2164
|
const [pan, setPan] = useState2({ x: 0, y: 0 });
|
|
2162
2165
|
const [zoom, setZoom] = useState2(1);
|
|
2163
2166
|
const entry = model.entries[activeTab];
|
|
2164
|
-
const
|
|
2167
|
+
const view_model = entry ? {
|
|
2165
2168
|
...model,
|
|
2166
2169
|
entries: [entry],
|
|
2167
2170
|
states: entry.states,
|
|
@@ -2240,7 +2243,7 @@ function Diagram({
|
|
|
2240
2243
|
const { ns, es, boxes, minX, minY, width, height, layoutError } = useMemo(() => {
|
|
2241
2244
|
try {
|
|
2242
2245
|
return {
|
|
2243
|
-
...
|
|
2246
|
+
...compute_layout(view_model),
|
|
2244
2247
|
layoutError: void 0
|
|
2245
2248
|
};
|
|
2246
2249
|
} catch (e) {
|
|
@@ -2256,7 +2259,7 @@ function Diagram({
|
|
|
2256
2259
|
layoutError: msg
|
|
2257
2260
|
};
|
|
2258
2261
|
}
|
|
2259
|
-
}, [
|
|
2262
|
+
}, [view_model]);
|
|
2260
2263
|
const fitTransform = useCallback(() => {
|
|
2261
2264
|
const el = svgContainerRef.current;
|
|
2262
2265
|
const cw = el?.clientWidth || 800;
|
|
@@ -2284,7 +2287,7 @@ function Diagram({
|
|
|
2284
2287
|
layoutError
|
|
2285
2288
|
] });
|
|
2286
2289
|
}
|
|
2287
|
-
if (
|
|
2290
|
+
if (view_model.states.length === 0 && view_model.projections.length === 0) {
|
|
2288
2291
|
return /* @__PURE__ */ jsx2("div", { className: "flex h-full items-center justify-center text-xs text-zinc-600", children: "Nothing to diagram here" });
|
|
2289
2292
|
}
|
|
2290
2293
|
return /* @__PURE__ */ jsxs2("div", { className: "relative flex h-full flex-col bg-zinc-950", children: [
|
|
@@ -2351,7 +2354,7 @@ function Diagram({
|
|
|
2351
2354
|
title: "@rotorsoft/act-diagram version",
|
|
2352
2355
|
children: [
|
|
2353
2356
|
"v",
|
|
2354
|
-
"0.
|
|
2357
|
+
"1.0.0"
|
|
2355
2358
|
]
|
|
2356
2359
|
}
|
|
2357
2360
|
)
|
|
@@ -2381,7 +2384,7 @@ function Diagram({
|
|
|
2381
2384
|
}
|
|
2382
2385
|
)
|
|
2383
2386
|
] }),
|
|
2384
|
-
/* @__PURE__ */ jsx2("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(
|
|
2387
|
+
/* @__PURE__ */ jsx2("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) })
|
|
2385
2388
|
] }),
|
|
2386
2389
|
showWarnings && warnings.length > 0 && /* @__PURE__ */ jsxs2("div", { className: "flex max-h-[30%] flex-col border-b border-zinc-800 bg-zinc-950", children: [
|
|
2387
2390
|
/* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between border-b border-zinc-800 bg-zinc-900 px-3 py-1", children: [
|
|
@@ -2905,7 +2908,7 @@ function useExtractModel(files) {
|
|
|
2905
2908
|
return;
|
|
2906
2909
|
}
|
|
2907
2910
|
const timer = setTimeout(() => {
|
|
2908
|
-
const { model, error } =
|
|
2911
|
+
const { model, error } = extract_model(files);
|
|
2909
2912
|
const warnings = validate(model);
|
|
2910
2913
|
const hasErrors = !!error || model.slices.some((s) => !!s.error);
|
|
2911
2914
|
if (!hasErrors) {
|
|
@@ -2966,7 +2969,7 @@ function ActDiagram({
|
|
|
2966
2969
|
const handleClick = useCallback2(
|
|
2967
2970
|
(name, type, file) => {
|
|
2968
2971
|
if (!onNavigate) return;
|
|
2969
|
-
const result =
|
|
2972
|
+
const result = navigate_to_code(files, name, type, file);
|
|
2970
2973
|
if (result) onNavigate(result.file, result.line, result.col, type);
|
|
2971
2974
|
},
|
|
2972
2975
|
[files, onNavigate]
|
|
@@ -3153,57 +3156,6 @@ function Tooltip({
|
|
|
3153
3156
|
);
|
|
3154
3157
|
}
|
|
3155
3158
|
|
|
3156
|
-
// src/client/lib/strip-fences.ts
|
|
3157
|
-
function parseMultiFileResponse(raw) {
|
|
3158
|
-
const files = [];
|
|
3159
|
-
const re = /```(?:typescript|ts):([^\n]+)\n([\s\S]*?)```/g;
|
|
3160
|
-
let m;
|
|
3161
|
-
while ((m = re.exec(raw)) !== null) {
|
|
3162
|
-
const path = m[1].trim();
|
|
3163
|
-
const content = m[2].trim();
|
|
3164
|
-
if (path && content) {
|
|
3165
|
-
files.push({ path, content });
|
|
3166
|
-
}
|
|
3167
|
-
}
|
|
3168
|
-
if (files.length === 0) {
|
|
3169
|
-
const code = stripFences(raw);
|
|
3170
|
-
if (code.trim()) {
|
|
3171
|
-
files.push({ path: "src/app.ts", content: code });
|
|
3172
|
-
}
|
|
3173
|
-
}
|
|
3174
|
-
return files;
|
|
3175
|
-
}
|
|
3176
|
-
function stripFences(code) {
|
|
3177
|
-
let result = code.replace(/```(?:typescript|ts)?\s*\n/g, "");
|
|
3178
|
-
result = result.replace(/\n?```\s*$/g, "");
|
|
3179
|
-
result = result.replace(
|
|
3180
|
-
/^[\s\S]*?(?=\/\*\*|\/\/|import\b|export\b|const\b|let\b|var\b|type\b|interface\b|function\b)/,
|
|
3181
|
-
""
|
|
3182
|
-
);
|
|
3183
|
-
const lines = result.split("\n");
|
|
3184
|
-
let lastCodeLine = lines.length - 1;
|
|
3185
|
-
while (lastCodeLine > 0) {
|
|
3186
|
-
const trimmed = lines[lastCodeLine].trim();
|
|
3187
|
-
if (trimmed && /[;{})\]:]$|^\s*\/\/|^\s*\*\/|^\s*\*|^$/.test(trimmed))
|
|
3188
|
-
break;
|
|
3189
|
-
lastCodeLine--;
|
|
3190
|
-
}
|
|
3191
|
-
if (lastCodeLine < lines.length - 1) {
|
|
3192
|
-
result = lines.slice(0, lastCodeLine + 1).join("\n");
|
|
3193
|
-
}
|
|
3194
|
-
return result.trim();
|
|
3195
|
-
}
|
|
3196
|
-
function deriveProjectName(prompt, code) {
|
|
3197
|
-
if (code) {
|
|
3198
|
-
const actMatch = code.match(/(?:const|let|var)\s+(\w+)\s*=\s*act\s*\(/);
|
|
3199
|
-
if (actMatch) return actMatch[1];
|
|
3200
|
-
const stateMatch = code.match(/state\(\s*\{\s*(\w+)/);
|
|
3201
|
-
if (stateMatch) return stateMatch[1] + " App";
|
|
3202
|
-
}
|
|
3203
|
-
const words = prompt.replace(/[^\w\s]/g, "").split(/\s+/).filter((w) => w.length > 2).slice(0, 3);
|
|
3204
|
-
return words.length > 0 ? words.map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(" ") : "Generated App";
|
|
3205
|
-
}
|
|
3206
|
-
|
|
3207
3159
|
// src/client/types/domain-model.ts
|
|
3208
3160
|
function emptyModel2() {
|
|
3209
3161
|
return {
|
|
@@ -3221,15 +3173,7 @@ export {
|
|
|
3221
3173
|
Diagram,
|
|
3222
3174
|
Logo,
|
|
3223
3175
|
Tooltip,
|
|
3224
|
-
buildModel,
|
|
3225
|
-
computeLayout,
|
|
3226
|
-
deriveProjectName,
|
|
3227
3176
|
emptyModel2 as emptyModel,
|
|
3228
|
-
extractModel,
|
|
3229
|
-
navigateToCode,
|
|
3230
|
-
parseMultiFileResponse,
|
|
3231
|
-
stripFences,
|
|
3232
|
-
topoSort,
|
|
3233
3177
|
validate
|
|
3234
3178
|
};
|
|
3235
3179
|
//# sourceMappingURL=index.js.map
|