@pixerate/editor-react 0.38.0 → 0.40.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 +87 -8
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +8 -2
- package/dist/chart/index.d.ts +8 -2
- package/dist/chart/index.js +5 -3
- package/dist/chart/index.js.map +1 -1
- package/dist/{chunk-IH5ZIOK3.js → chunk-SIEOYRHX.js} +93 -7
- package/dist/chunk-SIEOYRHX.js.map +1 -0
- package/dist/index.cjs +60 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-IH5ZIOK3.js.map +0 -1
package/dist/chart/index.cjs
CHANGED
|
@@ -42,7 +42,8 @@ __export(chart_exports, {
|
|
|
42
42
|
useChartDirector: () => useChartDirector,
|
|
43
43
|
useChartEditor: () => useChartEditor,
|
|
44
44
|
useChartState: () => useChartState,
|
|
45
|
-
useChartToolProvider: () => useChartToolProvider
|
|
45
|
+
useChartToolProvider: () => useChartToolProvider,
|
|
46
|
+
useOfficeChartToolProvider: () => useOfficeChartToolProvider
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(chart_exports);
|
|
48
49
|
|
|
@@ -96,6 +97,29 @@ function useChartToolProvider(registry, controller, options = {}) {
|
|
|
96
97
|
return registry.register((0, import_chart.createChartToolProvider)(controller, { ...rest, id, namespace, rasterize: rasterize === false ? void 0 : rasterize ?? (0, import_chart.createChartRasterizer)() }));
|
|
97
98
|
}, [registry, controller, id, namespace]);
|
|
98
99
|
}
|
|
100
|
+
function useOfficeChartToolProvider(registry, options = {}) {
|
|
101
|
+
const latest = (0, import_react.useRef)(options);
|
|
102
|
+
latest.current = options;
|
|
103
|
+
const { id, namespace, controller } = options;
|
|
104
|
+
const hasFiles = !!options.files;
|
|
105
|
+
(0, import_react.useEffect)(() => {
|
|
106
|
+
if (!registry) return;
|
|
107
|
+
const current = latest.current;
|
|
108
|
+
return registry.register(
|
|
109
|
+
(0, import_chart.createOfficeChartToolProvider)({
|
|
110
|
+
...current,
|
|
111
|
+
id,
|
|
112
|
+
namespace,
|
|
113
|
+
controller,
|
|
114
|
+
files: hasFiles ? () => latest.current.files?.() ?? [] : void 0,
|
|
115
|
+
readOnly: () => {
|
|
116
|
+
const r = latest.current.readOnly;
|
|
117
|
+
return (typeof r === "function" ? r() : r) ?? false;
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}, [registry, id, namespace, controller, hasFiles]);
|
|
122
|
+
}
|
|
99
123
|
function useChartDirector(controller, options = {}) {
|
|
100
124
|
const sceneRef = (0, import_react.useRef)(null);
|
|
101
125
|
const ref = (0, import_react.useRef)(null);
|
|
@@ -435,7 +459,7 @@ function Toggle({ label, checked, onChange, name }) {
|
|
|
435
459
|
function Select({ id, value, options, onChange, name, labels }) {
|
|
436
460
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("select", { id, className: chartInputClass, value, "data-option": name, onChange: (e) => onChange(e.currentTarget.value), children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: o, children: labels?.[o] ?? cap(o) }, o)) });
|
|
437
461
|
}
|
|
438
|
-
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false }) {
|
|
462
|
+
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false, scales = false }) {
|
|
439
463
|
const set = (patch) => controller.setAxis(axis, patch);
|
|
440
464
|
const setFormat = (patch) => set({ format: { ...value.format, ...patch } });
|
|
441
465
|
const bound = (key2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -468,9 +492,22 @@ function AxisSection({ controller, axis, value, idBase, horizontal, numeric = fa
|
|
|
468
492
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Title", htmlFor: `${idBase}-${axis}-title`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${idBase}-${axis}-title`, value: value.title, "data-option": `${axis}Axis.title`, className: chartInputClass, onCommit: (title) => void set({ title }) }) }),
|
|
469
493
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
470
494
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Grid lines", name: `${key}.gridlines`, checked: value.gridlines, onChange: (gridlines) => set({ gridlines }) }),
|
|
471
|
-
axis === "x" && !numeric && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) })
|
|
495
|
+
axis === "x" && !numeric && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) }),
|
|
496
|
+
scales && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Reverse", name: `${key}.reverse`, checked: !!value.reverse, onChange: (reverse) => set({ reverse }) }),
|
|
497
|
+
scales && valueAxis && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Log scale", name: `${key}.scale`, checked: value.scale === "log", onChange: (log) => set({ scale: log ? "log" : "linear" }) })
|
|
472
498
|
] }),
|
|
473
|
-
valueAxis && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "
|
|
499
|
+
scales && valueAxis && value.scale === "log" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Log base", htmlFor: `${idBase}-${axis}-log-base`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
500
|
+
ChartCommitInput,
|
|
501
|
+
{
|
|
502
|
+
id: `${idBase}-${axis}-log-base`,
|
|
503
|
+
value: String(value.logBase ?? 10),
|
|
504
|
+
inputMode: "decimal",
|
|
505
|
+
"data-option": `${key}.logBase`,
|
|
506
|
+
className: chartInputClass,
|
|
507
|
+
onCommit: (text) => set({ logBase: text.trim() === "" ? void 0 : Number(text) }).ok
|
|
508
|
+
}
|
|
509
|
+
) }),
|
|
510
|
+
valueAxis && value.scale !== "log" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Step", htmlFor: `${idBase}-${axis}-step`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
474
511
|
ChartCommitInput,
|
|
475
512
|
{
|
|
476
513
|
id: `${idBase}-${axis}-step`,
|
|
@@ -528,6 +565,44 @@ function AxisSection({ controller, axis, value, idBase, horizontal, numeric = fa
|
|
|
528
565
|
] })
|
|
529
566
|
] });
|
|
530
567
|
}
|
|
568
|
+
function ErrorBarFields({ controller, series, which, idBase }) {
|
|
569
|
+
const bars = series[which];
|
|
570
|
+
const key = `series.${which}`;
|
|
571
|
+
const id = `${idBase}-${which}`;
|
|
572
|
+
const values = which === "xErrorBars" ? series.x ?? [] : series.values;
|
|
573
|
+
const set = (next) => controller.updateSeries(series.id, { [which]: next });
|
|
574
|
+
const patch = (p) => bars && set({ ...bars, ...p });
|
|
575
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-1.5", "data-section": which === "errorBars" ? "error-bars" : "x-error-bars", children: [
|
|
576
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: which === "errorBars" ? "Error bars" : "X error bars", htmlFor: `${id}-type`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { id: `${id}-type`, className: chartInputClass, value: bars?.type ?? "", "data-option": `${key}.type`, onChange: (e) => set((0, import_chart4.chartErrorBarsOfType)(e.currentTarget.value, bars, values)), children: [
|
|
577
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "None" }),
|
|
578
|
+
import_chart4.CHART_ERROR_BAR_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: t, children: import_chart4.CHART_ERROR_BAR_LABELS[t] }, t))
|
|
579
|
+
] }) }),
|
|
580
|
+
bars && (bars.type === "fixed" || bars.type === "percent" || bars.type === "stddev") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: bars.type === "percent" ? "Percent" : bars.type === "stddev" ? "Deviations" : "Amount", htmlFor: `${id}-value`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${id}-value`, value: String(bars.value ?? (0, import_chart4.defaultChartErrorBarValue)(bars.type)), inputMode: "decimal", "data-option": `${key}.value`, className: chartInputClass, onCommit: (text) => !!patch({ value: text.trim() === "" ? void 0 : Number(text) })?.ok }) }),
|
|
581
|
+
bars?.type === "custom" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
582
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Plus", htmlFor: `${id}-plus`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${id}-plus`, value: (0, import_chart4.formatChartAmountList)(bars.plus), placeholder: "1, 2, -, 0.5", "data-option": `${key}.plus`, className: chartInputClass, onCommit: (text) => !!patch({ plus: (0, import_chart4.parseChartAmountList)(text) })?.ok }) }),
|
|
583
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Minus", htmlFor: `${id}-minus`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
584
|
+
ChartCommitInput,
|
|
585
|
+
{
|
|
586
|
+
id: `${id}-minus`,
|
|
587
|
+
value: (0, import_chart4.formatChartAmountList)(bars.minus),
|
|
588
|
+
placeholder: "Same as plus",
|
|
589
|
+
"data-option": `${key}.minus`,
|
|
590
|
+
className: chartInputClass,
|
|
591
|
+
onCommit: (text) => {
|
|
592
|
+
const next = { ...bars };
|
|
593
|
+
if (text.trim()) next.minus = (0, import_chart4.parseChartAmountList)(text);
|
|
594
|
+
else delete next.minus;
|
|
595
|
+
return set(next).ok;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
) })
|
|
599
|
+
] }),
|
|
600
|
+
bars && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
601
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("select", { className: `${chartInputClass} flex-1`, "aria-label": "Error bar direction", value: bars.direction ?? "both", "data-option": `${key}.direction`, onChange: (e) => patch({ direction: e.currentTarget.value }), children: import_chart4.CHART_ERROR_BAR_DIRECTIONS.map((d) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: d, children: d === "both" ? "Both ways" : d === "plus" ? "Plus only" : "Minus only" }, d)) }),
|
|
602
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Toggle, { label: "Caps", name: `${key}.cap`, checked: bars.cap !== false, onChange: (cap2) => patch({ cap: cap2 }) })
|
|
603
|
+
] })
|
|
604
|
+
] });
|
|
605
|
+
}
|
|
531
606
|
function ChartInspector({ controller, sections, className }) {
|
|
532
607
|
const { spec, selectedSeries } = useChartState(controller);
|
|
533
608
|
const idBase = (0, import_react4.useId)();
|
|
@@ -541,6 +616,7 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
541
616
|
const hasBars = cartesian && types.includes("bar");
|
|
542
617
|
const hasLines = cartesian && types.some((t) => t === "line" || t === "area");
|
|
543
618
|
const seriesIndex = selectedSeries ? spec.series.findIndex((s) => s.id === selectedSeries.id) : -1;
|
|
619
|
+
const scales = family === "cartesian" || family === "xy";
|
|
544
620
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `space-y-3 text-xs ${className ?? ""}`, "data-chart-inspector": "", children: [
|
|
545
621
|
show("type") && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: chartSectionClass, "data-section": "type", children: /* @__PURE__ */ (0, import_jsx_runtime3.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_runtime3.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)) }) }),
|
|
546
622
|
show("style") && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: chartSectionClass, "data-section": "style", children: [
|
|
@@ -611,9 +687,9 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
611
687
|
spec.legend.show && /* @__PURE__ */ (0, import_jsx_runtime3.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_runtime3.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)) })
|
|
612
688
|
] }),
|
|
613
689
|
show("axes") && hasAxes && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
614
|
-
family !== "box" && family !== "histogram" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy" }),
|
|
615
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal" }),
|
|
616
|
-
usesSecondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal" })
|
|
690
|
+
family !== "box" && family !== "histogram" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy", scales }),
|
|
691
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal", scales }),
|
|
692
|
+
usesSecondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal", scales })
|
|
617
693
|
] }),
|
|
618
694
|
show("series") && selectedSeries && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
|
|
619
695
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
|
|
@@ -662,6 +738,8 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
662
738
|
]
|
|
663
739
|
}
|
|
664
740
|
) }),
|
|
741
|
+
scales && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorBarFields, { controller, series: selectedSeries, which: "errorBars", idBase }),
|
|
742
|
+
family === "xy" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorBarFields, { controller, series: selectedSeries, which: "xErrorBars", idBase }),
|
|
665
743
|
(0, import_chart4.chartSupportsTrendlines)(spec.type, spec.stacking) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-1", "data-section": "trendlines", children: [
|
|
666
744
|
(selectedSeries.trendlines ?? []).map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1", "data-trendline": i, children: [
|
|
667
745
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "flex-1 truncate text-muted-foreground", children: (0, import_chart4.chartTrendlineName)(t, selectedSeries.name) }),
|
|
@@ -801,6 +879,7 @@ function ChartSparkline({ values, width = 80, height = 20, label, className, ...
|
|
|
801
879
|
useChartDirector,
|
|
802
880
|
useChartEditor,
|
|
803
881
|
useChartState,
|
|
804
|
-
useChartToolProvider
|
|
882
|
+
useChartToolProvider,
|
|
883
|
+
useOfficeChartToolProvider
|
|
805
884
|
});
|
|
806
885
|
//# sourceMappingURL=index.cjs.map
|