@epilot/spark-ui 0.30.1 → 0.30.3
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/components/accordion.cjs +1 -1
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.cjs +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/attachment.cjs +1 -1
- package/dist/components/attachment.js +1 -1
- package/dist/components/autocomplete.cjs +1 -1
- package/dist/components/autocomplete.js +1 -1
- package/dist/components/badge.cjs +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/banner.cjs +1 -1
- package/dist/components/banner.js +1 -1
- package/dist/components/breadcrumbs.cjs +1 -1
- package/dist/components/breadcrumbs.js +1 -1
- package/dist/components/bubble.cjs +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/bubble.js +1 -1
- package/dist/components/button-group.cjs +1 -1
- package/dist/components/button-group.js +1 -1
- package/dist/components/button.cjs +1 -1
- package/dist/components/button.d.cts +2 -2
- package/dist/components/button.d.ts +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.cjs +3 -1
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.js +3 -1
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.cjs +1 -1
- package/dist/components/callout.js +1 -1
- package/dist/components/card.cjs +1 -1
- package/dist/components/card.js +1 -1
- package/dist/components/combobox.cjs +1 -1
- package/dist/components/combobox.js +1 -1
- package/dist/components/dialog.cjs +1 -1
- package/dist/components/dialog.js +1 -1
- package/dist/components/drawer.cjs +1 -1
- package/dist/components/drawer.js +1 -1
- package/dist/components/dropdown-menu.cjs +1 -1
- package/dist/components/dropdown-menu.js +1 -1
- package/dist/components/empty-state.cjs +1 -1
- package/dist/components/empty-state.js +1 -1
- package/dist/components/entity-card.cjs +1 -1
- package/dist/components/entity-card.js +1 -1
- package/dist/components/field.cjs +8 -5
- package/dist/components/field.cjs.map +1 -1
- package/dist/components/field.js +8 -5
- package/dist/components/field.js.map +1 -1
- package/dist/components/hero-metric.cjs +1 -1
- package/dist/components/hero-metric.js +1 -1
- package/dist/components/info-block.cjs +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/info-block.js +1 -1
- package/dist/components/input-date-time.cjs +7 -2
- package/dist/components/input-date-time.cjs.map +1 -1
- package/dist/components/input-date-time.js +7 -2
- package/dist/components/input-date-time.js.map +1 -1
- package/dist/components/input-date.cjs +1 -1
- package/dist/components/input-date.js +1 -1
- package/dist/components/input-group.cjs +1 -1
- package/dist/components/input-group.js +1 -1
- package/dist/components/input-otp.cjs +1 -1
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input.cjs +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/list.cjs +1 -1
- package/dist/components/list.js +1 -1
- package/dist/components/marker.cjs +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/marker.js +1 -1
- package/dist/components/message-scroller.cjs +1 -1
- package/dist/components/message-scroller.js +1 -1
- package/dist/components/page-header.cjs +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/page-header.js +1 -1
- package/dist/components/period-tabs.cjs +1 -1
- package/dist/components/period-tabs.js +1 -1
- package/dist/components/pill.cjs +1 -1
- package/dist/components/pill.js +1 -1
- package/dist/components/popover.cjs +1 -1
- package/dist/components/popover.js +1 -1
- package/dist/components/power-network.cjs +1 -1
- package/dist/components/power-network.js +1 -1
- package/dist/components/schedule-list.cjs +1 -1
- package/dist/components/schedule-list.js +1 -1
- package/dist/components/select.cjs +1 -1
- package/dist/components/select.js +1 -1
- package/dist/components/separator.cjs +1 -1
- package/dist/components/separator.js +1 -1
- package/dist/components/sheet.cjs +1 -1
- package/dist/components/sheet.js +1 -1
- package/dist/components/skeleton.cjs +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/stepper.cjs +1 -1
- package/dist/components/stepper.js +1 -1
- package/dist/components/table.cjs +1 -1
- package/dist/components/table.js +1 -1
- package/dist/components/tabs.cjs +1 -1
- package/dist/components/tabs.js +1 -1
- package/dist/components/textarea.cjs +1 -1
- package/dist/components/textarea.js +1 -1
- package/dist/components/theme.cjs +1 -1
- package/dist/components/theme.js +1 -1
- package/dist/components/toast.cjs +1 -1
- package/dist/components/toast.js +1 -1
- package/dist/components/tooltip.cjs +1 -1
- package/dist/components/tooltip.js +1 -1
- package/dist/components/trace.cjs +1 -1
- package/dist/components/trace.js +1 -1
- package/dist/lib/calendar-day-button.cjs +23 -0
- package/dist/lib/calendar-day-button.cjs.map +1 -0
- package/dist/lib/calendar-day-button.d.cts +14 -0
- package/dist/lib/calendar-day-button.d.ts +14 -0
- package/dist/lib/calendar-day-button.js +20 -0
- package/dist/lib/calendar-day-button.js.map +1 -0
- package/dist/lib/calendar-lists.cjs +6 -5
- package/dist/lib/calendar-lists.cjs.map +1 -1
- package/dist/lib/calendar-lists.js +6 -5
- package/dist/lib/calendar-lists.js.map +1 -1
- package/dist/lib/input-date-parts.cjs +3 -2
- package/dist/lib/input-date-parts.cjs.map +1 -1
- package/dist/lib/input-date-parts.js +3 -2
- package/dist/lib/input-date-parts.js.map +1 -1
- package/dist/lib/scroll-within.cjs +27 -0
- package/dist/lib/scroll-within.cjs.map +1 -0
- package/dist/lib/scroll-within.d.cts +14 -0
- package/dist/lib/scroll-within.d.ts +14 -0
- package/dist/lib/scroll-within.js +25 -0
- package/dist/lib/scroll-within.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-date-parts.js","names":["React"],"sources":["../../src/lib/input-date-parts.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport {\n applyDateTimeMask,\n applyDateTimePaste,\n formatTime,\n isDateTimeMaskKey,\n} from './date-time-mask'\n\nconst MINUTES_PER_DAY = 24 * 60\n// a finer step would list hundreds of buttons; a typed off-grid time is still offered\nconst MIN_STEP = 5\n\n/** `HH:MM` every `step` minutes (5 at least), plus `extra` when it is off that grid. */\nexport function timesOf(step: number, extra?: string) {\n const times: string[] = []\n for (\n let minutes = 0;\n minutes < MINUTES_PER_DAY;\n minutes += Math.max(MIN_STEP, step)\n ) {\n times.push(\n formatTime({\n hours: Math.floor(minutes / 60),\n minutes: minutes % 60,\n seconds: 0,\n }),\n )\n }\n if (extra && !times.includes(extra)) {\n const after = times.findIndex((time) => time > extra)\n times.splice(after === -1 ? times.length : after, 0, extra)\n }\n return times\n}\n\nexport function TimeList({\n defaultTime,\n label,\n onPick,\n open,\n selectedTime,\n times,\n}: {\n defaultTime: string\n label?: string\n onPick: (time: string) => void\n open: boolean\n selectedTime?: string\n times: string[]\n}) {\n const listRef = React.useRef<HTMLDivElement>(null)\n\n // the picked time scrolls into view when the popup opens; found in the DOM rather than with a ref per option\n React.useEffect(() => {\n if (!open) return\n const frame = requestAnimationFrame(() => {\n listRef.current
|
|
1
|
+
{"version":3,"file":"input-date-parts.js","names":["React"],"sources":["../../src/lib/input-date-parts.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport {\n applyDateTimeMask,\n applyDateTimePaste,\n formatTime,\n isDateTimeMaskKey,\n} from './date-time-mask'\nimport { focusWithin, scrollWithin } from './scroll-within'\n\nconst MINUTES_PER_DAY = 24 * 60\n// a finer step would list hundreds of buttons; a typed off-grid time is still offered\nconst MIN_STEP = 5\n\n/** `HH:MM` every `step` minutes (5 at least), plus `extra` when it is off that grid. */\nexport function timesOf(step: number, extra?: string) {\n const times: string[] = []\n for (\n let minutes = 0;\n minutes < MINUTES_PER_DAY;\n minutes += Math.max(MIN_STEP, step)\n ) {\n times.push(\n formatTime({\n hours: Math.floor(minutes / 60),\n minutes: minutes % 60,\n seconds: 0,\n }),\n )\n }\n if (extra && !times.includes(extra)) {\n const after = times.findIndex((time) => time > extra)\n times.splice(after === -1 ? times.length : after, 0, extra)\n }\n return times\n}\n\nexport function TimeList({\n defaultTime,\n label,\n onPick,\n open,\n selectedTime,\n times,\n}: {\n defaultTime: string\n label?: string\n onPick: (time: string) => void\n open: boolean\n selectedTime?: string\n times: string[]\n}) {\n const listRef = React.useRef<HTMLDivElement>(null)\n\n // the picked time scrolls into view when the popup opens; found in the DOM rather than with a ref per option\n React.useEffect(() => {\n if (!open) return\n const frame = requestAnimationFrame(() => {\n scrollWithin(\n listRef.current,\n listRef.current?.querySelector<HTMLElement>('[aria-selected=\"true\"]') ??\n null,\n 'center',\n )\n })\n return () => cancelAnimationFrame(frame)\n }, [open])\n\n const moveFocus = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const options = Array.from(\n listRef.current?.querySelectorAll<HTMLButtonElement>('[role=\"option\"]') ??\n [],\n )\n const index = options.indexOf(document.activeElement as HTMLButtonElement)\n const target = {\n ArrowDown: index + 1,\n ArrowUp: index - 1,\n End: options.length - 1,\n Home: 0,\n }[event.key]\n if (target === undefined) return\n event.preventDefault()\n focusWithin(\n listRef.current,\n options[Math.max(0, Math.min(options.length - 1, target))] ?? null,\n )\n }\n\n return (\n // the column runs the calendar's full height and the list scrolls inside it\n <div\n className=\"relative border-gray-a4 max-sm:h-40 max-sm:border-t sm:w-24 sm:border-l\"\n data-slot=\"input-date-times\"\n >\n <div\n aria-label={label}\n className=\"absolute inset-0 flex flex-col gap-0.5 overflow-y-auto p-2\"\n onKeyDown={moveFocus}\n ref={listRef}\n role=\"listbox\"\n tabIndex={-1}\n >\n {times.map((time) => {\n const isSelected = time === selectedTime\n return (\n <button\n aria-selected={isSelected}\n className={cn(\n 'shrink-0 cursor-pointer rounded-md px-3 py-1.5 text-center text-sm text-gray hover:bg-gray-a3 focus-visible:focus-outline',\n isSelected &&\n 'bg-(--spark-style-bg,var(--color-primary)) text-(--spark-style-fg,var(--color-primary-foreground)) hover:bg-(--spark-style-bg-hover,var(--color-primary-hover))',\n )}\n key={time}\n onClick={() => onPick(time)}\n role=\"option\"\n tabIndex={\n isSelected || (!selectedTime && time === defaultTime) ? 0 : -1\n }\n type=\"button\"\n >\n {time}\n </button>\n )\n })}\n </div>\n </div>\n )\n}\n\ntype MaskHandlers = {\n commit: (next: string) => void\n inputRef: React.RefObject<HTMLInputElement | null>\n onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>\n onOpen: () => void\n onPaste?: React.ClipboardEventHandler<HTMLInputElement>\n onRejectedKey: () => void\n pickerOnly: boolean\n separator: string\n withTime: boolean\n}\n\n/** Keystrokes and pastes through the date (and time) mask. */\nexport function useMaskHandlers({\n commit,\n inputRef,\n onKeyDown,\n onOpen,\n onPaste,\n onRejectedKey,\n pickerOnly,\n separator,\n withTime,\n}: MaskHandlers) {\n const placeCaret = (caret: number) => {\n const input = inputRef.current\n requestAnimationFrame(() => {\n input?.setSelectionRange(caret, caret)\n })\n }\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n onOpen()\n return\n }\n if (pickerOnly || event.ctrlKey || event.metaKey || event.altKey) return\n if (!isDateTimeMaskKey(event.key, withTime)) {\n // a printable key the mask ignores: say why nothing appeared\n if (event.key.length === 1) {\n event.preventDefault()\n onRejectedKey()\n }\n return\n }\n event.preventDefault()\n const next = applyDateTimeMask({\n caret: event.currentTarget.selectionStart ?? 0,\n key: event.key,\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n withTime,\n })\n commit(next.value)\n placeCaret(next.caret)\n }\n\n const handlePaste = (event: React.ClipboardEvent<HTMLInputElement>) => {\n onPaste?.(event)\n if (event.defaultPrevented || pickerOnly) return\n event.preventDefault()\n const next = applyDateTimePaste({\n caret: event.currentTarget.selectionStart ?? 0,\n pasted: event.clipboardData.getData('text'),\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n withTime,\n })\n commit(next.value)\n placeCaret(next.caret)\n }\n\n return { onKeyDown: handleKeyDown, onPaste: handlePaste }\n}\n\n/** A polite message that is read again when it repeats. */\nexport function useAnnouncement() {\n const [message, setMessage] = React.useState({ text: '', count: 0 })\n const announce = React.useCallback(\n (text: string) =>\n setMessage((current) => ({ text, count: current.count + 1 })),\n [],\n )\n // the trailing no-break space alternates, so a repeated message is new text and read again\n const region = (\n <span aria-live=\"polite\" className=\"sr-only\" data-slot=\"input-date-status\">\n {message.text}\n {message.count % 2 ? ' ' : ''}\n </span>\n )\n return [region, announce] as const\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/lib/scroll-within.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scrolls `list` so `item` shows, without scrolling the page or any other ancestor
|
|
6
|
+
* (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only
|
|
7
|
+
* scrolls when it is cut off.
|
|
8
|
+
*/
|
|
9
|
+
function scrollWithin(list, item, align = "nearest") {
|
|
10
|
+
if (!list || !item) return;
|
|
11
|
+
const listBox = list.getBoundingClientRect();
|
|
12
|
+
const itemBox = item.getBoundingClientRect();
|
|
13
|
+
const top = itemBox.top - listBox.top;
|
|
14
|
+
if (align === "center") list.scrollTop += top - (list.clientHeight - itemBox.height) / 2;
|
|
15
|
+
else if (top < 0) list.scrollTop += top;
|
|
16
|
+
else if (top + itemBox.height > list.clientHeight) list.scrollTop += top + itemBox.height - list.clientHeight;
|
|
17
|
+
}
|
|
18
|
+
/** Focuses `item` and brings it into view inside `list` only. */
|
|
19
|
+
function focusWithin(list, item) {
|
|
20
|
+
item?.focus({ preventScroll: true });
|
|
21
|
+
scrollWithin(list, item);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.focusWithin = focusWithin;
|
|
25
|
+
exports.scrollWithin = scrollWithin;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=scroll-within.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-within.cjs","names":[],"sources":["../../src/lib/scroll-within.ts"],"sourcesContent":["/**\n * Scrolls `list` so `item` shows, without scrolling the page or any other ancestor\n * (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only\n * scrolls when it is cut off.\n */\nexport function scrollWithin(\n list: HTMLElement | null,\n item: HTMLElement | null,\n align: 'center' | 'nearest' = 'nearest',\n) {\n if (!list || !item) return\n const listBox = list.getBoundingClientRect()\n const itemBox = item.getBoundingClientRect()\n const top = itemBox.top - listBox.top\n if (align === 'center') {\n list.scrollTop += top - (list.clientHeight - itemBox.height) / 2\n } else if (top < 0) {\n list.scrollTop += top\n } else if (top + itemBox.height > list.clientHeight) {\n list.scrollTop += top + itemBox.height - list.clientHeight\n }\n}\n\n/** Focuses `item` and brings it into view inside `list` only. */\nexport function focusWithin(\n list: HTMLElement | null,\n item: HTMLElement | null,\n) {\n item?.focus({ preventScroll: true })\n scrollWithin(list, item)\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,aACd,MACA,MACA,QAA8B,WAC9B;CACA,IAAI,CAAC,QAAQ,CAAC,MAAM;CACpB,MAAM,UAAU,KAAK,sBAAsB;CAC3C,MAAM,UAAU,KAAK,sBAAsB;CAC3C,MAAM,MAAM,QAAQ,MAAM,QAAQ;CAClC,IAAI,UAAU,UACZ,KAAK,aAAa,OAAO,KAAK,eAAe,QAAQ,UAAU;MAC1D,IAAI,MAAM,GACf,KAAK,aAAa;MACb,IAAI,MAAM,QAAQ,SAAS,KAAK,cACrC,KAAK,aAAa,MAAM,QAAQ,SAAS,KAAK;AAElD;;AAGA,SAAgB,YACd,MACA,MACA;CACA,MAAM,MAAM,EAAE,eAAe,KAAK,CAAC;CACnC,aAAa,MAAM,IAAI;AACzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/scroll-within.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scrolls `list` so `item` shows, without scrolling the page or any other ancestor
|
|
6
|
+
* (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only
|
|
7
|
+
* scrolls when it is cut off.
|
|
8
|
+
*/
|
|
9
|
+
declare function scrollWithin(list: HTMLElement | null, item: HTMLElement | null, align?: 'center' | 'nearest'): void;
|
|
10
|
+
/** Focuses `item` and brings it into view inside `list` only. */
|
|
11
|
+
declare function focusWithin(list: HTMLElement | null, item: HTMLElement | null): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { focusWithin, scrollWithin };
|
|
14
|
+
//# sourceMappingURL=scroll-within.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/scroll-within.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scrolls `list` so `item` shows, without scrolling the page or any other ancestor
|
|
6
|
+
* (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only
|
|
7
|
+
* scrolls when it is cut off.
|
|
8
|
+
*/
|
|
9
|
+
declare function scrollWithin(list: HTMLElement | null, item: HTMLElement | null, align?: 'center' | 'nearest'): void;
|
|
10
|
+
/** Focuses `item` and brings it into view inside `list` only. */
|
|
11
|
+
declare function focusWithin(list: HTMLElement | null, item: HTMLElement | null): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { focusWithin, scrollWithin };
|
|
14
|
+
//# sourceMappingURL=scroll-within.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/lib/scroll-within.ts
|
|
3
|
+
/**
|
|
4
|
+
* Scrolls `list` so `item` shows, without scrolling the page or any other ancestor
|
|
5
|
+
* (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only
|
|
6
|
+
* scrolls when it is cut off.
|
|
7
|
+
*/
|
|
8
|
+
function scrollWithin(list, item, align = "nearest") {
|
|
9
|
+
if (!list || !item) return;
|
|
10
|
+
const listBox = list.getBoundingClientRect();
|
|
11
|
+
const itemBox = item.getBoundingClientRect();
|
|
12
|
+
const top = itemBox.top - listBox.top;
|
|
13
|
+
if (align === "center") list.scrollTop += top - (list.clientHeight - itemBox.height) / 2;
|
|
14
|
+
else if (top < 0) list.scrollTop += top;
|
|
15
|
+
else if (top + itemBox.height > list.clientHeight) list.scrollTop += top + itemBox.height - list.clientHeight;
|
|
16
|
+
}
|
|
17
|
+
/** Focuses `item` and brings it into view inside `list` only. */
|
|
18
|
+
function focusWithin(list, item) {
|
|
19
|
+
item?.focus({ preventScroll: true });
|
|
20
|
+
scrollWithin(list, item);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { focusWithin, scrollWithin };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=scroll-within.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-within.js","names":[],"sources":["../../src/lib/scroll-within.ts"],"sourcesContent":["/**\n * Scrolls `list` so `item` shows, without scrolling the page or any other ancestor\n * (`scrollIntoView` scrolls them all). `center` puts it in the middle; `nearest` only\n * scrolls when it is cut off.\n */\nexport function scrollWithin(\n list: HTMLElement | null,\n item: HTMLElement | null,\n align: 'center' | 'nearest' = 'nearest',\n) {\n if (!list || !item) return\n const listBox = list.getBoundingClientRect()\n const itemBox = item.getBoundingClientRect()\n const top = itemBox.top - listBox.top\n if (align === 'center') {\n list.scrollTop += top - (list.clientHeight - itemBox.height) / 2\n } else if (top < 0) {\n list.scrollTop += top\n } else if (top + itemBox.height > list.clientHeight) {\n list.scrollTop += top + itemBox.height - list.clientHeight\n }\n}\n\n/** Focuses `item` and brings it into view inside `list` only. */\nexport function focusWithin(\n list: HTMLElement | null,\n item: HTMLElement | null,\n) {\n item?.focus({ preventScroll: true })\n scrollWithin(list, item)\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,aACd,MACA,MACA,QAA8B,WAC9B;CACA,IAAI,CAAC,QAAQ,CAAC,MAAM;CACpB,MAAM,UAAU,KAAK,sBAAsB;CAC3C,MAAM,UAAU,KAAK,sBAAsB;CAC3C,MAAM,MAAM,QAAQ,MAAM,QAAQ;CAClC,IAAI,UAAU,UACZ,KAAK,aAAa,OAAO,KAAK,eAAe,QAAQ,UAAU;MAC1D,IAAI,MAAM,GACf,KAAK,aAAa;MACb,IAAI,MAAM,QAAQ,SAAS,KAAK,cACrC,KAAK,aAAa,MAAM,QAAQ,SAAS,KAAK;AAElD;;AAGA,SAAgB,YACd,MACA,MACA;CACA,MAAM,MAAM,EAAE,eAAe,KAAK,CAAC;CACnC,aAAa,MAAM,IAAI;AACzB"}
|