reifyui 0.18.4 → 0.19.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 +43 -0
- package/dist/chart.js +4 -59
- package/dist/chart.js.map +1 -1
- package/dist/chunk-FPLC5KAD.js +62 -0
- package/dist/chunk-FPLC5KAD.js.map +1 -0
- package/dist/graph.cjs +30 -4
- package/dist/graph.cjs.map +1 -1
- package/dist/graph.d.ts +2 -1
- package/dist/graph.js +30 -4
- package/dist/graph.js.map +1 -1
- package/dist/slides.cjs +62 -15
- package/dist/slides.cjs.map +1 -1
- package/dist/slides.js +5 -14
- package/dist/slides.js.map +1 -1
- package/dist/tree.cjs +1159 -0
- package/dist/tree.cjs.map +1 -0
- package/dist/tree.d.ts +178 -0
- package/dist/tree.js +1129 -0
- package/dist/tree.js.map +1 -0
- package/package.json +9 -1
- package/src/graph/ConnectPane.jsx +28 -3
- package/src/graph/index.d.ts +2 -1
- package/src/slides/elements.jsx +7 -11
- package/src/tree/FileTree.jsx +668 -0
- package/src/tree/index.d.ts +178 -0
- package/src/tree/index.js +14 -0
- package/src/tree/model.js +220 -0
- package/styles/graph.css +18 -1
- package/styles/tree.css +199 -0
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ A production-grade surface for rendering and interacting with a live agent turn:
|
|
|
62
62
|
| **Slides** (`reifyui/slides`) | `SlideView`, `SlideStage`, `EditorCanvas`, `Presentation`, `ElementView`, `themeVars` — render a JSON deck, edit it by direct manipulation, present it |
|
|
63
63
|
| **Spreadsheet** | `SheetGrid`, `sheetToDelimited`, `sheetToAoA` — an AI-editable grid, extensible with your own column types |
|
|
64
64
|
| **HarnessRouter** (`reifyui/harness`) | `configureKit`, `kitHarness`, `listSessions`, `readFile`, `writeFile`, `createResponse`, `streamTurn`, `turnsToMessages`, `fileToInputBlock` — the transport for apps served by a HarnessRouter console |
|
|
65
|
+
| **File tree** (`reifyui/tree`) | `FileTree`, `buildFileTree`, `treeKeyAction`, `nameProblem`, `canMove` — a folder tree of files the way an editor's Explorer shows one: names typed in place, a delete asked in the row, drag into a folder, a right-click menu, the WAI-ARIA tree keyboard |
|
|
65
66
|
| **Agent chat** (`reifyui/agent-chat`) | `AgentConversation`, `AgentTurnView`, `AgentComposer`, `WorkingIndicator`, `StepRow`, `WorkGroup`, `TodoCard`, `reduceTurn`, `turnFromMessage`, `describeTool`, `motionFor` — an agent's turn the way Claude Code shows it: one live line, work folded to a past-tense line per run of calls, every call one click from its input and output |
|
|
66
67
|
| **Icons / tool meta** | `Ic*` icon set, `toolMeta`, `humanize`, `summarizeSteps` |
|
|
67
68
|
| **Auth (optional)** | `configureAuth`, `login`, `AuthForm`, `GoogleButton` — a thin JWT client for products with a `/v1/auth`-style backend; wired to nothing by default |
|
|
@@ -157,6 +158,7 @@ import 'reifyui/styles/panels.css'; // panel + panel grid, stat tile, res
|
|
|
157
158
|
import 'reifyui/styles/tasks.css'; // task list
|
|
158
159
|
import 'reifyui/styles/dialog.css'; // alert / confirm / prompt dialogs
|
|
159
160
|
import 'reifyui/styles/agent-chat.css'; // reifyui/agent-chat: the agent conversation
|
|
161
|
+
import 'reifyui/styles/tree.css'; // reifyui/tree: the file tree
|
|
160
162
|
```
|
|
161
163
|
|
|
162
164
|
Themes are CSS-variable files — load one, or switch at runtime by toggling which you apply. Override
|
|
@@ -231,6 +233,47 @@ into a kind, a target, lines added and removed, and the plan; a browser call rea
|
|
|
231
233
|
the logos: pass your mark as a node and `motionFor(base)` names a motion, or none for three dots.
|
|
232
234
|
All motion stops under `prefers-reduced-motion`.
|
|
233
235
|
|
|
236
|
+
## File tree
|
|
237
|
+
|
|
238
|
+
`reifyui/tree` is a folder tree of files the way an editor's Explorer shows one. It draws a flat
|
|
239
|
+
list of paths (folders are implied by the files in them; a `dir` entry keeps an empty one) and
|
|
240
|
+
reports what the person did; your list changes and comes back in.
|
|
241
|
+
|
|
242
|
+
```jsx
|
|
243
|
+
import { FileTree } from 'reifyui/tree';
|
|
244
|
+
import 'reifyui/styles/tree.css';
|
|
245
|
+
|
|
246
|
+
<FileTree
|
|
247
|
+
title="Snippets"
|
|
248
|
+
entries={[{ path: 'tasks/refund', kind: 'file' }, { path: 'drafts', kind: 'dir' }]}
|
|
249
|
+
selected={open} onSelect={(path, kind) => kind === 'file' && setOpen(path)}
|
|
250
|
+
labels={{ newFile: 'New snippet', newFileInput: 'Name of the new snippet' }}
|
|
251
|
+
onCreate={({ path, kind }) => api.create(path, kind)} // a returned string is shown under the name
|
|
252
|
+
onRename={({ from, to }) => api.rename(from, to)}
|
|
253
|
+
onDelete={({ path, kind }) => api.remove(path, kind)}
|
|
254
|
+
onMove={({ from, toDir }) => api.move(from, toDir)}
|
|
255
|
+
onUpload={(dir) => pickFilesInto(dir)} // your own file picker
|
|
256
|
+
validateName={(name) => (name.length > 64 ? 'Use 64 characters or fewer.' : '')}
|
|
257
|
+
menuItems={[{ id: 'include', label: 'Copy include line', when: (p, kind) => kind === 'file',
|
|
258
|
+
onSelect: (p) => copy(`{{template "${p}" .}}`) }]}
|
|
259
|
+
/>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The header holds the title and, beside it, New file, New folder, Upload and Collapse all (only the
|
|
263
|
+
ones whose handler you pass; `actions` picks fewer). New file and New folder open a name field in the
|
|
264
|
+
folder in use: Enter keeps it, Escape puts it away, leaving the field keeps a valid name. `''`, `.`,
|
|
265
|
+
`..`, a slash and a name already in that folder are refused before `validateName` is asked. F2 or the
|
|
266
|
+
row's pencil renames in place; Delete asks in the row ("Delete tasks and the 3 files in it?"); a row
|
|
267
|
+
drags into another folder or the top, never into itself. A right click, Shift+F10 or the menu key
|
|
268
|
+
opens the row's menu. Arrow keys, Home and End move; Right and Left open, close and step in and out.
|
|
269
|
+
A handler may return a message, or a Promise of one, to refuse: it shows where the person acted.
|
|
270
|
+
|
|
271
|
+
`open` + `onOpenChange` control the open folders (`defaultOpen` otherwise: every folder, or a list).
|
|
272
|
+
`readOnly` draws the tree with nothing to change. `busy`, `pending` (paths with a save in flight),
|
|
273
|
+
`rowErrors` and `error` show what the host is doing. Every word is in `labels`. The model it runs on
|
|
274
|
+
(`buildFileTree`, `visibleRows`, `treeKeyAction`, `nameProblem`, `canMove`) needs no React, so a
|
|
275
|
+
host can check a name or a move by the same rules. Colours come from `--uic-*` (or `--rui-tree-*`).
|
|
276
|
+
|
|
234
277
|
## Slides
|
|
235
278
|
|
|
236
279
|
A deck is JSON — a fixed 1920×1080 stage, and elements with absolute frames and stable ids. That
|
package/dist/chart.js
CHANGED
|
@@ -1,66 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
safeChartOption,
|
|
3
|
+
safeHref
|
|
4
|
+
} from "./chunk-FPLC5KAD.js";
|
|
1
5
|
import "./chunk-PZ5AY32C.js";
|
|
2
6
|
|
|
3
7
|
// src/chart/Chart.jsx
|
|
4
8
|
import { useEffect, useRef, useState } from "react";
|
|
5
|
-
|
|
6
|
-
// src/chart/safe.js
|
|
7
|
-
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
8
|
-
function safeHref(v) {
|
|
9
|
-
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, "")) ? v : "";
|
|
10
|
-
}
|
|
11
|
-
var ESC = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
12
|
-
var esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
|
|
13
|
-
var isPlain = (v) => {
|
|
14
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
15
|
-
const p = Object.getPrototypeOf(v);
|
|
16
|
-
return p === Object.prototype || p === null;
|
|
17
|
-
};
|
|
18
|
-
function safeChartOption(option) {
|
|
19
|
-
if (!isPlain(option) && !Array.isArray(option)) return option;
|
|
20
|
-
const seen = /* @__PURE__ */ new Map();
|
|
21
|
-
const escaped = /* @__PURE__ */ new Set();
|
|
22
|
-
const walk = (n) => {
|
|
23
|
-
if (Array.isArray(n)) {
|
|
24
|
-
if (seen.has(n)) return seen.get(n);
|
|
25
|
-
const out2 = [];
|
|
26
|
-
seen.set(n, out2);
|
|
27
|
-
for (const x of n) out2.push(walk(x));
|
|
28
|
-
return out2;
|
|
29
|
-
}
|
|
30
|
-
if (!isPlain(n)) return n;
|
|
31
|
-
if (seen.has(n)) return seen.get(n);
|
|
32
|
-
const out = {};
|
|
33
|
-
seen.set(n, out);
|
|
34
|
-
for (const k of Object.keys(n)) {
|
|
35
|
-
const v = n[k];
|
|
36
|
-
if ((k === "link" || k === "sublink") && typeof v === "string") {
|
|
37
|
-
if (safeHref(v)) out[k] = v;
|
|
38
|
-
} else if (k === "tooltip") {
|
|
39
|
-
out[k] = tooltip(v);
|
|
40
|
-
} else if (k === "dataView" && isPlain(v)) {
|
|
41
|
-
out[k] = dataView(walk(v));
|
|
42
|
-
} else {
|
|
43
|
-
out[k] = walk(v);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
};
|
|
48
|
-
const tooltip = (v) => {
|
|
49
|
-
if (v === true) return { renderMode: "richText" };
|
|
50
|
-
if (Array.isArray(v)) return v.map((t) => isPlain(t) ? { ...walk(t), renderMode: "richText" } : walk(t));
|
|
51
|
-
return isPlain(v) ? { ...walk(v), renderMode: "richText" } : walk(v);
|
|
52
|
-
};
|
|
53
|
-
const dataView = (d) => {
|
|
54
|
-
if (escaped.has(d)) return d;
|
|
55
|
-
escaped.add(d);
|
|
56
|
-
if (typeof d.title === "string") d.title = esc(d.title);
|
|
57
|
-
if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => typeof s === "string" ? esc(s) : s);
|
|
58
|
-
return d;
|
|
59
|
-
};
|
|
60
|
-
return walk(option);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/chart/Chart.jsx
|
|
64
9
|
import { jsx } from "react/jsx-runtime";
|
|
65
10
|
function applyOption(chart, option, notMerge) {
|
|
66
11
|
chart.setOption(safeChartOption(option), notMerge);
|
package/dist/chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chart/Chart.jsx","../src/chart/safe.js","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\nimport { safeChartOption } from './safe.js';\n\n// Every option reaches ECharts through here, made inert first (safe.js): a tooltip draws text, a link is http(s) or\n// mailto, the data view's words are escaped. An option a host sets on the instance it got from onInit is its own.\nexport function applyOption(chart, option, notMerge) {\n chart.setOption(safeChartOption(option), notMerge);\n}\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { applyOption(chart, opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n applyOption(inst.current, option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// An ECharts option can come from anywhere (a person, a saved dashboard, an agent writing it), so the chart keeps it\n// inert before ECharts sees it (found 2026-11-10). ECharts writes some option strings into the page as HTML or opens\n// them as URLs:\n// - a tooltip's content (its formatter, series and data names) in the default HTML render mode;\n// - a title's link / sublink and a sunburst or treemap node's link, opened in a window that keeps the page's origin;\n// - the data view's title and button labels (toolbox.feature.dataView.title / lang).\n// So every tooltip draws in the chart itself (renderMode 'richText': text, never markup), a link is kept only when it is\n// http(s) or mailto, and the data view's words are escaped. The option passed in is never changed: plain objects and\n// arrays are copied, anything else (functions, typed arrays, dates, gradient objects) is passed through as it is.\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:)/i;\n\nexport function safeHref(v) {\n return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\\u0000- \\u007f]/g, '')) ? v : '';\n}\n\nconst ESC = { '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' };\nconst esc = (s) => String(s).replace(/[&<>\"']/g, (c) => ESC[c]);\n\nconst isPlain = (v) => {\n if (!v || typeof v !== 'object' || Array.isArray(v)) return false;\n const p = Object.getPrototypeOf(v);\n return p === Object.prototype || p === null;\n};\n\nexport function safeChartOption(option) {\n if (!isPlain(option) && !Array.isArray(option)) return option;\n const seen = new Map();\n const escaped = new Set();\n const walk = (n) => {\n if (Array.isArray(n)) {\n if (seen.has(n)) return seen.get(n);\n const out = []; seen.set(n, out);\n for (const x of n) out.push(walk(x));\n return out;\n }\n if (!isPlain(n)) return n;\n if (seen.has(n)) return seen.get(n);\n const out = {}; seen.set(n, out);\n for (const k of Object.keys(n)) {\n const v = n[k];\n if ((k === 'link' || k === 'sublink') && typeof v === 'string') {\n if (safeHref(v)) out[k] = v;\n } else if (k === 'tooltip') {\n out[k] = tooltip(v);\n } else if (k === 'dataView' && isPlain(v)) {\n out[k] = dataView(walk(v));\n } else {\n out[k] = walk(v);\n }\n }\n return out;\n };\n const tooltip = (v) => {\n if (v === true) return { renderMode: 'richText' };\n if (Array.isArray(v)) return v.map((t) => (isPlain(t) ? { ...walk(t), renderMode: 'richText' } : walk(t)));\n return isPlain(v) ? { ...walk(v), renderMode: 'richText' } : walk(v);\n };\n const dataView = (d) => {\n if (escaped.has(d)) return d; // the same data view reached twice: escape once\n escaped.add(d);\n if (typeof d.title === 'string') d.title = esc(d.title);\n if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => (typeof s === 'string' ? esc(s) : s));\n return d;\n };\n return walk(option);\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\n}\n"],"mappings":";;;AAYA,SAAS,WAAW,QAAQ,gBAAgB;;;ACH5C,IAAM,YAAY;AAEX,SAAS,SAAS,GAAG;AAC1B,SAAO,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,QAAQ,qBAAqB,EAAE,CAAC,IAAI,IAAI;AAC3F;AAEA,IAAM,MAAM,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,UAAU,KAAK,QAAQ;AAClF,IAAM,MAAM,CAAC,MAAM,OAAO,CAAC,EAAE,QAAQ,YAAY,CAAC,MAAM,IAAI,C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","../src/chart/useChartTokens.js"],"sourcesContent":["// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\nimport { safeChartOption } from './safe.js';\n\n// Every option reaches ECharts through here, made inert first (safe.js): a tooltip draws text, a link is http(s) or\n// mailto, the data view's words are escaped. An option a host sets on the instance it got from onInit is its own.\nexport function applyOption(chart, option, notMerge) {\n chart.setOption(safeChartOption(option), notMerge);\n}\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { applyOption(chart, opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n applyOption(inst.current, option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\n}\n"],"mappings":";;;;;;;AAYA,SAAS,WAAW,QAAQ,gBAAgB;AA2EvB;AAtEd,SAAS,YAAY,OAAO,QAAQ,UAAU;AACnD,QAAM,UAAU,gBAAgB,MAAM,GAAG,QAAQ;AACnD;AAYO,SAAS,MAAM,OAAO;AAC3B,QAAM,EAAE,QAAQ,WAAW,UAAU,WAAW,MAAM,QAAQ,OAAO,WAAW,MAAM,YAAY,GAAG,IAAI;AACzG,QAAM,OAAO,OAAO,IAAI;AACxB,QAAM,OAAO,OAAO,IAAI;AACxB,QAAM,UAAU,OAAO,IAAI;AAC3B,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,KAAK;AAG1C,QAAM,SAAS,OAAO,EAAE,QAAQ,UAAU,OAAO,CAAC;AAClD,SAAO,UAAU,EAAE,QAAQ,UAAU,OAAO;AAE5C,YAAU,MAAM;AACd,QAAI,OAAO;AACX,KAAC,YAAY;AACX,UAAI;AACF,cAAM,MAAM,MAAM,OAAO,SAAS;AAClC,cAAM,UAAU,OAAO,IAAI,SAAS,aAAa,MAAO,IAAI,WAAW;AACvE,YAAI,QAAQ,CAAC,KAAK,QAAS;AAC3B,cAAM,QAAQ,QAAQ,KAAK,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IAC5C,IAAI,KAAK,GAAG,YAAY,SAAS,EAAE;AAAA,IACnC,MAAM,KAAK,GAAG,cAAc,SAAS,IAAI;AAAA,IACzC,KAAK,KAAK,GAAG,kBAAkB,SAAS,GAAG;AAAA,IAC3C,MAAM,KAAK,GAAG,cAAc,SAAS,IAAI;AAAA,EAC3C;AACF;;;ACnDA,SAAS,aAAa,aAAAA,YAAW,UAAAC,SAAQ,YAAAC,iBAAgB;AAclD,SAAS,iBAAiB;AAC/B,QAAM,MAAMC,QAAO,IAAI;AACvB,QAAM,CAAC,QAAQ,SAAS,IAAIC,UAAS,MAAM,YAAY,IAAI,CAAC;AAC5D,QAAM,SAAS,YAAY,MAAM,UAAU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AAExE,EAAAC,WAAU,MAAM;AACd,WAAO;AACP,QAAI,OAAO,qBAAqB,WAAY,QAAO;AACnD,UAAM,MAAM,IAAI,iBAAiB,MAAM;AACvC,UAAM,OAAO,EAAE,YAAY,MAAM,iBAAiB,CAAC,SAAS,SAAS,YAAY,EAAE;AACnF,QAAI,QAAQ,SAAS,iBAAiB,IAAI;AAC1C,QAAI,SAAS,KAAM,KAAI,QAAQ,SAAS,MAAM,IAAI;AAClD,UAAM,KAAK,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;AAC3F,QAAI,mBAAmB,UAAU,MAAM;AACvC,WAAO,MAAM;AAAE,UAAI,WAAW;AAAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["useEffect","useRef","useState","useRef","useState","useEffect"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/chart/safe.js
|
|
2
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
3
|
+
function safeHref(v) {
|
|
4
|
+
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, "")) ? v : "";
|
|
5
|
+
}
|
|
6
|
+
var ESC = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
7
|
+
var esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
|
|
8
|
+
var isPlain = (v) => {
|
|
9
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
10
|
+
const p = Object.getPrototypeOf(v);
|
|
11
|
+
return p === Object.prototype || p === null;
|
|
12
|
+
};
|
|
13
|
+
function safeChartOption(option) {
|
|
14
|
+
if (!isPlain(option) && !Array.isArray(option)) return option;
|
|
15
|
+
const seen = /* @__PURE__ */ new Map();
|
|
16
|
+
const escaped = /* @__PURE__ */ new Set();
|
|
17
|
+
const walk = (n) => {
|
|
18
|
+
if (Array.isArray(n)) {
|
|
19
|
+
if (seen.has(n)) return seen.get(n);
|
|
20
|
+
const out2 = [];
|
|
21
|
+
seen.set(n, out2);
|
|
22
|
+
for (const x of n) out2.push(walk(x));
|
|
23
|
+
return out2;
|
|
24
|
+
}
|
|
25
|
+
if (!isPlain(n)) return n;
|
|
26
|
+
if (seen.has(n)) return seen.get(n);
|
|
27
|
+
const out = {};
|
|
28
|
+
seen.set(n, out);
|
|
29
|
+
for (const k of Object.keys(n)) {
|
|
30
|
+
const v = n[k];
|
|
31
|
+
if ((k === "link" || k === "sublink") && typeof v === "string") {
|
|
32
|
+
if (safeHref(v)) out[k] = v;
|
|
33
|
+
} else if (k === "tooltip") {
|
|
34
|
+
out[k] = tooltip(v);
|
|
35
|
+
} else if (k === "dataView" && isPlain(v)) {
|
|
36
|
+
out[k] = dataView(walk(v));
|
|
37
|
+
} else {
|
|
38
|
+
out[k] = walk(v);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
const tooltip = (v) => {
|
|
44
|
+
if (v === true) return { renderMode: "richText" };
|
|
45
|
+
if (Array.isArray(v)) return v.map((t) => isPlain(t) ? { ...walk(t), renderMode: "richText" } : walk(t));
|
|
46
|
+
return isPlain(v) ? { ...walk(v), renderMode: "richText" } : walk(v);
|
|
47
|
+
};
|
|
48
|
+
const dataView = (d) => {
|
|
49
|
+
if (escaped.has(d)) return d;
|
|
50
|
+
escaped.add(d);
|
|
51
|
+
if (typeof d.title === "string") d.title = esc(d.title);
|
|
52
|
+
if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => typeof s === "string" ? esc(s) : s);
|
|
53
|
+
return d;
|
|
54
|
+
};
|
|
55
|
+
return walk(option);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
safeHref,
|
|
60
|
+
safeChartOption
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-FPLC5KAD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/chart/safe.js"],"sourcesContent":["// An ECharts option can come from anywhere (a person, a saved dashboard, an agent writing it), so the chart keeps it\n// inert before ECharts sees it (found 2026-11-10). ECharts writes some option strings into the page as HTML or opens\n// them as URLs:\n// - a tooltip's content (its formatter, series and data names) in the default HTML render mode;\n// - a title's link / sublink and a sunburst or treemap node's link, opened in a window that keeps the page's origin;\n// - the data view's title and button labels (toolbox.feature.dataView.title / lang).\n// So every tooltip draws in the chart itself (renderMode 'richText': text, never markup), a link is kept only when it is\n// http(s) or mailto, and the data view's words are escaped. The option passed in is never changed: plain objects and\n// arrays are copied, anything else (functions, typed arrays, dates, gradient objects) is passed through as it is.\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:)/i;\n\nexport function safeHref(v) {\n return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\\u0000- \\u007f]/g, '')) ? v : '';\n}\n\nconst ESC = { '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' };\nconst esc = (s) => String(s).replace(/[&<>\"']/g, (c) => ESC[c]);\n\nconst isPlain = (v) => {\n if (!v || typeof v !== 'object' || Array.isArray(v)) return false;\n const p = Object.getPrototypeOf(v);\n return p === Object.prototype || p === null;\n};\n\nexport function safeChartOption(option) {\n if (!isPlain(option) && !Array.isArray(option)) return option;\n const seen = new Map();\n const escaped = new Set();\n const walk = (n) => {\n if (Array.isArray(n)) {\n if (seen.has(n)) return seen.get(n);\n const out = []; seen.set(n, out);\n for (const x of n) out.push(walk(x));\n return out;\n }\n if (!isPlain(n)) return n;\n if (seen.has(n)) return seen.get(n);\n const out = {}; seen.set(n, out);\n for (const k of Object.keys(n)) {\n const v = n[k];\n if ((k === 'link' || k === 'sublink') && typeof v === 'string') {\n if (safeHref(v)) out[k] = v;\n } else if (k === 'tooltip') {\n out[k] = tooltip(v);\n } else if (k === 'dataView' && isPlain(v)) {\n out[k] = dataView(walk(v));\n } else {\n out[k] = walk(v);\n }\n }\n return out;\n };\n const tooltip = (v) => {\n if (v === true) return { renderMode: 'richText' };\n if (Array.isArray(v)) return v.map((t) => (isPlain(t) ? { ...walk(t), renderMode: 'richText' } : walk(t)));\n return isPlain(v) ? { ...walk(v), renderMode: 'richText' } : walk(v);\n };\n const dataView = (d) => {\n if (escaped.has(d)) return d; // the same data view reached twice: escape once\n escaped.add(d);\n if (typeof d.title === 'string') d.title = esc(d.title);\n if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => (typeof s === 'string' ? esc(s) : s));\n return d;\n };\n return walk(option);\n}\n"],"mappings":";AASA,IAAM,YAAY;AAEX,SAAS,SAAS,GAAG;AAC1B,SAAO,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,QAAQ,qBAAqB,EAAE,CAAC,IAAI,IAAI;AAC3F;AAEA,IAAM,MAAM,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,UAAU,KAAK,QAAQ;AAClF,IAAM,MAAM,CAAC,MAAM,OAAO,CAAC,EAAE,QAAQ,YAAY,CAAC,MAAM,IAAI,CAAC,CAAC;AAE9D,IAAM,UAAU,CAAC,MAAM;AACrB,MAAI,CAAC,KAAK,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,EA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,EAAG,QAAO,EAAE,IAAI,CAAC,MAAO,QAAQ,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,YAAY,WAAW,IAAI,KAAK,CAAC,CAAE;AACzG,WAAO,QAAQ,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,YAAY,WAAW,IAAI,KAAK,CAAC;AAAA,EACrE;AACA,QAAM,WAAW,CAAC,MAAM;AACtB,QAAI,QAAQ,IAAI,CAAC,EAAG,QAAO;AAC3B,YAAQ,IAAI,CAAC;AACb,QAAI,OAAO,EAAE,UAAU,SAAU,GAAE,QAAQ,IAAI,EAAE,KAAK;AACtD,QAAI,MAAM,QAAQ,EAAE,IAAI,EAAG,GAAE,OAAO,EAAE,KAAK,IAAI,CAAC,MAAO,OAAO,MAAM,WAAW,IAAI,CAAC,IAAI,CAAE;AAC1F,WAAO;AAAA,EACT;AACA,SAAO,KAAK,MAAM;AACpB;","names":["out"]}
|
package/dist/graph.cjs
CHANGED
|
@@ -1525,6 +1525,7 @@ function KeyRow({ k, onRevoke }) {
|
|
|
1525
1525
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.KeyRound, { size: 13, "aria-hidden": "true" }),
|
|
1526
1526
|
k.name || "\u2014"
|
|
1527
1527
|
] }),
|
|
1528
|
+
k.read_only && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "pill brand cn-key-ro", title: "Agents with this key can read but not change anything", children: "Read only" }),
|
|
1528
1529
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono cn-key-prefix", children: k.prefix ? `${k.prefix}\u2026` : "\u2014" }),
|
|
1529
1530
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "cn-key-meta", children: [
|
|
1530
1531
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-key-lbl", children: "Created" }),
|
|
@@ -1584,6 +1585,7 @@ function ConnectionCard({ url, keys, expanded, onToggle, onCreateKey, onRevoke }
|
|
|
1584
1585
|
}
|
|
1585
1586
|
function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
|
|
1586
1587
|
const [name, setName] = (0, import_react9.useState)("");
|
|
1588
|
+
const [readOnly, setReadOnly] = (0, import_react9.useState)(false);
|
|
1587
1589
|
const ref = (0, import_react9.useRef)(null);
|
|
1588
1590
|
(0, import_react9.useEffect)(() => {
|
|
1589
1591
|
ref.current?.focus();
|
|
@@ -1593,7 +1595,7 @@ function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
|
|
|
1593
1595
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-dlg-body", children: "Name the key after the agent or place that will use it, so you can tell keys apart later." }),
|
|
1594
1596
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: (e) => {
|
|
1595
1597
|
e.preventDefault();
|
|
1596
|
-
if (ok && !busy) onSubmit(name.trim());
|
|
1598
|
+
if (ok && !busy) onSubmit(name.trim(), readOnly);
|
|
1597
1599
|
}, children: [
|
|
1598
1600
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1599
1601
|
"input",
|
|
@@ -1606,6 +1608,13 @@ function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
|
|
|
1606
1608
|
maxLength: 80
|
|
1607
1609
|
}
|
|
1608
1610
|
),
|
|
1611
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "cn-ro-opt", children: [
|
|
1612
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("input", { type: "checkbox", checked: readOnly, disabled: busy, onChange: (e) => setReadOnly(e.target.checked) }),
|
|
1613
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1614
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-ro-title", children: "Read only" }),
|
|
1615
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-ro-hint", children: "Agents with this key can read your data but can't change or delete anything. This can't be changed later." })
|
|
1616
|
+
] })
|
|
1617
|
+
] }),
|
|
1609
1618
|
error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-err", children: error }),
|
|
1610
1619
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-foot", children: [
|
|
1611
1620
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn", onClick: onClose, disabled: busy, children: "Cancel" }),
|
|
@@ -1616,7 +1625,10 @@ function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
|
|
|
1616
1625
|
}
|
|
1617
1626
|
function SecretDialog({ secret, onClose }) {
|
|
1618
1627
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Modal, { open: true, onClose, title: "Your new API key", width: 480, classNames: { root: "cn-dlg" }, children: [
|
|
1619
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.
|
|
1628
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-body", children: [
|
|
1629
|
+
"Copy this key now and store it somewhere safe. For your security, it will not be shown again.",
|
|
1630
|
+
secret.read_only && " This key can only read."
|
|
1631
|
+
] }),
|
|
1620
1632
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-secret", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono", children: secret.key }) }),
|
|
1621
1633
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-foot", children: [
|
|
1622
1634
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopyButton, { text: secret.key, label: "Copy key", sm: false }),
|
|
@@ -1878,11 +1890,25 @@ function ConnectPane({ graphId, liveRegistry, client }) {
|
|
|
1878
1890
|
setConfirmBusy(false);
|
|
1879
1891
|
}
|
|
1880
1892
|
};
|
|
1881
|
-
const doCreateKey = async (name) => {
|
|
1893
|
+
const doCreateKey = async (name, readOnly) => {
|
|
1882
1894
|
setCreateBusy(true);
|
|
1883
1895
|
setCreateError("");
|
|
1884
1896
|
try {
|
|
1885
|
-
const minted = await client.createConnectKey(graphId, name);
|
|
1897
|
+
const minted = await client.createConnectKey(graphId, name, { readOnly });
|
|
1898
|
+
if (readOnly && minted?.read_only !== true) {
|
|
1899
|
+
let gone = true;
|
|
1900
|
+
try {
|
|
1901
|
+
await client.revokeConnectKey(graphId, minted.id);
|
|
1902
|
+
} catch {
|
|
1903
|
+
gone = false;
|
|
1904
|
+
}
|
|
1905
|
+
const list = await client.listConnectKeys(graphId);
|
|
1906
|
+
setKeys(list);
|
|
1907
|
+
if (gone) throw new Error("Read-only keys aren\u2019t available yet. No key was created.");
|
|
1908
|
+
const row = list.find((k) => k.id === minted.id);
|
|
1909
|
+
const mark = row?.prefix ? `${row.prefix}\u2026` : minted.id;
|
|
1910
|
+
throw new Error(`Read-only keys aren\u2019t available yet. Revoke the key \u201C${name}\u201D (${mark}) from the list.`);
|
|
1911
|
+
}
|
|
1886
1912
|
setCreatingKey(false);
|
|
1887
1913
|
setSecret(minted);
|
|
1888
1914
|
setKeys(await client.listConnectKeys(graphId));
|