@pixerate/editor-react 0.201.1 → 0.203.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.
@@ -5,6 +5,8 @@ import { type ChartCanvasProps } from './ChartCanvas.cjs';
5
5
  export interface ChartEditorProps {
6
6
  controller: ChartController;
7
7
  /** The settings sidebar (default `true`). */
8
+ /** House colours the inspector offers beside each series colour (e.g. from `useStyleSwatches`). */
9
+ swatches?: readonly string[];
8
10
  showInspector?: boolean;
9
11
  /** The data grid under the chart (default `true`). */
10
12
  showDataGrid?: boolean;
@@ -28,4 +30,4 @@ export interface ChartEditorProps {
28
30
  onPlaybackReveal?: () => void | Promise<void>;
29
31
  }
30
32
  /** Toolbar, chart, settings sidebar and data grid for a `ChartController`. */
31
- export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
33
+ export declare function ChartEditor({ controller, swatches, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
@@ -5,6 +5,8 @@ import { type ChartCanvasProps } from './ChartCanvas.js';
5
5
  export interface ChartEditorProps {
6
6
  controller: ChartController;
7
7
  /** The settings sidebar (default `true`). */
8
+ /** House colours the inspector offers beside each series colour (e.g. from `useStyleSwatches`). */
9
+ swatches?: readonly string[];
8
10
  showInspector?: boolean;
9
11
  /** The data grid under the chart (default `true`). */
10
12
  showDataGrid?: boolean;
@@ -28,4 +30,4 @@ export interface ChartEditorProps {
28
30
  onPlaybackReveal?: () => void | Promise<void>;
29
31
  }
30
32
  /** Toolbar, chart, settings sidebar and data grid for a `ChartController`. */
31
- export declare function ChartEditor({ controller, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
33
+ export declare function ChartEditor({ controller, swatches, showInspector, showDataGrid, showToolbar, pngOptions, height, canvasProps, className, playback, playbackId, onPlaybackReveal }: ChartEditorProps): React.JSX.Element;
@@ -5,10 +5,12 @@ export interface ChartInspectorProps {
5
5
  /** Which sections to show (default: all that apply to the chart). */
6
6
  sections?: readonly ChartInspectorSection[];
7
7
  className?: string;
8
+ /** House colours offered beside the series colour (e.g. from `useStyleSwatches`). */
9
+ swatches?: readonly string[];
8
10
  }
9
11
  export type ChartInspectorSection = 'type' | 'style' | 'titles' | 'options' | 'legend' | 'axes' | 'annotations' | 'series';
10
12
  /**
11
13
  * Settings for a chart controller: type, titles, stacking and line options, legend, both
12
14
  * axes and the selected series. Every change is one undo step.
13
15
  */
14
- export declare function ChartInspector({ controller, sections, className }: ChartInspectorProps): React.JSX.Element;
16
+ export declare function ChartInspector({ controller, sections, className, swatches }: ChartInspectorProps): React.JSX.Element;
@@ -5,10 +5,12 @@ export interface ChartInspectorProps {
5
5
  /** Which sections to show (default: all that apply to the chart). */
6
6
  sections?: readonly ChartInspectorSection[];
7
7
  className?: string;
8
+ /** House colours offered beside the series colour (e.g. from `useStyleSwatches`). */
9
+ swatches?: readonly string[];
8
10
  }
9
11
  export type ChartInspectorSection = 'type' | 'style' | 'titles' | 'options' | 'legend' | 'axes' | 'annotations' | 'series';
10
12
  /**
11
13
  * Settings for a chart controller: type, titles, stacking and line options, legend, both
12
14
  * axes and the selected series. Every change is one undo step.
13
15
  */
14
- export declare function ChartInspector({ controller, sections, className }: ChartInspectorProps): React.JSX.Element;
16
+ export declare function ChartInspector({ controller, sections, className, swatches }: ChartInspectorProps): React.JSX.Element;
@@ -756,7 +756,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
756
756
  ] })
757
757
  ] });
758
758
  }
