sygnal 6.5.0 → 7.0.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/README.md +2 -0
  3. package/dist/astro/index.cjs.js +423 -27
  4. package/dist/astro/index.cjs.js.map +1 -1
  5. package/dist/astro/index.mjs +423 -27
  6. package/dist/astro/index.mjs.map +1 -1
  7. package/dist/astro/server.cjs.js.map +1 -1
  8. package/dist/astro/server.mjs.map +1 -1
  9. package/dist/devtools.cjs.js +141 -3
  10. package/dist/devtools.cjs.js.map +1 -1
  11. package/dist/devtools.esm.js +141 -4
  12. package/dist/devtools.esm.js.map +1 -1
  13. package/dist/diagnostics.cjs.js +169 -14
  14. package/dist/diagnostics.cjs.js.map +1 -1
  15. package/dist/diagnostics.esm.js +168 -15
  16. package/dist/diagnostics.esm.js.map +1 -1
  17. package/dist/guide/accessibility.md +2 -0
  18. package/dist/guide/ai-chat.md +6 -6
  19. package/dist/guide/behaviors.md +1 -1
  20. package/dist/guide/element-commands.md +4 -2
  21. package/dist/guide/forms-reference.md +89 -3
  22. package/dist/guide/forms.md +8 -8
  23. package/dist/guide/http.md +77 -7
  24. package/dist/guide/migrating-to-7.md +314 -0
  25. package/dist/guide/recipes/ai-summarize.md +2 -1
  26. package/dist/guide/recipes/i18n.md +1 -1
  27. package/dist/guide/ui/tabs.md +5 -4
  28. package/dist/guide/ui/tooltip.md +24 -0
  29. package/dist/index.cjs.js +781 -320
  30. package/dist/index.cjs.js.map +1 -1
  31. package/dist/index.d.ts +319 -43
  32. package/dist/index.esm.js +781 -320
  33. package/dist/index.esm.js.map +1 -1
  34. package/dist/sygnal.min.js +1 -1
  35. package/dist/sygnal.min.js.map +1 -1
  36. package/dist/ui.cjs.js +96 -11
  37. package/dist/ui.cjs.js.map +1 -1
  38. package/dist/ui.esm.js +96 -12
  39. package/dist/ui.esm.js.map +1 -1
  40. package/dist/vike/config/package.json +1 -1
  41. package/dist/vike/onRenderClient.cjs.js +63 -43
  42. package/dist/vike/onRenderClient.cjs.js.map +1 -1
  43. package/dist/vike/onRenderClient.mjs +63 -43
  44. package/dist/vike/onRenderClient.mjs.map +1 -1
  45. package/dist/vike/onRenderHtml.cjs.js +21 -25
  46. package/dist/vike/onRenderHtml.cjs.js.map +1 -1
  47. package/dist/vike/onRenderHtml.mjs +21 -25
  48. package/dist/vike/onRenderHtml.mjs.map +1 -1
  49. package/dist/vite/plugin.cjs.js +410 -27
  50. package/dist/vite/plugin.cjs.js.map +1 -1
  51. package/dist/vite/plugin.mjs +410 -27
  52. package/dist/vite/plugin.mjs.map +1 -1
  53. package/llms.txt +17 -16
  54. package/package.json +1 -1
  55. package/src/astro/index.d.ts +8 -0
  56. package/src/astro/index.ts +18 -0
  57. package/src/core/actions.ts +28 -21
  58. package/src/core/define.ts +2 -0
  59. package/src/core/hooks.ts +8 -2
  60. package/src/core/hosts/collection.ts +4 -3
  61. package/src/core/instance.ts +60 -16
  62. package/src/core/runtime.ts +5 -1
  63. package/src/core/view.ts +2 -0
  64. package/src/cycle/dom/utils.ts +4 -2
  65. package/src/devtools.d.ts +13 -0
  66. package/src/devtools.ts +3 -0
  67. package/src/extra/ai/chat/behavior.ts +3 -3
  68. package/src/extra/ai/commandBar.ts +3 -3
  69. package/src/extra/ai/compose/behavior.ts +3 -3
  70. package/src/extra/ai/transports/shared.ts +8 -2
  71. package/src/extra/behaviors.ts +21 -0
  72. package/src/extra/devGraph.ts +111 -0
  73. package/src/extra/devMcp.ts +1 -1
  74. package/src/extra/devtools.ts +18 -0
  75. package/src/extra/diagnostics/checks/fetch.ts +21 -1
  76. package/src/extra/diagnostics/checks/forms.ts +4 -3
  77. package/src/extra/diagnostics/checks/index.ts +2 -1
  78. package/src/extra/diagnostics/checks/inspect.ts +68 -6
  79. package/src/extra/diagnostics/checks/next.ts +3 -0
  80. package/src/extra/diagnostics/checks/public.d.ts +133 -12
  81. package/src/extra/diagnostics/checks/timingAudit.ts +47 -0
  82. package/src/extra/diagnostics/codes.ts +19 -0
  83. package/src/extra/fetchDriver.ts +112 -7
  84. package/src/extra/fetchEventSource.ts +113 -0
  85. package/src/extra/form.ts +68 -26
  86. package/src/extra/formHelpers.ts +3 -1
  87. package/src/extra/lens.ts +3 -2
  88. package/src/extra/queryCache.ts +4 -3
  89. package/src/extra/socketDriver.ts +10 -4
  90. package/src/extra/testing.ts +68 -11
  91. package/src/index.d.ts +199 -30
  92. package/src/index.ts +1 -0
  93. package/src/shared.ts +3 -0
  94. package/src/ui/dialog.ts +3 -2
  95. package/src/ui/tooltips.ts +92 -0
  96. package/src/ui.d.ts +35 -0
  97. package/src/ui.ts +1 -0
  98. package/src/vike/onRenderClient.ts +44 -46
  99. package/src/vike/onRenderHtml.ts +5 -26
  100. package/src/vike/shell.ts +33 -0
  101. package/src/vite/graph.ts +255 -0
  102. package/src/vite/mcp.ts +3 -3
  103. package/src/vite/plugin.d.ts +19 -0
  104. package/src/vite/plugin.ts +144 -25
