@microsoft/fabric-slicers 0.0.0-stage → 3.0.1

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.js ADDED
@@ -0,0 +1,1296 @@
1
+ // src/components/list-slicer/list-slicer.tsx
2
+ import { useVirtualizer } from "@tanstack/react-virtual";
3
+ import { useCallback as useCallback2, useEffect, useId, useMemo as useMemo2, useRef, useState as useState2 } from "react";
4
+ import { getString as getString3 } from "@microsoft/fabric-visuals-core";
5
+
6
+ // src/hooks/use-list-slicer.ts
7
+ import { useCallback, useMemo, useState } from "react";
8
+ import { formatString, formatValue, getString, isDataTable } from "@microsoft/fabric-visuals-core";
9
+ function isSlicerValue(value) {
10
+ return value == null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || value instanceof Date && Number.isFinite(value.getTime());
11
+ }
12
+ function valueKey(value) {
13
+ if (value instanceof Date) return `date:${value.getTime()}`;
14
+ return `${typeof value}:${String(value)}`;
15
+ }
16
+ function prepareListSlicerData({ data, column, title }) {
17
+ let resolvedTitle = title ?? column;
18
+ let format;
19
+ let valueCount;
20
+ let valueAt;
21
+ if (isDataTable(data)) {
22
+ const columnIndex = data.columns.findIndex((candidate) => candidate.name === column);
23
+ if (columnIndex < 0) {
24
+ return { title: resolvedTitle, items: [], error: formatString("Slicer_MissingColumn", column) };
25
+ }
26
+ resolvedTitle = title ?? data.columns[columnIndex].displayName ?? column;
27
+ format = data.columns[columnIndex].format;
28
+ valueCount = data.rows.length;
29
+ valueAt = (index) => data.rows[index][columnIndex];
30
+ } else if (Array.isArray(data)) {
31
+ valueCount = data.length;
32
+ valueAt = (index) => data[index];
33
+ } else {
34
+ return { title: resolvedTitle, items: [], error: getString("Slicer_InvalidData") };
35
+ }
36
+ const items = [];
37
+ const seenKeys = /* @__PURE__ */ new Set();
38
+ for (let index = 0; index < valueCount; index++) {
39
+ const value = valueAt(index);
40
+ if (!isSlicerValue(value)) {
41
+ return { title: resolvedTitle, items: [], error: getString("Slicer_InvalidData") };
42
+ }
43
+ const key = valueKey(value);
44
+ if (seenKeys.has(key)) continue;
45
+ seenKeys.add(key);
46
+ const label = value == null || value === "" ? getString("Slicer_Blank") : String(formatValue(value, format));
47
+ items.push({ key, value, label });
48
+ }
49
+ return { title: resolvedTitle, items };
50
+ }
51
+ function useListSlicer({ data, column, title }) {
52
+ const prepared = useMemo(
53
+ () => prepareListSlicerData({ data, column, title }),
54
+ [data, column, title]
55
+ );
56
+ const [selection, setSelection] = useState("all");
57
+ const isSelected = useCallback(
58
+ (key) => selection === "all" || selection.has(key),
59
+ [selection]
60
+ );
61
+ const selectedItems = useMemo(
62
+ () => prepared.items.filter((item) => isSelected(item.key)),
63
+ [prepared.items, isSelected]
64
+ );
65
+ const toggle = useCallback((keys) => {
66
+ if (keys.length === 0) return;
67
+ setSelection((previous) => {
68
+ const next = previous === "all" ? new Set(prepared.items.map((item) => item.key)) : new Set(previous);
69
+ const remove = keys.every((key) => next.has(key));
70
+ for (const key of keys) {
71
+ if (remove) next.delete(key);
72
+ else next.add(key);
73
+ }
74
+ return prepared.items.length > 0 && prepared.items.every((item) => next.has(item.key)) ? "all" : next;
75
+ });
76
+ }, [prepared.items]);
77
+ const clear = useCallback(() => setSelection("all"), []);
78
+ return {
79
+ ...prepared,
80
+ selectedItems,
81
+ isSelected,
82
+ toggle,
83
+ clear,
84
+ allSelected: selection === "all"
85
+ };
86
+ }
87
+
88
+ // src/components/shared/slicer-header.tsx
89
+ import { formatString as formatString2, getString as getString2 } from "@microsoft/fabric-visuals-core";
90
+
91
+ // src/components/shared/slicer-styles.ts
92
+ import { makeStyles } from "@griffel/react";
93
+ import { fontFamily, injectDesignTokens, inVisualsLayer, normalizeCssLength, tokens } from "@microsoft/fabric-visuals-core";
94
+ import { mergeClasses } from "@griffel/react";
95
+ injectDesignTokens();
96
+ function slicerThemeStyle(theme) {
97
+ if (!theme) return {};
98
+ return {
99
+ "--slicer-foreground": theme.foreground,
100
+ "--slicer-secondary": theme.foregroundSecondary,
101
+ "--slicer-brand": theme.brandBackground,
102
+ "--slicer-link": theme.brandForeground,
103
+ "--slicer-background": theme.background,
104
+ "--slicer-muted": theme.backgroundSecondary,
105
+ "--slicer-hover": theme.backgroundHover,
106
+ "--slicer-stroke": theme.border?.color ?? theme.stroke,
107
+ "--slicer-radius": normalizeCssLength(theme.border?.radius) ?? "8px",
108
+ "--slicer-font": theme.typography?.label?.family ?? fontFamily.base,
109
+ "--slicer-size": `${theme.typography?.label?.size ?? 14}px`,
110
+ "--slicer-weight": theme.typography?.label?.weight ?? 400,
111
+ "--slicer-heading-font": theme.typography?.heading?.family ?? fontFamily.heading,
112
+ "--slicer-heading-size": `${theme.typography?.heading?.size ?? 14}px`,
113
+ "--slicer-heading-weight": theme.typography?.heading?.weight ?? 600
114
+ };
115
+ }
116
+ var useSlicerStyles = makeStyles(inVisualsLayer({
117
+ typography: {
118
+ fontFamily: `var(--slicer-font, ${tokens.fontBase})`,
119
+ fontSize: `var(--slicer-size, ${tokens.text300})`,
120
+ fontWeight: `var(--slicer-weight, ${tokens.fontWeightRegular})`,
121
+ color: `var(--slicer-foreground, ${tokens.colorForeground})`,
122
+ lineHeight: "20px",
123
+ "& button, & input": { fontFamily: "inherit", fontSize: "inherit" },
124
+ "& button:focus-visible, & input:focus-visible": {
125
+ outline: `2px solid var(--slicer-link, ${tokens.colorBrandForeground})`,
126
+ outlineOffset: "2px"
127
+ }
128
+ },
129
+ root: { display: "flex", flexDirection: "column", gap: "8px", minWidth: 0, minHeight: 0, width: "100%" },
130
+ fillHeight: { height: "100%", maxHeight: "100%" },
131
+ header: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", flexShrink: 0 },
132
+ title: {
133
+ margin: 0,
134
+ overflow: "hidden",
135
+ textOverflow: "ellipsis",
136
+ whiteSpace: "nowrap",
137
+ fontFamily: `var(--slicer-heading-font, ${tokens.fontHeading})`,
138
+ fontSize: `var(--slicer-heading-size, ${tokens.text300})`,
139
+ fontWeight: `var(--slicer-heading-weight, ${tokens.fontWeightSemibold})`
140
+ },
141
+ clear: {
142
+ border: 0,
143
+ backgroundColor: "transparent",
144
+ color: `var(--slicer-link, ${tokens.colorBrandForeground})`,
145
+ cursor: "pointer",
146
+ padding: "2px",
147
+ fontFamily: "inherit",
148
+ fontSize: "12px",
149
+ flexShrink: 0,
150
+ ":focus-visible": {
151
+ outline: `2px solid var(--slicer-link, ${tokens.colorBrandForeground})`,
152
+ outlineOffset: "2px"
153
+ },
154
+ ":disabled": { opacity: 0.5, cursor: "default" }
155
+ },
156
+ clearHidden: { visibility: "hidden" },
157
+ panel: {
158
+ display: "flex",
159
+ flexDirection: "column",
160
+ minHeight: 0,
161
+ minWidth: 0,
162
+ backgroundColor: `var(--slicer-background, ${tokens.colorBackground})`,
163
+ border: `1px solid var(--slicer-stroke, ${tokens.colorBorder})`,
164
+ borderRadius: `var(--slicer-radius, ${tokens.radiusXl})`,
165
+ padding: "8px",
166
+ boxSizing: "border-box",
167
+ overflow: "hidden",
168
+ flexGrow: 1
169
+ },
170
+ text: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flexGrow: 1 },
171
+ message: { padding: "16px 8px", color: `var(--slicer-secondary, ${tokens.colorMutedForeground})`, overflowWrap: "anywhere" },
172
+ icon: { flexShrink: 0, display: "block" }
173
+ }));
174
+
175
+ // src/components/shared/slicer-header.tsx
176
+ import { jsx, jsxs } from "react/jsx-runtime";
177
+ function SlicerHeader({ title, titleId, onClear, clearDisabled }) {
178
+ const styles = useSlicerStyles();
179
+ return /* @__PURE__ */ jsxs("div", { className: styles.header, children: [
180
+ /* @__PURE__ */ jsx("h3", { id: titleId, className: styles.title, title, children: title }),
181
+ /* @__PURE__ */ jsx(
182
+ "button",
183
+ {
184
+ type: "button",
185
+ className: mergeClasses(styles.clear, !onClear && styles.clearHidden),
186
+ "aria-hidden": !onClear,
187
+ "aria-label": formatString2("Slicer_ClearLabel", title),
188
+ disabled: !onClear || clearDisabled,
189
+ onClick: onClear,
190
+ title: getString2("Slicer_ClearDescription"),
191
+ children: getString2("Slicer_Clear")
192
+ }
193
+ )
194
+ ] });
195
+ }
196
+
197
+ // src/components/ui/checkbox.tsx
198
+ import { Checkbox as CheckBox } from "radix-ui";
199
+ import { mergeClasses as mergeClasses2 } from "@griffel/react";
200
+
201
+ // src/components/ui/ui-slicer-styles.ts
202
+ import { makeStyles as makeStyles2, shorthands } from "@griffel/react";
203
+ import { inVisualsLayer as inVisualsLayer2, tokens as tokens2 } from "@microsoft/fabric-visuals-core";
204
+ var useCheckboxStyles = makeStyles2(inVisualsLayer2({
205
+ checkbox: {
206
+ width: "16px",
207
+ height: "16px",
208
+ borderRadius: "4px",
209
+ border: `1px solid var(--slicer-stroke, ${tokens2.colorBorder})`,
210
+ padding: 0,
211
+ display: "inline-flex",
212
+ alignItems: "center",
213
+ justifyContent: "center",
214
+ flexShrink: 0,
215
+ cursor: "pointer",
216
+ backgroundColor: `var(--slicer-background, ${tokens2.colorBackground})`,
217
+ color: "#ffffff",
218
+ '&[data-state="checked"], &[data-state="indeterminate"]': {
219
+ backgroundColor: `var(--slicer-brand, ${tokens2.colorBrand})`,
220
+ ...shorthands.borderColor(`var(--slicer-brand, ${tokens2.colorBrand})`)
221
+ },
222
+ ":disabled": { opacity: 0.5, cursor: "default" },
223
+ "@media (forced-colors: active)": {
224
+ ...shorthands.borderColor("ButtonText"),
225
+ '&[data-state="checked"], &[data-state="indeterminate"]': {
226
+ backgroundColor: "Highlight",
227
+ color: "HighlightText",
228
+ ...shorthands.borderColor("Highlight"),
229
+ forcedColorAdjust: "none"
230
+ }
231
+ }
232
+ },
233
+ indicator: { display: "flex" }
234
+ }));
235
+
236
+ // src/components/ui/checkbox.tsx
237
+ import { jsx as jsx2 } from "react/jsx-runtime";
238
+ function Checkbox({ className, checked, ...props }) {
239
+ const styles = useCheckboxStyles();
240
+ return /* @__PURE__ */ jsx2(CheckBox.Root, { ...props, checked, className: mergeClasses2(styles.checkbox, className), children: /* @__PURE__ */ jsx2(CheckBox.Indicator, { className: styles.indicator, children: /* @__PURE__ */ jsx2("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx2(
241
+ "path",
242
+ {
243
+ d: checked === "indeterminate" ? "M2 6h8" : "m2 6 2.5 2.5L10 3",
244
+ stroke: "currentColor",
245
+ strokeWidth: "1.5",
246
+ strokeLinecap: "round",
247
+ strokeLinejoin: "round"
248
+ }
249
+ ) }) }) });
250
+ }
251
+
252
+ // src/components/ui/icons.tsx
253
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
254
+ function ChevronDownIcon({ className }) {
255
+ return /* @__PURE__ */ jsx3("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("path", { d: "m4 6 4 4 4-4", stroke: "currentColor", strokeWidth: "1.5" }) });
256
+ }
257
+ function SearchIcon({ className }) {
258
+ return /* @__PURE__ */ jsxs2("svg", { className, width: "16", height: "16", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
259
+ /* @__PURE__ */ jsx3("circle", { cx: "6.5", cy: "6.5", r: "4.5", fill: "none", stroke: "currentColor" }),
260
+ /* @__PURE__ */ jsx3("path", { d: "m10 10 4 4", stroke: "currentColor" })
261
+ ] });
262
+ }
263
+
264
+ // src/components/list-slicer/list-slicer-styles.ts
265
+ import { makeStyles as makeStyles3 } from "@griffel/react";
266
+ import { inVisualsLayer as inVisualsLayer3, tokens as tokens3 } from "@microsoft/fabric-visuals-core";
267
+ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
268
+ search: {
269
+ display: "flex",
270
+ alignItems: "center",
271
+ gap: "6px",
272
+ flexShrink: 0,
273
+ backgroundColor: `var(--slicer-muted, ${tokens3.colorMuted})`,
274
+ border: `1px solid var(--slicer-stroke, ${tokens3.colorBorder})`,
275
+ borderRadius: `var(--slicer-radius, ${tokens3.radiusXl})`,
276
+ padding: "4px 8px",
277
+ marginBottom: "4px",
278
+ color: `var(--slicer-secondary, ${tokens3.colorMutedForeground})`,
279
+ ":focus-within": {
280
+ outline: `2px solid var(--slicer-link, ${tokens3.colorBrandForeground})`,
281
+ outlineOffset: "1px",
282
+ "& > input:focus-visible": { outline: "none" }
283
+ }
284
+ },
285
+ input: {
286
+ width: "100%",
287
+ minWidth: 0,
288
+ height: "22px",
289
+ padding: 0,
290
+ border: 0,
291
+ color: `var(--slicer-foreground, ${tokens3.colorForeground})`,
292
+ backgroundColor: "transparent",
293
+ "::placeholder": { color: `var(--slicer-secondary, ${tokens3.colorMutedForeground})` }
294
+ },
295
+ scroll: {
296
+ overflowY: "auto",
297
+ minHeight: 0,
298
+ scrollbarWidth: "thin",
299
+ "@supports selector(::-webkit-scrollbar)": {
300
+ // A non-auto scrollbar-width overrides the thumb's minimum height in Chromium.
301
+ scrollbarWidth: "auto",
302
+ "::-webkit-scrollbar": { width: "6px" },
303
+ "::-webkit-scrollbar-thumb": {
304
+ minHeight: "32px",
305
+ borderRadius: "3px",
306
+ backgroundColor: `var(--slicer-secondary, ${tokens3.colorMutedForeground})`
307
+ },
308
+ "::-webkit-scrollbar-track": { backgroundColor: "transparent" },
309
+ "@media (forced-colors: active)": {
310
+ "::-webkit-scrollbar-thumb": {
311
+ backgroundColor: "CanvasText",
312
+ forcedColorAdjust: "none"
313
+ },
314
+ "::-webkit-scrollbar-track": {
315
+ backgroundColor: "Canvas",
316
+ forcedColorAdjust: "none"
317
+ }
318
+ }
319
+ }
320
+ },
321
+ scrollFade: {
322
+ maskImage: "linear-gradient(to bottom, #000 calc(100% - 32px), transparent)",
323
+ ":has(:focus-visible)": { maskImage: "none" },
324
+ "@media (forced-colors: active)": { maskImage: "none" }
325
+ },
326
+ list: { listStyleType: "none", padding: 0, margin: 0, position: "relative" },
327
+ row: {
328
+ display: "flex",
329
+ alignItems: "center",
330
+ gap: "8px",
331
+ padding: "0 8px",
332
+ height: "32px",
333
+ boxSizing: "border-box",
334
+ borderRadius: "4px",
335
+ minWidth: 0,
336
+ ":hover": { backgroundColor: `var(--slicer-hover, ${tokens3.colorHover})` }
337
+ },
338
+ selectAll: { flexShrink: 0, fontWeight: 600 },
339
+ label: {
340
+ display: "flex",
341
+ alignItems: "center",
342
+ gap: "8px",
343
+ height: "100%",
344
+ cursor: "pointer",
345
+ minWidth: 0,
346
+ flexGrow: 1
347
+ }
348
+ }));
349
+
350
+ // src/components/list-slicer/list-slicer.tsx
351
+ import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
352
+ var ROW_HEIGHT = 32;
353
+ function ListSlicerRow({ label, checked, onToggle, disabled, className }) {
354
+ const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
355
+ const id = useId();
356
+ return /* @__PURE__ */ jsxs3("div", { className: mergeClasses(styles.row, className), children: [
357
+ /* @__PURE__ */ jsx4(
358
+ Checkbox,
359
+ {
360
+ id,
361
+ checked,
362
+ onCheckedChange: onToggle,
363
+ disabled,
364
+ "aria-label": label
365
+ }
366
+ ),
367
+ /* @__PURE__ */ jsx4("label", { className: styles.label, htmlFor: id, children: /* @__PURE__ */ jsx4("span", { className: styles.text, title: label, children: label }) })
368
+ ] });
369
+ }
370
+ function ItemRow({ item, state }) {
371
+ const toggle = useCallback2(() => state.toggle([item.key]), [state, item.key]);
372
+ return /* @__PURE__ */ jsx4(
373
+ ListSlicerRow,
374
+ {
375
+ label: item.label,
376
+ checked: state.isSelected(item.key),
377
+ onToggle: toggle
378
+ }
379
+ );
380
+ }
381
+ function virtualRowStyle(start) {
382
+ return { position: "absolute", top: 0, left: 0, width: "100%", height: ROW_HEIGHT, transform: `translateY(${start}px)` };
383
+ }
384
+ function ListSlicer(props) {
385
+ return /* @__PURE__ */ jsx4(StatefulListSlicer, { ...props }, props.column);
386
+ }
387
+ function StatefulListSlicer(props) {
388
+ const state = useListSlicer(props);
389
+ return /* @__PURE__ */ jsx4(ListSlicerContent, { state, theme: props.theme, displayOptions: props.displayOptions });
390
+ }
391
+ function ListSlicerContent({
392
+ state,
393
+ theme,
394
+ displayOptions,
395
+ maxVisibleItems = 8
396
+ }) {
397
+ const styles = { ...useSlicerStyles(), ...useListSlicerStyles() };
398
+ const titleId = useId();
399
+ const themeStyle = useMemo2(() => slicerThemeStyle(theme), [theme]);
400
+ const showSearch = displayOptions?.showSearch ?? true;
401
+ const hideHeader = displayOptions?.hideHeader ?? false;
402
+ const scrollRef = useRef(null);
403
+ const scrollStyle = useMemo2(
404
+ () => ({ maxHeight: maxVisibleItems * ROW_HEIGHT }),
405
+ [maxVisibleItems]
406
+ );
407
+ const [search, setSearch] = useState2("");
408
+ const items = useMemo2(() => {
409
+ const query = showSearch ? search.toLocaleLowerCase() : "";
410
+ return state.items.filter((item) => item.label.toLocaleLowerCase().includes(query));
411
+ }, [state.items, search, showSearch]);
412
+ const handleSearch = useCallback2((event) => {
413
+ setSearch(event.target.value);
414
+ if (scrollRef.current) scrollRef.current.scrollTop = 0;
415
+ }, []);
416
+ const selectedCount = items.filter((item) => state.isSelected(item.key)).length;
417
+ const checked = selectedCount === 0 ? false : selectedCount === items.length ? true : "indeterminate";
418
+ const toggleAll = useCallback2(() => state.toggle(items.map((item) => item.key)), [state, items]);
419
+ const virtual = items.length > 50;
420
+ const virtualizer = useVirtualizer({
421
+ count: items.length,
422
+ getScrollElement: () => scrollRef.current,
423
+ estimateSize: () => ROW_HEIGHT,
424
+ getItemKey: (index) => items[index].key,
425
+ overscan: 5,
426
+ enabled: virtual
427
+ });
428
+ const totalHeight = virtualizer.getTotalSize();
429
+ const listStyle = useMemo2(
430
+ () => virtual ? { height: totalHeight } : void 0,
431
+ [virtual, totalHeight]
432
+ );
433
+ const [hasMoreBelow, setHasMoreBelow] = useState2(false);
434
+ useEffect(() => {
435
+ const scroll = scrollRef.current;
436
+ if (!scroll) return;
437
+ const updateFade = () => {
438
+ setHasMoreBelow(items.length > 0 && scroll.scrollHeight - scroll.clientHeight - scroll.scrollTop > 1);
439
+ };
440
+ const observer = new ResizeObserver(updateFade);
441
+ observer.observe(scroll);
442
+ if (scroll.firstElementChild) observer.observe(scroll.firstElementChild);
443
+ scroll.addEventListener("scroll", updateFade, { passive: true });
444
+ updateFade();
445
+ return () => {
446
+ observer.disconnect();
447
+ scroll.removeEventListener("scroll", updateFade);
448
+ };
449
+ }, [items.length, state.error]);
450
+ return /* @__PURE__ */ jsxs3(
451
+ "section",
452
+ {
453
+ className: mergeClasses(styles.typography, styles.root, !hideHeader && styles.fillHeight),
454
+ style: themeStyle,
455
+ "aria-labelledby": hideHeader ? void 0 : titleId,
456
+ "aria-label": hideHeader ? state.title : void 0,
457
+ children: [
458
+ !hideHeader && /* @__PURE__ */ jsx4(
459
+ SlicerHeader,
460
+ {
461
+ title: state.title,
462
+ titleId,
463
+ onClear: state.allSelected ? void 0 : state.clear,
464
+ clearDisabled: !!state.error || state.items.length === 0
465
+ }
466
+ ),
467
+ /* @__PURE__ */ jsx4("div", { className: styles.panel, children: state.error ? /* @__PURE__ */ jsx4("div", { role: "alert", className: styles.message, children: state.error }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
468
+ showSearch && /* @__PURE__ */ jsxs3("div", { className: styles.search, children: [
469
+ /* @__PURE__ */ jsx4(SearchIcon, { className: styles.icon }),
470
+ /* @__PURE__ */ jsx4(
471
+ "input",
472
+ {
473
+ type: "search",
474
+ className: styles.input,
475
+ placeholder: getString3("Slicer_Search"),
476
+ "aria-label": getString3("Slicer_Search"),
477
+ value: search,
478
+ onChange: handleSearch
479
+ }
480
+ )
481
+ ] }),
482
+ /* @__PURE__ */ jsx4(
483
+ ListSlicerRow,
484
+ {
485
+ className: styles.selectAll,
486
+ label: getString3("Slicer_SelectAll"),
487
+ checked,
488
+ onToggle: toggleAll,
489
+ disabled: items.length === 0
490
+ }
491
+ ),
492
+ /* @__PURE__ */ jsx4("div", { ref: scrollRef, className: mergeClasses(styles.scroll, hasMoreBelow && styles.scrollFade), style: scrollStyle, children: items.length === 0 ? /* @__PURE__ */ jsx4("div", { role: "status", className: styles.message, children: getString3(state.items.length === 0 ? "Slicer_NoData" : "Slicer_NoResults") }) : /* @__PURE__ */ jsx4("ul", { className: styles.list, style: listStyle, "aria-label": state.title, children: virtual ? virtualizer.getVirtualItems().map((row) => /* @__PURE__ */ jsx4("li", { style: virtualRowStyle(row.start), "aria-posinset": row.index + 1, "aria-setsize": items.length, children: /* @__PURE__ */ jsx4(ItemRow, { item: items[row.index], state }) }, row.key)) : items.map((item) => /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsx4(ItemRow, { item, state }) }, item.key)) }) })
493
+ ] }) })
494
+ ]
495
+ }
496
+ );
497
+ }
498
+
499
+ // src/components/dropdown-slicer/dropdown-slicer.tsx
500
+ import { useId as useId2, useMemo as useMemo3 } from "react";
501
+ import { formatString as formatString3, getString as getString4 } from "@microsoft/fabric-visuals-core";
502
+
503
+ // src/components/ui/popover.tsx
504
+ import { Popover as PopoverPrimitive } from "radix-ui";
505
+ import { makeStyles as makeStyles4 } from "@griffel/react";
506
+ import { inVisualsLayer as inVisualsLayer4, tokens as tokens4 } from "@microsoft/fabric-visuals-core";
507
+ import { jsx as jsx5 } from "react/jsx-runtime";
508
+ var usePopoverStyles = makeStyles4(inVisualsLayer4({
509
+ popover: {
510
+ width: "var(--radix-popover-trigger-width)",
511
+ maxWidth: "min(calc(100vw - 16px), var(--radix-popover-content-available-width))",
512
+ maxHeight: "var(--radix-popover-content-available-height)",
513
+ display: "flex",
514
+ outline: "none",
515
+ zIndex: 1e3,
516
+ borderRadius: `var(--slicer-radius, ${tokens4.radiusXl})`,
517
+ boxShadow: "0 2px 6px rgba(0, 0, 0, 0.16)"
518
+ }
519
+ }));
520
+ var Popover = PopoverPrimitive.Root;
521
+ var PopoverTrigger = PopoverPrimitive.Trigger;
522
+ function PopoverContent({ className, ...props }) {
523
+ const styles = { ...useSlicerStyles(), ...usePopoverStyles() };
524
+ return /* @__PURE__ */ jsx5(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx5(
525
+ PopoverPrimitive.Content,
526
+ {
527
+ align: "start",
528
+ side: "bottom",
529
+ sideOffset: 4,
530
+ avoidCollisions: false,
531
+ collisionPadding: 8,
532
+ ...props,
533
+ className: mergeClasses(styles.typography, styles.popover, className)
534
+ }
535
+ ) });
536
+ }
537
+
538
+ // src/components/dropdown-slicer/dropdown-slicer-styles.ts
539
+ import { makeStyles as makeStyles5 } from "@griffel/react";
540
+ import { inVisualsLayer as inVisualsLayer5, tokens as tokens5 } from "@microsoft/fabric-visuals-core";
541
+ var useDropdownStyles = makeStyles5(inVisualsLayer5({
542
+ trigger: {
543
+ display: "flex",
544
+ alignItems: "center",
545
+ justifyContent: "space-between",
546
+ gap: "8px",
547
+ width: "100%",
548
+ minWidth: 0,
549
+ height: "32px",
550
+ padding: "4px 10px",
551
+ backgroundColor: `var(--slicer-background, ${tokens5.colorBackground})`,
552
+ color: `var(--slicer-foreground, ${tokens5.colorForeground})`,
553
+ border: `1px solid var(--slicer-stroke, ${tokens5.colorBorder})`,
554
+ borderRadius: `var(--slicer-radius, ${tokens5.radiusXl})`,
555
+ textAlign: "start",
556
+ cursor: "pointer",
557
+ ":hover": { backgroundColor: `var(--slicer-hover, ${tokens5.colorHover})` }
558
+ }
559
+ }));
560
+
561
+ // src/components/dropdown-slicer/dropdown-slicer.tsx
562
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
563
+ function DropdownSlicer(props) {
564
+ return /* @__PURE__ */ jsx6(DropdownSlicerContent, { ...props }, props.column);
565
+ }
566
+ function DropdownSlicerContent(props) {
567
+ const state = useListSlicer(props);
568
+ const styles = { ...useSlicerStyles(), ...useDropdownStyles() };
569
+ const titleId = useId2();
570
+ const summaryId = useId2();
571
+ const themeStyle = useMemo3(() => slicerThemeStyle(props.theme), [props.theme]);
572
+ const hideHeader = props.displayOptions?.hideHeader ?? false;
573
+ const listDisplayOptions = useMemo3(
574
+ () => ({ ...props.displayOptions, hideHeader: true }),
575
+ [props.displayOptions]
576
+ );
577
+ const summary = state.items.length === 0 ? getString4("Slicer_NoData") : state.allSelected ? getString4("Slicer_All") : state.selectedItems.length === 0 ? getString4("Slicer_None") : state.selectedItems.length > 2 ? formatString3("Slicer_SelectionCount", state.selectedItems.length, state.items.length) : state.selectedItems.map((item) => item.label).join(", ");
578
+ return /* @__PURE__ */ jsxs4(
579
+ "section",
580
+ {
581
+ className: mergeClasses(styles.typography, styles.root),
582
+ style: themeStyle,
583
+ "aria-labelledby": hideHeader ? void 0 : titleId,
584
+ "aria-label": hideHeader ? state.title : void 0,
585
+ children: [
586
+ !hideHeader && /* @__PURE__ */ jsx6(
587
+ SlicerHeader,
588
+ {
589
+ title: state.title,
590
+ titleId,
591
+ onClear: state.allSelected ? void 0 : state.clear,
592
+ clearDisabled: !!state.error || state.items.length === 0
593
+ }
594
+ ),
595
+ state.error ? /* @__PURE__ */ jsx6(ListSlicerContent, { state, theme: props.theme, displayOptions: listDisplayOptions }) : /* @__PURE__ */ jsxs4(Popover, { children: [
596
+ /* @__PURE__ */ jsx6(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(
597
+ "button",
598
+ {
599
+ type: "button",
600
+ className: styles.trigger,
601
+ "aria-labelledby": hideHeader ? void 0 : `${titleId} ${summaryId}`,
602
+ "aria-label": hideHeader ? `${state.title} ${summary}` : void 0,
603
+ children: [
604
+ /* @__PURE__ */ jsx6("span", { id: summaryId, className: styles.text, title: summary, children: summary }),
605
+ /* @__PURE__ */ jsx6(ChevronDownIcon, { className: styles.icon })
606
+ ]
607
+ }
608
+ ) }),
609
+ /* @__PURE__ */ jsx6(PopoverContent, { style: themeStyle, "aria-label": state.title, children: /* @__PURE__ */ jsx6(
610
+ ListSlicerContent,
611
+ {
612
+ state,
613
+ theme: props.theme,
614
+ displayOptions: listDisplayOptions,
615
+ maxVisibleItems: 10
616
+ }
617
+ ) })
618
+ ] })
619
+ ]
620
+ }
621
+ );
622
+ }
623
+
624
+ // src/components/range-slicer/range-slicer.tsx
625
+ import { useCallback as useCallback6, useId as useId5, useMemo as useMemo6 } from "react";
626
+ import { mergeClasses as mergeClasses3 } from "@griffel/react";
627
+ import { formatString as formatString8, formatValue as formatValue2, getString as getString5 } from "@microsoft/fabric-visuals-core";
628
+
629
+ // src/components/range-slicer/range-slicer-data.ts
630
+ import { formatString as formatString4, isDataTable as isDataTable2 } from "@microsoft/fabric-visuals-core";
631
+ var maxAutomaticHistogramBinCount = 24;
632
+ function readRangeSlicerData(data, column, includeHistogram = true, binCount) {
633
+ const table = isDataTable2(data) ? data : { columns: [{ name: column }], rows: data.map((value) => [value]) };
634
+ const columnIndex = table.columns.findIndex((definition2) => definition2.name === column);
635
+ if (columnIndex < 0) {
636
+ return {
637
+ title: column,
638
+ format: void 0,
639
+ domain: null,
640
+ histogram: [],
641
+ error: formatString4("Common_ColumnNotFound", column)
642
+ };
643
+ }
644
+ const definition = table.columns[columnIndex];
645
+ let minimum;
646
+ let maximum;
647
+ let numericRowCount = 0;
648
+ const validBinCount = includeHistogram ? getValidHistogramBinCount(binCount) : void 0;
649
+ const distinctValues = includeHistogram && validBinCount === void 0 ? /* @__PURE__ */ new Set() : void 0;
650
+ for (const row of table.rows) {
651
+ const value = row[columnIndex];
652
+ if (typeof value === "number" && Number.isFinite(value)) {
653
+ minimum = minimum === void 0 ? value : Math.min(minimum, value);
654
+ maximum = maximum === void 0 ? value : Math.max(maximum, value);
655
+ if (distinctValues) {
656
+ numericRowCount++;
657
+ if (distinctValues.size < maxAutomaticHistogramBinCount) distinctValues.add(value);
658
+ }
659
+ }
660
+ }
661
+ const domain = minimum !== void 0 && maximum !== void 0 ? [minimum, maximum] : null;
662
+ let histogram = [];
663
+ if (includeHistogram && domain) {
664
+ const histogramBinCount = domain[0] === domain[1] ? 1 : validBinCount ?? Math.min(Math.ceil(Math.log2(numericRowCount) + 1), distinctValues?.size ?? 0);
665
+ histogram = Array.from({ length: histogramBinCount }, () => 0);
666
+ for (const row of table.rows) {
667
+ const value = row[columnIndex];
668
+ if (typeof value === "number" && Number.isFinite(value)) {
669
+ const binIndex = Math.min(histogram.length - 1, Math.floor(getRangePosition(value, domain) * histogram.length));
670
+ histogram[binIndex]++;
671
+ }
672
+ }
673
+ }
674
+ return {
675
+ title: definition.displayName ?? definition.name,
676
+ format: definition.format,
677
+ domain,
678
+ histogram
679
+ };
680
+ }
681
+ function getValidHistogramBinCount(binCount) {
682
+ return binCount !== void 0 && Number.isSafeInteger(binCount) && binCount > 0 ? binCount : void 0;
683
+ }
684
+ function getRangePosition(value, domain) {
685
+ const [minimum, maximum] = domain;
686
+ if (minimum === maximum) return 0.5;
687
+ const span = maximum - minimum;
688
+ return Number.isFinite(span) ? (value - minimum) / span : (value / 2 - minimum / 2) / (maximum / 2 - minimum / 2);
689
+ }
690
+
691
+ // src/components/range-slicer/range-slicer-styles.ts
692
+ import { makeStyles as makeStyles6, shorthands as shorthands2 } from "@griffel/react";
693
+ import { borderRadius, fontFamily as fontFamily2, fontSize, injectDesignTokens as injectDesignTokens2, inVisualsLayer as inVisualsLayer6, lineHeight, spacing, tokens as tokens6 } from "@microsoft/fabric-visuals-core";
694
+ injectDesignTokens2();
695
+ var useRangeSlicerStyles = makeStyles6(inVisualsLayer6({
696
+ root: {
697
+ "--range-foreground": tokens6.colorForeground,
698
+ "--range-secondary": tokens6.colorMutedForeground,
699
+ "--range-accent": tokens6.colorBrandForeground,
700
+ "--range-background": tokens6.colorBackground,
701
+ "--range-stroke": tokens6.colorBorder,
702
+ "--range-error": tokens6.colorDestructive,
703
+ display: "flex",
704
+ flexDirection: "column",
705
+ gap: spacing.s,
706
+ width: "300px",
707
+ maxWidth: "100%",
708
+ minWidth: 0,
709
+ fontFamily: fontFamily2.base,
710
+ fontSize: fontSize[300],
711
+ lineHeight: lineHeight[300],
712
+ color: "var(--range-foreground)",
713
+ "& [data-disabled]": {
714
+ cursor: "not-allowed"
715
+ },
716
+ // Supply system colors explicitly because the track and thumbs disable automatic color adjustment.
717
+ "@media (forced-colors: active)": {
718
+ "& *": {
719
+ "--range-accent": "Highlight",
720
+ "--range-background": "Canvas",
721
+ "--range-foreground": "CanvasText",
722
+ "--range-secondary": "CanvasText",
723
+ "--range-stroke": "GrayText",
724
+ "--range-error": "CanvasText"
725
+ }
726
+ }
727
+ },
728
+ body: {
729
+ boxSizing: "border-box",
730
+ padding: spacing.mNudge,
731
+ border: "1px solid var(--range-stroke)",
732
+ borderRadius: borderRadius.xLarge,
733
+ backgroundColor: "var(--range-background)"
734
+ },
735
+ framelessBody: {
736
+ padding: 0,
737
+ border: "none",
738
+ borderRadius: 0,
739
+ backgroundColor: "transparent"
740
+ },
741
+ empty: {
742
+ margin: 0,
743
+ color: "var(--range-secondary)",
744
+ fontSize: fontSize[200]
745
+ },
746
+ histogram: {
747
+ // Match the track inset so histogram values align with the thumb centers.
748
+ marginInline: spacing.m,
749
+ height: "40px",
750
+ "& svg": {
751
+ display: "block",
752
+ // These fills already use system colors in forced-color mode.
753
+ forcedColorAdjust: "none"
754
+ }
755
+ },
756
+ // Share the track and range colors so both layers follow themes and forced-color overrides.
757
+ histogramMuted: {
758
+ fill: "var(--range-stroke)"
759
+ },
760
+ histogramSelected: {
761
+ fill: "var(--range-accent)"
762
+ },
763
+ slider: {
764
+ position: "relative",
765
+ display: "flex",
766
+ alignItems: "center",
767
+ height: spacing.xxl,
768
+ touchAction: "none",
769
+ userSelect: "none",
770
+ cursor: "pointer"
771
+ },
772
+ track: {
773
+ position: "relative",
774
+ flexGrow: 1,
775
+ height: "3px",
776
+ marginInline: spacing.m,
777
+ backgroundColor: "var(--range-stroke)",
778
+ borderRadius: borderRadius.circular,
779
+ forcedColorAdjust: "none"
780
+ },
781
+ range: {
782
+ position: "absolute",
783
+ height: "100%",
784
+ backgroundColor: "var(--range-accent)",
785
+ borderRadius: borderRadius.circular
786
+ },
787
+ thumb: {
788
+ display: "block",
789
+ position: "relative",
790
+ width: spacing.xxl,
791
+ height: spacing.xxl,
792
+ borderRadius: borderRadius.circular,
793
+ outline: "none",
794
+ forcedColorAdjust: "none",
795
+ // Draw a small visible handle while retaining a larger pointer target.
796
+ "::before": {
797
+ content: '""',
798
+ position: "absolute",
799
+ inset: "6px",
800
+ border: "1px solid var(--range-accent)",
801
+ borderRadius: borderRadius.circular,
802
+ backgroundColor: "var(--range-background)"
803
+ },
804
+ ":hover::before": {
805
+ borderWidth: "2px"
806
+ },
807
+ ":focus-visible": {
808
+ outline: "2px solid var(--range-accent)",
809
+ outlineOffset: "1px"
810
+ }
811
+ },
812
+ inputs: {
813
+ display: "grid",
814
+ gridTemplateColumns: "minmax(0, 1fr) auto minmax(0, 1fr)",
815
+ alignItems: "start",
816
+ gap: spacing.s
817
+ },
818
+ input: {
819
+ boxSizing: "border-box",
820
+ width: "100%",
821
+ minWidth: 0,
822
+ height: "28px",
823
+ paddingInline: spacing.s,
824
+ border: "1px solid var(--range-stroke)",
825
+ borderRadius: borderRadius.xLarge,
826
+ color: "var(--range-foreground)",
827
+ backgroundColor: "var(--range-background)",
828
+ fontFamily: "inherit",
829
+ fontSize: "inherit",
830
+ fontVariantNumeric: "tabular-nums",
831
+ ":focus-visible": {
832
+ outline: "2px solid var(--range-accent)",
833
+ outlineOffset: "1px"
834
+ },
835
+ ":disabled": {
836
+ color: "var(--range-secondary)",
837
+ cursor: "not-allowed"
838
+ },
839
+ '&[aria-invalid="true"]': {
840
+ ...shorthands2.borderColor("var(--range-error)"),
841
+ color: "var(--range-error)",
842
+ outlineColor: "var(--range-error)",
843
+ boxShadow: "0 0 0 3px color-mix(in srgb, var(--range-error) 20%, transparent)"
844
+ }
845
+ },
846
+ separator: {
847
+ lineHeight: "28px",
848
+ fontSize: fontSize[200],
849
+ color: "var(--range-secondary)"
850
+ },
851
+ fullRange: {
852
+ margin: 0,
853
+ marginTop: spacing.s,
854
+ color: "var(--range-secondary)",
855
+ fontSize: fontSize[200],
856
+ lineHeight: lineHeight[200],
857
+ overflowWrap: "anywhere"
858
+ },
859
+ error: {
860
+ display: "block",
861
+ marginTop: spacing.xs,
862
+ color: "var(--range-error)",
863
+ fontSize: fontSize[300],
864
+ lineHeight: lineHeight[300],
865
+ overflowWrap: "anywhere"
866
+ }
867
+ }));
868
+
869
+ // src/components/range-slicer/range-value-input.tsx
870
+ import { useCallback as useCallback3, useId as useId3, useState as useState3 } from "react";
871
+ import { formatString as formatString5 } from "@microsoft/fabric-visuals-core";
872
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
873
+ function RangeValueInput({
874
+ label,
875
+ value,
876
+ min,
877
+ max,
878
+ disabled,
879
+ descriptionId,
880
+ formatValue: formatValue3,
881
+ onCommit
882
+ }) {
883
+ const styles = useRangeSlicerStyles();
884
+ const errorId = useId3();
885
+ const [draft, setDraft] = useState3();
886
+ const [error, setError] = useState3();
887
+ const handleFocus = useCallback3(() => {
888
+ setDraft(String(value));
889
+ setError(void 0);
890
+ }, [value]);
891
+ const handleChange = useCallback3((event) => {
892
+ setDraft(event.currentTarget.value);
893
+ setError(void 0);
894
+ }, []);
895
+ const handleBlur = useCallback3((event) => {
896
+ const text = event.currentTarget.value.trim();
897
+ const nextValue = Number(text);
898
+ if (text !== "" && Number.isFinite(nextValue) && nextValue >= min && nextValue <= max) {
899
+ onCommit(nextValue);
900
+ setDraft(void 0);
901
+ setError(void 0);
902
+ } else {
903
+ setError(formatString5("RangeSlicer_InvalidValue", formatValue3(min), formatValue3(max)));
904
+ }
905
+ }, [min, max, formatValue3, onCommit]);
906
+ const handleKeyDown = useCallback3((event) => {
907
+ if (event.key === "Enter") {
908
+ event.preventDefault();
909
+ event.currentTarget.blur();
910
+ } else if (event.key === "Escape") {
911
+ event.preventDefault();
912
+ setDraft(String(value));
913
+ setError(void 0);
914
+ }
915
+ }, [value]);
916
+ return /* @__PURE__ */ jsxs5("div", { children: [
917
+ /* @__PURE__ */ jsx7(
918
+ "input",
919
+ {
920
+ className: styles.input,
921
+ type: "text",
922
+ inputMode: "decimal",
923
+ "aria-label": label,
924
+ "aria-describedby": error ? `${descriptionId} ${errorId}` : descriptionId,
925
+ "aria-invalid": Boolean(error),
926
+ disabled,
927
+ value: draft ?? formatValue3(value),
928
+ onFocus: handleFocus,
929
+ onChange: handleChange,
930
+ onBlur: handleBlur,
931
+ onKeyDown: handleKeyDown
932
+ }
933
+ ),
934
+ error && /* @__PURE__ */ jsx7("span", { className: styles.error, id: errorId, role: "alert", children: error })
935
+ ] });
936
+ }
937
+
938
+ // src/components/range-slicer/range-histogram.tsx
939
+ import { useId as useId4 } from "react";
940
+ import { formatString as formatString6 } from "@microsoft/fabric-visuals-core";
941
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
942
+ var histogramWidth = 240;
943
+ var histogramHeight = 40;
944
+ function RangeHistogram({ counts, domain, selectedRange, title }) {
945
+ const styles = useRangeSlicerStyles();
946
+ const clipId = useId4();
947
+ const maximumCount = Math.max(...counts);
948
+ const isFixedRange = domain[0] === domain[1];
949
+ const binWidth = isFixedRange ? 10 : histogramWidth / counts.length;
950
+ const gap = Math.min(2, binWidth * 0.2);
951
+ const startX = isFixedRange ? (histogramWidth - binWidth) / 2 : 0;
952
+ const bars = counts.map((count, index) => {
953
+ const height = count / maximumCount * histogramHeight;
954
+ const x = startX + index * binWidth + gap / 2;
955
+ return /* @__PURE__ */ jsx8("rect", { x, y: histogramHeight - height, width: binWidth - gap, height }, x);
956
+ });
957
+ const selectionStart = isFixedRange ? 0 : getRangePosition(selectedRange[0], domain) * histogramWidth;
958
+ const selectionEnd = isFixedRange ? histogramWidth : getRangePosition(selectedRange[1], domain) * histogramWidth;
959
+ return /* @__PURE__ */ jsx8("div", { className: styles.histogram, children: /* @__PURE__ */ jsxs6(
960
+ "svg",
961
+ {
962
+ width: "100%",
963
+ height: histogramHeight,
964
+ viewBox: `0 0 ${histogramWidth} ${histogramHeight}`,
965
+ preserveAspectRatio: "none",
966
+ role: "img",
967
+ "aria-label": formatString6("RangeSlicer_DistributionLabel", title),
968
+ focusable: "false",
969
+ children: [
970
+ /* @__PURE__ */ jsx8("defs", { children: /* @__PURE__ */ jsx8("clipPath", { id: clipId, children: /* @__PURE__ */ jsx8("rect", { x: selectionStart, y: 0, width: selectionEnd - selectionStart, height: histogramHeight }) }) }),
971
+ /* @__PURE__ */ jsx8("g", { className: styles.histogramMuted, children: bars }),
972
+ /* @__PURE__ */ jsx8("g", { className: styles.histogramSelected, clipPath: `url(#${clipId})`, children: bars })
973
+ ]
974
+ }
975
+ ) });
976
+ }
977
+
978
+ // src/components/range-slicer/range-slider.tsx
979
+ import { Root as Slider, Track, Range, Thumb } from "@radix-ui/react-slider";
980
+ import { useCallback as useCallback4, useMemo as useMemo4, useRef as useRef2 } from "react";
981
+ import { formatString as formatString7 } from "@microsoft/fabric-visuals-core";
982
+
983
+ // src/components/range-slicer/range-slider-steps.ts
984
+ function getAutomaticRangeStep(domain, formatBound = String) {
985
+ const [minimum, maximum] = domain;
986
+ if (minimum === maximum) return 1;
987
+ const span = maximum - minimum;
988
+ let step = getNiceStep(Math.max(span / 100, Number.MIN_VALUE));
989
+ while (step < span && hasRepeatedLabels(domain, step, formatBound)) {
990
+ step = getNiceStep(step * 2);
991
+ }
992
+ return step;
993
+ }
994
+ function getNiceStep(rawStep) {
995
+ const magnitude = 10 ** Math.floor(Math.log10(rawStep));
996
+ if (magnitude === 0) return rawStep;
997
+ const fraction = rawStep / magnitude;
998
+ const factor = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
999
+ return factor * magnitude;
1000
+ }
1001
+ function hasRepeatedLabels(domain, step, formatBound) {
1002
+ const [minimum, maximum] = domain;
1003
+ let previousLabel = formatBound(minimum);
1004
+ for (let index = 1; minimum + index * step < maximum; index++) {
1005
+ const label = formatBound(minimum + index * step);
1006
+ if (label === previousLabel) return true;
1007
+ previousLabel = label;
1008
+ }
1009
+ return previousLabel === formatBound(maximum);
1010
+ }
1011
+
1012
+ // src/components/range-slicer/range-slider.tsx
1013
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1014
+ function RangeSlider({
1015
+ domain,
1016
+ selectedRange,
1017
+ step,
1018
+ disabled,
1019
+ title,
1020
+ descriptionId,
1021
+ formatBound,
1022
+ onValueChange,
1023
+ onValueCommit
1024
+ }) {
1025
+ const styles = useRangeSlicerStyles();
1026
+ const lowerThumb = useRef2(null);
1027
+ const upperThumb = useRef2(null);
1028
+ const usesAutomaticStep = step === void 0;
1029
+ const sliderStep = useMemo4(
1030
+ () => step ?? getAutomaticRangeStep(domain, formatBound),
1031
+ [domain, step, formatBound]
1032
+ );
1033
+ const handleKeyDown = useCallback4((event) => {
1034
+ if (usesAutomaticStep && !disabled) {
1035
+ if (event.key === "Home") {
1036
+ event.preventDefault();
1037
+ onValueChange([domain[0], selectedRange[1]]);
1038
+ onValueCommit([domain[0], selectedRange[1]]);
1039
+ lowerThumb.current?.focus();
1040
+ } else if (event.key === "End") {
1041
+ event.preventDefault();
1042
+ onValueChange([selectedRange[0], domain[1]]);
1043
+ onValueCommit([selectedRange[0], domain[1]]);
1044
+ upperThumb.current?.focus();
1045
+ }
1046
+ }
1047
+ }, [usesAutomaticStep, disabled, selectedRange, domain, onValueChange, onValueCommit]);
1048
+ return /* @__PURE__ */ jsxs7(
1049
+ Slider,
1050
+ {
1051
+ className: styles.slider,
1052
+ min: domain[0],
1053
+ max: domain[1],
1054
+ step: sliderStep,
1055
+ value: selectedRange,
1056
+ disabled,
1057
+ onValueChange,
1058
+ onValueCommit,
1059
+ onKeyDown: handleKeyDown,
1060
+ children: [
1061
+ /* @__PURE__ */ jsx9(Track, { className: styles.track, children: /* @__PURE__ */ jsx9(Range, { className: styles.range }) }),
1062
+ /* @__PURE__ */ jsx9(
1063
+ Thumb,
1064
+ {
1065
+ ref: lowerThumb,
1066
+ className: styles.thumb,
1067
+ "aria-label": formatString7("RangeSlicer_MinimumLabel", title),
1068
+ "aria-valuemin": domain[0],
1069
+ "aria-valuemax": domain[1],
1070
+ "aria-valuenow": selectedRange[0],
1071
+ "aria-valuetext": formatBound(selectedRange[0]),
1072
+ "aria-describedby": descriptionId
1073
+ }
1074
+ ),
1075
+ /* @__PURE__ */ jsx9(
1076
+ Thumb,
1077
+ {
1078
+ ref: upperThumb,
1079
+ className: styles.thumb,
1080
+ "aria-label": formatString7("RangeSlicer_MaximumLabel", title),
1081
+ "aria-valuemin": domain[0],
1082
+ "aria-valuemax": domain[1],
1083
+ "aria-valuenow": selectedRange[1],
1084
+ "aria-valuetext": formatBound(selectedRange[1]),
1085
+ "aria-describedby": descriptionId
1086
+ }
1087
+ )
1088
+ ]
1089
+ }
1090
+ );
1091
+ }
1092
+
1093
+ // src/components/range-slicer/use-range-selection.ts
1094
+ import { useCallback as useCallback5, useEffect as useEffect2, useMemo as useMemo5, useRef as useRef3, useState as useState4 } from "react";
1095
+ function resolveSelection(domain, selection) {
1096
+ if (selection) {
1097
+ if (Number.isNaN(selection[0]) || Number.isNaN(selection[1]) || selection[0] > selection[1]) {
1098
+ throw new Error("RangeSlicer selection must contain ordered numeric bounds.");
1099
+ }
1100
+ if (domain) {
1101
+ return [
1102
+ Math.max(domain[0], Math.min(domain[1], selection[0])),
1103
+ Math.max(domain[0], Math.min(domain[1], selection[1]))
1104
+ ];
1105
+ }
1106
+ }
1107
+ return domain;
1108
+ }
1109
+ function useRangeSelection(domain, column, onInteraction, selection) {
1110
+ const resolvedSelection = useMemo5(() => resolveSelection(domain, selection), [domain, selection]);
1111
+ const [selectedRange, setSelectedRange] = useState4(resolvedSelection);
1112
+ const lastCommittedRange = useRef3(resolvedSelection);
1113
+ const [inputRevision, setInputRevision] = useState4(0);
1114
+ const incrementInputRevision = useCallback5(() => {
1115
+ setInputRevision((revision) => revision + 1);
1116
+ }, []);
1117
+ useEffect2(() => {
1118
+ if (selection !== void 0) {
1119
+ const previousRange = lastCommittedRange.current;
1120
+ if (previousRange?.[0] === resolvedSelection?.[0] && previousRange?.[1] === resolvedSelection?.[1]) return;
1121
+ lastCommittedRange.current = resolvedSelection;
1122
+ setSelectedRange(resolvedSelection);
1123
+ incrementInputRevision();
1124
+ }
1125
+ }, [selection, resolvedSelection, incrementInputRevision]);
1126
+ const commitSelectedRange = useCallback5((values) => {
1127
+ if (domain) {
1128
+ setSelectedRange([values[0], values[1]]);
1129
+ const previousRange = lastCommittedRange.current;
1130
+ if (previousRange && previousRange[0] === values[0] && previousRange[1] === values[1]) return;
1131
+ lastCommittedRange.current = [values[0], values[1]];
1132
+ if (onInteraction) {
1133
+ const isLowerBoundAtDomainMinimum = values[0] === domain[0];
1134
+ const isUpperBoundAtDomainMaximum = values[1] === domain[1];
1135
+ const isFullRange = isLowerBoundAtDomainMinimum && isUpperBoundAtDomainMaximum;
1136
+ const event = isFullRange ? { action: "clear" } : {
1137
+ action: "select",
1138
+ selections: [{
1139
+ predicates: [{
1140
+ type: "range",
1141
+ name: column,
1142
+ min: isLowerBoundAtDomainMinimum ? -Infinity : values[0],
1143
+ max: isUpperBoundAtDomainMaximum ? Infinity : values[1]
1144
+ }]
1145
+ }]
1146
+ };
1147
+ onInteraction([event]);
1148
+ }
1149
+ }
1150
+ }, [domain, column, onInteraction]);
1151
+ const handleSliderChange = useCallback5((values) => {
1152
+ setSelectedRange([values[0], values[1]]);
1153
+ incrementInputRevision();
1154
+ }, [incrementInputRevision]);
1155
+ const clearSelection = useCallback5(() => {
1156
+ setSelectedRange(domain);
1157
+ lastCommittedRange.current = domain;
1158
+ incrementInputRevision();
1159
+ onInteraction?.([{ action: "clear" }]);
1160
+ }, [domain, onInteraction, incrementInputRevision]);
1161
+ return {
1162
+ selectedRange,
1163
+ inputRevision,
1164
+ handleSliderChange,
1165
+ commitSelectedRange,
1166
+ clearSelection
1167
+ };
1168
+ }
1169
+
1170
+ // src/components/range-slicer/range-slicer.tsx
1171
+ import { Fragment as Fragment2, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1172
+ function RangeSlicer({
1173
+ data,
1174
+ column,
1175
+ title,
1176
+ theme,
1177
+ step,
1178
+ disabled = false,
1179
+ displayOptions,
1180
+ onInteraction,
1181
+ selection
1182
+ }) {
1183
+ const styles = useRangeSlicerStyles();
1184
+ const id = useId5();
1185
+ const titleId = `${id}-title`;
1186
+ const descriptionId = `${id}-description`;
1187
+ const hideHeader = displayOptions?.hideHeader ?? false;
1188
+ const showHistogram = displayOptions?.showHistogram ?? true;
1189
+ const binCount = showHistogram ? displayOptions?.binCount : void 0;
1190
+ const slicerData = useMemo6(
1191
+ () => readRangeSlicerData(data, column, showHistogram, binCount),
1192
+ [data, column, showHistogram, binCount]
1193
+ );
1194
+ const { selectedRange, inputRevision, handleSliderChange, commitSelectedRange, clearSelection } = useRangeSelection(
1195
+ slicerData.domain,
1196
+ column,
1197
+ onInteraction,
1198
+ selection
1199
+ );
1200
+ const displayTitle = title ?? slicerData.title;
1201
+ const hasSelection = selectedRange !== null && slicerData.domain !== null && (selectedRange[0] !== slicerData.domain[0] || selectedRange[1] !== slicerData.domain[1]);
1202
+ const isFixedRange = slicerData.domain !== null && slicerData.domain[0] === slicerData.domain[1];
1203
+ const areControlsDisabled = disabled || isFixedRange;
1204
+ const sliderStep = step !== void 0 && Number.isFinite(step) && step > 0 ? step : void 0;
1205
+ const themeStyle = useMemo6(() => theme ? {
1206
+ ...slicerThemeStyle(theme),
1207
+ "--range-foreground": theme.foreground,
1208
+ "--range-secondary": theme.foregroundSecondary,
1209
+ "--range-accent": theme.brandForeground,
1210
+ "--range-background": theme.background,
1211
+ "--range-stroke": theme.stroke,
1212
+ fontFamily: theme.typography?.label?.family
1213
+ } : {}, [theme]);
1214
+ const formatBound = useCallback6((value) => String(formatValue2(value, slicerData.format)), [slicerData.format]);
1215
+ const handleLowerCommit = useCallback6((value) => {
1216
+ if (selectedRange) commitSelectedRange([value, selectedRange[1]]);
1217
+ }, [selectedRange, commitSelectedRange]);
1218
+ const handleUpperCommit = useCallback6((value) => {
1219
+ if (selectedRange) commitSelectedRange([selectedRange[0], value]);
1220
+ }, [selectedRange, commitSelectedRange]);
1221
+ if (slicerData.error) return /* @__PURE__ */ jsx10("div", { role: "alert", children: slicerData.error });
1222
+ return /* @__PURE__ */ jsxs8(
1223
+ "section",
1224
+ {
1225
+ className: styles.root,
1226
+ style: themeStyle,
1227
+ "aria-labelledby": hideHeader ? void 0 : titleId,
1228
+ "aria-label": hideHeader ? displayTitle : void 0,
1229
+ children: [
1230
+ !hideHeader && /* @__PURE__ */ jsx10(
1231
+ SlicerHeader,
1232
+ {
1233
+ title: displayTitle,
1234
+ titleId,
1235
+ onClear: hasSelection ? clearSelection : void 0,
1236
+ clearDisabled: areControlsDisabled
1237
+ }
1238
+ ),
1239
+ /* @__PURE__ */ jsx10("div", { className: mergeClasses3(styles.body, displayOptions?.frameless && styles.framelessBody), children: selectedRange && slicerData.domain ? /* @__PURE__ */ jsxs8(Fragment2, { children: [
1240
+ showHistogram && /* @__PURE__ */ jsx10(RangeHistogram, { counts: slicerData.histogram, domain: slicerData.domain, selectedRange, title: displayTitle }),
1241
+ isFixedRange ? /* @__PURE__ */ jsx10("div", { className: styles.slider, "aria-hidden": "true", children: /* @__PURE__ */ jsx10("div", { className: styles.track }) }) : /* @__PURE__ */ jsx10(
1242
+ RangeSlider,
1243
+ {
1244
+ domain: slicerData.domain,
1245
+ selectedRange,
1246
+ step: sliderStep,
1247
+ disabled: areControlsDisabled,
1248
+ title: displayTitle,
1249
+ descriptionId,
1250
+ formatBound,
1251
+ onValueChange: handleSliderChange,
1252
+ onValueCommit: commitSelectedRange
1253
+ }
1254
+ ),
1255
+ /* @__PURE__ */ jsxs8("div", { className: styles.inputs, children: [
1256
+ /* @__PURE__ */ jsx10(
1257
+ RangeValueInput,
1258
+ {
1259
+ label: formatString8("RangeSlicer_MinimumLabel", displayTitle),
1260
+ value: selectedRange[0],
1261
+ min: slicerData.domain[0],
1262
+ max: selectedRange[1],
1263
+ disabled: areControlsDisabled,
1264
+ descriptionId,
1265
+ formatValue: formatBound,
1266
+ onCommit: handleLowerCommit
1267
+ },
1268
+ `lower-${inputRevision}`
1269
+ ),
1270
+ /* @__PURE__ */ jsx10("span", { className: styles.separator, children: getString5("RangeSlicer_To") }),
1271
+ /* @__PURE__ */ jsx10(
1272
+ RangeValueInput,
1273
+ {
1274
+ label: formatString8("RangeSlicer_MaximumLabel", displayTitle),
1275
+ value: selectedRange[1],
1276
+ min: selectedRange[0],
1277
+ max: slicerData.domain[1],
1278
+ disabled: areControlsDisabled,
1279
+ descriptionId,
1280
+ formatValue: formatBound,
1281
+ onCommit: handleUpperCommit
1282
+ },
1283
+ `upper-${inputRevision}`
1284
+ )
1285
+ ] }),
1286
+ /* @__PURE__ */ jsx10("p", { id: descriptionId, className: styles.fullRange, children: formatString8("RangeSlicer_FullRange", formatBound(slicerData.domain[0]), formatBound(slicerData.domain[1])) })
1287
+ ] }) : /* @__PURE__ */ jsx10("p", { className: styles.empty, role: "status", children: getString5("Common_NoNumericValues") }) })
1288
+ ]
1289
+ }
1290
+ );
1291
+ }
1292
+ export {
1293
+ DropdownSlicer,
1294
+ ListSlicer,
1295
+ RangeSlicer
1296
+ };