reifyui 0.11.2 → 0.11.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reifyui",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI — model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
5
5
  "keywords": [
6
6
  "react",
@@ -18,13 +18,13 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "author": "Epsilla",
21
- "homepage": "https://github.com/epsilla-enterprise/ReifyUI#readme",
21
+ "homepage": "https://github.com/HarnessRouter/ReifyUI#readme",
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "git+https://github.com/epsilla-enterprise/ReifyUI.git"
24
+ "url": "git+https://github.com/HarnessRouter/ReifyUI.git"
25
25
  },
26
26
  "bugs": {
27
- "url": "https://github.com/epsilla-enterprise/ReifyUI/issues"
27
+ "url": "https://github.com/HarnessRouter/ReifyUI/issues"
28
28
  },
29
29
  "type": "module",
30
30
  "sideEffects": [
@@ -68,7 +68,8 @@
68
68
  "build": "tsup",
69
69
  "prepublishOnly": "npm run build",
70
70
  "clean": "rm -rf dist",
71
- "prepare": "npm run build"
71
+ "prepare": "npm run build",
72
+ "test": "node test/run.mjs"
72
73
  },
73
74
  "peerDependencies": {
74
75
  "echarts": "^5 || ^6",
@@ -11,6 +11,13 @@
11
11
  // not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports
12
12
  // a Button must not resolve a charting library.
13
13
  import { useEffect, useRef, useState } from 'react';
14
+ import { safeChartOption } from './safe.js';
15
+
16
+ // Every option reaches ECharts through here, made inert first (safe.js): a tooltip draws text, a link is http(s) or
17
+ // mailto, the data view's words are escaped. An option a host sets on the instance it got from onInit is its own.
18
+ export function applyOption(chart, option, notMerge) {
19
+ chart.setOption(safeChartOption(option), notMerge);
20
+ }
14
21
 
15
22
  /**
16
23
  * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a
@@ -43,7 +50,7 @@ export function Chart(props) {
43
50
  const chart = echarts.init(host.current, null, { renderer });
44
51
  inst.current = chart;
45
52
  const { option: opt, notMerge: nm, onInit: cb } = latest.current;
46
- if (opt) { chart.setOption(opt, nm); applied.current = opt; }
53
+ if (opt) { applyOption(chart, opt, nm); applied.current = opt; }
47
54
  if (cb) cb(chart);
48
55
  } catch {
49
56
  if (!dead) setFailed(true); // no chart code: say so, never draw a fake one
@@ -61,7 +68,7 @@ export function Chart(props) {
61
68
  // arrives asynchronously, so both paths run on the first render that has one.
62
69
  useEffect(() => {
63
70
  if (!inst.current || !option || applied.current === option) return;
64
- inst.current.setOption(option, notMerge);
71
+ applyOption(inst.current, option, notMerge);
65
72
  applied.current = option;
66
73
  }, [option, notMerge]);
67
74
 
@@ -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
+
@@ -4,6 +4,8 @@
4
4
  // dependency graph of every consumer, so an app that renders a Button and no chart would have to
5
5
  // resolve a charting library to build. Same rule, same reason, as 'reifyui/slides'.
6
6
  export { Chart } from './Chart.jsx';
7
+ // What the chart does to every option before ECharts sees it, for a host that sets options on the instance itself.
8
+ export { safeChartOption, safeHref } from './safe.js';
7
9
  // The theme as strings a chart option can hold — series colours, axis ink, tooltip chrome. CSS
8
10
  // variables do not reach inside a canvas; these do.
9
11
  export { chartTokens } from './tokens.js';
@@ -0,0 +1,66 @@
1
+ // An ECharts option can come from anywhere (a person, a saved dashboard, an agent writing it), so the chart keeps it
2
+ // inert before ECharts sees it (found 2026-11-10). ECharts writes some option strings into the page as HTML or opens
3
+ // them as URLs:
4
+ // - a tooltip's content (its formatter, series and data names) in the default HTML render mode;
5
+ // - a title's link / sublink and a sunburst or treemap node's link, opened in a window that keeps the page's origin;
6
+ // - the data view's title and button labels (toolbox.feature.dataView.title / lang).
7
+ // So every tooltip draws in the chart itself (renderMode 'richText': text, never markup), a link is kept only when it is
8
+ // http(s) or mailto, and the data view's words are escaped. The option passed in is never changed: plain objects and
9
+ // arrays are copied, anything else (functions, typed arrays, dates, gradient objects) is passed through as it is.
10
+ const SAFE_HREF = /^(https?:\/\/|mailto:)/i;
11
+
12
+ export function safeHref(v) {
13
+ return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, '')) ? v : '';
14
+ }
15
+
16
+ const ESC = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
17
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
18
+
19
+ const isPlain = (v) => {
20
+ if (!v || typeof v !== 'object' || Array.isArray(v)) return false;
21
+ const p = Object.getPrototypeOf(v);
22
+ return p === Object.prototype || p === null;
23
+ };
24
+
25
+ export function safeChartOption(option) {
26
+ if (!isPlain(option) && !Array.isArray(option)) return option;
27
+ const seen = new Map();
28
+ const escaped = new Set();
29
+ const walk = (n) => {
30
+ if (Array.isArray(n)) {
31
+ if (seen.has(n)) return seen.get(n);
32
+ const out = []; seen.set(n, out);
33
+ for (const x of n) out.push(walk(x));
34
+ return out;
35
+ }
36
+ if (!isPlain(n)) return n;
37
+ if (seen.has(n)) return seen.get(n);
38
+ const out = {}; seen.set(n, out);
39
+ for (const k of Object.keys(n)) {
40
+ const v = n[k];
41
+ if ((k === 'link' || k === 'sublink') && typeof v === 'string') {
42
+ if (safeHref(v)) out[k] = v;
43
+ } else if (k === 'tooltip') {
44
+ out[k] = tooltip(v);
45
+ } else if (k === 'dataView' && isPlain(v)) {
46
+ out[k] = dataView(walk(v));
47
+ } else {
48
+ out[k] = walk(v);
49
+ }
50
+ }
51
+ return out;
52
+ };
53
+ const tooltip = (v) => {
54
+ if (v === true) return { renderMode: 'richText' };
55
+ if (Array.isArray(v)) return v.map((t) => (isPlain(t) ? { ...walk(t), renderMode: 'richText' } : walk(t)));
56
+ return isPlain(v) ? { ...walk(v), renderMode: 'richText' } : walk(v);
57
+ };
58
+ const dataView = (d) => {
59
+ if (escaped.has(d)) return d; // the same data view reached twice: escape once
60
+ escaped.add(d);
61
+ if (typeof d.title === 'string') d.title = esc(d.title);
62
+ if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => (typeof s === 'string' ? esc(s) : s));
63
+ return d;
64
+ };
65
+ return walk(option);
66
+ }
@@ -6,6 +6,26 @@
6
6
  // render to SVG so they stay crisp in the canvas, thumbnails, and PDF.
7
7
  import { useEffect, useRef, useState } from 'react';
8
8
 
9
+ // A deck can come from anywhere (a save, the copilot, a peer writing the live document), so the renderer itself
10
+ // keeps it inert: a link is a link only when it is http(s) or mailto (React 18 renders a javascript: href), and a
11
+ // chart's tooltip draws text, not HTML (found 2026-11-05).
12
+ const SAFE_HREF = /^(https?:\/\/|mailto:)/i;
13
+ export function safeHref(v) {
14
+ return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\u0000-\u0020\u007f]/g, '')) ? v : '';
15
+ }
16
+ export function safeChartSpec(spec) {
17
+ const out = JSON.parse(JSON.stringify(spec));
18
+ const walk = (n) => {
19
+ if (Array.isArray(n)) { n.forEach(walk); return; }
20
+ if (!n || typeof n !== 'object') return;
21
+ for (const k of ['link', 'sublink']) if (k in n && !safeHref(n[k])) delete n[k];
22
+ Object.values(n).forEach(walk);
23
+ };
24
+ walk(out);
25
+ for (const t of [].concat(out.tooltip || [])) if (t && typeof t === 'object') t.renderMode = 'richText';
26
+ return out;
27
+ }
28
+
9
29
  // Rich-text runs → spans with marks. role drives default sizing (the stage is
10
30
  // 1920 wide, so these px sizes read correctly once the stage is scaled).
11
31
  //
@@ -29,8 +49,8 @@ function runSpans(runs) {
29
49
  if (marks.has('italic')) style.fontStyle = 'italic';
30
50
  if (marks.has('underline')) style.textDecoration = 'underline';
31
51
  if (marks.has('code')) { style.fontFamily = 'var(--sl-mono, monospace)'; style.background = 'rgba(0,0,0,.06)'; style.padding = '0 6px'; style.borderRadius = 4; }
32
- const link = (r.marks || []).find((m) => typeof m === 'object' && m.link);
33
- if (link) return <a key={i} href={link.link} style={{ ...style, color: 'var(--sl-brand)' }}>{node}</a>;
52
+ const link = (r.marks || []).find((m) => typeof m === 'object' && safeHref(m.link));
53
+ if (link) return <a key={i} href={safeHref(link.link)} style={{ ...style, color: 'var(--sl-brand)' }}>{node}</a>;
34
54
  return <span key={i} style={style}>{node}</span>;
35
55
  });
36
56
  }
@@ -70,7 +90,7 @@ function ChartEl({ el }) {
70
90
  const echarts = (await import('echarts')).default || (await import('echarts'));
71
91
  if (dead || !ref.current) return;
72
92
  chart = echarts.init(ref.current, null, { renderer: 'svg' });
73
- if (el.content?.spec) chart.setOption(el.content.spec);
93
+ if (el.content?.spec) chart.setOption(safeChartSpec(el.content.spec));
74
94
  } catch { /* echarts missing — leave the box */ }
