@surreal-ui/catalog 0.9.1 → 0.10.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/dist/{chunk-G2FSYMIB.js → chunk-NROGLREK.js} +761 -4
- package/dist/components.css +5 -0
- package/dist/index.js +1 -1
- package/dist/lazy.js +1 -1
- package/dist/react/editor.d.ts +129 -1
- package/dist/react/editor.js +529 -31
- package/dist/sources/bar-chart/react.tsx +15 -13
- package/dist/sources/braid/react.tsx +174 -0
- package/dist/sources/donut-chart/react.tsx +65 -0
- package/dist/sources/line-chart/react.tsx +79 -0
- package/dist/sources/lineage/react.tsx +169 -0
- package/dist/sources/sparkline/react.tsx +12 -13
- package/dist/sources/weave/react.tsx +165 -0
- package/llms.txt +5 -0
- package/package.json +3 -3
- package/skills/surreal-use/references/components.md +5 -0
package/dist/react/editor.js
CHANGED
|
@@ -32,19 +32,20 @@ function BarChart({
|
|
|
32
32
|
}, [width]);
|
|
33
33
|
const w = width ?? measured;
|
|
34
34
|
const h = height ?? 240;
|
|
35
|
-
const
|
|
36
|
-
() =>
|
|
37
|
-
Object.
|
|
38
|
-
Object.entries({ categories, series, title, unit }).filter(([, v]) => v !== void 0)
|
|
39
|
-
),
|
|
40
|
-
{
|
|
41
|
-
width: w,
|
|
42
|
-
height: h,
|
|
43
|
-
theme: colors?.scheme ?? "light",
|
|
44
|
-
...colors ? { colors: colors.css } : {}
|
|
45
|
-
}
|
|
35
|
+
const data = React.useMemo(
|
|
36
|
+
() => Object.fromEntries(
|
|
37
|
+
Object.entries({ categories, series, title, unit }).filter(([, v]) => v !== void 0)
|
|
46
38
|
),
|
|
47
|
-
[categories, series, title, unit
|
|
39
|
+
[categories, series, title, unit]
|
|
40
|
+
);
|
|
41
|
+
const svg = React.useMemo(
|
|
42
|
+
() => w === void 0 ? "" : COMPONENT.render(data, {
|
|
43
|
+
width: w,
|
|
44
|
+
height: h,
|
|
45
|
+
theme: colors?.scheme ?? "light",
|
|
46
|
+
...colors ? { colors: colors.css } : {}
|
|
47
|
+
}),
|
|
48
|
+
[data, w, h, colors]
|
|
48
49
|
);
|
|
49
50
|
return /* @__PURE__ */ jsx(
|
|
50
51
|
"span",
|
|
@@ -57,32 +58,395 @@ function BarChart({
|
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
// ../../components/
|
|
61
|
+
// ../../components/braid/react.tsx
|
|
61
62
|
import * as React2 from "react";
|
|
62
63
|
import { uiComponents as uiComponents2 } from "@pixerate/editor/chart";
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
|
|
64
|
+
import { createLinkFocus } from "@pixerate/editor/tools";
|
|
65
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
66
|
+
var ROLES2 = ["surface", "ink", "accent"];
|
|
67
|
+
var COMPONENT2 = uiComponents2().find((c) => c.id === "braid");
|
|
68
|
+
var VISUALLY_HIDDEN = {
|
|
69
|
+
position: "absolute",
|
|
70
|
+
width: 1,
|
|
71
|
+
height: 1,
|
|
72
|
+
overflow: "hidden",
|
|
73
|
+
clip: "rect(0 0 0 0)",
|
|
74
|
+
whiteSpace: "nowrap"
|
|
75
|
+
};
|
|
76
|
+
function Braid({
|
|
77
|
+
root,
|
|
78
|
+
strands,
|
|
79
|
+
turns,
|
|
80
|
+
title,
|
|
81
|
+
focus,
|
|
82
|
+
onFocusChange,
|
|
83
|
+
progress,
|
|
84
|
+
animate,
|
|
85
|
+
duration,
|
|
86
|
+
width,
|
|
87
|
+
height,
|
|
88
|
+
className,
|
|
89
|
+
style
|
|
90
|
+
}) {
|
|
67
91
|
const ref = React2.useRef(null);
|
|
68
92
|
const colors = useRoleColors(ref, ROLES2);
|
|
69
|
-
const
|
|
70
|
-
|
|
93
|
+
const [measured, setMeasured] = React2.useState(void 0);
|
|
94
|
+
React2.useEffect(() => {
|
|
95
|
+
const el = ref.current?.parentElement;
|
|
96
|
+
if (!el || width !== void 0) return;
|
|
97
|
+
const observer = new ResizeObserver(
|
|
98
|
+
([entry]) => setMeasured(Math.max(280, Math.round(entry.contentRect.width)))
|
|
99
|
+
);
|
|
100
|
+
observer.observe(el);
|
|
101
|
+
return () => observer.disconnect();
|
|
102
|
+
}, [width]);
|
|
103
|
+
const w = width ?? measured;
|
|
104
|
+
const h = height ?? 240;
|
|
105
|
+
const data = React2.useMemo(
|
|
106
|
+
() => Object.fromEntries(
|
|
107
|
+
Object.entries({ root, strands, turns, title }).filter(([, v]) => v !== void 0)
|
|
108
|
+
),
|
|
109
|
+
[root, strands, turns, title]
|
|
110
|
+
);
|
|
111
|
+
const controlled = progress !== void 0;
|
|
112
|
+
const [played, setPlayed] = React2.useState(controlled || animate === false ? 1 : 0);
|
|
113
|
+
React2.useEffect(() => {
|
|
114
|
+
if (controlled || animate === false) return;
|
|
115
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
116
|
+
setPlayed(1);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let frame = 0;
|
|
120
|
+
const start = performance.now();
|
|
121
|
+
const length = Math.max(1, duration ?? 1600);
|
|
122
|
+
const tick = (now) => {
|
|
123
|
+
const p2 = Math.min(1, (now - start) / length);
|
|
124
|
+
setPlayed(p2);
|
|
125
|
+
if (p2 < 1) frame = requestAnimationFrame(tick);
|
|
126
|
+
};
|
|
127
|
+
frame = requestAnimationFrame(tick);
|
|
128
|
+
return () => cancelAnimationFrame(frame);
|
|
129
|
+
}, [controlled, animate, duration]);
|
|
130
|
+
const p = Math.min(1, Math.max(0, progress ?? played));
|
|
131
|
+
const dataKey = React2.useMemo(() => JSON.stringify(data), [data]);
|
|
132
|
+
const model = React2.useMemo(
|
|
133
|
+
() => createLinkFocus(COMPONENT2.interaction(JSON.parse(dataKey))),
|
|
134
|
+
[dataKey]
|
|
135
|
+
);
|
|
136
|
+
const [ownFocus, setOwnFocus] = React2.useState(null);
|
|
137
|
+
const onFocusChangeRef = React2.useRef(onFocusChange);
|
|
138
|
+
onFocusChangeRef.current = onFocusChange;
|
|
139
|
+
React2.useEffect(() => {
|
|
140
|
+
setOwnFocus(model.getState().focus);
|
|
141
|
+
return model.subscribe((state) => {
|
|
142
|
+
setOwnFocus(state.focus);
|
|
143
|
+
onFocusChangeRef.current?.(state.focus);
|
|
144
|
+
});
|
|
145
|
+
}, [model]);
|
|
146
|
+
React2.useEffect(() => {
|
|
147
|
+
if (focus !== void 0 && (focus === null || model.order.includes(focus))) model.focus(focus);
|
|
148
|
+
}, [model, focus]);
|
|
149
|
+
const wanted = focus !== void 0 ? focus : ownFocus;
|
|
150
|
+
const f = wanted !== null && model.order.includes(wanted) ? wanted : null;
|
|
71
151
|
const svg = React2.useMemo(
|
|
72
|
-
() => w === void 0 ? "" : COMPONENT2.render(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
|
|
152
|
+
() => w === void 0 ? "" : COMPONENT2.render(data, {
|
|
153
|
+
width: w,
|
|
154
|
+
height: h,
|
|
155
|
+
theme: colors?.scheme ?? "light",
|
|
156
|
+
...colors ? { colors: colors.css } : {},
|
|
157
|
+
progress: p,
|
|
158
|
+
focus: f
|
|
159
|
+
}),
|
|
160
|
+
[data, w, h, colors, p, f]
|
|
161
|
+
);
|
|
162
|
+
return /* @__PURE__ */ jsxs(
|
|
163
|
+
"span",
|
|
164
|
+
{
|
|
165
|
+
ref,
|
|
166
|
+
className: ["sui-provider", className].filter(Boolean).join(" "),
|
|
167
|
+
style: {
|
|
168
|
+
display: "inline-block",
|
|
169
|
+
position: "relative",
|
|
170
|
+
width: w ?? "100%",
|
|
78
171
|
height: h,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
172
|
+
...style
|
|
173
|
+
},
|
|
174
|
+
tabIndex: 0,
|
|
175
|
+
onKeyDown: (event) => {
|
|
176
|
+
if (model.handleKey(event)) event.preventDefault();
|
|
177
|
+
},
|
|
178
|
+
onPointerOver: (event) => {
|
|
179
|
+
const key = event.target.closest("[data-link-focus]")?.getAttribute("data-link-focus");
|
|
180
|
+
if (key && !key.includes(" ")) model.focus(key);
|
|
181
|
+
},
|
|
182
|
+
onPointerLeave: () => model.clear(),
|
|
183
|
+
onBlur: (event) => {
|
|
184
|
+
if (!event.currentTarget.contains(event.relatedTarget)) model.clear();
|
|
185
|
+
},
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ jsx2("span", { style: { display: "block" }, dangerouslySetInnerHTML: { __html: svg } }),
|
|
188
|
+
/* @__PURE__ */ jsx2("span", { "aria-live": "polite", style: VISUALLY_HIDDEN, children: f === null ? "" : model.describe(f) })
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ../../components/donut-chart/react.tsx
|
|
195
|
+
import * as React3 from "react";
|
|
196
|
+
import { uiComponents as uiComponents3 } from "@pixerate/editor/chart";
|
|
197
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
198
|
+
var ROLES3 = ["surface", "ink", "accent"];
|
|
199
|
+
var COMPONENT3 = uiComponents3().find((c) => c.id === "donut-chart");
|
|
200
|
+
function DonutChart({
|
|
201
|
+
slices,
|
|
202
|
+
title,
|
|
203
|
+
unit,
|
|
204
|
+
width,
|
|
205
|
+
height,
|
|
206
|
+
className,
|
|
207
|
+
style
|
|
208
|
+
}) {
|
|
209
|
+
const ref = React3.useRef(null);
|
|
210
|
+
const colors = useRoleColors(ref, ROLES3);
|
|
211
|
+
const w = width ?? 196;
|
|
212
|
+
const h = height ?? 140;
|
|
213
|
+
const data = React3.useMemo(
|
|
214
|
+
() => Object.fromEntries(
|
|
215
|
+
Object.entries({ slices, title, unit }).filter(([, v]) => v !== void 0)
|
|
216
|
+
),
|
|
217
|
+
[slices, title, unit]
|
|
218
|
+
);
|
|
219
|
+
const svg = React3.useMemo(
|
|
220
|
+
() => w === void 0 ? "" : COMPONENT3.render(data, {
|
|
221
|
+
width: w,
|
|
222
|
+
height: h,
|
|
223
|
+
theme: colors?.scheme ?? "light",
|
|
224
|
+
...colors ? { colors: colors.css } : {}
|
|
225
|
+
}),
|
|
226
|
+
[data, w, h, colors]
|
|
227
|
+
);
|
|
228
|
+
return /* @__PURE__ */ jsx3(
|
|
229
|
+
"span",
|
|
230
|
+
{
|
|
231
|
+
ref,
|
|
232
|
+
className: ["sui-provider", className].filter(Boolean).join(" "),
|
|
233
|
+
style: { display: "inline-block", width: w, height: h, ...style },
|
|
234
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ../../components/line-chart/react.tsx
|
|
240
|
+
import * as React4 from "react";
|
|
241
|
+
import { uiComponents as uiComponents4 } from "@pixerate/editor/chart";
|
|
242
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
243
|
+
var ROLES4 = ["surface", "ink", "ink-muted", "border", "accent"];
|
|
244
|
+
var COMPONENT4 = uiComponents4().find((c) => c.id === "line-chart");
|
|
245
|
+
function LineChart({
|
|
246
|
+
categories,
|
|
247
|
+
series,
|
|
248
|
+
title,
|
|
249
|
+
unit,
|
|
250
|
+
width,
|
|
251
|
+
height,
|
|
252
|
+
className,
|
|
253
|
+
style
|
|
254
|
+
}) {
|
|
255
|
+
const ref = React4.useRef(null);
|
|
256
|
+
const colors = useRoleColors(ref, ROLES4);
|
|
257
|
+
const [measured, setMeasured] = React4.useState(void 0);
|
|
258
|
+
React4.useEffect(() => {
|
|
259
|
+
const el = ref.current?.parentElement;
|
|
260
|
+
if (!el || width !== void 0) return;
|
|
261
|
+
const observer = new ResizeObserver(
|
|
262
|
+
([entry]) => setMeasured(Math.max(200, Math.round(entry.contentRect.width)))
|
|
263
|
+
);
|
|
264
|
+
observer.observe(el);
|
|
265
|
+
return () => observer.disconnect();
|
|
266
|
+
}, [width]);
|
|
267
|
+
const w = width ?? measured;
|
|
268
|
+
const h = height ?? 240;
|
|
269
|
+
const data = React4.useMemo(
|
|
270
|
+
() => Object.fromEntries(
|
|
271
|
+
Object.entries({ categories, series, title, unit }).filter(([, v]) => v !== void 0)
|
|
82
272
|
),
|
|
83
|
-
[
|
|
273
|
+
[categories, series, title, unit]
|
|
84
274
|
);
|
|
85
|
-
|
|
275
|
+
const svg = React4.useMemo(
|
|
276
|
+
() => w === void 0 ? "" : COMPONENT4.render(data, {
|
|
277
|
+
width: w,
|
|
278
|
+
height: h,
|
|
279
|
+
theme: colors?.scheme ?? "light",
|
|
280
|
+
...colors ? { colors: colors.css } : {}
|
|
281
|
+
}),
|
|
282
|
+
[data, w, h, colors]
|
|
283
|
+
);
|
|
284
|
+
return /* @__PURE__ */ jsx4(
|
|
285
|
+
"span",
|
|
286
|
+
{
|
|
287
|
+
ref,
|
|
288
|
+
className: ["sui-provider", className].filter(Boolean).join(" "),
|
|
289
|
+
style: { display: "inline-block", width: w ?? "100%", height: h, ...style },
|
|
290
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ../../components/lineage/react.tsx
|
|
296
|
+
import * as React5 from "react";
|
|
297
|
+
import { uiComponents as uiComponents5 } from "@pixerate/editor/chart";
|
|
298
|
+
import { createLinkFocus as createLinkFocus2 } from "@pixerate/editor/tools";
|
|
299
|
+
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
300
|
+
var ROLES5 = ["surface", "ink", "ink-muted", "accent"];
|
|
301
|
+
var COMPONENT5 = uiComponents5().find((c) => c.id === "lineage");
|
|
302
|
+
var VISUALLY_HIDDEN2 = {
|
|
303
|
+
position: "absolute",
|
|
304
|
+
width: 1,
|
|
305
|
+
height: 1,
|
|
306
|
+
overflow: "hidden",
|
|
307
|
+
clip: "rect(0 0 0 0)",
|
|
308
|
+
whiteSpace: "nowrap"
|
|
309
|
+
};
|
|
310
|
+
function Lineage({
|
|
311
|
+
root,
|
|
312
|
+
items,
|
|
313
|
+
title,
|
|
314
|
+
focus,
|
|
315
|
+
onFocusChange,
|
|
316
|
+
progress,
|
|
317
|
+
animate,
|
|
318
|
+
duration,
|
|
319
|
+
width,
|
|
320
|
+
height,
|
|
321
|
+
className,
|
|
322
|
+
style
|
|
323
|
+
}) {
|
|
324
|
+
const ref = React5.useRef(null);
|
|
325
|
+
const colors = useRoleColors(ref, ROLES5);
|
|
326
|
+
const [measured, setMeasured] = React5.useState(void 0);
|
|
327
|
+
React5.useEffect(() => {
|
|
328
|
+
const el = ref.current?.parentElement;
|
|
329
|
+
if (!el || width !== void 0) return;
|
|
330
|
+
const observer = new ResizeObserver(
|
|
331
|
+
([entry]) => setMeasured(Math.max(240, Math.round(entry.contentRect.width)))
|
|
332
|
+
);
|
|
333
|
+
observer.observe(el);
|
|
334
|
+
return () => observer.disconnect();
|
|
335
|
+
}, [width]);
|
|
336
|
+
const w = width ?? measured;
|
|
337
|
+
const h = height ?? 240;
|
|
338
|
+
const data = React5.useMemo(
|
|
339
|
+
() => Object.fromEntries(Object.entries({ root, items, title }).filter(([, v]) => v !== void 0)),
|
|
340
|
+
[root, items, title]
|
|
341
|
+
);
|
|
342
|
+
const controlled = progress !== void 0;
|
|
343
|
+
const [played, setPlayed] = React5.useState(controlled || animate === false ? 1 : 0);
|
|
344
|
+
React5.useEffect(() => {
|
|
345
|
+
if (controlled || animate === false) return;
|
|
346
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
347
|
+
setPlayed(1);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
let frame = 0;
|
|
351
|
+
const start = performance.now();
|
|
352
|
+
const length = Math.max(1, duration ?? 1600);
|
|
353
|
+
const tick = (now) => {
|
|
354
|
+
const p2 = Math.min(1, (now - start) / length);
|
|
355
|
+
setPlayed(p2);
|
|
356
|
+
if (p2 < 1) frame = requestAnimationFrame(tick);
|
|
357
|
+
};
|
|
358
|
+
frame = requestAnimationFrame(tick);
|
|
359
|
+
return () => cancelAnimationFrame(frame);
|
|
360
|
+
}, [controlled, animate, duration]);
|
|
361
|
+
const p = Math.min(1, Math.max(0, progress ?? played));
|
|
362
|
+
const dataKey = React5.useMemo(() => JSON.stringify(data), [data]);
|
|
363
|
+
const model = React5.useMemo(
|
|
364
|
+
() => createLinkFocus2(COMPONENT5.interaction(JSON.parse(dataKey))),
|
|
365
|
+
[dataKey]
|
|
366
|
+
);
|
|
367
|
+
const [ownFocus, setOwnFocus] = React5.useState(null);
|
|
368
|
+
const onFocusChangeRef = React5.useRef(onFocusChange);
|
|
369
|
+
onFocusChangeRef.current = onFocusChange;
|
|
370
|
+
React5.useEffect(() => {
|
|
371
|
+
setOwnFocus(model.getState().focus);
|
|
372
|
+
return model.subscribe((state) => {
|
|
373
|
+
setOwnFocus(state.focus);
|
|
374
|
+
onFocusChangeRef.current?.(state.focus);
|
|
375
|
+
});
|
|
376
|
+
}, [model]);
|
|
377
|
+
React5.useEffect(() => {
|
|
378
|
+
if (focus !== void 0 && (focus === null || model.order.includes(focus))) model.focus(focus);
|
|
379
|
+
}, [model, focus]);
|
|
380
|
+
const wanted = focus !== void 0 ? focus : ownFocus;
|
|
381
|
+
const f = wanted !== null && model.order.includes(wanted) ? wanted : null;
|
|
382
|
+
const svg = React5.useMemo(
|
|
383
|
+
() => w === void 0 ? "" : COMPONENT5.render(data, {
|
|
384
|
+
width: w,
|
|
385
|
+
height: h,
|
|
386
|
+
theme: colors?.scheme ?? "light",
|
|
387
|
+
...colors ? { colors: colors.css } : {},
|
|
388
|
+
progress: p,
|
|
389
|
+
focus: f
|
|
390
|
+
}),
|
|
391
|
+
[data, w, h, colors, p, f]
|
|
392
|
+
);
|
|
393
|
+
return /* @__PURE__ */ jsxs2(
|
|
394
|
+
"span",
|
|
395
|
+
{
|
|
396
|
+
ref,
|
|
397
|
+
className: ["sui-provider", className].filter(Boolean).join(" "),
|
|
398
|
+
style: {
|
|
399
|
+
display: "inline-block",
|
|
400
|
+
position: "relative",
|
|
401
|
+
width: w ?? "100%",
|
|
402
|
+
height: h,
|
|
403
|
+
...style
|
|
404
|
+
},
|
|
405
|
+
tabIndex: 0,
|
|
406
|
+
onKeyDown: (event) => {
|
|
407
|
+
if (model.handleKey(event)) event.preventDefault();
|
|
408
|
+
},
|
|
409
|
+
onPointerOver: (event) => {
|
|
410
|
+
const key = event.target.closest("[data-link-focus]")?.getAttribute("data-link-focus");
|
|
411
|
+
if (key && !key.includes(" ")) model.focus(key);
|
|
412
|
+
},
|
|
413
|
+
onPointerLeave: () => model.clear(),
|
|
414
|
+
onBlur: (event) => {
|
|
415
|
+
if (!event.currentTarget.contains(event.relatedTarget)) model.clear();
|
|
416
|
+
},
|
|
417
|
+
children: [
|
|
418
|
+
/* @__PURE__ */ jsx5("span", { style: { display: "block" }, dangerouslySetInnerHTML: { __html: svg } }),
|
|
419
|
+
/* @__PURE__ */ jsx5("span", { "aria-live": "polite", style: VISUALLY_HIDDEN2, children: f === null ? "" : model.describe(f) })
|
|
420
|
+
]
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// ../../components/sparkline/react.tsx
|
|
426
|
+
import * as React6 from "react";
|
|
427
|
+
import { uiComponents as uiComponents6 } from "@pixerate/editor/chart";
|
|
428
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
429
|
+
var ROLES6 = ["accent"];
|
|
430
|
+
var COMPONENT6 = uiComponents6().find((c) => c.id === "sparkline");
|
|
431
|
+
function Sparkline({ values, label, width, height, className, style }) {
|
|
432
|
+
const ref = React6.useRef(null);
|
|
433
|
+
const colors = useRoleColors(ref, ROLES6);
|
|
434
|
+
const w = width ?? 240;
|
|
435
|
+
const h = height ?? 48;
|
|
436
|
+
const data = React6.useMemo(
|
|
437
|
+
() => Object.fromEntries(Object.entries({ values, label }).filter(([, v]) => v !== void 0)),
|
|
438
|
+
[values, label]
|
|
439
|
+
);
|
|
440
|
+
const svg = React6.useMemo(
|
|
441
|
+
() => w === void 0 ? "" : COMPONENT6.render(data, {
|
|
442
|
+
width: w,
|
|
443
|
+
height: h,
|
|
444
|
+
theme: colors?.scheme ?? "light",
|
|
445
|
+
...colors ? { colors: colors.css } : {}
|
|
446
|
+
}),
|
|
447
|
+
[data, w, h, colors]
|
|
448
|
+
);
|
|
449
|
+
return /* @__PURE__ */ jsx6(
|
|
86
450
|
"span",
|
|
87
451
|
{
|
|
88
452
|
ref,
|
|
@@ -92,7 +456,141 @@ function Sparkline({ values, label, width, height, className, style }) {
|
|
|
92
456
|
}
|
|
93
457
|
);
|
|
94
458
|
}
|
|
459
|
+
|
|
460
|
+
// ../../components/weave/react.tsx
|
|
461
|
+
import * as React7 from "react";
|
|
462
|
+
import { uiComponents as uiComponents7 } from "@pixerate/editor/chart";
|
|
463
|
+
import { createLinkFocus as createLinkFocus3 } from "@pixerate/editor/tools";
|
|
464
|
+
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
465
|
+
var ROLES7 = ["surface", "surface-raised", "ink", "ink-muted", "border", "accent"];
|
|
466
|
+
var COMPONENT7 = uiComponents7().find((c) => c.id === "weave");
|
|
467
|
+
var VISUALLY_HIDDEN3 = {
|
|
468
|
+
position: "absolute",
|
|
469
|
+
width: 1,
|
|
470
|
+
height: 1,
|
|
471
|
+
overflow: "hidden",
|
|
472
|
+
clip: "rect(0 0 0 0)",
|
|
473
|
+
whiteSpace: "nowrap"
|
|
474
|
+
};
|
|
475
|
+
function Weave({
|
|
476
|
+
items,
|
|
477
|
+
title,
|
|
478
|
+
focus,
|
|
479
|
+
onFocusChange,
|
|
480
|
+
progress,
|
|
481
|
+
animate,
|
|
482
|
+
duration,
|
|
483
|
+
width,
|
|
484
|
+
height,
|
|
485
|
+
className,
|
|
486
|
+
style
|
|
487
|
+
}) {
|
|
488
|
+
const ref = React7.useRef(null);
|
|
489
|
+
const colors = useRoleColors(ref, ROLES7);
|
|
490
|
+
const [measured, setMeasured] = React7.useState(void 0);
|
|
491
|
+
React7.useEffect(() => {
|
|
492
|
+
const el = ref.current?.parentElement;
|
|
493
|
+
if (!el || width !== void 0) return;
|
|
494
|
+
const observer = new ResizeObserver(
|
|
495
|
+
([entry]) => setMeasured(Math.max(280, Math.round(entry.contentRect.width)))
|
|
496
|
+
);
|
|
497
|
+
observer.observe(el);
|
|
498
|
+
return () => observer.disconnect();
|
|
499
|
+
}, [width]);
|
|
500
|
+
const w = width ?? measured;
|
|
501
|
+
const h = height ?? 240;
|
|
502
|
+
const data = React7.useMemo(
|
|
503
|
+
() => Object.fromEntries(Object.entries({ items, title }).filter(([, v]) => v !== void 0)),
|
|
504
|
+
[items, title]
|
|
505
|
+
);
|
|
506
|
+
const controlled = progress !== void 0;
|
|
507
|
+
const [played, setPlayed] = React7.useState(controlled || animate === false ? 1 : 0);
|
|
508
|
+
React7.useEffect(() => {
|
|
509
|
+
if (controlled || animate === false) return;
|
|
510
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
511
|
+
setPlayed(1);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
let frame = 0;
|
|
515
|
+
const start = performance.now();
|
|
516
|
+
const length = Math.max(1, duration ?? 1600);
|
|
517
|
+
const tick = (now) => {
|
|
518
|
+
const p2 = Math.min(1, (now - start) / length);
|
|
519
|
+
setPlayed(p2);
|
|
520
|
+
if (p2 < 1) frame = requestAnimationFrame(tick);
|
|
521
|
+
};
|
|
522
|
+
frame = requestAnimationFrame(tick);
|
|
523
|
+
return () => cancelAnimationFrame(frame);
|
|
524
|
+
}, [controlled, animate, duration]);
|
|
525
|
+
const p = Math.min(1, Math.max(0, progress ?? played));
|
|
526
|
+
const dataKey = React7.useMemo(() => JSON.stringify(data), [data]);
|
|
527
|
+
const model = React7.useMemo(
|
|
528
|
+
() => createLinkFocus3(COMPONENT7.interaction(JSON.parse(dataKey))),
|
|
529
|
+
[dataKey]
|
|
530
|
+
);
|
|
531
|
+
const [ownFocus, setOwnFocus] = React7.useState(null);
|
|
532
|
+
const onFocusChangeRef = React7.useRef(onFocusChange);
|
|
533
|
+
onFocusChangeRef.current = onFocusChange;
|
|
534
|
+
React7.useEffect(() => {
|
|
535
|
+
setOwnFocus(model.getState().focus);
|
|
536
|
+
return model.subscribe((state) => {
|
|
537
|
+
setOwnFocus(state.focus);
|
|
538
|
+
onFocusChangeRef.current?.(state.focus);
|
|
539
|
+
});
|
|
540
|
+
}, [model]);
|
|
541
|
+
React7.useEffect(() => {
|
|
542
|
+
if (focus !== void 0 && (focus === null || model.order.includes(focus))) model.focus(focus);
|
|
543
|
+
}, [model, focus]);
|
|
544
|
+
const wanted = focus !== void 0 ? focus : ownFocus;
|
|
545
|
+
const f = wanted !== null && model.order.includes(wanted) ? wanted : null;
|
|
546
|
+
const svg = React7.useMemo(
|
|
547
|
+
() => w === void 0 ? "" : COMPONENT7.render(data, {
|
|
548
|
+
width: w,
|
|
549
|
+
height: h,
|
|
550
|
+
theme: colors?.scheme ?? "light",
|
|
551
|
+
...colors ? { colors: colors.css } : {},
|
|
552
|
+
progress: p,
|
|
553
|
+
focus: f
|
|
554
|
+
}),
|
|
555
|
+
[data, w, h, colors, p, f]
|
|
556
|
+
);
|
|
557
|
+
return /* @__PURE__ */ jsxs3(
|
|
558
|
+
"span",
|
|
559
|
+
{
|
|
560
|
+
ref,
|
|
561
|
+
className: ["sui-provider", className].filter(Boolean).join(" "),
|
|
562
|
+
style: {
|
|
563
|
+
display: "inline-block",
|
|
564
|
+
position: "relative",
|
|
565
|
+
width: w ?? "100%",
|
|
566
|
+
height: h,
|
|
567
|
+
...style
|
|
568
|
+
},
|
|
569
|
+
tabIndex: 0,
|
|
570
|
+
onKeyDown: (event) => {
|
|
571
|
+
if (model.handleKey(event)) event.preventDefault();
|
|
572
|
+
},
|
|
573
|
+
onPointerOver: (event) => {
|
|
574
|
+
const key = event.target.closest("[data-link-focus]")?.getAttribute("data-link-focus");
|
|
575
|
+
if (key && !key.includes(" ")) model.focus(key);
|
|
576
|
+
},
|
|
577
|
+
onPointerLeave: () => model.clear(),
|
|
578
|
+
onBlur: (event) => {
|
|
579
|
+
if (!event.currentTarget.contains(event.relatedTarget)) model.clear();
|
|
580
|
+
},
|
|
581
|
+
children: [
|
|
582
|
+
/* @__PURE__ */ jsx7("span", { style: { display: "block" }, dangerouslySetInnerHTML: { __html: svg } }),
|
|
583
|
+
/* @__PURE__ */ jsx7("span", { "aria-live": "polite", style: VISUALLY_HIDDEN3, children: f === null ? "" : model.describe(f) })
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
}
|
|
95
588
|
export {
|
|
96
589
|
BarChart,
|
|
97
|
-
|
|
590
|
+
Braid,
|
|
591
|
+
DonutChart,
|
|
592
|
+
LineChart,
|
|
593
|
+
Lineage,
|
|
594
|
+
Sparkline,
|
|
595
|
+
Weave
|
|
98
596
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by packages/catalog/scripts/sync-providers.ts from @pixerate/editor 0.
|
|
1
|
+
// Generated by packages/catalog/scripts/sync-providers.ts from @pixerate/editor 0.322.0 (bar-chart). Do not edit.
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { uiComponents } from '@pixerate/editor/chart';
|
|
4
4
|
import { useRoleColors } from '../../packages/catalog/src/runtime/role-colors';
|
|
@@ -49,22 +49,24 @@ export function BarChart({
|
|
|
49
49
|
}, [width]);
|
|
50
50
|
const w = width ?? measured;
|
|
51
51
|
const h = height ?? 240;
|
|
52
|
+
const data = React.useMemo(
|
|
53
|
+
() =>
|
|
54
|
+
Object.fromEntries(
|
|
55
|
+
Object.entries({ categories, series, title, unit }).filter(([, v]) => v !== undefined)
|
|
56
|
+
),
|
|
57
|
+
[categories, series, title, unit]
|
|
58
|
+
);
|
|
52
59
|
const svg = React.useMemo(
|
|
53
60
|
() =>
|
|
54
61
|
w === undefined
|
|
55
62
|
? ''
|
|
56
|
-
: COMPONENT.render(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
theme: colors?.scheme ?? 'light',
|
|
64
|
-
...(colors ? { colors: colors.css } : {})
|
|
65
|
-
}
|
|
66
|
-
),
|
|
67
|
-
[categories, series, title, unit, w, h, colors]
|
|
63
|
+
: COMPONENT.render(data, {
|
|
64
|
+
width: w,
|
|
65
|
+
height: h,
|
|
66
|
+
theme: colors?.scheme ?? 'light',
|
|
67
|
+
...(colors ? { colors: colors.css } : {})
|
|
68
|
+
}),
|
|
69
|
+
[data, w, h, colors]
|
|
68
70
|
);
|
|
69
71
|
return (
|
|
70
72
|
<span
|