@surfaces-ui/page 0.4.0 → 0.6.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/README.md CHANGED
@@ -37,4 +37,45 @@ step, no npm in the page. For hosts that load their scripts with
37
37
  charts does not need it.
38
38
  - **React is inside**, so the page needs nothing else.
39
39
 
40
+ ## Live data in a Claude artifact
41
+
42
+ `surfaces-connected.js` is the same script with one more call. In a Claude
43
+ artifact it reads a real database through a connector the viewer already
44
+ has, with no server to install or host:
45
+
46
+ ```html
47
+ <link rel="stylesheet" href="surfaces-page.css">
48
+ <script src="https://cdn.jsdelivr.net/npm/echarts@6.1.0/dist/echarts.min.js"></script>
49
+ <script src="https://cdn.jsdelivr.net/npm/@surfaces-ui/page@VERSION/dist/surfaces-connected.js"></script>
50
+ <div id="app"></div>
51
+ <script>
52
+ const page = {
53
+ id: "orders", title: "Orders", catalogId: "urn:surfaces:catalog:analytics:v1",
54
+ components: [
55
+ { id: "root", component: "Column", children: ["total", "rows"] },
56
+ { id: "total", component: "Metric", sourceId: "db", sql: "SELECT * FROM sales.orders",
57
+ column: "amount", aggregate: "sum", label: "Revenue", format: "currency" },
58
+ { id: "rows", component: "DataGrid", sourceId: "db", sql: "SELECT * FROM sales.orders", height: 360 },
59
+ ],
60
+ };
61
+ surfaces.mountConnectedPage(document.getElementById("app"), page, {
62
+ sources: [{ id: "db", server: "Postgres", dialect: "postgres" }],
63
+ });
64
+ </script>
65
+ ```
66
+
67
+ - `server` is the connector's name as Claude lists it; `dialect` is
68
+ `"postgres"`, `"mysql"`, `"duckdb"` or `"teradata"`. The connector's query
69
+ tool is found by its shape; name it with `tool` and `argument` if not.
70
+ - Publish the artifact with the `mcp` capability naming that connector and
71
+ its query tool. The viewer is asked once before the first query.
72
+ - Sorting, filtering, paging and totals run in the database, as everywhere
73
+ else in Surfaces UI. The page never loads a table to work on it.
74
+ - The base query is checked as text to be one read-only statement. This
75
+ script has no SQL parser, so on Teradata keep `WITH`, `LOCKING` and
76
+ `ORDER BY` out of a component's `sql`.
77
+ - Components with `sourceId: "page"` still read the page's own `data.tables`.
78
+ - The stylesheet is `surfaces-page.css` for both scripts. An artifact cannot
79
+ load a stylesheet from a CDN, so publish it beside the page.
80
+
40
81
  Build with `pnpm --filter @surfaces-ui/page build`; the files are in `dist/`.