@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 CHANGED
@@ -1453,7 +1453,8 @@ function TlaExportModal({ spec, onClose }) {
1453
1453
  };
1454
1454
  }
1455
1455
  }, [spec]);
1456
- const content = output.ok ? activeTab === "tla" ? output.files.tlaFileContent : output.files.cfgFileContent : output.error;
1456
+ const jsonContent = react.useMemo(() => JSON.stringify(spec, null, 2), [spec]);
1457
+ const content = activeTab === "json" ? jsonContent : output.ok ? activeTab === "tla" ? output.files.tlaFileContent : output.files.cfgFileContent : output.error;
1457
1458
  const handleCopy = async () => {
1458
1459
  await navigator.clipboard.writeText(content);
1459
1460
  setCopied(true);
@@ -1503,9 +1504,21 @@ function TlaExportModal({ spec, onClose }) {
1503
1504
  ".cfg"
1504
1505
  ]
1505
1506
  }
1507
+ ),
1508
+ /* @__PURE__ */ jsxRuntime.jsxs(
1509
+ "button",
1510
+ {
1511
+ type: "button",
1512
+ className: `tsmc-btn tsmc-btn-sm ${activeTab === "json" ? "tsmc-btn-primary" : ""}`,
1513
+ onClick: () => setActiveTab("json"),
1514
+ children: [
1515
+ spec.moduleName,
1516
+ ".json"
1517
+ ]
1518
+ }
1506
1519
  )
1507
1520
  ] }),
1508
- output.ok && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6 }, children: [
1521
+ (output.ok || activeTab === "json") && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6 }, children: [
1509
1522
  /* @__PURE__ */ jsxRuntime.jsxs(
1510
1523
  "button",
1511
1524
  {
@@ -1524,7 +1537,7 @@ function TlaExportModal({ spec, onClose }) {
1524
1537
  type: "button",
1525
1538
  className: "tsmc-btn tsmc-btn-sm",
1526
1539
  onClick: () => handleDownload(
1527
- activeTab === "tla" ? `${spec.moduleName}.tla` : `${spec.moduleName}.cfg`,
1540
+ activeTab === "tla" ? `${spec.moduleName}.tla` : activeTab === "cfg" ? `${spec.moduleName}.cfg` : `${spec.moduleName}.json`,
1528
1541
  content
1529
1542
  ),
1530
1543
  children: [
@@ -1555,6 +1568,252 @@ function TlaExportModal({ spec, onClose }) {
1555
1568
  ] })
1556
1569
  ] }) });
1557
1570
  }
