@ts-model-checker/react 1.0.2 → 1.0.3
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/index.cjs +263 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +265 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -83,6 +83,12 @@ interface TlaExportModalProps {
|
|
|
83
83
|
}
|
|
84
84
|
declare function TlaExportModal({ spec, onClose }: TlaExportModalProps): react.JSX.Element;
|
|
85
85
|
|
|
86
|
+
interface ImportModalProps {
|
|
87
|
+
readonly onImport: (spec: VisualSpecIR) => void;
|
|
88
|
+
readonly onClose: () => void;
|
|
89
|
+
}
|
|
90
|
+
declare function ImportModal({ onImport, onClose }: ImportModalProps): react.JSX.Element;
|
|
91
|
+
|
|
86
92
|
interface UseModelCheckerReturn {
|
|
87
93
|
readonly isRunning: boolean;
|
|
88
94
|
readonly progress: CheckerProgress | null;
|
|
@@ -101,4 +107,4 @@ declare function useModelChecker(defaultCreateWorker?: () => Worker): UseModelCh
|
|
|
101
107
|
/** Formats an AST ExprNode into a concise, human-readable string for visual cards. */
|
|
102
108
|
declare function formatExpr(node: ExprNode): string;
|
|
103
109
|
|
|
104
|
-
export { ActionEditorModal, type ActionEditorModalProps, type ActionFlowNode, ActionNode, type ActionNodeData, ExprBuilder, type ExprBuilderProps, FormalCanvas, type FormalCanvasProps, InitEditorModal, type InitEditorModalProps, type InitFlowNode, InitNode, type InitNodeData, PropertiesPanel, type PropertiesPanelProps, TlaExportModal, type TlaExportModalProps, TracePlayer, type TracePlayerProps, type UseModelCheckerReturn, formatExpr, useModelChecker };
|
|
110
|
+
export { ActionEditorModal, type ActionEditorModalProps, type ActionFlowNode, ActionNode, type ActionNodeData, ExprBuilder, type ExprBuilderProps, FormalCanvas, type FormalCanvasProps, ImportModal, type ImportModalProps, InitEditorModal, type InitEditorModalProps, type InitFlowNode, InitNode, type InitNodeData, PropertiesPanel, type PropertiesPanelProps, TlaExportModal, type TlaExportModalProps, TracePlayer, type TracePlayerProps, type UseModelCheckerReturn, formatExpr, useModelChecker };
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ interface TlaExportModalProps {
|
|
|
83
83
|
}
|
|
84
84
|
declare function TlaExportModal({ spec, onClose }: TlaExportModalProps): react.JSX.Element;
|
|
85
85
|
|
|
86
|
+
interface ImportModalProps {
|
|
87
|
+
readonly onImport: (spec: VisualSpecIR) => void;
|
|
88
|
+
readonly onClose: () => void;
|
|
89
|
+
}
|
|
90
|
+
declare function ImportModal({ onImport, onClose }: ImportModalProps): react.JSX.Element;
|
|
91
|
+
|
|
86
92
|
interface UseModelCheckerReturn {
|
|
87
93
|
readonly isRunning: boolean;
|
|
88
94
|
readonly progress: CheckerProgress | null;
|
|
@@ -101,4 +107,4 @@ declare function useModelChecker(defaultCreateWorker?: () => Worker): UseModelCh
|
|
|
101
107
|
/** Formats an AST ExprNode into a concise, human-readable string for visual cards. */
|
|
102
108
|
declare function formatExpr(node: ExprNode): string;
|
|
103
109
|
|
|
104
|
-
export { ActionEditorModal, type ActionEditorModalProps, type ActionFlowNode, ActionNode, type ActionNodeData, ExprBuilder, type ExprBuilderProps, FormalCanvas, type FormalCanvasProps, InitEditorModal, type InitEditorModalProps, type InitFlowNode, InitNode, type InitNodeData, PropertiesPanel, type PropertiesPanelProps, TlaExportModal, type TlaExportModalProps, TracePlayer, type TracePlayerProps, type UseModelCheckerReturn, formatExpr, useModelChecker };
|
|
110
|
+
export { ActionEditorModal, type ActionEditorModalProps, type ActionFlowNode, ActionNode, type ActionNodeData, ExprBuilder, type ExprBuilderProps, FormalCanvas, type FormalCanvasProps, ImportModal, type ImportModalProps, InitEditorModal, type InitEditorModalProps, type InitFlowNode, InitNode, type InitNodeData, PropertiesPanel, type PropertiesPanelProps, TlaExportModal, type TlaExportModalProps, TracePlayer, type TracePlayerProps, type UseModelCheckerReturn, formatExpr, useModelChecker };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
2
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';
|
|
3
|
+
import { X, Plus, Trash2, Zap, Edit3, Play, Shield, Sparkles, AlertTriangle, SkipBack, ChevronLeft, Pause, ChevronRight, SkipForward, Repeat, Check, Copy, Download, Upload, FileUp } from 'lucide-react';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
-
import { transpileToTla } from '@ts-model-checker/core';
|
|
5
|
+
import { transpileToTla, parseTlaToSpec, parseJsonToSpec, hasValidationErrors } from '@ts-model-checker/core';
|
|
6
6
|
import { runModelCheckAsync } from '@ts-model-checker/worker';
|
|
7
7
|
|
|
8
8
|
// src/components/FormalCanvas.tsx
|
|
@@ -1451,7 +1451,8 @@ function TlaExportModal({ spec, onClose }) {
|
|
|
1451
1451
|
};
|
|
1452
1452
|
}
|
|
1453
1453
|
}, [spec]);
|
|
1454
|
-
const
|
|
1454
|
+
const jsonContent = useMemo(() => JSON.stringify(spec, null, 2), [spec]);
|
|
1455
|
+
const content = activeTab === "json" ? jsonContent : output.ok ? activeTab === "tla" ? output.files.tlaFileContent : output.files.cfgFileContent : output.error;
|
|
1455
1456
|
const handleCopy = async () => {
|
|
1456
1457
|
await navigator.clipboard.writeText(content);
|
|
1457
1458
|
setCopied(true);
|
|
@@ -1501,9 +1502,21 @@ function TlaExportModal({ spec, onClose }) {
|
|
|
1501
1502
|
".cfg"
|
|
1502
1503
|
]
|
|
1503
1504
|
}
|
|
1505
|
+
),
|
|
1506
|
+
/* @__PURE__ */ jsxs(
|
|
1507
|
+
"button",
|
|
1508
|
+
{
|
|
1509
|
+
type: "button",
|
|
1510
|
+
className: `tsmc-btn tsmc-btn-sm ${activeTab === "json" ? "tsmc-btn-primary" : ""}`,
|
|
1511
|
+
onClick: () => setActiveTab("json"),
|
|
1512
|
+
children: [
|
|
1513
|
+
spec.moduleName,
|
|
1514
|
+
".json"
|
|
1515
|
+
]
|
|
1516
|
+
}
|
|
1504
1517
|
)
|
|
1505
1518
|
] }),
|
|
1506
|
-
output.ok && /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6 }, children: [
|
|
1519
|
+
(output.ok || activeTab === "json") && /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6 }, children: [
|
|
1507
1520
|
/* @__PURE__ */ jsxs(
|
|
1508
1521
|
"button",
|
|
1509
1522
|
{
|
|
@@ -1522,7 +1535,7 @@ function TlaExportModal({ spec, onClose }) {
|
|
|
1522
1535
|
type: "button",
|
|
1523
1536
|
className: "tsmc-btn tsmc-btn-sm",
|
|
1524
1537
|
onClick: () => handleDownload(
|
|
1525
|
-
activeTab === "tla" ? `${spec.moduleName}.tla` : `${spec.moduleName}.cfg`,
|
|
1538
|
+
activeTab === "tla" ? `${spec.moduleName}.tla` : activeTab === "cfg" ? `${spec.moduleName}.cfg` : `${spec.moduleName}.json`,
|
|
1526
1539
|
content
|
|
1527
1540
|
),
|
|
1528
1541
|
children: [
|
|
@@ -1553,6 +1566,252 @@ function TlaExportModal({ spec, onClose }) {
|
|
|
1553
1566
|
] })
|
|
1554
1567
|
] }) });
|
|
1555
1568
|
}
|
|
1569
|
+
function ImportModal({ onImport, onClose }) {
|
|
1570
|
+
const [tab, setTab] = useState("tla");
|
|
1571
|
+
const [tlaText, setTlaText] = useState("");
|
|
1572
|
+
const [cfgText, setCfgText] = useState("");
|
|
1573
|
+
const [jsonText, setJsonText] = useState("");
|
|
1574
|
+
const [error, setError] = useState(null);
|
|
1575
|
+
const [warnings, setWarnings] = useState([]);
|
|
1576
|
+
const handleFileUpload = (e, setter) => {
|
|
1577
|
+
const file = e.target.files?.[0];
|
|
1578
|
+
if (!file) return;
|
|
1579
|
+
const reader = new FileReader();
|
|
1580
|
+
reader.onload = () => {
|
|
1581
|
+
if (typeof reader.result === "string") {
|
|
1582
|
+
setter(reader.result);
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
reader.readAsText(file);
|
|
1586
|
+
};
|
|
1587
|
+
const handleImport = () => {
|
|
1588
|
+
setError(null);
|
|
1589
|
+
setWarnings([]);
|
|
1590
|
+
try {
|
|
1591
|
+
if (tab === "tla") {
|
|
1592
|
+
if (!tlaText.trim()) {
|
|
1593
|
+
setError("Please paste or upload a .tla module first.");
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
const res = parseTlaToSpec(tlaText, {
|
|
1597
|
+
cfgContent: cfgText.trim() ? cfgText : void 0
|
|
1598
|
+
});
|
|
1599
|
+
if (res.warnings.length > 0) {
|
|
1600
|
+
setWarnings(res.warnings);
|
|
1601
|
+
}
|
|
1602
|
+
onImport(res.spec);
|
|
1603
|
+
onClose();
|
|
1604
|
+
} else {
|
|
1605
|
+
if (!jsonText.trim()) {
|
|
1606
|
+
setError("Please paste or upload a VisualSpecIR JSON file first.");
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
const res = parseJsonToSpec(jsonText);
|
|
1610
|
+
if (hasValidationErrors(res.issues)) {
|
|
1611
|
+
setError(
|
|
1612
|
+
res.issues.filter((i) => i.severity === "error").map((i) => `[${i.location}] ${i.message}`).join("; ")
|
|
1613
|
+
);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
onImport(res.spec);
|
|
1617
|
+
onClose();
|
|
1618
|
+
}
|
|
1619
|
+
} catch (err) {
|
|
1620
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
return /* @__PURE__ */ jsx("div", { className: "tsmc-modal-backdrop", onClick: onClose, children: /* @__PURE__ */ jsxs("div", { className: "tsmc-modal", onClick: (e) => e.stopPropagation(), children: [
|
|
1624
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-header", children: [
|
|
1625
|
+
/* @__PURE__ */ jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: 8 }, children: [
|
|
1626
|
+
/* @__PURE__ */ jsx(Upload, { size: 16 }),
|
|
1627
|
+
" Import Model (TLA+ or JSON)"
|
|
1628
|
+
] }),
|
|
1629
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: onClose, children: /* @__PURE__ */ jsx(X, { size: 14 }) })
|
|
1630
|
+
] }),
|
|
1631
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-body", children: [
|
|
1632
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6 }, children: [
|
|
1633
|
+
/* @__PURE__ */ jsx(
|
|
1634
|
+
"button",
|
|
1635
|
+
{
|
|
1636
|
+
type: "button",
|
|
1637
|
+
className: `tsmc-btn tsmc-btn-sm ${tab === "tla" ? "tsmc-btn-primary" : ""}`,
|
|
1638
|
+
onClick: () => {
|
|
1639
|
+
setTab("tla");
|
|
1640
|
+
setError(null);
|
|
1641
|
+
},
|
|
1642
|
+
children: "TLA+ (.tla / .cfg)"
|
|
1643
|
+
}
|
|
1644
|
+
),
|
|
1645
|
+
/* @__PURE__ */ jsx(
|
|
1646
|
+
"button",
|
|
1647
|
+
{
|
|
1648
|
+
type: "button",
|
|
1649
|
+
className: `tsmc-btn tsmc-btn-sm ${tab === "json" ? "tsmc-btn-primary" : ""}`,
|
|
1650
|
+
onClick: () => {
|
|
1651
|
+
setTab("json");
|
|
1652
|
+
setError(null);
|
|
1653
|
+
},
|
|
1654
|
+
children: "JSON (VisualSpecIR)"
|
|
1655
|
+
}
|
|
1656
|
+
)
|
|
1657
|
+
] }),
|
|
1658
|
+
tab === "tla" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1659
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1660
|
+
/* @__PURE__ */ jsxs(
|
|
1661
|
+
"div",
|
|
1662
|
+
{
|
|
1663
|
+
style: {
|
|
1664
|
+
display: "flex",
|
|
1665
|
+
justifyContent: "space-between",
|
|
1666
|
+
alignItems: "center",
|
|
1667
|
+
marginBottom: 4
|
|
1668
|
+
},
|
|
1669
|
+
children: [
|
|
1670
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "TLA+ Module (.tla)" }),
|
|
1671
|
+
/* @__PURE__ */ jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
|
|
1672
|
+
/* @__PURE__ */ jsx(FileUp, { size: 12 }),
|
|
1673
|
+
" Upload .tla",
|
|
1674
|
+
/* @__PURE__ */ jsx(
|
|
1675
|
+
"input",
|
|
1676
|
+
{
|
|
1677
|
+
type: "file",
|
|
1678
|
+
accept: ".tla,text/plain",
|
|
1679
|
+
style: { display: "none" },
|
|
1680
|
+
onChange: (e) => handleFileUpload(e, setTlaText)
|
|
1681
|
+
}
|
|
1682
|
+
)
|
|
1683
|
+
] })
|
|
1684
|
+
]
|
|
1685
|
+
}
|
|
1686
|
+
),
|
|
1687
|
+
/* @__PURE__ */ jsx(
|
|
1688
|
+
"textarea",
|
|
1689
|
+
{
|
|
1690
|
+
className: "tsmc-input",
|
|
1691
|
+
style: {
|
|
1692
|
+
width: "100%",
|
|
1693
|
+
minHeight: 170,
|
|
1694
|
+
fontFamily: "var(--tsmc-mono)",
|
|
1695
|
+
fontSize: 12,
|
|
1696
|
+
boxSizing: "border-box"
|
|
1697
|
+
},
|
|
1698
|
+
placeholder: "---- MODULE MyModel ----\nVARIABLES x\nInit == x = 0\n...",
|
|
1699
|
+
value: tlaText,
|
|
1700
|
+
onChange: (e) => setTlaText(e.target.value)
|
|
1701
|
+
}
|
|
1702
|
+
)
|
|
1703
|
+
] }),
|
|
1704
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1705
|
+
/* @__PURE__ */ jsxs(
|
|
1706
|
+
"div",
|
|
1707
|
+
{
|
|
1708
|
+
style: {
|
|
1709
|
+
display: "flex",
|
|
1710
|
+
justifyContent: "space-between",
|
|
1711
|
+
alignItems: "center",
|
|
1712
|
+
marginBottom: 4
|
|
1713
|
+
},
|
|
1714
|
+
children: [
|
|
1715
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "TLC Config (.cfg \u2014 Optional)" }),
|
|
1716
|
+
/* @__PURE__ */ jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
|
|
1717
|
+
/* @__PURE__ */ jsx(FileUp, { size: 12 }),
|
|
1718
|
+
" Upload .cfg",
|
|
1719
|
+
/* @__PURE__ */ jsx(
|
|
1720
|
+
"input",
|
|
1721
|
+
{
|
|
1722
|
+
type: "file",
|
|
1723
|
+
accept: ".cfg,text/plain",
|
|
1724
|
+
style: { display: "none" },
|
|
1725
|
+
onChange: (e) => handleFileUpload(e, setCfgText)
|
|
1726
|
+
}
|
|
1727
|
+
)
|
|
1728
|
+
] })
|
|
1729
|
+
]
|
|
1730
|
+
}
|
|
1731
|
+
),
|
|
1732
|
+
/* @__PURE__ */ jsx(
|
|
1733
|
+
"textarea",
|
|
1734
|
+
{
|
|
1735
|
+
className: "tsmc-input",
|
|
1736
|
+
style: {
|
|
1737
|
+
width: "100%",
|
|
1738
|
+
minHeight: 80,
|
|
1739
|
+
fontFamily: "var(--tsmc-mono)",
|
|
1740
|
+
fontSize: 12,
|
|
1741
|
+
boxSizing: "border-box"
|
|
1742
|
+
},
|
|
1743
|
+
placeholder: "SPECIFICATION Spec\nINVARIANT Inv_1",
|
|
1744
|
+
value: cfgText,
|
|
1745
|
+
onChange: (e) => setCfgText(e.target.value)
|
|
1746
|
+
}
|
|
1747
|
+
)
|
|
1748
|
+
] })
|
|
1749
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
1750
|
+
/* @__PURE__ */ jsxs(
|
|
1751
|
+
"div",
|
|
1752
|
+
{
|
|
1753
|
+
style: {
|
|
1754
|
+
display: "flex",
|
|
1755
|
+
justifyContent: "space-between",
|
|
1756
|
+
alignItems: "center",
|
|
1757
|
+
marginBottom: 4
|
|
1758
|
+
},
|
|
1759
|
+
children: [
|
|
1760
|
+
/* @__PURE__ */ jsx("span", { className: "tsmc-section-label", children: "VisualSpecIR JSON" }),
|
|
1761
|
+
/* @__PURE__ */ jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
|
|
1762
|
+
/* @__PURE__ */ jsx(FileUp, { size: 12 }),
|
|
1763
|
+
" Upload .json",
|
|
1764
|
+
/* @__PURE__ */ jsx(
|
|
1765
|
+
"input",
|
|
1766
|
+
{
|
|
1767
|
+
type: "file",
|
|
1768
|
+
accept: ".json,application/json",
|
|
1769
|
+
style: { display: "none" },
|
|
1770
|
+
onChange: (e) => handleFileUpload(e, setJsonText)
|
|
1771
|
+
}
|
|
1772
|
+
)
|
|
1773
|
+
] })
|
|
1774
|
+
]
|
|
1775
|
+
}
|
|
1776
|
+
),
|
|
1777
|
+
/* @__PURE__ */ jsx(
|
|
1778
|
+
"textarea",
|
|
1779
|
+
{
|
|
1780
|
+
className: "tsmc-input",
|
|
1781
|
+
style: {
|
|
1782
|
+
width: "100%",
|
|
1783
|
+
minHeight: 240,
|
|
1784
|
+
fontFamily: "var(--tsmc-mono)",
|
|
1785
|
+
fontSize: 12,
|
|
1786
|
+
boxSizing: "border-box"
|
|
1787
|
+
},
|
|
1788
|
+
placeholder: '{ "schemaVersion": 1, "moduleName": "MyModel", ... }',
|
|
1789
|
+
value: jsonText,
|
|
1790
|
+
onChange: (e) => setJsonText(e.target.value)
|
|
1791
|
+
}
|
|
1792
|
+
)
|
|
1793
|
+
] }),
|
|
1794
|
+
error && /* @__PURE__ */ jsxs("div", { className: "tsmc-badge tsmc-badge-danger", style: { borderRadius: 6, padding: "8px 10px" }, children: [
|
|
1795
|
+
/* @__PURE__ */ jsx(AlertTriangle, { size: 14 }),
|
|
1796
|
+
" ",
|
|
1797
|
+
error
|
|
1798
|
+
] }),
|
|
1799
|
+
warnings.length > 0 && /* @__PURE__ */ jsx("div", { className: "tsmc-badge tsmc-badge-warning", style: { borderRadius: 6, padding: "8px 10px" }, children: warnings.join(" | ") })
|
|
1800
|
+
] }),
|
|
1801
|
+
/* @__PURE__ */ jsxs("div", { className: "tsmc-modal-footer", children: [
|
|
1802
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "tsmc-btn", onClick: onClose, children: "Cancel" }),
|
|
1803
|
+
/* @__PURE__ */ jsx(
|
|
1804
|
+
"button",
|
|
1805
|
+
{
|
|
1806
|
+
type: "button",
|
|
1807
|
+
className: "tsmc-btn tsmc-btn-primary",
|
|
1808
|
+
onClick: handleImport,
|
|
1809
|
+
children: "Import into Canvas"
|
|
1810
|
+
}
|
|
1811
|
+
)
|
|
1812
|
+
] })
|
|
1813
|
+
] }) });
|
|
1814
|
+
}
|
|
1556
1815
|
function useModelChecker(defaultCreateWorker) {
|
|
1557
1816
|
const [isRunning, setIsRunning] = useState(false);
|
|
1558
1817
|
const [progress, setProgress] = useState(null);
|
|
@@ -1611,6 +1870,6 @@ function useModelChecker(defaultCreateWorker) {
|
|
|
1611
1870
|
};
|
|
1612
1871
|
}
|
|
1613
1872
|
|
|
1614
|
-
export { ActionEditorModal, ActionNode, ExprBuilder, FormalCanvas, InitEditorModal, InitNode, PropertiesPanel, TlaExportModal, TracePlayer, formatExpr, useModelChecker };
|
|
1873
|
+
export { ActionEditorModal, ActionNode, ExprBuilder, FormalCanvas, ImportModal, InitEditorModal, InitNode, PropertiesPanel, TlaExportModal, TracePlayer, formatExpr, useModelChecker };
|
|
1615
1874
|
//# sourceMappingURL=index.js.map
|
|
1616
1875
|
//# sourceMappingURL=index.js.map
|