@arshad-shah/cynosure 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/components/Accordion/Accordion.d.ts +14 -0
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Announcer/Announcer.d.ts +1 -0
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.d.ts +22 -1
- package/dist/components/AppShell/AppShell.js +95 -83
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/AppShell/index.d.ts +1 -1
- package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
- package/dist/components/AspectRatio/AspectRatio.js +21 -0
- package/dist/components/AspectRatio/AspectRatio.js.map +1 -0
- package/dist/components/AspectRatio/index.d.ts +1 -0
- package/dist/components/Avatar/Avatar.d.ts +96 -0
- package/dist/components/Avatar/Avatar.js +90 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +55 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +85 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/dist/components/Breadcrumbs/index.d.ts +1 -0
- package/dist/components/Button/Button.d.ts +13 -2
- package/dist/components/Button/Button.js +28 -26
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.d.ts +65 -7
- package/dist/components/Calendar/Calendar.js +207 -95
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Calendar/dates.d.ts +4 -0
- package/dist/components/Calendar/dates.js +41 -27
- package/dist/components/Calendar/dates.js.map +1 -1
- package/dist/components/Calendar/index.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +27 -0
- package/dist/components/Card/Card.js +48 -36
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/index.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts +8 -1
- package/dist/components/Checkbox/Checkbox.js +7 -6
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checkbox/ChoiceRow.d.ts +17 -1
- package/dist/components/Checkbox/ChoiceRow.js +19 -18
- package/dist/components/Checkbox/ChoiceRow.js.map +1 -1
- package/dist/components/Checklist/Checklist.d.ts +65 -0
- package/dist/components/Checklist/Checklist.js +163 -0
- package/dist/components/Checklist/Checklist.js.map +1 -0
- package/dist/components/Checklist/index.d.ts +1 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +5 -0
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/ColorField/ColorField.d.ts +12 -0
- package/dist/components/ColorField/ColorField.js +19 -19
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/ColorSwatches/ColorSwatches.d.ts +5 -0
- package/dist/components/ColorSwatches/ColorSwatches.js +6 -6
- package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
- package/dist/components/Combobox/Combobox.d.ts +20 -1
- package/dist/components/Combobox/Combobox.js +38 -34
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/CommandPalette/CommandPalette.d.ts +9 -0
- package/dist/components/CommandPalette/CommandPalette.js +10 -10
- package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
- package/dist/components/CompareSlider/CompareSlider.d.ts +4 -0
- package/dist/components/CompareSlider/CompareSlider.js +4 -4
- package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
- package/dist/components/Container/Container.d.ts +44 -0
- package/dist/components/Container/Container.js +24 -0
- package/dist/components/Container/Container.js.map +1 -0
- package/dist/components/Container/index.d.ts +1 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DateField/DateField.d.ts +17 -0
- package/dist/components/DateField/DateField.js +6 -6
- package/dist/components/DateField/DateField.js.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
- package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +16 -2
- package/dist/components/Dialog/Dialog.js +82 -70
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Disclosure/Disclosure.d.ts +7 -0
- package/dist/components/Disclosure/Disclosure.js.map +1 -1
- package/dist/components/Divider/Divider.d.ts +59 -0
- package/dist/components/Divider/Divider.js +32 -0
- package/dist/components/Divider/Divider.js.map +1 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/DocumentViewport/DocumentViewport.d.ts +8 -0
- package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +3 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/Field/Field.d.ts +6 -0
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/FileDrop/FileDrop.d.ts +8 -0
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +4 -0
- package/dist/components/FloatingToolbar/FloatingToolbar.js +4 -4
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +33 -7
- package/dist/components/Grid/Grid.js +46 -25
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/Grid/index.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +57 -0
- package/dist/components/Heading/Heading.js +33 -0
- package/dist/components/Heading/Heading.js.map +1 -0
- package/dist/components/Heading/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -0
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Image/Image.d.ts +62 -0
- package/dist/components/Image/Image.js +75 -0
- package/dist/components/Image/Image.js.map +1 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Inline/Inline.d.ts +7 -3
- package/dist/components/Inline/Inline.js +19 -13
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/Kbd/Kbd.d.ts +2 -0
- package/dist/components/Kbd/Kbd.js.map +1 -1
- package/dist/components/KeyValueEditor/KeyValueEditor.d.ts +7 -0
- package/dist/components/KeyValueEditor/KeyValueEditor.js +8 -8
- package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
- package/dist/components/Link/Link.d.ts +7 -0
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/LoadingDots/LoadingDots.d.ts +2 -0
- package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
- package/dist/components/Menu/Menu.d.ts +13 -1
- package/dist/components/Menu/Menu.js +37 -35
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/components/Notice/Notice.d.ts +5 -0
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/NumberField/NumberField.d.ts +17 -0
- package/dist/components/NumberField/NumberField.js +8 -8
- package/dist/components/NumberField/NumberField.js.map +1 -1
- package/dist/components/PageHeader/PageHeader.d.ts +61 -0
- package/dist/components/PageHeader/PageHeader.js +63 -0
- package/dist/components/PageHeader/PageHeader.js.map +1 -0
- package/dist/components/PageHeader/index.d.ts +1 -0
- package/dist/components/Pagination/Pagination.d.ts +77 -0
- package/dist/components/Pagination/Pagination.js +120 -0
- package/dist/components/Pagination/Pagination.js.map +1 -0
- package/dist/components/Pagination/index.d.ts +1 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +4 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
- package/dist/components/Popover/Popover.d.ts +10 -0
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/components/ProgressOverlay/ProgressOverlay.d.ts +3 -0
- package/dist/components/ProgressOverlay/ProgressOverlay.js.map +1 -1
- package/dist/components/Prose/Prose.d.ts +1 -0
- package/dist/components/Prose/Prose.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +13 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +9 -0
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.d.ts +18 -1
- package/dist/components/Select/Select.js +97 -88
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/SelectionFrame/SelectionFrame.d.ts +6 -0
- package/dist/components/SelectionFrame/SelectionFrame.js.map +1 -1
- package/dist/components/SideNav/SideNav.d.ts +37 -1
- package/dist/components/SideNav/SideNav.js +100 -73
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SideNav/index.d.ts +1 -1
- package/dist/components/SignaturePad/SignaturePad.d.ts +3 -0
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts +1 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/Slider/Slider.d.ts +11 -0
- package/dist/components/Slider/Slider.js +6 -6
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SortableList/SortableList.d.ts +6 -0
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +5 -0
- package/dist/components/SplitPane/SplitPane.js +4 -4
- package/dist/components/SplitPane/SplitPane.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +7 -3
- package/dist/components/Stack/Stack.js +18 -12
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -0
- package/dist/components/Stack/space.d.ts +18 -0
- package/dist/components/Stack/space.js +12 -0
- package/dist/components/Stack/space.js.map +1 -0
- package/dist/components/Steps/Steps.d.ts +4 -0
- package/dist/components/Steps/Steps.js.map +1 -1
- package/dist/components/Table/Table.d.ts +12 -0
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +14 -0
- package/dist/components/Tabs/Tabs.js +4 -4
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.d.ts +18 -0
- package/dist/components/TagInput/TagInput.js +5 -5
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/Text/Text.d.ts +72 -0
- package/dist/components/Text/Text.js +30 -0
- package/dist/components/Text/Text.js.map +1 -0
- package/dist/components/Text/index.d.ts +1 -0
- package/dist/components/TextArea/TextArea.d.ts +10 -0
- package/dist/components/TextArea/TextArea.js +4 -4
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +13 -0
- package/dist/components/TextField/TextField.js +4 -4
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/ThemeToggle/ThemeToggle.d.ts +4 -0
- package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
- package/dist/components/TimeField/TimeField.d.ts +62 -8
- package/dist/components/TimeField/TimeField.js +308 -72
- package/dist/components/TimeField/TimeField.js.map +1 -1
- package/dist/components/Toast/Toast.d.ts +25 -1
- package/dist/components/Toast/Toast.js +134 -125
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tree/Tree.d.ts +8 -0
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList/VirtualList.js +4 -4
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/ZoomControls/ZoomControls.d.ts +4 -0
- package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
- package/dist/foundations/ChoiceBase/ChoiceBase.d.ts +1 -0
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/HiddenValue/HiddenValue.d.ts +3 -0
- package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
- package/dist/foundations/Icon/Icon.d.ts +3 -0
- package/dist/foundations/Icon/Icon.js.map +1 -1
- package/dist/foundations/image-outcome.d.ts +15 -0
- package/dist/foundations/image-outcome.js +39 -0
- package/dist/foundations/image-outcome.js.map +1 -0
- package/dist/foundations/option-icon.d.ts +26 -0
- package/dist/foundations/option-icon.js +16 -0
- package/dist/foundations/option-icon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +476 -474
- package/dist/icons/keywords.d.ts +249 -0
- package/dist/icons/keywords.js +1728 -0
- package/dist/icons/keywords.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.js +240 -213
- package/dist/styles/aspect-ratio.css +1 -0
- package/dist/styles/avatar.css +1 -0
- package/dist/styles/breadcrumbs.css +1 -0
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/checklist.css +1 -0
- package/dist/styles/container.css +1 -0
- package/dist/styles/divider.css +1 -0
- package/dist/styles/generated-css.d.ts +1 -1
- package/dist/styles/generated-css.js +1 -1
- package/dist/styles/generated-css.js.map +1 -1
- package/dist/styles/grid.css +1 -1
- package/dist/styles/heading.css +1 -0
- package/dist/styles/image.css +1 -0
- package/dist/styles/menu.css +1 -1
- package/dist/styles/page-header.css +1 -0
- package/dist/styles/pagination.css +1 -0
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/stack.css +1 -1
- package/dist/styles/text.css +1 -0
- package/dist/styles/time-field.css +1 -1
- package/dist/styles/toast.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme/CynosureTheme.d.ts +4 -0
- package/dist/theme/CynosureTheme.js.map +1 -1
- package/dist/tokens/to-css.js +12 -12
- package/dist/tokens/to-css.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","names":["_Fragment","closeIcon","Icon","useClientLayoutEffect","Button","IconButton","close","ToastHostContext","TONE_ICONS","createContext","useCallback","useContext","useEffect","useId","useMemo","useRef","useState","Fragment$1","jsx","jsxs","createPortal","DEFAULT_LABELS","SWIPE","ToastContext","useToast","api","Toaster","position","max","labels","className","style","children","text","prefix","count","items","setItems","hovered","setHovered","focused","setFocused","hidden","setHidden","region","memory","hosts","setHosts","registry","el","list","h","host","remove","id","t","dismiss","active","holder","others","next","button","toast","options","onVisibility","live","shown","paused","regionEl","e","item","ToastItem","collapsed","dismissLabel","onDismiss","onRemoved","title","description","tone","action","duration","leaving","mem","found","announcedBefore","drag","ready","setReady","started","left","node","ms","endSwipe","event","start","icon"],"sources":["../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import {\n type CSSProperties,\n createContext,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { TONE_ICONS } from \"../../foundations/tone-icons.js\";\nimport { close as closeIcon } from \"../../icons/close.js\";\nimport { ToastHostContext, type ToastHostRegistry } from \"../../overlay/toast-host.js\";\nimport type { Tone } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\n\nexport interface ToastTokens {\n width: string;\n radius: string;\n padding: string;\n gap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n toast: ToastTokens;\n }\n}\n\nexport type ToastTone = Extract<Tone, \"neutral\" | \"success\" | \"danger\" | \"warning\" | \"info\">;\n\nexport interface ToastOptions {\n title: string;\n description?: string;\n /** Colour and icon. `danger` is announced assertively (`role=\"alert\"`); the others politely. */\n tone?: ToastTone;\n /** One button in the toast. It does not close the toast unless `onClick` dismisses it. */\n action?: { label: string; onClick: () => void };\n /** Milliseconds before it closes itself (default 5000). `Infinity` keeps it until dismissed. */\n duration?: number;\n}\n\nexport interface ToastApi {\n /** Shows a toast and returns its id. */\n toast: (options: ToastOptions) => string;\n /** Closes one toast, or all of them without an id. */\n dismiss: (id?: string) => void;\n}\n\nexport type ToastPosition =\n | \"top-start\"\n | \"top-center\"\n | \"top-end\"\n | \"bottom-start\"\n | \"bottom-center\"\n | \"bottom-end\";\n\nexport interface ToastLabels {\n /** Name of the notifications region. */\n region: string;\n /** Accessible name of each toast's close button. */\n dismiss: string;\n}\n\nexport interface ToasterProps {\n /** Where toasts stack. `start`/`end` follow the reading direction. */\n position?: ToastPosition;\n /** How many show at once; older ones collapse until newer ones close. */\n max?: number;\n labels?: Partial<ToastLabels>;\n className?: string;\n /** Layout only, applied to the region. Restyle through --cy-toast-* tokens. */\n style?: CSSProperties;\n /** The part of the app that can call `useToast()`. */\n children?: ReactNode;\n}\n\ninterface Item extends ToastOptions {\n id: string;\n leaving?: boolean;\n}\n\nconst DEFAULT_LABELS: ToastLabels = { region: \"Notifications\", dismiss: \"Dismiss\" };\n/** Horizontal distance a touch has to travel to swipe a toast away. */\nconst SWIPE = 64;\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\n/** `toast()` and `dismiss()` for the nearest `<Toaster>`. */\nexport function useToast(): ToastApi {\n const api = useContext(ToastContext);\n if (!api) throw new Error(\"useToast() needs a <Toaster> around it.\");\n return api;\n}\n\ntype RegionEl = HTMLElement & { showPopover?: () => void; hidePopover?: () => void };\n\n/** What a toast keeps when its element is re-created (the region moved into or out of a Dialog). */\ninterface Memory {\n announced: boolean;\n remaining?: number;\n}\ntype MemoryMap = Map<string, Memory>;\n\n/**\n * Hosts toasts for everything inside it: a region in the top layer, a store per Toaster (no globals), timers that pause\n * while the pointer or focus is on a toast, and polite or assertive announcements.\n */\nexport function Toaster({\n position = \"bottom-end\",\n max = 3,\n labels,\n className,\n style,\n children,\n}: ToasterProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const prefix = useId();\n const count = useRef(0);\n const [items, setItems] = useState<Item[]>([]);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const [hidden, setHidden] = useState(false);\n const region = useRef<RegionEl>(null);\n const memory = useRef<MemoryMap>(new Map());\n // Containers lent by open modal Dialogs; the latest one hosts the region.\n const [hosts, setHosts] = useState<HTMLElement[]>([]);\n const registry = useMemo<ToastHostRegistry>(\n () => ({\n register: (el) => {\n setHosts((list) => [...list, el]);\n return () => setHosts((list) => list.filter((h) => h !== el));\n },\n }),\n [],\n );\n const host = hosts.at(-1) ?? null;\n\n const remove = useCallback((id: string) => {\n memory.current.delete(id);\n setItems((list) => list.filter((t) => t.id !== id));\n }, []);\n const dismiss = useCallback((id?: string) => {\n // Closing the toast that holds focus (its close button, from the keyboard): hand focus to the next toast's close\n // button, or let the region stop pausing if there is none.\n const active = region.current?.ownerDocument.activeElement;\n const holder = active?.closest<HTMLElement>(\".cy-toast\");\n if (holder && region.current?.contains(holder) && (id === undefined || holder.dataset.id === id)) {\n const others = [\n ...region.current.querySelectorAll<HTMLElement>(\n \".cy-toast:not([data-collapsed]):not([data-leaving])\",\n ),\n ];\n const next = id === undefined ? undefined : others.find((t) => t !== holder);\n const button = next ? [...next.querySelectorAll<HTMLElement>(\"button\")].at(-1) : undefined;\n if (button) button.focus();\n else {\n (active as HTMLElement).blur();\n setFocused(false);\n }\n }\n setItems((list) => list.map((t) => (id === undefined || t.id === id ? { ...t, leaving: true } : t)));\n }, []);\n const toast = useCallback(\n (options: ToastOptions) => {\n count.current += 1;\n const id = `${prefix}-${count.current}`;\n setItems((list) => [...list, { ...options, id }]);\n return id;\n },\n [prefix],\n );\n const api = useMemo<ToastApi>(() => ({ toast, dismiss }), [toast, dismiss]);\n\n // The region lives in the top layer for as long as the Toaster is mounted, so live regions exist before content.\n // It is re-created when it moves into or out of a Dialog; showing it again puts it on top of that dialog.\n useClientLayoutEffect(() => {\n const el = region.current;\n el?.showPopover?.();\n return () => {\n if (el?.matches(\":popover-open\")) el.hidePopover?.();\n };\n }, [host]);\n useEffect(() => {\n const onVisibility = () => setHidden(document.visibilityState === \"hidden\");\n document.addEventListener(\"visibilitychange\", onVisibility);\n return () => document.removeEventListener(\"visibilitychange\", onVisibility);\n }, []);\n // Focus left the region entirely (a toast closing with focus inside also counts).\n useEffect(() => {\n if (focused && !items.some((t) => !t.leaving)) setFocused(false);\n }, [focused, items]);\n\n const live = items.filter((t) => !t.leaving);\n const shown = new Set(live.slice(-max).map((t) => t.id));\n const paused = hovered || focused || hidden;\n\n const regionEl = (\n <section\n ref={region}\n aria-label={text.region}\n {...{ popover: \"manual\" }}\n className={className ? `cy-toaster ${className}` : \"cy-toaster\"}\n data-position={position}\n style={style}\n onPointerEnter={() => setHovered(true)}\n onPointerLeave={() => setHovered(false)}\n onFocus={() => setFocused(true)}\n onBlur={(e) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n }}\n >\n {items.map((item) => (\n <ToastItem\n key={item.id}\n item={item}\n collapsed={!item.leaving && !shown.has(item.id)}\n paused={paused}\n dismissLabel={text.dismiss}\n onDismiss={dismiss}\n onRemoved={remove}\n memory={memory.current}\n />\n ))}\n </section>\n );\n\n return (\n <ToastContext.Provider value={api}>\n <ToastHostContext.Provider value={registry}>{children}</ToastHostContext.Provider>\n {host ? createPortal(regionEl, host) : regionEl}\n </ToastContext.Provider>\n );\n}\n\ninterface ToastItemProps {\n item: Item;\n collapsed: boolean;\n paused: boolean;\n dismissLabel: string;\n onDismiss: (id: string) => void;\n onRemoved: (id: string) => void;\n memory: MemoryMap;\n}\n\nfunction ToastItem({ item, collapsed, paused, dismissLabel, onDismiss, onRemoved, memory }: ToastItemProps) {\n const { id, title, description, tone = \"neutral\", action, duration = 5000, leaving = false } = item;\n const el = useRef<HTMLDivElement>(null);\n // Survives the element being re-created (region moved into or out of a Dialog).\n const [mem] = useState<Memory>(() => {\n const found = memory.get(id) ?? { announced: false };\n memory.set(id, found);\n return found;\n });\n const [announcedBefore] = useState(mem.announced);\n const drag = useRef<{ x: number; pointer: number } | null>(null);\n // The live element exists (empty) first and its text arrives a moment later: screen readers announce text added to\n // a live region, and the text is added once, so the toast is announced once.\n // Already announced (re-created after a move): show the text at once, so nothing is inserted to announce again.\n const [ready, setReady] = useState(mem.announced);\n useEffect(() => {\n if (ready) return;\n const t = setTimeout(() => {\n mem.announced = true;\n setReady(true);\n }, 50);\n return () => clearTimeout(t);\n }, [ready, mem]);\n\n // Collapsed and leaving toasts cannot be focused or clicked. Set as a property: React 18 drops `inert={true}`.\n useClientLayoutEffect(() => {\n if (el.current) el.current.inert = collapsed || leaving;\n }, [collapsed, leaving]);\n\n // Auto-dismiss, keeping the time already spent across pauses and moves. The time left lives in `mem`, read when the\n // timer starts: a re-created toast's effects run after the old one has saved it.\n useEffect(() => {\n if (paused || collapsed || leaving || !Number.isFinite(duration) || duration <= 0) return;\n const started = Date.now();\n const left = mem.remaining ?? duration;\n const t = setTimeout(() => onDismiss(id), Math.max(left, 0));\n return () => {\n clearTimeout(t);\n mem.remaining = left - (Date.now() - started);\n };\n }, [paused, collapsed, leaving, duration, id, onDismiss, mem]);\n\n // Leaving: play the exit transition (none under reduced motion), then drop it from the store.\n useEffect(() => {\n if (!leaving) return;\n const node = el.current;\n const ms = node ? Number.parseFloat(getComputedStyle(node).transitionDuration) * 1000 || 0 : 0;\n const t = setTimeout(() => onRemoved(id), ms);\n return () => clearTimeout(t);\n }, [leaving, id, onRemoved]);\n\n const endSwipe = (event: PointerEvent<HTMLDivElement>) => {\n const start = drag.current;\n if (!start || start.pointer !== event.pointerId) return;\n drag.current = null;\n const node = event.currentTarget;\n delete node.dataset.swiping;\n if (Math.abs(event.clientX - start.x) >= SWIPE) onDismiss(id);\n else node.style.removeProperty(\"--_dx\");\n };\n\n const icon = TONE_ICONS[tone];\n return (\n <div\n ref={el}\n // An alert announces whenever it appears; one already announced comes back as a status.\n role={tone === \"danger\" && !announcedBefore ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n className=\"cy-toast\"\n data-id={id}\n data-tone={tone}\n data-collapsed={collapsed || undefined}\n data-leaving={leaving || undefined}\n onPointerDown={(event) => {\n if (event.pointerType !== \"touch\") return;\n drag.current = { x: event.clientX, pointer: event.pointerId };\n }}\n onPointerMove={(event) => {\n const start = drag.current;\n if (!start || start.pointer !== event.pointerId) return;\n event.currentTarget.dataset.swiping = \"\";\n event.currentTarget.style.setProperty(\"--_dx\", `${event.clientX - start.x}px`);\n }}\n onPointerUp={endSwipe}\n onPointerCancel={(event) => {\n // The browser took the gesture (a scroll): spring back, never dismiss.\n drag.current = null;\n delete event.currentTarget.dataset.swiping;\n event.currentTarget.style.removeProperty(\"--_dx\");\n }}\n >\n {icon && <Icon icon={icon} className=\"cy-toast-icon\" />}\n <div className=\"cy-toast-text cy-reset\">\n {ready && (\n <>\n <span className=\"cy-toast-title cy-reset\">{title}</span>\n {description && <span className=\"cy-toast-description cy-reset\">{description}</span>}\n </>\n )}\n </div>\n {action && (\n <Button size=\"sm\" variant=\"soft\" tone={tone === \"neutral\" ? \"accent\" : tone} onClick={action.onClick}>\n {action.label}\n </Button>\n )}\n <IconButton\n icon={closeIcon}\n label={dismissLabel}\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => onDismiss(id)}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAyFA,IAAMqB,KAA8B;AAAA,EAAE,QAAQ;AAAA,EAAiB,SAAS;AAAU,GAE5EC,KAAQ,IAERC,IAAed,EAA+B,IAAI;AAGxD,SAAgBe,KAAqB;AACnC,QAAMC,IAAMd,GAAWY,CAAY;AACnC,MAAI,CAACE,EAAK,O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AAAA,QACL,SAAA,MAAeC,EAAUpB,CAAE;AAAA,MAC5B,CAAA;AAAA,IACE;AAAA,E;AAET"}
|
|
1
|
+
{"version":3,"file":"Toast.js","names":["_Fragment","closeIcon","Icon","useClientLayoutEffect","Button","IconButton","close","ToastHostContext","space","TONE_ICONS","createContext","useCallback","useContext","useEffect","useId","useMemo","useRef","useState","Fragment$1","jsx","jsxs","createPortal","DEFAULT_LABELS","SWIPE","length","value","offsetVars","offset","block","inline","vars","ToastContext","useToast","api","Toaster","position","max","labels","className","style","children","text","prefix","count","items","setItems","hovered","setHovered","focused","setFocused","hidden","setHidden","region","memory","hosts","setHosts","registry","el","list","h","host","remove","id","t","dismiss","active","holder","others","next","button","toast","options","onVisibility","live","shown","paused","regionEl","e","item","ToastItem","collapsed","dismissLabel","onDismiss","onRemoved","title","description","tone","action","duration","leaving","mem","found","announcedBefore","drag","ready","setReady","started","left","node","ms","endSwipe","event","start","icon"],"sources":["../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import {\n type CSSProperties,\n createContext,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { TONE_ICONS } from \"../../foundations/tone-icons.js\";\nimport { close as closeIcon } from \"../../icons/close.js\";\nimport { ToastHostContext, type ToastHostRegistry } from \"../../overlay/toast-host.js\";\nimport type { Tone } from \"../../tokens/schema.js\";\nimport { Button } from \"../Button/Button.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { type Space, space } from \"../Stack/space.js\";\n\nexport interface ToastTokens {\n width: string;\n radius: string;\n padding: string;\n gap: string;\n /** Extra distance between the toasts and the top or bottom edge they sit on (a fixed tab bar or header). */\n offsetBlock: string;\n /** Extra distance between the toasts and the side they sit on (a fixed side rail). */\n offsetInline: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n toast: ToastTokens;\n }\n}\n\nexport type ToastTone = Extract<Tone, \"neutral\" | \"success\" | \"danger\" | \"warning\" | \"info\">;\n\nexport interface ToastOptions {\n title: string;\n description?: string;\n /** Colour and icon. `danger` is announced assertively (`role=\"alert\"`); the others politely. */\n tone?: ToastTone;\n /** One button in the toast. It does not close the toast unless `onClick` dismisses it. */\n action?: { label: string; onClick: () => void };\n /** Milliseconds before it closes itself (default 5000). `Infinity` keeps it until dismissed. */\n duration?: number;\n}\n\nexport interface ToastApi {\n /** Shows a toast and returns its id. */\n toast: (options: ToastOptions) => string;\n /** Closes one toast, or all of them without an id. */\n dismiss: (id?: string) => void;\n}\n\nexport type ToastPosition =\n | \"top-start\"\n | \"top-center\"\n | \"top-end\"\n | \"bottom-start\"\n | \"bottom-center\"\n | \"bottom-end\";\n\n/** A distance: a step of the space scale (`\"6\"` is `--cy-space-6`) or any CSS length (`\"72px\"`, `\"calc(56px + 1rem)\"`). */\nexport type ToastOffsetLength = Space | (string & {});\n\n/** How far in from their edges the toasts sit, for each axis. */\nexport interface ToastOffset {\n /** From the top or bottom edge, whichever `position` names. */\n block?: ToastOffsetLength | undefined;\n /** From the side `position` names (both sides for `center`). Follows the reading direction. */\n inline?: ToastOffsetLength | undefined;\n}\n\nexport interface ToastLabels {\n /** Name of the notifications region. */\n region: string;\n /** Accessible name of each toast's close button. */\n dismiss: string;\n}\n\nexport interface ToasterProps {\n /** Where toasts stack. `start`/`end` follow the reading direction. */\n position?: ToastPosition;\n /** How many show at once; older ones collapse until newer ones close. */\n max?: number;\n /**\n * Keeps the toasts clear of fixed parts of the app, such as a bottom tab bar: extra distance from the edge they sit\n * on, added to the usual margin and the device's safe area. A step of the space scale (`\"8\"`) or a CSS length\n * (`\"72px\"`) moves them in from the top or bottom edge; `{ block, inline }` sets that and the distance from the\n * side. To set it from CSS instead (only below a breakpoint, say) use the `--cy-toast-offset-block` and\n * `--cy-toast-offset-inline` tokens; this prop wins over them. Default: none.\n */\n offset?: ToastOffsetLength | ToastOffset | undefined;\n /** Replace the built-in English text: the region's name and the close button's name. */\n labels?: Partial<ToastLabels>;\n /** Added to the notifications region, for layout. */\n className?: string;\n /** Layout only, applied to the region. Restyle through --cy-toast-* tokens. */\n style?: CSSProperties;\n /** The part of the app that can call `useToast()`. */\n children?: ReactNode;\n}\n\ninterface Item extends ToastOptions {\n id: string;\n leaving?: boolean;\n}\n\nconst DEFAULT_LABELS: ToastLabels = { region: \"Notifications\", dismiss: \"Dismiss\" };\n/** Horizontal distance a touch has to travel to swipe a toast away. */\nconst SWIPE = 64;\n\nconst length = (value: ToastOffsetLength) => (/^(\\d|10)$/.test(value) ? space(value as Space) : value);\n/** The private custom properties toast.css reads the `offset` prop from; an axis that is not set is left to the token. */\nfunction offsetVars(offset: ToasterProps[\"offset\"]) {\n const { block, inline }: ToastOffset = typeof offset === \"object\" ? offset : { block: offset };\n const vars: Record<string, string> = {};\n if (block) vars[\"--_offset-block\"] = length(block);\n if (inline) vars[\"--_offset-inline\"] = length(inline);\n return vars;\n}\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\n/** `toast()` and `dismiss()` for the nearest `<Toaster>`. */\nexport function useToast(): ToastApi {\n const api = useContext(ToastContext);\n if (!api) throw new Error(\"useToast() needs a <Toaster> around it.\");\n return api;\n}\n\ntype RegionEl = HTMLElement & { showPopover?: () => void; hidePopover?: () => void };\n\n/** What a toast keeps when its element is re-created (the region moved into or out of a Dialog). */\ninterface Memory {\n announced: boolean;\n remaining?: number;\n}\ntype MemoryMap = Map<string, Memory>;\n\n/**\n * Hosts toasts for everything inside it: a region in the top layer, a store per Toaster (no globals), timers that pause\n * while the pointer or focus is on a toast, and polite or assertive announcements.\n */\nexport function Toaster({\n position = \"bottom-end\",\n max = 3,\n offset,\n labels,\n className,\n style,\n children,\n}: ToasterProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const prefix = useId();\n const count = useRef(0);\n const [items, setItems] = useState<Item[]>([]);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const [hidden, setHidden] = useState(false);\n const region = useRef<RegionEl>(null);\n const memory = useRef<MemoryMap>(new Map());\n // Containers lent by open modal Dialogs; the latest one hosts the region.\n const [hosts, setHosts] = useState<HTMLElement[]>([]);\n const registry = useMemo<ToastHostRegistry>(\n () => ({\n register: (el) => {\n setHosts((list) => [...list, el]);\n return () => setHosts((list) => list.filter((h) => h !== el));\n },\n }),\n [],\n );\n const host = hosts.at(-1) ?? null;\n\n const remove = useCallback((id: string) => {\n memory.current.delete(id);\n setItems((list) => list.filter((t) => t.id !== id));\n }, []);\n const dismiss = useCallback((id?: string) => {\n // Closing the toast that holds focus (its close button, from the keyboard): hand focus to the next toast's close\n // button, or let the region stop pausing if there is none.\n const active = region.current?.ownerDocument.activeElement;\n const holder = active?.closest<HTMLElement>(\".cy-toast\");\n if (holder && region.current?.contains(holder) && (id === undefined || holder.dataset.id === id)) {\n const others = [\n ...region.current.querySelectorAll<HTMLElement>(\n \".cy-toast:not([data-collapsed]):not([data-leaving])\",\n ),\n ];\n const next = id === undefined ? undefined : others.find((t) => t !== holder);\n const button = next ? [...next.querySelectorAll<HTMLElement>(\"button\")].at(-1) : undefined;\n if (button) button.focus();\n else {\n (active as HTMLElement).blur();\n setFocused(false);\n }\n }\n setItems((list) => list.map((t) => (id === undefined || t.id === id ? { ...t, leaving: true } : t)));\n }, []);\n const toast = useCallback(\n (options: ToastOptions) => {\n count.current += 1;\n const id = `${prefix}-${count.current}`;\n setItems((list) => [...list, { ...options, id }]);\n return id;\n },\n [prefix],\n );\n const api = useMemo<ToastApi>(() => ({ toast, dismiss }), [toast, dismiss]);\n\n // The region lives in the top layer for as long as the Toaster is mounted, so live regions exist before content.\n // It is re-created when it moves into or out of a Dialog; showing it again puts it on top of that dialog.\n useClientLayoutEffect(() => {\n const el = region.current;\n el?.showPopover?.();\n return () => {\n if (el?.matches(\":popover-open\")) el.hidePopover?.();\n };\n }, [host]);\n useEffect(() => {\n const onVisibility = () => setHidden(document.visibilityState === \"hidden\");\n document.addEventListener(\"visibilitychange\", onVisibility);\n return () => document.removeEventListener(\"visibilitychange\", onVisibility);\n }, []);\n // Focus left the region entirely (a toast closing with focus inside also counts).\n useEffect(() => {\n if (focused && !items.some((t) => !t.leaving)) setFocused(false);\n }, [focused, items]);\n\n const live = items.filter((t) => !t.leaving);\n const shown = new Set(live.slice(-max).map((t) => t.id));\n const paused = hovered || focused || hidden;\n\n const regionEl = (\n <section\n ref={region}\n aria-label={text.region}\n {...{ popover: \"manual\" }}\n className={className ? `cy-toaster ${className}` : \"cy-toaster\"}\n data-position={position}\n style={{ ...offsetVars(offset), ...style }}\n onPointerEnter={() => setHovered(true)}\n onPointerLeave={() => setHovered(false)}\n onFocus={() => setFocused(true)}\n onBlur={(e) => {\n if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n }}\n >\n {items.map((item) => (\n <ToastItem\n key={item.id}\n item={item}\n collapsed={!item.leaving && !shown.has(item.id)}\n paused={paused}\n dismissLabel={text.dismiss}\n onDismiss={dismiss}\n onRemoved={remove}\n memory={memory.current}\n />\n ))}\n </section>\n );\n\n return (\n <ToastContext.Provider value={api}>\n <ToastHostContext.Provider value={registry}>{children}</ToastHostContext.Provider>\n {host ? createPortal(regionEl, host) : regionEl}\n </ToastContext.Provider>\n );\n}\n\ninterface ToastItemProps {\n item: Item;\n collapsed: boolean;\n paused: boolean;\n dismissLabel: string;\n onDismiss: (id: string) => void;\n onRemoved: (id: string) => void;\n memory: MemoryMap;\n}\n\nfunction ToastItem({ item, collapsed, paused, dismissLabel, onDismiss, onRemoved, memory }: ToastItemProps) {\n const { id, title, description, tone = \"neutral\", action, duration = 5000, leaving = false } = item;\n const el = useRef<HTMLDivElement>(null);\n // Survives the element being re-created (region moved into or out of a Dialog).\n const [mem] = useState<Memory>(() => {\n const found = memory.get(id) ?? { announced: false };\n memory.set(id, found);\n return found;\n });\n const [announcedBefore] = useState(mem.announced);\n const drag = useRef<{ x: number; pointer: number } | null>(null);\n // The live element exists (empty) first and its text arrives a moment later: screen readers announce text added to\n // a live region, and the text is added once, so the toast is announced once.\n // Already announced (re-created after a move): show the text at once, so nothing is inserted to announce again.\n const [ready, setReady] = useState(mem.announced);\n useEffect(() => {\n if (ready) return;\n const t = setTimeout(() => {\n mem.announced = true;\n setReady(true);\n }, 50);\n return () => clearTimeout(t);\n }, [ready, mem]);\n\n // Collapsed and leaving toasts cannot be focused or clicked. Set as a property: React 18 drops `inert={true}`.\n useClientLayoutEffect(() => {\n if (el.current) el.current.inert = collapsed || leaving;\n }, [collapsed, leaving]);\n\n // Auto-dismiss, keeping the time already spent across pauses and moves. The time left lives in `mem`, read when the\n // timer starts: a re-created toast's effects run after the old one has saved it.\n useEffect(() => {\n if (paused || collapsed || leaving || !Number.isFinite(duration) || duration <= 0) return;\n const started = Date.now();\n const left = mem.remaining ?? duration;\n const t = setTimeout(() => onDismiss(id), Math.max(left, 0));\n return () => {\n clearTimeout(t);\n mem.remaining = left - (Date.now() - started);\n };\n }, [paused, collapsed, leaving, duration, id, onDismiss, mem]);\n\n // Leaving: play the exit transition (none under reduced motion), then drop it from the store.\n useEffect(() => {\n if (!leaving) return;\n const node = el.current;\n const ms = node ? Number.parseFloat(getComputedStyle(node).transitionDuration) * 1000 || 0 : 0;\n const t = setTimeout(() => onRemoved(id), ms);\n return () => clearTimeout(t);\n }, [leaving, id, onRemoved]);\n\n const endSwipe = (event: PointerEvent<HTMLDivElement>) => {\n const start = drag.current;\n if (!start || start.pointer !== event.pointerId) return;\n drag.current = null;\n const node = event.currentTarget;\n delete node.dataset.swiping;\n if (Math.abs(event.clientX - start.x) >= SWIPE) onDismiss(id);\n else node.style.removeProperty(\"--_dx\");\n };\n\n const icon = TONE_ICONS[tone];\n return (\n <div\n ref={el}\n // An alert announces whenever it appears; one already announced comes back as a status.\n role={tone === \"danger\" && !announcedBefore ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n className=\"cy-toast\"\n data-id={id}\n data-tone={tone}\n data-collapsed={collapsed || undefined}\n data-leaving={leaving || undefined}\n onPointerDown={(event) => {\n if (event.pointerType !== \"touch\") return;\n drag.current = { x: event.clientX, pointer: event.pointerId };\n }}\n onPointerMove={(event) => {\n const start = drag.current;\n if (!start || start.pointer !== event.pointerId) return;\n event.currentTarget.dataset.swiping = \"\";\n event.currentTarget.style.setProperty(\"--_dx\", `${event.clientX - start.x}px`);\n }}\n onPointerUp={endSwipe}\n onPointerCancel={(event) => {\n // The browser took the gesture (a scroll): spring back, never dismiss.\n drag.current = null;\n delete event.currentTarget.dataset.swiping;\n event.currentTarget.style.removeProperty(\"--_dx\");\n }}\n >\n {icon && <Icon icon={icon} className=\"cy-toast-icon\" />}\n <div className=\"cy-toast-text cy-reset\">\n {ready && (\n <>\n <span className=\"cy-toast-title cy-reset\">{title}</span>\n {description && <span className=\"cy-toast-description cy-reset\">{description}</span>}\n </>\n )}\n </div>\n {action && (\n <Button size=\"sm\" variant=\"soft\" tone={tone === \"neutral\" ? \"accent\" : tone} onClick={action.onClick}>\n {action.label}\n </Button>\n )}\n <IconButton\n icon={closeIcon}\n label={dismissLabel}\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => onDismiss(id)}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAmHA,IAAMsB,KAA8B;AAAA,EAAE,QAAQ;AAAA,EAAiB,SAAS;AAAU,GAE5EC,KAAQ,IAERC,IAAA,CAAUC,MAA8B,YAAY,KAAKA,CAAK,IAAIjB,GAAMiB,CAAc,IAAIA;AAEhG,SAASC,GAAWC,GAAgC;AAClD,QAAM,EAAE,OAAAC,GAAO,QAAAC,EAAA,IAAwB,OAAOF,KAAW,WAAWA,IAAS,EAAE,OAAOA,EAAO,GACvFG,IAA+B,CAAC;AACtC,SAAIF,MAAOE,EAAK,iBAAA,IAAqBN,EAAOI,CAAK,IAC7CC,MAAQC,EAAK,kBAAA,IAAsBN,EA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AQ;AAAA,QAAO,MAAMkF,MAAS,YAAY,WAAWA;AAAA,QAAM,SAASC,EAAO;AAAA,QAC1F,UAAAA,EAAO;AAAA,MACF,CAAA;AAAA,MAEV,gBAAApE,EAACd,GAAD;AAAA,QACE,MAAMJ;AAAAA,QACN,OAAOgF;AAAA,QACP,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,SAAA,MAAeC,EAAUpB,CAAE;AAAA,MAC5B,CAAA;AAAA,IACE;AAAA,E;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type ToastApi, Toaster, type ToasterProps, type ToastLabels, type ToastOptions, type ToastPosition, type ToastTokens, type ToastTone, useToast, } from "./Toast.js";
|
|
1
|
+
export { type ToastApi, Toaster, type ToasterProps, type ToastLabels, type ToastOffset, type ToastOffsetLength, type ToastOptions, type ToastPosition, type ToastTokens, type ToastTone, useToast, } from "./Toast.js";
|
|
@@ -2,14 +2,17 @@ import { type CSSProperties, type ReactNode } from "react";
|
|
|
2
2
|
export interface ToolbarProps {
|
|
3
3
|
/** Accessible name (required: a toolbar must be named). */
|
|
4
4
|
label: string;
|
|
5
|
+
/** Direction of the toolbar: Left/Right move between controls, or Up/Down when vertical. Default "horizontal". */
|
|
5
6
|
orientation?: "horizontal" | "vertical";
|
|
6
7
|
/** Arrow keys wrap from the last item to the first. */
|
|
7
8
|
loop?: boolean;
|
|
9
|
+
/** Added to the root element, for layout. */
|
|
8
10
|
className?: string;
|
|
9
11
|
/** Layout only. */
|
|
10
12
|
style?: CSSProperties;
|
|
11
13
|
/** Buttons, IconButtons, SegmentedControls, fields. */
|
|
12
14
|
children?: ReactNode;
|
|
15
|
+
/** Test id, set on the toolbar element. */
|
|
13
16
|
"data-testid"?: string;
|
|
14
17
|
}
|
|
15
18
|
/** APG toolbar: one Tab stop; arrow keys move between controls (RTL aware), Home and End jump. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.js","names":["useRovingFocus","useRef","jsx","ITEMS","Toolbar","label","orientation","loop","className","style","children","rest","ref"],"sources":["../../../src/components/Toolbar/Toolbar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useRef } from \"react\";\nimport { useRovingFocus } from \"../../foundations/roving-focus.js\";\n\nexport interface ToolbarProps {\n /** Accessible name (required: a toolbar must be named). */\n label: string;\n orientation?: \"horizontal\" | \"vertical\";\n /** Arrow keys wrap from the last item to the first. */\n loop?: boolean;\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** Buttons, IconButtons, SegmentedControls, fields. */\n children?: ReactNode;\n \"data-testid\"?: string;\n}\n\n/** Every focusable control inside joins the roving group (hidden form proxies excluded). */\nconst ITEMS =\n 'button, a[href], textarea, input:not([type=\"hidden\"]):not([aria-hidden=\"true\"]), [data-roving]';\n\n/** APG toolbar: one Tab stop; arrow keys move between controls (RTL aware), Home and End jump. */\nexport function Toolbar({\n label,\n orientation = \"horizontal\",\n loop = true,\n className,\n style,\n children,\n ...rest\n}: ToolbarProps) {\n const ref = useRef<HTMLDivElement>(null);\n useRovingFocus(ref, { orientation, loop, selector: ITEMS });\n return (\n <div\n ref={ref}\n {...rest}\n role=\"toolbar\"\n aria-label={label}\n aria-orientation={orientation}\n className={className ? `cy-toolbar ${className}` : \"cy-toolbar\"}\n style={style}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"Toolbar.js","names":["useRovingFocus","useRef","jsx","ITEMS","Toolbar","label","orientation","loop","className","style","children","rest","ref"],"sources":["../../../src/components/Toolbar/Toolbar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useRef } from \"react\";\nimport { useRovingFocus } from \"../../foundations/roving-focus.js\";\n\nexport interface ToolbarProps {\n /** Accessible name (required: a toolbar must be named). */\n label: string;\n /** Direction of the toolbar: Left/Right move between controls, or Up/Down when vertical. Default \"horizontal\". */\n orientation?: \"horizontal\" | \"vertical\";\n /** Arrow keys wrap from the last item to the first. */\n loop?: boolean;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** Buttons, IconButtons, SegmentedControls, fields. */\n children?: ReactNode;\n /** Test id, set on the toolbar element. */\n \"data-testid\"?: string;\n}\n\n/** Every focusable control inside joins the roving group (hidden form proxies excluded). */\nconst ITEMS =\n 'button, a[href], textarea, input:not([type=\"hidden\"]):not([aria-hidden=\"true\"]), [data-roving]';\n\n/** APG toolbar: one Tab stop; arrow keys move between controls (RTL aware), Home and End jump. */\nexport function Toolbar({\n label,\n orientation = \"horizontal\",\n loop = true,\n className,\n style,\n children,\n ...rest\n}: ToolbarProps) {\n const ref = useRef<HTMLDivElement>(null);\n useRovingFocus(ref, { orientation, loop, selector: ITEMS });\n return (\n <div\n ref={ref}\n {...rest}\n role=\"toolbar\"\n aria-label={label}\n aria-orientation={orientation}\n className={className ? `cy-toolbar ${className}` : \"cy-toolbar\"}\n style={style}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";;;;AAqBA,IAAMG,IACJ;AAGF,SAAgBC,EAAQ,EACtB,OAAAC,GACA,aAAAC,IAAc,cACd,MAAAC,IAAO,IACP,WAAAC,GACA,OAAAC,GACA,UAAAC,GACA,GAAGC,EAAA,GACY;AACf,QAAMC,IAAMX,EAAuB,IAAI;AACvC,SAAAD,EAAeY,GAAK;AAAA,IAAE,aAAAN;AAAA,IAAa,MAAAC;AAAA,IAAM,UAAUJ;AAAA,EAAM,CAAC,GAExD,gBAAAD,EAAC,OAAD;AAAA,IACO,KAAAU;AAAA,IACL,GAAID;AAAA,IACJ,MAAK;AAAA,IACL,cAAYN;AAAA,IACZ,oBAAkBC;AAAA,IAClB,WAAWE,IAAY,cAAcA,CAAA,KAAc;AAAA,IAC5C,OAAAC;AAAA,IAEN,UAAAC;AAAA,EACE,CAAA;AAET"}
|
|
@@ -16,6 +16,7 @@ export interface TooltipProps {
|
|
|
16
16
|
content: ReactNode;
|
|
17
17
|
/** One focusable element (Button, IconButton, Link…). */
|
|
18
18
|
children: ReactElement<Record<string, unknown>>;
|
|
19
|
+
/** Preferred side; flips when it does not fit. Default "top". */
|
|
19
20
|
placement?: Placement;
|
|
20
21
|
/** Hover delay in ms (focus opens immediately). */
|
|
21
22
|
delay?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["useDismiss","usePopover","useAnchoredPosition","cloneElement","useCallback","useEffect","useId","useLayoutEffect","useRef","useState","jsx","jsxs","Tooltip","content","children","placement","delay","id","anchor","tip","timer","open","setOpen","trigger","triggerRef","pointerFocus","show","wait","hide"],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n cloneElement,\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useDismiss } from \"../../overlay/dismiss.js\";\nimport { usePopover } from \"../../overlay/floating.js\";\nimport type { Placement } from \"../../overlay/position.js\";\nimport { useAnchoredPosition } from \"../../overlay/use-anchored-position.js\";\n\nexport interface TooltipTokens {\n bg: string;\n ink: string;\n radius: string;\n maxWidth: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n tooltip: TooltipTokens;\n }\n}\n\nexport interface TooltipProps {\n /** Short supplementary text; it becomes the trigger's accessible description. */\n content: ReactNode;\n /** One focusable element (Button, IconButton, Link…). */\n children: ReactElement<Record<string, unknown>>;\n placement?: Placement;\n /** Hover delay in ms (focus opens immediately). */\n delay?: number;\n}\n\n/**\n * Tooltip in the top layer (Popover API), positioned against its trigger. Opens on hover after `delay` and on\n * keyboard focus; dismissible with Escape; hoverable; never opens on touch (WCAG 1.4.13).\n */\nexport function Tooltip({ content, children, placement = \"top\", delay = 300 }: TooltipProps) {\n const id = `cy-tip-${useId().replace(/:/g, \"\")}`;\n const anchor = useRef<HTMLSpanElement>(null);\n const tip = useRef<HTMLSpanElement>(null);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const [open, setOpen] = useState(false);\n const trigger = () => (anchor.current?.firstElementChild as HTMLElement | null) ?? anchor.current;\n const triggerRef = useRef<HTMLElement | null>(null);\n // Focus that follows a pointer press (mouse or touch) is not keyboard focus: hover handles mouse, touch never opens.\n const pointerFocus = useRef(false);\n\n const show = useCallback((wait: number) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setOpen(true), wait);\n }, []);\n const hide = useCallback((wait = 0) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setOpen(false), wait);\n }, []);\n\n useEffect(() => () => clearTimeout(timer.current), []);\n useLayoutEffect(() => {\n triggerRef.current = trigger();\n });\n usePopover(tip, open);\n // Escape closes the tooltip first when it sits inside a Popover, Menu or Dialog (shared layer stack).\n useDismiss({ open, onClose: () => setOpen(false), inside: [triggerRef, tip], outside: false });\n useAnchoredPosition(triggerRef, tip, open, placement);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: delegated hover/focus listeners for the interactive child\n <span\n ref={anchor}\n className=\"cy-tooltip-anchor\"\n onPointerEnter={(e) => e.pointerType !== \"touch\" && show(delay)}\n onPointerLeave={() => hide(120)}\n onPointerDown={() => {\n pointerFocus.current = true;\n hide();\n }}\n onFocus={(e) => {\n if (!pointerFocus.current && (e.target as HTMLElement).matches(\":focus-visible\")) show(0);\n pointerFocus.current = false;\n }}\n onBlur={() => {\n pointerFocus.current = false;\n hide();\n }}\n >\n {cloneElement(children, {\n \"aria-describedby\": [children.props[\"aria-describedby\"], id].filter(Boolean).join(\" \"),\n })}\n <span\n ref={tip}\n id={id}\n role=\"tooltip\"\n className=\"cy-tooltip\"\n {...{ popover: \"manual\" }}\n onPointerEnter={() => clearTimeout(timer.current)}\n onPointerLeave={() => hide(120)}\n >\n {content}\n </span>\n </span>\n );\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["useDismiss","usePopover","useAnchoredPosition","cloneElement","useCallback","useEffect","useId","useLayoutEffect","useRef","useState","jsx","jsxs","Tooltip","content","children","placement","delay","id","anchor","tip","timer","open","setOpen","trigger","triggerRef","pointerFocus","show","wait","hide"],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import {\n cloneElement,\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useDismiss } from \"../../overlay/dismiss.js\";\nimport { usePopover } from \"../../overlay/floating.js\";\nimport type { Placement } from \"../../overlay/position.js\";\nimport { useAnchoredPosition } from \"../../overlay/use-anchored-position.js\";\n\nexport interface TooltipTokens {\n bg: string;\n ink: string;\n radius: string;\n maxWidth: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n tooltip: TooltipTokens;\n }\n}\n\nexport interface TooltipProps {\n /** Short supplementary text; it becomes the trigger's accessible description. */\n content: ReactNode;\n /** One focusable element (Button, IconButton, Link…). */\n children: ReactElement<Record<string, unknown>>;\n /** Preferred side; flips when it does not fit. Default \"top\". */\n placement?: Placement;\n /** Hover delay in ms (focus opens immediately). */\n delay?: number;\n}\n\n/**\n * Tooltip in the top layer (Popover API), positioned against its trigger. Opens on hover after `delay` and on\n * keyboard focus; dismissible with Escape; hoverable; never opens on touch (WCAG 1.4.13).\n */\nexport function Tooltip({ content, children, placement = \"top\", delay = 300 }: TooltipProps) {\n const id = `cy-tip-${useId().replace(/:/g, \"\")}`;\n const anchor = useRef<HTMLSpanElement>(null);\n const tip = useRef<HTMLSpanElement>(null);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const [open, setOpen] = useState(false);\n const trigger = () => (anchor.current?.firstElementChild as HTMLElement | null) ?? anchor.current;\n const triggerRef = useRef<HTMLElement | null>(null);\n // Focus that follows a pointer press (mouse or touch) is not keyboard focus: hover handles mouse, touch never opens.\n const pointerFocus = useRef(false);\n\n const show = useCallback((wait: number) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setOpen(true), wait);\n }, []);\n const hide = useCallback((wait = 0) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setOpen(false), wait);\n }, []);\n\n useEffect(() => () => clearTimeout(timer.current), []);\n useLayoutEffect(() => {\n triggerRef.current = trigger();\n });\n usePopover(tip, open);\n // Escape closes the tooltip first when it sits inside a Popover, Menu or Dialog (shared layer stack).\n useDismiss({ open, onClose: () => setOpen(false), inside: [triggerRef, tip], outside: false });\n useAnchoredPosition(triggerRef, tip, open, placement);\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: delegated hover/focus listeners for the interactive child\n <span\n ref={anchor}\n className=\"cy-tooltip-anchor\"\n onPointerEnter={(e) => e.pointerType !== \"touch\" && show(delay)}\n onPointerLeave={() => hide(120)}\n onPointerDown={() => {\n pointerFocus.current = true;\n hide();\n }}\n onFocus={(e) => {\n if (!pointerFocus.current && (e.target as HTMLElement).matches(\":focus-visible\")) show(0);\n pointerFocus.current = false;\n }}\n onBlur={() => {\n pointerFocus.current = false;\n hide();\n }}\n >\n {cloneElement(children, {\n \"aria-describedby\": [children.props[\"aria-describedby\"], id].filter(Boolean).join(\" \"),\n })}\n <span\n ref={tip}\n id={id}\n role=\"tooltip\"\n className=\"cy-tooltip\"\n {...{ popover: \"manual\" }}\n onPointerEnter={() => clearTimeout(timer.current)}\n onPointerLeave={() => hide(120)}\n >\n {content}\n </span>\n </span>\n );\n}\n"],"mappings":";;;;;;AA4CA,SAAgBY,EAAQ,EAAE,SAAAC,GAAS,UAAAC,GAAU,WAAAC,IAAY,OAAO,OAAAC,IAAQ,IAAA,GAAqB;AAC3F,QAAMC,IAAK,UAAUX,EAAM,EAAE,QAAQ,MAAM,EAAE,CAAA,IACvCY,IAASV,EAAwB,IAAI,GACrCW,IAAMX,EAAwB,IAAI,GAClCY,IAAQZ,EAAkD,MAAS,GACnE,CAACa,GAAMC,CAAA,IAAWb,EAAS,EAAK,GAChCc,IAAA,MAAiBL,EAAO,SAAS,qBAA4CA,EAAO,SACpFM,IAAahB,EAA2B,IAAI,GAE5CiB,IA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kBAAA,GAAqBG,CAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EACvF,CAAC,GACD,gBAAAP,EAAC,QAAD;AAAA,MACE,KAAKS;AAAA,MACD,IAAAF;AAAA,MACJ,MAAK;AAAA,MACL,WAAU;AAAA,MACJ,SAAS;AAAA,MACf,gBAAA,MAAsB,aAAaG,EAAM,OAAO;AAAA,MAChD,gBAAA,MAAsBQ,EAAK,GAAG;AAAA,MAE7B,UAAAf;AAAA,IACG,CAAA,CACF;AAAA,E;AAEV"}
|
|
@@ -28,14 +28,19 @@ export interface TreeLabels {
|
|
|
28
28
|
export interface TreeProps {
|
|
29
29
|
/** Accessible name of the tree. */
|
|
30
30
|
label: string;
|
|
31
|
+
/** The top-level items; each can hold more under `children`. */
|
|
31
32
|
items: TreeItem[];
|
|
32
33
|
/** Selected ids (controlled) and the default for uncontrolled use. */
|
|
33
34
|
selected?: string[];
|
|
35
|
+
/** Ids selected at the start when uncontrolled. */
|
|
34
36
|
defaultSelected?: string[];
|
|
37
|
+
/** Called with the selected ids when the selection changes. */
|
|
35
38
|
onSelectionChange?: (ids: string[]) => void;
|
|
36
39
|
/** Expanded ids (controlled) and the default for uncontrolled use. */
|
|
37
40
|
expanded?: string[];
|
|
41
|
+
/** Ids expanded at the start when uncontrolled. */
|
|
38
42
|
defaultExpanded?: string[];
|
|
43
|
+
/** Called with the expanded ids when an item is expanded or collapsed. */
|
|
39
44
|
onExpandedChange?: (ids: string[]) => void;
|
|
40
45
|
/** `single` (default): one at a time. `multiple`: Space and clicks toggle. */
|
|
41
46
|
selectionMode?: "single" | "multiple";
|
|
@@ -50,8 +55,11 @@ export interface TreeProps {
|
|
|
50
55
|
* must share one height.
|
|
51
56
|
*/
|
|
52
57
|
virtual?: boolean;
|
|
58
|
+
/** Row height and indent. Default "md". */
|
|
53
59
|
size?: Extract<Size, "sm" | "md">;
|
|
60
|
+
/** Replace the built-in English text: the loading row and the failed-to-load row. */
|
|
54
61
|
labels?: Partial<TreeLabels>;
|
|
62
|
+
/** Added to the root element, for layout. */
|
|
55
63
|
className?: string;
|
|
56
64
|
/** Layout only. Restyle through --cy-tree-* tokens. */
|
|
57
65
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.js","names":["_Fragment","useControllableState","Icon","LoadingDots","isRtl","chevronRight","isTypeaheadKey","useTypeahead","useVirtualWindow","memo","useCallback","useLayoutEffect","useMemo","useRef","useState","Fragment$1","jsx","jsxs","DEFAULT_LABELS","Tree","label","items","selected","defaultSelected","onSelectionChange","expanded","defaultExpanded","onExpandedChange","selectionMode","loadChildren","renderLabel","onAction","virtual","size","labels","className","style","loadingText","failedText","text","picked","setPicked","open","setOpen","loaded","setLoaded","status","setStatus","focusKey","setFocusKey","moveFocus","root","typeTo","childrenOf","item","isBranch","rows","out","openSet","walk","list","level","parent","i","kids","focusable","r","tabStop","stopIndex","win","rowH","outside","seenOutside","index","load","s","l","_","rest","expand","collapse","id","toggle","select","additive","next","focusRow","key","onKeyDown","event","at","row","rtl","branch","isOpen","handled","siblings","clickRef","onChevron","onRowClick","TreeRow","offset","tabbable","busy","onClick","kind","note","e"],"sources":["../../../src/components/Tree/Tree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n memo,\n type ReactNode,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { isTypeaheadKey, useTypeahead } from \"../../foundations/listbox.js\";\nimport { useVirtualWindow } from \"../../foundations/virtual-window.js\";\nimport { chevronRight } from \"../../icons/chevron-right.js\";\nimport type { IconData } from \"../../icons/types.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { LoadingDots } from \"../LoadingDots/LoadingDots.js\";\n\nexport interface TreeTokens {\n indent: string;\n rowHeight: string;\n selectedBg: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n tree: TreeTokens;\n }\n}\n\nexport interface TreeItem {\n id: string;\n label: string;\n icon?: IconData;\n disabled?: boolean;\n /** Known children. Leave it out and set `hasChildren` to load them with `loadChildren` on first expand. */\n children?: TreeItem[];\n hasChildren?: boolean;\n}\n\nexport interface TreeLabels {\n loading: string;\n /** Row shown when `loadChildren` fails; Enter or a click on it tries again. */\n failed: string;\n}\n\nexport interface TreeProps {\n /** Accessible name of the tree. */\n label: string;\n items: TreeItem[];\n /** Selected ids (controlled) and the default for uncontrolled use. */\n selected?: string[];\n defaultSelected?: string[];\n onSelectionChange?: (ids: string[]) => void;\n /** Expanded ids (controlled) and the default for uncontrolled use. */\n expanded?: string[];\n defaultExpanded?: string[];\n onExpandedChange?: (ids: string[]) => void;\n /** `single` (default): one at a time. `multiple`: Space and clicks toggle. */\n selectionMode?: \"single\" | \"multiple\";\n /** Fetch the children of an item that `hasChildren` but has none yet. */\n loadChildren?: (item: TreeItem) => Promise<TreeItem[]>;\n /** Custom row content after the chevron (a value, a badge, a line number). `label` still drives type-ahead. */\n renderLabel?: (item: TreeItem) => ReactNode;\n /** Enter (or a double-click) on an item: its default action, such as opening it or copying its path. Space selects. */\n onAction?: ((item: TreeItem) => void) | undefined;\n /**\n * Render only the rows in view (for tens of thousands of rows). Give the tree a height (`style` or a class); rows\n * must share one height.\n */\n virtual?: boolean;\n size?: Extract<Size, \"sm\" | \"md\">;\n labels?: Partial<TreeLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-tree-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: TreeLabels = { loading: \"Loading…\", failed: \"Could not load. Press Enter to retry.\" };\n\n/** One visible row: an item, or a loading or failure row for a parent whose children are being fetched. */\ninterface Row {\n key: string;\n item: TreeItem;\n level: number;\n pos: number;\n setSize: number;\n parent: string | null;\n kind: \"item\" | \"loading\" | \"failed\";\n}\n\ntype Status = \"loading\" | \"failed\";\n\n/** Hierarchical list (WAI-ARIA APG tree view): arrows, type-ahead, expand and collapse, selection, lazy children. */\nexport function Tree({\n label,\n items,\n selected,\n defaultSelected = [],\n onSelectionChange,\n expanded,\n defaultExpanded = [],\n onExpandedChange,\n selectionMode = \"single\",\n loadChildren,\n renderLabel,\n onAction,\n virtual = false,\n size = \"md\",\n labels,\n className,\n style,\n}: TreeProps) {\n const loadingText = labels?.loading ?? DEFAULT_LABELS.loading;\n const failedText = labels?.failed ?? DEFAULT_LABELS.failed;\n const text = useMemo(() => ({ loading: loadingText, failed: failedText }), [loadingText, failedText]);\n const [picked, setPicked] = useControllableState(selected, defaultSelected, onSelectionChange);\n const [open, setOpen] = useControllableState(expanded, defaultExpanded, onExpandedChange);\n const [loaded, setLoaded] = useState<Record<string, TreeItem[]>>({});\n const [status, setStatus] = useState<Record<string, Status>>({});\n const [focusKey, setFocusKey] = useState<string | null>(null);\n const moveFocus = useRef(false);\n const root = useRef<HTMLDivElement>(null);\n const typeTo = useTypeahead();\n\n const childrenOf = useCallback((item: TreeItem) => item.children ?? loaded[item.id], [loaded]);\n const isBranch = useCallback((item: TreeItem) => Boolean(item.children?.length || item.hasChildren), []);\n\n // Visible rows, depth first through expanded branches only: a collapsed subtree costs nothing.\n const rows = useMemo(() => {\n const out: Row[] = [];\n const openSet = new Set(open);\n const walk = (list: TreeItem[], level: number, parent: string | null) => {\n list.forEach((item, i) => {\n out.push({ key: item.id, item, level, pos: i + 1, setSize: list.length, parent, kind: \"item\" });\n if (!openSet.has(item.id) || !isBranch(item)) return;\n const kids = childrenOf(item);\n if (kids) walk(kids, level + 1, item.id);\n else if (status[item.id])\n out.push({\n key: `${item.id}::${status[item.id]}`,\n item,\n level: level + 1,\n pos: 1,\n setSize: 1,\n parent: item.id,\n kind: status[item.id] as Status,\n });\n });\n };\n walk(items, 1, null);\n return out;\n }, [items, open, status, childrenOf, isBranch]);\n\n const focusable = rows.filter((r) => r.kind !== \"loading\" && !(r.kind === \"item\" && r.item.disabled));\n const tabStop =\n (focusKey && rows.some((r) => r.key === focusKey) ? focusKey : null) ??\n rows.find((r) => r.kind === \"item\" && picked.includes(r.item.id))?.key ??\n focusable[0]?.key ??\n null;\n\n // Virtual mode: render the rows in view (plus a few either side). The focused row is always rendered, so keyboard\n // focus survives scrolling it out of view.\n const stopIndex = rows.findIndex((r) => r.key === tabStop);\n const win = useVirtualWindow(root, {\n count: rows.length,\n enabled: virtual,\n rowSelector: \".cy-tree-row\",\n keep: stopIndex,\n });\n const rowH = win.rowSize;\n\n // A selection made from outside (search next/previous) moves the tab stop to it and scrolls it into view, without\n // taking focus from where the person is (the search field).\n const outside = selected?.[0];\n const seenOutside = useRef(outside);\n useLayoutEffect(() => {\n if (outside === seenOutside.current) return;\n seenOutside.current = outside;\n const index = rows.findIndex((r) => r.key === outside);\n if (outside === undefined || index < 0) return;\n setFocusKey(outside);\n if (virtual) win.reveal(index);\n else\n root.current\n ?.querySelector(`[data-key=\"${CSS.escape(outside)}\"]`)\n ?.scrollIntoView?.({ block: \"nearest\" });\n });\n\n useLayoutEffect(() => {\n if (!moveFocus.current || !tabStop) return;\n moveFocus.current = false;\n // Bring the row into view first; it is rendered either way.\n if (stopIndex >= 0) win.reveal(stopIndex);\n root.current\n ?.querySelector<HTMLElement>(`[data-key=\"${CSS.escape(tabStop)}\"]`)\n ?.focus({ preventScroll: virtual });\n });\n\n const load = (item: TreeItem) => {\n if (!loadChildren || item.children || loaded[item.id] || status[item.id] === \"loading\") return;\n setStatus((s) => ({ ...s, [item.id]: \"loading\" }));\n loadChildren(item).then(\n (kids) => {\n setLoaded((l) => ({ ...l, [item.id]: kids }));\n setStatus(({ [item.id]: _, ...rest }) => rest);\n },\n () => setStatus((s) => ({ ...s, [item.id]: \"failed\" })),\n );\n };\n const expand = (item: TreeItem) => {\n if (!open.includes(item.id)) setOpen([...open, item.id]);\n if (!childrenOf(item)) load(item);\n };\n const collapse = (item: TreeItem) => setOpen(open.filter((id) => id !== item.id));\n const toggle = (item: TreeItem) => (open.includes(item.id) ? collapse(item) : expand(item));\n const select = (item: TreeItem, additive: boolean) => {\n if (item.disabled) return;\n const next =\n selectionMode === \"multiple\" && additive\n ? picked.includes(item.id)\n ? picked.filter((id) => id !== item.id)\n : [...picked, item.id]\n : [item.id];\n setPicked(next);\n };\n const focusRow = (key: string | undefined) => {\n if (!key) return;\n moveFocus.current = true;\n setFocusKey(key);\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const at = rows.findIndex((r) => r.key === tabStop);\n const row = rows[at];\n if (!row) return;\n const rtl = isRtl(event.currentTarget);\n const key =\n rtl && event.key === \"ArrowLeft\"\n ? \"ArrowRight\"\n : rtl && event.key === \"ArrowRight\"\n ? \"ArrowLeft\"\n : event.key;\n const index = focusable.findIndex((r) => r.key === tabStop);\n const item = row.item;\n const branch = row.kind === \"item\" && isBranch(item);\n const isOpen = open.includes(item.id);\n let handled = true;\n switch (key) {\n case \"ArrowDown\":\n focusRow(focusable[index + 1]?.key);\n break;\n case \"ArrowUp\":\n focusRow(focusable[index - 1]?.key);\n break;\n case \"Home\":\n focusRow(focusable[0]?.key);\n break;\n case \"End\":\n focusRow(focusable[focusable.length - 1]?.key);\n break;\n case \"ArrowRight\":\n if (branch && !isOpen) expand(item);\n else if (branch) focusRow(rows[at + 1]?.kind === \"item\" ? rows[at + 1]?.key : undefined);\n break;\n case \"ArrowLeft\":\n if (branch && isOpen) collapse(item);\n else focusRow(row.parent ?? undefined);\n break;\n case \"Enter\":\n case \" \":\n if (row.kind === \"failed\") load(item);\n else if (key === \"Enter\" && onAction && !item.disabled) onAction(item);\n else select(item, key === \" \" || event.ctrlKey || event.metaKey);\n break;\n case \"*\": {\n const siblings = rows.filter((r) => r.kind === \"item\" && r.parent === row.parent && isBranch(r.item));\n setOpen([...new Set([...open, ...siblings.map((r) => r.item.id)])]);\n for (const s of siblings) if (!childrenOf(s.item)) load(s.item);\n break;\n }\n default:\n handled = false;\n if (isTypeaheadKey(event)) {\n const labels = focusable.map((r) => (r.kind === \"item\" ? r.item.label : null));\n focusRow(focusable[typeTo(event.key, labels, index)]?.key);\n handled = true;\n }\n }\n if (handled) event.preventDefault();\n };\n\n // A click on a row selects it; on its chevron, toggles it; on a failure row, retries. The callback is stable (rows\n // are memoised) and reads the latest state through a ref.\n const clickRef = useRef<(row: Row, onChevron: boolean, additive: boolean) => void>(() => {});\n clickRef.current = (row, onChevron, additive) => {\n if (row.kind === \"failed\") return load(row.item);\n if (row.kind !== \"item\" || row.item.disabled) return;\n setFocusKey(row.key);\n if (onChevron) toggle(row.item);\n else select(row.item, additive);\n };\n const onRowClick = useCallback((row: Row, onChevron: boolean, additive: boolean) => {\n clickRef.current(row, onChevron, additive);\n }, []);\n\n return (\n <div\n ref={root}\n role=\"tree\"\n aria-label={label}\n aria-multiselectable={selectionMode === \"multiple\" || undefined}\n className={className ? `cy-tree ${className}` : \"cy-tree\"}\n data-size={size}\n data-virtual={virtual || undefined}\n style={style}\n onKeyDown={onKeyDown}\n onScroll={virtual ? (e) => win.onScroll(e.currentTarget.scrollTop) : undefined}\n >\n {virtual && <div className=\"cy-tree-space\" style={{ blockSize: win.total }} aria-hidden=\"true\" />}\n {win.indices.map((i) => {\n const row = rows[i] as Row;\n return (\n <TreeRow\n key={row.key}\n row={row}\n offset={virtual ? i * rowH : undefined}\n renderLabel={renderLabel}\n branch={row.kind === \"item\" && isBranch(row.item)}\n open={open.includes(row.item.id)}\n selected={row.kind === \"item\" && picked.includes(row.item.id)}\n tabbable={row.key === tabStop}\n busy={status[row.item.id] === \"loading\"}\n text={text}\n onClick={onRowClick}\n onAction={onAction}\n />\n );\n })}\n </div>\n );\n}\n\ninterface TreeRowProps {\n row: Row;\n /** Virtual mode: the row's position from the top of the list. */\n offset: number | undefined;\n renderLabel: ((item: TreeItem) => ReactNode) | undefined;\n branch: boolean;\n open: boolean;\n selected: boolean;\n tabbable: boolean;\n busy: boolean;\n text: TreeLabels;\n onClick: (row: Row, onChevron: boolean, additive: boolean) => void;\n onAction: ((item: TreeItem) => void) | undefined;\n}\n\n/** Memoised so that moving focus or selection re-renders two rows, not the whole tree. */\nconst TreeRow = memo(function TreeRow({\n row,\n offset,\n renderLabel,\n branch,\n open,\n selected,\n tabbable,\n busy,\n text,\n onClick,\n onAction,\n}: TreeRowProps) {\n const { item, level, kind } = row;\n const note = kind === \"loading\" ? text.loading : kind === \"failed\" ? text.failed : null;\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: the tree handles keys for every row (roving focus)\n <div\n role=\"treeitem\"\n data-key={row.key}\n data-kind={kind}\n className=\"cy-tree-row cy-reset\"\n aria-level={level}\n aria-posinset={row.pos}\n aria-setsize={row.setSize}\n aria-expanded={branch ? open : undefined}\n aria-selected={kind === \"item\" ? selected : undefined}\n aria-disabled={kind === \"loading\" || item.disabled || undefined}\n aria-busy={busy || undefined}\n // Disabled and loading rows never take focus, not even from a click.\n tabIndex={kind === \"loading\" || item.disabled ? undefined : tabbable ? 0 : -1}\n style={{ \"--_level\": level - 1, insetBlockStart: offset } as CSSProperties}\n onClick={(e) => {\n const onChevron = (e.target as Element).closest(\".cy-tree-chevron\") !== null;\n onClick(row, onChevron, e.ctrlKey || e.metaKey);\n }}\n onDoubleClick={(e) => {\n if (kind === \"item\" && !item.disabled && !(e.target as Element).closest(\".cy-tree-chevron\"))\n onAction?.(item);\n }}\n >\n <span className=\"cy-tree-chevron cy-reset\" data-open={open || undefined} aria-hidden=\"true\">\n {branch && <Icon icon={chevronRight} size=\"sm\" />}\n </span>\n {note ? (\n <span className=\"cy-tree-note cy-reset\">\n {kind === \"loading\" && <LoadingDots size=\"sm\" />}\n {note}\n </span>\n ) : (\n <>\n {item.icon && <Icon icon={item.icon} className=\"cy-tree-icon\" />}\n <span className=\"cy-tree-label cy-reset\">{renderLabel ? renderLabel(item) : item.label}</span>\n </>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;AAiFA,IAAMkB,KAA6B;AAAA,EAAE,SAAS;AAAA,EAAY,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B,CAAI,IAAIA,EAAK;AAAA,IAAY,CAAA,CAC7F,EAAA,CAAA,CAED;AAAA,E;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"Tree.js","names":["_Fragment","useControllableState","Icon","LoadingDots","isRtl","chevronRight","isTypeaheadKey","useTypeahead","useVirtualWindow","memo","useCallback","useLayoutEffect","useMemo","useRef","useState","Fragment$1","jsx","jsxs","DEFAULT_LABELS","Tree","label","items","selected","defaultSelected","onSelectionChange","expanded","defaultExpanded","onExpandedChange","selectionMode","loadChildren","renderLabel","onAction","virtual","size","labels","className","style","loadingText","failedText","text","picked","setPicked","open","setOpen","loaded","setLoaded","status","setStatus","focusKey","setFocusKey","moveFocus","root","typeTo","childrenOf","item","isBranch","rows","out","openSet","walk","list","level","parent","i","kids","focusable","r","tabStop","stopIndex","win","rowH","outside","seenOutside","index","load","s","l","_","rest","expand","collapse","id","toggle","select","additive","next","focusRow","key","onKeyDown","event","at","row","rtl","branch","isOpen","handled","siblings","clickRef","onChevron","onRowClick","TreeRow","offset","tabbable","busy","onClick","kind","note","e"],"sources":["../../../src/components/Tree/Tree.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n memo,\n type ReactNode,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { isTypeaheadKey, useTypeahead } from \"../../foundations/listbox.js\";\nimport { useVirtualWindow } from \"../../foundations/virtual-window.js\";\nimport { chevronRight } from \"../../icons/chevron-right.js\";\nimport type { IconData } from \"../../icons/types.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { LoadingDots } from \"../LoadingDots/LoadingDots.js\";\n\nexport interface TreeTokens {\n indent: string;\n rowHeight: string;\n selectedBg: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n tree: TreeTokens;\n }\n}\n\nexport interface TreeItem {\n id: string;\n label: string;\n icon?: IconData;\n disabled?: boolean;\n /** Known children. Leave it out and set `hasChildren` to load them with `loadChildren` on first expand. */\n children?: TreeItem[];\n hasChildren?: boolean;\n}\n\nexport interface TreeLabels {\n loading: string;\n /** Row shown when `loadChildren` fails; Enter or a click on it tries again. */\n failed: string;\n}\n\nexport interface TreeProps {\n /** Accessible name of the tree. */\n label: string;\n /** The top-level items; each can hold more under `children`. */\n items: TreeItem[];\n /** Selected ids (controlled) and the default for uncontrolled use. */\n selected?: string[];\n /** Ids selected at the start when uncontrolled. */\n defaultSelected?: string[];\n /** Called with the selected ids when the selection changes. */\n onSelectionChange?: (ids: string[]) => void;\n /** Expanded ids (controlled) and the default for uncontrolled use. */\n expanded?: string[];\n /** Ids expanded at the start when uncontrolled. */\n defaultExpanded?: string[];\n /** Called with the expanded ids when an item is expanded or collapsed. */\n onExpandedChange?: (ids: string[]) => void;\n /** `single` (default): one at a time. `multiple`: Space and clicks toggle. */\n selectionMode?: \"single\" | \"multiple\";\n /** Fetch the children of an item that `hasChildren` but has none yet. */\n loadChildren?: (item: TreeItem) => Promise<TreeItem[]>;\n /** Custom row content after the chevron (a value, a badge, a line number). `label` still drives type-ahead. */\n renderLabel?: (item: TreeItem) => ReactNode;\n /** Enter (or a double-click) on an item: its default action, such as opening it or copying its path. Space selects. */\n onAction?: ((item: TreeItem) => void) | undefined;\n /**\n * Render only the rows in view (for tens of thousands of rows). Give the tree a height (`style` or a class); rows\n * must share one height.\n */\n virtual?: boolean;\n /** Row height and indent. Default \"md\". */\n size?: Extract<Size, \"sm\" | \"md\">;\n /** Replace the built-in English text: the loading row and the failed-to-load row. */\n labels?: Partial<TreeLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-tree-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: TreeLabels = { loading: \"Loading…\", failed: \"Could not load. Press Enter to retry.\" };\n\n/** One visible row: an item, or a loading or failure row for a parent whose children are being fetched. */\ninterface Row {\n key: string;\n item: TreeItem;\n level: number;\n pos: number;\n setSize: number;\n parent: string | null;\n kind: \"item\" | \"loading\" | \"failed\";\n}\n\ntype Status = \"loading\" | \"failed\";\n\n/** Hierarchical list (WAI-ARIA APG tree view): arrows, type-ahead, expand and collapse, selection, lazy children. */\nexport function Tree({\n label,\n items,\n selected,\n defaultSelected = [],\n onSelectionChange,\n expanded,\n defaultExpanded = [],\n onExpandedChange,\n selectionMode = \"single\",\n loadChildren,\n renderLabel,\n onAction,\n virtual = false,\n size = \"md\",\n labels,\n className,\n style,\n}: TreeProps) {\n const loadingText = labels?.loading ?? DEFAULT_LABELS.loading;\n const failedText = labels?.failed ?? DEFAULT_LABELS.failed;\n const text = useMemo(() => ({ loading: loadingText, failed: failedText }), [loadingText, failedText]);\n const [picked, setPicked] = useControllableState(selected, defaultSelected, onSelectionChange);\n const [open, setOpen] = useControllableState(expanded, defaultExpanded, onExpandedChange);\n const [loaded, setLoaded] = useState<Record<string, TreeItem[]>>({});\n const [status, setStatus] = useState<Record<string, Status>>({});\n const [focusKey, setFocusKey] = useState<string | null>(null);\n const moveFocus = useRef(false);\n const root = useRef<HTMLDivElement>(null);\n const typeTo = useTypeahead();\n\n const childrenOf = useCallback((item: TreeItem) => item.children ?? loaded[item.id], [loaded]);\n const isBranch = useCallback((item: TreeItem) => Boolean(item.children?.length || item.hasChildren), []);\n\n // Visible rows, depth first through expanded branches only: a collapsed subtree costs nothing.\n const rows = useMemo(() => {\n const out: Row[] = [];\n const openSet = new Set(open);\n const walk = (list: TreeItem[], level: number, parent: string | null) => {\n list.forEach((item, i) => {\n out.push({ key: item.id, item, level, pos: i + 1, setSize: list.length, parent, kind: \"item\" });\n if (!openSet.has(item.id) || !isBranch(item)) return;\n const kids = childrenOf(item);\n if (kids) walk(kids, level + 1, item.id);\n else if (status[item.id])\n out.push({\n key: `${item.id}::${status[item.id]}`,\n item,\n level: level + 1,\n pos: 1,\n setSize: 1,\n parent: item.id,\n kind: status[item.id] as Status,\n });\n });\n };\n walk(items, 1, null);\n return out;\n }, [items, open, status, childrenOf, isBranch]);\n\n const focusable = rows.filter((r) => r.kind !== \"loading\" && !(r.kind === \"item\" && r.item.disabled));\n const tabStop =\n (focusKey && rows.some((r) => r.key === focusKey) ? focusKey : null) ??\n rows.find((r) => r.kind === \"item\" && picked.includes(r.item.id))?.key ??\n focusable[0]?.key ??\n null;\n\n // Virtual mode: render the rows in view (plus a few either side). The focused row is always rendered, so keyboard\n // focus survives scrolling it out of view.\n const stopIndex = rows.findIndex((r) => r.key === tabStop);\n const win = useVirtualWindow(root, {\n count: rows.length,\n enabled: virtual,\n rowSelector: \".cy-tree-row\",\n keep: stopIndex,\n });\n const rowH = win.rowSize;\n\n // A selection made from outside (search next/previous) moves the tab stop to it and scrolls it into view, without\n // taking focus from where the person is (the search field).\n const outside = selected?.[0];\n const seenOutside = useRef(outside);\n useLayoutEffect(() => {\n if (outside === seenOutside.current) return;\n seenOutside.current = outside;\n const index = rows.findIndex((r) => r.key === outside);\n if (outside === undefined || index < 0) return;\n setFocusKey(outside);\n if (virtual) win.reveal(index);\n else\n root.current\n ?.querySelector(`[data-key=\"${CSS.escape(outside)}\"]`)\n ?.scrollIntoView?.({ block: \"nearest\" });\n });\n\n useLayoutEffect(() => {\n if (!moveFocus.current || !tabStop) return;\n moveFocus.current = false;\n // Bring the row into view first; it is rendered either way.\n if (stopIndex >= 0) win.reveal(stopIndex);\n root.current\n ?.querySelector<HTMLElement>(`[data-key=\"${CSS.escape(tabStop)}\"]`)\n ?.focus({ preventScroll: virtual });\n });\n\n const load = (item: TreeItem) => {\n if (!loadChildren || item.children || loaded[item.id] || status[item.id] === \"loading\") return;\n setStatus((s) => ({ ...s, [item.id]: \"loading\" }));\n loadChildren(item).then(\n (kids) => {\n setLoaded((l) => ({ ...l, [item.id]: kids }));\n setStatus(({ [item.id]: _, ...rest }) => rest);\n },\n () => setStatus((s) => ({ ...s, [item.id]: \"failed\" })),\n );\n };\n const expand = (item: TreeItem) => {\n if (!open.includes(item.id)) setOpen([...open, item.id]);\n if (!childrenOf(item)) load(item);\n };\n const collapse = (item: TreeItem) => setOpen(open.filter((id) => id !== item.id));\n const toggle = (item: TreeItem) => (open.includes(item.id) ? collapse(item) : expand(item));\n const select = (item: TreeItem, additive: boolean) => {\n if (item.disabled) return;\n const next =\n selectionMode === \"multiple\" && additive\n ? picked.includes(item.id)\n ? picked.filter((id) => id !== item.id)\n : [...picked, item.id]\n : [item.id];\n setPicked(next);\n };\n const focusRow = (key: string | undefined) => {\n if (!key) return;\n moveFocus.current = true;\n setFocusKey(key);\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const at = rows.findIndex((r) => r.key === tabStop);\n const row = rows[at];\n if (!row) return;\n const rtl = isRtl(event.currentTarget);\n const key =\n rtl && event.key === \"ArrowLeft\"\n ? \"ArrowRight\"\n : rtl && event.key === \"ArrowRight\"\n ? \"ArrowLeft\"\n : event.key;\n const index = focusable.findIndex((r) => r.key === tabStop);\n const item = row.item;\n const branch = row.kind === \"item\" && isBranch(item);\n const isOpen = open.includes(item.id);\n let handled = true;\n switch (key) {\n case \"ArrowDown\":\n focusRow(focusable[index + 1]?.key);\n break;\n case \"ArrowUp\":\n focusRow(focusable[index - 1]?.key);\n break;\n case \"Home\":\n focusRow(focusable[0]?.key);\n break;\n case \"End\":\n focusRow(focusable[focusable.length - 1]?.key);\n break;\n case \"ArrowRight\":\n if (branch && !isOpen) expand(item);\n else if (branch) focusRow(rows[at + 1]?.kind === \"item\" ? rows[at + 1]?.key : undefined);\n break;\n case \"ArrowLeft\":\n if (branch && isOpen) collapse(item);\n else focusRow(row.parent ?? undefined);\n break;\n case \"Enter\":\n case \" \":\n if (row.kind === \"failed\") load(item);\n else if (key === \"Enter\" && onAction && !item.disabled) onAction(item);\n else select(item, key === \" \" || event.ctrlKey || event.metaKey);\n break;\n case \"*\": {\n const siblings = rows.filter((r) => r.kind === \"item\" && r.parent === row.parent && isBranch(r.item));\n setOpen([...new Set([...open, ...siblings.map((r) => r.item.id)])]);\n for (const s of siblings) if (!childrenOf(s.item)) load(s.item);\n break;\n }\n default:\n handled = false;\n if (isTypeaheadKey(event)) {\n const labels = focusable.map((r) => (r.kind === \"item\" ? r.item.label : null));\n focusRow(focusable[typeTo(event.key, labels, index)]?.key);\n handled = true;\n }\n }\n if (handled) event.preventDefault();\n };\n\n // A click on a row selects it; on its chevron, toggles it; on a failure row, retries. The callback is stable (rows\n // are memoised) and reads the latest state through a ref.\n const clickRef = useRef<(row: Row, onChevron: boolean, additive: boolean) => void>(() => {});\n clickRef.current = (row, onChevron, additive) => {\n if (row.kind === \"failed\") return load(row.item);\n if (row.kind !== \"item\" || row.item.disabled) return;\n setFocusKey(row.key);\n if (onChevron) toggle(row.item);\n else select(row.item, additive);\n };\n const onRowClick = useCallback((row: Row, onChevron: boolean, additive: boolean) => {\n clickRef.current(row, onChevron, additive);\n }, []);\n\n return (\n <div\n ref={root}\n role=\"tree\"\n aria-label={label}\n aria-multiselectable={selectionMode === \"multiple\" || undefined}\n className={className ? `cy-tree ${className}` : \"cy-tree\"}\n data-size={size}\n data-virtual={virtual || undefined}\n style={style}\n onKeyDown={onKeyDown}\n onScroll={virtual ? (e) => win.onScroll(e.currentTarget.scrollTop) : undefined}\n >\n {virtual && <div className=\"cy-tree-space\" style={{ blockSize: win.total }} aria-hidden=\"true\" />}\n {win.indices.map((i) => {\n const row = rows[i] as Row;\n return (\n <TreeRow\n key={row.key}\n row={row}\n offset={virtual ? i * rowH : undefined}\n renderLabel={renderLabel}\n branch={row.kind === \"item\" && isBranch(row.item)}\n open={open.includes(row.item.id)}\n selected={row.kind === \"item\" && picked.includes(row.item.id)}\n tabbable={row.key === tabStop}\n busy={status[row.item.id] === \"loading\"}\n text={text}\n onClick={onRowClick}\n onAction={onAction}\n />\n );\n })}\n </div>\n );\n}\n\ninterface TreeRowProps {\n row: Row;\n /** Virtual mode: the row's position from the top of the list. */\n offset: number | undefined;\n renderLabel: ((item: TreeItem) => ReactNode) | undefined;\n branch: boolean;\n open: boolean;\n selected: boolean;\n tabbable: boolean;\n busy: boolean;\n text: TreeLabels;\n onClick: (row: Row, onChevron: boolean, additive: boolean) => void;\n onAction: ((item: TreeItem) => void) | undefined;\n}\n\n/** Memoised so that moving focus or selection re-renders two rows, not the whole tree. */\nconst TreeRow = memo(function TreeRow({\n row,\n offset,\n renderLabel,\n branch,\n open,\n selected,\n tabbable,\n busy,\n text,\n onClick,\n onAction,\n}: TreeRowProps) {\n const { item, level, kind } = row;\n const note = kind === \"loading\" ? text.loading : kind === \"failed\" ? text.failed : null;\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: the tree handles keys for every row (roving focus)\n <div\n role=\"treeitem\"\n data-key={row.key}\n data-kind={kind}\n className=\"cy-tree-row cy-reset\"\n aria-level={level}\n aria-posinset={row.pos}\n aria-setsize={row.setSize}\n aria-expanded={branch ? open : undefined}\n aria-selected={kind === \"item\" ? selected : undefined}\n aria-disabled={kind === \"loading\" || item.disabled || undefined}\n aria-busy={busy || undefined}\n // Disabled and loading rows never take focus, not even from a click.\n tabIndex={kind === \"loading\" || item.disabled ? undefined : tabbable ? 0 : -1}\n style={{ \"--_level\": level - 1, insetBlockStart: offset } as CSSProperties}\n onClick={(e) => {\n const onChevron = (e.target as Element).closest(\".cy-tree-chevron\") !== null;\n onClick(row, onChevron, e.ctrlKey || e.metaKey);\n }}\n onDoubleClick={(e) => {\n if (kind === \"item\" && !item.disabled && !(e.target as Element).closest(\".cy-tree-chevron\"))\n onAction?.(item);\n }}\n >\n <span className=\"cy-tree-chevron cy-reset\" data-open={open || undefined} aria-hidden=\"true\">\n {branch && <Icon icon={chevronRight} size=\"sm\" />}\n </span>\n {note ? (\n <span className=\"cy-tree-note cy-reset\">\n {kind === \"loading\" && <LoadingDots size=\"sm\" />}\n {note}\n </span>\n ) : (\n <>\n {item.icon && <Icon icon={item.icon} className=\"cy-tree-icon\" />}\n <span className=\"cy-tree-label cy-reset\">{renderLabel ? renderLabel(item) : item.label}</span>\n </>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;AAyFA,IAAMkB,KAA6B;AAAA,EAAE,SAAS;AAAA,EAAY,QAAQ;AAAwC;AAgB1G,SAAgBC,GAAK,EACnB,OAAAC,GACA,OAAAC,GACA,UAAAC,GACA,iBAAAC,IAAkB,CAAC,GACnB,mBAAAC,GACA,UAAAC,GACA,iBAAAC,IAAkB,CAAC,GACnB,kBAAAC,GACA,eAAAC,IAAgB,UAChB,cAAAC,GACA,aAAAC,GACA,UAAAC,GACA,SAAAC,IAAU,IACV,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACY;AACZ,QAAMC,KAAcH,GAAQ,WAAWhB,GAAe,SAChDoB,KAAaJ,GAAQ,UAAUhB,GAAe,QAC9CqB,KAAO3B,GAAA,OAAe;AAAA,IAAE,SAASyB;AAAA,IAAa,QAAQC;AAAA,EAAW,IAAI,CAACD,IAAaC,EAAU,CAAC,GAC9F,CAACE,GAAQC,EAAA,IAAaxC,GAAqBqB,GAAUC,GAAiBC,CAAiB,GACvF,CAACkB,GAAMC,CAAA,IAAW1C,GAAqBwB,GAAUC,GAAiBC,CAAgB,GAClF,CAACiB,GAAQC,EAAA,IAAa/B,EAAqC,CAAC,CAAC,GAC7D,CAACgC,GAAQC,CAAA,IAAajC,EAAiC,CAAC,CAAC,GACzD,CAACkC,GAAUC,CAAA,IAAenC,EAAwB,IAAI,GACtDoC,IAAYrC,EAAO,EAAK,GACxBsC,IAAOtC,EAAuB,IAAI,GAClCuC,KAAS7C,GAAa,GAEtB8C,IAAa3C,EAAA,CAAa4C,MAAmBA,EAAK,YAAYV,EAAOU,EAAK,EAAA,GAAK,CAACV,CAAM,CAAC,GACvFW,IAAW7C,EAAA,CAAa4C,MAAmB,GAAQA,EAAK,UAAU,UAAUA,EAAK,cAAc,CAAC,CAAC,GAGjGE,IAAO5C,GAAA,M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IAAD;AAAA,MAAM,MAAMoD,EAAK;AAAA,MAAM,WAAU;AAAA,IAAgB,CAAA,GAC/D,gBAAAtC,EAAC,QAAD;AAAA,MAAM,WAAU;AAAA,MAA0B,UAAAc,IAAcA,EAAYwB,CAAI,IAAIA,EAAK;AAAA,IAAY,CAAA,CAC7F,EAAA,CAAA,CAED;AAAA,E;AAET,CAAC"}
|
|
@@ -28,6 +28,7 @@ export interface VirtualListHandle {
|
|
|
28
28
|
export interface VirtualListProps<T> {
|
|
29
29
|
/** Accessible name of the list. */
|
|
30
30
|
label: string;
|
|
31
|
+
/** The data, one entry per row. */
|
|
31
32
|
items: readonly T[];
|
|
32
33
|
/** A stable, unique key per item. */
|
|
33
34
|
getKey: (item: T, index: number) => string;
|
|
@@ -44,11 +45,15 @@ export interface VirtualListProps<T> {
|
|
|
44
45
|
isHeader?: (item: T) => boolean;
|
|
45
46
|
/** `scrollToIndex` and `scrollToEnd`, for scrolling from outside the list. */
|
|
46
47
|
handle?: Ref<VirtualListHandle>;
|
|
48
|
+
/** Return true for rows that cannot be selected; the arrow keys skip them. */
|
|
47
49
|
isDisabled?: (item: T) => boolean;
|
|
48
50
|
/** "none" (a list to act on), "single" (default) or "multiple". */
|
|
49
51
|
selectionMode?: "none" | "single" | "multiple";
|
|
52
|
+
/** Keys of the selected rows (controlled). */
|
|
50
53
|
selectedKeys?: string[] | undefined;
|
|
54
|
+
/** Keys of the rows selected at the start when uncontrolled. */
|
|
51
55
|
defaultSelectedKeys?: string[];
|
|
56
|
+
/** Called with the selected keys when the selection changes. */
|
|
52
57
|
onSelectionChange?: ((keys: string[]) => void) | undefined;
|
|
53
58
|
/** Enter on a row, a double-click, or a click when nothing is selectable. */
|
|
54
59
|
onAction?: ((item: T, index: number) => void) | undefined;
|
|
@@ -59,8 +64,11 @@ export interface VirtualListProps<T> {
|
|
|
59
64
|
onMove?: ((keys: string[], to: number) => void) | undefined;
|
|
60
65
|
/** Shown when there are no items. */
|
|
61
66
|
empty?: ReactNode;
|
|
67
|
+
/** Replace the built-in English text: the announcement after a move. */
|
|
62
68
|
labels?: Partial<VirtualListLabels>;
|
|
69
|
+
/** Row height and text size. Default "md". */
|
|
63
70
|
size?: "sm" | "md";
|
|
71
|
+
/** Added to the root element, for layout. */
|
|
64
72
|
className?: string;
|
|
65
73
|
/** Layout only (e.g. `blockSize`). Restyle through --cy-virtual-list-* tokens. */
|
|
66
74
|
style?: CSSProperties;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useControllableState as ze } from "../../foundations/controllable.js";
|
|
3
3
|
import { useClientLayoutEffect as _ } from "../../foundations/client-layout-effect.js";
|
|
4
4
|
import { clamp as L } from "../../foundations/math.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { seekEnabled as De } from "../../foundations/listbox.js";
|
|
6
|
+
import { useDrag as Te } from "../../foundations/drag.js";
|
|
7
7
|
import { useVirtualWindow as Ee } from "../../foundations/virtual-window.js";
|
|
8
8
|
import { moveItems as He } from "../../foundations/reorder.js";
|
|
9
9
|
import { useImperativeHandle as Ne, useRef as k, useState as b } from "react";
|
|
@@ -70,7 +70,7 @@ function Be({ label: x, items: a, getKey: S, renderItem: B, isDisabled: se, sele
|
|
|
70
70
|
}, we = (e) => {
|
|
71
71
|
$(s[e]), E.current = !0;
|
|
72
72
|
}, H = (e, t) => {
|
|
73
|
-
const r =
|
|
73
|
+
const r = De(s.length, e, t, (n) => !i(n));
|
|
74
74
|
return r < 0 ? e : r;
|
|
75
75
|
}, N = (e, t) => {
|
|
76
76
|
const r = L(e, 0, s.length - 1);
|
|
@@ -81,7 +81,7 @@ function Be({ label: x, items: a, getKey: S, renderItem: B, isDisabled: se, sele
|
|
|
81
81
|
const r = L(t, 0, s.length - e.length);
|
|
82
82
|
He(s, e, r, (n) => n).every((n, c) => n === s[c]) || (D?.(e, r), he(de.moved(e.length, r + 1, s.length)), E.current = !0);
|
|
83
83
|
}, ke = (e) => s.filter((t) => !e.includes(t) && s.indexOf(t) < s.indexOf(e[0])).length;
|
|
84
|
-
|
|
84
|
+
Te(u, {
|
|
85
85
|
distance: 4,
|
|
86
86
|
touchAction: "css",
|
|
87
87
|
onStart: ({ pointerType: e, path: t }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualList.js","names":["_Fragment","useControllableState","useClientLayoutEffect","clamp","useDrag","seekEnabled","useVirtualWindow","moveItems","useImperativeHandle","useRef","useState","Fragment$1","jsx","jsxs","DEFAULT_LABELS","count","position","total","VirtualList","label","items","getKey","renderItem","isDisabled","selectionMode","selectedKeys","defaultSelectedKeys","onSelectionChange","onAction","onMove","wrap","follow","isHeader","handle","empty","labels","size","className","style","root","picked","choose","focusKey","setFocusKey","moveFocus","anchor","text","said","setSaid","drag","setDragState","dragRef","setDrag","next","keys","item","i","header","off","firstEnabled","_","focusIndex","pickedIndex","k","stop","measured","setMeasured","line","setLine","sizes","win","rows","row","key","h","top","gapAt","y","atEnd","scrollToEnd","el","index","align","pinned","first","toggle","go","seek","from","step","near","at","ahead","blockFrom","n","move","block","to","placeOf","pointerType","path","point","box","gap","cancelled","d","onKeyDown","event","page","multi","target","lo","hi","range","onRowClick","rootClass","disabled","selected"],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n type Ref,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { seekEnabled } from \"../../foundations/listbox.js\";\nimport { clamp } from \"../../foundations/math.js\";\nimport { moveItems } from \"../../foundations/reorder.js\";\nimport { useVirtualWindow } from \"../../foundations/virtual-window.js\";\n\nexport interface VirtualListTokens {\n /** Height of the list (it scrolls inside). */\n height: string;\n /** Minimum row height. */\n rowHeight: string;\n /** Background of the chosen rows. */\n selectedBackground: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n virtualList: VirtualListTokens;\n }\n}\n\nexport interface VirtualItemState {\n index: number;\n selected: boolean;\n disabled: boolean;\n}\n\n/** What `handle` gives you: scroll a row into view from outside (a search hit, a \"jump to latest\" button). */\nexport interface VirtualListHandle {\n /** Scrolls row `index` into view: `nearest` (default, the least scrolling), `start` or `center`. */\n scrollToIndex: (index: number, align?: \"nearest\" | \"start\" | \"center\") => void;\n /** Scrolls to the last row. */\n scrollToEnd: () => void;\n}\n\nexport interface VirtualListProps<T> {\n /** Accessible name of the list. */\n label: string;\n items: readonly T[];\n /** A stable, unique key per item. */\n getKey: (item: T, index: number) => string;\n /** The content of one row. Rows share one height unless `wrap` is set. */\n renderItem: (item: T, state: VirtualItemState) => ReactNode;\n /** Rows wrap their text and take the height they need (log lines, messages); each is measured as it renders. */\n wrap?: boolean;\n /** Keep the end in view as rows are added, while the list is scrolled to the end (a log, a live feed). */\n follow?: boolean;\n /**\n * Rows that head a section (a date, a group). They cannot be focused or selected, and the current section's heading\n * stays pinned at the top while its rows scroll under it.\n */\n isHeader?: (item: T) => boolean;\n /** `scrollToIndex` and `scrollToEnd`, for scrolling from outside the list. */\n handle?: Ref<VirtualListHandle>;\n isDisabled?: (item: T) => boolean;\n /** \"none\" (a list to act on), \"single\" (default) or \"multiple\". */\n selectionMode?: \"none\" | \"single\" | \"multiple\";\n selectedKeys?: string[] | undefined;\n defaultSelectedKeys?: string[];\n onSelectionChange?: ((keys: string[]) => void) | undefined;\n /** Enter on a row, a double-click, or a click when nothing is selectable. */\n onAction?: ((item: T, index: number) => void) | undefined;\n /**\n * Reordering: Alt+Up/Down moves the selection (or the focused row), and so does dragging it with a mouse or pen.\n * `keys` are the rows moved, in order; `to` is where the first of them lands in the new order. `moveItems` applies it.\n */\n onMove?: ((keys: string[], to: number) => void) | undefined;\n /** Shown when there are no items. */\n empty?: ReactNode;\n labels?: Partial<VirtualListLabels>;\n size?: \"sm\" | \"md\";\n className?: string;\n /** Layout only (e.g. `blockSize`). Restyle through --cy-virtual-list-* tokens. */\n style?: CSSProperties;\n}\n\nexport interface VirtualListLabels {\n /** Announced after a move. Default \"Moved to position 5 of 120\" or \"Moved 3 rows to position 5 of 120\". */\n moved: (count: number, position: number, total: number) => string;\n}\n\nconst DEFAULT_LABELS: VirtualListLabels = {\n moved: (count, position, total) =>\n count === 1\n ? `Moved to position ${position} of ${total}`\n : `Moved ${count} rows to position ${position} of ${total}`,\n};\n\nexport { moveItems };\n\n/**\n * A long list (thousands of rows) that renders only the rows in view: logs, file lists, search results. An APG listbox\n * with one tab stop; the focused row is always rendered, so focus survives scrolling.\n */\nexport function VirtualList<T>({\n label,\n items,\n getKey,\n renderItem,\n isDisabled,\n selectionMode = \"single\",\n selectedKeys,\n defaultSelectedKeys = [],\n onSelectionChange,\n onAction,\n onMove,\n wrap = false,\n follow = false,\n isHeader,\n handle,\n empty,\n labels,\n size = \"md\",\n className,\n style,\n}: VirtualListProps<T>) {\n const root = useRef<HTMLDivElement>(null);\n const [picked, choose] = useControllableState(selectedKeys, defaultSelectedKeys, onSelectionChange);\n const [focusKey, setFocusKey] = useState<string | null>(null);\n const moveFocus = useRef(false);\n const anchor = useRef<number | null>(null);\n const text = { ...DEFAULT_LABELS, ...labels };\n const [said, setSaid] = useState(\"\");\n /** While dragging: the rows moved and the gap they would drop into (0 to the row count). */\n const [drag, setDragState] = useState<{ block: string[]; gap: number } | null>(null);\n const dragRef = useRef(drag);\n const setDrag = (next: typeof drag) => {\n dragRef.current = next;\n setDragState(next);\n };\n\n const keys = items.map((item, i) => getKey(item, i));\n const header = (i: number) => !!isHeader?.(items[i] as T);\n const off = (i: number) => !!isDisabled?.(items[i] as T) || header(i);\n const firstEnabled = keys.findIndex((_, i) => !off(i));\n const focusIndex = focusKey === null ? -1 : keys.indexOf(focusKey);\n const pickedIndex = keys.findIndex((k, i) => picked.includes(k) && !off(i));\n const stop = focusIndex >= 0 ? focusIndex : pickedIndex >= 0 ? pickedIndex : firstEnabled;\n\n // Wrapped rows are measured as they render; rows not yet seen are guessed at the height of one line.\n const [measured, setMeasured] = useState<ReadonlyMap<string, number>>(() => new Map());\n const [line, setLine] = useState(0);\n const sizes = wrap ? keys.map((k) => measured.get(k) ?? line) : undefined;\n const win = useVirtualWindow(root, {\n count: items.length,\n rowSelector: \".cy-virtual-list-row\",\n keep: stop,\n ...(sizes && line ? { sizes } : {}),\n });\n useClientLayoutEffect(() => {\n if (!wrap) return;\n const rows = root.current?.querySelectorAll<HTMLElement>(\".cy-virtual-list-row\") ?? [];\n let next: Map<string, number> | null = null;\n for (const row of rows) {\n const key = keys[Number(row.dataset.index)] as string;\n const h = row.offsetHeight;\n if (h && measured.get(key) !== h) {\n next ??= new Map(measured);\n next.set(key, h);\n }\n }\n if (next) setMeasured(next);\n // One line: the smallest row, so unseen rows are never guessed taller than they can be.\n if (!line && rows.length) setLine(Math.min(...[...rows].map((row) => row.offsetHeight || win.rowSize)));\n });\n const top = (i: number) => (wrap && line ? win.offsetOf(i) : i * win.rowSize);\n /** The gap (0 to the row count) nearest to `y`, in content pixels. */\n const gapAt = (y: number) => {\n if (!(wrap && line)) return clamp(Math.round(y / win.rowSize), 0, keys.length);\n let i = 0;\n while (i < keys.length && top(i) + win.sizeOf(i) / 2 < y) i++;\n return i;\n };\n\n // Following: while the list sits at its end, new rows keep it there.\n const atEnd = useRef(true);\n const scrollToEnd = () => {\n const el = root.current;\n if (el) el.scrollTop = el.scrollHeight;\n };\n useClientLayoutEffect(() => {\n if (follow && atEnd.current) scrollToEnd();\n }, [follow, items.length, win.total]);\n useImperativeHandle(handle, () => ({\n scrollToEnd,\n scrollToIndex: (index, align = \"nearest\") => {\n const el = root.current;\n const i = clamp(index, 0, keys.length - 1);\n if (!el) return;\n if (align === \"nearest\") win.reveal(i);\n else el.scrollTop = align === \"start\" ? top(i) : top(i) + win.sizeOf(i) / 2 - el.clientHeight / 2;\n },\n }));\n\n // The heading pinned at the top: the last header at or above the first row in view.\n let pinned = -1;\n if (isHeader) {\n const first = win.indices.length\n ? Math.min(...win.indices.filter((i) => top(i) + win.sizeOf(i) > win.view.top))\n : -1;\n for (let i = Math.min(first, keys.length - 1); i >= 0; i--)\n if (header(i)) {\n pinned = i;\n break;\n }\n }\n\n useClientLayoutEffect(() => {\n if (!moveFocus.current) return;\n moveFocus.current = false;\n win.reveal(stop);\n root.current?.querySelector<HTMLElement>(`[data-index=\"${stop}\"]`)?.focus({ preventScroll: true });\n });\n\n const toggle = (i: number) => {\n const key = keys[i] as string;\n if (selectionMode === \"single\") choose([key]);\n else if (selectionMode === \"multiple\")\n choose(picked.includes(key) ? picked.filter((k) => k !== key) : [...picked, key]);\n };\n const go = (i: number) => {\n setFocusKey(keys[i] as string);\n moveFocus.current = true;\n };\n /** The next enabled row from `from` in direction `step`, or `from` itself when there is none. */\n const seek = (from: number, step: 1 | -1) => {\n const i = seekEnabled(keys.length, from, step, (n) => !off(n));\n return i < 0 ? from : i;\n };\n /** Row `i` (clamped), or the nearest enabled row to it, looking in direction `step` first. */\n const near = (i: number, step: 1 | -1) => {\n const at = clamp(i, 0, keys.length - 1);\n if (!off(at)) return at;\n const ahead = seek(at, step);\n return ahead !== at ? ahead : seek(at, step === 1 ? -1 : 1);\n };\n\n /** What moves from row `i`: the selection if `i` is in it, else row `i` alone. Disabled rows stay. */\n const blockFrom = (i: number) =>\n picked.includes(keys[i] as string)\n ? keys.filter((k, n) => picked.includes(k) && !off(n))\n : [keys[i] as string];\n /** Moves `block` so its first row lands at `to` among the rows that stay, and announces it. */\n const move = (block: string[], to: number) => {\n const at = clamp(to, 0, keys.length - block.length);\n const next = moveItems(keys, block, at, (k) => k);\n if (next.every((k, n) => k === keys[n])) return;\n onMove?.(block, at);\n setSaid(text.moved(block.length, at + 1, keys.length));\n moveFocus.current = true;\n };\n /** Where `block`'s first row is now, counted among the rows that stay. */\n const placeOf = (block: string[]) =>\n keys.filter((k) => !block.includes(k) && keys.indexOf(k) < keys.indexOf(block[0] as string)).length;\n\n // Dragging the selection with a mouse or pen. A finger scrolls the list instead.\n useDrag(root, {\n distance: 4,\n touchAction: \"css\",\n onStart: ({ pointerType, path }) => {\n if (!onMove || pointerType === \"touch\") return false;\n // The row pressed, from the press's own path (the current event is a move on the window).\n const row = path.find(\n (n): n is HTMLElement => n instanceof HTMLElement && n.classList.contains(\"cy-virtual-list-row\"),\n );\n const i = row ? Number(row.dataset.index) : -1;\n if (i < 0 || off(i)) return false;\n setDrag({ block: blockFrom(i), gap: i });\n },\n onMove: ({ point }) => {\n const el = root.current as HTMLDivElement;\n const box = el.getBoundingClientRect();\n // Near an edge, scroll toward it so a drop far away is reachable.\n if (point.y < box.top + win.rowSize) el.scrollTop -= win.rowSize / 2;\n else if (point.y > box.bottom - win.rowSize) el.scrollTop += win.rowSize / 2;\n const gap = gapAt(point.y - box.top + el.scrollTop);\n setDrag({ ...(dragRef.current as { block: string[]; gap: number }), gap });\n },\n onEnd: (_, cancelled) => {\n const d = dragRef.current as { block: string[]; gap: number };\n setDrag(null);\n if (cancelled) return;\n move(d.block, keys.slice(0, d.gap).filter((k) => !d.block.includes(k)).length);\n },\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (onMove && event.altKey && (event.key === \"ArrowUp\" || event.key === \"ArrowDown\")) {\n event.preventDefault();\n if (off(stop)) return;\n const block = blockFrom(stop);\n move(block, placeOf(block) + (event.key === \"ArrowUp\" ? -1 : 1));\n return;\n }\n const page = Math.max(1, Math.floor((root.current as HTMLDivElement).clientHeight / win.rowSize) - 1);\n const multi = selectionMode === \"multiple\";\n let target: number | null = null;\n switch (event.key) {\n case \"ArrowDown\":\n target = seek(stop, 1);\n break;\n case \"ArrowUp\":\n target = seek(stop, -1);\n break;\n case \"PageDown\":\n target = near(stop + page, 1);\n break;\n case \"PageUp\":\n target = near(stop - page, -1);\n break;\n case \"Home\":\n target = near(0, 1);\n break;\n case \"End\":\n target = near(keys.length - 1, -1);\n break;\n case \" \":\n event.preventDefault();\n if (!off(stop)) toggle(stop);\n anchor.current = stop;\n return;\n case \"Enter\":\n event.preventDefault();\n if (off(stop)) return;\n if (onAction) onAction(items[stop] as T, stop);\n else toggle(stop);\n return;\n case \"a\":\n if (multi && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n choose(keys.filter((_, i) => !off(i)));\n }\n return;\n default:\n return;\n }\n event.preventDefault();\n if (multi && event.shiftKey && target !== stop && !off(target)) {\n // Shift+arrows extend the selection from where it was anchored.\n const from = anchor.current ?? stop;\n const lo = Math.min(from, target);\n const hi = Math.max(from, target);\n const range = keys.filter((_, i) => i >= lo && i <= hi && !off(i));\n choose([...picked.filter((k) => !range.includes(k)), ...range]);\n anchor.current = from;\n } else anchor.current = target;\n go(target);\n };\n\n const onRowClick = (i: number) => {\n setFocusKey(keys[i] as string);\n anchor.current = i;\n if (off(i)) return;\n if (selectionMode === \"none\") onAction?.(items[i] as T, i);\n else toggle(i);\n };\n\n const rootClass = className ? `cy-virtual-list ${className}` : \"cy-virtual-list\";\n // An empty listbox is invalid ARIA: with no items the list is just its message.\n if (items.length === 0)\n return (\n <div ref={root} className={rootClass} data-size={size} style={style}>\n <div className=\"cy-virtual-list-empty cy-reset\">{empty}</div>\n </div>\n );\n return (\n <>\n <div\n ref={root}\n role=\"listbox\"\n aria-label={label}\n aria-multiselectable={selectionMode === \"multiple\" || undefined}\n className={rootClass}\n data-size={size}\n data-wrap={wrap ? \"\" : undefined}\n style={style}\n onKeyDown={onKeyDown}\n onScroll={(e) => {\n const el = e.currentTarget;\n atEnd.current = el.scrollTop + el.clientHeight >= el.scrollHeight - 2;\n win.onScroll(el.scrollTop);\n }}\n >\n {pinned >= 0 && win.view.top > top(pinned) && (\n <div className=\"cy-virtual-list-pinned cy-reset\" aria-hidden=\"true\">\n {renderItem(items[pinned] as T, { index: pinned, selected: false, disabled: true })}\n </div>\n )}\n <div className=\"cy-virtual-list-space cy-reset\" style={{ blockSize: win.total }} aria-hidden=\"true\" />\n {drag && (\n <div\n className=\"cy-virtual-list-drop cy-reset\"\n style={{ insetBlockStart: drag.gap < keys.length ? top(drag.gap) : win.total }}\n aria-hidden=\"true\"\n />\n )}\n {win.indices.map((i) => {\n const key = keys[i] as string;\n const disabled = off(i);\n const selected = selectionMode !== \"none\" && picked.includes(key);\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: the listbox handles keys for every row (roving focus)\n <div\n key={key}\n role=\"option\"\n data-index={i}\n aria-selected={selectionMode === \"none\" ? undefined : selected}\n aria-disabled={disabled || undefined}\n aria-posinset={i + 1}\n aria-setsize={items.length}\n tabIndex={i === stop ? 0 : -1}\n className=\"cy-virtual-list-row cy-reset\"\n data-moving={drag?.block.includes(key) ? \"\" : undefined}\n data-header={header(i) ? \"\" : undefined}\n style={{ insetBlockStart: top(i) }}\n onClick={() => onRowClick(i)}\n // Focus can arrive without our keys (a screen reader, a script): keys then act from here.\n onFocus={() => focusKey !== key && setFocusKey(key)}\n onDoubleClick={() => !disabled && selectionMode !== \"none\" && onAction?.(items[i] as T, i)}\n >\n {renderItem(items[i] as T, { index: i, selected, disabled })}\n </div>\n );\n })}\n </div>\n {onMove && (\n <span className=\"cy-visually-hidden\" role=\"status\">\n {said}\n </span>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AA4FA,IAAMc,KAAoC,EACxC,OAAA,CAAQC,GAAOC,GAAUC,MACvBF,MAAU,IACN,qBAAqBC,CAAA,OAAeC,CAAA,KACpC,SAASF,CAAA,qBAA0BC,CAAA,OAAeC,CAAA,GAC1D;AAQA,SAAgBC,GAAe,EAC7B,OAAAC,GACA,OAAAC,GACA,QAAAC,GACA,YAAAC,GACA,YAAAC,IACA,eAAAC,IAAgB,UAChB,cAAAC,IACA,qBAAAC,KAAsB,CAAC,GACvB,mBAAAC,IACA,UAAAC,GACA,QAAAC,GACA,MAAAC,IAAO,IACP,QAAAC,IAAS,IACT,UAAAC,GACA,QAAAC,IACA,OAAAC,IACA,QAAAC,IACA,MAAA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CAAKd,MAAM;AACtB,cAAMiB,IAAMnB,EAAKE,CAAA,GACX4D,IAAW1D,EAAIF,CAAC,GAChB6D,IAAW7F,MAAkB,UAAUgB,EAAO,SAASiC,CAAG;AAChE,eAEE,gBAAA7D,EAAC,OAAD;AAAA,UAEE,MAAK;AAAA,UACL,cAAY4C;AAAA,UACZ,iBAAehC,MAAkB,SAAS,SAAY6F;AAAA,UACtD,iBAAeD,KAAY;AAAA,UAC3B,iBAAe5D,IAAI;AAAA,UACnB,gBAAcpC,EAAM;AAAA,UACpB,UAAUoC,MAAMQ,IAAO,IAAI;AAAA,UAC3B,WAAU;AAAA,UACV,eAAaf,GAAM,MAAM,SAASwB,CAAG,IAAI,KAAK;AAAA,UAC9C,eAAahB,EAAOD,CAAC,IAAI,KAAK;AAAA,UAC9B,OAAO,EAAE,iBAAiBmB,EAAInB,CAAC,EAAE;AAAA,UACjC,SAAA,MAAe0D,GAAW1D,CAAC;AAAA,UAE3B,SAAA,MAAed,MAAa+B,KAAO9B,EAAY8B,CAAG;AAAA,UAClD,eAAA,MAAqB,CAAC2C,KAAY5F,MAAkB,UAAUI,IAAWR,EAAMoC,CAAA,GAASA,CAAC;AAAA,UAExF,UAAAlC,EAAWF,EAAMoC,CAAA,GAAS;AAAA,YAAE,OAAOA;AAAA,YAAG,UAAA6D;AAAA,YAAU,UAAAD;AAAA,UAAS,CAAC;AAAA,QACxD,GAlBE3C,CAkBF;AAAA,MAET,CAAC;AAAA,IACE;AAAA,EACJ,CAAA,GAAA5C,KACC,gBAAAjB,EAAC,QAAD;AAAA,IAAM,WAAU;AAAA,IAAqB,MAAK;AAAA,IACvC,UAAAmC;AAAA,EACG,CAAA,CAER,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"VirtualList.js","names":["_Fragment","useControllableState","useClientLayoutEffect","clamp","seekEnabled","useDrag","useVirtualWindow","moveItems","useImperativeHandle","useRef","useState","Fragment$1","jsx","jsxs","DEFAULT_LABELS","count","position","total","VirtualList","label","items","getKey","renderItem","isDisabled","selectionMode","selectedKeys","defaultSelectedKeys","onSelectionChange","onAction","onMove","wrap","follow","isHeader","handle","empty","labels","size","className","style","root","picked","choose","focusKey","setFocusKey","moveFocus","anchor","text","said","setSaid","drag","setDragState","dragRef","setDrag","next","keys","item","i","header","off","firstEnabled","_","focusIndex","pickedIndex","k","stop","measured","setMeasured","line","setLine","sizes","win","rows","row","key","h","top","gapAt","y","atEnd","scrollToEnd","el","index","align","pinned","first","toggle","go","seek","from","step","near","at","ahead","blockFrom","n","move","block","to","placeOf","pointerType","path","point","box","gap","cancelled","d","onKeyDown","event","page","multi","target","lo","hi","range","onRowClick","rootClass","disabled","selected"],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n type Ref,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { seekEnabled } from \"../../foundations/listbox.js\";\nimport { clamp } from \"../../foundations/math.js\";\nimport { moveItems } from \"../../foundations/reorder.js\";\nimport { useVirtualWindow } from \"../../foundations/virtual-window.js\";\n\nexport interface VirtualListTokens {\n /** Height of the list (it scrolls inside). */\n height: string;\n /** Minimum row height. */\n rowHeight: string;\n /** Background of the chosen rows. */\n selectedBackground: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n virtualList: VirtualListTokens;\n }\n}\n\nexport interface VirtualItemState {\n index: number;\n selected: boolean;\n disabled: boolean;\n}\n\n/** What `handle` gives you: scroll a row into view from outside (a search hit, a \"jump to latest\" button). */\nexport interface VirtualListHandle {\n /** Scrolls row `index` into view: `nearest` (default, the least scrolling), `start` or `center`. */\n scrollToIndex: (index: number, align?: \"nearest\" | \"start\" | \"center\") => void;\n /** Scrolls to the last row. */\n scrollToEnd: () => void;\n}\n\nexport interface VirtualListProps<T> {\n /** Accessible name of the list. */\n label: string;\n /** The data, one entry per row. */\n items: readonly T[];\n /** A stable, unique key per item. */\n getKey: (item: T, index: number) => string;\n /** The content of one row. Rows share one height unless `wrap` is set. */\n renderItem: (item: T, state: VirtualItemState) => ReactNode;\n /** Rows wrap their text and take the height they need (log lines, messages); each is measured as it renders. */\n wrap?: boolean;\n /** Keep the end in view as rows are added, while the list is scrolled to the end (a log, a live feed). */\n follow?: boolean;\n /**\n * Rows that head a section (a date, a group). They cannot be focused or selected, and the current section's heading\n * stays pinned at the top while its rows scroll under it.\n */\n isHeader?: (item: T) => boolean;\n /** `scrollToIndex` and `scrollToEnd`, for scrolling from outside the list. */\n handle?: Ref<VirtualListHandle>;\n /** Return true for rows that cannot be selected; the arrow keys skip them. */\n isDisabled?: (item: T) => boolean;\n /** \"none\" (a list to act on), \"single\" (default) or \"multiple\". */\n selectionMode?: \"none\" | \"single\" | \"multiple\";\n /** Keys of the selected rows (controlled). */\n selectedKeys?: string[] | undefined;\n /** Keys of the rows selected at the start when uncontrolled. */\n defaultSelectedKeys?: string[];\n /** Called with the selected keys when the selection changes. */\n onSelectionChange?: ((keys: string[]) => void) | undefined;\n /** Enter on a row, a double-click, or a click when nothing is selectable. */\n onAction?: ((item: T, index: number) => void) | undefined;\n /**\n * Reordering: Alt+Up/Down moves the selection (or the focused row), and so does dragging it with a mouse or pen.\n * `keys` are the rows moved, in order; `to` is where the first of them lands in the new order. `moveItems` applies it.\n */\n onMove?: ((keys: string[], to: number) => void) | undefined;\n /** Shown when there are no items. */\n empty?: ReactNode;\n /** Replace the built-in English text: the announcement after a move. */\n labels?: Partial<VirtualListLabels>;\n /** Row height and text size. Default \"md\". */\n size?: \"sm\" | \"md\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only (e.g. `blockSize`). Restyle through --cy-virtual-list-* tokens. */\n style?: CSSProperties;\n}\n\nexport interface VirtualListLabels {\n /** Announced after a move. Default \"Moved to position 5 of 120\" or \"Moved 3 rows to position 5 of 120\". */\n moved: (count: number, position: number, total: number) => string;\n}\n\nconst DEFAULT_LABELS: VirtualListLabels = {\n moved: (count, position, total) =>\n count === 1\n ? `Moved to position ${position} of ${total}`\n : `Moved ${count} rows to position ${position} of ${total}`,\n};\n\nexport { moveItems };\n\n/**\n * A long list (thousands of rows) that renders only the rows in view: logs, file lists, search results. An APG listbox\n * with one tab stop; the focused row is always rendered, so focus survives scrolling.\n */\nexport function VirtualList<T>({\n label,\n items,\n getKey,\n renderItem,\n isDisabled,\n selectionMode = \"single\",\n selectedKeys,\n defaultSelectedKeys = [],\n onSelectionChange,\n onAction,\n onMove,\n wrap = false,\n follow = false,\n isHeader,\n handle,\n empty,\n labels,\n size = \"md\",\n className,\n style,\n}: VirtualListProps<T>) {\n const root = useRef<HTMLDivElement>(null);\n const [picked, choose] = useControllableState(selectedKeys, defaultSelectedKeys, onSelectionChange);\n const [focusKey, setFocusKey] = useState<string | null>(null);\n const moveFocus = useRef(false);\n const anchor = useRef<number | null>(null);\n const text = { ...DEFAULT_LABELS, ...labels };\n const [said, setSaid] = useState(\"\");\n /** While dragging: the rows moved and the gap they would drop into (0 to the row count). */\n const [drag, setDragState] = useState<{ block: string[]; gap: number } | null>(null);\n const dragRef = useRef(drag);\n const setDrag = (next: typeof drag) => {\n dragRef.current = next;\n setDragState(next);\n };\n\n const keys = items.map((item, i) => getKey(item, i));\n const header = (i: number) => !!isHeader?.(items[i] as T);\n const off = (i: number) => !!isDisabled?.(items[i] as T) || header(i);\n const firstEnabled = keys.findIndex((_, i) => !off(i));\n const focusIndex = focusKey === null ? -1 : keys.indexOf(focusKey);\n const pickedIndex = keys.findIndex((k, i) => picked.includes(k) && !off(i));\n const stop = focusIndex >= 0 ? focusIndex : pickedIndex >= 0 ? pickedIndex : firstEnabled;\n\n // Wrapped rows are measured as they render; rows not yet seen are guessed at the height of one line.\n const [measured, setMeasured] = useState<ReadonlyMap<string, number>>(() => new Map());\n const [line, setLine] = useState(0);\n const sizes = wrap ? keys.map((k) => measured.get(k) ?? line) : undefined;\n const win = useVirtualWindow(root, {\n count: items.length,\n rowSelector: \".cy-virtual-list-row\",\n keep: stop,\n ...(sizes && line ? { sizes } : {}),\n });\n useClientLayoutEffect(() => {\n if (!wrap) return;\n const rows = root.current?.querySelectorAll<HTMLElement>(\".cy-virtual-list-row\") ?? [];\n let next: Map<string, number> | null = null;\n for (const row of rows) {\n const key = keys[Number(row.dataset.index)] as string;\n const h = row.offsetHeight;\n if (h && measured.get(key) !== h) {\n next ??= new Map(measured);\n next.set(key, h);\n }\n }\n if (next) setMeasured(next);\n // One line: the smallest row, so unseen rows are never guessed taller than they can be.\n if (!line && rows.length) setLine(Math.min(...[...rows].map((row) => row.offsetHeight || win.rowSize)));\n });\n const top = (i: number) => (wrap && line ? win.offsetOf(i) : i * win.rowSize);\n /** The gap (0 to the row count) nearest to `y`, in content pixels. */\n const gapAt = (y: number) => {\n if (!(wrap && line)) return clamp(Math.round(y / win.rowSize), 0, keys.length);\n let i = 0;\n while (i < keys.length && top(i) + win.sizeOf(i) / 2 < y) i++;\n return i;\n };\n\n // Following: while the list sits at its end, new rows keep it there.\n const atEnd = useRef(true);\n const scrollToEnd = () => {\n const el = root.current;\n if (el) el.scrollTop = el.scrollHeight;\n };\n useClientLayoutEffect(() => {\n if (follow && atEnd.current) scrollToEnd();\n }, [follow, items.length, win.total]);\n useImperativeHandle(handle, () => ({\n scrollToEnd,\n scrollToIndex: (index, align = \"nearest\") => {\n const el = root.current;\n const i = clamp(index, 0, keys.length - 1);\n if (!el) return;\n if (align === \"nearest\") win.reveal(i);\n else el.scrollTop = align === \"start\" ? top(i) : top(i) + win.sizeOf(i) / 2 - el.clientHeight / 2;\n },\n }));\n\n // The heading pinned at the top: the last header at or above the first row in view.\n let pinned = -1;\n if (isHeader) {\n const first = win.indices.length\n ? Math.min(...win.indices.filter((i) => top(i) + win.sizeOf(i) > win.view.top))\n : -1;\n for (let i = Math.min(first, keys.length - 1); i >= 0; i--)\n if (header(i)) {\n pinned = i;\n break;\n }\n }\n\n useClientLayoutEffect(() => {\n if (!moveFocus.current) return;\n moveFocus.current = false;\n win.reveal(stop);\n root.current?.querySelector<HTMLElement>(`[data-index=\"${stop}\"]`)?.focus({ preventScroll: true });\n });\n\n const toggle = (i: number) => {\n const key = keys[i] as string;\n if (selectionMode === \"single\") choose([key]);\n else if (selectionMode === \"multiple\")\n choose(picked.includes(key) ? picked.filter((k) => k !== key) : [...picked, key]);\n };\n const go = (i: number) => {\n setFocusKey(keys[i] as string);\n moveFocus.current = true;\n };\n /** The next enabled row from `from` in direction `step`, or `from` itself when there is none. */\n const seek = (from: number, step: 1 | -1) => {\n const i = seekEnabled(keys.length, from, step, (n) => !off(n));\n return i < 0 ? from : i;\n };\n /** Row `i` (clamped), or the nearest enabled row to it, looking in direction `step` first. */\n const near = (i: number, step: 1 | -1) => {\n const at = clamp(i, 0, keys.length - 1);\n if (!off(at)) return at;\n const ahead = seek(at, step);\n return ahead !== at ? ahead : seek(at, step === 1 ? -1 : 1);\n };\n\n /** What moves from row `i`: the selection if `i` is in it, else row `i` alone. Disabled rows stay. */\n const blockFrom = (i: number) =>\n picked.includes(keys[i] as string)\n ? keys.filter((k, n) => picked.includes(k) && !off(n))\n : [keys[i] as string];\n /** Moves `block` so its first row lands at `to` among the rows that stay, and announces it. */\n const move = (block: string[], to: number) => {\n const at = clamp(to, 0, keys.length - block.length);\n const next = moveItems(keys, block, at, (k) => k);\n if (next.every((k, n) => k === keys[n])) return;\n onMove?.(block, at);\n setSaid(text.moved(block.length, at + 1, keys.length));\n moveFocus.current = true;\n };\n /** Where `block`'s first row is now, counted among the rows that stay. */\n const placeOf = (block: string[]) =>\n keys.filter((k) => !block.includes(k) && keys.indexOf(k) < keys.indexOf(block[0] as string)).length;\n\n // Dragging the selection with a mouse or pen. A finger scrolls the list instead.\n useDrag(root, {\n distance: 4,\n touchAction: \"css\",\n onStart: ({ pointerType, path }) => {\n if (!onMove || pointerType === \"touch\") return false;\n // The row pressed, from the press's own path (the current event is a move on the window).\n const row = path.find(\n (n): n is HTMLElement => n instanceof HTMLElement && n.classList.contains(\"cy-virtual-list-row\"),\n );\n const i = row ? Number(row.dataset.index) : -1;\n if (i < 0 || off(i)) return false;\n setDrag({ block: blockFrom(i), gap: i });\n },\n onMove: ({ point }) => {\n const el = root.current as HTMLDivElement;\n const box = el.getBoundingClientRect();\n // Near an edge, scroll toward it so a drop far away is reachable.\n if (point.y < box.top + win.rowSize) el.scrollTop -= win.rowSize / 2;\n else if (point.y > box.bottom - win.rowSize) el.scrollTop += win.rowSize / 2;\n const gap = gapAt(point.y - box.top + el.scrollTop);\n setDrag({ ...(dragRef.current as { block: string[]; gap: number }), gap });\n },\n onEnd: (_, cancelled) => {\n const d = dragRef.current as { block: string[]; gap: number };\n setDrag(null);\n if (cancelled) return;\n move(d.block, keys.slice(0, d.gap).filter((k) => !d.block.includes(k)).length);\n },\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (onMove && event.altKey && (event.key === \"ArrowUp\" || event.key === \"ArrowDown\")) {\n event.preventDefault();\n if (off(stop)) return;\n const block = blockFrom(stop);\n move(block, placeOf(block) + (event.key === \"ArrowUp\" ? -1 : 1));\n return;\n }\n const page = Math.max(1, Math.floor((root.current as HTMLDivElement).clientHeight / win.rowSize) - 1);\n const multi = selectionMode === \"multiple\";\n let target: number | null = null;\n switch (event.key) {\n case \"ArrowDown\":\n target = seek(stop, 1);\n break;\n case \"ArrowUp\":\n target = seek(stop, -1);\n break;\n case \"PageDown\":\n target = near(stop + page, 1);\n break;\n case \"PageUp\":\n target = near(stop - page, -1);\n break;\n case \"Home\":\n target = near(0, 1);\n break;\n case \"End\":\n target = near(keys.length - 1, -1);\n break;\n case \" \":\n event.preventDefault();\n if (!off(stop)) toggle(stop);\n anchor.current = stop;\n return;\n case \"Enter\":\n event.preventDefault();\n if (off(stop)) return;\n if (onAction) onAction(items[stop] as T, stop);\n else toggle(stop);\n return;\n case \"a\":\n if (multi && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n choose(keys.filter((_, i) => !off(i)));\n }\n return;\n default:\n return;\n }\n event.preventDefault();\n if (multi && event.shiftKey && target !== stop && !off(target)) {\n // Shift+arrows extend the selection from where it was anchored.\n const from = anchor.current ?? stop;\n const lo = Math.min(from, target);\n const hi = Math.max(from, target);\n const range = keys.filter((_, i) => i >= lo && i <= hi && !off(i));\n choose([...picked.filter((k) => !range.includes(k)), ...range]);\n anchor.current = from;\n } else anchor.current = target;\n go(target);\n };\n\n const onRowClick = (i: number) => {\n setFocusKey(keys[i] as string);\n anchor.current = i;\n if (off(i)) return;\n if (selectionMode === \"none\") onAction?.(items[i] as T, i);\n else toggle(i);\n };\n\n const rootClass = className ? `cy-virtual-list ${className}` : \"cy-virtual-list\";\n // An empty listbox is invalid ARIA: with no items the list is just its message.\n if (items.length === 0)\n return (\n <div ref={root} className={rootClass} data-size={size} style={style}>\n <div className=\"cy-virtual-list-empty cy-reset\">{empty}</div>\n </div>\n );\n return (\n <>\n <div\n ref={root}\n role=\"listbox\"\n aria-label={label}\n aria-multiselectable={selectionMode === \"multiple\" || undefined}\n className={rootClass}\n data-size={size}\n data-wrap={wrap ? \"\" : undefined}\n style={style}\n onKeyDown={onKeyDown}\n onScroll={(e) => {\n const el = e.currentTarget;\n atEnd.current = el.scrollTop + el.clientHeight >= el.scrollHeight - 2;\n win.onScroll(el.scrollTop);\n }}\n >\n {pinned >= 0 && win.view.top > top(pinned) && (\n <div className=\"cy-virtual-list-pinned cy-reset\" aria-hidden=\"true\">\n {renderItem(items[pinned] as T, { index: pinned, selected: false, disabled: true })}\n </div>\n )}\n <div className=\"cy-virtual-list-space cy-reset\" style={{ blockSize: win.total }} aria-hidden=\"true\" />\n {drag && (\n <div\n className=\"cy-virtual-list-drop cy-reset\"\n style={{ insetBlockStart: drag.gap < keys.length ? top(drag.gap) : win.total }}\n aria-hidden=\"true\"\n />\n )}\n {win.indices.map((i) => {\n const key = keys[i] as string;\n const disabled = off(i);\n const selected = selectionMode !== \"none\" && picked.includes(key);\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: the listbox handles keys for every row (roving focus)\n <div\n key={key}\n role=\"option\"\n data-index={i}\n aria-selected={selectionMode === \"none\" ? undefined : selected}\n aria-disabled={disabled || undefined}\n aria-posinset={i + 1}\n aria-setsize={items.length}\n tabIndex={i === stop ? 0 : -1}\n className=\"cy-virtual-list-row cy-reset\"\n data-moving={drag?.block.includes(key) ? \"\" : undefined}\n data-header={header(i) ? \"\" : undefined}\n style={{ insetBlockStart: top(i) }}\n onClick={() => onRowClick(i)}\n // Focus can arrive without our keys (a screen reader, a script): keys then act from here.\n onFocus={() => focusKey !== key && setFocusKey(key)}\n onDoubleClick={() => !disabled && selectionMode !== \"none\" && onAction?.(items[i] as T, i)}\n >\n {renderItem(items[i] as T, { index: i, selected, disabled })}\n </div>\n );\n })}\n </div>\n {onMove && (\n <span className=\"cy-visually-hidden\" role=\"status\">\n {said}\n </span>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAoGA,IAAMc,KAAoC,EACxC,OAAA,CAAQC,GAAOC,GAAUC,MACvBF,MAAU,IACN,qBAAqBC,CAAA,OAAeC,CAAA,KACpC,SAASF,CAAA,qBAA0BC,CAAA,OAAeC,CAAA,GAC1D;AAQA,SAAgBC,GAAe,EAC7B,OAAAC,GACA,OAAAC,GACA,QAAAC,GACA,YAAAC,GACA,YAAAC,IACA,eAAAC,IAAgB,UAChB,cAAAC,IACA,qBAAAC,KAAsB,CAAC,GACvB,mBAAAC,IACA,UAAAC,GACA,QAAAC,GACA,MAAAC,IAAO,IACP,QAAAC,IAAS,IACT,UAAAC,GACA,QAAAC,IACA,OAAAC,IACA,QAAAC,IACA,MAAAC,IAAO,MACP,WAAAC,GACA,OAAAC,EAAA,GACsB;AACtB,QAAMC,IAAO9B,EAAuB,IAAI,GAClC,CAAC+B,GAAQC,CAAA,IAAUxC,GAAqBwB,IAA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G;AAChE,eAEE,gBAAA7D,EAAC,OAAD;AAAA,UAEE,MAAK;AAAA,UACL,cAAY4C;AAAA,UACZ,iBAAehC,MAAkB,SAAS,SAAY6F;AAAA,UACtD,iBAAeD,KAAY;AAAA,UAC3B,iBAAe5D,IAAI;AAAA,UACnB,gBAAcpC,EAAM;AAAA,UACpB,UAAUoC,MAAMQ,IAAO,IAAI;AAAA,UAC3B,WAAU;AAAA,UACV,eAAaf,GAAM,MAAM,SAASwB,CAAG,IAAI,KAAK;AAAA,UAC9C,eAAahB,EAAOD,CAAC,IAAI,KAAK;AAAA,UAC9B,OAAO,EAAE,iBAAiBmB,EAAInB,CAAC,EAAE;AAAA,UACjC,SAAA,MAAe0D,GAAW1D,CAAC;AAAA,UAE3B,SAAA,MAAed,MAAa+B,KAAO9B,EAAY8B,CAAG;AAAA,UAClD,eAAA,MAAqB,CAAC2C,KAAY5F,MAAkB,UAAUI,IAAWR,EAAMoC,CAAA,GAASA,CAAC;AAAA,UAExF,UAAAlC,EAAWF,EAAMoC,CAAA,GAAS;AAAA,YAAE,OAAOA;AAAA,YAAG,UAAA6D;AAAA,YAAU,UAAAD;AAAA,UAAS,CAAC;AAAA,QACxD,GAlBE3C,CAkBF;AAAA,MAET,CAAC;AAAA,IACE;AAAA,EACJ,CAAA,GAAA5C,KACC,gBAAAjB,EAAC,QAAD;AAAA,IAAM,WAAU;AAAA,IAAqB,MAAK;AAAA,IACvC,UAAAmC;AAAA,EACG,CAAA,CAER,EAAA,CAAA;AAEN"}
|
|
@@ -16,11 +16,15 @@ export interface ZoomControlsProps {
|
|
|
16
16
|
zoom: ZoomSetting;
|
|
17
17
|
/** The percent it comes to now (DocumentViewport's `onScaleChange` times 100): shown, and stepped from. */
|
|
18
18
|
percent: number;
|
|
19
|
+
/** Called with the new setting when the person zooms in or out, or picks one from the menu. */
|
|
19
20
|
onZoomChange: (zoom: ZoomSetting) => void;
|
|
20
21
|
/** The percents offered in the menu. Default 50, 75, 100, 125, 150, 200, 400. */
|
|
21
22
|
presets?: number[];
|
|
23
|
+
/** Size of the three buttons. Default "sm". */
|
|
22
24
|
size?: Size;
|
|
25
|
+
/** Replace the built-in English text: the names of the toolbar, the buttons and the fit modes. */
|
|
23
26
|
labels?: Partial<ZoomControlsLabels>;
|
|
27
|
+
/** Added to the toolbar element, for layout. */
|
|
24
28
|
className?: string;
|
|
25
29
|
/** Layout only. */
|
|
26
30
|
style?: CSSProperties;
|