1571
+ function ImportModal({ onImport, onClose }) {
1572
+ const [tab, setTab] = react.useState("tla");
1573
+ const [tlaText, setTlaText] = react.useState("");
1574
+ const [cfgText, setCfgText] = react.useState("");
1575
+ const [jsonText, setJsonText] = react.useState("");
1576
+ const [error, setError] = react.useState(null);
1577
+ const [warnings, setWarnings] = react.useState([]);
1578
+ const handleFileUpload = (e, setter) => {
1579
+ const file = e.target.files?.[0];
1580
+ if (!file) return;
1581
+ const reader = new FileReader();
1582
+ reader.onload = () => {
1583
+ if (typeof reader.result === "string") {
1584
+ setter(reader.result);
1585
+ }
1586
+ };
1587
+ reader.readAsText(file);
1588
+ };
1589
+ const handleImport = () => {
1590
+ setError(null);
1591
+ setWarnings([]);
1592
+ try {
1593
+ if (tab === "tla") {
1594
+ if (!tlaText.trim()) {
1595
+ setError("Please paste or upload a .tla module first.");
1596
+ return;
1597
+ }
1598
+ const res = core.parseTlaToSpec(tlaText, {
1599
+ cfgContent: cfgText.trim() ? cfgText : void 0
1600
+ });
1601
+ if (res.warnings.length > 0) {
1602
+ setWarnings(res.warnings);
1603
+ }
1604
+ onImport(res.spec);
1605
+ onClose();
1606
+ } else {
1607
+ if (!jsonText.trim()) {
1608
+ setError("Please paste or upload a VisualSpecIR JSON file first.");
1609
+ return;
1610
+ }
1611
+ const res = core.parseJsonToSpec(jsonText);
1612
+ if (core.hasValidationErrors(res.issues)) {
1613
+ setError(
1614
+ res.issues.filter((i) => i.severity === "error").map((i) => `[${i.location}] ${i.message}`).join("; ")
1615
+ );
1616
+ return;
1617
+ }
1618
+ onImport(res.spec);
1619
+ onClose();
1620
+ }
1621
+ } catch (err) {
1622
+ setError(err instanceof Error ? err.message : String(err));
1623
+ }
1624
+ };
1625
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tsmc-modal-backdrop", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tsmc-modal", onClick: (e) => e.stopPropagation(), children: [
1626
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tsmc-modal-header", children: [
1627
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: 8 }, children: [
1628
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 16 }),
1629
+ " Import Model (TLA+ or JSON)"
1630
+ ] }),
1631
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tsmc-btn tsmc-btn-sm", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 14 }) })
1632
+ ] }),
1633
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tsmc-modal-body", children: [
1634
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 6 }, children: [
1635
+ /* @__PURE__ */ jsxRuntime.jsx(
1636
+ "button",
1637
+ {
1638
+ type: "button",
1639
+ className: `tsmc-btn tsmc-btn-sm ${tab === "tla" ? "tsmc-btn-primary" : ""}`,
1640
+ onClick: () => {
1641
+ setTab("tla");
1642
+ setError(null);
1643
+ },
1644
+ children: "TLA+ (.tla / .cfg)"
1645
+ }
1646
+ ),
1647
+ /* @__PURE__ */ jsxRuntime.jsx(
1648
+ "button",
1649
+ {
1650
+ type: "button",
1651
+ className: `tsmc-btn tsmc-btn-sm ${tab === "json" ? "tsmc-btn-primary" : ""}`,
1652
+ onClick: () => {
1653
+ setTab("json");
1654
+ setError(null);
1655
+ },
1656
+ children: "JSON (VisualSpecIR)"
1657
+ }
1658
+ )
1659
+ ] }),
1660
+ tab === "tla" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1661
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1662
+ /* @__PURE__ */ jsxRuntime.jsxs(
1663
+ "div",
1664
+ {
1665
+ style: {
1666
+ display: "flex",
1667
+ justifyContent: "space-between",
1668
+ alignItems: "center",
1669
+ marginBottom: 4
1670
+ },
1671
+ children: [
1672
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tsmc-section-label", children: "TLA+ Module (.tla)" }),
1673
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
1674
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileUp, { size: 12 }),
1675
+ " Upload .tla",
1676
+ /* @__PURE__ */ jsxRuntime.jsx(
1677
+ "input",
1678
+ {
1679
+ type: "file",
1680
+ accept: ".tla,text/plain",
1681
+ style: { display: "none" },
1682
+ onChange: (e) => handleFileUpload(e, setTlaText)
1683
+ }
1684
+ )
1685
+ ] })
1686
+ ]
1687
+ }
1688
+ ),
1689
+ /* @__PURE__ */ jsxRuntime.jsx(
1690
+ "textarea",
1691
+ {
1692
+ className: "tsmc-input",
1693
+ style: {
1694
+ width: "100%",
1695
+ minHeight: 170,
1696
+ fontFamily: "var(--tsmc-mono)",
1697
+ fontSize: 12,
1698
+ boxSizing: "border-box"
1699
+ },
1700
+ placeholder: "---- MODULE MyModel ----\nVARIABLES x\nInit == x = 0\n...",
1701
+ value: tlaText,
1702
+ onChange: (e) => setTlaText(e.target.value)
1703
+ }
1704
+ )
1705
+ ] }),
1706
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1707
+ /* @__PURE__ */ jsxRuntime.jsxs(
1708
+ "div",
1709
+ {
1710
+ style: {
1711
+ display: "flex",
1712
+ justifyContent: "space-between",
1713
+ alignItems: "center",
1714
+ marginBottom: 4
1715
+ },
1716
+ children: [
1717
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tsmc-section-label", children: "TLC Config (.cfg \u2014 Optional)" }),
1718
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
1719
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileUp, { size: 12 }),
1720
+ " Upload .cfg",
1721
+ /* @__PURE__ */ jsxRuntime.jsx(
1722
+ "input",
1723
+ {
1724
+ type: "file",
1725
+ accept: ".cfg,text/plain",
1726
+ style: { display: "none" },
1727
+ onChange: (e) => handleFileUpload(e, setCfgText)
1728
+ }
1729
+ )
1730
+ ] })
1731
+ ]
1732
+ }
1733
+ ),
1734
+ /* @__PURE__ */ jsxRuntime.jsx(
1735
+ "textarea",
1736
+ {
1737
+ className: "tsmc-input",
1738
+ style: {
1739
+ width: "100%",
1740
+ minHeight: 80,
1741
+ fontFamily: "var(--tsmc-mono)",
1742
+ fontSize: 12,
1743
+ boxSizing: "border-box"
1744
+ },
1745
+ placeholder: "SPECIFICATION Spec\nINVARIANT Inv_1",
1746
+ value: cfgText,
1747
+ onChange: (e) => setCfgText(e.target.value)
1748
+ }
1749
+ )
1750
+ ] })
1751
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1752
+ /* @__PURE__ */ jsxRuntime.jsxs(
1753
+ "div",
1754
+ {
1755
+ style: {
1756
+ display: "flex",
1757
+ justifyContent: "space-between",
1758
+ alignItems: "center",
1759
+ marginBottom: 4
1760
+ },
1761
+ children: [
1762
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tsmc-section-label", children: "VisualSpecIR JSON" }),
1763
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "tsmc-btn tsmc-btn-sm", style: { cursor: "pointer" }, children: [
1764
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileUp, { size: 12 }),
1765
+ " Upload .json",
1766
+ /* @__PURE__ */ jsxRuntime.jsx(
1767
+ "input",
1768
+ {
1769
+ type: "file",
1770
+ accept: ".json,application/json",
1771
+ style: { display: "none" },
1772
+ onChange: (e) => handleFileUpload(e, setJsonText)
1773
+ }
1774
+ )
1775
+ ] })
1776
+ ]
1777
+ }
1778
+ ),
1779
+ /* @__PURE__ */ jsxRuntime.jsx(
1780
+ "textarea",
1781
+ {
1782
+ className: "tsmc-input",
1783
+ style: {
1784
+ width: "100%",
1785
+ minHeight: 240,
1786
+ fontFamily: "var(--tsmc-mono)",
1787
+ fontSize: 12,
1788
+ boxSizing: "border-box"
1789
+ },
1790
+ placeholder: '{ "schemaVersion": 1, "moduleName": "MyModel", ... }',
1791
+ value: jsonText,
1792
+ onChange: (e) => setJsonText(e.target.value)
1793
+ }
1794
+ )
1795
+ ] }),
1796
+ error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tsmc-badge tsmc-badge-danger", style: { borderRadius: 6, padding: "8px 10px" }, children: [
1797
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertTriangle, { size: 14 }),
1798
+ " ",
1799
+ error
1800
+ ] }),
1801
+ warnings.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tsmc-badge tsmc-badge-warning", style: { borderRadius: 6, padding: "8px 10px" }, children: warnings.join(" | ") })
1802
+ ] }),
1803
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tsmc-modal-footer", children: [
1804
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tsmc-btn", onClick: onClose, children: "Cancel" }),
1805
+ /* @__PURE__ */ jsxRuntime.jsx(
1806
+ "button",
1807
+ {
1808
+ type: "button",
1809
+ className: "tsmc-btn tsmc-btn-primary",
1810
+ onClick: handleImport,
1811
+ children: "Import into Canvas"
1812
+ }
1813
+ )
1814
+ ] })
1815
+ ] }) });
1816
+ }
1558
1817
  function useModelChecker(defaultCreateWorker) {
1559
1818
  const [isRunning, setIsRunning] = react.useState(false);
1560
1819
  const [progress, setProgress] = react.useState(null);
@@ -1617,6 +1876,7 @@ exports.ActionEditorModal = ActionEditorModal;
1617
1876
  exports.ActionNode = ActionNode;
1618
1877
  exports.ExprBuilder = ExprBuilder;
1619
1878
  exports.FormalCanvas = FormalCanvas;
1879
+ exports.ImportModal = ImportModal;
1620
1880
  exports.InitEditorModal = InitEditorModal;
1621
1881
  exports.InitNode = InitNode;
1622
1882
  exports.PropertiesPanel = PropertiesPanel;