759
- function ChartInspector({ controller, sections, className }) {
759
+ function ChartInspector({ controller, sections, className, swatches }) {
760
760
  const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
761
761
  const idBase = (0, import_react4.useId)();
762
762
  const show = (section) => !sections || sections.includes(section);
@@ -938,22 +938,37 @@ function ChartInspector({ controller, sections, className }) {
938
938
  show("series") && selectedSeries && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
939
939
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
940
940
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Name", htmlFor: `${idBase}-series-name`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChartCommitInput, { id: `${idBase}-series-name`, value: selectedSeries.name, "data-option": "series.name", className: chartInputClass, onCommit: (name) => void controller.updateSeries(selectedSeries.id, { name }) }) }),
941
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1", children: [
942
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
943
- "input",
941
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: [
942
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1", children: [
943
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
944
+ "input",
945
+ {
946
+ id: `${idBase}-series-color`,
947
+ type: "color",
948
+ value: (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)),
949
+ "data-option": "series.color",
950
+ className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
951
+ onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
952
+ onBlur: () => controller.endGesture(),
953
+ onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
954
+ }
955
+ ),
956
+ selectedSeries.color && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
957
+ ] }),
958
+ swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mt-1 flex flex-wrap gap-1", role: "group", "aria-label": "House colours", "data-option": "series.swatches", children: swatches.map((color) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
959
+ "button",
944
960
  {
945
- id: `${idBase}-series-color`,
946
- type: "color",
947
- value: (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)),
948
- "data-option": "series.color",
949
- className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
950
- onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
951
- onBlur: () => controller.endGesture(),
952
- onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
953
- }
954
- ),
955
- selectedSeries.color && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
956
- ] }) }),
961
+ type: "button",
962
+ title: color,
963
+ "aria-label": `Use ${color}`,
964
+ "aria-pressed": (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)) === (0, import_chart4.chartColorInputValue)(color),
965
+ className: "h-5 w-5 rounded border border-border",
966
+ style: { background: color },
967
+ onClick: () => controller.updateSeries(selectedSeries.id, { color })
968
+ },
969
+ color
970
+ )) })
971
+ ] }),
957
972
  cartesian && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Field, { label: "Draw as", htmlFor: `${idBase}-series-type`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
958
973
  "select",
959
974
  {
@@ -1125,7 +1140,7 @@ function PresenceLayer({ presence, viewport, clip = true, renderCursor, classNam
1125
1140
 
1126
1141
  // src/chart/ChartEditor.tsx
1127
1142
  var import_jsx_runtime6 = require("react/jsx-runtime");
1128
- function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
1143
+ function ChartEditor({ controller, swatches, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
1129
1144
  const state = useChartState(controller);
1130
1145
  const rootRef = (0, import_react8.useRef)(null);
1131
1146
  const ownScene = (0, import_react8.useRef)(null);
@@ -1203,7 +1218,7 @@ function ChartEditor({ controller, showInspector = true, showDataGrid = true, sh
1203
1218
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
1204
1219
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartCanvas, { controller, height, ...canvasProps, sceneRef, presence: playing ? void 0 : canvasProps?.presence }) }),
1205
1220
  showInspector && // Side by side, the canvas sets the row's height and the inspector scrolls within it.
1206
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartInspector, { controller, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
1221
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartInspector, { controller, swatches, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
1207
1222
  ] }),
1208
1223
  showDataGrid && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartDataGrid, { controller })
1209
1224
  ] });