@@ -871,6 +871,25 @@ class SygnalDevTools {
871
871
  case 'GET_STATE':
872
872
  this._sendComponentState(msg.payload.componentId);
873
873
  break;
874
+ case 'GET_GRAPH':
875
+ this._post('GRAPH', this._graph(msg.payload));
876
+ break;
877
+ }
878
+ }
879
+ /**
880
+ * PLAN-10 P-1: the runtime app graph for the panel's App graph view: inspect() with the recent
881
+ * actions, JSON-safe. inspect() is on this object only when 'sygnal/diagnostics' is loaded
882
+ * (sygnal/vite loads it in dev); without it the panel shows why.
883
+ */
884
+ _graph(opts) {
885
+ const inspect = this.inspect;
886
+ if (typeof inspect !== 'function')
887
+ return { graph: null, reason: 'no-diagnostics' };
888
+ try {
889
+ return { graph: JSON.parse(JSON.stringify(inspect({ actions: opts?.actions ?? 200 }))) };
890
+ }
891
+ catch (e) {
892
+ return { graph: null, reason: 'error', message: String(e?.message ?? e) };
874
893
  }
875
894
  }
876
895
  onComponentCreated(componentNumber, name, instance) {
@@ -1746,15 +1765,15 @@ function pageTools(o, notifyWaiting = () => { }) {
1746
1765
  };
1747
1766
  return tools;
1748
1767
  }
1749
- let installed = null;
1768
+ let installed$1 = null;
1750
1769
  /**
1751
1770
  * Connect this page to the dev server's MCP endpoint (sygnal/vite with `mcp: true` calls it from
1752
1771
  * 'virtual:sygnal/mcp'). Once per page; no-op without a hot channel.
1753
1772
  */
1754
1773
  function installMcpBridge(hot, options = {}) {
1755
- if (!hot || installed === hot)
1774
+ if (!hot || installed$1 === hot)
1756
1775
  return;
1757
- installed = hot;
1776
+ installed$1 = hot;
1758
1777
  if (!options.app)
1759
1778
  trackApps();
1760
1779
  const tools = pageTools(options, (id) => hot.send(MCP_RESPONSE, { id, waiting: true }));
@@ -1800,6 +1819,124 @@ function installMcpBridge(hot, options = {}) {
1800
1819
  }
1801
1820
  }
1802
1821
 