75
95
  })();
76
96
  return () => { dead = true; try { chart && chart.dispose(); } catch {} };
@@ -160,9 +180,18 @@ function CodeEl({ el }) {
160
180
  );
161
181
  }
162
182
 
183
+ // An embed's html is a document of its own: the srcdoc of a sandboxed frame (no scripts, an opaque origin) behind
184
+ // a policy that allows no script and no plain-http load. Put straight into the page, its markup ran in the host's
185
+ // origin, where the person's session lives (found 2026-11-05). pointer-events: none keeps the element selectable
186
+ // and draggable in the editor.
187
+ const EMBED_POLICY = '<meta http-equiv="Content-Security-Policy" content="default-src https: data:; '
188
+ + "style-src 'unsafe-inline' https: data:; script-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'\">"
189
+ + '<style>html,body{margin:0;padding:0;background:transparent;overflow:hidden}</style>';
190
+
163
191
  function EmbedEl({ el }) {
164
- return <div style={{ width: '100%', height: '100%', overflow: 'hidden' }}
165
- dangerouslySetInnerHTML={{ __html: el.content?.html || '' }} />;
192
+ return <iframe title="Embedded content" sandbox="" referrerPolicy="no-referrer"
193
+ srcDoc={EMBED_POLICY + (el.content?.html || '')}
194
+ style={{ border: 0, width: '100%', height: '100%', display: 'block', pointerEvents: 'none' }} />;
166
195
  }
167
196
 
168
197
  function ph() {