@@ -22,7 +22,7 @@ import {
22
22
  useChartState,
23
23
  useChartToolProvider,
24
24
  useOfficeChartToolProvider
25
- } from "../chunk-VUSYAHIU.js";
25
+ } from "../chunk-HOTNCOPK.js";
26
26
  import {
27
27
  PresenceLayer,
28
28
  useAgentPlayback,
@@ -33,7 +33,7 @@ import {
33
33
  import { useRef, useState } from "react";
34
34
  import { describeChartSelection, downloadChartPng, locateChartPoint, ChartPresence } from "@pixerate/editor/chart";
35
35
  import { jsx, jsxs } from "react/jsx-runtime";
36
- function ChartEditor({ controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
36
+ function ChartEditor({ controller, swatches, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps, className, playback, playbackId = "chart", onPlaybackReveal }) {
37
37
  const state = useChartState(controller);
38
38
  const rootRef = useRef(null);
39
39
  const ownScene = useRef(null);
@@ -111,7 +111,7 @@ function ChartEditor({ controller, showInspector = true, showDataGrid = true, sh
111
111
  /* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
112
112
  /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1 rounded-md border border-border bg-background p-1", children: /* @__PURE__ */ jsx(ChartCanvas, { controller, height, ...canvasProps, sceneRef, presence: playing ? void 0 : canvasProps?.presence }) }),
113
113
  showInspector && // Side by side, the canvas sets the row's height and the inspector scrolls within it.
114
- /* @__PURE__ */ jsx("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ jsx(ChartInspector, { controller, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
114
+ /* @__PURE__ */ jsx("div", { className: "relative w-full shrink-0 md:w-64", children: /* @__PURE__ */ jsx(ChartInspector, { controller, swatches, className: "overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" }) })
115
115
  ] }),
116
116
  showDataGrid && /* @__PURE__ */ jsx(ChartDataGrid, { controller })
117
117
  ] });
@@ -764,7 +764,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
764
764
  ] })
765
765
  ] });
766
766
  }
