@sentry/scraps 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +0 -2
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
- package/dist/clipboard/copyToClipboardButton.js +32 -0
- package/dist/clipboard/index.d.ts +1 -0
- package/dist/clipboard/index.js +1 -0
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.js +1 -0
- package/dist/codeBlock/codeBlock.d.ts +68 -0
- package/dist/codeBlock/codeBlock.js +242 -0
- package/dist/codeBlock/index.d.ts +2 -0
- package/dist/codeBlock/index.js +2 -0
- package/dist/codeBlock/prism.d.ts +11 -0
- package/dist/codeBlock/prism.js +101 -0
- package/dist/codeBlock/styles.d.ts +2 -0
- package/dist/codeBlock/styles.js +133 -0
- package/dist/compactSelect/compactSelect.d.ts +21 -0
- package/dist/compactSelect/compactSelect.js +150 -0
- package/dist/compactSelect/composite.d.ts +54 -0
- package/dist/compactSelect/composite.js +101 -0
- package/dist/compactSelect/control.d.ts +112 -0
- package/dist/compactSelect/control.js +354 -0
- package/dist/compactSelect/fzf.d.ts +8 -0
- package/dist/compactSelect/fzf.js +151 -0
- package/dist/compactSelect/gridList/index.d.ts +46 -0
- package/dist/compactSelect/gridList/index.js +102 -0
- package/dist/compactSelect/gridList/option.d.ts +15 -0
- package/dist/compactSelect/gridList/option.js +111 -0
- package/dist/compactSelect/gridList/section.d.ts +15 -0
- package/dist/compactSelect/gridList/section.js +58 -0
- package/dist/compactSelect/highlightText.d.ts +6 -0
- package/dist/compactSelect/highlightText.js +33 -0
- package/dist/compactSelect/index.d.ts +9 -0
- package/dist/compactSelect/index.js +8 -0
- package/dist/compactSelect/list.d.ts +94 -0
- package/dist/compactSelect/list.js +167 -0
- package/dist/compactSelect/listBox/index.d.ts +84 -0
- package/dist/compactSelect/listBox/index.js +175 -0
- package/dist/compactSelect/listBox/option.d.ts +19 -0
- package/dist/compactSelect/listBox/option.js +101 -0
- package/dist/compactSelect/listBox/section.d.ts +21 -0
- package/dist/compactSelect/listBox/section.js +58 -0
- package/dist/compactSelect/menuComponents.d.ts +89 -0
- package/dist/compactSelect/menuComponents.js +117 -0
- package/dist/compactSelect/selectFilterContext.d.ts +2 -0
- package/dist/compactSelect/selectFilterContext.js +3 -0
- package/dist/compactSelect/styles.d.ts +39 -0
- package/dist/compactSelect/styles.js +155 -0
- package/dist/compactSelect/types.d.ts +1 -0
- package/dist/compactSelect/types.js +0 -0
- package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
- package/dist/compactSelect/useVirtualizedItems.js +74 -0
- package/dist/compactSelect/utils.d.ts +80 -0
- package/dist/compactSelect/utils.js +268 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/descriptionList/descriptionList.js +4 -3
- package/dist/disclosure/disclosure.js +2 -2
- package/dist/dragHandle/dragHandle.d.ts +3 -1
- package/dist/dragHandle/dragHandle.js +8 -5
- package/dist/drawer/components.d.ts +46 -0
- package/dist/drawer/components.js +265 -0
- package/dist/drawer/globalDrawer.d.ts +106 -0
- package/dist/drawer/globalDrawer.js +173 -0
- package/dist/drawer/index.d.ts +3 -0
- package/dist/drawer/index.js +2 -0
- package/dist/drawer/useDrawerResizing.d.ts +19 -0
- package/dist/drawer/useDrawerResizing.js +111 -0
- package/dist/drawer/useDrawerWidth.d.ts +1 -0
- package/dist/drawer/useDrawerWidth.js +42 -0
- package/dist/dropdownMenu/content.d.ts +1 -0
- package/dist/dropdownMenu/content.js +1 -0
- package/dist/dropdownMenu/context.d.ts +24 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +103 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +136 -0
- package/dist/dropdownMenu/item.js +182 -0
- package/dist/dropdownMenu/list.d.ts +59 -0
- package/dist/dropdownMenu/list.js +410 -0
- package/dist/dropdownMenu/search.d.ts +16 -0
- package/dist/dropdownMenu/search.js +16 -0
- package/dist/dropdownMenu/section.d.ts +21 -0
- package/dist/dropdownMenu/section.js +40 -0
- package/dist/dropdownMenu/separator.d.ts +7 -0
- package/dist/dropdownMenu/separator.js +15 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +260 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +55 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useSafetyTriangle.d.ts +12 -0
- package/dist/dropdownMenu/useSafetyTriangle.js +119 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +57 -0
- package/dist/form/FormSearch.d.ts +19 -0
- package/dist/form/FormSearch.js +4 -0
- package/dist/form/autoSaveForm.d.ts +110 -0
- package/dist/form/autoSaveForm.js +100 -0
- package/dist/{formPresentation → form}/displayField.js +2 -2
- package/dist/form/field/baseField.d.ts +23 -0
- package/dist/form/field/baseField.js +116 -0
- package/dist/form/field/checkboxField.d.ts +11 -0
- package/dist/form/field/checkboxField.js +42 -0
- package/dist/form/field/checkboxGroupField.d.ts +16 -0
- package/dist/form/field/checkboxGroupField.js +80 -0
- package/dist/form/field/compactSelectField.d.ts +19 -0
- package/dist/form/field/compactSelectField.js +77 -0
- package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
- package/dist/form/field/inputField.d.ts +19 -0
- package/dist/form/field/inputField.js +31 -0
- package/dist/{formPresentation → form/field}/meta.js +6 -6
- package/dist/form/field/numberField.d.ts +5 -0
- package/dist/form/field/numberField.js +11 -0
- package/dist/form/field/passwordField.d.ts +3 -0
- package/dist/form/field/passwordField.js +27 -0
- package/dist/form/field/radioGroupField.d.ts +16 -0
- package/dist/form/field/radioGroupField.js +92 -0
- package/dist/form/field/rangeField.d.ts +8 -0
- package/dist/form/field/rangeField.js +34 -0
- package/dist/form/field/selectAsyncField.d.ts +31 -0
- package/dist/form/field/selectAsyncField.js +22 -0
- package/dist/form/field/selectField.d.ts +9 -0
- package/dist/form/field/selectField.js +72 -0
- package/dist/form/field/switchField.d.ts +7 -0
- package/dist/form/field/switchField.js +37 -0
- package/dist/form/field/textAreaField.d.ts +7 -0
- package/dist/form/field/textAreaField.js +25 -0
- package/dist/{formPresentation → form}/formContext.js +1 -1
- package/dist/form/formErrorContext/index.d.ts +9 -0
- package/dist/form/formErrorContext/index.js +7 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.js +8 -0
- package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
- package/dist/{formPresentation → form/layout}/base.js +1 -1
- package/dist/form/layout/fieldGroup.d.ts +6 -0
- package/dist/form/layout/fieldGroup.js +60 -0
- package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
- package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
- package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
- package/dist/form/scrapsForm.d.ts +220 -0
- package/dist/form/scrapsForm.js +126 -0
- package/dist/hotkey/hotkey.d.ts +9 -8
- package/dist/hotkey/hotkey.js +13 -6
- package/dist/hotkey/index.d.ts +2 -1
- package/dist/hotkey/index.js +2 -1
- package/dist/hotkey/keyMappings.d.ts +1 -15
- package/dist/hotkey/keyMappings.js +29 -174
- package/dist/hotkey/useHotkeys.d.ts +3 -47
- package/dist/hotkey/useHotkeys.js +8 -42
- package/dist/image/image.js +2 -1
- package/dist/info/infoTip.d.ts +1 -1
- package/dist/info/infoTip.js +4 -3
- package/dist/input/index.d.ts +0 -3
- package/dist/input/index.js +0 -2
- package/dist/input/input.d.ts +2 -0
- package/dist/input/input.js +2 -0
- package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
- package/dist/input/passwordManagerIgnoreProps.js +8 -0
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/layout/styles.d.ts +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +2 -0
- package/dist/link/linkBehaviorContext.js +17 -10
- package/dist/menu/controlContext.d.ts +32 -0
- package/dist/menu/controlContext.js +7 -0
- package/dist/menu/dropdownButton.d.ts +18 -0
- package/dist/menu/dropdownButton.js +66 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +3 -0
- package/dist/menu/menu.d.ts +167 -0
- package/dist/menu/menu.js +568 -0
- package/dist/menu/selectTypes.d.ts +96 -0
- package/dist/menu/selectTypes.js +0 -0
- package/dist/menu/selectValue.d.ts +13 -0
- package/dist/menu/selectValue.js +0 -0
- package/dist/modal/components.d.ts +19 -0
- package/dist/modal/components.js +99 -0
- package/dist/modal/errorBoundary.d.ts +2 -0
- package/dist/modal/errorBoundary.js +35 -0
- package/dist/modal/index.d.ts +33 -0
- package/dist/modal/index.js +260 -0
- package/dist/modal/portal.d.ts +1 -0
- package/dist/modal/portal.js +10 -0
- package/dist/modal/state.d.ts +17 -0
- package/dist/modal/state.js +41 -0
- package/dist/modal/types.d.ts +75 -0
- package/dist/modal/types.js +0 -0
- package/dist/numberInput/index.d.ts +3 -0
- package/dist/numberInput/index.js +2 -0
- package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberDragInput.js +1 -1
- package/dist/{input → numberInput}/numberInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberInput.js +1 -1
- package/dist/overlayContext.d.ts +29 -0
- package/dist/overlayContext.js +7 -0
- package/dist/overlayTrigger.d.ts +22 -0
- package/dist/overlayTrigger.js +30 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/pagination.d.ts +24 -0
- package/dist/pagination/pagination.js +63 -0
- package/dist/pictureInPicture/index.d.ts +2 -0
- package/dist/pictureInPicture/index.js +2 -0
- package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
- package/dist/pictureInPicture/pictureInPicture.js +100 -0
- package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
- package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
- package/dist/pictureInPicture/portalContext.d.ts +2 -0
- package/dist/pictureInPicture/portalContext.js +3 -0
- package/dist/revealOnHover/revealOnHover.js +1 -1
- package/dist/segmentedControl/segmentedControl.js +1 -1
- package/dist/select/filter.d.ts +4 -0
- package/dist/select/filter.js +12 -0
- package/dist/select/index.d.ts +3 -0
- package/dist/select/index.js +2 -0
- package/dist/select/option.d.ts +16 -0
- package/dist/select/option.js +81 -0
- package/dist/select/reactSelectWrapper.d.ts +8 -0
- package/dist/select/reactSelectWrapper.js +25 -0
- package/dist/select/select.d.ts +79 -0
- package/dist/select/select.js +454 -0
- package/dist/select/styles.d.ts +9 -0
- package/dist/select/styles.js +27 -0
- package/dist/select/types.d.ts +60 -0
- package/dist/select/types.js +0 -0
- package/dist/select/virtualizedMenuList.d.ts +24 -0
- package/dist/select/virtualizedMenuList.js +123 -0
- package/dist/slideOverPanel.d.ts +20 -0
- package/dist/slideOverPanel.js +141 -0
- package/dist/slot/knownContexts.d.ts +1 -1
- package/dist/spinner/index.d.ts +1 -0
- package/dist/spinner/index.js +1 -0
- package/dist/spinner/spinner.d.ts +14 -0
- package/dist/spinner/spinner.js +126 -0
- package/dist/splitPanel/index.d.ts +1 -0
- package/dist/splitPanel/index.js +1 -0
- package/dist/splitPanel/splitPanel.d.ts +38 -0
- package/dist/splitPanel/splitPanel.js +145 -0
- package/dist/table/table.d.ts +1 -1
- package/dist/table/table.js +39 -20
- package/dist/table/useColumnResize.d.ts +6 -5
- package/dist/table/useColumnResize.js +5 -4
- package/dist/tabs/index.d.ts +4 -0
- package/dist/tabs/index.js +3 -0
- package/dist/tabs/item.d.ts +13 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +205 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +256 -0
- package/dist/tabs/tabPanels.d.ts +14 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +38 -0
- package/dist/tabs/tabs.js +56 -0
- package/dist/tabs/utils.d.ts +3 -0
- package/dist/tabs/utils.js +6 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/heading.js +1 -1
- package/dist/text/styles.js +1 -1
- package/dist/text/text.d.ts +1 -1
- package/dist/text/text.js +1 -1
- package/dist/theme/dark.js +9 -9
- package/dist/theme/light.js +9 -9
- package/dist/toast/index.d.ts +5 -0
- package/dist/toast/index.js +4 -0
- package/dist/toast/toast.d.ts +10 -0
- package/dist/toast/toast.js +182 -0
- package/dist/toast/toastApi.d.ts +10 -0
- package/dist/toast/toastApi.js +53 -0
- package/dist/toast/toaster.d.ts +4 -0
- package/dist/toast/toaster.js +42 -0
- package/dist/toast/types.d.ts +17 -0
- package/dist/toast/types.js +2 -0
- package/dist/toggleCard/index.d.ts +1 -0
- package/dist/toggleCard/index.js +1 -0
- package/dist/toggleCard/toggleCard.d.ts +32 -0
- package/dist/toggleCard/toggleCard.js +301 -0
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/useDimensions.d.ts +12 -0
- package/dist/useDimensions.js +31 -0
- package/dist/useMedia.d.ts +15 -0
- package/dist/useMedia.js +24 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnClickOutside.js +22 -0
- package/dist/useOverlay.d.ts +1 -0
- package/dist/useOverlay.js +1 -0
- package/dist/useResizableDrawer.d.ts +72 -0
- package/dist/useResizableDrawer.js +136 -0
- package/dist/useVirtualCollection.d.ts +154 -0
- package/dist/useVirtualCollection.js +143 -0
- package/dist/useVirtualRows.d.ts +26 -0
- package/dist/useVirtualRows.js +26 -0
- package/dist/virtualCollectionLayout.d.ts +51 -0
- package/dist/virtualCollectionLayout.js +49 -0
- package/package.json +148 -16
- package/dist/formPresentation/index.d.ts +0 -8
- package/dist/formPresentation/index.js +0 -8
- package/dist/interactionStateLayer/index.d.ts +0 -1
- package/dist/interactionStateLayer/index.js +0 -1
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
- package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
- package/dist/unreachable.d.ts +0 -1
- package/dist/unreachable.js +0 -4
- /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
- /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
- /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
- /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.js +0 -0
- /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
4
|
+
import { css, useTheme } from "@emotion/react";
|
|
5
|
+
import styled from "@emotion/styled";
|
|
6
|
+
import { FocusScope } from "@react-aria/focus";
|
|
7
|
+
import { useKeyboard } from "@react-aria/interactions";
|
|
8
|
+
import { mergeProps } from "@react-aria/utils";
|
|
9
|
+
import { Badge } from "../badge/index.js";
|
|
10
|
+
import { useBoundaryContext } from "../boundaryContext.js";
|
|
11
|
+
import { Button } from "../button/index.js";
|
|
12
|
+
import { Container, Flex, Stack } from "../layout/index.js";
|
|
13
|
+
import { ControlContext, Footer, Header, Search, Title } from "../menu/index.js";
|
|
14
|
+
import { Overlay, PositionWrapper } from "../overlay.js";
|
|
15
|
+
import { OverlayTrigger } from "../overlayTrigger.js";
|
|
16
|
+
import { Spinner } from "../spinner/index.js";
|
|
17
|
+
import { useTranslation } from "../translation/index.js";
|
|
18
|
+
import { useOverlay } from "../useOverlay.js";
|
|
19
|
+
import { getDisabledOptions, getHiddenOptions, getSearchConfig } from "./utils.js";
|
|
20
|
+
function nextFrameCallback(cb) {
|
|
21
|
+
if ('requestAnimationFrame' in window) window.requestAnimationFrame(()=>cb());
|
|
22
|
+
else setTimeout(()=>{
|
|
23
|
+
cb();
|
|
24
|
+
}, 1);
|
|
25
|
+
}
|
|
26
|
+
function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable, onInteractOutside, shouldCloseOnInteractOutside, shouldCloseOnBlur, preventOverflowOptions, flipOptions, disabled, position = 'bottom-start', strategy = 'absolute', offset, hideOptions, menuTitle, maxMenuHeight = '32rem', menuWidth, menuMinWidth, menuHeight, menuHeaderTrailingItems, menuBody, menuFooter, onOpenChange, items = [], isOptionDisabled, value, size = 'md', search: searchConfig, clearable = false, onClear, loading = false, mode = 'list', children, menuRef, ...wrapperProps }) {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const wrapperRef = useRef(null);
|
|
29
|
+
const pendingAutoFocus = useRef(false);
|
|
30
|
+
const normalizedSearch = getSearchConfig(searchConfig);
|
|
31
|
+
const searchEnabled = void 0 !== normalizedSearch;
|
|
32
|
+
const searchFilter = 'function' == typeof normalizedSearch?.filter ? normalizedSearch.filter : void 0;
|
|
33
|
+
const highlightSearch = normalizedSearch?.highlight ?? false;
|
|
34
|
+
const [search, setSearch] = useState('');
|
|
35
|
+
const [searchInputValue, setSearchInputValue] = useState(search);
|
|
36
|
+
const searchRef = useRef(null);
|
|
37
|
+
const updateSearch = (newValue)=>{
|
|
38
|
+
normalizedSearch?.onChange?.(newValue);
|
|
39
|
+
setSearchInputValue(newValue);
|
|
40
|
+
if (normalizedSearch?.filter !== false) setSearch(newValue);
|
|
41
|
+
};
|
|
42
|
+
const selectableOptionCount = useMemo(()=>{
|
|
43
|
+
const { hidden: hiddenOptions } = getHiddenOptions(items, search, 1 / 0, searchFilter);
|
|
44
|
+
const disabledOptions = new Set(getDisabledOptions(items, isOptionDisabled));
|
|
45
|
+
return items.reduce((count, item)=>{
|
|
46
|
+
if ('options' in item) return count + item.options.filter((option)=>!hiddenOptions.has(option.key) && !disabledOptions.has(option.key)).length;
|
|
47
|
+
return count + (hiddenOptions.has(item.key) || disabledOptions.has(item.key) ? 0 : 1);
|
|
48
|
+
}, 0);
|
|
49
|
+
}, [
|
|
50
|
+
items,
|
|
51
|
+
search,
|
|
52
|
+
searchFilter,
|
|
53
|
+
isOptionDisabled
|
|
54
|
+
]);
|
|
55
|
+
const { keyboardProps: searchKeyboardProps } = useKeyboard({
|
|
56
|
+
onKeyDown: (e)=>{
|
|
57
|
+
if ('ArrowDown' === e.key) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
overlayRef.current?.querySelector(`li[role="${'grid' === mode ? 'row' : 'option'}"]`)?.focus();
|
|
60
|
+
}
|
|
61
|
+
if ('Enter' === e.key && !e.nativeEvent.isComposing) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
const firstOption = overlayRef.current?.querySelector(`li[role="${'grid' === mode ? 'row' : 'option'}"]:not([aria-disabled="true"])`);
|
|
64
|
+
const focusOptionList = ()=>{
|
|
65
|
+
if (firstOption) return void firstOption.focus();
|
|
66
|
+
overlayRef.current?.querySelector(`ul[role="${'grid' === mode ? 'grid' : 'listbox'}"]`)?.focus();
|
|
67
|
+
};
|
|
68
|
+
if (selectableOptionCount > 0 && !loading) if (1 === selectableOptionCount && firstOption) firstOption.click();
|
|
69
|
+
else focusOptionList();
|
|
70
|
+
}
|
|
71
|
+
e.continuePropagation();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const overflowBoundaryId = useBoundaryContext();
|
|
75
|
+
const getOverflowBoundary = useCallback(()=>(overflowBoundaryId ? document.getElementById(overflowBoundaryId) : null) ?? document.querySelector('main') ?? document.getElementById('main') ?? void 0, [
|
|
76
|
+
overflowBoundaryId
|
|
77
|
+
]);
|
|
78
|
+
const { isOpen: overlayIsOpen, state: overlayState, triggerRef, triggerProps: overlayTriggerProps, overlayRef, overlayProps } = useOverlay({
|
|
79
|
+
disableTrigger: disabled,
|
|
80
|
+
type: 'grid' === mode ? 'menu' : 'listbox',
|
|
81
|
+
position,
|
|
82
|
+
offset,
|
|
83
|
+
isOpen,
|
|
84
|
+
isDismissable,
|
|
85
|
+
onInteractOutside,
|
|
86
|
+
shouldCloseOnInteractOutside,
|
|
87
|
+
shouldCloseOnBlur,
|
|
88
|
+
preventOverflowOptions,
|
|
89
|
+
getOverflowBoundary,
|
|
90
|
+
flipOptions,
|
|
91
|
+
strategy,
|
|
92
|
+
onOpenChange: (open)=>{
|
|
93
|
+
pendingAutoFocus.current = open;
|
|
94
|
+
onOpenChange?.(open);
|
|
95
|
+
nextFrameCallback(()=>{
|
|
96
|
+
if (open) {
|
|
97
|
+
if (!pendingAutoFocus.current) return;
|
|
98
|
+
pendingAutoFocus.current = false;
|
|
99
|
+
if (searchEnabled) return void searchRef.current?.focus();
|
|
100
|
+
const firstSelectedOption = overlayRef.current?.querySelector(`li[role="${'grid' === mode ? 'row' : 'option'}"][aria-selected="true"]`);
|
|
101
|
+
if (firstSelectedOption) return void firstSelectedOption.focus();
|
|
102
|
+
overlayRef.current?.querySelector(`li[role="${'grid' === mode ? 'row' : 'option'}"]`)?.focus();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
onClose?.();
|
|
106
|
+
setSearchInputValue('');
|
|
107
|
+
setSearch('');
|
|
108
|
+
if (document.activeElement === document.body || wrapperRef.current?.contains(document.activeElement)) triggerRef.current?.focus();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const wasRefAvailable = useRef(false);
|
|
113
|
+
useEffect(()=>{
|
|
114
|
+
if (!triggerRef.current || wasRefAvailable.current) return;
|
|
115
|
+
wasRefAvailable.current = true;
|
|
116
|
+
if (autoFocus && !disabled) triggerRef.current.focus();
|
|
117
|
+
}, [
|
|
118
|
+
autoFocus,
|
|
119
|
+
disabled,
|
|
120
|
+
triggerRef
|
|
121
|
+
]);
|
|
122
|
+
const [menuFullWidth, setMenuFullWidth] = useState();
|
|
123
|
+
const onSearchFocus = ()=>setMenuFullWidth(overlayRef.current?.offsetWidth);
|
|
124
|
+
const onSearchBlur = ()=>!search && setMenuFullWidth(void 0);
|
|
125
|
+
const triggerLabel = useMemo(()=>{
|
|
126
|
+
const values = Array.isArray(value) ? value : [
|
|
127
|
+
value
|
|
128
|
+
];
|
|
129
|
+
const options = items.flatMap((item)=>{
|
|
130
|
+
if ('options' in item) return item.options;
|
|
131
|
+
return item;
|
|
132
|
+
}).filter((item)=>values.includes(item.value));
|
|
133
|
+
if (0 === options.length) return /*#__PURE__*/ jsx(TriggerLabel, {
|
|
134
|
+
children: t('None')
|
|
135
|
+
});
|
|
136
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
137
|
+
children: [
|
|
138
|
+
/*#__PURE__*/ jsx(TriggerLabel, {
|
|
139
|
+
children: options[0]?.label
|
|
140
|
+
}),
|
|
141
|
+
options.length > 1 && /*#__PURE__*/ jsx(StyledBadge, {
|
|
142
|
+
variant: "muted",
|
|
143
|
+
children: `+${options.length - 1}`
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
}, [
|
|
148
|
+
items,
|
|
149
|
+
t,
|
|
150
|
+
value
|
|
151
|
+
]);
|
|
152
|
+
const { keyboardProps: triggerKeyboardProps } = useKeyboard({
|
|
153
|
+
onKeyDown: (e)=>{
|
|
154
|
+
if ('ArrowDown' === e.key || 'ArrowUp' === e.key) {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
overlayState.open();
|
|
157
|
+
} else e.continuePropagation();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const hasSelection = useMemo(()=>{
|
|
161
|
+
if (void 0 === value) return false;
|
|
162
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
163
|
+
return true;
|
|
164
|
+
}, [
|
|
165
|
+
value
|
|
166
|
+
]);
|
|
167
|
+
const contextValue = useMemo(()=>({
|
|
168
|
+
overlayState,
|
|
169
|
+
overlayIsOpen,
|
|
170
|
+
search,
|
|
171
|
+
searchable: searchEnabled,
|
|
172
|
+
size,
|
|
173
|
+
disabled,
|
|
174
|
+
searchMatcher: searchFilter,
|
|
175
|
+
highlightSearch
|
|
176
|
+
}), [
|
|
177
|
+
overlayState,
|
|
178
|
+
overlayIsOpen,
|
|
179
|
+
search,
|
|
180
|
+
searchEnabled,
|
|
181
|
+
size,
|
|
182
|
+
disabled,
|
|
183
|
+
searchFilter,
|
|
184
|
+
highlightSearch
|
|
185
|
+
]);
|
|
186
|
+
const showClearButton = clearable && (hasSelection || !!menuTitle);
|
|
187
|
+
const hasHeader = !!menuTitle || !!menuHeaderTrailingItems || showClearButton;
|
|
188
|
+
const theme = useTheme();
|
|
189
|
+
const mergedTriggerProps = mergeProps({
|
|
190
|
+
id: triggerId,
|
|
191
|
+
children: triggerLabel
|
|
192
|
+
}, triggerKeyboardProps, overlayTriggerProps);
|
|
193
|
+
return /*#__PURE__*/ jsx(ControlContext, {
|
|
194
|
+
value: contextValue,
|
|
195
|
+
children: /*#__PURE__*/ jsxs(Container, {
|
|
196
|
+
width: "max-content",
|
|
197
|
+
position: "relative",
|
|
198
|
+
...wrapperProps,
|
|
199
|
+
children: [
|
|
200
|
+
trigger ? trigger(mergedTriggerProps, overlayIsOpen) : /*#__PURE__*/ jsx(OverlayTrigger.Button, {
|
|
201
|
+
...mergedTriggerProps
|
|
202
|
+
}),
|
|
203
|
+
/*#__PURE__*/ jsx(StyledPositionWrapper, {
|
|
204
|
+
visible: overlayIsOpen,
|
|
205
|
+
zIndex: theme.zIndex?.dropdown,
|
|
206
|
+
...overlayProps,
|
|
207
|
+
children: overlayIsOpen && /*#__PURE__*/ jsx(StyledOverlay, {
|
|
208
|
+
ref: menuRef,
|
|
209
|
+
onFocusCapture: ()=>{
|
|
210
|
+
pendingAutoFocus.current = false;
|
|
211
|
+
},
|
|
212
|
+
width: menuWidth ?? menuFullWidth,
|
|
213
|
+
height: menuHeight,
|
|
214
|
+
minWidth: menuMinWidth ?? overlayProps.style?.minWidth,
|
|
215
|
+
maxWidth: overlayProps.style?.maxWidth ? `calc(${withUnits(overlayProps.style.maxWidth)} * 0.9)` : void 0,
|
|
216
|
+
maxHeight: overlayProps.style?.maxHeight,
|
|
217
|
+
maxHeightProp: maxMenuHeight,
|
|
218
|
+
"data-menu-has-header": hasHeader,
|
|
219
|
+
"data-menu-has-search": searchEnabled,
|
|
220
|
+
"data-menu-has-footer": !!menuFooter,
|
|
221
|
+
children: /*#__PURE__*/ jsxs(FocusScope, {
|
|
222
|
+
contain: true,
|
|
223
|
+
children: [
|
|
224
|
+
hasHeader && /*#__PURE__*/ jsx(Header, {
|
|
225
|
+
borderBottom: searchEnabled ? 'none' : 'muted',
|
|
226
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
|
227
|
+
align: "center",
|
|
228
|
+
justify: "between",
|
|
229
|
+
gap: "xl",
|
|
230
|
+
minHeight: "24px",
|
|
231
|
+
padding: searchEnabled ? 'xs lg 0 lg' : 'xs lg',
|
|
232
|
+
children: [
|
|
233
|
+
menuTitle && /*#__PURE__*/ jsx(Title, {
|
|
234
|
+
children: menuTitle
|
|
235
|
+
}),
|
|
236
|
+
/*#__PURE__*/ jsxs(Flex, {
|
|
237
|
+
align: "center",
|
|
238
|
+
gap: "xs",
|
|
239
|
+
marginLeft: "auto",
|
|
240
|
+
children: [
|
|
241
|
+
loading && /*#__PURE__*/ jsx(StyledSpinner, {
|
|
242
|
+
size: 12
|
|
243
|
+
}),
|
|
244
|
+
'function' == typeof menuHeaderTrailingItems ? menuHeaderTrailingItems({
|
|
245
|
+
closeOverlay: overlayState.close
|
|
246
|
+
}) : menuHeaderTrailingItems,
|
|
247
|
+
showClearButton && /*#__PURE__*/ jsx(ClearButton, {
|
|
248
|
+
onClick: ()=>onClear?.({
|
|
249
|
+
overlayState
|
|
250
|
+
}),
|
|
251
|
+
size: "zero",
|
|
252
|
+
variant: "transparent",
|
|
253
|
+
"aria-hidden": !hasSelection,
|
|
254
|
+
disabled: !hasSelection,
|
|
255
|
+
children: t('Clear')
|
|
256
|
+
})
|
|
257
|
+
]
|
|
258
|
+
})
|
|
259
|
+
]
|
|
260
|
+
})
|
|
261
|
+
}),
|
|
262
|
+
searchEnabled && /*#__PURE__*/ jsx(Search, {
|
|
263
|
+
ref: searchRef,
|
|
264
|
+
placeholder: normalizedSearch?.placeholder ?? 'Search…',
|
|
265
|
+
value: searchInputValue,
|
|
266
|
+
onFocus: onSearchFocus,
|
|
267
|
+
onBlur: onSearchBlur,
|
|
268
|
+
onChange: (e)=>updateSearch(e.target.value),
|
|
269
|
+
...searchKeyboardProps
|
|
270
|
+
}),
|
|
271
|
+
'function' == typeof menuBody ? menuBody({
|
|
272
|
+
closeOverlay: overlayState.close
|
|
273
|
+
}) : menuBody,
|
|
274
|
+
!hideOptions && /*#__PURE__*/ jsx(Stack, {
|
|
275
|
+
minHeight: "0",
|
|
276
|
+
children: children
|
|
277
|
+
}),
|
|
278
|
+
menuFooter && /*#__PURE__*/ jsx(Footer, {
|
|
279
|
+
children: /*#__PURE__*/ jsx(Container, {
|
|
280
|
+
width: "100%",
|
|
281
|
+
children: 'function' == typeof menuFooter ? menuFooter({
|
|
282
|
+
closeOverlay: overlayState.close,
|
|
283
|
+
resetSearch: ()=>updateSearch('')
|
|
284
|
+
}) : menuFooter
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
]
|
|
288
|
+
})
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
]
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const TriggerLabel = styled('span')`
|
|
296
|
+
display: block;
|
|
297
|
+
width: 100%;
|
|
298
|
+
white-space: nowrap;
|
|
299
|
+
overflow: hidden;
|
|
300
|
+
text-overflow: ellipsis;
|
|
301
|
+
text-align: left;
|
|
302
|
+
`;
|
|
303
|
+
const StyledBadge = styled(Badge)`
|
|
304
|
+
margin-left: ${(p)=>p.theme.space.xs};
|
|
305
|
+
flex-shrink: 0;
|
|
306
|
+
top: auto;
|
|
307
|
+
`;
|
|
308
|
+
const StyledSpinner = styled(Spinner)`
|
|
309
|
+
display: flex;
|
|
310
|
+
align-items: center;
|
|
311
|
+
&& {
|
|
312
|
+
margin: 0;
|
|
313
|
+
}
|
|
314
|
+
`;
|
|
315
|
+
const ClearButton = styled(Button)`
|
|
316
|
+
font-weight: ${(p)=>p.theme.font.weight.sans.regular};
|
|
317
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
318
|
+
padding: 0 ${(p)=>p.theme.space.xs};
|
|
319
|
+
margin: 0 -${(p)=>p.theme.space.xs};
|
|
320
|
+
|
|
321
|
+
&[aria-hidden='true'] {
|
|
322
|
+
visibility: hidden;
|
|
323
|
+
}
|
|
324
|
+
`;
|
|
325
|
+
const withUnits = (value)=>'string' == typeof value ? value : `${value}px`;
|
|
326
|
+
const StyledOverlay = styled(Overlay, {
|
|
327
|
+
shouldForwardProp: (prop)=>is_prop_valid(prop)
|
|
328
|
+
})`
|
|
329
|
+
/* Should be a flex container so that when maxHeight is set (to avoid page overflow),
|
|
330
|
+
ListBoxWrap/GridListWrap will also shrink to fit */
|
|
331
|
+
display: flex;
|
|
332
|
+
flex-direction: column;
|
|
333
|
+
overflow: hidden;
|
|
334
|
+
|
|
335
|
+
${(p)=>p.width && css`
|
|
336
|
+
width: ${withUnits(p.width)};
|
|
337
|
+
`}
|
|
338
|
+
${(p)=>p.height && css`
|
|
339
|
+
height: ${withUnits(p.height)};
|
|
340
|
+
`}
|
|
341
|
+
${(p)=>p.minWidth && css`
|
|
342
|
+
min-width: ${withUnits(p.minWidth)};
|
|
343
|
+
`}
|
|
344
|
+
max-width: ${(p)=>p.maxWidth ? `min(${withUnits(p.maxWidth)}, 100%)` : '100%'};
|
|
345
|
+
max-height: ${(p)=>p.maxHeight ? `min(${withUnits(p.maxHeight)}, ${withUnits(p.maxHeightProp)})` : withUnits(p.maxHeightProp)};
|
|
346
|
+
`;
|
|
347
|
+
const StyledPositionWrapper = styled(PositionWrapper, {
|
|
348
|
+
shouldForwardProp: (prop)=>is_prop_valid(prop)
|
|
349
|
+
})`
|
|
350
|
+
min-width: 100%;
|
|
351
|
+
display: ${(p)=>p.visible ? 'block' : 'none'};
|
|
352
|
+
z-index: ${(p)=>p?.zIndex};
|
|
353
|
+
`;
|
|
354
|
+
export { ClearButton, Control, TriggerLabel };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const scoreMatch = 16;
|
|
2
|
+
const scoreGapStart = -3;
|
|
3
|
+
const scoreGapExtention = -1;
|
|
4
|
+
const bonusBoundary = scoreMatch / 2;
|
|
5
|
+
const bonusNonWord = scoreMatch / 2;
|
|
6
|
+
const bonusCamel123 = bonusBoundary + scoreGapExtention;
|
|
7
|
+
const bonusConsecutive = -(scoreGapStart + scoreGapExtention);
|
|
8
|
+
const bonusFirstCharMultiplier = 2;
|
|
9
|
+
const CharCodes = {
|
|
10
|
+
lowerA: 'a'.charCodeAt(0),
|
|
11
|
+
lowerZ: 'z'.charCodeAt(0),
|
|
12
|
+
upperA: 'A'.charCodeAt(0),
|
|
13
|
+
upperZ: 'Z'.charCodeAt(0),
|
|
14
|
+
zero: '0'.charCodeAt(0),
|
|
15
|
+
nine: '9'.charCodeAt(0)
|
|
16
|
+
};
|
|
17
|
+
function getCharClass(c) {
|
|
18
|
+
if (c >= CharCodes.lowerA && c <= CharCodes.lowerZ) return 0;
|
|
19
|
+
if (c >= CharCodes.upperA && c <= CharCodes.upperZ) return 1;
|
|
20
|
+
if (c >= CharCodes.zero && c <= CharCodes.nine) return 2;
|
|
21
|
+
return 3;
|
|
22
|
+
}
|
|
23
|
+
function fzf(text, pattern, caseSensitive) {
|
|
24
|
+
if (0 === pattern.length) return {
|
|
25
|
+
end: 0,
|
|
26
|
+
score: 0,
|
|
27
|
+
start: 0,
|
|
28
|
+
matches: []
|
|
29
|
+
};
|
|
30
|
+
let pidx = 0;
|
|
31
|
+
let sidx = -1;
|
|
32
|
+
let eidx = -1;
|
|
33
|
+
const textLength = text.length;
|
|
34
|
+
const patternLength = pattern.length;
|
|
35
|
+
for(let index = 0; index < textLength; index++){
|
|
36
|
+
let char = text[index];
|
|
37
|
+
if (!caseSensitive) {
|
|
38
|
+
const cc = char.charCodeAt(0);
|
|
39
|
+
if (cc >= 65 && cc <= 90) char = String.fromCharCode(cc + 32);
|
|
40
|
+
}
|
|
41
|
+
const patternchar = pattern[pidx];
|
|
42
|
+
if (char === patternchar) {
|
|
43
|
+
pidx++;
|
|
44
|
+
if (sidx < 0) sidx = index;
|
|
45
|
+
if (pidx === patternLength) {
|
|
46
|
+
eidx = index + 1;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (-1 === eidx) return {
|
|
52
|
+
end: -1,
|
|
53
|
+
score: 0,
|
|
54
|
+
start: -1,
|
|
55
|
+
matches: []
|
|
56
|
+
};
|
|
57
|
+
pidx--;
|
|
58
|
+
for(let index = eidx - 1; index >= sidx; index--){
|
|
59
|
+
let char = text[index];
|
|
60
|
+
if (!caseSensitive) {
|
|
61
|
+
const cc = char.charCodeAt(0);
|
|
62
|
+
if (cc >= 65 && cc <= 90) char = String.fromCharCode(cc + 32);
|
|
63
|
+
}
|
|
64
|
+
const patternchar = pattern[pidx];
|
|
65
|
+
if (char === patternchar) {
|
|
66
|
+
pidx--;
|
|
67
|
+
if (pidx < 0) {
|
|
68
|
+
sidx = index;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const [scoreBase, matches] = calculateScore(text, pattern, sidx, eidx, caseSensitive);
|
|
74
|
+
let score = scoreBase;
|
|
75
|
+
if (0 === sidx && eidx === textLength && textLength === patternLength) score += scoreMatch;
|
|
76
|
+
return {
|
|
77
|
+
start: sidx,
|
|
78
|
+
end: eidx,
|
|
79
|
+
score,
|
|
80
|
+
matches
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function bonusForCharClass(prevClass, currentClass) {
|
|
84
|
+
if (3 === prevClass && 3 !== currentClass) return bonusBoundary;
|
|
85
|
+
if (0 === prevClass && 1 === currentClass || 2 !== prevClass && 2 === currentClass) return bonusCamel123;
|
|
86
|
+
if (3 === currentClass) return bonusNonWord;
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
function calculateScore(text, pattern, sidx, eidx, caseSensitive) {
|
|
90
|
+
let pidx = 0;
|
|
91
|
+
let score = 0;
|
|
92
|
+
let inGap = false;
|
|
93
|
+
let firstBonus = 0;
|
|
94
|
+
let consecutive = 0;
|
|
95
|
+
let prevCharClass = 3;
|
|
96
|
+
const pos = Array.from({
|
|
97
|
+
length: pattern.length
|
|
98
|
+
});
|
|
99
|
+
if (sidx > 0) prevCharClass = getCharClass(text.charCodeAt(sidx - 1));
|
|
100
|
+
for(let idx = sidx; idx < eidx; idx++){
|
|
101
|
+
let char = text[idx];
|
|
102
|
+
if (!caseSensitive) {
|
|
103
|
+
const cc = char.charCodeAt(0);
|
|
104
|
+
if (cc >= 65 && cc <= 90) char = String.fromCharCode(cc + 32);
|
|
105
|
+
}
|
|
106
|
+
const patternchar = pattern[pidx];
|
|
107
|
+
const currentCharClass = getCharClass(char.charCodeAt(0));
|
|
108
|
+
if (char === patternchar) {
|
|
109
|
+
pos[pidx] = idx;
|
|
110
|
+
score += scoreMatch;
|
|
111
|
+
let bonus = bonusForCharClass(prevCharClass, currentCharClass);
|
|
112
|
+
if (0 === consecutive) firstBonus = bonus;
|
|
113
|
+
else {
|
|
114
|
+
if (bonus === bonusBoundary) firstBonus = bonus;
|
|
115
|
+
bonus = Math.max(bonus, firstBonus, bonusConsecutive);
|
|
116
|
+
}
|
|
117
|
+
if (0 === pidx) score += bonus * bonusFirstCharMultiplier;
|
|
118
|
+
else score += bonus;
|
|
119
|
+
inGap = false;
|
|
120
|
+
consecutive++;
|
|
121
|
+
pidx++;
|
|
122
|
+
} else {
|
|
123
|
+
if (inGap) score += scoreGapExtention;
|
|
124
|
+
else score += scoreGapStart;
|
|
125
|
+
inGap = true;
|
|
126
|
+
consecutive = 0;
|
|
127
|
+
firstBonus = 0;
|
|
128
|
+
}
|
|
129
|
+
prevCharClass = currentCharClass;
|
|
130
|
+
}
|
|
131
|
+
if (!pos.length) throw new Error('Calculate score should not be called for a result with no matches');
|
|
132
|
+
const matches = [
|
|
133
|
+
[
|
|
134
|
+
pos[0],
|
|
135
|
+
pos[0] + 1
|
|
136
|
+
]
|
|
137
|
+
];
|
|
138
|
+
for(let i = 1; i < pos.length; i++){
|
|
139
|
+
const lastrange = matches[matches.length - 1];
|
|
140
|
+
if (lastrange[1] === pos[i]) lastrange[1] = pos[i] + 1;
|
|
141
|
+
else matches.push([
|
|
142
|
+
pos[i],
|
|
143
|
+
pos[i] + 1
|
|
144
|
+
]);
|
|
145
|
+
}
|
|
146
|
+
return [
|
|
147
|
+
score,
|
|
148
|
+
matches
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
export { fzf };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { AriaGridListOptions } from '@react-aria/gridlist';
|
|
3
|
+
import type { ListState } from '@react-stately/list';
|
|
4
|
+
import type { CollectionChildren } from '@react-types/shared';
|
|
5
|
+
import type { ListItemBase } from '../types.js';
|
|
6
|
+
import { type GridListOptionProps } from './option.js';
|
|
7
|
+
interface GridListProps<T extends ListItemBase> extends Omit<React.HTMLAttributes<HTMLUListElement>, 'children'>, Omit<AriaGridListOptions<any>, 'disabledKeys' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'autoFocus'> {
|
|
8
|
+
/**
|
|
9
|
+
* Keyboard event handler, to be attached to the list (`ul`) element, to seamlessly
|
|
10
|
+
* move focus from one composite list to another when an arrow key is pressed. Returns
|
|
11
|
+
* a boolean indicating whether the keyboard event was intercepted. If yes, then no
|
|
12
|
+
* further callback function should be run.
|
|
13
|
+
*/
|
|
14
|
+
keyDownHandler: (e: React.KeyboardEvent<HTMLUListElement>) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Object containing the selection state and focus position, needed for
|
|
17
|
+
* `useGridList()`.
|
|
18
|
+
*/
|
|
19
|
+
listState: ListState<T>;
|
|
20
|
+
children?: CollectionChildren<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Text label to be rendered as heading on top of grid list.
|
|
23
|
+
*/
|
|
24
|
+
label?: React.ReactNode;
|
|
25
|
+
size?: GridListOptionProps<ListItemBase>['size'];
|
|
26
|
+
/**
|
|
27
|
+
* Message to be displayed when some options are hidden due to `sizeLimit`.
|
|
28
|
+
*/
|
|
29
|
+
sizeLimitMessage?: string;
|
|
30
|
+
/**
|
|
31
|
+
* If true, virtualization will be enabled for the list.
|
|
32
|
+
*/
|
|
33
|
+
virtualized?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A grid list with accessibile behaviors & attributes.
|
|
37
|
+
* https://react-spectrum.adobe.com/react-aria/useGridList.html
|
|
38
|
+
*
|
|
39
|
+
* Unlike list boxes, grid lists are two-dimensional. Users can press Arrow Up/Down to
|
|
40
|
+
* move between rows (options), and Arrow Left/Right to move between "columns". This is
|
|
41
|
+
* useful when the select options have smaller, interactive elements (buttons/links)
|
|
42
|
+
* inside. Grid lists allow users to focus on those child elements (using the Arrow
|
|
43
|
+
* Left/Right keys) and interact with them, which isn't possible with list boxes.
|
|
44
|
+
*/
|
|
45
|
+
declare function GridList<T extends ListItemBase>({ listState, size, label, sizeLimitMessage, keyDownHandler, virtualized, ...props }: GridListProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
46
|
+
export { GridList };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement } from "@emotion/react";
|
|
3
|
+
import { useContext, useId, useMemo, useRef } from "react";
|
|
4
|
+
import { useGridList } from "@react-aria/gridlist";
|
|
5
|
+
import { mergeProps } from "@react-aria/utils";
|
|
6
|
+
import { SelectFilterContext } from "../selectFilterContext.js";
|
|
7
|
+
import { ListLabel, ListSeparator, ListWrap, SizeLimitMessage } from "../styles.js";
|
|
8
|
+
import { useVirtualizedItems } from "../useVirtualizedItems.js";
|
|
9
|
+
import { hasVisibleLeadingItems } from "../utils.js";
|
|
10
|
+
import { Container } from "../../layout/index.js";
|
|
11
|
+
import { ControlContext, ReserveLeadingSlot } from "../../menu/index.js";
|
|
12
|
+
import { useTranslation } from "../../translation/index.js";
|
|
13
|
+
import { GridListOption } from "./option.js";
|
|
14
|
+
import { GridListSection } from "./section.js";
|
|
15
|
+
function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHandler, virtualized, ...props }) {
|
|
16
|
+
const { t } = useTranslation();
|
|
17
|
+
const ref = useRef(null);
|
|
18
|
+
const labelId = useId();
|
|
19
|
+
const { gridProps } = useGridList({
|
|
20
|
+
...props,
|
|
21
|
+
'aria-labelledby': label ? labelId : props['aria-labelledby']
|
|
22
|
+
}, listState, ref);
|
|
23
|
+
const onKeyDown = (e)=>{
|
|
24
|
+
const continueCallback = keyDownHandler?.(e);
|
|
25
|
+
if (continueCallback && 'Escape' !== e.key) gridProps.onKeyDown?.(e);
|
|
26
|
+
};
|
|
27
|
+
const { overlayIsOpen, searchable } = useContext(ControlContext);
|
|
28
|
+
const hiddenOptions = useContext(SelectFilterContext);
|
|
29
|
+
const listItems = useMemo(()=>[
|
|
30
|
+
...listState.collection
|
|
31
|
+
].filter((node)=>{
|
|
32
|
+
if ('section' === node.type) return ![
|
|
33
|
+
...node.childNodes
|
|
34
|
+
].every((child)=>hiddenOptions.has(child.key));
|
|
35
|
+
return !hiddenOptions.has(node.key);
|
|
36
|
+
}), [
|
|
37
|
+
listState.collection,
|
|
38
|
+
hiddenOptions
|
|
39
|
+
]);
|
|
40
|
+
const reserveLeadingSlot = useMemo(()=>hasVisibleLeadingItems(listItems, hiddenOptions), [
|
|
41
|
+
listItems,
|
|
42
|
+
hiddenOptions
|
|
43
|
+
]);
|
|
44
|
+
const virtualizer = useVirtualizedItems({
|
|
45
|
+
listItems,
|
|
46
|
+
virtualized,
|
|
47
|
+
size
|
|
48
|
+
});
|
|
49
|
+
const mergedProps = mergeProps(gridProps, props);
|
|
50
|
+
return /*#__PURE__*/ jsxs(ReserveLeadingSlot, {
|
|
51
|
+
reserve: reserveLeadingSlot,
|
|
52
|
+
children: [
|
|
53
|
+
0 !== listItems.length && /*#__PURE__*/ jsx(ListSeparator, {
|
|
54
|
+
role: "separator"
|
|
55
|
+
}),
|
|
56
|
+
0 !== listItems.length && label && /*#__PURE__*/ jsx(ListLabel, {
|
|
57
|
+
id: labelId,
|
|
58
|
+
children: label
|
|
59
|
+
}),
|
|
60
|
+
overlayIsOpen && /*#__PURE__*/ jsx(Container, {
|
|
61
|
+
ref: virtualizer.scrollElementRef,
|
|
62
|
+
height: "100%",
|
|
63
|
+
overflowY: "auto",
|
|
64
|
+
children: /*#__PURE__*/ jsx(Container, {
|
|
65
|
+
...virtualizer.wrapperProps,
|
|
66
|
+
children: /*#__PURE__*/ jsxs(ListWrap, {
|
|
67
|
+
...mergedProps,
|
|
68
|
+
style: {
|
|
69
|
+
...mergedProps.style,
|
|
70
|
+
...virtualizer.listWrapStyle
|
|
71
|
+
},
|
|
72
|
+
onKeyDown: onKeyDown,
|
|
73
|
+
ref: ref,
|
|
74
|
+
children: [
|
|
75
|
+
virtualizer.items.map((row)=>{
|
|
76
|
+
const item = listItems[row.index];
|
|
77
|
+
if (!item) return null;
|
|
78
|
+
if ('section' === item.type) return /*#__PURE__*/ createElement(GridListSection, {
|
|
79
|
+
...virtualizer.itemProps(row.index),
|
|
80
|
+
key: item.key,
|
|
81
|
+
node: item,
|
|
82
|
+
listState: listState,
|
|
83
|
+
size: size
|
|
84
|
+
});
|
|
85
|
+
return /*#__PURE__*/ jsx(GridListOption, {
|
|
86
|
+
...virtualizer.itemProps(row.index),
|
|
87
|
+
node: item,
|
|
88
|
+
listState: listState,
|
|
89
|
+
size: size
|
|
90
|
+
}, item.key);
|
|
91
|
+
}),
|
|
92
|
+
!searchable && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
|
|
93
|
+
children: sizeLimitMessage ?? t('Use search to find more options…')
|
|
94
|
+
})
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
export { GridList };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AriaGridListItemOptions } from '@react-aria/gridlist';
|
|
2
|
+
import type { ListState } from '@react-stately/list';
|
|
3
|
+
import type { Node } from '@react-types/shared';
|
|
4
|
+
import type { ListItemBase } from '../types.js';
|
|
5
|
+
import type { FormSize } from '../../theme/index.js';
|
|
6
|
+
export interface GridListOptionProps<T extends ListItemBase> extends AriaGridListItemOptions {
|
|
7
|
+
listState: ListState<T>;
|
|
8
|
+
node: Node<T>;
|
|
9
|
+
size: FormSize;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A <li /> element with accessibile behaviors & attributes.
|
|
13
|
+
* https://react-spectrum.adobe.com/react-aria/useGridList.html
|
|
14
|
+
*/
|
|
15
|
+
export declare function GridListOption<T extends ListItemBase>({ node, listState, size, }: GridListOptionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|