@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,155 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { css } from "@emotion/react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { Button } from "../button/index.js";
|
|
5
|
+
import { Flex, Stack } from "../layout/index.js";
|
|
6
|
+
import { SectionSeparator } from "../menu/index.js";
|
|
7
|
+
const ListWrap = styled('ul')`
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: ${(p)=>p.theme.space.xs} 0;
|
|
10
|
+
|
|
11
|
+
> [data-section-separator]:first-of-type {
|
|
12
|
+
display: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* Add 1px to top padding if preceded by menu header, to account for the header's
|
|
16
|
+
shadow border */
|
|
17
|
+
[data-menu-has-header='true'] > div > &:first-of-type {
|
|
18
|
+
padding-top: calc(${(p)=>p.theme.space.xs} + 1px);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* Add 1px to bottom padding if succeeded by menu footer, to account for the footer's
|
|
22
|
+
shadow border */
|
|
23
|
+
[data-menu-has-footer='true'] > div > &:last-of-type {
|
|
24
|
+
padding-bottom: calc(${(p)=>p.theme.space.xs} + 1px);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Remove top padding if preceded by search input, since search input already has
|
|
28
|
+
vertical padding. Account for InputGroup wrapper div. */
|
|
29
|
+
div:has(input) ~ &&:first-of-type,
|
|
30
|
+
div:has(input) ~ div > &&:first-of-type {
|
|
31
|
+
padding-top: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:empty {
|
|
35
|
+
padding: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Should scroll if it's in a non-composite select */
|
|
39
|
+
:only-of-type {
|
|
40
|
+
min-height: 0;
|
|
41
|
+
overflow: auto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
:focus-visible {
|
|
45
|
+
outline: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* The first section follows a hidden separator in a headerless menu. */
|
|
49
|
+
[data-menu-has-header='false']
|
|
50
|
+
&:first-of-type
|
|
51
|
+
li[role='presentation']:nth-of-type(2)
|
|
52
|
+
> [data-section-header] {
|
|
53
|
+
padding-top: 0;
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const ListLabel = styled('span')`
|
|
57
|
+
display: inline-block;
|
|
58
|
+
font-weight: ${(p)=>p.theme.font.weight.sans.medium};
|
|
59
|
+
font-size: ${(p)=>p.theme.font.size.xs};
|
|
60
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
61
|
+
text-transform: uppercase;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
margin: ${(p)=>p.theme.space.xs} ${(p)=>p.theme.space.lg};
|
|
64
|
+
padding-right: ${(p)=>p.theme.space.md};
|
|
65
|
+
`;
|
|
66
|
+
const ListSeparator = styled('div')`
|
|
67
|
+
border-top: solid 1px ${(p)=>p.theme.tokens.border.secondary};
|
|
68
|
+
margin: ${(p)=>p.theme.space.xs} ${(p)=>p.theme.space.lg};
|
|
69
|
+
|
|
70
|
+
:first-child {
|
|
71
|
+
display: none;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ul:empty + & {
|
|
75
|
+
display: none;
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
const SectionToggleButton = styled(Button)`
|
|
79
|
+
padding: 0 ${(p)=>p.theme.space.xs};
|
|
80
|
+
margin: 0 -${(p)=>p.theme.space.xs} 0 ${(p)=>p.theme.space.xl};
|
|
81
|
+
font-weight: ${(p)=>p.theme.font.weight.sans.regular};
|
|
82
|
+
font-size: ${(p)=>p.theme.font.size.sm};
|
|
83
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
84
|
+
transition: opacity 0.1s;
|
|
85
|
+
|
|
86
|
+
&:focus-visible {
|
|
87
|
+
opacity: 1;
|
|
88
|
+
pointer-events: all;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
${(p)=>p.visible ? css`
|
|
92
|
+
opacity: 1;
|
|
93
|
+
pointer-events: all;
|
|
94
|
+
` : css`
|
|
95
|
+
opacity: 0;
|
|
96
|
+
pointer-events: none;
|
|
97
|
+
`}
|
|
98
|
+
|
|
99
|
+
li[role='rowgroup']:hover &,
|
|
100
|
+
li[role='presentation']:hover & {
|
|
101
|
+
opacity: 1;
|
|
102
|
+
pointer-events: all;
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
function styles_SectionSeparator(props) {
|
|
106
|
+
return /*#__PURE__*/ jsx(Stack, {
|
|
107
|
+
as: "li",
|
|
108
|
+
"data-section-separator": true,
|
|
109
|
+
justify: "center",
|
|
110
|
+
height: "8px",
|
|
111
|
+
padding: "0 lg 0 xl",
|
|
112
|
+
...props,
|
|
113
|
+
role: "presentation",
|
|
114
|
+
children: /*#__PURE__*/ jsx(SectionSeparator, {})
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function getOptionPaddingLeft({ hasCheck, hasLeadingItems }) {
|
|
118
|
+
if (hasCheck && hasLeadingItems) return 'md';
|
|
119
|
+
return hasCheck || hasLeadingItems ? 'xs' : 'md';
|
|
120
|
+
}
|
|
121
|
+
function LeadWrap(props) {
|
|
122
|
+
return /*#__PURE__*/ jsx(Flex, {
|
|
123
|
+
justify: "center",
|
|
124
|
+
align: "center",
|
|
125
|
+
minWidth: "1em",
|
|
126
|
+
height: "1rem",
|
|
127
|
+
pointerEvents: "none",
|
|
128
|
+
...props
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const EmptyMessage = styled('p')`
|
|
132
|
+
text-align: center;
|
|
133
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
134
|
+
padding: ${(p)=>p.theme.space.md} ${(p)=>p.theme.space.lg} ${(p)=>p.theme.space.lg};
|
|
135
|
+
margin: 0;
|
|
136
|
+
|
|
137
|
+
/* Message should only be displayed when _all_ preceding lists are empty */
|
|
138
|
+
display: block;
|
|
139
|
+
div:has(ul:not(:empty)) ~ &,
|
|
140
|
+
ul:not(:empty) ~ & {
|
|
141
|
+
display: none;
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
const SizeLimitMessage = styled('li')`
|
|
145
|
+
border-top: solid 1px ${(p)=>p.theme.tokens.border.secondary};
|
|
146
|
+
margin: ${(p)=>p.theme.space.xs} ${(p)=>p.theme.space.lg} ${(p)=>p.theme.space.xs};
|
|
147
|
+
padding: ${(p)=>p.theme.space.sm} ${(p)=>p.theme.space.md} 0;
|
|
148
|
+
|
|
149
|
+
font-size: ${(p)=>p.theme.font.size.sm};
|
|
150
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
151
|
+
list-style-type: none;
|
|
152
|
+
white-space: nowrap;
|
|
153
|
+
text-align: center;
|
|
154
|
+
`;
|
|
155
|
+
export { EmptyMessage, LeadWrap, ListLabel, ListSeparator, ListWrap, SectionToggleButton, SizeLimitMessage, getOptionPaddingLeft, styles_SectionSeparator as SectionSeparator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ListItemBase, SelectKey, SelectOption, SelectSection, SelectOptionOrSection, SearchMatchResult, SearchConfig, SelectOptionWithKey, SelectSectionWithKey, SelectOptionOrSectionWithKey, } from '../menu/index.js';
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Node } from '@react-types/shared';
|
|
2
|
+
import type { FormSize } from '../theme/index.js';
|
|
3
|
+
type ObjectLike = object;
|
|
4
|
+
export declare function useVirtualizedItems<T extends ObjectLike>({ listItems, listPadding, virtualized, size, }: {
|
|
5
|
+
listItems: Array<Node<T>>;
|
|
6
|
+
size: FormSize;
|
|
7
|
+
virtualized: boolean | undefined;
|
|
8
|
+
listPadding?: number;
|
|
9
|
+
}): {
|
|
10
|
+
readonly items: import("@tanstack/react-virtual").VirtualItem[];
|
|
11
|
+
readonly scrollToIndex: (index: number) => void;
|
|
12
|
+
readonly scrollElementRef: import("react").RefObject<HTMLDivElement | null>;
|
|
13
|
+
readonly itemProps: (index: number) => {
|
|
14
|
+
ref: (node: Element | null) => void;
|
|
15
|
+
'data-index': number;
|
|
16
|
+
};
|
|
17
|
+
readonly wrapperProps: {
|
|
18
|
+
readonly 'data-is-virtualized': true;
|
|
19
|
+
readonly style: {
|
|
20
|
+
readonly height: number;
|
|
21
|
+
readonly width: "100%";
|
|
22
|
+
readonly position: "relative";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
readonly listWrapStyle: {
|
|
26
|
+
readonly position: "absolute";
|
|
27
|
+
readonly top: 0;
|
|
28
|
+
readonly left: 0;
|
|
29
|
+
readonly width: "100%";
|
|
30
|
+
readonly transform: `translateY(${number}px)`;
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
readonly items: {
|
|
34
|
+
index: number;
|
|
35
|
+
start: number;
|
|
36
|
+
}[];
|
|
37
|
+
readonly scrollToIndex: () => void;
|
|
38
|
+
readonly scrollElementRef: undefined;
|
|
39
|
+
readonly itemProps: () => void;
|
|
40
|
+
readonly wrapperProps: {
|
|
41
|
+
readonly 'data-is-virtualized': false;
|
|
42
|
+
readonly style?: undefined;
|
|
43
|
+
};
|
|
44
|
+
readonly listWrapStyle: {
|
|
45
|
+
readonly position?: undefined;
|
|
46
|
+
readonly top?: undefined;
|
|
47
|
+
readonly left?: undefined;
|
|
48
|
+
readonly width?: undefined;
|
|
49
|
+
readonly transform?: undefined;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { useVirtualRows } from "../useVirtualRows.js";
|
|
3
|
+
const heightEstimations = {
|
|
4
|
+
sm: {
|
|
5
|
+
regular: 32,
|
|
6
|
+
large: 49
|
|
7
|
+
},
|
|
8
|
+
md: {
|
|
9
|
+
regular: 36,
|
|
10
|
+
large: 53
|
|
11
|
+
},
|
|
12
|
+
xs: {
|
|
13
|
+
regular: 25,
|
|
14
|
+
large: 42
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const listPaddingVertical = 4;
|
|
18
|
+
function useVirtualizedItems({ listItems, listPadding = listPaddingVertical, virtualized = false, size }) {
|
|
19
|
+
const scrollElementRef = useRef(null);
|
|
20
|
+
const heightEstimation = heightEstimations[size];
|
|
21
|
+
const { totalSize, virtualItems, virtualizer } = useVirtualRows({
|
|
22
|
+
count: listItems.length,
|
|
23
|
+
getScrollElement: ()=>scrollElementRef?.current,
|
|
24
|
+
estimateSize: (index)=>{
|
|
25
|
+
const item = listItems[index];
|
|
26
|
+
if (item?.props?.details) return heightEstimation.large;
|
|
27
|
+
return heightEstimation.regular;
|
|
28
|
+
},
|
|
29
|
+
enabled: virtualized,
|
|
30
|
+
overscan: 1
|
|
31
|
+
});
|
|
32
|
+
if (virtualized) return {
|
|
33
|
+
items: virtualItems,
|
|
34
|
+
scrollToIndex: (index)=>{
|
|
35
|
+
virtualizer.scrollToIndex(index, {
|
|
36
|
+
align: 'auto'
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
scrollElementRef,
|
|
40
|
+
itemProps: (index)=>({
|
|
41
|
+
ref: virtualizer.measureElement,
|
|
42
|
+
'data-index': index
|
|
43
|
+
}),
|
|
44
|
+
wrapperProps: {
|
|
45
|
+
'data-is-virtualized': true,
|
|
46
|
+
style: {
|
|
47
|
+
height: totalSize + 2 * listPadding,
|
|
48
|
+
width: '100%',
|
|
49
|
+
position: 'relative'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
listWrapStyle: {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
width: '100%',
|
|
57
|
+
transform: `translateY(${virtualItems[0]?.start ?? 0}px)`
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
items: listItems.map((_, index)=>({
|
|
62
|
+
index,
|
|
63
|
+
start: 0
|
|
64
|
+
})),
|
|
65
|
+
scrollToIndex: ()=>{},
|
|
66
|
+
scrollElementRef: void 0,
|
|
67
|
+
itemProps: ()=>{},
|
|
68
|
+
wrapperProps: {
|
|
69
|
+
'data-is-virtualized': false
|
|
70
|
+
},
|
|
71
|
+
listWrapStyle: {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { useVirtualizedItems };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ListState } from '@react-stately/list';
|
|
2
|
+
import type { Node, Selection } from '@react-types/shared';
|
|
3
|
+
import type { SelectProps } from './compactSelect.js';
|
|
4
|
+
import type { SearchConfig, SearchMatchResult, SelectKey, SelectOption, SelectOptionOrSection, SelectOptionOrSectionWithKey, SelectOptionWithKey, SelectSectionWithKey } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Whether any visible option has custom leading items, so options without them
|
|
7
|
+
* should reserve matching space to keep labels aligned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hasVisibleLeadingItems(listItems: Array<Node<unknown>>, hiddenOptions: Set<SelectKey>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Normalises the `search` prop into a plain config object (or `undefined` if
|
|
12
|
+
* search is disabled). Accepts `true` as shorthand for `{}` and treats
|
|
13
|
+
* `false`/`undefined` as "no search".
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSearchConfig<Value extends SelectKey>(search: boolean | SearchConfig<Value> | undefined): SearchConfig<Value> | undefined;
|
|
16
|
+
export declare function getEscapedKey(value: SelectKey): string;
|
|
17
|
+
export declare function getItemsWithKeys<Value extends SelectKey>(options: Array<SelectOption<Value>>): Array<SelectOptionWithKey<Value>>;
|
|
18
|
+
export declare function getItemsWithKeys<Value extends SelectKey>(options: Array<SelectOptionOrSection<Value>>): Array<SelectOptionOrSectionWithKey<Value>>;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively finds the selected option(s) from an options array. Useful for
|
|
21
|
+
* non-flat arrays that contain sections (groups of options).
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSelectedOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, selection: Selection): Array<SelectOption<Value>>;
|
|
24
|
+
/**
|
|
25
|
+
* Recursively finds the selected option(s) from an options array. Useful for non-flat
|
|
26
|
+
* arrays that contain sections (groups of options). Returns the values of options that
|
|
27
|
+
* were removed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDisabledOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, isOptionDisabled?: (opt: SelectOptionWithKey<Value>) => boolean): SelectKey[];
|
|
30
|
+
/**
|
|
31
|
+
* Recursively finds the option(s) that don't match the designated search string or are
|
|
32
|
+
* outside the list box's count limit. Also collects match scores for use in sorting.
|
|
33
|
+
*
|
|
34
|
+
* An option is considered a match when its score is greater than 0. The default matcher
|
|
35
|
+
* uses fzf and always returns a positive score for any subsequence match, 0 when there
|
|
36
|
+
* is no match. Custom matchers can return any positive score to influence sort order —
|
|
37
|
+
* higher scores appear first.
|
|
38
|
+
*
|
|
39
|
+
* Returns both the set of hidden option keys and a map of key → score for matched
|
|
40
|
+
* options.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getHiddenOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, search: string, limit?: number, searchMatcher?: (option: SelectOptionWithKey<Value>, search: string) => SearchMatchResult): {
|
|
43
|
+
hidden: Set<SelectKey>;
|
|
44
|
+
scores: Map<SelectKey, number>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Sorts items by their match scores (descending). Options with higher scores appear
|
|
48
|
+
* first. Options without a score entry maintain their original relative order.
|
|
49
|
+
*
|
|
50
|
+
* For sectioned lists, options are sorted within each section. For flat lists, all
|
|
51
|
+
* options are sorted globally.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getSortedItems<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, scores: Map<SelectKey, number>): Array<SelectOptionOrSectionWithKey<Value>>;
|
|
54
|
+
interface SectionToggleProps {
|
|
55
|
+
item: Node<any>;
|
|
56
|
+
listState: ListState<any>;
|
|
57
|
+
listId?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A visible toggle button to select/unselect all options within a given section. See
|
|
61
|
+
* also: `HiddenSectionToggle`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function SectionToggle({ item, listState }: SectionToggleProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
64
|
+
/**
|
|
65
|
+
* A visually hidden but keyboard-focusable button to toggle (select/unselect) all
|
|
66
|
+
* options in a given section. We need these hidden buttons because the visible toggle
|
|
67
|
+
* buttons inside ListBox/GridList are not keyboard-focusable (due to them implementing
|
|
68
|
+
* roving `tabindex`).
|
|
69
|
+
*/
|
|
70
|
+
export declare function HiddenSectionToggle({ item, listState, listId, ...props }: SectionToggleProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
71
|
+
export declare function itemIsSectionWithKey<T extends SelectKey>(item: SelectOptionOrSectionWithKey<T>): item is SelectSectionWithKey<T>;
|
|
72
|
+
export declare function shouldCloseOnSelect({ multiple, closeOnSelect, selectedOptions, }: Pick<SelectProps<any>, 'multiple' | 'closeOnSelect'> & {
|
|
73
|
+
selectedOptions: Array<SelectOption<any>>;
|
|
74
|
+
}): boolean;
|
|
75
|
+
export declare function getDuplicateOptionKeysInfo<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>): {
|
|
76
|
+
duplicateOptionKeys: string[];
|
|
77
|
+
hasSections: boolean;
|
|
78
|
+
optionCount: number;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import { useFocus, usePress } from "@react-aria/interactions";
|
|
4
|
+
import { mergeProps } from "@react-aria/utils";
|
|
5
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
|
+
import { useTranslation } from "../translation/index.js";
|
|
7
|
+
import { fzf } from "./fzf.js";
|
|
8
|
+
import { SectionToggleButton } from "./styles.js";
|
|
9
|
+
function hasVisibleLeadingItems(listItems, hiddenOptions) {
|
|
10
|
+
return listItems.flatMap((node)=>'section' === node.type ? [
|
|
11
|
+
...node.childNodes
|
|
12
|
+
] : [
|
|
13
|
+
node
|
|
14
|
+
]).some((node)=>{
|
|
15
|
+
const { leadingItems } = node.props;
|
|
16
|
+
return !hiddenOptions.has(node.key) && Boolean(leadingItems);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const SIMPLE_CSS_IDENTIFIER = /^-?(?!\d)\w[-\w]*$/;
|
|
20
|
+
function getSearchConfig(search) {
|
|
21
|
+
if (!search) return;
|
|
22
|
+
if (true === search) return {};
|
|
23
|
+
return search;
|
|
24
|
+
}
|
|
25
|
+
function getEscapedKey(value) {
|
|
26
|
+
const stringValue = String(value);
|
|
27
|
+
return SIMPLE_CSS_IDENTIFIER.test(stringValue) ? stringValue : CSS.escape(stringValue);
|
|
28
|
+
}
|
|
29
|
+
function getItemsWithKeys(options) {
|
|
30
|
+
return options.map((item, i)=>{
|
|
31
|
+
if ('options' in item) return {
|
|
32
|
+
...item,
|
|
33
|
+
key: item.key ?? `options-${i}`,
|
|
34
|
+
options: getItemsWithKeys(item.options)
|
|
35
|
+
};
|
|
36
|
+
const existingKey = 'key' in item && 'string' == typeof item.key ? item.key : void 0;
|
|
37
|
+
return {
|
|
38
|
+
...item,
|
|
39
|
+
key: existingKey ?? getEscapedKey(item.value)
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function getSelectedOptions(items, selection) {
|
|
44
|
+
return items.reduce((acc, cur)=>{
|
|
45
|
+
if ('options' in cur) return acc.concat(getSelectedOptions(cur.options, selection));
|
|
46
|
+
if ('all' === selection || selection.has(cur.key)) {
|
|
47
|
+
const { key: _key, ...opt } = cur;
|
|
48
|
+
acc.push(opt);
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}, []);
|
|
52
|
+
}
|
|
53
|
+
function getDisabledOptions(items, isOptionDisabled) {
|
|
54
|
+
return items.reduce((acc, cur)=>{
|
|
55
|
+
if ('options' in cur) {
|
|
56
|
+
if (cur.disabled) {
|
|
57
|
+
for (const opt of cur.options)acc.push(opt.key);
|
|
58
|
+
return acc;
|
|
59
|
+
}
|
|
60
|
+
return acc.concat(getDisabledOptions(cur.options, isOptionDisabled));
|
|
61
|
+
}
|
|
62
|
+
if (isOptionDisabled?.(cur) ?? cur.disabled) acc.push(cur.key);
|
|
63
|
+
return acc;
|
|
64
|
+
}, []);
|
|
65
|
+
}
|
|
66
|
+
function defaultSearchMatcher(option, search) {
|
|
67
|
+
const text = option.textValue ?? ('string' == typeof option.label ? option.label : '');
|
|
68
|
+
if (!text) return {
|
|
69
|
+
score: 0
|
|
70
|
+
};
|
|
71
|
+
const result = fzf(text, search.toLowerCase(), false);
|
|
72
|
+
if (-1 === result.end) return {
|
|
73
|
+
score: 0
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
score: Math.max(1, result.score)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function getHiddenOptions(items, search, limit = 1 / 0, searchMatcher) {
|
|
80
|
+
const scores = new Map();
|
|
81
|
+
const matcher = searchMatcher ?? defaultSearchMatcher;
|
|
82
|
+
const filterOption = (opt)=>{
|
|
83
|
+
if (!search) return true;
|
|
84
|
+
const result = matcher(opt, search);
|
|
85
|
+
if (result.score > 0) {
|
|
86
|
+
scores.set(opt.key, result.score);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
91
|
+
const hiddenOptionsSet = new Set();
|
|
92
|
+
const remainingItems = items.flatMap((item)=>{
|
|
93
|
+
if ('options' in item) {
|
|
94
|
+
const filteredOptions = item.options.map((opt)=>{
|
|
95
|
+
if (filterOption(opt)) return opt;
|
|
96
|
+
hiddenOptionsSet.add(opt.key);
|
|
97
|
+
return null;
|
|
98
|
+
}).filter((opt)=>!!opt);
|
|
99
|
+
return filteredOptions.length > 0 ? {
|
|
100
|
+
...item,
|
|
101
|
+
options: filteredOptions
|
|
102
|
+
} : null;
|
|
103
|
+
}
|
|
104
|
+
if (filterOption(item)) return item;
|
|
105
|
+
hiddenOptionsSet.add(item.key);
|
|
106
|
+
return null;
|
|
107
|
+
}).filter((item)=>!!item);
|
|
108
|
+
const orderedRemainingItems = scores.size > 0 ? getSortedItems(remainingItems, scores) : remainingItems;
|
|
109
|
+
let threshold = [
|
|
110
|
+
1 / 0,
|
|
111
|
+
1 / 0
|
|
112
|
+
];
|
|
113
|
+
let accumulator = 0;
|
|
114
|
+
let currentIndex = 0;
|
|
115
|
+
while(currentIndex < orderedRemainingItems.length){
|
|
116
|
+
const item = orderedRemainingItems[currentIndex];
|
|
117
|
+
const delta = item && 'options' in item ? item.options.length : 1;
|
|
118
|
+
if (accumulator + delta > limit) {
|
|
119
|
+
threshold = [
|
|
120
|
+
currentIndex,
|
|
121
|
+
limit - accumulator
|
|
122
|
+
];
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
accumulator += delta;
|
|
126
|
+
currentIndex += 1;
|
|
127
|
+
}
|
|
128
|
+
for(let i = threshold[0]; i < orderedRemainingItems.length; i++){
|
|
129
|
+
const item = orderedRemainingItems[i];
|
|
130
|
+
if (item) if ('options' in item) {
|
|
131
|
+
const startingIndex = i === threshold[0] ? threshold[1] : 0;
|
|
132
|
+
for (const option of item.options.slice(startingIndex))hiddenOptionsSet.add(option.key);
|
|
133
|
+
} else hiddenOptionsSet.add(item.key);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
hidden: hiddenOptionsSet,
|
|
137
|
+
scores
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function getSortedItems(items, scores) {
|
|
141
|
+
const hasSections = items.some((item)=>'options' in item);
|
|
142
|
+
if (hasSections) return items.map((item)=>{
|
|
143
|
+
if ('options' in item) return {
|
|
144
|
+
...item,
|
|
145
|
+
options: item.options.toSorted((a, b)=>(scores.get(b.key) ?? 0) - (scores.get(a.key) ?? 0))
|
|
146
|
+
};
|
|
147
|
+
return item;
|
|
148
|
+
});
|
|
149
|
+
return items.toSorted((a, b)=>(scores.get(b.key) ?? 0) - (scores.get(a.key) ?? 0));
|
|
150
|
+
}
|
|
151
|
+
function toggleOptions(optionKeys, selectionManager) {
|
|
152
|
+
const { selectedKeys } = selectionManager;
|
|
153
|
+
const newSelectedKeys = new Set(selectedKeys);
|
|
154
|
+
const allOptionsSelected = optionKeys.every((val)=>selectionManager.isSelected(val));
|
|
155
|
+
optionKeys.forEach((val)=>allOptionsSelected ? newSelectedKeys.delete(val) : newSelectedKeys.add(val));
|
|
156
|
+
selectionManager.setSelectedKeys(newSelectedKeys);
|
|
157
|
+
}
|
|
158
|
+
function SectionToggle({ item, listState }) {
|
|
159
|
+
const { t } = useTranslation();
|
|
160
|
+
const allOptionsSelected = useMemo(()=>[
|
|
161
|
+
...item.childNodes
|
|
162
|
+
].every((n)=>listState.selectionManager.isSelected(n.key)), [
|
|
163
|
+
item,
|
|
164
|
+
listState.selectionManager
|
|
165
|
+
]);
|
|
166
|
+
const visible = useMemo(()=>{
|
|
167
|
+
const listHasFocus = listState.selectionManager.isFocused;
|
|
168
|
+
const sectionHasFocus = [
|
|
169
|
+
...item.childNodes
|
|
170
|
+
].some((n)=>listState.selectionManager.focusedKey === n.key);
|
|
171
|
+
return listHasFocus && sectionHasFocus;
|
|
172
|
+
}, [
|
|
173
|
+
item,
|
|
174
|
+
listState.selectionManager.focusedKey,
|
|
175
|
+
listState.selectionManager.isFocused
|
|
176
|
+
]);
|
|
177
|
+
const toggleAllOptions = useCallback(()=>{
|
|
178
|
+
toggleOptions(Array.from(item.childNodes, (n)=>n.key), listState.selectionManager);
|
|
179
|
+
}, [
|
|
180
|
+
item,
|
|
181
|
+
listState.selectionManager
|
|
182
|
+
]);
|
|
183
|
+
return /*#__PURE__*/ jsx(SectionToggleButton, {
|
|
184
|
+
"data-key": item.key,
|
|
185
|
+
visible: visible,
|
|
186
|
+
size: "zero",
|
|
187
|
+
variant: "transparent",
|
|
188
|
+
"aria-hidden": true,
|
|
189
|
+
tabIndex: -1,
|
|
190
|
+
onClick: toggleAllOptions,
|
|
191
|
+
children: allOptionsSelected ? t('Unselect All') : t('Select All')
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function HiddenSectionToggle({ item, listState, listId = '', ...props }) {
|
|
195
|
+
const { t } = useTranslation();
|
|
196
|
+
const { focusProps } = useFocus({
|
|
197
|
+
onFocus: ()=>{
|
|
198
|
+
const visibleCounterpart = document.getElementById(listId)?.querySelector(`button[aria-hidden][data-key="${item.key}"]`);
|
|
199
|
+
if (!visibleCounterpart) return;
|
|
200
|
+
visibleCounterpart.classList.add('focus-visible');
|
|
201
|
+
},
|
|
202
|
+
onBlur: ()=>{
|
|
203
|
+
const visibleCounterpart = document.getElementById(listId)?.querySelector(`button[aria-hidden][data-key="${item.key}"]`);
|
|
204
|
+
if (!visibleCounterpart) return;
|
|
205
|
+
visibleCounterpart.classList.remove('focus-visible');
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
const allOptionsSelected = useMemo(()=>[
|
|
209
|
+
...item.childNodes
|
|
210
|
+
].every((n)=>listState.selectionManager.isSelected(n.key)), [
|
|
211
|
+
item,
|
|
212
|
+
listState.selectionManager
|
|
213
|
+
]);
|
|
214
|
+
const { pressProps } = usePress({
|
|
215
|
+
onPress: ()=>{
|
|
216
|
+
toggleOptions(Array.from(item.childNodes, (n)=>n.key), listState.selectionManager);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return /*#__PURE__*/ jsx(VisuallyHidden, {
|
|
220
|
+
role: "presentation",
|
|
221
|
+
children: /*#__PURE__*/ jsxs("button", {
|
|
222
|
+
...props,
|
|
223
|
+
...mergeProps(focusProps, pressProps),
|
|
224
|
+
"aria-controls": listId,
|
|
225
|
+
id: `${listId}-section-toggle-${item.key}`,
|
|
226
|
+
children: [
|
|
227
|
+
allOptionsSelected ? t('Unselect All in ') : t('Select All in '),
|
|
228
|
+
item.textValue || item.rendered
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function itemIsSectionWithKey(item) {
|
|
234
|
+
return 'options' in item;
|
|
235
|
+
}
|
|
236
|
+
function shouldCloseOnSelect({ multiple, closeOnSelect, selectedOptions }) {
|
|
237
|
+
if ('function' == typeof closeOnSelect) return closeOnSelect(multiple ? selectedOptions : selectedOptions[0]);
|
|
238
|
+
if (null != closeOnSelect) return closeOnSelect;
|
|
239
|
+
return !multiple;
|
|
240
|
+
}
|
|
241
|
+
function getDuplicateOptionKeysInfo(items) {
|
|
242
|
+
const seen = new Set();
|
|
243
|
+
const duplicates = new Set();
|
|
244
|
+
let optionCount = 0;
|
|
245
|
+
let hasSections = false;
|
|
246
|
+
const collect = (list)=>{
|
|
247
|
+
for (const item of list){
|
|
248
|
+
if ('options' in item) {
|
|
249
|
+
hasSections = true;
|
|
250
|
+
collect(item.options);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
optionCount += 1;
|
|
254
|
+
const key = String(item.key);
|
|
255
|
+
if (!duplicates.has(key)) if (seen.has(key)) duplicates.add(key);
|
|
256
|
+
else seen.add(key);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
collect(items);
|
|
260
|
+
return {
|
|
261
|
+
duplicateOptionKeys: [
|
|
262
|
+
...duplicates
|
|
263
|
+
],
|
|
264
|
+
hasSections,
|
|
265
|
+
optionCount
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
export { HiddenSectionToggle, SectionToggle, getDisabledOptions, getDuplicateOptionKeysInfo, getEscapedKey, getHiddenOptions, getItemsWithKeys, getSearchConfig, getSelectedOptions, getSortedItems, hasVisibleLeadingItems, itemIsSectionWithKey, shouldCloseOnSelect };
|