@pixerate/editor-react 0.36.0 → 0.38.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/chart/index.cjs +22 -13
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +13 -6
- package/dist/chart/index.d.ts +13 -6
- package/dist/chart/index.js +58 -712
- package/dist/chart/index.js.map +1 -1
- package/dist/chunk-IH5ZIOK3.js +710 -0
- package/dist/chunk-IH5ZIOK3.js.map +1 -0
- package/dist/index.cjs +674 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
AdjustmentLayersPanel: () => AdjustmentLayersPanel,
|
|
34
34
|
AssetMentionChips: () => AssetMentionChips,
|
|
35
35
|
BubbleMenu: () => BubbleMenu,
|
|
36
|
+
ChartNodeView: () => ChartNodeView,
|
|
36
37
|
CommandPalette: () => CommandPalette,
|
|
37
38
|
CommentButton: () => CommentButton,
|
|
38
39
|
CommentsPanel: () => CommentsPanel,
|
|
@@ -74,6 +75,7 @@ __export(src_exports, {
|
|
|
74
75
|
bindDirtyToHistory: () => import_editor21.bindDirtyToHistory,
|
|
75
76
|
createDirtyTracker: () => import_editor21.createDirtyTracker,
|
|
76
77
|
createHistoryManager: () => import_editor21.createHistoryManager,
|
|
78
|
+
createReactChartNodeView: () => createReactChartNodeView,
|
|
77
79
|
defaultIsEqual: () => import_editor21.defaultIsEqual,
|
|
78
80
|
useAgentToolProvider: () => useAgentToolProvider,
|
|
79
81
|
useAutosave: () => useAutosave,
|
|
@@ -7233,11 +7235,682 @@ var TableBubbleMenu = ({
|
|
|
7233
7235
|
pluginKey = "tableBubbleMenu",
|
|
7234
7236
|
...rest
|
|
7235
7237
|
}) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(BubbleMenu, { editor, pluginKey, shouldShow: import_editor20.shouldShowTableBubbleMenu, ...rest, children: children ?? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(TableToolbar, { editor, ...toolbarProps }) });
|
|
7238
|
+
|
|
7239
|
+
// src/chart-node/ChartNodeView.tsx
|
|
7240
|
+
var import_client = require("react-dom/client");
|
|
7241
|
+
|
|
7242
|
+
// src/chart/ChartCanvas.tsx
|
|
7243
|
+
var import_react57 = require("react");
|
|
7244
|
+
var import_chart2 = require("@pixerate/editor/chart");
|
|
7245
|
+
|
|
7246
|
+
// src/chart/useChartEditor.ts
|
|
7247
|
+
var import_react56 = require("react");
|
|
7248
|
+
var import_chart = require("@pixerate/editor/chart");
|
|
7249
|
+
function useChartState(controller) {
|
|
7250
|
+
return (0, import_react56.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
7251
|
+
}
|
|
7252
|
+
|
|
7253
|
+
// src/chart/ChartCanvas.tsx
|
|
7254
|
+
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
7255
|
+
function renderChartMark(mark, fontFamily, interactive) {
|
|
7256
|
+
const common = {
|
|
7257
|
+
"data-role": mark.role,
|
|
7258
|
+
"data-chart-key": mark.target ? mark.key : void 0,
|
|
7259
|
+
"data-selected": mark.selected ? "" : void 0,
|
|
7260
|
+
opacity: mark.opacity,
|
|
7261
|
+
pointerEvents: mark.role === "selection" || mark.role === "drag-readout" || !mark.target && mark.role !== "background" ? "none" : void 0,
|
|
7262
|
+
cursor: interactive && mark.target && mark.role !== "background" ? "pointer" : void 0
|
|
7263
|
+
};
|
|
7264
|
+
switch (mark.kind) {
|
|
7265
|
+
case "rect":
|
|
7266
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("rect", { ...common, x: mark.x, y: mark.y, width: mark.width, height: mark.height, rx: mark.radius, style: { fill: mark.fill, stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
7267
|
+
case "path":
|
|
7268
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
|
7269
|
+
"path",
|
|
7270
|
+
{
|
|
7271
|
+
...common,
|
|
7272
|
+
d: mark.d,
|
|
7273
|
+
strokeLinejoin: "round",
|
|
7274
|
+
strokeLinecap: "round",
|
|
7275
|
+
strokeDasharray: mark.dash,
|
|
7276
|
+
style: { fill: mark.fill ?? "none", stroke: mark.stroke, strokeWidth: mark.strokeWidth }
|
|
7277
|
+
},
|
|
7278
|
+
mark.key
|
|
7279
|
+
);
|
|
7280
|
+
case "circle":
|
|
7281
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("circle", { ...common, cx: mark.cx, cy: mark.cy, r: mark.r, style: { fill: mark.fill, stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
7282
|
+
case "line":
|
|
7283
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("line", { ...common, x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, strokeDasharray: mark.dash, style: { stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
7284
|
+
case "text":
|
|
7285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
|
7286
|
+
"text",
|
|
7287
|
+
{
|
|
7288
|
+
...common,
|
|
7289
|
+
x: mark.x,
|
|
7290
|
+
y: mark.y,
|
|
7291
|
+
textAnchor: mark.anchor,
|
|
7292
|
+
dominantBaseline: (0, import_chart2.chartTextBaseline)(mark.baseline),
|
|
7293
|
+
transform: (0, import_chart2.chartTextTransform)(mark),
|
|
7294
|
+
style: { fill: mark.fill, fontSize: mark.size, fontWeight: mark.weight, fontFamily, userSelect: "none" },
|
|
7295
|
+
children: mark.text
|
|
7296
|
+
},
|
|
7297
|
+
mark.key
|
|
7298
|
+
);
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
function ChartPresenceLayer({ presence }) {
|
|
7302
|
+
const { actors } = (0, import_react57.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
7303
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
|
|
7304
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 }, transform: a.pressed ? "scale(0.9)" : void 0 }),
|
|
7305
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("g", { transform: "translate(13 16)", children: [
|
|
7306
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("rect", { x: 0, y: 0, rx: 4, height: 18, width: Math.max(28, (a.message ?? a.name).length * 6.4 + 12), style: { fill: a.color } }),
|
|
7307
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("text", { x: 6, y: 9, dominantBaseline: "central", style: { fill: "#ffffff", fontSize: 11, fontWeight: 600, fontFamily: "inherit" }, children: a.message ?? a.name })
|
|
7308
|
+
] })
|
|
7309
|
+
] }, a.id)) });
|
|
7310
|
+
}
|
|
7311
|
+
function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef }) {
|
|
7312
|
+
const state = useChartState(controller);
|
|
7313
|
+
const wrapper = (0, import_react57.useRef)(null);
|
|
7314
|
+
const svg = (0, import_react57.useRef)(null);
|
|
7315
|
+
const drag = (0, import_react57.useRef)(null);
|
|
7316
|
+
const [measured, setMeasured] = (0, import_react57.useState)(null);
|
|
7317
|
+
const [frozen, setFrozen] = (0, import_react57.useState)(null);
|
|
7318
|
+
(0, import_react57.useEffect)(() => {
|
|
7319
|
+
const el = wrapper.current;
|
|
7320
|
+
if (!responsive || !el || typeof ResizeObserver === "undefined") return;
|
|
7321
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
7322
|
+
const w = Math.round(entry.contentRect.width);
|
|
7323
|
+
if (w > 0) setMeasured(w);
|
|
7324
|
+
});
|
|
7325
|
+
observer.observe(el);
|
|
7326
|
+
return () => observer.disconnect();
|
|
7327
|
+
}, [responsive]);
|
|
7328
|
+
const sceneWidth = responsive && measured || width;
|
|
7329
|
+
const fullTheme = (0, import_react57.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
|
|
7330
|
+
const scene = (0, import_react57.useMemo)(
|
|
7331
|
+
() => (0, import_chart2.layoutChart)(state.spec, {
|
|
7332
|
+
width: sceneWidth,
|
|
7333
|
+
height,
|
|
7334
|
+
theme: fullTheme,
|
|
7335
|
+
selection: editable ? state.selection : null,
|
|
7336
|
+
measureText,
|
|
7337
|
+
emptyMessage,
|
|
7338
|
+
valueDomain: frozen?.valueDomain,
|
|
7339
|
+
valueDomain2: frozen?.valueDomain2,
|
|
7340
|
+
xDomain: frozen?.xDomain,
|
|
7341
|
+
readout: frozen?.readout
|
|
7342
|
+
}),
|
|
7343
|
+
[state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
|
|
7344
|
+
);
|
|
7345
|
+
if (sceneRef) sceneRef.current = scene;
|
|
7346
|
+
const byKey = (0, import_react57.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
|
|
7347
|
+
(0, import_react57.useEffect)(() => () => drag.current?.end(), []);
|
|
7348
|
+
const scenePoint = (e) => (0, import_chart2.chartClientToScene)(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
|
|
7349
|
+
const onPointerDown = (e) => {
|
|
7350
|
+
if (!editable || e.button !== 0) return;
|
|
7351
|
+
const key = e.target.closest?.("[data-chart-key]")?.getAttribute("data-chart-key");
|
|
7352
|
+
const target = key ? byKey.get(key)?.target : void 0;
|
|
7353
|
+
controller.select(target ?? null);
|
|
7354
|
+
drag.current = (0, import_chart2.startChartPointDrag)(controller, scene, target, scenePoint(e));
|
|
7355
|
+
if (drag.current) {
|
|
7356
|
+
const d = drag.current;
|
|
7357
|
+
setFrozen({ valueDomain: d.valueDomain, valueDomain2: d.valueDomain2 ?? null, xDomain: d.xDomain ?? null, readout: d.target });
|
|
7358
|
+
svg.current?.setPointerCapture?.(e.pointerId);
|
|
7359
|
+
}
|
|
7360
|
+
};
|
|
7361
|
+
const onPointerMove = (e) => {
|
|
7362
|
+
if (drag.current) drag.current.move(scenePoint(e), { fine: e.altKey, lockAxis: e.shiftKey, noSnap: e.ctrlKey || e.metaKey });
|
|
7363
|
+
};
|
|
7364
|
+
const endDrag = () => {
|
|
7365
|
+
drag.current?.end();
|
|
7366
|
+
drag.current = null;
|
|
7367
|
+
setFrozen(null);
|
|
7368
|
+
};
|
|
7369
|
+
const onKeyDown = (e) => {
|
|
7370
|
+
if (drag.current && e.key === "Escape") {
|
|
7371
|
+
drag.current.cancel();
|
|
7372
|
+
drag.current = null;
|
|
7373
|
+
setFrozen(null);
|
|
7374
|
+
e.preventDefault();
|
|
7375
|
+
return;
|
|
7376
|
+
}
|
|
7377
|
+
if (editable && (0, import_chart2.handleChartKey)(controller, scene, e)) e.preventDefault();
|
|
7378
|
+
};
|
|
7379
|
+
const label = state.spec.title || "Chart";
|
|
7380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { ref: wrapper, className: `w-full ${className ?? ""}`, "data-chart-canvas": "", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
|
|
7381
|
+
"svg",
|
|
7382
|
+
{
|
|
7383
|
+
ref: svg,
|
|
7384
|
+
width: sceneWidth,
|
|
7385
|
+
height,
|
|
7386
|
+
viewBox: `0 0 ${scene.width} ${scene.height}`,
|
|
7387
|
+
role: "img",
|
|
7388
|
+
"aria-label": editable ? `${label}. ${(0, import_chart2.describeChartSelection)(controller, state.selection)}` : label,
|
|
7389
|
+
tabIndex: editable ? 0 : void 0,
|
|
7390
|
+
className: "block max-w-full touch-none select-none rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",
|
|
7391
|
+
onPointerDown,
|
|
7392
|
+
onPointerMove,
|
|
7393
|
+
onPointerUp: endDrag,
|
|
7394
|
+
onPointerCancel: endDrag,
|
|
7395
|
+
onKeyDown,
|
|
7396
|
+
children: [
|
|
7397
|
+
scene.marks.map((m) => renderChartMark(m, scene.theme.fontFamily, editable)),
|
|
7398
|
+
presence && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChartPresenceLayer, { presence })
|
|
7399
|
+
]
|
|
7400
|
+
}
|
|
7401
|
+
) });
|
|
7402
|
+
}
|
|
7403
|
+
|
|
7404
|
+
// src/chart/ChartDataGrid.tsx
|
|
7405
|
+
var import_react58 = require("react");
|
|
7406
|
+
var import_chart3 = require("@pixerate/editor/chart");
|
|
7407
|
+
|
|
7408
|
+
// src/chart/styles.ts
|
|
7409
|
+
var chartInputClass = "h-7 w-full min-w-0 rounded-md border border-input bg-background px-2 text-xs text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
7410
|
+
var chartButtonClass = "inline-flex h-7 items-center justify-center gap-1 rounded-md border border-input bg-background px-2 text-xs text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";
|
|
7411
|
+
var chartIconButtonClass = "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded text-xs text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-40";
|
|
7412
|
+
var chartSegmentClass = (active) => `inline-flex h-7 flex-1 items-center justify-center rounded px-2 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary ${active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`;
|
|
7413
|
+
var chartLabelClass = "text-[11px] font-medium text-muted-foreground";
|
|
7414
|
+
var chartSectionClass = "space-y-2 border-b border-border pb-3 last:border-b-0";
|
|
7415
|
+
var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right text-xs tabular-nums text-foreground focus-visible:bg-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary";
|
|
7416
|
+
|
|
7417
|
+
// src/chart/ChartDataGrid.tsx
|
|
7418
|
+
var import_jsx_runtime39 = require("react/jsx-runtime");
|
|
7419
|
+
function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
7420
|
+
const [draft, setDraft] = (0, import_react58.useState)(value);
|
|
7421
|
+
const typing = (0, import_react58.useRef)(false);
|
|
7422
|
+
(0, import_react58.useEffect)(() => {
|
|
7423
|
+
if (!typing.current) setDraft(value);
|
|
7424
|
+
}, [value]);
|
|
7425
|
+
const commit = () => {
|
|
7426
|
+
if (!typing.current) return;
|
|
7427
|
+
typing.current = false;
|
|
7428
|
+
if (draft === value) return;
|
|
7429
|
+
if (onCommit(draft) === false) setDraft(value);
|
|
7430
|
+
};
|
|
7431
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7432
|
+
"input",
|
|
7433
|
+
{
|
|
7434
|
+
...rest,
|
|
7435
|
+
value: draft,
|
|
7436
|
+
onChange: (e) => {
|
|
7437
|
+
typing.current = true;
|
|
7438
|
+
setDraft(e.currentTarget.value);
|
|
7439
|
+
},
|
|
7440
|
+
onBlur: (e) => {
|
|
7441
|
+
onBlur?.(e);
|
|
7442
|
+
commit();
|
|
7443
|
+
},
|
|
7444
|
+
onKeyDown: (e) => {
|
|
7445
|
+
onKeyDown?.(e);
|
|
7446
|
+
if (e.defaultPrevented) return;
|
|
7447
|
+
if (e.key === "Enter") {
|
|
7448
|
+
e.preventDefault();
|
|
7449
|
+
commit();
|
|
7450
|
+
} else if (e.key === "Escape") {
|
|
7451
|
+
typing.current = false;
|
|
7452
|
+
setDraft(value);
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7455
|
+
}
|
|
7456
|
+
);
|
|
7457
|
+
}
|
|
7458
|
+
function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
|
|
7459
|
+
const { spec, selection } = useChartState(controller);
|
|
7460
|
+
const paste = (row, column) => (e) => {
|
|
7461
|
+
const text = e.clipboardData?.getData("text/plain") ?? "";
|
|
7462
|
+
if (!/[\t\n]/.test(text.replace(/\n$/, ""))) return;
|
|
7463
|
+
e.preventDefault();
|
|
7464
|
+
controller.pasteCells(row, column, text);
|
|
7465
|
+
};
|
|
7466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", children: [
|
|
7467
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("table", { className: "w-full border-collapse text-xs", children: [
|
|
7468
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("thead", { className: "bg-muted/50", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("tr", { children: [
|
|
7469
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("th", { className: "border-b border-r border-border px-2 py-1 text-left font-medium text-muted-foreground", children: categoryHeader }),
|
|
7470
|
+
spec.series.map((s, si) => {
|
|
7471
|
+
const color = (0, import_chart3.chartSeriesColor)(spec, si);
|
|
7472
|
+
const selected = selection?.kind === "series" && selection.seriesId === s.id;
|
|
7473
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("th", { "data-series-id": s.id, className: `border-b border-r border-border px-1 py-1 font-medium ${selected ? "bg-primary/10" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
7474
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7475
|
+
"input",
|
|
7476
|
+
{
|
|
7477
|
+
type: "color",
|
|
7478
|
+
"aria-label": `${s.name} colour`,
|
|
7479
|
+
value: (0, import_chart3.chartColorInputValue)(color),
|
|
7480
|
+
disabled: readOnly,
|
|
7481
|
+
onPointerDown: () => controller.beginGesture(`color:${s.id}`),
|
|
7482
|
+
onChange: (e) => controller.updateSeries(s.id, { color: e.currentTarget.value }),
|
|
7483
|
+
onBlur: () => controller.endGesture(),
|
|
7484
|
+
className: "h-5 w-5 shrink-0 cursor-pointer rounded border-0 bg-transparent p-0"
|
|
7485
|
+
}
|
|
7486
|
+
),
|
|
7487
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7488
|
+
ChartCommitInput,
|
|
7489
|
+
{
|
|
7490
|
+
value: s.name,
|
|
7491
|
+
"aria-label": "Series name",
|
|
7492
|
+
onFocus: () => controller.select({ kind: "series", seriesId: s.id }),
|
|
7493
|
+
onCommit: (name) => void controller.updateSeries(s.id, { name }),
|
|
7494
|
+
className: `${chartInputClass} h-6 min-w-[5rem] border-transparent bg-transparent font-medium ${s.hidden ? "text-muted-foreground line-through" : ""}`
|
|
7495
|
+
}
|
|
7496
|
+
),
|
|
7497
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
|
|
7498
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7499
|
+
"button",
|
|
7500
|
+
{
|
|
7501
|
+
type: "button",
|
|
7502
|
+
className: chartIconButtonClass,
|
|
7503
|
+
title: s.hidden ? "Show series" : "Hide series",
|
|
7504
|
+
"aria-label": s.hidden ? `Show ${s.name}` : `Hide ${s.name}`,
|
|
7505
|
+
"aria-pressed": !s.hidden,
|
|
7506
|
+
"data-action": "toggle-series",
|
|
7507
|
+
onClick: () => controller.toggleSeries(s.id),
|
|
7508
|
+
children: s.hidden ? "\u25CB" : "\u25CF"
|
|
7509
|
+
}
|
|
7510
|
+
),
|
|
7511
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("button", { type: "button", className: chartIconButtonClass, title: "Delete series", "aria-label": `Delete ${s.name}`, "data-action": "remove-series", onClick: () => controller.removeSeries(s.id), children: "\xD7" })
|
|
7512
|
+
] })
|
|
7513
|
+
] }) }, s.id);
|
|
7514
|
+
}),
|
|
7515
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("th", { className: "w-8 border-b border-border px-1", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("button", { type: "button", className: chartIconButtonClass, title: "Add series", "aria-label": "Add series", "data-action": "add-series", onClick: () => controller.addSeries(), children: "+" }) })
|
|
7516
|
+
] }) }),
|
|
7517
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("tbody", { children: spec.categories.map((category, i) => {
|
|
7518
|
+
const rowSelected = selection?.kind === "category" && selection.index === i;
|
|
7519
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("tr", { "data-category-index": i, className: rowSelected ? "bg-primary/10" : void 0, children: [
|
|
7520
|
+
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)("th", { className: "border-b border-r border-border p-0 text-left font-normal", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7521
|
+
ChartCommitInput,
|
|
7522
|
+
{
|
|
7523
|
+
value: category,
|
|
7524
|
+
"aria-label": `Category ${i + 1}`,
|
|
7525
|
+
onFocus: () => controller.select({ kind: "category", index: i }),
|
|
7526
|
+
onPaste: paste(i, -1),
|
|
7527
|
+
onCommit: (label) => void controller.renameCategory(i, label),
|
|
7528
|
+
className: `${chartCellClass} text-left`
|
|
7529
|
+
}
|
|
7530
|
+
) }),
|
|
7531
|
+
spec.series.map((s) => {
|
|
7532
|
+
const value = s.values[i];
|
|
7533
|
+
const selected = selection?.kind === "point" && selection.seriesId === s.id && selection.index === i;
|
|
7534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("td", { className: `border-b border-r border-border p-0 ${selected ? "bg-primary/10" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
7535
|
+
ChartCommitInput,
|
|
7536
|
+
{
|
|
7537
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
7538
|
+
inputMode: "decimal",
|
|
7539
|
+
"aria-label": `${s.name}, ${category}`,
|
|
7540
|
+
title: value === null ? void 0 : (0, import_chart3.formatChartNumber)(value, spec.yAxis.format),
|
|
7541
|
+
"data-cell": `${s.id}:${i}`,
|
|
7542
|
+
onFocus: () => controller.select({ kind: "point", seriesId: s.id, index: i }),
|
|
7543
|
+
onPaste: paste(i, spec.series.indexOf(s)),
|
|
7544
|
+
onCommit: (text) => controller.setValue(s.id, i, text).ok,
|
|
7545
|
+
className: chartCellClass
|
|
7546
|
+
}
|
|
7547
|
+
) }, s.id);
|
|
7548
|
+
}),
|
|
7549
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("td", { className: "border-b border-border px-1", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("button", { type: "button", className: chartIconButtonClass, title: "Delete category", "aria-label": `Delete ${category}`, "data-action": "remove-category", onClick: () => controller.removeCategory(i), children: "\xD7" }) })
|
|
7550
|
+
] }, i);
|
|
7551
|
+
}) })
|
|
7552
|
+
] }),
|
|
7553
|
+
!readOnly && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "p-1", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "add-category", onClick: () => controller.addCategory(), children: "+ Add category" }) })
|
|
7554
|
+
] });
|
|
7555
|
+
}
|
|
7556
|
+
|
|
7557
|
+
// src/chart/ChartInspector.tsx
|
|
7558
|
+
var import_react59 = require("react");
|
|
7559
|
+
var import_chart4 = require("@pixerate/editor/chart");
|
|
7560
|
+
var import_jsx_runtime40 = require("react/jsx-runtime");
|
|
7561
|
+
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
7562
|
+
function Field({ label, htmlFor, children }) {
|
|
7563
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
7564
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("label", { htmlFor, className: `${chartLabelClass} w-20 shrink-0`, children: label }),
|
|
7565
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "min-w-0 flex-1", children })
|
|
7566
|
+
] });
|
|
7567
|
+
}
|
|
7568
|
+
function Toggle({ label, checked, onChange, name }) {
|
|
7569
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("label", { className: "flex cursor-pointer items-center gap-2 text-xs text-foreground", children: [
|
|
7570
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("input", { type: "checkbox", className: "h-3.5 w-3.5 accent-primary", checked, "data-option": name, onChange: (e) => onChange(e.currentTarget.checked) }),
|
|
7571
|
+
label
|
|
7572
|
+
] });
|
|
7573
|
+
}
|
|
7574
|
+
function Select({ id, value, options, onChange, name, labels }) {
|
|
7575
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("select", { id, className: chartInputClass, value, "data-option": name, onChange: (e) => onChange(e.currentTarget.value), children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: o, children: labels?.[o] ?? cap(o) }, o)) });
|
|
7576
|
+
}
|
|
7577
|
+
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false }) {
|
|
7578
|
+
const set = (patch) => controller.setAxis(axis, patch);
|
|
7579
|
+
const setFormat = (patch) => set({ format: { ...value.format, ...patch } });
|
|
7580
|
+
const bound = (key2) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7581
|
+
ChartCommitInput,
|
|
7582
|
+
{
|
|
7583
|
+
id: `${idBase}-${axis}-${key2}`,
|
|
7584
|
+
value: value[key2] === null ? "" : String(value[key2]),
|
|
7585
|
+
placeholder: "Auto",
|
|
7586
|
+
inputMode: "decimal",
|
|
7587
|
+
"data-option": `${axis}Axis.${key2}`,
|
|
7588
|
+
className: chartInputClass,
|
|
7589
|
+
onCommit: (text) => set({ [key2]: text.trim() === "" ? null : Number(text) }).ok
|
|
7590
|
+
}
|
|
7591
|
+
);
|
|
7592
|
+
const name = axis === "x" ? numeric ? "X axis" : "Category axis" : axis === "y" ? "Value axis" : "Secondary axis";
|
|
7593
|
+
const valueAxis = axis !== "x" || numeric;
|
|
7594
|
+
const key = axis === "y2" ? "yAxis2" : `${axis}Axis`;
|
|
7595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": `axis-${axis}`, children: [
|
|
7596
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between", children: [
|
|
7597
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("h4", { className: "text-xs font-semibold text-foreground", children: [
|
|
7598
|
+
name,
|
|
7599
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("span", { className: "ml-1 font-normal text-muted-foreground", children: [
|
|
7600
|
+
"(",
|
|
7601
|
+
axis === "x" ? horizontal ? "left" : "bottom" : axis === "y2" ? horizontal ? "top" : "right" : horizontal ? "bottom" : "left",
|
|
7602
|
+
")"
|
|
7603
|
+
] })
|
|
7604
|
+
] }),
|
|
7605
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Show", name: `${axis}Axis.show`, checked: value.show, onChange: (show) => set({ show }) })
|
|
7606
|
+
] }),
|
|
7607
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Title", htmlFor: `${idBase}-${axis}-title`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-${axis}-title`, value: value.title, "data-option": `${axis}Axis.title`, className: chartInputClass, onCommit: (title) => void set({ title }) }) }),
|
|
7608
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
7609
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Grid lines", name: `${key}.gridlines`, checked: value.gridlines, onChange: (gridlines) => set({ gridlines }) }),
|
|
7610
|
+
axis === "x" && !numeric && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) })
|
|
7611
|
+
] }),
|
|
7612
|
+
valueAxis && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Step", htmlFor: `${idBase}-${axis}-step`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7613
|
+
ChartCommitInput,
|
|
7614
|
+
{
|
|
7615
|
+
id: `${idBase}-${axis}-step`,
|
|
7616
|
+
value: value.step === null ? "" : String(value.step),
|
|
7617
|
+
placeholder: "Auto",
|
|
7618
|
+
inputMode: "decimal",
|
|
7619
|
+
"data-option": `${key}.step`,
|
|
7620
|
+
className: chartInputClass,
|
|
7621
|
+
onCommit: (text) => set({ step: text.trim() === "" ? null : Number(text) }).ok
|
|
7622
|
+
}
|
|
7623
|
+
) }),
|
|
7624
|
+
valueAxis && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
|
|
7625
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Min / max", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex gap-1", children: [
|
|
7626
|
+
bound("min"),
|
|
7627
|
+
bound("max")
|
|
7628
|
+
] }) }),
|
|
7629
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Format", htmlFor: `${idBase}-${axis}-format`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex gap-1", children: [
|
|
7630
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Select, { id: `${idBase}-${axis}-format`, name: `${key}.format.style`, value: value.format.style ?? "number", options: import_chart4.CHART_NUMBER_STYLES, onChange: (style) => setFormat({ style }) }),
|
|
7631
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7632
|
+
ChartCommitInput,
|
|
7633
|
+
{
|
|
7634
|
+
value: value.format.decimals === void 0 ? "" : String(value.format.decimals),
|
|
7635
|
+
placeholder: "Auto",
|
|
7636
|
+
"aria-label": "Decimals",
|
|
7637
|
+
title: "Decimals",
|
|
7638
|
+
inputMode: "numeric",
|
|
7639
|
+
"data-option": `${key}.format.decimals`,
|
|
7640
|
+
className: `${chartInputClass} w-14 shrink-0`,
|
|
7641
|
+
onCommit: (text) => {
|
|
7642
|
+
const format = { ...value.format };
|
|
7643
|
+
if (text.trim() === "") delete format.decimals;
|
|
7644
|
+
else format.decimals = Number(text);
|
|
7645
|
+
return set({ format }).ok;
|
|
7646
|
+
}
|
|
7647
|
+
}
|
|
7648
|
+
)
|
|
7649
|
+
] }) }),
|
|
7650
|
+
value.format.style === "currency" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Currency", htmlFor: `${idBase}-${axis}-currency`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-${axis}-currency`, value: value.format.currency ?? "USD", "data-option": `${key}.format.currency`, className: chartInputClass, onCommit: (currency) => void setFormat({ currency: currency.toUpperCase() }) }) }),
|
|
7651
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Code", htmlFor: `${idBase}-${axis}-code`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7652
|
+
ChartCommitInput,
|
|
7653
|
+
{
|
|
7654
|
+
id: `${idBase}-${axis}-code`,
|
|
7655
|
+
value: value.format.code ?? "",
|
|
7656
|
+
placeholder: 'e.g. #,##0.0,,"M"',
|
|
7657
|
+
"data-option": `${key}.format.code`,
|
|
7658
|
+
className: chartInputClass,
|
|
7659
|
+
onCommit: (code) => {
|
|
7660
|
+
const format = { ...value.format };
|
|
7661
|
+
if (code.trim()) format.code = code.trim();
|
|
7662
|
+
else delete format.code;
|
|
7663
|
+
return set({ format }).ok;
|
|
7664
|
+
}
|
|
7665
|
+
}
|
|
7666
|
+
) })
|
|
7667
|
+
] })
|
|
7668
|
+
] });
|
|
7669
|
+
}
|
|
7670
|
+
function ChartInspector({ controller, sections, className }) {
|
|
7671
|
+
const { spec, selectedSeries } = useChartState(controller);
|
|
7672
|
+
const idBase = (0, import_react59.useId)();
|
|
7673
|
+
const show = (section) => !sections || sections.includes(section);
|
|
7674
|
+
const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
|
|
7675
|
+
const family = (0, import_chart4.chartFamily)(spec);
|
|
7676
|
+
const hasAxes = family === "cartesian" || family === "xy" || family === "waterfall" || family === "histogram" || family === "box";
|
|
7677
|
+
const types = spec.series.map((s) => (0, import_chart4.chartSeriesType)(spec, s));
|
|
7678
|
+
const usesSecondary = family === "cartesian" && spec.series.some((s) => s.axis === "secondary" && !s.hidden);
|
|
7679
|
+
const colorCheck = (0, import_chart4.checkChartColors)(spec.series.filter((s) => !s.hidden).map((s) => (0, import_chart4.chartSeriesColor)(spec, spec.series.indexOf(s))));
|
|
7680
|
+
const hasBars = cartesian && types.includes("bar");
|
|
7681
|
+
const hasLines = cartesian && types.some((t) => t === "line" || t === "area");
|
|
7682
|
+
const seriesIndex = selectedSeries ? spec.series.findIndex((s) => s.id === selectedSeries.id) : -1;
|
|
7683
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: `space-y-3 text-xs ${className ?? ""}`, "data-chart-inspector": "", children: [
|
|
7684
|
+
show("type") && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: chartSectionClass, "data-section": "type", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "grid grid-cols-3 gap-0.5 rounded-md bg-muted p-0.5", role: "radiogroup", "aria-label": "Chart type", children: import_chart4.CHART_TYPES.map((type) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", role: "radio", "aria-checked": spec.type === type, "data-chart-type": type, className: chartSegmentClass(spec.type === type), onClick: () => controller.setType(type), children: import_chart4.CHART_TYPE_LABELS[type] }, type)) }) }),
|
|
7685
|
+
show("style") && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "style", children: [
|
|
7686
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Layout", htmlFor: `${idBase}-layout`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("select", { id: `${idBase}-layout`, className: chartInputClass, value: "", "data-option": "preset.layout", onChange: (e) => e.currentTarget.value && controller.applyPreset({ layout: e.currentTarget.value }), children: [
|
|
7687
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "Quick layout\u2026" }),
|
|
7688
|
+
import_chart4.CHART_LAYOUT_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: p.id, title: p.description, children: p.label }, p.id))
|
|
7689
|
+
] }) }),
|
|
7690
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Colours", htmlFor: `${idBase}-colors`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("select", { id: `${idBase}-colors`, className: chartInputClass, value: import_chart4.CHART_COLOR_SCHEMES.find((c) => c.palette.join() === spec.palette.join())?.id ?? "", "data-option": "preset.colors", onChange: (e) => e.currentTarget.value && controller.applyPreset({ colors: e.currentTarget.value }), children: [
|
|
7691
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "Custom" }),
|
|
7692
|
+
import_chart4.CHART_COLOR_SCHEMES.map((c) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: c.id, title: c.description, children: c.label }, c.id))
|
|
7693
|
+
] }) }),
|
|
7694
|
+
!colorCheck.ok && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "text-[11px] leading-snug text-amber-600 dark:text-amber-400", "data-chart-color-warning": "", children: colorCheck.issues[0] }),
|
|
7695
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "transpose", onClick: () => controller.transpose(), children: "Switch rows and columns" })
|
|
7696
|
+
] }),
|
|
7697
|
+
show("titles") && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "titles", children: [
|
|
7698
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Title", htmlFor: `${idBase}-title`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-title`, value: spec.title, "data-option": "title", className: chartInputClass, onCommit: (title) => void controller.setTitle(title) }) }),
|
|
7699
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Subtitle", htmlFor: `${idBase}-subtitle`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-subtitle`, value: spec.subtitle, "data-option": "subtitle", className: chartInputClass, onCommit: (subtitle) => void controller.setSubtitle(subtitle) }) })
|
|
7700
|
+
] }),
|
|
7701
|
+
show("options") && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "options", children: [
|
|
7702
|
+
cartesian && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Stacking", htmlFor: `${idBase}-stacking`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Select, { id: `${idBase}-stacking`, name: "stacking", value: spec.stacking, options: import_chart4.CHART_STACKINGS, labels: { none: "None", stacked: "Stacked", percent: "100%" }, onChange: (stacking) => controller.update({ stacking }) }) }),
|
|
7703
|
+
hasBars && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Bars", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "flex gap-0.5 rounded-md bg-muted p-0.5", children: ["vertical", "horizontal"].map((o) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", "aria-pressed": spec.orientation === o, "data-option": `orientation.${o}`, className: chartSegmentClass(spec.orientation === o), onClick: () => controller.update({ orientation: o }), children: cap(o) }, o)) }) }),
|
|
7704
|
+
hasLines && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Lines", htmlFor: `${idBase}-curve`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Select, { id: `${idBase}-curve`, name: "curve", value: spec.curve, options: import_chart4.CHART_CURVES, onChange: (curve) => controller.update({ curve }) }) }),
|
|
7705
|
+
spec.type === "donut" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Hole", htmlFor: `${idBase}-hole`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7706
|
+
"input",
|
|
7707
|
+
{
|
|
7708
|
+
id: `${idBase}-hole`,
|
|
7709
|
+
type: "range",
|
|
7710
|
+
min: 0,
|
|
7711
|
+
max: 0.9,
|
|
7712
|
+
step: 0.05,
|
|
7713
|
+
value: spec.innerRadius,
|
|
7714
|
+
"data-option": "innerRadius",
|
|
7715
|
+
className: "w-full accent-primary",
|
|
7716
|
+
onPointerDown: () => controller.beginGesture("innerRadius"),
|
|
7717
|
+
onPointerUp: () => controller.endGesture(),
|
|
7718
|
+
onChange: (e) => controller.update({ innerRadius: Number(e.currentTarget.value) })
|
|
7719
|
+
}
|
|
7720
|
+
) }),
|
|
7721
|
+
hasBars && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Spacing", htmlFor: `${idBase}-gap`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7722
|
+
"input",
|
|
7723
|
+
{
|
|
7724
|
+
id: `${idBase}-gap`,
|
|
7725
|
+
type: "range",
|
|
7726
|
+
min: 0,
|
|
7727
|
+
max: 0.9,
|
|
7728
|
+
step: 0.02,
|
|
7729
|
+
value: spec.gapWidth,
|
|
7730
|
+
"data-option": "gapWidth",
|
|
7731
|
+
className: "w-full accent-primary",
|
|
7732
|
+
onPointerDown: () => controller.beginGesture("gapWidth"),
|
|
7733
|
+
onPointerUp: () => controller.endGesture(),
|
|
7734
|
+
onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
|
|
7735
|
+
}
|
|
7736
|
+
) }),
|
|
7737
|
+
spec.dataLabels && hasBars && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Labels", htmlFor: `${idBase}-label-position`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Select, { id: `${idBase}-label-position`, name: "labelPosition", value: spec.labelPosition, options: import_chart4.CHART_LABEL_POSITIONS, onChange: (labelPosition) => controller.update({ labelPosition }) }) }),
|
|
7738
|
+
spec.type === "histogram" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Bins", htmlFor: `${idBase}-bins`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-bins`, value: spec.bins === null ? "" : String(spec.bins), placeholder: "Auto", inputMode: "numeric", "data-option": "bins", className: chartInputClass, onCommit: (text) => controller.update({ bins: text.trim() === "" ? null : Number(text) }).ok }) }),
|
|
7739
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
7740
|
+
spec.type === "waterfall" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Total bar", name: "showTotal", checked: spec.showTotal, onChange: (showTotal) => controller.update({ showTotal }) }),
|
|
7741
|
+
hasLines && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Points", name: "points", checked: spec.points, onChange: (points) => controller.update({ points }) }),
|
|
7742
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Data labels", name: "dataLabels", checked: spec.dataLabels, onChange: (dataLabels) => controller.update({ dataLabels }) })
|
|
7743
|
+
] })
|
|
7744
|
+
] }),
|
|
7745
|
+
show("legend") && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "legend", children: [
|
|
7746
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center justify-between", children: [
|
|
7747
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Legend" }),
|
|
7748
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Show", name: "legend.show", checked: spec.legend.show, onChange: (v) => controller.setLegend({ show: v }) })
|
|
7749
|
+
] }),
|
|
7750
|
+
spec.legend.show && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "flex gap-0.5 rounded-md bg-muted p-0.5", children: import_chart4.CHART_LEGEND_POSITIONS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", "aria-pressed": spec.legend.position === p, "data-option": `legend.${p}`, className: chartSegmentClass(spec.legend.position === p), onClick: () => controller.setLegend({ position: p }), children: cap(p) }, p)) })
|
|
7751
|
+
] }),
|
|
7752
|
+
show("axes") && hasAxes && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
|
|
7753
|
+
family !== "box" && family !== "histogram" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy" }),
|
|
7754
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal" }),
|
|
7755
|
+
usesSecondary && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal" })
|
|
7756
|
+
] }),
|
|
7757
|
+
show("series") && selectedSeries && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
|
|
7758
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
|
|
7759
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Name", htmlFor: `${idBase}-series-name`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-series-name`, value: selectedSeries.name, "data-option": "series.name", className: chartInputClass, onCommit: (name) => void controller.updateSeries(selectedSeries.id, { name }) }) }),
|
|
7760
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
7761
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7762
|
+
"input",
|
|
7763
|
+
{
|
|
7764
|
+
id: `${idBase}-series-color`,
|
|
7765
|
+
type: "color",
|
|
7766
|
+
value: (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)),
|
|
7767
|
+
"data-option": "series.color",
|
|
7768
|
+
className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
|
|
7769
|
+
onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
|
|
7770
|
+
onBlur: () => controller.endGesture(),
|
|
7771
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
|
|
7772
|
+
}
|
|
7773
|
+
),
|
|
7774
|
+
selectedSeries.color && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
|
|
7775
|
+
] }) }),
|
|
7776
|
+
cartesian && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Draw as", htmlFor: `${idBase}-series-type`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
|
|
7777
|
+
"select",
|
|
7778
|
+
{
|
|
7779
|
+
id: `${idBase}-series-type`,
|
|
7780
|
+
className: chartInputClass,
|
|
7781
|
+
value: selectedSeries.type ?? "",
|
|
7782
|
+
"data-option": "series.type",
|
|
7783
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { type: e.currentTarget.value || null }),
|
|
7784
|
+
children: [
|
|
7785
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "Chart type" }),
|
|
7786
|
+
import_chart4.CHART_SERIES_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: t, children: import_chart4.CHART_TYPE_LABELS[t] }, t))
|
|
7787
|
+
]
|
|
7788
|
+
}
|
|
7789
|
+
) }),
|
|
7790
|
+
(cartesian || family === "xy") && ["line", "area", "scatter"].includes((0, import_chart4.chartSeriesType)(spec, selectedSeries)) && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Marker", htmlFor: `${idBase}-series-marker`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
|
|
7791
|
+
"select",
|
|
7792
|
+
{
|
|
7793
|
+
id: `${idBase}-series-marker`,
|
|
7794
|
+
className: chartInputClass,
|
|
7795
|
+
value: selectedSeries.marker ?? "",
|
|
7796
|
+
"data-option": "series.marker",
|
|
7797
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { marker: e.currentTarget.value || null }),
|
|
7798
|
+
children: [
|
|
7799
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "Default" }),
|
|
7800
|
+
import_chart4.CHART_MARKERS.map((m) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: m, children: cap(m) }, m))
|
|
7801
|
+
]
|
|
7802
|
+
}
|
|
7803
|
+
) }),
|
|
7804
|
+
(0, import_chart4.chartSupportsTrendlines)(spec.type, spec.stacking) && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "space-y-1", "data-section": "trendlines", children: [
|
|
7805
|
+
(selectedSeries.trendlines ?? []).map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-1", "data-trendline": i, children: [
|
|
7806
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 truncate text-muted-foreground", children: (0, import_chart4.chartTrendlineName)(t, selectedSeries.name) }),
|
|
7807
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "R\xB2", name: `trendline.${i}.showR2`, checked: !!t.showR2, onChange: (showR2) => controller.updateTrendline(selectedSeries.id, i, { showR2 }) }),
|
|
7808
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: chartButtonClass, "aria-label": "Delete trendline", "data-action": "trendline-delete", onClick: () => controller.removeTrendline(selectedSeries.id, i), children: "\xD7" })
|
|
7809
|
+
] }, i)),
|
|
7810
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
|
|
7811
|
+
"select",
|
|
7812
|
+
{
|
|
7813
|
+
className: chartInputClass,
|
|
7814
|
+
value: "",
|
|
7815
|
+
"aria-label": "Add trendline",
|
|
7816
|
+
"data-option": "trendline.add",
|
|
7817
|
+
onChange: (e) => e.currentTarget.value && controller.addTrendline(selectedSeries.id, { type: e.currentTarget.value }),
|
|
7818
|
+
children: [
|
|
7819
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "Add trendline\u2026" }),
|
|
7820
|
+
import_chart4.CHART_TRENDLINE_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: t, children: cap(t.replace("-", " ")) }, t))
|
|
7821
|
+
]
|
|
7822
|
+
}
|
|
7823
|
+
)
|
|
7824
|
+
] }),
|
|
7825
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
7826
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Hidden", name: "series.hidden", checked: !!selectedSeries.hidden, onChange: (hidden) => controller.updateSeries(selectedSeries.id, { hidden }) }),
|
|
7827
|
+
family === "cartesian" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Secondary axis", name: "series.axis", checked: selectedSeries.axis === "secondary", onChange: (secondary) => controller.updateSeries(selectedSeries.id, { axis: secondary ? "secondary" : null }) }),
|
|
7828
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1" }),
|
|
7829
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: chartButtonClass, disabled: seriesIndex <= 0, "aria-label": "Move series earlier", "data-action": "series-up", onClick: () => controller.moveSeries(selectedSeries.id, seriesIndex - 1), children: "\u2191" }),
|
|
7830
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: chartButtonClass, disabled: seriesIndex >= spec.series.length - 1, "aria-label": "Move series later", "data-action": "series-down", onClick: () => controller.moveSeries(selectedSeries.id, seriesIndex + 1), children: "\u2193" }),
|
|
7831
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", className: `${chartButtonClass} text-destructive`, "data-action": "series-delete", onClick: () => controller.removeSeries(selectedSeries.id), children: "Delete" })
|
|
7832
|
+
] })
|
|
7833
|
+
] })
|
|
7834
|
+
] });
|
|
7835
|
+
}
|
|
7836
|
+
|
|
7837
|
+
// src/chart-node/ChartNodeView.tsx
|
|
7838
|
+
var import_jsx_runtime41 = require("react/jsx-runtime");
|
|
7839
|
+
function ChartNodeView({ state, theme, showDataGrid = true }) {
|
|
7840
|
+
const { controller, editing, editable, selected, width, height, setEditing } = state;
|
|
7841
|
+
const open = () => {
|
|
7842
|
+
if (editable && !editing) setEditing(true);
|
|
7843
|
+
};
|
|
7844
|
+
return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
|
|
7845
|
+
"div",
|
|
7846
|
+
{
|
|
7847
|
+
className: `not-prose my-2 rounded-md border bg-background p-1 ${selected ? "border-primary ring-1 ring-primary" : "border-border"}`,
|
|
7848
|
+
"data-chart-node-view": "",
|
|
7849
|
+
"data-editing": editing ? "" : void 0,
|
|
7850
|
+
onKeyDown: (e) => {
|
|
7851
|
+
if (editing && e.key === "Escape") {
|
|
7852
|
+
e.stopPropagation();
|
|
7853
|
+
setEditing(false);
|
|
7854
|
+
}
|
|
7855
|
+
},
|
|
7856
|
+
children: [
|
|
7857
|
+
editing && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "mb-1 flex items-center justify-between gap-2 px-1", "data-chart-node-toolbar": "", children: [
|
|
7858
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "text-xs text-muted-foreground", children: "Editing chart" }),
|
|
7859
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "done", onClick: () => setEditing(false), children: "Done" })
|
|
7860
|
+
] }),
|
|
7861
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
|
|
7862
|
+
"div",
|
|
7863
|
+
{
|
|
7864
|
+
className: editable && !editing ? "cursor-pointer" : void 0,
|
|
7865
|
+
onClick: open,
|
|
7866
|
+
title: editable && !editing ? "Click to edit the chart" : void 0,
|
|
7867
|
+
"data-chart-node-canvas": "",
|
|
7868
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ChartCanvas, { controller, width: width ?? 640, height, responsive: width === null, editable: editing, theme })
|
|
7869
|
+
}
|
|
7870
|
+
),
|
|
7871
|
+
editing && // Wraps by the document's width, not the viewport's: side by side when there is room.
|
|
7872
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "mt-2 flex flex-wrap items-start gap-2", "data-chart-node-panel": "", children: [
|
|
7873
|
+
showDataGrid && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "min-w-0 flex-[1_1_20rem] overflow-x-auto", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ChartDataGrid, { controller }) }),
|
|
7874
|
+
/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ChartInspector, { controller, className: "max-h-96 min-w-0 flex-[1_1_16rem] overflow-y-auto rounded-md border border-border p-3" })
|
|
7875
|
+
] })
|
|
7876
|
+
]
|
|
7877
|
+
}
|
|
7878
|
+
);
|
|
7879
|
+
}
|
|
7880
|
+
function createReactChartNodeView(options = {}) {
|
|
7881
|
+
const { component: Component = ChartNodeView, ...props } = options;
|
|
7882
|
+
return (dom, state) => {
|
|
7883
|
+
const root = (0, import_client.createRoot)(dom);
|
|
7884
|
+
let latest = state;
|
|
7885
|
+
let scheduled = false;
|
|
7886
|
+
let destroyed = false;
|
|
7887
|
+
const schedule = () => {
|
|
7888
|
+
if (scheduled) return;
|
|
7889
|
+
scheduled = true;
|
|
7890
|
+
queueMicrotask(() => {
|
|
7891
|
+
scheduled = false;
|
|
7892
|
+
if (!destroyed) root.render(/* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Component, { ...props, state: latest }));
|
|
7893
|
+
});
|
|
7894
|
+
};
|
|
7895
|
+
schedule();
|
|
7896
|
+
return {
|
|
7897
|
+
update: (next) => {
|
|
7898
|
+
latest = next;
|
|
7899
|
+
schedule();
|
|
7900
|
+
},
|
|
7901
|
+
destroy: () => {
|
|
7902
|
+
destroyed = true;
|
|
7903
|
+
queueMicrotask(() => root.unmount());
|
|
7904
|
+
}
|
|
7905
|
+
};
|
|
7906
|
+
};
|
|
7907
|
+
}
|
|
7236
7908
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7237
7909
|
0 && (module.exports = {
|
|
7238
7910
|
AdjustmentLayersPanel,
|
|
7239
7911
|
AssetMentionChips,
|
|
7240
7912
|
BubbleMenu,
|
|
7913
|
+
ChartNodeView,
|
|
7241
7914
|
CommandPalette,
|
|
7242
7915
|
CommentButton,
|
|
7243
7916
|
CommentsPanel,
|
|
@@ -7279,6 +7952,7 @@ var TableBubbleMenu = ({
|
|
|
7279
7952
|
bindDirtyToHistory,
|
|
7280
7953
|
createDirtyTracker,
|
|
7281
7954
|
createHistoryManager,
|
|
7955
|
+
createReactChartNodeView,
|
|
7282
7956
|
defaultIsEqual,
|
|
7283
7957
|
useAgentToolProvider,
|
|
7284
7958
|
useAutosave,
|