767
- function ChartInspector({ controller, sections, className }) {
767
+ function ChartInspector({ controller, sections, className, swatches }) {
768
768
  const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
769
769
  const idBase = useId();
770
770
  const show = (section) => !sections || sections.includes(section);
@@ -946,22 +946,37 @@ function ChartInspector({ controller, sections, className }) {
946
946
  show("series") && selectedSeries && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
947
947
  /* @__PURE__ */ jsx3("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
948
948
  /* @__PURE__ */ jsx3(Field, { label: "Name", htmlFor: `${idBase}-series-name`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-series-name`, value: selectedSeries.name, "data-option": "series.name", className: chartInputClass, onCommit: (name) => void controller.updateSeries(selectedSeries.id, { name }) }) }),
949
- /* @__PURE__ */ jsx3(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
950
- /* @__PURE__ */ jsx3(
951
- "input",
949
+ /* @__PURE__ */ jsxs3(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: [
950
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
951
+ /* @__PURE__ */ jsx3(
952
+ "input",
953
+ {
954
+ id: `${idBase}-series-color`,
955
+ type: "color",
956
+ value: chartColorInputValue2(chartSeriesColor2(spec, seriesIndex)),
957
+ "data-option": "series.color",
958
+ className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
959
+ onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
960
+ onBlur: () => controller.endGesture(),
961
+ onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
962
+ }
963
+ ),
964
+ selectedSeries.color && /* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
965
+ ] }),
966
+ swatches && swatches.length > 0 && /* @__PURE__ */ jsx3("div", { className: "mt-1 flex flex-wrap gap-1", role: "group", "aria-label": "House colours", "data-option": "series.swatches", children: swatches.map((color) => /* @__PURE__ */ jsx3(
967
+ "button",
952
968
  {
953
- id: `${idBase}-series-color`,
954
- type: "color",
955
- value: chartColorInputValue2(chartSeriesColor2(spec, seriesIndex)),
956
- "data-option": "series.color",
957
- className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
958
- onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
959
- onBlur: () => controller.endGesture(),
960
- onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
961
- }
962
- ),
963
- selectedSeries.color && /* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
964
- ] }) }),
969
+ type: "button",
970
+ title: color,
971
+ "aria-label": `Use ${color}`,
972
+ "aria-pressed": chartColorInputValue2(chartSeriesColor2(spec, seriesIndex)) === chartColorInputValue2(color),
973
+ className: "h-5 w-5 rounded border border-border",
974
+ style: { background: color },
975
+ onClick: () => controller.updateSeries(selectedSeries.id, { color })
976
+ },
977
+ color
978
+ )) })
979
+ ] }),
965
980
  cartesian && /* @__PURE__ */ jsx3(Field, { label: "Draw as", htmlFor: `${idBase}-series-type`, children: /* @__PURE__ */ jsxs3(
966
981
  "select",
967
982
  {
package/dist/index.cjs CHANGED
@@ -148,7 +148,9 @@ __export(src_exports, {
148
148
  useSpreadsheetEditor: () => useSpreadsheetEditor,
149
149
  useSpreadsheetViewport: () => useSpreadsheetViewport,
150
150
  useStyle: () => useStyle,
151
+ useStyleChoices: () => useStyleChoices,
151
152
  useStyleFindings: () => useStyleFindings,
153
+ useStyleSwatches: () => useStyleSwatches,
152
154
  useTableMenu: () => useTableMenu,
153
155
  useToolBridge: () => useToolBridge,
154
156
  useToolRegistryView: () => useToolRegistryView,
@@ -14183,7 +14185,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
14183
14185
  ] })
14184
14186
  ] });
14185
14187
  }
14186
- function ChartInspector({ controller, sections, className }) {
14188
+ function ChartInspector({ controller, sections, className, swatches }) {
14187
14189
  const { spec, selectedSeries, selection, raceFrame, racePlaying } = useChartState(controller);
14188
14190
  const idBase = (0, import_react103.useId)();
14189
14191
  const show = (section) => !sections || sections.includes(section);
@@ -14365,22 +14367,37 @@ function ChartInspector({ controller, sections, className }) {
14365
14367
  show("series") && selectedSeries && /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
14366
14368
  /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
14367
14369
  /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(Field, { label: "Name", htmlFor: `${idBase}-series-name`, children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(ChartCommitInput, { id: `${idBase}-series-name`, value: selectedSeries.name, "data-option": "series.name", className: chartInputClass, onCommit: (name) => void controller.updateSeries(selectedSeries.id, { name }) }) }),
14368
- /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { className: "flex items-center gap-1", children: [
14369
- /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14370
- "input",
14370
+ /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: [
14371
+ /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { className: "flex items-center gap-1", children: [
14372
+ /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14373
+ "input",
14374
+ {
14375
+ id: `${idBase}-series-color`,
14376
+ type: "color",
14377
+ value: (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)),
14378
+ "data-option": "series.color",
14379
+ className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
14380
+ onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
14381
+ onBlur: () => controller.endGesture(),
14382
+ onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
14383
+ }
14384
+ ),
14385
+ selectedSeries.color && /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
14386
+ ] }),
14387
+ swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { className: "mt-1 flex flex-wrap gap-1", role: "group", "aria-label": "House colours", "data-option": "series.swatches", children: swatches.map((color) => /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14388
+ "button",
14371
14389
  {
14372
- id: `${idBase}-series-color`,
14373
- type: "color",
14374
- value: (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)),
14375
- "data-option": "series.color",
14376
- className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
14377
- onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
14378
- onBlur: () => controller.endGesture(),
14379
- onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
14380
- }
14381
- ),
14382
- selectedSeries.color && /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
14383
- ] }) }),
14390
+ type: "button",
14391
+ title: color,
14392
+ "aria-label": `Use ${color}`,
14393
+ "aria-pressed": (0, import_chart4.chartColorInputValue)((0, import_chart4.chartSeriesColor)(spec, seriesIndex)) === (0, import_chart4.chartColorInputValue)(color),
14394
+ className: "h-5 w-5 rounded border border-border",
14395
+ style: { background: color },
14396
+ onClick: () => controller.updateSeries(selectedSeries.id, { color })
14397
+ },
14398
+ color
14399
+ )) })
14400
+ ] }),
14384
14401
  cartesian && /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(Field, { label: "Draw as", htmlFor: `${idBase}-series-type`, children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14385
14402
  "select",
14386
14403
  {
@@ -14529,6 +14546,7 @@ function createReactChartNodeView(options = {}) {
14529
14546
 
14530
14547
  // src/style/useStyle.ts
14531
14548
  var import_react104 = require("react");
14549
+ var import_tools5 = require("@pixerate/editor/tools");
14532
14550
  var message = (error) => error instanceof Error ? error.message : String(error);
14533
14551
  function useResolverTask(styles, run, deliver, deps) {
14534
14552
  (0, import_react104.useEffect)(() => {
@@ -14583,6 +14601,41 @@ function useStyleFindings(styles, domain, state) {
14583
14601
  );
14584
14602
  return result;
14585
14603
  }
14604
+ function useStyleChoices(styles, scope) {
14605
+ const [state, setState] = (0, import_react104.useState)({ groups: null, error: null });
14606
+ useResolverTask(
14607
+ styles,
14608
+ (s) => s.choices(scope !== void 0 ? { scope } : {}),
14609
+ ({ value, error }) => setState({ groups: value, error }),
14610
+ [scope]
14611
+ );
14612
+ const choose = (0, import_react104.useCallback)(
14613
+ async (name, options = {}) => {
14614
+ if (!styles) throw new Error("There is no style resolver to choose with.");
14615
+ try {
14616
+ return await styles.choose(name, { ...options, ...scope !== void 0 ? { scope } : {} });
14617
+ } catch (error) {
14618
+ setState((prev) => ({ ...prev, error: message(error) }));
14619
+ throw error;
14620
+ }
14621
+ },
14622
+ [styles, scope]
14623
+ );
14624
+ return { ...state, choose };
14625
+ }
14626
+ function useStyleSwatches(styles, domain, scope) {
14627
+ const [state, setState] = (0, import_react104.useState)({ style: null, error: null });
14628
+ useResolverTask(
14629
+ styles,
14630
+ (s) => s.resolve(domain, scope !== void 0 ? { scope } : {}),
14631
+ ({ value, error }) => setState({ style: value, error }),
14632
+ [domain, scope]
14633
+ );
14634
+ return (0, import_react104.useMemo)(() => {
14635
+ const { colors, fonts } = state.style ? (0, import_tools5.styleSwatches)(state.style) : { colors: [], fonts: [] };
14636
+ return { colors: colors.map((c) => c.color), swatches: colors, fonts, error: state.error };
14637
+ }, [state]);
14638
+ }
14586
14639
 
14587
14640
  // src/style/StyleFindings.tsx
14588
14641
  var import_jsx_runtime80 = require("react/jsx-runtime");
@@ -14756,7 +14809,9 @@ function StyleFindings({ report, onSelect, title = "House style", className = ""
14756
14809
  useSpreadsheetEditor,
14757
14810
  useSpreadsheetViewport,
14758
14811
  useStyle,
14812
+ useStyleChoices,
14759
14813
  useStyleFindings,
14814
+ useStyleSwatches,
14760
14815
  useTableMenu,
14761
14816
  useToolBridge,
14762
14817
  useToolRegistryView,
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  ChartDataGrid,
16
16
  ChartInspector,
17
17
  chartButtonClass
18
- } from "./chunk-VUSYAHIU.js";
18
+ } from "./chunk-HOTNCOPK.js";
19
19
  import {
20
20
  FormulaHints,
21
21
  NameManager,
@@ -2264,7 +2264,8 @@ function createReactChartNodeView(options = {}) {
2264
2264
  }
2265
2265
 
2266
2266
  // src/style/useStyle.ts
2267
- import { useEffect as useEffect13, useState as useState14 } from "react";
2267
+ import { useCallback as useCallback9, useEffect as useEffect13, useMemo as useMemo17, useState as useState14 } from "react";
2268
+ import { styleSwatches } from "@pixerate/editor/tools";
2268
2269
  var message = (error) => error instanceof Error ? error.message : String(error);
2269
2270
  function useResolverTask(styles, run, deliver, deps) {
2270
2271
  useEffect13(() => {
@@ -2319,6 +2320,41 @@ function useStyleFindings(styles, domain, state) {
2319
2320
  );
2320
2321
  return result;
2321
2322
  }
2323
+ function useStyleChoices(styles, scope) {
2324
+ const [state, setState] = useState14({ groups: null, error: null });
2325
+ useResolverTask(
2326
+ styles,
2327
+ (s) => s.choices(scope !== void 0 ? { scope } : {}),
2328
+ ({ value, error }) => setState({ groups: value, error }),
2329
+ [scope]
2330
+ );
2331
+ const choose = useCallback9(
2332
+ async (name, options = {}) => {
2333
+ if (!styles) throw new Error("There is no style resolver to choose with.");
2334
+ try {
2335
+ return await styles.choose(name, { ...options, ...scope !== void 0 ? { scope } : {} });
2336
+ } catch (error) {
2337
+ setState((prev) => ({ ...prev, error: message(error) }));
2338
+ throw error;
2339
+ }
2340
+ },
2341
+ [styles, scope]
2342
+ );
2343
+ return { ...state, choose };
2344
+ }
2345
+ function useStyleSwatches(styles, domain, scope) {
2346
+ const [state, setState] = useState14({ style: null, error: null });
2347
+ useResolverTask(
2348
+ styles,
2349
+ (s) => s.resolve(domain, scope !== void 0 ? { scope } : {}),
2350
+ ({ value, error }) => setState({ style: value, error }),
2351
+ [domain, scope]
2352
+ );
2353
+ return useMemo17(() => {
2354
+ const { colors, fonts } = state.style ? styleSwatches(state.style) : { colors: [], fonts: [] };
2355
+ return { colors: colors.map((c) => c.color), swatches: colors, fonts, error: state.error };
2356
+ }, [state]);
2357
+ }
2322
2358
 
2323
2359
  // src/style/StyleFindings.tsx
2324
2360
  import { Fragment as Fragment2, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
@@ -2491,7 +2527,9 @@ export {
2491
2527
  useSpreadsheetEditor,
2492
2528
  useSpreadsheetViewport,
2493
2529
  useStyle,
2530
+ useStyleChoices,
2494
2531
  useStyleFindings,
2532
+ useStyleSwatches,
2495
2533
  useTableMenu,
2496
2534
  useToolBridge,
2497
2535
  useToolRegistryView,
@@ -1,4 +1,4 @@
1
- import type { ResolvedStyle, StyleCheckReport, StyleResolver } from '@pixerate/editor/tools';
1
+ import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver, StyleSwatch } from '@pixerate/editor/tools';
2
2
  export interface UseStyleResult {
3
3
  /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
4
  style: ResolvedStyle | null;
@@ -20,3 +20,34 @@ export declare function useStyle(styles: StyleResolver | null | undefined, domai
20
20
  * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
21
  */
22
22
  export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
23
+ export interface UseStyleChoicesResult {
24
+ /** The one-of-a-kind groups (a look, a theme) with the chosen skill and every option, or `null` before the first read. */
25
+ groups: StyleChoiceGroup[] | null;
26
+ /** Why the last read or choice failed, or `null`. */
27
+ error: string | null;
28
+ /** Chooses a skill of its group (see `StyleResolver.choose`); resolves to what changed, or rejects with the reason. */
29
+ choose(name: string, options?: {
30
+ layer?: string;
31
+ }): Promise<StyleChoiceResult>;
32
+ }
33
+ /**
34
+ * The house-style choices for a picker: each one-of-a-kind group with the skill that applies
35
+ * and its options, in `scope` when given. Re-reads when the resolver notifies, so a choice an
36
+ * agent makes with `choose_style` shows at once. Parity with Svelte's `useStyleChoices`.
37
+ */
38
+ export declare function useStyleChoices(styles: StyleResolver | null | undefined, scope?: string): UseStyleChoicesResult;
39
+ export interface UseStyleSwatchesResult {
40
+ /** The house colours, in picker order (feed `ColorPicker`'s `swatches` or `ChartEditor`'s). */
41
+ colors: string[];
42
+ /** The same colours with what each is for (`primary`, `palette 2`, ...). */
43
+ swatches: StyleSwatch[];
44
+ /** The house fonts (for a font picker's suggestions). */
45
+ fonts: string[];
46
+ /** Why the last resolve failed, or `null`. */
47
+ error: string | null;
48
+ }
49
+ /**
50
+ * The colours and fonts the house style offers for one domain, for pickers. The agent's
51
+ * `get_style` returns the same list, so people and agents choose from one set.
52
+ */
53
+ export declare function useStyleSwatches(styles: StyleResolver | null | undefined, domain: string, scope?: string): UseStyleSwatchesResult;
@@ -1,4 +1,4 @@
1
- import type { ResolvedStyle, StyleCheckReport, StyleResolver } from '@pixerate/editor/tools';
1
+ import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver, StyleSwatch } from '@pixerate/editor/tools';
2
2
  export interface UseStyleResult {
3
3
  /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
4
  style: ResolvedStyle | null;
@@ -20,3 +20,34 @@ export declare function useStyle(styles: StyleResolver | null | undefined, domai
20
20
  * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
21
  */
22
22
  export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
23
+ export interface UseStyleChoicesResult {
24
+ /** The one-of-a-kind groups (a look, a theme) with the chosen skill and every option, or `null` before the first read. */
25
+ groups: StyleChoiceGroup[] | null;
26
+ /** Why the last read or choice failed, or `null`. */
27
+ error: string | null;
28
+ /** Chooses a skill of its group (see `StyleResolver.choose`); resolves to what changed, or rejects with the reason. */
29
+ choose(name: string, options?: {
30
+ layer?: string;
31
+ }): Promise<StyleChoiceResult>;
32
+ }
33
+ /**
34
+ * The house-style choices for a picker: each one-of-a-kind group with the skill that applies
35
+ * and its options, in `scope` when given. Re-reads when the resolver notifies, so a choice an
36
+ * agent makes with `choose_style` shows at once. Parity with Svelte's `useStyleChoices`.
37
+ */
38
+ export declare function useStyleChoices(styles: StyleResolver | null | undefined, scope?: string): UseStyleChoicesResult;
39
+ export interface UseStyleSwatchesResult {
40
+ /** The house colours, in picker order (feed `ColorPicker`'s `swatches` or `ChartEditor`'s). */
41
+ colors: string[];
42
+ /** The same colours with what each is for (`primary`, `palette 2`, ...). */
43
+ swatches: StyleSwatch[];
44
+ /** The house fonts (for a font picker's suggestions). */
45
+ fonts: string[];
46
+ /** Why the last resolve failed, or `null`. */
47
+ error: string | null;
48
+ }
49
+ /**
50
+ * The colours and fonts the house style offers for one domain, for pickers. The agent's
51
+ * `get_style` returns the same list, so people and agents choose from one set.
52
+ */
53
+ export declare function useStyleSwatches(styles: StyleResolver | null | undefined, domain: string, scope?: string): UseStyleSwatchesResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.201.1",
3
+ "version": "0.203.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -283,7 +283,7 @@
283
283
  "dependencies": {},
284
284
  "peerDependencies": {
285
285
  "@dagrejs/dagre": "^1.1.8",
286
- "@pixerate/editor": ">=0.294.0 <1.0.0-0",
286
+ "@pixerate/editor": ">=0.301.0 <1.0.0-0",
287
287
  "@tiptap/core": "^2.27.3",
288
288
  "@tiptap/extension-bubble-menu": "^2.27.3",
289
289
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -334,7 +334,7 @@
334
334
  "tsup": "^9.0.0",
335
335
  "typescript": "^5.7.3",
336
336
  "vitest": "^5.1.0",
337
- "@pixerate/editor": "0.294.0"
337
+ "@pixerate/editor": "0.301.0"
338
338
  },
339
339
  "scripts": {
340
340
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",