reifyui 0.18.3 → 0.18.5
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/chart.cjs +66 -2
- package/dist/chart.cjs.map +1 -1
- package/dist/chart.d.ts +8 -0
- package/dist/chart.js +11 -2
- 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/package.json +1 -1
- package/src/chart/Chart.jsx +9 -2
- package/src/chart/index.d.ts +8 -0
- package/src/chart/index.js +2 -0
- package/src/chart/safe.js +66 -0
- package/src/graph/ConnectPane.jsx +28 -3
- package/src/graph/index.d.ts +2 -1
- package/src/slides/elements.jsx +7 -11
- package/styles/graph.css +18 -1
package/dist/chart.cjs
CHANGED
|
@@ -31,13 +31,77 @@ var chart_exports = {};
|
|
|
31
31
|
__export(chart_exports, {
|
|
32
32
|
Chart: () => Chart,
|
|
33
33
|
chartTokens: () => chartTokens,
|
|
34
|
+
safeChartOption: () => safeChartOption,
|
|
35
|
+
safeHref: () => safeHref,
|
|
34
36
|
useChartTokens: () => useChartTokens
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(chart_exports);
|
|
37
39
|
|
|
38
40
|
// src/chart/Chart.jsx
|
|
39
41
|
var import_react = require("react");
|
|
42
|
+
|
|
43
|
+
// src/chart/safe.js
|
|
44
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
45
|
+
function safeHref(v) {
|
|
46
|
+
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, "")) ? v : "";
|
|
47
|
+
}
|
|
48
|
+
var ESC = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
49
|
+
var esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
|
|
50
|
+
var isPlain = (v) => {
|
|
51
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
52
|
+
const p = Object.getPrototypeOf(v);
|
|
53
|
+
return p === Object.prototype || p === null;
|
|
54
|
+
};
|
|
55
|
+
function safeChartOption(option) {
|
|
56
|
+
if (!isPlain(option) && !Array.isArray(option)) return option;
|
|
57
|
+
const seen = /* @__PURE__ */ new Map();
|
|
58
|
+
const escaped = /* @__PURE__ */ new Set();
|
|
59
|
+
const walk = (n) => {
|
|
60
|
+
if (Array.isArray(n)) {
|
|
61
|
+
if (seen.has(n)) return seen.get(n);
|
|
62
|
+
const out2 = [];
|
|
63
|
+
seen.set(n, out2);
|
|
64
|
+
for (const x of n) out2.push(walk(x));
|
|
65
|
+
return out2;
|
|
66
|
+
}
|
|
67
|
+
if (!isPlain(n)) return n;
|
|
68
|
+
if (seen.has(n)) return seen.get(n);
|
|
69
|
+
const out = {};
|
|
70
|
+
seen.set(n, out);
|
|
71
|
+
for (const k of Object.keys(n)) {
|
|
72
|
+
const v = n[k];
|
|
73
|
+
if ((k === "link" || k === "sublink") && typeof v === "string") {
|
|
74
|
+
if (safeHref(v)) out[k] = v;
|
|
75
|
+
} else if (k === "tooltip") {
|
|
76
|
+
out[k] = tooltip(v);
|
|
77
|
+
} else if (k === "dataView" && isPlain(v)) {
|
|
78
|
+
out[k] = dataView(walk(v));
|
|
79
|
+
} else {
|
|
80
|
+
out[k] = walk(v);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
};
|
|
85
|
+
const tooltip = (v) => {
|
|
86
|
+
if (v === true) return { renderMode: "richText" };
|
|
87
|
+
if (Array.isArray(v)) return v.map((t) => isPlain(t) ? { ...walk(t), renderMode: "richText" } : walk(t));
|
|
88
|
+
return isPlain(v) ? { ...walk(v), renderMode: "richText" } : walk(v);
|
|
89
|
+
};
|
|
90
|
+
const dataView = (d) => {
|
|
91
|
+
if (escaped.has(d)) return d;
|
|
92
|
+
escaped.add(d);
|
|
93
|
+
if (typeof d.title === "string") d.title = esc(d.title);
|
|
94
|
+
if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => typeof s === "string" ? esc(s) : s);
|
|
95
|
+
return d;
|
|
96
|
+
};
|
|
97
|
+
return walk(option);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/chart/Chart.jsx
|
|
40
101
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
102
|
+
function applyOption(chart, option, notMerge) {
|
|
103
|
+
chart.setOption(safeChartOption(option), notMerge);
|
|
104
|
+
}
|
|
41
105
|
function Chart(props) {
|
|
42
106
|
const { option, renderer = "canvas", notMerge = true, onInit, label, fallback = null, className = "" } = props;
|
|
43
107
|
const host = (0, import_react.useRef)(null);
|
|
@@ -57,7 +121,7 @@ function Chart(props) {
|
|
|
57
121
|
inst.current = chart;
|
|
58
122
|
const { option: opt, notMerge: nm, onInit: cb } = latest.current;
|
|
59
123
|
if (opt) {
|
|
60
|
-
chart
|
|
124
|
+
applyOption(chart, opt, nm);
|
|
61
125
|
applied.current = opt;
|
|
62
126
|
}
|
|
63
127
|
if (cb) cb(chart);
|
|
@@ -77,7 +141,7 @@ function Chart(props) {
|
|
|
77
141
|
}, [renderer]);
|
|
78
142
|
(0, import_react.useEffect)(() => {
|
|
79
143
|
if (!inst.current || !option || applied.current === option) return;
|
|
80
|
-
inst.current
|
|
144
|
+
applyOption(inst.current, option, notMerge);
|
|
81
145
|
applied.current = option;
|
|
82
146
|
}, [option, notMerge]);
|
|
83
147
|
(0, import_react.useEffect)(() => {
|
package/dist/chart.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chart/index.js","../src/chart/Chart.jsx","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// The chart entry — IMPORT VIA SUBPATH ONLY ('reifyui/chart'), never from the root index.\n//\n// echarts is an optional peer and loads lazily inside Chart. A root re-export would put it in the\n// dependency graph of every consumer, so an app that renders a Button and no chart would have to\n// resolve a charting library to build. Same rule, same reason, as 'reifyui/slides'.\nexport { Chart } from './Chart.jsx';\n// The theme as strings a chart option can hold — series colours, axis ink, tooltip chrome. CSS\n// variables do not reach inside a canvas; these do.\nexport { chartTokens } from './tokens.js';\nexport { useChartTokens } from './useChartTokens.js';\n","// 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';\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) { chart.setOption(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 inst.current.setOption(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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,mBAA4C;AAoEvB;AAxDd,SAAS,MAAM,OAAO;AAC3B,QAAM,EAAE,QAAQ,WAAW,UAAU,WAAW,MAAM,QAAQ,OAAO,WAAW,MAAM,YAAY,GAAG,IAAI;AACzG,QAAM,WAAO,qBAAO,IAAI;AACxB,QAAM,WAAO,qBAAO,IAAI;AACxB,QAAM,cAAU,qBAAO,IAAI;AAC3B,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,KAAK;AAG1C,QAAM,aAAS,qBAAO,EAAE,QAAQ,UAAU,OAAO,CAAC;AAClD,SAAO,UAAU,EAAE,QAAQ,UAAU,OAAO;AAE5C,8BAAU,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;AAC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iB,SAAS,OAAO;AAAA,IAClD,OAAO,KAAK,GAAG,eAAe,SAAS,KAAK;AAAA,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,IAAAA,gBAAyD;AAclD,SAAS,iBAAiB;AAC/B,QAAM,UAAM,sBAAO,IAAI;AACvB,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAAS,MAAM,YAAY,IAAI,CAAC;AAC5D,QAAM,aAAS,2BAAY,MAAM,UAAU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AAExE,+BAAU,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":["import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/chart/index.js","../src/chart/Chart.jsx","../src/chart/safe.js","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// The chart entry — IMPORT VIA SUBPATH ONLY ('reifyui/chart'), never from the root index.\n//\n// echarts is an optional peer and loads lazily inside Chart. A root re-export would put it in the\n// dependency graph of every consumer, so an app that renders a Button and no chart would have to\n// resolve a charting library to build. Same rule, same reason, as 'reifyui/slides'.\nexport { Chart } from './Chart.jsx';\n// What the chart does to every option before ECharts sees it, for a host that sets options on the instance itself.\nexport { safeChartOption, safeHref } from './safe.js';\n// The theme as strings a chart option can hold — series colours, axis ink, tooltip chrome. CSS\n// variables do not reach inside a canvas; these do.\nexport { chartTokens } from './tokens.js';\nexport { useChartTokens } from './useChartTokens.js';\n","// 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,mBAA4C;;;ACH5C,IAAM,YAAY;AAEX,SAAS,SAAS,GAAG;AAC1B,SAAO,OAAO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AAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["out","import_react"]}
|
package/dist/chart.d.ts
CHANGED
|
@@ -55,3 +55,11 @@ export function chartTokens(el?: Element | null): ChartTokens;
|
|
|
55
55
|
/** chartTokens(), re-read when the theme changes (a class/data-* flip on <html> or <body>, or the
|
|
56
56
|
* OS preference). Put the returned ref on the element the chart lives in. */
|
|
57
57
|
export function useChartTokens(): [ChartTokens, RefObject<HTMLElement | null>];
|
|
58
|
+
|
|
59
|
+
/** A copy of an option with what ECharts would write as HTML or open as a URL made inert: every tooltip draws text
|
|
60
|
+
* (renderMode 'richText'), a link or sublink is kept only for http(s) or mailto, and the data view's title and labels
|
|
61
|
+
* are escaped. Chart applies it to every option; call it yourself before setOption on the instance from onInit. */
|
|
62
|
+
export function safeChartOption<T>(option: T): T;
|
|
63
|
+
/** The value when it is an http(s) or mailto URL, else ''. */
|
|
64
|
+
export function safeHref(value: unknown): string;
|
|
65
|
+
|
package/dist/chart.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
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
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
function applyOption(chart, option, notMerge) {
|
|
11
|
+
chart.setOption(safeChartOption(option), notMerge);
|
|
12
|
+
}
|
|
6
13
|
function Chart(props) {
|
|
7
14
|
const { option, renderer = "canvas", notMerge = true, onInit, label, fallback = null, className = "" } = props;
|
|
8
15
|
const host = useRef(null);
|
|
@@ -22,7 +29,7 @@ function Chart(props) {
|
|
|
22
29
|
inst.current = chart;
|
|
23
30
|
const { option: opt, notMerge: nm, onInit: cb } = latest.current;
|
|
24
31
|
if (opt) {
|
|
25
|
-
chart
|
|
32
|
+
applyOption(chart, opt, nm);
|
|
26
33
|
applied.current = opt;
|
|
27
34
|
}
|
|
28
35
|
if (cb) cb(chart);
|
|
@@ -42,7 +49,7 @@ function Chart(props) {
|
|
|
42
49
|
}, [renderer]);
|
|
43
50
|
useEffect(() => {
|
|
44
51
|
if (!inst.current || !option || applied.current === option) return;
|
|
45
|
-
inst.current
|
|
52
|
+
applyOption(inst.current, option, notMerge);
|
|
46
53
|
applied.current = option;
|
|
47
54
|
}, [option, notMerge]);
|
|
48
55
|
useEffect(() => {
|
|
@@ -135,6 +142,8 @@ function useChartTokens() {
|
|
|
135
142
|
export {
|
|
136
143
|
Chart,
|
|
137
144
|
chartTokens,
|
|
145
|
+
safeChartOption,
|
|
146
|
+
safeHref,
|
|
138
147
|
useChartTokens
|
|
139
148
|
};
|
|
140
149
|
//# sourceMappingURL=chart.js.map
|
package/dist/chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chart/Chart.jsx","../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';\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) { chart.setOption(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 inst.current.setOption(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;AAoEvB;AAxDd,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,OA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,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/chart/Chart.jsx","../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","// 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,UAA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G,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,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W,MAAM,cAAc,QAAQ,CAAC,GAAG;AACzC,YAAI,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC;AAAA,MAC3B,OAAO;AACL,YAAI,CAAC,IAAI,KAAK,CAAC;AAAA,MACjB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,QAAM,UAAU,CAAC,MAAM;AACrB,QAAI,MAAM,KAAM,QAAO,EAAE,YAAY,WAAW;AAChD,QAAI,MAAM,QAAQ,CAAC,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));
|