@momoi-labs/kiso-react 0.19.1 → 0.21.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.
@@ -0,0 +1,12 @@
1
+ export type ChartSyncState = {
2
+ /** The inspected timestamp and the Chart that inspects it. */
3
+ hover: number | null;
4
+ source: object | null;
5
+ /** A timestamp a click, Enter or Space keeps marked across the group. */
6
+ pinned: number | null;
7
+ };
8
+ export declare function setChartHover(id: string, source: object, timestamp: number | null): void;
9
+ export declare function toggleChartPin(id: string, timestamp: number): void;
10
+ export declare function clearChartPin(id: string): void;
11
+ export declare function chartPinned(id: string): number | null;
12
+ export declare function useChartSync(id: string): ChartSyncState;
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ const groups = new Map();
4
+ const idle = { hover: null, source: null, pinned: null };
5
+ function group(id) {
6
+ let found = groups.get(id);
7
+ if (!found)
8
+ groups.set(id, found = { state: idle, listeners: new Set() });
9
+ return found;
10
+ }
11
+ function update(id, next) {
12
+ const found = group(id);
13
+ const state = next(found.state);
14
+ if (state === found.state)
15
+ return;
16
+ found.state = state;
17
+ found.listeners.forEach(listener => listener());
18
+ }
19
+ export function setChartHover(id, source, timestamp) {
20
+ update(id, state => timestamp === null
21
+ ? state.source === source ? { ...state, hover: null, source: null } : state
22
+ : state.source === source && state.hover === timestamp ? state : { ...state, hover: timestamp, source });
23
+ }
24
+ /* A click while a timestamp is pinned clears it, so the same gesture undoes
25
+ itself without aiming at the same sample again. */
26
+ export function toggleChartPin(id, timestamp) {
27
+ update(id, state => ({ ...state, pinned: state.pinned === null ? timestamp : null }));
28
+ }
29
+ export function clearChartPin(id) {
30
+ update(id, state => state.pinned === null ? state : { ...state, pinned: null });
31
+ }
32
+ export function chartPinned(id) {
33
+ return groups.get(id)?.state.pinned ?? null;
34
+ }
35
+ export function useChartSync(id) {
36
+ const subscribe = React.useCallback((listener) => {
37
+ const found = group(id);
38
+ found.listeners.add(listener);
39
+ return () => {
40
+ found.listeners.delete(listener);
41
+ // A group that no Chart shows forgets its pin.
42
+ if (!found.listeners.size && groups.get(id) === found)
43
+ groups.delete(id);
44
+ };
45
+ }, [id]);
46
+ const snapshot = React.useCallback(() => groups.get(id)?.state ?? idle, [id]);
47
+ return React.useSyncExternalStore(subscribe, snapshot, () => idle);
48
+ }
package/dist/chart.d.ts CHANGED
@@ -28,4 +28,4 @@ export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
28
28
  timestamp to another. TimeRangeControl stays the keyboard and touch path. */
29
29
  onRangeSelect?: (range: TimeRange) => void;
30
30
  } & ChartTreatmentProps;
