@opendata-ai/openchart-react 9.4.0 → 9.5.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/index.d.ts CHANGED
@@ -53,9 +53,11 @@ interface ChartBaseProps<TData extends DataRow = DataRow> extends ChartEventHand
53
53
  /**
54
54
  * Interaction mode: `'read'`, `'select'`, or `'edit'`. When omitted it is
55
55
  * inferred from the callbacks (`onEdit` -> edit, `onSelect`/`onDeselect` ->
56
- * select, otherwise read). Changing it recreates the chart.
56
+ * select, otherwise read). Changes switch modes in place.
57
57
  */
58
58
  interaction?: InteractionMode;
59
+ /** Selection outline color. Changing it recreates the chart, like theme. */
60
+ selectionColor?: string;
59
61
  /** Theme overrides. */
60
62
  theme?: ThemeConfig;
61
63
  /** Dark mode: "auto", "force", or "off". */
package/dist/index.js CHANGED
@@ -121,7 +121,8 @@ var BarList = /* @__PURE__ */ forwardRef(function BarList2({ spec, theme: themeP
121
121
  import { mergeThemeConfig as mergeThemeConfig2 } from "@opendata-ai/openchart-core";
122
122
  import {
123
123
  createChart,
124
- createChartReaderBinding
124
+ createChartReaderBinding,
125
+ resolveInteractionMode
125
126
  } from "@opendata-ai/openchart-vanilla";
126
127
  import {
127
128
  forwardRef as forwardRef2,
@@ -154,15 +155,17 @@ function ChartInner({
154
155
  onSelect,
155
156
  onDeselect,
156
157
  onReveal,
158
+ onPlacementToolChange,
157
159
  interaction,
160
+ selectionColor,
158
161
  selectedElement: selectedElementProp,
159
162
  highlight,
160
163
  className,
161
164
  style
162
165
  }, ref) {
166
+ const mode = resolveInteractionMode({ interaction, onEdit, onSelect, onDeselect });
163
167
  const hasEditListener = Boolean(onEdit);
164
- const hasSelectListener = Boolean(onSelect);
165
- const hasDeselectListener = Boolean(onDeselect);
168
+ const previousSelectedElement = useRef2(selectedElementProp);
166
169
  const contextTheme = useVizTheme();
167
170
  const contextDarkMode = useVizDarkMode();
168
171
  const theme = useMemo2(() => mergeThemeConfig2(contextTheme, themeProp), [contextTheme, themeProp]);
@@ -200,7 +203,8 @@ function ChartInner({
200
203
  onAnnotationClick,
201
204
  onSelect,
202
205
  onDeselect,
203
- onReveal
206
+ onReveal,
207
+ onPlacementToolChange
204
208
  };
205
209
  const stableOnMarkClick = useCallback2(
206
210
  (event) => handlersRef.current.onMarkClick?.(event),
@@ -243,6 +247,10 @@ function ChartInner({
243
247
  (guess) => handlersRef.current.onReveal?.(guess),
244
248
  []
245
249
  );
250
+ const stableOnPlacementToolChange = useCallback2(
251
+ (tool) => handlersRef.current.onPlacementToolChange?.(tool),
252
+ []
253
+ );
246
254
  useImperativeHandle2(
247
255
  ref,
248
256
  () => ({
@@ -268,6 +276,7 @@ function ChartInner({
268
276
  theme,
269
277
  darkMode: resolvedDarkMode,
270
278
  renderer,
279
+ selectionColor,
271
280
  onMarkClick: stableOnMarkClick,
272
281
  onMarkHover: stableOnMarkHover,
273
282
  onMarkFocus: stableOnMarkFocus,
@@ -275,18 +284,16 @@ function ChartInner({
275
284
  onLegendToggle: stableOnLegendToggle,
276
285
  onHighlightChange: stableOnHighlightChange,
277
286
  onAnnotationClick: stableOnAnnotationClick,
278
- // Only include editing callbacks when the consumer provides them.
279
- // The stable wrappers are always truthy, so gating on handlersRef
280
- // avoids adding unstable prop references to the effect deps.
281
- ...handlersRef.current.onSelect ? { onSelect: stableOnSelect } : {},
282
- ...handlersRef.current.onDeselect ? { onDeselect: stableOnDeselect } : {},
287
+ onSelect: stableOnSelect,
288
+ onDeselect: stableOnDeselect,
289
+ onPlacementToolChange: stableOnPlacementToolChange,
283
290
  ...handlersRef.current.onReveal ? { onReveal: stableOnReveal } : {},
284
- ...interaction != null ? { interaction } : {},
291
+ interaction: mode,
285
292
  ...selectedElementProp ? { selectedElement: selectedElementProp } : {},
286
293
  rowHover,
287
294
  autoResize,
288
295
  revision,
289
- ...handlersRef.current.onEdit ? { onEdit: stableOnEdit } : {}
296
+ onEdit: stableOnEdit
290
297
  };
291
298
  chartRef.current = createChart(container, spec, options);
292
299
  specRef.current = JSON.stringify(spec);
@@ -300,12 +307,10 @@ function ChartInner({
300
307
  theme,
301
308
  resolvedDarkMode,
302
309
  renderer,
303
- interaction,
310
+ selectionColor,
304
311
  stableOnAnnotationClick,
305
312
  stableOnEdit,
306
- hasEditListener,
307
- hasSelectListener,
308
- hasDeselectListener,
313
+ stableOnPlacementToolChange,
309
314
  rowHover,
310
315
  autoResize,
311
316
  stableOnLegendToggle,
@@ -318,6 +323,17 @@ function ChartInner({
318
323
  stableOnDeselect,
319
324
  stableOnReveal
320
325
  ]);
326
+ useEffect2(() => {
327
+ const chart = chartRef.current;
328
+ if (chart && chart.getInteraction() !== mode) chart.setInteraction(mode);
329
+ }, [mode]);
330
+ useEffect2(() => {
331
+ if (mode === "edit" && !hasEditListener) {
332
+ console.warn(
333
+ "[openchart] interaction: 'edit' was set without an onEdit handler; edit gestures will run but their transactions have no sink."
334
+ );
335
+ }
336
+ }, [mode, hasEditListener]);
321
337
  useEffect2(() => {
322
338
  syncReader();
323
339
  }, [reader, readerSelection, onReaderChange]);
@@ -338,11 +354,12 @@ function ChartInner({
338
354
  const chart = chartRef.current;
339
355
  if (!chart || !chart.select) return;
340
356
  if (selectedElementProp) {
341
- chart.select(selectedElementProp);
342
- } else if (chart.getSelectedElement?.()) {
357
+ if (mode !== "read") chart.select(selectedElementProp);
358
+ } else if (previousSelectedElement.current && chart.getSelectedElement?.()) {
343
359
  chart.deselect();
344
360
  }
345
- }, [selectedElementProp]);
361
+ previousSelectedElement.current = selectedElementProp;
362
+ }, [selectedElementProp, mode]);
346
363
  useEffect2(() => {
347
364
  if (chartRef.current && highlight !== void 0) {
348
365
  chartRef.current.setHighlight(highlight);