1822
+ /**
1823
+ * PLAN-10 P-2 (D544): the app side of the graph page's "Live data" (sygnal/vite serves the page at
1824
+ * `/__sygnal/graph` in dev, W-2 / D543). Dev only: it is part of the 'sygnal/devtools' entry, and
1825
+ * sygnal/vite's 'virtual:sygnal/graph' module (served by the dev server, never in a build) calls
1826
+ * installGraphBridge().
1827
+ *
1828
+ * The page is served by the dev server on the app's own origin, so the two talk over a
1829
+ * BroadcastChannel ('sygnal:graph'): no server round trip, no HMR traffic, nothing a page on
1830
+ * another origin can join. Every message carries `v: 1`.
1831
+ *
1832
+ * page → apps { type: 'who', watch? } every 2 s while the page is open; `watch` names
1833
+ * the tab the page follows (it keeps that tab
1834
+ * sending for 6 s)
1835
+ * app → page { type: 'here', tab, url, title, at, ok } the answer, and on load / focus
1836
+ * (`at`: when the tab was last loaded or focused;
1837
+ * `ok`: inspect() is there, i.e. diagnostics on)
1838
+ * app → page { type: 'graph', tab, graph } inspect({ actions: 200 }) of the page's apps, JSON
1839
+ * safe: when it starts being watched, then 150 ms
1840
+ * after the last action or component change
1841
+ * app → page { type: 'action', tab, record } { type, instance, component } at once (a flash)
1842
+ * page → app { type: 'get-state', tab, req, id } an instance's state
1843
+ * app → page { type: 'state', tab, req, id, value?, error? }
1844
+ * app → page { type: 'bye', tab } the tab is going away (pagehide)
1845
+ *
1846
+ * State values go through the DevTools preview (JSON safe, as the MCP tools send them). The static
1847
+ * keys the page joins on are on the component functions (sygnal/vite's dev transform) and come out
1848
+ * of inspect() as `key`.
1849
+ */
1850
+ const GRAPH_CHANNEL = 'sygnal:graph';
1851
+ const WATCH_MS = 6000;
1852
+ const SETTLE_MS = 150;
1853
+ let installed = false;
1854
+ /** Connect this page to the graph page's "Live data" (sygnal/vite calls it in dev). Once per page. */
1855
+ function installGraphBridge(options = {}) {
1856
+ const g = globalThis;
1857
+ if (installed || typeof g.BroadcastChannel != 'function' || !g.window)
1858
+ return;
1859
+ installed = true;
1860
+ trackApps();
1861
+ const bc = new g.BroadcastChannel(options.channel || GRAPH_CHANNEL);
1862
+ const tab = Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
1863
+ const tools = pageTools({});
1864
+ let at = Date.now();
1865
+ let watchedUntil = 0;
1866
+ let timer = 0;
1867
+ const inspect = () => {
1868
+ const f = g.__SYGNAL_DIAGNOSTICS__?.inspect || getDevTools()?.inspect;
1869
+ return typeof f == 'function' ? f : null;
1870
+ };
1871
+ const post = (m) => { try {
1872
+ bc.postMessage({ v: 1, tab, ...m });
1873
+ }
1874
+ catch (_) { /* closed */ } };
1875
+ const here = () => post({ type: 'here', url: String(g.location?.href || ''), title: String(g.document?.title || ''), at, ok: !!inspect() });
1876
+ const watched = () => Date.now() < watchedUntil;
1877
+ const sendGraph = () => {
1878
+ clearTimeout(timer);
1879
+ timer = 0;
1880
+ const f = inspect();
1881
+ if (!watched() || !f)
1882
+ return;
1883
+ let graph;
1884
+ try {
1885
+ graph = JSON.parse(JSON.stringify(f({ actions: 200 })));
1886
+ }
1887
+ catch (_) {
1888
+ return;
1889
+ }
1890
+ post({ type: 'graph', graph });
1891
+ };
1892
+ const settle = () => {
1893
+ if (!watched())
1894
+ return;
1895
+ clearTimeout(timer);
1896
+ timer = setTimeout(sendGraph, SETTLE_MS);
1897
+ };
1898
+ const watch = () => {
1899
+ const was = watched();
1900
+ watchedUntil = Date.now() + WATCH_MS;
1901
+ if (!was)
1902
+ sendGraph();
1903
+ };
1904
+ bc.onmessage = (e) => {
1905
+ const m = e && e.data;
1906
+ if (!m || m.v !== 1 || typeof m.type != 'string')
1907
+ return;
1908
+ if (m.type == 'who') {
1909
+ if (m.watch === tab)
1910
+ watch();
1911
+ here();
1912
+ }
1913
+ else if (m.type == 'get-state' && m.tab === tab) {
1914
+ let value, error;
1915
+ try {
1916
+ value = tools.get_state({ component: String(m.id) }, m.req).state;
1917
+ }
1918
+ catch (err) {
1919
+ error = String(err?.message || err);
1920
+ }
1921
+ post({ type: 'state', req: m.req, id: m.id, ...(error ? { error } : { value }) });
1922
+ }
1923
+ };
1924
+ onAction((a, kind) => {
1925
+ if (!watched())
1926
+ return;
1927
+ if (kind == 'add' && a)
1928
+ post({ type: 'action', record: { type: a.type, instance: String(a.instance), component: a.component } });
1929
+ settle();
1930
+ });
1931
+ addLayer(() => ({ onCreate: settle, onDispose: settle }));
1932
+ const seen = () => { at = Date.now(); here(); };
1933
+ g.addEventListener?.('focus', seen);
1934
+ g.document?.addEventListener?.('visibilitychange', () => { if (g.document.visibilityState == 'visible')
1935
+ seen(); });
1936
+ g.addEventListener?.('pagehide', () => post({ type: 'bye' }));
1937
+ here();
1938
+ }
1939
+
1803
1940
  // 'sygnal/devtools' (D77): the DevTools bridge for the browser extension, a dev-only
1804
1941
  // entry. Importing it installs window.__SYGNAL_DEVTOOLS__ (run() did this before 6.0),
1805
1942
  // so import it before run(): components created earlier are not in the tree.
@@ -1823,5 +1960,5 @@ function copyAsTest(target, options) {
1823
1960
  return copyAsTestResult(target, options).code;
1824
1961
  }
1825
1962
 
1826
- export { clearActions, connectReduxDevtools, copyAsTest, copyAsTestResult, getActions, getDevTools, getSession, installDevTools, installMcpBridge, isRecording, onAction, recordActions };
1963
+ export { clearActions, connectReduxDevtools, copyAsTest, copyAsTestResult, getActions, getDevTools, getSession, installDevTools, installGraphBridge, installMcpBridge, isRecording, onAction, recordActions };
1827
1964
  //# sourceMappingURL=devtools.esm.js.map