31
- export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime, formatValue, min, max, onRangeSelect, chartStyle, chartLine, chartFill, ref, className, ...props }: ChartProps): React.JSX.Element;
31
+ export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime, formatValue, min, max, onRangeSelect, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }: ChartProps): React.JSX.Element;
package/dist/chart.js CHANGED
@@ -2,12 +2,14 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { clsx as cn } from "clsx";
5
- import { Area, CartesianGrid, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
5
+ import { createPortal } from "react-dom";
6
+ import { Area, CartesianGrid, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis, usePlotArea, useXAxisInverseDataSnapScale, useXAxisScale, useYAxisScale } from "recharts";
6
7
  import { ChartLegend, ChartSeriesLabel } from "./chart-legend.js";
7
8
  import { ChartDot, ChartPattern, pixelCurve, useChartPresentation, useChartStyle } from "./chart-style.js";
8
9
  import { useChartFill } from "./chart-fill.js";
10
+ import { chartPinned, clearChartPin, setChartHover, toggleChartPin, useChartSync } from "./chart-sync.js";
9
11
  import { chartColor, chartSlot, formatChartTime, formatChartValue, measured, validateChart } from "./chart-data.js";
10
- export function Chart({ data, series, label, variant = "line", layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime = formatChartTime, formatValue = formatChartValue, min, max, onRangeSelect, chartStyle, chartLine, chartFill, ref, className, ...props }) {
12
+ export function Chart({ data, series, label, variant = "line", layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime = formatChartTime, formatValue = formatChartValue, min, max, onRangeSelect, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }) {
11
13
  const id = React.useId();
12
14
  const frame = React.useRef(null);
13
15
  const { line, fill } = useChartStyle(frame, { chartStyle, chartLine, chartFill });
@@ -21,7 +23,18 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
21
23
  const height = heightProp ?? expanded.height ?? defaultHeight;
22
24
  const bold = line === "stepped" || line === "curved";
23
25
  const [localHighlight, setLocalHighlight] = React.useState(null);
24
- const [activeTimestamp, setActiveTimestamp] = React.useState(null);
26
+ // Charts with the same syncId share the inspected and pinned timestamps
27
+ // through a Kiso store, not Recharts' syncId. An expanded Chart, or one
28
+ // without a syncId, keeps a group of its own.
29
+ const group = (expanded.fill ? undefined : syncId) ?? id;
30
+ const [source] = React.useState(() => ({}));
31
+ const inspected = React.useRef(null);
32
+ const pick = React.useRef(null);
33
+ const inspect = React.useCallback((timestamp) => {
34
+ inspected.current = timestamp;
35
+ setChartHover(group, source, timestamp);
36
+ }, [group, source]);
37
+ React.useEffect(() => () => setChartHover(group, source, null), [group, source]);
25
38
  // A drag moves the band in the DOM. Rendering the Chart on every pointer
26
39
  // move is far too slow for a stack of many series.
27
40
  const drag = React.useRef(null);
@@ -72,10 +85,19 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
72
85
  }
73
86
  const sampleAt = (index) => typeof index === "number" ? plot[index]?.timestamp
74
87
  : typeof index === "string" && index !== "" ? plot[Number(index)]?.timestamp : undefined;
75
- const rangeHandlers = onRangeSelect && plot.length > 1 ? {
88
+ const selectRange = onRangeSelect && plot.length > 1 ? onRangeSelect : undefined;
89
+ // A press that ends on the same sample is a click and pins that timestamp.
90
+ // A press that moves to another sample is a drag and selects a range.
91
+ const pointerHandlers = {
76
92
  onMouseDown: (state, event) => {
77
- const at = sampleAt(state.activeTooltipIndex), x = state.activeCoordinate?.x;
78
- if (at === undefined || x === undefined || event.button !== 0)
93
+ const mouse = event;
94
+ // A tap, or a click right after the pointer arrives, comes before
95
+ // Recharts reads the pointer, so find the sample under it here.
96
+ const active = sampleAt(state.activeTooltipIndex);
97
+ const picked = active === undefined && mouse.currentTarget instanceof Element
98
+ ? pick.current?.(mouse.clientX - mouse.currentTarget.getBoundingClientRect().left) : undefined;
99
+ const at = active ?? picked?.at, x = picked ? picked.x : state.activeCoordinate?.x;
100
+ if (at === undefined || x === undefined || mouse.button !== 0)
79
101
  return;
80
102
  stopDrag.current?.();
81
103
  drag.current = { from: at, to: at, x1: x, x2: x };
@@ -83,8 +105,12 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
83
105
  const end = () => {
84
106
  const range = drag.current;
85
107
  stop();
86
- if (range && range.from !== range.to)
87
- onRangeSelect({ from: Math.min(range.from, range.to), to: Math.max(range.from, range.to) });
108
+ if (!range)
109
+ return;
110
+ if (range.from === range.to)
111
+ toggleChartPin(group, range.from);
112
+ else
113
+ selectRange?.({ from: Math.min(range.from, range.to), to: Math.max(range.from, range.to) });
88
114
  };
89
115
  const cancel = (key) => { if (key.key === "Escape") {
90
116
  key.preventDefault();
@@ -106,11 +132,12 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
106
132
  if (!drag.current || at === undefined || x === undefined || at === drag.current.to)
107
133
  return;
108
134
  drag.current = { ...drag.current, to: at, x2: x };
109
- paintDrag();
135
+ if (selectRange)
136
+ paintDrag();
110
137
  },
111
- } : undefined;
112
- const renderPlot = (indices, lane) => _jsxs("div", { className: "chart-plot", style: { height }, "data-range-select": rangeHandlers ? "" : undefined, children: [_jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(ComposedChart, { data: plot, syncId: (expanded.fill ? undefined : syncId) ?? (layout === "split" ? id : undefined), syncMethod: "value", accessibilityLayer: true, "aria-label": lane ? `${label}: ${lane.label}` : label, "aria-describedby": `${id}-help`, margin: { top: 8, right: 20, bottom: 0, left: 0 }, ...rangeHandlers, children: [_jsx("defs", { children: indices.map(index => _jsx(ChartPattern, { id: `${id}-fill-${index}`, color: chartColor(chartSlot(series[index], index)), fill: fill }, series[index].key)) }), _jsx(CartesianGrid, { vertical: false, stroke: "var(--color-border)", strokeWidth: 0.5 }), _jsx(XAxis, { dataKey: "timestamp", type: "number", domain: ["dataMin", "dataMax"], scale: "time", axisLine: false, tickLine: false, tickFormatter: formatTime, minTickGap: 48, tick: { fill: "var(--color-muted-foreground)" } }), _jsx(YAxis, { domain: layout === "split" ? [splitMin, splitMax]
113
- : [min ?? (variant === "stacked-area" ? 0 : "auto"), max ?? "auto"], tickCount: 3, axisLine: false, tickLine: false, tickFormatter: formatValue, tick: { fill: "var(--color-muted-foreground)" }, width: 56 }), _jsx(Tooltip, { filterNull: false, isAnimationActive: false, cursor: { stroke: "var(--color-border-strong)", strokeDasharray: "3 3" }, content: ({ active, label: timestamp }) => _jsx(ChartReadout, { active: active, timestamp: Number(timestamp), data: data, series: series, formatTime: formatTime, displayValue: displayValue, sidebar: legend === "sidebar", onInspect: legend === "sidebar" && (!lane || indices[0] === 0) ? setActiveTimestamp : undefined }) }), indices.map(index => {
138
+ };
139
+ const renderPlot = (indices, lane) => _jsxs("div", { className: "chart-plot", style: { height }, "data-range-select": selectRange ? "" : undefined, children: [_jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(ComposedChart, { data: plot, syncId: layout === "split" ? id : undefined, syncMethod: "value", accessibilityLayer: true, "aria-label": lane ? `${label}: ${lane.label}` : label, "aria-describedby": `${id}-help`, margin: { top: 8, right: 20, bottom: 0, left: 0 }, ...pointerHandlers, children: [_jsx("defs", { children: indices.map(index => _jsx(ChartPattern, { id: `${id}-fill-${index}`, color: chartColor(chartSlot(series[index], index)), fill: fill }, series[index].key)) }), _jsx(CartesianGrid, { vertical: false, stroke: "var(--color-border)", strokeWidth: 0.5 }), _jsx(XAxis, { dataKey: "timestamp", type: "number", domain: ["dataMin", "dataMax"], scale: "time", axisLine: false, tickLine: false, tickFormatter: formatTime, minTickGap: 48, tick: { fill: "var(--color-muted-foreground)" } }), _jsx(YAxis, { domain: layout === "split" ? [splitMin, splitMax]
140
+ : [min ?? (variant === "stacked-area" ? 0 : "auto"), max ?? "auto"], tickCount: 3, axisLine: false, tickLine: false, tickFormatter: formatValue, tick: { fill: "var(--color-muted-foreground)" }, width: 56 }), _jsx(Tooltip, { filterNull: false, isAnimationActive: false, cursor: { stroke: "var(--color-border-strong)", strokeDasharray: "3 3" }, content: ({ active, label: timestamp }) => _jsx(ChartReadout, { active: active, timestamp: Number(timestamp), data: data, series: series, formatTime: formatTime, displayValue: displayValue, sidebar: legend === "sidebar", onInspect: !lane || indices[0] === 0 ? inspect : undefined }) }), indices.map(index => {
114
141
  const item = series[index];
115
142
  const slot = chartSlot(item, index);
116
143
  const dimmed = highlighted !== null && item.key !== highlighted;
@@ -131,15 +158,33 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
131
158
  return variant === "stacked-area" || fill !== "none"
132
159
  ? _jsx(Area, { ...common, type: curve, stackId: variant === "stacked-area" ? "total" : undefined, fill: textured ? `url(#${id}-fill-${index})` : chartColor(slot), fillOpacity: dimmed ? 0.06 : 0.2 }, item.key)
133
160
  : _jsx(Line, { ...common, type: curve }, item.key);
134
- })] }) }), rangeHandlers && _jsx("div", { className: "chart-range-band", hidden: true, "aria-hidden": "true" })] });
135
- const legendContent = _jsx(ChartLegend, { data: data, series: series, label: `${label}: summary`, variant: legend, summary: summary, formatValue: formatValue, formatTime: formatTime, activeTimestamp: legend === "sidebar" && hasData ? activeTimestamp : null, highlightSeries: highlighted, onHighlightSeriesChange: highlight });
161
+ }), _jsx(ChartSyncMarker, { group: group, source: source, plot: plot, data: data, series: series, indices: indices, stacked: variant === "stacked-area", line: line, highlighted: highlighted, pick: !lane || indices[0] === 0 ? pick : undefined, readout: legend !== "sidebar" && (!lane || indices[0] === 0), formatTime: formatTime, displayValue: displayValue })] }) }), selectRange && _jsx("div", { className: "chart-range-band", hidden: true, "aria-hidden": "true" })] });
162
+ const legendProps = { data, series, label: `${label}: summary`, variant: legend, summary, formatValue, formatTime,
163
+ highlightSeries: highlighted, onHighlightSeriesChange: highlight };
164
+ // Only a sidebar follows the inspected timestamp, so only it subscribes.
165
+ const legendContent = legend === "sidebar"
166
+ ? _jsx(ChartSidebarLegend, { group: group, ...legendProps })
167
+ : _jsx(ChartLegend, { ...legendProps });
136
168
  return _jsxs("figure", { ...props, ref: element => {
137
169
  frame.current = element;
138
170
  if (typeof ref === "function")
139
171
  return ref(element);
140
172
  if (ref)
141
173
  ref.current = element;
142
- }, "data-slot": "chart", "data-layout": layout, "data-legend": legend, "data-line": line, "data-fill": fill, className: cn("framed-chart", className), "aria-labelledby": `${id}-title`, children: [_jsx("figcaption", { id: `${id}-title`, className: "t-h3", children: label }), _jsx("p", { id: `${id}-help`, className: "chart-help", children: "Focus the chart and use Left and Right to inspect samples. Select a series in the legend to highlight it. Exact values are available below." }), _jsxs("div", { className: "chart-body", children: [_jsx("div", { className: "chart-plots", children: hasData ? layout === "split" ? series.map((item, index) => _jsxs("div", { className: "chart-lane", children: [_jsxs("div", { className: "chart-lane-heading", children: [_jsx(ChartSeriesLabel, { series: item, index: index }), _jsx("span", { children: displayValue(data.at(-1)?.values[item.key]) })] }), renderPlot([index], item)] }, item.key)) : renderPlot(series.map((_, index) => index))
174
+ }, "data-slot": "chart", "data-layout": layout, "data-legend": legend, "data-line": line, "data-fill": fill, className: cn("framed-chart", className), "aria-labelledby": `${id}-title`, onKeyDown: event => {
175
+ onKeyDown?.(event);
176
+ if (event.defaultPrevented || drag.current)
177
+ return;
178
+ if (event.key === "Escape" && chartPinned(group) !== null) {
179
+ event.preventDefault();
180
+ clearChartPin(group);
181
+ }
182
+ else if ((event.key === "Enter" || event.key === " ") && inspected.current !== null
183
+ && event.target instanceof Element && event.target.closest(".chart-plot")) {
184
+ event.preventDefault();
185
+ toggleChartPin(group, inspected.current);
186
+ }
187
+ }, children: [_jsx("figcaption", { id: `${id}-title`, className: "t-h3", children: label }), _jsx("p", { id: `${id}-help`, className: "chart-help", children: "Focus the chart and use Left and Right to inspect samples. Press Enter to mark the inspected sample in every synchronized chart, and Escape to clear it. Select a series in the legend to highlight it. Exact values are available below." }), _jsxs("div", { className: "chart-body", children: [_jsx("div", { className: "chart-plots", children: hasData ? layout === "split" ? series.map((item, index) => _jsxs("div", { className: "chart-lane", children: [_jsxs("div", { className: "chart-lane-heading", children: [_jsx(ChartSeriesLabel, { series: item, index: index }), _jsx("span", { children: displayValue(data.at(-1)?.values[item.key]) })] }), renderPlot([index], item)] }, item.key)) : renderPlot(series.map((_, index) => index))
143
188
  : _jsx("div", { className: "chart-empty hatch", style: { minHeight: height }, children: "No collected samples in this window." }) }), legend === "sidebar" && legendContent] }), legend !== "sidebar" && legendContent, _jsxs("details", { className: "disclosure chart-values", children: [_jsx("summary", { children: "View exact values" }), _jsx("div", { className: "chart-table-scroll", children: _jsxs("table", { className: "chart-table", children: [_jsxs("caption", { children: [label, ": collected samples, timestamps in UTC"] }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Timestamp" }), series.map(item => _jsx("th", { scope: "col", children: item.label }, item.key))] }) }), _jsx("tbody", { children: data.map(sample => _jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatChartTime(sample.timestamp) }), series.map(item => _jsx("td", { children: measured(sample.values[item.key]) ? String(sample.values[item.key]) : "Not collected" }, item.key))] }, sample.timestamp)) })] }) })] })] });
144
189
  }
145
190
  // Observe Recharts' synchronized tooltip state after render. This keeps the
@@ -150,5 +195,55 @@ function ChartReadout({ active, timestamp, data, series, formatTime, displayValu
150
195
  React.useEffect(() => { onInspect?.(inspectedTimestamp); }, [onInspect, inspectedTimestamp]);
151
196
  if (!sample || sidebar)
152
197
  return null;
153
- return _jsxs("div", { className: "chart-inspection", role: "status", children: [_jsx("strong", { children: formatTime(sample.timestamp) }), _jsx("dl", { children: series.map((item, index) => _jsxs(React.Fragment, { children: [_jsx("dt", { children: _jsx(ChartSeriesLabel, { series: item, index: index }) }), _jsx("dd", { children: displayValue(sample.values[item.key]) })] }, item.key)) })] });
198
+ return _jsx(ChartInspection, { role: "status", sample: sample, series: series, formatTime: formatTime, displayValue: displayValue });
199
+ }
200
+ function ChartInspection({ sample, series, formatTime, displayValue, className, ...props }) {
201
+ return _jsxs("div", { ...props, className: cn("chart-inspection", className), children: [_jsx("strong", { children: formatTime(sample.timestamp) }), _jsx("dl", { children: series.map((item, index) => _jsxs(React.Fragment, { children: [_jsx("dt", { children: _jsx(ChartSeriesLabel, { series: item, index: index }) }), _jsx("dd", { children: displayValue(sample.values[item.key]) })] }, item.key)) })] });
202
+ }
203
+ // The other Charts of a group mark the inspected timestamp with a line and
204
+ // dots, and a pinned timestamp with a solid line and its values. This
205
+ // subtree alone renders on hover; the plot, legend, and tables do not.
206
+ function ChartSyncMarker({ group, source, plot, data, series, indices, stacked, line, highlighted, pick, readout, formatTime, displayValue }) {
207
+ const { hover, source: hovering, pinned } = useChartSync(group);
208
+ const xScale = useXAxisScale(), yScale = useYAxisScale(), area = usePlotArea(), snap = useXAxisInverseDataSnapScale();
209
+ React.useLayoutEffect(() => {
210
+ if (!pick)
211
+ return;
212
+ pick.current = x => {
213
+ const at = area && x >= area.x && x <= area.x + area.width ? snap?.(x) : undefined;
214
+ const snapped = typeof at === "number" ? xScale?.(at) : undefined;
215
+ return typeof at === "number" && snapped !== undefined ? { at, x: snapped } : undefined;
216
+ };
217
+ }, [pick, area, snap, xScale]);
218
+ const mark = React.useRef(null);
219
+ const [layer, setLayer] = React.useState(null);
220
+ React.useLayoutEffect(() => setLayer(mark.current?.closest(".chart-plot") ?? null), []);
221
+ const place = (timestamp) => {
222
+ if (timestamp === null || !xScale || !area)
223
+ return undefined;
224
+ const sample = plot.find(item => item.timestamp === timestamp);
225
+ const x = sample && xScale(timestamp);
226
+ return sample && x !== undefined && Number.isFinite(x) ? { sample, x } : undefined;
227
+ };
228
+ const drawn = place(hovering === source ? null : hover), held = place(pinned);
229
+ const marker = (at, dash) => _jsxs("g", { children: [_jsx("line", { x1: at.x, x2: at.x, y1: area.y, y2: area.y + area.height, stroke: "var(--color-border-strong)", strokeWidth: dash ? 1 : 1.5, strokeDasharray: dash }), yScale && indices.map(index => {
230
+ const value = at.sample.values[index];
231
+ if (!measured(value))
232
+ return null;
233
+ const total = stacked ? at.sample.values.slice(0, index + 1).reduce((sum, item) => sum + (item ?? 0), 0) : value;
234
+ const y = yScale(total);
235
+ const item = series[index];
236
+ return y === undefined ? null : _jsx(ChartDot, { cx: at.x, cy: y, line: line, fill: chartColor(chartSlot(item, index)), opacity: highlighted !== null && item.key !== highlighted ? 0.3 : 1 }, item.key);
237
+ })] });
238
+ // The hovered Chart shows its own readout, so its pinned one steps aside.
239
+ const pinnedSample = readout && held && !(hovering === source && hover !== null)
240
+ ? data.find(item => item.timestamp === held.sample.timestamp) : undefined;
241
+ const flip = held && area ? held.x > area.x + area.width / 2 : false;
242
+ return _jsxs("g", { ref: mark, className: "chart-sync-marker", pointerEvents: "none", children: [held && marker(held), drawn && marker(drawn, "3 3"), layer && pinnedSample && held && area && createPortal(_jsx(ChartInspection, { className: "chart-pin-readout", sample: pinnedSample, series: series, formatTime: formatTime, displayValue: displayValue, style: { top: area.y, left: flip ? held.x - 12 : held.x + 12, translate: flip ? "-100%" : undefined } }), layer)] });
243
+ }
244
+ function ChartSidebarLegend({ group, data, ...props }) {
245
+ const { hover, pinned } = useChartSync(group);
246
+ const activeTimestamp = [hover, pinned].find(timestamp => timestamp !== null
247
+ && data.some(sample => sample.timestamp === timestamp)) ?? null;
248
+ return _jsx(ChartLegend, { ...props, data: data, activeTimestamp: activeTimestamp });
154
249
  }
@@ -15,8 +15,9 @@ export type PaneGridProps = Omit<React.ComponentProps<"section">, "title"> & {
15
15
  pack?: boolean;
16
16
  scrollPages?: number;
17
17
  debug?: boolean;
18
+ static?: boolean;
18
19
  };
19
- export declare function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow, flow, fill, pack, scrollPages, debug, className, children, ...props }: PaneGridProps): React.JSX.Element;
20
+ export declare function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow, flow, fill, pack, scrollPages, debug, static: isStatic, className, children, ...props }: PaneGridProps): React.JSX.Element;
20
21
  export type GridPaneProps = Omit<React.ComponentProps<"article">, "title" | "id"> & {
21
22
  id: string;
22
23
  title: string;
package/dist/pane-grid.js CHANGED
@@ -76,7 +76,7 @@ function layRow(ids, specs, sizes, columns, options) {
76
76
  }
77
77
  return lines;
78
78
  }
79
- export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow = "wrap", flow = "rows", fill = false, pack = false, scrollPages = 2, debug = false, className, children, ...props }) {
79
+ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow = "wrap", flow = "rows", fill = false, pack = false, scrollPages = 2, debug = false, static: isStatic = false, className, children, ...props }) {
80
80
  const elements = new Map();
81
81
  const specs = [];
82
82
  for (const child of React.Children.toArray(children)) {
@@ -108,11 +108,11 @@ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutCha
108
108
  observer.observe(body);
109
109
  return () => observer.disconnect();
110
110
  }, []);
111
- const columns = pickColumns(width);
111
+ const columns = isStatic ? 1 : pickColumns(width);
112
112
  const compact = columns !== COLUMNS;
113
113
  const stacked = columns === 1;
114
114
  const scrolling = overflow === "scroll" && !stacked;
115
- const masonry = flow === "masonry" && overflow === "wrap";
115
+ const masonry = flow === "masonry" && overflow === "wrap" && !isStatic;
116
116
  const scrollMax = columns * Math.max(1, scrollPages);
117
117
  let gridRow = 0;
118
118
  const rows = layout.rows.map((ids) => {
@@ -438,7 +438,7 @@ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutCha
438
438
  for (const line of row.lines) {
439
439
  for (const item of line.items) {
440
440
  const max = masonry ? columns : scrolling ? Math.min(columns, item.size + scrollMax - line.used) : item.size + line.free;
441
- placements.set(item.id, { id: item.id, row: line.scroll ? 1 : line.row, col: item.col, span: item.span, size: item.size, min: item.min, max, compact, stacked, debug });
441
+ placements.set(item.id, { id: item.id, row: line.scroll ? 1 : line.row, col: item.col, span: item.span, size: item.size, min: item.min, max, compact, stacked, static: isStatic, debug });
442
442
  }
443
443
  }
444
444
  }
@@ -449,8 +449,8 @@ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutCha
449
449
  return null;
450
450
  return (_jsx(PaneContext.Provider, { value: { placement, api }, children: element }, id));
451
451
  };
452
- return (_jsxs("section", { "data-slot": "pane-grid", className: cn("pane-grid", className), ...props, children: [title != null && _jsx("h2", { "data-slot": "pane-grid-title", className: "pane-grid-title t-h2", children: title }), _jsxs("div", { ref: bodyRef, "data-slot": "pane-grid-body", className: "pane-grid-body", "data-columns": columns, "data-compact": compact ? "true" : undefined, "data-overflow": overflow, "data-flow": masonry ? "masonry" : "rows", "data-debug": debug ? "true" : undefined, style: { "--pane-cols": columns, "--pane-grid-width": `${width}px` }, children: [rows.flatMap((row, index) => [
453
- (index > 0 || debug) && (_jsx("div", { className: "pane-grid-rule", "data-pane-row": index, "aria-hidden": "true", style: { "--r": row.lines[0].row }, children: debug && `row ${index + 1} · ${row.lines.map((line) => `${line.used}/${columns}${line.scroll ? " ⇆ scroll" : ""}`).join(" + ")}` }, `rule-${index}`)),
452
+ return (_jsxs("section", { "data-slot": "pane-grid", className: cn("pane-grid", className), ...props, children: [title != null && _jsx("h2", { "data-slot": "pane-grid-title", className: "pane-grid-title t-h2", children: title }), _jsxs("div", { ref: bodyRef, "data-slot": "pane-grid-body", className: "pane-grid-body", "data-columns": columns, "data-compact": compact ? "true" : undefined, "data-overflow": overflow, "data-flow": masonry ? "masonry" : "rows", "data-debug": debug ? "true" : undefined, "data-static": isStatic ? "true" : undefined, style: { "--pane-cols": columns, "--pane-grid-width": `${width}px` }, children: [rows.flatMap((row, index) => [
453
+ (index > 0 || debug) && !isStatic && (_jsx("div", { className: "pane-grid-rule", "data-pane-row": index, "aria-hidden": "true", style: { "--r": row.lines[0].row }, children: debug && `row ${index + 1} · ${row.lines.map((line) => `${line.used}/${columns}${line.scroll ? " ⇆ scroll" : ""}`).join(" + ")}` }, `rule-${index}`)),
454
454
  ...(masonry ? row.ids.map(renderPane) : row.lines.flatMap((line) => line.scroll
455
455
  ? [
456
456
  _jsx("div", { className: "pane-grid-scroll", style: { "--r": line.row, "--n": line.used }, children: line.items.map((item) => renderPane(item.id)) }, `scroll-${line.items[0].id}`),
@@ -466,19 +466,25 @@ export function GridPane({ id, title, min: _min, size: _size, newRow: _newRow, a
466
466
  if (!context)
467
467
  throw new Error("GridPane must be a child of PaneGrid.");
468
468
  const { placement, api } = context;
469
- return (_jsxs("article", { "data-slot": "grid-pane", "data-pane-id": id, className: cn("grid-pane card", className), style: { "--r": placement.row, "--c": placement.col, "--s": placement.span, ...style }, ...props, children: [_jsxs("div", { "data-slot": "grid-pane-head", className: "grid-pane-head", role: "button", tabIndex: 0, "aria-label": `Move ${title}`, onPointerDown: (event) => api.startMove(id, event), onKeyDown: (event) => {
470
- if (event.target !== event.currentTarget)
471
- return;
472
- if (event.key === "ArrowLeft" || (placement.stacked && event.key === "ArrowUp"))
473
- api.moveBy(id, -1);
474
- else if (event.key === "ArrowRight" || (placement.stacked && event.key === "ArrowDown"))
475
- api.moveBy(id, 1);
476
- else if (event.key === "Enter" || event.key === " ")
477
- api.toggleRow(id);
478
- else
479
- return;
480
- event.preventDefault();
481
- }, children: [_jsx(GripVertical, { className: "icon grid-pane-grip", "aria-hidden": "true" }), _jsx("h3", { "data-slot": "grid-pane-title", className: "grid-pane-title t-h3", children: title }), placement.debug && _jsxs("span", { className: "grid-pane-meta", children: ["size=", placement.size, " \u00B7 min=", placement.min, " \u00B7 max=", placement.max] }), actions != null && _jsx("div", { "data-slot": "grid-pane-actions", className: "grid-pane-actions", children: actions })] }), _jsx("div", { "data-slot": "grid-pane-body", className: "grid-pane-body", children: children }), !placement.compact && (_jsx("div", { "data-slot": "grid-pane-resizer", className: "grid-pane-resizer", role: "separator", tabIndex: 0, "aria-orientation": "vertical", "aria-label": `Resize ${title}`, "aria-valuenow": placement.size, "aria-valuemin": placement.min, "aria-valuemax": placement.max, "aria-disabled": placement.min === placement.max || undefined, onPointerDown: (event) => api.startResize(id, event), onKeyDown: (event) => {
469
+ return (_jsxs("article", { "data-slot": "grid-pane", "data-pane-id": id, className: cn("grid-pane card", className), style: { "--r": placement.row, "--c": placement.col, "--s": placement.span, ...style }, ...props, children: [_jsxs("div", { "data-slot": "grid-pane-head", className: "grid-pane-head", ...(!placement.static && {
470
+ role: "button",
471
+ tabIndex: 0,
472
+ "aria-label": `Move ${title}`,
473
+ onPointerDown: (event) => api.startMove(id, event),
474
+ onKeyDown: (event) => {
475
+ if (event.target !== event.currentTarget)
476
+ return;
477
+ if (event.key === "ArrowLeft" || (placement.stacked && event.key === "ArrowUp"))
478
+ api.moveBy(id, -1);
479
+ else if (event.key === "ArrowRight" || (placement.stacked && event.key === "ArrowDown"))
480
+ api.moveBy(id, 1);
481
+ else if (event.key === "Enter" || event.key === " ")
482
+ api.toggleRow(id);
483
+ else
484
+ return;
485
+ event.preventDefault();
486
+ },
487
+ }), children: [!placement.static && _jsx(GripVertical, { className: "icon grid-pane-grip", "aria-hidden": "true" }), _jsx("h3", { "data-slot": "grid-pane-title", className: "grid-pane-title t-h3", children: title }), placement.debug && _jsxs("span", { className: "grid-pane-meta", children: ["size=", placement.size, " \u00B7 min=", placement.min, " \u00B7 max=", placement.max] }), actions != null && _jsx("div", { "data-slot": "grid-pane-actions", className: "grid-pane-actions", children: actions })] }), _jsx("div", { "data-slot": "grid-pane-body", className: "grid-pane-body", children: children }), !placement.compact && (_jsx("div", { "data-slot": "grid-pane-resizer", className: "grid-pane-resizer", role: "separator", tabIndex: 0, "aria-orientation": "vertical", "aria-label": `Resize ${title}`, "aria-valuenow": placement.size, "aria-valuemin": placement.min, "aria-valuemax": placement.max, "aria-disabled": placement.min === placement.max || undefined, onPointerDown: (event) => api.startResize(id, event), onKeyDown: (event) => {
482
488
  if (event.key === "ArrowRight")
483
489
  api.resize(id, placement.size + 1);
484
490
  else if (event.key === "ArrowLeft")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momoi-labs/kiso-react",
3
- "version": "0.19.1",
3
+ "version": "0.21.0",
4
4
  "description": "Kiso React components built with shadcn/ui and Radix",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "prepack": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@momoi-labs/kiso": "^0.24.0",
35
+ "@momoi-labs/kiso": "^0.26.0",
36
36
  "class-variance-authority": "0.7.1",
37
37
  "clsx": "2.1.1",
38
38
  "radix-ui": "1.6.7",