@ts-model-checker/react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +1628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +1616 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +315 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1616 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { Handle, Position, ReactFlow, Background, Controls, MiniMap } from '@xyflow/react';
|
|
3
|
+
import { X, Plus, Trash2, Zap, Edit3, Play, Shield, Sparkles, AlertTriangle, SkipBack, ChevronLeft, Pause, ChevronRight, SkipForward, Repeat, Check, Copy, Download } from 'lucide-react';
|
|
4
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import { transpileToTla } from '@ts-model-checker/core';
|
|
6
|
+
import { runModelCheckAsync } from '@ts-model-checker/worker';
|
|
7
|
+
|
|
8
|
+
// src/components/FormalCanvas.tsx
|
|
9
|
+
var BINARY_OPERATORS = [
|
|
10
|
+
{ value: "==", label: "= (equals)" },
|
|
11
|
+
{ value: "!=", label: "\u2260 (not equals)" },
|
|
12
|
+
{ value: "<", label: "< (less than)" },
|
|
13
|
+
{ value: "<=", label: "\u2264 (less than or equal)" },
|
|
14
|
+
{ value: ">", label: "> (greater than)" },
|
|
15
|
+
{ value: ">=", label: "\u2265 (greater than or equal)" },
|
|
16
|
+
{ value: "&&", label: "AND (both true)" },
|
|
17
|
+
{ value: "||", label: "OR (at least one)" },
|
|
18
|
+
{ value: "=>", label: "\u21D2 (implies)" },
|
|
19
|
+
{ value: "+", label: "+ (add)" },
|
|
20
|
+
{ value: "-", label: "- (subtract)" },
|
|
21
|
+
{ value: "*", label: "* (multiply)" },
|
|
22
|
+
{ value: "/", label: "\xF7 (integer division)" },
|
|
23
|
+
{ value: "IN", label: "\u2208 (in set)" },
|
|
24
|
+
{ value: "NOT_IN", label: "\u2209 (not in set)" },
|
|
25
|
+
{ value: "UNION", label: "\u222A (set union)" }
|
|
26
|
+
];
|
|
27
|
+
var UNARY_OPERATORS = [
|
|
28
|
+
{ value: "!", label: "NOT (negation)" },
|
|
29
|
+
{ value: "-", label: "- (negate)" },
|
|
30
|
+
{ value: "CARDINALITY", label: "|S| (set size)" },
|
|
31
|
+
{ value: "IS_EMPTY", label: "S = \u2205 (is empty)" }
|
|
32
|
+
];
|
|
33
|
+
function parseLiteralInput(raw, typeHint) {
|
|
34
|
+
if (typeHint === "boolean") return raw === "true";
|
|
35
|
+
if (typeHint === "number") {
|
|
36
|
+
const n = Number(raw);
|
|
37
|
+
return Number.isNaN(n) ? 0 : n;
|
|
38
|
+
}
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
function ExprBuilder({
|
|
42
|
+
value,
|
|
43
|
+
variables,
|
|
44
|
+
onChange,
|
|
45
|
+
depth = 0
|
|
46
|
+
}) {
|
|
47
|
+
const firstVarName = variables[0]?.name ?? "x";
|
|
48
|
+
const handleKindChange = (nextKind) => {
|
|
49
|
+
switch (nextKind) {
|
|
50
|
+
case "Literal":
|
|
51
|
+
onChange({ kind: "Literal", value: 0 });
|
|
52
|
+
break;
|
|
53
|
+
case "Var":
|
|
54
|
+
onChange({ kind: "Var", name: firstVarName });
|
|
55
|
+
break;
|
|
56
|
+
case "BinaryOp":
|
|
57
|
+
onChange({
|
|
58
|
+
kind: "BinaryOp",
|
|
59
|
+
op: "==",
|
|
60
|
+
left: { kind: "Var", name: firstVarName },
|
|
61
|
+
right: { kind: "Literal", value: 0 }
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
case "UnaryOp":
|
|
65
|
+
onChange({
|
|
66
|
+
kind: "UnaryOp",
|
|
67
|
+
op: "!",
|
|
68
|
+
operand: { kind: "Literal", value: true }
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
case "Range":
|
|
72
|
+
onChange({
|
|
73
|
+
kind: "Range",
|
|
74
|
+
start: { kind: "Literal", value: 1 },
|
|
75
|
+
end: { kind: "Literal", value: 5 }
|
|
76
|
+
});
|
|
77
|
+
break;
|
|
78
|
+
case "IfThenElse":
|
|
79
|
+
onChange({
|
|
80
|
+
kind: "IfThenElse",
|
|
81
|
+
condition: { kind: "Literal", value: true },
|
|
82
|
+
thenBranch: { kind: "Literal", value: 1 },
|
|
83
|
+
elseBranch: { kind: "Literal", value: 0 }
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return /* @__PURE__ */ jsxs("div", { className: "tsmc-expr-box", style: { marginLeft: depth > 0 ? 8 : 0 }, children: [
|
|
89
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-expr-row", children: [
|
|
90
|
+
/* @__PURE__ */ jsxs(
|
|
91
|
+
"select",
|
|
92
|
+
{
|
|
93
|
+
className: "tsmc-select",
|
|
94
|
+
value: value.kind,
|
|
95
|
+
onChange: (e) => handleKindChange(e.target.value),
|
|
96
|
+
children: [
|
|
97
|
+
/* @__PURE__ */ jsx("option", { value: "BinaryOp", children: "Operation / Comparison" }),
|
|
98
|
+
/* @__PURE__ */ jsx("option", { value: "Var", children: "Variable" }),
|
|
99
|
+
/* @__PURE__ */ jsx("option", { value: "Literal", children: "Fixed Value" }),
|
|
100
|
+
/* @__PURE__ */ jsx("option", { value: "UnaryOp", children: "Negation / Unary" }),
|
|
101
|
+
/* @__PURE__ */ jsx("option", { value: "Range", children: "Range (a..b)" }),
|
|
102
|
+
/* @__PURE__ */ jsx("option", { value: "IfThenElse", children: "Conditional (If / Then / Else)" })
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
value.kind === "Literal" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
107
|
+
/* @__PURE__ */ jsxs(
|
|
108
|
+
"select",
|
|
109
|
+
{
|
|
110
|
+
className: "tsmc-select",
|
|
111
|
+
value: typeof value.value === "boolean" ? "boolean" : typeof value.value === "number" ? "number" : "string",
|
|
112
|
+
onChange: (e) => {
|
|
113
|
+
const t = e.target.value;
|
|
114
|
+
onChange({
|
|
115
|
+
kind: "Literal",
|
|
116
|
+
value: t === "boolean" ? true : t === "number" ? 0 : ""
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
children: [
|
|
120
|
+
/* @__PURE__ */ jsx("option", { value: "number", children: "Number" }),
|
|
121
|
+
/* @__PURE__ */ jsx("option", { value: "string", children: "String" }),
|
|
122
|
+
/* @__PURE__ */ jsx("option", { value: "boolean", children: "Boolean" })
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
typeof value.value === "boolean" ? /* @__PURE__ */ jsxs(
|
|
127
|
+
"select",
|
|
128
|
+
{
|
|
129
|
+
className: "tsmc-select",
|
|
130
|
+
value: String(value.value),
|
|
131
|
+
onChange: (e) => onChange({ kind: "Literal", value: e.target.value === "true" }),
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ jsx("option", { value: "true", children: "True (true)" }),
|
|
134
|
+
/* @__PURE__ */ jsx("option", { value: "false", children: "False (false)" })
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
) : /* @__PURE__ */ jsx(
|
|
138
|
+
"input",
|
|
139
|
+
{
|
|
140
|
+
className: "tsmc-input",
|
|
141
|
+
type: typeof value.value === "number" ? "number" : "text",
|
|
142
|
+
value: String(value.value ?? ""),
|
|
143
|
+
onChange: (e) => onChange({
|
|
144
|
+
kind: "Literal",
|
|
145
|
+
value: parseLiteralInput(
|
|
146
|
+
e.target.value,
|
|
147
|
+
typeof value.value === "number" ? "number" : "string"
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
] }),
|
|
153
|
+
value.kind === "Var" && /* @__PURE__ */ jsx(
|
|
154
|
+
"select",
|
|
155
|
+
{
|
|
156
|
+
className: "tsmc-select",
|
|
157
|
+
value: value.name,
|
|
158
|
+
onChange: (e) => onChange({ kind: "Var", name: e.target.value }),
|
|
159
|
+
children: variables.map((v) => /* @__PURE__ */ jsxs("option", { value: v.name, children: [
|
|
160
|
+
v.name,
|
|
161
|
+
" (",
|
|
162
|
+
v.type,
|
|
163
|
+
")"
|
|
164
|
+
] }, v.name))
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
value.kind === "UnaryOp" && /* @__PURE__ */ jsx(
|
|
168
|
+
"select",
|
|
169
|
+
{
|
|
170
|
+
className: "tsmc-select",
|
|
171
|
+
value: value.op,
|
|
172
|
+
onChange: (e) => onChange({ ...value, op: e.target.value }),
|
|
173
|
+
children: UNARY_OPERATORS.map((op) => /* @__PURE__ */ jsx("option", { value: op.value, children: op.label }, op.value))
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
value.kind === "BinaryOp" && /* @__PURE__ */ jsx(
|
|
177
|
+
"select",
|
|
178
|
+
{
|
|
179
|
+
className: "tsmc-select",
|
|
180
|
+
value: value.op,
|
|
181
|
+
onChange: (e) => onChange({ ...value, op: e.target.value }),
|
|
182
|
+
children: BINARY_OPERATORS.map((op) => /* @__PURE__ */ jsx("option", { value: op.value, children: op.label }, op.value))
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
] }),
|
|
186
|
+
value.kind === "UnaryOp" && /* @__PURE__ */ jsx(
|
|
187
|
+
ExprBuilder,
|
|
188
|
+
{
|
|
189
|
+
value: value.operand,
|
|
190
|
+
variables,
|
|
191
|
+
onChange: (operand) => onChange({ ...value, operand }),
|
|
192
|
+
depth: depth + 1
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
value.kind === "BinaryOp" && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: [
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
ExprBuilder,
|
|
198
|
+
{
|
|
199
|
+
value: value.left,
|
|
200
|
+
variables,
|
|
201
|
+
onChange: (left) => onChange({ ...value, left }),
|
|
202
|
+
depth: depth + 1
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
/* @__PURE__ */ jsx(
|
|
206
|
+
ExprBuilder,
|
|
207
|
+
{
|
|
208
|
+
value: value.right,
|
|
209
|
+
variables,
|
|
210
|
+
onChange: (right) => onChange({ ...value, right }),
|
|
211
|
+
depth: depth + 1
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
] }),
|
|
215
|
+
value.kind === "Range" && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: [
|
|
216
|
+
/* @__PURE__ */ jsx(
|
|
217
|
+
ExprBuilder,
|
|
218
|
+
{
|
|
219
|
+
value: value.start,
|
|
220
|
+
variables,
|
|
221
|
+
onChange: (start) => onChange({ ...value, start }),
|
|
222
|
+
depth: depth + 1
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
/* @__PURE__ */ jsx(
|
|
226
|
+
ExprBuilder,
|
|
227
|
+
{
|
|
228
|
+
value: value.end,
|
|
229
|
+
variables,
|
|
230
|
+
onChange: (end) => onChange({ ...value, end }),
|
|
231
|
+
depth: depth + 1
|
|
232
|
+
}
|
|
233
|
+
)
|
|
234
|
+
] }),
|
|
235
|
+
value.kind === "IfThenElse" && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: [
|
|
236
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "If:" }),
|
|
237
|
+
/* @__PURE__ */ jsx(
|
|
238
|
+
ExprBuilder,
|
|
239
|
+
{
|
|
240
|
+
value: value.condition,
|
|
241
|
+
variables,
|
|
242
|
+
onChange: (condition) => onChange({ ...value, condition }),
|
|
243
|
+
depth: depth + 1
|
|
244
|
+
}
|
|
245
|
+
),
|
|
246
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "Then:" }),
|
|
247
|
+
/* @__PURE__ */ jsx(
|
|
248
|
+
ExprBuilder,
|
|
249
|
+
{
|
|
250
|
+
value: value.thenBranch,
|
|
251
|
+
variables,
|
|
252
|
+
onChange: (thenBranch) => onChange({ ...value, thenBranch }),
|
|
253
|
+
depth: depth + 1
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "Else:" }),
|
|
257
|
+
/* @__PURE__ */ jsx(
|
|
258
|
+
ExprBuilder,
|
|
259
|
+
{
|
|
260
|
+
value: value.elseBranch,
|
|
261
|
+
variables,
|
|
262
|
+
onChange: (elseBranch) => onChange({ ...value, elseBranch }),
|
|
263
|
+
depth: depth + 1
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
] })
|
|
267
|
+
] });
|
|
268
|
+
}
|
|
269
|
+
function ActionEditorModal({
|
|
270
|
+
action,
|
|
271
|
+
variables,
|
|
272
|
+
onSave,
|
|
273
|
+
onDelete,
|
|
274
|
+
onClose
|
|
275
|
+
}) {
|
|
276
|
+
const [draft, setDraft] = useState(action);
|
|
277
|
+
const handleAddEffect = () => {
|
|
278
|
+
const unusedVar = variables.find((v) => !draft.effects.some((e) => e.targetVar === v.name))?.name ?? variables[0]?.name ?? "x";
|
|
279
|
+
const nextEffect = {
|
|
280
|
+
targetVar: unusedVar,
|
|
281
|
+
expression: { kind: "Literal", value: 0 }
|
|
282
|
+
};
|
|
283
|
+
setDraft({ ...draft, effects: [...draft.effects, nextEffect] });
|
|
284
|
+
};
|
|
285
|
+
const handleRemoveEffect = (index) => {
|
|
286
|
+
setDraft({
|
|
287
|
+
...draft,
|
|
288
|
+
effects: draft.effects.filter((_, idx) => idx !== index)
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
return /* @__PURE__ */ jsx("div", { className: "tsmc-modal-backdrop", onClick: onClose, children: /* @__PURE__ */ jsxs("div", { className: "tsmc-modal", onClick: (e) => e.stopPropagation(), children: [
|
|
292
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-header", children: [
|
|
293
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
294
|
+
"Edit Action: ",
|
|
295
|
+
draft.name
|
|
296
|
+
] }),
|
|
297
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: onClose, children: /* @__PURE__ */ jsx(X, { size: 14 }) })
|
|
298
|
+
] }),
|
|
299
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-body", children: [
|
|
300
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }, children: [
|
|
301
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
|
|
302
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "Action Name" }),
|
|
303
|
+
/* @__PURE__ */ jsx(
|
|
304
|
+
"input",
|
|
305
|
+
{
|
|
306
|
+
className: "tsmc-input",
|
|
307
|
+
value: draft.name,
|
|
308
|
+
onChange: (e) => setDraft({ ...draft, name: e.target.value })
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
] }),
|
|
312
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
|
|
313
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "Description (Optional)" }),
|
|
314
|
+
/* @__PURE__ */ jsx(
|
|
315
|
+
"input",
|
|
316
|
+
{
|
|
317
|
+
className: "tsmc-input",
|
|
318
|
+
value: draft.description ?? "",
|
|
319
|
+
onChange: (e) => setDraft({ ...draft, description: e.target.value })
|
|
320
|
+
}
|
|
321
|
+
)
|
|
322
|
+
] })
|
|
323
|
+
] }),
|
|
324
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
325
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "When it can run (Guard)" }),
|
|
326
|
+
/* @__PURE__ */ jsx(
|
|
327
|
+
ExprBuilder,
|
|
328
|
+
{
|
|
329
|
+
value: draft.guard,
|
|
330
|
+
variables,
|
|
331
|
+
onChange: (guard) => setDraft({ ...draft, guard })
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
] }),
|
|
335
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
336
|
+
/* @__PURE__ */ jsxs(
|
|
337
|
+
"div",
|
|
338
|
+
{
|
|
339
|
+
style: {
|
|
340
|
+
display: "flex",
|
|
341
|
+
justifyContent: "space-between",
|
|
342
|
+
alignItems: "center",
|
|
343
|
+
marginBottom: 6
|
|
344
|
+
},
|
|
345
|
+
children: [
|
|
346
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "Next-state changes (Effects)" }),
|
|
347
|
+
/* @__PURE__ */ jsxs(
|
|
348
|
+
"button",
|
|
349
|
+
{
|
|
350
|
+
type: "button",
|
|
351
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
352
|
+
onClick: handleAddEffect,
|
|
353
|
+
disabled: variables.length === 0,
|
|
354
|
+
children: [
|
|
355
|
+
/* @__PURE__ */ jsx(Plus, { size: 12 }),
|
|
356
|
+
" Add Effect"
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
draft.effects.length === 0 ? /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--tsmc-text-muted)" }, children: "No effects defined \u2014 all variables remain UNCHANGED." }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 10 }, children: draft.effects.map((eff, idx) => /* @__PURE__ */ jsxs(
|
|
364
|
+
"div",
|
|
365
|
+
{
|
|
366
|
+
style: {
|
|
367
|
+
border: "1px solid var(--tsmc-border)",
|
|
368
|
+
borderRadius: 8,
|
|
369
|
+
padding: 10,
|
|
370
|
+
display: "flex",
|
|
371
|
+
flexDirection: "column",
|
|
372
|
+
gap: 8
|
|
373
|
+
},
|
|
374
|
+
children: [
|
|
375
|
+
/* @__PURE__ */ jsxs(
|
|
376
|
+
"div",
|
|
377
|
+
{
|
|
378
|
+
style: {
|
|
379
|
+
display: "flex",
|
|
380
|
+
justifyContent: "space-between",
|
|
381
|
+
alignItems: "center",
|
|
382
|
+
gap: 8
|
|
383
|
+
},
|
|
384
|
+
children: [
|
|
385
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
|
|
386
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: 13 }, children: "Next value of:" }),
|
|
387
|
+
/* @__PURE__ */ jsx(
|
|
388
|
+
"select",
|
|
389
|
+
{
|
|
390
|
+
className: "tsmc-select",
|
|
391
|
+
value: eff.targetVar,
|
|
392
|
+
onChange: (e) => {
|
|
393
|
+
const updated = [...draft.effects];
|
|
394
|
+
updated[idx] = { ...eff, targetVar: e.target.value };
|
|
395
|
+
setDraft({ ...draft, effects: updated });
|
|
396
|
+
},
|
|
397
|
+
children: variables.map((v) => /* @__PURE__ */ jsxs("option", { value: v.name, children: [
|
|
398
|
+
v.name,
|
|
399
|
+
"'"
|
|
400
|
+
] }, v.name))
|
|
401
|
+
}
|
|
402
|
+
)
|
|
403
|
+
] }),
|
|
404
|
+
/* @__PURE__ */ jsx(
|
|
405
|
+
"button",
|
|
406
|
+
{
|
|
407
|
+
type: "button",
|
|
408
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-danger",
|
|
409
|
+
onClick: () => handleRemoveEffect(idx),
|
|
410
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 12 })
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
/* @__PURE__ */ jsx(
|
|
417
|
+
ExprBuilder,
|
|
418
|
+
{
|
|
419
|
+
value: eff.expression,
|
|
420
|
+
variables,
|
|
421
|
+
onChange: (expression) => {
|
|
422
|
+
const updated = [...draft.effects];
|
|
423
|
+
updated[idx] = { ...eff, expression };
|
|
424
|
+
setDraft({ ...draft, effects: updated });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
)
|
|
428
|
+
]
|
|
429
|
+
},
|
|
430
|
+
idx
|
|
431
|
+
)) })
|
|
432
|
+
] })
|
|
433
|
+
] }),
|
|
434
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-footer", style: { justifyContent: "space-between" }, children: [
|
|
435
|
+
/* @__PURE__ */ jsx("div", { children: onDelete && /* @__PURE__ */ jsxs(
|
|
436
|
+
"button",
|
|
437
|
+
{
|
|
438
|
+
type: "button",
|
|
439
|
+
className: "tsmc-btn tsmc-btn-danger",
|
|
440
|
+
onClick: () => {
|
|
441
|
+
onDelete(draft.id);
|
|
442
|
+
onClose();
|
|
443
|
+
},
|
|
444
|
+
children: [
|
|
445
|
+
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
446
|
+
" Delete Action"
|
|
447
|
+
]
|
|
448
|
+
}
|
|
449
|
+
) }),
|
|
450
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
451
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn", onClick: onClose, children: "Cancel" }),
|
|
452
|
+
/* @__PURE__ */ jsx(
|
|
453
|
+
"button",
|
|
454
|
+
{
|
|
455
|
+
type: "button",
|
|
456
|
+
className: "tsmc-btn tsmc-btn-primary",
|
|
457
|
+
onClick: () => {
|
|
458
|
+
onSave(draft);
|
|
459
|
+
onClose();
|
|
460
|
+
},
|
|
461
|
+
children: "Save Changes"
|
|
462
|
+
}
|
|
463
|
+
)
|
|
464
|
+
] })
|
|
465
|
+
] })
|
|
466
|
+
] }) });
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// src/utils/formatExpr.ts
|
|
470
|
+
var OP_LABELS = {
|
|
471
|
+
"==": "=",
|
|
472
|
+
"!=": "\u2260",
|
|
473
|
+
"&&": "AND",
|
|
474
|
+
"||": "OR",
|
|
475
|
+
"=>": "\u21D2",
|
|
476
|
+
IN: "\u2208",
|
|
477
|
+
NOT_IN: "\u2209",
|
|
478
|
+
UNION: "\u222A",
|
|
479
|
+
INTERSECT: "\u2229",
|
|
480
|
+
DIFF: "\u2216",
|
|
481
|
+
SUBSET_EQ: "\u2286"
|
|
482
|
+
};
|
|
483
|
+
function formatExpr(node) {
|
|
484
|
+
switch (node.kind) {
|
|
485
|
+
case "Literal":
|
|
486
|
+
return typeof node.value === "string" ? `"${node.value}"` : String(node.value);
|
|
487
|
+
case "Var":
|
|
488
|
+
return node.name;
|
|
489
|
+
case "SetLiteral":
|
|
490
|
+
return `{${node.elements.map(formatExpr).join(", ")}}`;
|
|
491
|
+
case "RecordLiteral":
|
|
492
|
+
return `{ ${Object.entries(node.fields).map(([k, v]) => `${k}: ${formatExpr(v)}`).join(", ")} }`;
|
|
493
|
+
case "FieldAccess":
|
|
494
|
+
return `${formatExpr(node.target)}.${node.field}`;
|
|
495
|
+
case "Range":
|
|
496
|
+
return `${formatExpr(node.start)}..${formatExpr(node.end)}`;
|
|
497
|
+
case "UnaryOp":
|
|
498
|
+
if (node.op === "!") return `NOT (${formatExpr(node.operand)})`;
|
|
499
|
+
if (node.op === "CARDINALITY") return `|${formatExpr(node.operand)}|`;
|
|
500
|
+
if (node.op === "IS_EMPTY") return `${formatExpr(node.operand)} = \u2205`;
|
|
501
|
+
return `-${formatExpr(node.operand)}`;
|
|
502
|
+
case "BinaryOp": {
|
|
503
|
+
const op = OP_LABELS[node.op] ?? node.op;
|
|
504
|
+
return `(${formatExpr(node.left)} ${op} ${formatExpr(node.right)})`;
|
|
505
|
+
}
|
|
506
|
+
case "IfThenElse":
|
|
507
|
+
return `IF ${formatExpr(node.condition)} THEN ${formatExpr(node.thenBranch)} ELSE ${formatExpr(node.elseBranch)}`;
|
|
508
|
+
case "Quantifier": {
|
|
509
|
+
const q = node.quantifier === "FORALL" ? "\u2200" : "\u2203";
|
|
510
|
+
return `${q} ${node.boundVar} \u2208 ${formatExpr(node.domain)}: ${formatExpr(node.predicate)}`;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function ActionNode({ data }) {
|
|
515
|
+
const { action, isActive, isViolated, onEdit } = data;
|
|
516
|
+
const stateClass = isViolated ? "tsmc-node-violated" : isActive ? "tsmc-node-active" : "";
|
|
517
|
+
return /* @__PURE__ */ jsxs("div", { className: `tsmc-node ${stateClass}`, children: [
|
|
518
|
+
/* @__PURE__ */ jsx(Handle, { type: "target", position: Position.Top }),
|
|
519
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-node-header", children: [
|
|
520
|
+
/* @__PURE__ */ jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 }, children: [
|
|
521
|
+
/* @__PURE__ */ jsx(Zap, { size: 14, color: "#2563eb" }),
|
|
522
|
+
" ",
|
|
523
|
+
action.name
|
|
524
|
+
] }),
|
|
525
|
+
onEdit && /* @__PURE__ */ jsx(
|
|
526
|
+
"button",
|
|
527
|
+
{
|
|
528
|
+
type: "button",
|
|
529
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
530
|
+
onClick: () => onEdit(action.id),
|
|
531
|
+
title: "Edit action",
|
|
532
|
+
children: /* @__PURE__ */ jsx(Edit3, { size: 12 })
|
|
533
|
+
}
|
|
534
|
+
)
|
|
535
|
+
] }),
|
|
536
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-node-body", children: [
|
|
537
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
538
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "When (Guard)" }),
|
|
539
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-code-chip", children: formatExpr(action.guard) })
|
|
540
|
+
] }),
|
|
541
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
542
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-section-label", children: "Then (Effects)" }),
|
|
543
|
+
action.effects.length === 0 ? /* @__PURE__ */ jsx("div", { className: "tsmc-code-chip", style: { color: "var(--tsmc-text-muted)" }, children: "UNCHANGED (No changes)" }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: action.effects.map((eff) => /* @__PURE__ */ jsxs("div", { className: "tsmc-code-chip", children: [
|
|
544
|
+
/* @__PURE__ */ jsxs("strong", { children: [
|
|
545
|
+
eff.targetVar,
|
|
546
|
+
"'"
|
|
547
|
+
] }),
|
|
548
|
+
" = ",
|
|
549
|
+
formatExpr(eff.expression)
|
|
550
|
+
] }, eff.targetVar)) })
|
|
551
|
+
] })
|
|
552
|
+
] }),
|
|
553
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", position: Position.Bottom })
|
|
554
|
+
] });
|
|
555
|
+
}
|
|
556
|
+
function defaultForType(type) {
|
|
557
|
+
switch (type) {
|
|
558
|
+
case "number":
|
|
559
|
+
return 0;
|
|
560
|
+
case "boolean":
|
|
561
|
+
return false;
|
|
562
|
+
case "string":
|
|
563
|
+
return "IDLE";
|
|
564
|
+
case "set":
|
|
565
|
+
return [];
|
|
566
|
+
case "record":
|
|
567
|
+
return {};
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function parseValue(raw, type) {
|
|
571
|
+
if (type === "number") {
|
|
572
|
+
const n = Number(raw);
|
|
573
|
+
return Number.isNaN(n) ? 0 : n;
|
|
574
|
+
}
|
|
575
|
+
if (type === "boolean") {
|
|
576
|
+
return raw === "true";
|
|
577
|
+
}
|
|
578
|
+
if (type === "set" || type === "record") {
|
|
579
|
+
try {
|
|
580
|
+
return JSON.parse(raw);
|
|
581
|
+
} catch {
|
|
582
|
+
return defaultForType(type);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return raw;
|
|
586
|
+
}
|
|
587
|
+
function InitEditorModal({
|
|
588
|
+
variables,
|
|
589
|
+
initialState,
|
|
590
|
+
onSave,
|
|
591
|
+
onClose
|
|
592
|
+
}) {
|
|
593
|
+
const [vars, setVars] = useState([...variables]);
|
|
594
|
+
const [stateDraft, setStateDraft] = useState({
|
|
595
|
+
...initialState
|
|
596
|
+
});
|
|
597
|
+
const handleAddVar = () => {
|
|
598
|
+
let idx = vars.length + 1;
|
|
599
|
+
let name = `var${idx}`;
|
|
600
|
+
while (vars.some((v) => v.name === name)) {
|
|
601
|
+
idx += 1;
|
|
602
|
+
name = `var${idx}`;
|
|
603
|
+
}
|
|
604
|
+
setVars([...vars, { name, type: "number" }]);
|
|
605
|
+
setStateDraft({ ...stateDraft, [name]: 0 });
|
|
606
|
+
};
|
|
607
|
+
const handleRenameVar = (index, nextName) => {
|
|
608
|
+
const oldName = vars[index].name;
|
|
609
|
+
const updated = [...vars];
|
|
610
|
+
updated[index] = { ...vars[index], name: nextName };
|
|
611
|
+
setVars(updated);
|
|
612
|
+
if (oldName !== nextName) {
|
|
613
|
+
const nextState = { ...stateDraft };
|
|
614
|
+
nextState[nextName] = nextState[oldName] ?? defaultForType(vars[index].type);
|
|
615
|
+
delete nextState[oldName];
|
|
616
|
+
setStateDraft(nextState);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
const handleTypeChange = (index, nextType) => {
|
|
620
|
+
const v = vars[index];
|
|
621
|
+
const updated = [...vars];
|
|
622
|
+
updated[index] = { ...v, type: nextType };
|
|
623
|
+
setVars(updated);
|
|
624
|
+
setStateDraft({ ...stateDraft, [v.name]: defaultForType(nextType) });
|
|
625
|
+
};
|
|
626
|
+
const handleRemoveVar = (index) => {
|
|
627
|
+
const name = vars[index].name;
|
|
628
|
+
setVars(vars.filter((_, i) => i !== index));
|
|
629
|
+
const nextState = { ...stateDraft };
|
|
630
|
+
delete nextState[name];
|
|
631
|
+
setStateDraft(nextState);
|
|
632
|
+
};
|
|
633
|
+
return /* @__PURE__ */ jsx("div", { className: "tsmc-modal-backdrop", onClick: onClose, children: /* @__PURE__ */ jsxs("div", { className: "tsmc-modal", onClick: (e) => e.stopPropagation(), children: [
|
|
634
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-header", children: [
|
|
635
|
+
/* @__PURE__ */ jsx("span", { children: "Configure Variables & Initial State (Init)" }),
|
|
636
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: onClose, children: /* @__PURE__ */ jsx(X, { size: 14 }) })
|
|
637
|
+
] }),
|
|
638
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-body", children: [
|
|
639
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
640
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: 13, color: "var(--tsmc-text-muted)" }, children: "Define the system state variables and their initial values." }),
|
|
641
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: handleAddVar, children: [
|
|
642
|
+
/* @__PURE__ */ jsx(Plus, { size: 12 }),
|
|
643
|
+
" New Variable"
|
|
644
|
+
] })
|
|
645
|
+
] }),
|
|
646
|
+
vars.map((v, idx) => /* @__PURE__ */ jsxs(
|
|
647
|
+
"div",
|
|
648
|
+
{
|
|
649
|
+
style: {
|
|
650
|
+
display: "grid",
|
|
651
|
+
gridTemplateColumns: "1fr 120px 1fr auto",
|
|
652
|
+
gap: 8,
|
|
653
|
+
alignItems: "center"
|
|
654
|
+
},
|
|
655
|
+
children: [
|
|
656
|
+
/* @__PURE__ */ jsx(
|
|
657
|
+
"input",
|
|
658
|
+
{
|
|
659
|
+
className: "tsmc-input",
|
|
660
|
+
value: v.name,
|
|
661
|
+
placeholder: "Name",
|
|
662
|
+
onChange: (e) => handleRenameVar(idx, e.target.value)
|
|
663
|
+
}
|
|
664
|
+
),
|
|
665
|
+
/* @__PURE__ */ jsxs(
|
|
666
|
+
"select",
|
|
667
|
+
{
|
|
668
|
+
className: "tsmc-select",
|
|
669
|
+
value: v.type,
|
|
670
|
+
onChange: (e) => handleTypeChange(idx, e.target.value),
|
|
671
|
+
children: [
|
|
672
|
+
/* @__PURE__ */ jsx("option", { value: "number", children: "Number" }),
|
|
673
|
+
/* @__PURE__ */ jsx("option", { value: "string", children: "String" }),
|
|
674
|
+
/* @__PURE__ */ jsx("option", { value: "boolean", children: "Boolean" }),
|
|
675
|
+
/* @__PURE__ */ jsx("option", { value: "set", children: "Set" }),
|
|
676
|
+
/* @__PURE__ */ jsx("option", { value: "record", children: "Record" })
|
|
677
|
+
]
|
|
678
|
+
}
|
|
679
|
+
),
|
|
680
|
+
v.type === "boolean" ? /* @__PURE__ */ jsxs(
|
|
681
|
+
"select",
|
|
682
|
+
{
|
|
683
|
+
className: "tsmc-select",
|
|
684
|
+
value: String(Boolean(stateDraft[v.name])),
|
|
685
|
+
onChange: (e) => setStateDraft({
|
|
686
|
+
...stateDraft,
|
|
687
|
+
[v.name]: e.target.value === "true"
|
|
688
|
+
}),
|
|
689
|
+
children: [
|
|
690
|
+
/* @__PURE__ */ jsx("option", { value: "true", children: "true" }),
|
|
691
|
+
/* @__PURE__ */ jsx("option", { value: "false", children: "false" })
|
|
692
|
+
]
|
|
693
|
+
}
|
|
694
|
+
) : /* @__PURE__ */ jsx(
|
|
695
|
+
"input",
|
|
696
|
+
{
|
|
697
|
+
className: "tsmc-input",
|
|
698
|
+
type: v.type === "number" ? "number" : "text",
|
|
699
|
+
value: typeof stateDraft[v.name] === "object" ? JSON.stringify(stateDraft[v.name]) : String(stateDraft[v.name] ?? ""),
|
|
700
|
+
onChange: (e) => setStateDraft({
|
|
701
|
+
...stateDraft,
|
|
702
|
+
[v.name]: parseValue(e.target.value, v.type)
|
|
703
|
+
})
|
|
704
|
+
}
|
|
705
|
+
),
|
|
706
|
+
/* @__PURE__ */ jsx(
|
|
707
|
+
"button",
|
|
708
|
+
{
|
|
709
|
+
type: "button",
|
|
710
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-danger",
|
|
711
|
+
onClick: () => handleRemoveVar(idx),
|
|
712
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 12 })
|
|
713
|
+
}
|
|
714
|
+
)
|
|
715
|
+
]
|
|
716
|
+
},
|
|
717
|
+
idx
|
|
718
|
+
))
|
|
719
|
+
] }),
|
|
720
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-footer", children: [
|
|
721
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn", onClick: onClose, children: "Cancel" }),
|
|
722
|
+
/* @__PURE__ */ jsx(
|
|
723
|
+
"button",
|
|
724
|
+
{
|
|
725
|
+
type: "button",
|
|
726
|
+
className: "tsmc-btn tsmc-btn-primary",
|
|
727
|
+
onClick: () => {
|
|
728
|
+
onSave(vars, stateDraft);
|
|
729
|
+
onClose();
|
|
730
|
+
},
|
|
731
|
+
children: "Save Initial State"
|
|
732
|
+
}
|
|
733
|
+
)
|
|
734
|
+
] })
|
|
735
|
+
] }) });
|
|
736
|
+
}
|
|
737
|
+
function InitNode({ data }) {
|
|
738
|
+
const { variables, initialState, isActive, onEdit } = data;
|
|
739
|
+
return /* @__PURE__ */ jsxs("div", { className: `tsmc-node tsmc-node-init ${isActive ? "tsmc-node-active" : ""}`, children: [
|
|
740
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-node-header", children: [
|
|
741
|
+
/* @__PURE__ */ jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 }, children: [
|
|
742
|
+
/* @__PURE__ */ jsx(Play, { size: 14 }),
|
|
743
|
+
" Initial State (Init)"
|
|
744
|
+
] }),
|
|
745
|
+
onEdit && /* @__PURE__ */ jsx(
|
|
746
|
+
"button",
|
|
747
|
+
{
|
|
748
|
+
type: "button",
|
|
749
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
750
|
+
onClick: onEdit,
|
|
751
|
+
title: "Edit initial variables",
|
|
752
|
+
children: /* @__PURE__ */ jsx(Edit3, { size: 12 })
|
|
753
|
+
}
|
|
754
|
+
)
|
|
755
|
+
] }),
|
|
756
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-node-body", children: variables.length === 0 ? /* @__PURE__ */ jsx("span", { style: { color: "var(--tsmc-text-muted)" }, children: "No variables defined" }) : variables.map((v) => /* @__PURE__ */ jsxs("div", { className: "tsmc-var-row", children: [
|
|
757
|
+
/* @__PURE__ */ jsx("strong", { children: v.name }),
|
|
758
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
759
|
+
"= ",
|
|
760
|
+
JSON.stringify(initialState[v.name])
|
|
761
|
+
] })
|
|
762
|
+
] }, v.name)) }),
|
|
763
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", position: Position.Bottom })
|
|
764
|
+
] });
|
|
765
|
+
}
|
|
766
|
+
var nodeTypes = {
|
|
767
|
+
initNode: InitNode,
|
|
768
|
+
actionNode: ActionNode
|
|
769
|
+
};
|
|
770
|
+
function FormalCanvas({
|
|
771
|
+
spec,
|
|
772
|
+
onChange,
|
|
773
|
+
activeActionName = null,
|
|
774
|
+
isViolationStep = false,
|
|
775
|
+
readOnly = false
|
|
776
|
+
}) {
|
|
777
|
+
const [editingActionId, setEditingActionId] = useState(null);
|
|
778
|
+
const [editingInit, setEditingInit] = useState(false);
|
|
779
|
+
const editingAction = useMemo(
|
|
780
|
+
() => spec.actions.find((a) => a.id === editingActionId) ?? null,
|
|
781
|
+
[spec.actions, editingActionId]
|
|
782
|
+
);
|
|
783
|
+
const nodes = useMemo(() => {
|
|
784
|
+
const initNode = {
|
|
785
|
+
id: "__init__",
|
|
786
|
+
type: "initNode",
|
|
787
|
+
position: { x: 230, y: 20 },
|
|
788
|
+
data: {
|
|
789
|
+
variables: spec.variables,
|
|
790
|
+
initialState: spec.initialStates[0] ?? {},
|
|
791
|
+
isActive: activeActionName === "Init",
|
|
792
|
+
onEdit: readOnly ? void 0 : () => setEditingInit(true)
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const actionNodes = spec.actions.map((act, idx) => ({
|
|
796
|
+
id: act.id,
|
|
797
|
+
type: "actionNode",
|
|
798
|
+
position: act.position ?? {
|
|
799
|
+
x: 60 + idx % 2 * 320,
|
|
800
|
+
y: 200 + Math.floor(idx / 2) * 180
|
|
801
|
+
},
|
|
802
|
+
data: {
|
|
803
|
+
action: act,
|
|
804
|
+
isActive: activeActionName === act.name && !isViolationStep,
|
|
805
|
+
isViolated: activeActionName === act.name && isViolationStep,
|
|
806
|
+
onEdit: readOnly ? void 0 : (id) => setEditingActionId(id)
|
|
807
|
+
}
|
|
808
|
+
}));
|
|
809
|
+
return [initNode, ...actionNodes];
|
|
810
|
+
}, [spec, activeActionName, isViolationStep, readOnly]);
|
|
811
|
+
const edges = useMemo(
|
|
812
|
+
() => spec.actions.map((act) => ({
|
|
813
|
+
id: `edge_init_${act.id}`,
|
|
814
|
+
source: "__init__",
|
|
815
|
+
target: act.id,
|
|
816
|
+
animated: activeActionName === act.name,
|
|
817
|
+
style: {
|
|
818
|
+
stroke: activeActionName === act.name ? "#2563eb" : "#94a3b8",
|
|
819
|
+
strokeWidth: activeActionName === act.name ? 2.5 : 1.5
|
|
820
|
+
}
|
|
821
|
+
})),
|
|
822
|
+
[spec.actions, activeActionName]
|
|
823
|
+
);
|
|
824
|
+
const handleNodesChange = useCallback(
|
|
825
|
+
(changes) => {
|
|
826
|
+
if (readOnly) return;
|
|
827
|
+
const positionUpdates = /* @__PURE__ */ new Map();
|
|
828
|
+
for (const ch of changes) {
|
|
829
|
+
if (ch.type === "position" && ch.position && ch.id !== "__init__") {
|
|
830
|
+
positionUpdates.set(ch.id, ch.position);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (positionUpdates.size === 0) return;
|
|
834
|
+
onChange({
|
|
835
|
+
...spec,
|
|
836
|
+
actions: spec.actions.map((act) => {
|
|
837
|
+
const pos = positionUpdates.get(act.id);
|
|
838
|
+
return pos ? { ...act, position: pos } : act;
|
|
839
|
+
})
|
|
840
|
+
});
|
|
841
|
+
},
|
|
842
|
+
[spec, onChange, readOnly]
|
|
843
|
+
);
|
|
844
|
+
const handleAddAction = () => {
|
|
845
|
+
const idx = spec.actions.length + 1;
|
|
846
|
+
const newAction = {
|
|
847
|
+
id: `act_${Date.now()}`,
|
|
848
|
+
name: `Action_${idx}`,
|
|
849
|
+
guard: { kind: "Literal", value: true },
|
|
850
|
+
effects: [],
|
|
851
|
+
position: {
|
|
852
|
+
x: 60 + (idx - 1) % 2 * 320,
|
|
853
|
+
y: 200 + Math.floor((idx - 1) / 2) * 180
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
onChange({ ...spec, actions: [...spec.actions, newAction] });
|
|
857
|
+
setEditingActionId(newAction.id);
|
|
858
|
+
};
|
|
859
|
+
const handleSaveAction = (updated) => {
|
|
860
|
+
onChange({
|
|
861
|
+
...spec,
|
|
862
|
+
actions: spec.actions.map((a) => a.id === updated.id ? updated : a)
|
|
863
|
+
});
|
|
864
|
+
};
|
|
865
|
+
const handleDeleteAction = (actionId) => {
|
|
866
|
+
onChange({
|
|
867
|
+
...spec,
|
|
868
|
+
actions: spec.actions.filter((a) => a.id !== actionId)
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
const handleSaveInit = (variables, initialState) => {
|
|
872
|
+
onChange({
|
|
873
|
+
...spec,
|
|
874
|
+
variables,
|
|
875
|
+
initialStates: [initialState, ...spec.initialStates.slice(1)]
|
|
876
|
+
});
|
|
877
|
+
};
|
|
878
|
+
return /* @__PURE__ */ jsxs("div", { className: "tsmc-canvas-wrapper", children: [
|
|
879
|
+
!readOnly && /* @__PURE__ */ jsx("div", { className: "tsmc-toolbar", children: /* @__PURE__ */ jsxs(
|
|
880
|
+
"button",
|
|
881
|
+
{
|
|
882
|
+
type: "button",
|
|
883
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-primary",
|
|
884
|
+
onClick: handleAddAction,
|
|
885
|
+
children: [
|
|
886
|
+
/* @__PURE__ */ jsx(Plus, { size: 14 }),
|
|
887
|
+
" New Action"
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
) }),
|
|
891
|
+
/* @__PURE__ */ jsxs(
|
|
892
|
+
ReactFlow,
|
|
893
|
+
{
|
|
894
|
+
nodes,
|
|
895
|
+
edges,
|
|
896
|
+
nodeTypes,
|
|
897
|
+
onNodesChange: handleNodesChange,
|
|
898
|
+
fitView: true,
|
|
899
|
+
nodesConnectable: false,
|
|
900
|
+
children: [
|
|
901
|
+
/* @__PURE__ */ jsx(Background, { gap: 16, size: 1 }),
|
|
902
|
+
/* @__PURE__ */ jsx(Controls, {}),
|
|
903
|
+
/* @__PURE__ */ jsx(MiniMap, { zoomable: true, pannable: true })
|
|
904
|
+
]
|
|
905
|
+
}
|
|
906
|
+
),
|
|
907
|
+
editingAction && /* @__PURE__ */ jsx(
|
|
908
|
+
ActionEditorModal,
|
|
909
|
+
{
|
|
910
|
+
action: editingAction,
|
|
911
|
+
variables: spec.variables,
|
|
912
|
+
onSave: handleSaveAction,
|
|
913
|
+
onDelete: handleDeleteAction,
|
|
914
|
+
onClose: () => setEditingActionId(null)
|
|
915
|
+
}
|
|
916
|
+
),
|
|
917
|
+
editingInit && /* @__PURE__ */ jsx(
|
|
918
|
+
InitEditorModal,
|
|
919
|
+
{
|
|
920
|
+
variables: spec.variables,
|
|
921
|
+
initialState: spec.initialStates[0] ?? {},
|
|
922
|
+
onSave: handleSaveInit,
|
|
923
|
+
onClose: () => setEditingInit(false)
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
] });
|
|
927
|
+
}
|
|
928
|
+
function PropertiesPanel({ spec, onChange }) {
|
|
929
|
+
const [editingInvId, setEditingInvId] = useState(null);
|
|
930
|
+
const [editingLiveId, setEditingLiveId] = useState(null);
|
|
931
|
+
const firstVar = spec.variables[0]?.name ?? "x";
|
|
932
|
+
const addInvariant = () => {
|
|
933
|
+
const id = `inv_${Date.now()}`;
|
|
934
|
+
const newInv = {
|
|
935
|
+
id,
|
|
936
|
+
description: `Ensure property holds on ${firstVar}`,
|
|
937
|
+
predicate: {
|
|
938
|
+
kind: "BinaryOp",
|
|
939
|
+
op: ">=",
|
|
940
|
+
left: { kind: "Var", name: firstVar },
|
|
941
|
+
right: { kind: "Literal", value: 0 }
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
onChange({ ...spec, invariants: [...spec.invariants, newInv] });
|
|
945
|
+
setEditingInvId(id);
|
|
946
|
+
};
|
|
947
|
+
const addLiveness = (kind) => {
|
|
948
|
+
const id = `live_${Date.now()}`;
|
|
949
|
+
const newLive = kind === "EVENTUALLY" ? {
|
|
950
|
+
id,
|
|
951
|
+
kind: "EVENTUALLY",
|
|
952
|
+
description: `Eventually ${firstVar} satisfies condition`,
|
|
953
|
+
eventually: {
|
|
954
|
+
kind: "BinaryOp",
|
|
955
|
+
op: "==",
|
|
956
|
+
left: { kind: "Var", name: firstVar },
|
|
957
|
+
right: { kind: "Literal", value: 0 }
|
|
958
|
+
}
|
|
959
|
+
} : {
|
|
960
|
+
id,
|
|
961
|
+
kind: "LEADS_TO",
|
|
962
|
+
description: `Whenever condition P holds, Q eventually holds`,
|
|
963
|
+
trigger: { kind: "Literal", value: true },
|
|
964
|
+
response: { kind: "Literal", value: true }
|
|
965
|
+
};
|
|
966
|
+
onChange({
|
|
967
|
+
...spec,
|
|
968
|
+
livenessProperties: [...spec.livenessProperties, newLive]
|
|
969
|
+
});
|
|
970
|
+
setEditingLiveId(id);
|
|
971
|
+
};
|
|
972
|
+
return /* @__PURE__ */ jsxs("div", { className: "tsmc-panel", children: [
|
|
973
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
974
|
+
/* @__PURE__ */ jsxs(
|
|
975
|
+
"div",
|
|
976
|
+
{
|
|
977
|
+
style: {
|
|
978
|
+
display: "flex",
|
|
979
|
+
justifyContent: "space-between",
|
|
980
|
+
alignItems: "center",
|
|
981
|
+
marginBottom: 8
|
|
982
|
+
},
|
|
983
|
+
children: [
|
|
984
|
+
/* @__PURE__ */ jsxs(
|
|
985
|
+
"span",
|
|
986
|
+
{
|
|
987
|
+
style: {
|
|
988
|
+
display: "inline-flex",
|
|
989
|
+
alignItems: "center",
|
|
990
|
+
gap: 6,
|
|
991
|
+
fontWeight: 600,
|
|
992
|
+
fontSize: 13
|
|
993
|
+
},
|
|
994
|
+
children: [
|
|
995
|
+
/* @__PURE__ */ jsx(Shield, { size: 15, color: "#2563eb" }),
|
|
996
|
+
" Safety Invariants (\u25A1P)"
|
|
997
|
+
]
|
|
998
|
+
}
|
|
999
|
+
),
|
|
1000
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: addInvariant, children: [
|
|
1001
|
+
/* @__PURE__ */ jsx(Plus, { size: 12 }),
|
|
1002
|
+
" Add"
|
|
1003
|
+
] })
|
|
1004
|
+
]
|
|
1005
|
+
}
|
|
1006
|
+
),
|
|
1007
|
+
spec.invariants.length === 0 ? /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--tsmc-text-muted)" }, children: "No invariants defined. Add rules that must hold in every reachable state." }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: spec.invariants.map((inv) => {
|
|
1008
|
+
const isEditing = editingInvId === inv.id;
|
|
1009
|
+
return /* @__PURE__ */ jsxs(
|
|
1010
|
+
"div",
|
|
1011
|
+
{
|
|
1012
|
+
style: {
|
|
1013
|
+
border: "1px solid var(--tsmc-border)",
|
|
1014
|
+
borderRadius: 8,
|
|
1015
|
+
padding: 8,
|
|
1016
|
+
display: "flex",
|
|
1017
|
+
flexDirection: "column",
|
|
1018
|
+
gap: 6
|
|
1019
|
+
},
|
|
1020
|
+
children: [
|
|
1021
|
+
/* @__PURE__ */ jsxs(
|
|
1022
|
+
"div",
|
|
1023
|
+
{
|
|
1024
|
+
style: {
|
|
1025
|
+
display: "flex",
|
|
1026
|
+
justifyContent: "space-between",
|
|
1027
|
+
alignItems: "center",
|
|
1028
|
+
gap: 6
|
|
1029
|
+
},
|
|
1030
|
+
children: [
|
|
1031
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: 12 }, children: inv.description }),
|
|
1032
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 4 }, children: [
|
|
1033
|
+
/* @__PURE__ */ jsx(
|
|
1034
|
+
"button",
|
|
1035
|
+
{
|
|
1036
|
+
type: "button",
|
|
1037
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1038
|
+
onClick: () => setEditingInvId(isEditing ? null : inv.id),
|
|
1039
|
+
children: isEditing ? "Close" : "Edit"
|
|
1040
|
+
}
|
|
1041
|
+
),
|
|
1042
|
+
/* @__PURE__ */ jsx(
|
|
1043
|
+
"button",
|
|
1044
|
+
{
|
|
1045
|
+
type: "button",
|
|
1046
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-danger",
|
|
1047
|
+
onClick: () => onChange({
|
|
1048
|
+
...spec,
|
|
1049
|
+
invariants: spec.invariants.filter(
|
|
1050
|
+
(i) => i.id !== inv.id
|
|
1051
|
+
)
|
|
1052
|
+
}),
|
|
1053
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 12 })
|
|
1054
|
+
}
|
|
1055
|
+
)
|
|
1056
|
+
] })
|
|
1057
|
+
]
|
|
1058
|
+
}
|
|
1059
|
+
),
|
|
1060
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-code-chip", children: formatExpr(inv.predicate) }),
|
|
1061
|
+
isEditing && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6, marginTop: 4 }, children: [
|
|
1062
|
+
/* @__PURE__ */ jsx(
|
|
1063
|
+
"input",
|
|
1064
|
+
{
|
|
1065
|
+
className: "tsmc-input",
|
|
1066
|
+
value: inv.description,
|
|
1067
|
+
onChange: (e) => onChange({
|
|
1068
|
+
...spec,
|
|
1069
|
+
invariants: spec.invariants.map(
|
|
1070
|
+
(i) => i.id === inv.id ? { ...i, description: e.target.value } : i
|
|
1071
|
+
)
|
|
1072
|
+
})
|
|
1073
|
+
}
|
|
1074
|
+
),
|
|
1075
|
+
/* @__PURE__ */ jsx(
|
|
1076
|
+
ExprBuilder,
|
|
1077
|
+
{
|
|
1078
|
+
value: inv.predicate,
|
|
1079
|
+
variables: spec.variables,
|
|
1080
|
+
onChange: (predicate) => onChange({
|
|
1081
|
+
...spec,
|
|
1082
|
+
invariants: spec.invariants.map(
|
|
1083
|
+
(i) => i.id === inv.id ? { ...i, predicate } : i
|
|
1084
|
+
)
|
|
1085
|
+
})
|
|
1086
|
+
}
|
|
1087
|
+
)
|
|
1088
|
+
] })
|
|
1089
|
+
]
|
|
1090
|
+
},
|
|
1091
|
+
inv.id
|
|
1092
|
+
);
|
|
1093
|
+
}) })
|
|
1094
|
+
] }),
|
|
1095
|
+
/* @__PURE__ */ jsxs("div", { style: { borderTop: "1px solid var(--tsmc-border)", paddingTop: 10 }, children: [
|
|
1096
|
+
/* @__PURE__ */ jsxs(
|
|
1097
|
+
"div",
|
|
1098
|
+
{
|
|
1099
|
+
style: {
|
|
1100
|
+
display: "flex",
|
|
1101
|
+
justifyContent: "space-between",
|
|
1102
|
+
alignItems: "center",
|
|
1103
|
+
marginBottom: 8,
|
|
1104
|
+
gap: 6,
|
|
1105
|
+
flexWrap: "wrap"
|
|
1106
|
+
},
|
|
1107
|
+
children: [
|
|
1108
|
+
/* @__PURE__ */ jsxs(
|
|
1109
|
+
"span",
|
|
1110
|
+
{
|
|
1111
|
+
style: {
|
|
1112
|
+
display: "inline-flex",
|
|
1113
|
+
alignItems: "center",
|
|
1114
|
+
gap: 6,
|
|
1115
|
+
fontWeight: 600,
|
|
1116
|
+
fontSize: 13
|
|
1117
|
+
},
|
|
1118
|
+
children: [
|
|
1119
|
+
/* @__PURE__ */ jsx(Sparkles, { size: 15, color: "#7c3aed" }),
|
|
1120
|
+
" Temporal Properties (Liveness)"
|
|
1121
|
+
]
|
|
1122
|
+
}
|
|
1123
|
+
),
|
|
1124
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 4 }, children: [
|
|
1125
|
+
/* @__PURE__ */ jsx(
|
|
1126
|
+
"button",
|
|
1127
|
+
{
|
|
1128
|
+
type: "button",
|
|
1129
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1130
|
+
onClick: () => addLiveness("EVENTUALLY"),
|
|
1131
|
+
children: "+ \u25C7 Eventually"
|
|
1132
|
+
}
|
|
1133
|
+
),
|
|
1134
|
+
/* @__PURE__ */ jsx(
|
|
1135
|
+
"button",
|
|
1136
|
+
{
|
|
1137
|
+
type: "button",
|
|
1138
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1139
|
+
onClick: () => addLiveness("LEADS_TO"),
|
|
1140
|
+
children: "+ P \u21DD Q"
|
|
1141
|
+
}
|
|
1142
|
+
)
|
|
1143
|
+
] })
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
spec.livenessProperties.length === 0 ? /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--tsmc-text-muted)" }, children: "No liveness properties configured." }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: spec.livenessProperties.map((live) => {
|
|
1148
|
+
const isEditing = editingLiveId === live.id;
|
|
1149
|
+
return /* @__PURE__ */ jsxs(
|
|
1150
|
+
"div",
|
|
1151
|
+
{
|
|
1152
|
+
style: {
|
|
1153
|
+
border: "1px solid var(--tsmc-border)",
|
|
1154
|
+
borderRadius: 8,
|
|
1155
|
+
padding: 8,
|
|
1156
|
+
display: "flex",
|
|
1157
|
+
flexDirection: "column",
|
|
1158
|
+
gap: 6
|
|
1159
|
+
},
|
|
1160
|
+
children: [
|
|
1161
|
+
/* @__PURE__ */ jsxs(
|
|
1162
|
+
"div",
|
|
1163
|
+
{
|
|
1164
|
+
style: {
|
|
1165
|
+
display: "flex",
|
|
1166
|
+
justifyContent: "space-between",
|
|
1167
|
+
alignItems: "center",
|
|
1168
|
+
gap: 6
|
|
1169
|
+
},
|
|
1170
|
+
children: [
|
|
1171
|
+
/* @__PURE__ */ jsxs("strong", { style: { fontSize: 12 }, children: [
|
|
1172
|
+
"[",
|
|
1173
|
+
live.kind === "EVENTUALLY" ? "\u25C7" : "\u21DD",
|
|
1174
|
+
"] ",
|
|
1175
|
+
live.description
|
|
1176
|
+
] }),
|
|
1177
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 4 }, children: [
|
|
1178
|
+
/* @__PURE__ */ jsx(
|
|
1179
|
+
"button",
|
|
1180
|
+
{
|
|
1181
|
+
type: "button",
|
|
1182
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1183
|
+
onClick: () => setEditingLiveId(isEditing ? null : live.id),
|
|
1184
|
+
children: isEditing ? "Close" : "Edit"
|
|
1185
|
+
}
|
|
1186
|
+
),
|
|
1187
|
+
/* @__PURE__ */ jsx(
|
|
1188
|
+
"button",
|
|
1189
|
+
{
|
|
1190
|
+
type: "button",
|
|
1191
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-danger",
|
|
1192
|
+
onClick: () => onChange({
|
|
1193
|
+
...spec,
|
|
1194
|
+
livenessProperties: spec.livenessProperties.filter(
|
|
1195
|
+
(l) => l.id !== live.id
|
|
1196
|
+
)
|
|
1197
|
+
}),
|
|
1198
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 12 })
|
|
1199
|
+
}
|
|
1200
|
+
)
|
|
1201
|
+
] })
|
|
1202
|
+
]
|
|
1203
|
+
}
|
|
1204
|
+
),
|
|
1205
|
+
/* @__PURE__ */ jsx("div", { className: "tsmc-code-chip", children: live.kind === "EVENTUALLY" ? `\u25C7 (${formatExpr(live.eventually)})` : `(${formatExpr(live.trigger)}) \u21DD (${formatExpr(live.response)})` }),
|
|
1206
|
+
isEditing && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6, marginTop: 4 }, children: [
|
|
1207
|
+
/* @__PURE__ */ jsx(
|
|
1208
|
+
"input",
|
|
1209
|
+
{
|
|
1210
|
+
className: "tsmc-input",
|
|
1211
|
+
value: live.description,
|
|
1212
|
+
onChange: (e) => onChange({
|
|
1213
|
+
...spec,
|
|
1214
|
+
livenessProperties: spec.livenessProperties.map(
|
|
1215
|
+
(l) => l.id === live.id ? { ...l, description: e.target.value } : l
|
|
1216
|
+
)
|
|
1217
|
+
})
|
|
1218
|
+
}
|
|
1219
|
+
),
|
|
1220
|
+
live.kind === "EVENTUALLY" ? /* @__PURE__ */ jsx(
|
|
1221
|
+
ExprBuilder,
|
|
1222
|
+
{
|
|
1223
|
+
value: live.eventually,
|
|
1224
|
+
variables: spec.variables,
|
|
1225
|
+
onChange: (eventually) => onChange({
|
|
1226
|
+
...spec,
|
|
1227
|
+
livenessProperties: spec.livenessProperties.map(
|
|
1228
|
+
(l) => l.id === live.id && l.kind === "EVENTUALLY" ? { ...l, eventually } : l
|
|
1229
|
+
)
|
|
1230
|
+
})
|
|
1231
|
+
}
|
|
1232
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1233
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "When (P):" }),
|
|
1234
|
+
/* @__PURE__ */ jsx(
|
|
1235
|
+
ExprBuilder,
|
|
1236
|
+
{
|
|
1237
|
+
value: live.trigger,
|
|
1238
|
+
variables: spec.variables,
|
|
1239
|
+
onChange: (trigger) => onChange({
|
|
1240
|
+
...spec,
|
|
1241
|
+
livenessProperties: spec.livenessProperties.map(
|
|
1242
|
+
(l) => l.id === live.id && l.kind === "LEADS_TO" ? { ...l, trigger } : l
|
|
1243
|
+
)
|
|
1244
|
+
})
|
|
1245
|
+
}
|
|
1246
|
+
),
|
|
1247
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "Eventually (Q):" }),
|
|
1248
|
+
/* @__PURE__ */ jsx(
|
|
1249
|
+
ExprBuilder,
|
|
1250
|
+
{
|
|
1251
|
+
value: live.response,
|
|
1252
|
+
variables: spec.variables,
|
|
1253
|
+
onChange: (response) => onChange({
|
|
1254
|
+
...spec,
|
|
1255
|
+
livenessProperties: spec.livenessProperties.map(
|
|
1256
|
+
(l) => l.id === live.id && l.kind === "LEADS_TO" ? { ...l, response } : l
|
|
1257
|
+
)
|
|
1258
|
+
})
|
|
1259
|
+
}
|
|
1260
|
+
)
|
|
1261
|
+
] })
|
|
1262
|
+
] })
|
|
1263
|
+
]
|
|
1264
|
+
},
|
|
1265
|
+
live.id
|
|
1266
|
+
);
|
|
1267
|
+
}) })
|
|
1268
|
+
] })
|
|
1269
|
+
] });
|
|
1270
|
+
}
|
|
1271
|
+
function TracePlayer({
|
|
1272
|
+
title,
|
|
1273
|
+
steps,
|
|
1274
|
+
cycleStartIndex,
|
|
1275
|
+
activeStepIndex,
|
|
1276
|
+
onStepChange
|
|
1277
|
+
}) {
|
|
1278
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
1279
|
+
useEffect(() => {
|
|
1280
|
+
if (!isPlaying || steps.length === 0) return;
|
|
1281
|
+
const timer = setInterval(() => {
|
|
1282
|
+
onStepChange(
|
|
1283
|
+
activeStepIndex + 1 >= steps.length ? cycleStartIndex ?? 0 : activeStepIndex + 1
|
|
1284
|
+
);
|
|
1285
|
+
}, 900);
|
|
1286
|
+
return () => clearInterval(timer);
|
|
1287
|
+
}, [isPlaying, activeStepIndex, steps.length, cycleStartIndex, onStepChange]);
|
|
1288
|
+
if (steps.length === 0) return null;
|
|
1289
|
+
const clampedIndex = Math.min(Math.max(0, activeStepIndex), steps.length - 1);
|
|
1290
|
+
const currentStep = steps[clampedIndex];
|
|
1291
|
+
const prevStep = clampedIndex > 0 ? steps[clampedIndex - 1] : null;
|
|
1292
|
+
const varNames = Object.keys(currentStep.state).sort();
|
|
1293
|
+
return /* @__PURE__ */ jsxs("div", { className: "tsmc-panel", children: [
|
|
1294
|
+
/* @__PURE__ */ jsxs(
|
|
1295
|
+
"div",
|
|
1296
|
+
{
|
|
1297
|
+
style: {
|
|
1298
|
+
display: "flex",
|
|
1299
|
+
justifyContent: "space-between",
|
|
1300
|
+
alignItems: "center",
|
|
1301
|
+
gap: 8,
|
|
1302
|
+
flexWrap: "wrap"
|
|
1303
|
+
},
|
|
1304
|
+
children: [
|
|
1305
|
+
/* @__PURE__ */ jsxs(
|
|
1306
|
+
"span",
|
|
1307
|
+
{
|
|
1308
|
+
className: "tsmc-badge tsmc-badge-danger",
|
|
1309
|
+
style: { fontSize: 12, padding: "4px 10px" },
|
|
1310
|
+
children: [
|
|
1311
|
+
/* @__PURE__ */ jsx(AlertTriangle, { size: 14 }),
|
|
1312
|
+
" ",
|
|
1313
|
+
title
|
|
1314
|
+
]
|
|
1315
|
+
}
|
|
1316
|
+
),
|
|
1317
|
+
/* @__PURE__ */ jsxs("span", { style: { fontSize: 12, color: "var(--tsmc-text-muted)" }, children: [
|
|
1318
|
+
"Step ",
|
|
1319
|
+
clampedIndex + 1,
|
|
1320
|
+
" of ",
|
|
1321
|
+
steps.length
|
|
1322
|
+
] })
|
|
1323
|
+
]
|
|
1324
|
+
}
|
|
1325
|
+
),
|
|
1326
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6, flexWrap: "wrap" }, children: [
|
|
1327
|
+
/* @__PURE__ */ jsx(
|
|
1328
|
+
"button",
|
|
1329
|
+
{
|
|
1330
|
+
type: "button",
|
|
1331
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1332
|
+
onClick: () => {
|
|
1333
|
+
setIsPlaying(false);
|
|
1334
|
+
onStepChange(0);
|
|
1335
|
+
},
|
|
1336
|
+
disabled: clampedIndex === 0,
|
|
1337
|
+
title: "Start",
|
|
1338
|
+
children: /* @__PURE__ */ jsx(SkipBack, { size: 14 })
|
|
1339
|
+
}
|
|
1340
|
+
),
|
|
1341
|
+
/* @__PURE__ */ jsx(
|
|
1342
|
+
"button",
|
|
1343
|
+
{
|
|
1344
|
+
type: "button",
|
|
1345
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1346
|
+
onClick: () => {
|
|
1347
|
+
setIsPlaying(false);
|
|
1348
|
+
onStepChange(Math.max(0, clampedIndex - 1));
|
|
1349
|
+
},
|
|
1350
|
+
disabled: clampedIndex === 0,
|
|
1351
|
+
title: "Previous Step",
|
|
1352
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { size: 14 })
|
|
1353
|
+
}
|
|
1354
|
+
),
|
|
1355
|
+
/* @__PURE__ */ jsxs(
|
|
1356
|
+
"button",
|
|
1357
|
+
{
|
|
1358
|
+
type: "button",
|
|
1359
|
+
className: "tsmc-btn tsmc-btn-sm tsmc-btn-primary",
|
|
1360
|
+
onClick: () => setIsPlaying((p) => !p),
|
|
1361
|
+
children: [
|
|
1362
|
+
isPlaying ? /* @__PURE__ */ jsx(Pause, { size: 14 }) : /* @__PURE__ */ jsx(Play, { size: 14 }),
|
|
1363
|
+
isPlaying ? "Pause" : "Play"
|
|
1364
|
+
]
|
|
1365
|
+
}
|
|
1366
|
+
),
|
|
1367
|
+
/* @__PURE__ */ jsx(
|
|
1368
|
+
"button",
|
|
1369
|
+
{
|
|
1370
|
+
type: "button",
|
|
1371
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1372
|
+
onClick: () => {
|
|
1373
|
+
setIsPlaying(false);
|
|
1374
|
+
onStepChange(Math.min(steps.length - 1, clampedIndex + 1));
|
|
1375
|
+
},
|
|
1376
|
+
disabled: clampedIndex === steps.length - 1,
|
|
1377
|
+
title: "Next Step",
|
|
1378
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { size: 14 })
|
|
1379
|
+
}
|
|
1380
|
+
),
|
|
1381
|
+
/* @__PURE__ */ jsx(
|
|
1382
|
+
"button",
|
|
1383
|
+
{
|
|
1384
|
+
type: "button",
|
|
1385
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1386
|
+
onClick: () => {
|
|
1387
|
+
setIsPlaying(false);
|
|
1388
|
+
onStepChange(steps.length - 1);
|
|
1389
|
+
},
|
|
1390
|
+
disabled: clampedIndex === steps.length - 1,
|
|
1391
|
+
title: "Last Step",
|
|
1392
|
+
children: /* @__PURE__ */ jsx(SkipForward, { size: 14 })
|
|
1393
|
+
}
|
|
1394
|
+
)
|
|
1395
|
+
] }),
|
|
1396
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", gap: 6, flexWrap: "wrap" }, children: steps.map((s, idx) => {
|
|
1397
|
+
const inCycle = cycleStartIndex !== void 0 && idx >= cycleStartIndex;
|
|
1398
|
+
const isCurrent = idx === clampedIndex;
|
|
1399
|
+
return /* @__PURE__ */ jsxs(
|
|
1400
|
+
"button",
|
|
1401
|
+
{
|
|
1402
|
+
type: "button",
|
|
1403
|
+
className: `tsmc-btn tsmc-btn-sm ${isCurrent ? "tsmc-btn-primary" : ""}`,
|
|
1404
|
+
onClick: () => {
|
|
1405
|
+
setIsPlaying(false);
|
|
1406
|
+
onStepChange(idx);
|
|
1407
|
+
},
|
|
1408
|
+
children: [
|
|
1409
|
+
inCycle && /* @__PURE__ */ jsx(Repeat, { size: 11 }),
|
|
1410
|
+
idx,
|
|
1411
|
+
". ",
|
|
1412
|
+
s.actionName
|
|
1413
|
+
]
|
|
1414
|
+
},
|
|
1415
|
+
idx
|
|
1416
|
+
);
|
|
1417
|
+
}) }),
|
|
1418
|
+
/* @__PURE__ */ jsxs("table", { className: "tsmc-diff-table", children: [
|
|
1419
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
1420
|
+
/* @__PURE__ */ jsx("th", { children: "Variable" }),
|
|
1421
|
+
/* @__PURE__ */ jsx("th", { children: "Previous" }),
|
|
1422
|
+
/* @__PURE__ */ jsxs("th", { children: [
|
|
1423
|
+
"Current (",
|
|
1424
|
+
currentStep.actionName,
|
|
1425
|
+
")"
|
|
1426
|
+
] })
|
|
1427
|
+
] }) }),
|
|
1428
|
+
/* @__PURE__ */ jsx("tbody", { children: varNames.map((v) => {
|
|
1429
|
+
const prevVal = prevStep ? prevStep.state[v] : void 0;
|
|
1430
|
+
const currVal = currentStep.state[v];
|
|
1431
|
+
const changed = prevStep !== null && JSON.stringify(prevVal) !== JSON.stringify(currVal);
|
|
1432
|
+
return /* @__PURE__ */ jsxs("tr", { className: changed ? "tsmc-diff-changed" : "", children: [
|
|
1433
|
+
/* @__PURE__ */ jsx("td", { children: v }),
|
|
1434
|
+
/* @__PURE__ */ jsx("td", { style: { color: "var(--tsmc-text-muted)" }, children: prevStep ? JSON.stringify(prevVal) : "\u2014" }),
|
|
1435
|
+
/* @__PURE__ */ jsx("td", { children: JSON.stringify(currVal) })
|
|
1436
|
+
] }, v);
|
|
1437
|
+
}) })
|
|
1438
|
+
] })
|
|
1439
|
+
] });
|
|
1440
|
+
}
|
|
1441
|
+
function TlaExportModal({ spec, onClose }) {
|
|
1442
|
+
const [activeTab, setActiveTab] = useState("tla");
|
|
1443
|
+
const [copied, setCopied] = useState(false);
|
|
1444
|
+
const output = useMemo(() => {
|
|
1445
|
+
try {
|
|
1446
|
+
return { ok: true, files: transpileToTla(spec) };
|
|
1447
|
+
} catch (err) {
|
|
1448
|
+
return {
|
|
1449
|
+
ok: false,
|
|
1450
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
}, [spec]);
|
|
1454
|
+
const content = output.ok ? activeTab === "tla" ? output.files.tlaFileContent : output.files.cfgFileContent : output.error;
|
|
1455
|
+
const handleCopy = async () => {
|
|
1456
|
+
await navigator.clipboard.writeText(content);
|
|
1457
|
+
setCopied(true);
|
|
1458
|
+
setTimeout(() => setCopied(false), 1500);
|
|
1459
|
+
};
|
|
1460
|
+
const handleDownload = (filename, text) => {
|
|
1461
|
+
const blob = new Blob([text], { type: "text/plain;charset=utf-8" });
|
|
1462
|
+
const url = URL.createObjectURL(blob);
|
|
1463
|
+
const a = document.createElement("a");
|
|
1464
|
+
a.href = url;
|
|
1465
|
+
a.download = filename;
|
|
1466
|
+
a.click();
|
|
1467
|
+
URL.revokeObjectURL(url);
|
|
1468
|
+
};
|
|
1469
|
+
return /* @__PURE__ */ jsx("div", { className: "tsmc-modal-backdrop", onClick: onClose, children: /* @__PURE__ */ jsxs("div", { className: "tsmc-modal", onClick: (e) => e.stopPropagation(), children: [
|
|
1470
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-header", children: [
|
|
1471
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1472
|
+
"Export TLA+ Specification (",
|
|
1473
|
+
spec.moduleName,
|
|
1474
|
+
")"
|
|
1475
|
+
] }),
|
|
1476
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: onClose, children: /* @__PURE__ */ jsx(X, { size: 14 }) })
|
|
1477
|
+
] }),
|
|
1478
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-body", children: [
|
|
1479
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
|
|
1480
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6 }, children: [
|
|
1481
|
+
/* @__PURE__ */ jsxs(
|
|
1482
|
+
"button",
|
|
1483
|
+
{
|
|
1484
|
+
type: "button",
|
|
1485
|
+
className: `tsmc-btn tsmc-btn-sm ${activeTab === "tla" ? "tsmc-btn-primary" : ""}`,
|
|
1486
|
+
onClick: () => setActiveTab("tla"),
|
|
1487
|
+
children: [
|
|
1488
|
+
spec.moduleName,
|
|
1489
|
+
".tla"
|
|
1490
|
+
]
|
|
1491
|
+
}
|
|
1492
|
+
),
|
|
1493
|
+
/* @__PURE__ */ jsxs(
|
|
1494
|
+
"button",
|
|
1495
|
+
{
|
|
1496
|
+
type: "button",
|
|
1497
|
+
className: `tsmc-btn tsmc-btn-sm ${activeTab === "cfg" ? "tsmc-btn-primary" : ""}`,
|
|
1498
|
+
onClick: () => setActiveTab("cfg"),
|
|
1499
|
+
children: [
|
|
1500
|
+
spec.moduleName,
|
|
1501
|
+
".cfg"
|
|
1502
|
+
]
|
|
1503
|
+
}
|
|
1504
|
+
)
|
|
1505
|
+
] }),
|
|
1506
|
+
output.ok && /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6 }, children: [
|
|
1507
|
+
/* @__PURE__ */ jsxs(
|
|
1508
|
+
"button",
|
|
1509
|
+
{
|
|
1510
|
+
type: "button",
|
|
1511
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1512
|
+
onClick: handleCopy,
|
|
1513
|
+
children: [
|
|
1514
|
+
copied ? /* @__PURE__ */ jsx(Check, { size: 12 }) : /* @__PURE__ */ jsx(Copy, { size: 12 }),
|
|
1515
|
+
copied ? "Copied" : "Copy"
|
|
1516
|
+
]
|
|
1517
|
+
}
|
|
1518
|
+
),
|
|
1519
|
+
/* @__PURE__ */ jsxs(
|
|
1520
|
+
"button",
|
|
1521
|
+
{
|
|
1522
|
+
type: "button",
|
|
1523
|
+
className: "tsmc-btn tsmc-btn-sm",
|
|
1524
|
+
onClick: () => handleDownload(
|
|
1525
|
+
activeTab === "tla" ? `${spec.moduleName}.tla` : `${spec.moduleName}.cfg`,
|
|
1526
|
+
content
|
|
1527
|
+
),
|
|
1528
|
+
children: [
|
|
1529
|
+
/* @__PURE__ */ jsx(Download, { size: 12 }),
|
|
1530
|
+
" Download"
|
|
1531
|
+
]
|
|
1532
|
+
}
|
|
1533
|
+
)
|
|
1534
|
+
] })
|
|
1535
|
+
] }),
|
|
1536
|
+
/* @__PURE__ */ jsx(
|
|
1537
|
+
"pre",
|
|
1538
|
+
{
|
|
1539
|
+
style: {
|
|
1540
|
+
margin: 0,
|
|
1541
|
+
padding: 12,
|
|
1542
|
+
borderRadius: 8,
|
|
1543
|
+
background: "#0f172a",
|
|
1544
|
+
color: "#e2e8f0",
|
|
1545
|
+
fontFamily: "var(--tsmc-mono)",
|
|
1546
|
+
fontSize: 12,
|
|
1547
|
+
overflow: "auto",
|
|
1548
|
+
maxHeight: 420
|
|
1549
|
+
},
|
|
1550
|
+
children: content
|
|
1551
|
+
}
|
|
1552
|
+
)
|
|
1553
|
+
] })
|
|
1554
|
+
] }) });
|
|
1555
|
+
}
|
|
1556
|
+
function useModelChecker(defaultCreateWorker) {
|
|
1557
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
1558
|
+
const [progress, setProgress] = useState(null);
|
|
1559
|
+
const [result, setResult] = useState(null);
|
|
1560
|
+
const [error, setError] = useState(null);
|
|
1561
|
+
const abortRef = useRef(null);
|
|
1562
|
+
const cancel = useCallback(() => {
|
|
1563
|
+
abortRef.current?.abort();
|
|
1564
|
+
abortRef.current = null;
|
|
1565
|
+
setIsRunning(false);
|
|
1566
|
+
}, []);
|
|
1567
|
+
const reset = useCallback(() => {
|
|
1568
|
+
cancel();
|
|
1569
|
+
setProgress(null);
|
|
1570
|
+
setResult(null);
|
|
1571
|
+
setError(null);
|
|
1572
|
+
}, [cancel]);
|
|
1573
|
+
const verify = useCallback(
|
|
1574
|
+
async (spec, options = {}) => {
|
|
1575
|
+
abortRef.current?.abort();
|
|
1576
|
+
const controller = new AbortController();
|
|
1577
|
+
abortRef.current = controller;
|
|
1578
|
+
setIsRunning(true);
|
|
1579
|
+
setProgress(null);
|
|
1580
|
+
setError(null);
|
|
1581
|
+
try {
|
|
1582
|
+
const res = await runModelCheckAsync(spec, {
|
|
1583
|
+
...options,
|
|
1584
|
+
createWorker: options.createWorker ?? defaultCreateWorker,
|
|
1585
|
+
signal: controller.signal,
|
|
1586
|
+
onProgress: (p) => setProgress(p)
|
|
1587
|
+
});
|
|
1588
|
+
if (!controller.signal.aborted) {
|
|
1589
|
+
setResult(res);
|
|
1590
|
+
setIsRunning(false);
|
|
1591
|
+
}
|
|
1592
|
+
return res;
|
|
1593
|
+
} catch (err) {
|
|
1594
|
+
if (!controller.signal.aborted) {
|
|
1595
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
1596
|
+
setIsRunning(false);
|
|
1597
|
+
}
|
|
1598
|
+
return null;
|
|
1599
|
+
}
|
|
1600
|
+
},
|
|
1601
|
+
[defaultCreateWorker]
|
|
1602
|
+
);
|
|
1603
|
+
return {
|
|
1604
|
+
isRunning,
|
|
1605
|
+
progress,
|
|
1606
|
+
result,
|
|
1607
|
+
error,
|
|
1608
|
+
verify,
|
|
1609
|
+
cancel,
|
|
1610
|
+
reset
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
export { ActionEditorModal, ActionNode, ExprBuilder, FormalCanvas, InitEditorModal, InitNode, PropertiesPanel, TlaExportModal, TracePlayer, formatExpr, useModelChecker };
|
|
1615
|
+
//# sourceMappingURL=index.js.map
|
|
1616
|
+
//# sourceMappingURL=index.js.map
|