@sentry/scraps 0.4.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/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +2 -0
- package/dist/link/linkBehaviorContext.js +17 -10
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -6
- package/dist/menu/menu.js +160 -56
- 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/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/splitPanel/splitPanel.d.ts +3 -1
- package/dist/splitPanel/splitPanel.js +2 -1
- 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/tooltip/tooltip.js +2 -5
- 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/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 +115 -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
package/dist/text/styles.js
CHANGED
|
@@ -9,7 +9,7 @@ function getTextDecoration(p) {
|
|
|
9
9
|
}
|
|
10
10
|
function getLineHeight(density, theme) {
|
|
11
11
|
if (void 0 === density) return;
|
|
12
|
-
return theme.font.lineHeight[density]
|
|
12
|
+
return String(theme.font.lineHeight[density]);
|
|
13
13
|
}
|
|
14
14
|
function getFontSize(size, theme) {
|
|
15
15
|
if (void 0 === size) return;
|
package/dist/text/text.d.ts
CHANGED
package/dist/text/text.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
3
|
import { css } from "@emotion/react";
|
|
4
4
|
import styled from "@emotion/styled";
|
|
5
|
-
import { rc } from "../layout/
|
|
5
|
+
import { rc } from "../layout/styles.js";
|
|
6
6
|
import { getFontSize, getLineHeight, getTextDecoration } from "./styles.js";
|
|
7
7
|
function getDefaultDisplay(p) {
|
|
8
8
|
if ('div' === p.as) return 'block';
|
package/dist/theme/dark.js
CHANGED
|
@@ -442,17 +442,17 @@ const shadow = {
|
|
|
442
442
|
};
|
|
443
443
|
const darkTheme = {
|
|
444
444
|
...baseTheme,
|
|
445
|
-
shadow
|
|
445
|
+
shadow,
|
|
446
446
|
tokens: {
|
|
447
|
-
background
|
|
448
|
-
border
|
|
449
|
-
content
|
|
450
|
-
dataviz
|
|
451
|
-
elevation
|
|
447
|
+
background,
|
|
448
|
+
border,
|
|
449
|
+
content,
|
|
450
|
+
dataviz,
|
|
451
|
+
elevation,
|
|
452
452
|
focus: dark_focus,
|
|
453
|
-
graphics
|
|
454
|
-
interactive
|
|
455
|
-
syntax
|
|
453
|
+
graphics,
|
|
454
|
+
interactive,
|
|
455
|
+
syntax
|
|
456
456
|
}
|
|
457
457
|
};
|
|
458
458
|
export { darkTheme };
|
package/dist/theme/light.js
CHANGED
|
@@ -442,17 +442,17 @@ const shadow = {
|
|
|
442
442
|
};
|
|
443
443
|
const lightTheme = {
|
|
444
444
|
...baseTheme,
|
|
445
|
-
shadow
|
|
445
|
+
shadow,
|
|
446
446
|
tokens: {
|
|
447
|
-
background
|
|
448
|
-
border
|
|
449
|
-
content
|
|
450
|
-
dataviz
|
|
451
|
-
elevation
|
|
447
|
+
background,
|
|
448
|
+
border,
|
|
449
|
+
content,
|
|
450
|
+
dataviz,
|
|
451
|
+
elevation,
|
|
452
452
|
focus: light_focus,
|
|
453
|
-
graphics
|
|
454
|
-
interactive
|
|
455
|
-
syntax
|
|
453
|
+
graphics,
|
|
454
|
+
interactive,
|
|
455
|
+
syntax
|
|
456
456
|
}
|
|
457
457
|
};
|
|
458
458
|
export { lightTheme };
|
package/dist/tooltip/tooltip.js
CHANGED
|
@@ -108,7 +108,7 @@ function TooltipHeader({ children, leadingItems, trailingItems }) {
|
|
|
108
108
|
})
|
|
109
109
|
]
|
|
110
110
|
}),
|
|
111
|
-
|
|
111
|
+
null != trailingItems && /*#__PURE__*/ jsx(Text, {
|
|
112
112
|
bold: true,
|
|
113
113
|
align: "right",
|
|
114
114
|
wrap: "nowrap",
|
|
@@ -160,7 +160,7 @@ function TooltipFooter({ children, leadingItems, trailingItems }) {
|
|
|
160
160
|
})
|
|
161
161
|
]
|
|
162
162
|
}),
|
|
163
|
-
|
|
163
|
+
null != trailingItems && /*#__PURE__*/ jsx(Text, {
|
|
164
164
|
variant: "muted",
|
|
165
165
|
align: "right",
|
|
166
166
|
wrap: "nowrap",
|
|
@@ -175,7 +175,4 @@ const Tooltip = Object.assign(TooltipComponent, {
|
|
|
175
175
|
Row: TooltipRow,
|
|
176
176
|
Footer: TooltipFooter
|
|
177
177
|
});
|
|
178
|
-
function defined(value) {
|
|
179
|
-
return null != value;
|
|
180
|
-
}
|
|
181
178
|
export { Tooltip, TooltipContent, TooltipContext };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook that updates when a media query result changes.
|
|
3
|
+
*
|
|
4
|
+
* Prefer this only for genuine media features that aren't container-expressible
|
|
5
|
+
* — e.g. `(prefers-color-scheme: ...)`, `(hover: ...)`, `(pointer: ...)`,
|
|
6
|
+
* `(max-height: ...)`, `(resolution: ...)`.
|
|
7
|
+
*
|
|
8
|
+
* For width-based checks, prefer scraps responsive props — bare breakpoint
|
|
9
|
+
* keys react to the nearest container (`<Flex direction={{xs: 'column'}} />`),
|
|
10
|
+
* `screen:`-prefixed keys to the viewport — or, when you need the resolved
|
|
11
|
+
* value in JS, `useContainerBreakpoint()` from `@sentry/scraps/layout`.
|
|
12
|
+
* Those react to an element's available space rather than the raw viewport,
|
|
13
|
+
* which is almost always what width checks actually want.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useMedia(query: string): boolean;
|
package/dist/useMedia.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
function useMedia(query) {
|
|
3
|
+
const [state, setState] = useState(()=>window.matchMedia?.(query)?.matches);
|
|
4
|
+
useEffect(()=>{
|
|
5
|
+
let mounted = true;
|
|
6
|
+
if (!window.matchMedia) return;
|
|
7
|
+
const mql = window.matchMedia(query);
|
|
8
|
+
const onChange = ()=>{
|
|
9
|
+
if (!mounted) return;
|
|
10
|
+
setState(!!mql.matches);
|
|
11
|
+
};
|
|
12
|
+
mql.addEventListener('change', onChange);
|
|
13
|
+
setState(mql.matches);
|
|
14
|
+
return ()=>{
|
|
15
|
+
mounted = false;
|
|
16
|
+
mql.removeEventListener('change', onChange);
|
|
17
|
+
};
|
|
18
|
+
}, [
|
|
19
|
+
query
|
|
20
|
+
]);
|
|
21
|
+
if (!window.matchMedia) return false;
|
|
22
|
+
return state;
|
|
23
|
+
}
|
|
24
|
+
export { useMedia };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
function useOnClickOutside(ref, handler) {
|
|
3
|
+
useLayoutEffect(()=>{
|
|
4
|
+
const listener = (event)=>{
|
|
5
|
+
if (!ref) return;
|
|
6
|
+
let el;
|
|
7
|
+
el = 'current' in ref ? ref.current : ref;
|
|
8
|
+
if (!el || el.contains(event.target)) return;
|
|
9
|
+
handler(event);
|
|
10
|
+
};
|
|
11
|
+
document.addEventListener('mousedown', listener);
|
|
12
|
+
document.addEventListener('touchstart', listener);
|
|
13
|
+
return ()=>{
|
|
14
|
+
document.removeEventListener('mousedown', listener);
|
|
15
|
+
document.removeEventListener('touchstart', listener);
|
|
16
|
+
};
|
|
17
|
+
}, [
|
|
18
|
+
ref,
|
|
19
|
+
handler
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
export { useOnClickOutside };
|
package/dist/useOverlay.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ interface UseOverlayResult {
|
|
|
63
63
|
};
|
|
64
64
|
isOpen: boolean;
|
|
65
65
|
overlayProps: ReturnType<typeof useOverlayTriggerAria>['overlayProps'] & ReturnType<typeof useOverlayAria>['overlayProps'] & {
|
|
66
|
+
'data-overlay-root': '';
|
|
66
67
|
ref: React.Dispatch<React.SetStateAction<HTMLDivElement | null>>;
|
|
67
68
|
style: React.CSSProperties | undefined;
|
|
68
69
|
};
|
package/dist/useOverlay.js
CHANGED
|
@@ -206,6 +206,7 @@ function useOverlay_useOverlay({ isOpen, onClose, defaultOpen, onOpenChange, typ
|
|
|
206
206
|
overlayProps: {
|
|
207
207
|
ref: setOverlayElement,
|
|
208
208
|
style: overlayStyle,
|
|
209
|
+
'data-overlay-root': '',
|
|
209
210
|
...mergeProps(overlayTriggerAriaProps, overlayAriaProps)
|
|
210
211
|
},
|
|
211
212
|
arrowProps: {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { Key, Node } from '@react-types/shared';
|
|
3
|
+
import type { FormSize } from './theme/index.js';
|
|
4
|
+
export { estimateRowHeight, isAfterFirstInSection } from './virtualCollectionLayout.js';
|
|
5
|
+
/**
|
|
6
|
+
* Item count above which shared menu controls (CompactSelect, DropdownMenu)
|
|
7
|
+
* virtualize their list.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_VIRTUALIZE_THRESHOLD = 150;
|
|
10
|
+
/**
|
|
11
|
+
* Lists a collection's nodes in the order `useVirtualCollection` renders them:
|
|
12
|
+
* each section is followed by its child nodes, so a long section is windowed
|
|
13
|
+
* like any other run of rows instead of mounting all at once. Nodes in
|
|
14
|
+
* `hiddenKeys` are left out, whether they are sections, their children or
|
|
15
|
+
* top-level items.
|
|
16
|
+
*/
|
|
17
|
+
export declare function flattenSections<T>(nodes: Iterable<Node<T>>, hiddenKeys?: ReadonlySet<Key>): Array<Node<T>>;
|
|
18
|
+
/** Props for the element that renders a row. Spread them onto the row's root element. */
|
|
19
|
+
export interface VirtualRowProps {
|
|
20
|
+
'data-index': number;
|
|
21
|
+
ref: (element: Element | null) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface VirtualRow<T> {
|
|
24
|
+
node: Node<T>;
|
|
25
|
+
/** Undefined when virtualization is disabled. */
|
|
26
|
+
props: VirtualRowProps | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Height of the unmounted rows between this row and the previous one. Render
|
|
29
|
+
* a `VirtualSpacer` of this height before the row. Usually only the first
|
|
30
|
+
* row has space before it, but the focused row stays mounted when it scrolls
|
|
31
|
+
* out of view, so there can be a gap on either side of it.
|
|
32
|
+
*/
|
|
33
|
+
spaceBefore: number;
|
|
34
|
+
}
|
|
35
|
+
export interface UseVirtualCollectionOptions<T> {
|
|
36
|
+
/**
|
|
37
|
+
* The collection's top-level nodes, such as a React Aria `state.collection`.
|
|
38
|
+
* Each section's child nodes are windowed as rows of their own, see
|
|
39
|
+
* `flattenSections`.
|
|
40
|
+
*/
|
|
41
|
+
collection: Iterable<Node<T>>;
|
|
42
|
+
/** Whether to virtualize. When false, every node is returned as a row. */
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The element that scrolls. Rows and spacers must render inside it.
|
|
46
|
+
*/
|
|
47
|
+
scrollRef: React.RefObject<HTMLElement | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Height to assume for a row that has not been measured yet. Read on every
|
|
50
|
+
* render, so it does not need to be stable. Defaults to the height of a menu
|
|
51
|
+
* `ListItem` of `size`, plus `sectionRowSpace`.
|
|
52
|
+
*/
|
|
53
|
+
estimateSize?: (node: Node<T>, index: number) => number;
|
|
54
|
+
/**
|
|
55
|
+
* The collection's focused key. When it changes through the keyboard, the
|
|
56
|
+
* row is scrolled into view so it mounts and React Aria can focus it. The
|
|
57
|
+
* focused row also stays mounted while it is scrolled out of view, so it
|
|
58
|
+
* keeps DOM focus and the keyboard keeps working.
|
|
59
|
+
*/
|
|
60
|
+
focusedKey?: Key | null;
|
|
61
|
+
/** Keys of nodes to leave out, whether they are sections, their children or top-level items. */
|
|
62
|
+
hiddenKeys?: ReadonlySet<Key>;
|
|
63
|
+
/**
|
|
64
|
+
* Vertical CSS padding (px) of the list, at each end. The first row starts
|
|
65
|
+
* below it, and rows scrolled into view keep clear of it.
|
|
66
|
+
*/
|
|
67
|
+
listPadding?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Space (px) above each row in a section except the first, if the rows are
|
|
70
|
+
* spaced that way. The virtualizer measures a row's border box, so the space
|
|
71
|
+
* must be padding on the row's own element for mounted rows to keep it. A
|
|
72
|
+
* margin, or a gap on the list, is not part of a measured row: the rows would
|
|
73
|
+
* lose it once they mount and the scroll range would shrink. Added to the
|
|
74
|
+
* estimates of unmounted rows so the range does not shrink until they mount.
|
|
75
|
+
*/
|
|
76
|
+
sectionRowSpace?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Item size of the default `estimateSize`. Defaults to `md`. Changing it, or
|
|
79
|
+
* `sectionRowSpace`, discards the measured row heights, since every row
|
|
80
|
+
* changes height. Pass it with a custom `estimateSize` too.
|
|
81
|
+
*/
|
|
82
|
+
size?: FormSize;
|
|
83
|
+
/**
|
|
84
|
+
* A row to keep mounted wherever the list is scrolled, such as the one with
|
|
85
|
+
* the longest label. A list that sizes its width to its content is then as
|
|
86
|
+
* wide as that row from the start, instead of widening as wider rows scroll
|
|
87
|
+
* into view.
|
|
88
|
+
*/
|
|
89
|
+
widestKey?: Key | null;
|
|
90
|
+
}
|
|
91
|
+
/** The result of `useVirtualCollection`. Render it with `VirtualRows`. */
|
|
92
|
+
export interface VirtualCollection<T> {
|
|
93
|
+
/** The rows to render, in order: every node, or the mounted ones when virtualized. */
|
|
94
|
+
rows: Array<VirtualRow<T>>;
|
|
95
|
+
/** Height of the unmounted rows after the last mounted one. */
|
|
96
|
+
spaceAfter: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Windows a React Aria collection so only the rows near the viewport mount.
|
|
100
|
+
*
|
|
101
|
+
* It owns layout only, never selection or focus. Callers keep their React Aria
|
|
102
|
+
* state and render the rows with `VirtualRows`, which puts each row in its
|
|
103
|
+
* section and fills the space of the unmounted rows:
|
|
104
|
+
*
|
|
105
|
+
* ```tsx
|
|
106
|
+
* const virtual = useVirtualCollection({
|
|
107
|
+
* collection: state.collection,
|
|
108
|
+
* enabled,
|
|
109
|
+
* size,
|
|
110
|
+
* scrollRef,
|
|
111
|
+
* focusedKey: state.selectionManager.focusedKey,
|
|
112
|
+
* });
|
|
113
|
+
* <ul ref={scrollRef}>
|
|
114
|
+
* <VirtualRows
|
|
115
|
+
* virtual={virtual}
|
|
116
|
+
* renderRow={({node, props}) => <Option {...props} node={node} />}
|
|
117
|
+
* renderSection={({node, props}, rows) => (
|
|
118
|
+
* <Section rowProps={props} node={node}>{rows}</Section>
|
|
119
|
+
* )}
|
|
120
|
+
* />
|
|
121
|
+
* </ul>
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* Spacers keep the list's own element and padding intact, so a virtualized
|
|
125
|
+
* list has the same DOM structure and styling as a regular one.
|
|
126
|
+
*/
|
|
127
|
+
export declare function useVirtualCollection<T>({ collection, enabled, scrollRef, estimateSize, focusedKey, hiddenKeys, listPadding, sectionRowSpace, size, widestKey, }: UseVirtualCollectionOptions<T>): VirtualCollection<T>;
|
|
128
|
+
interface VirtualRowsProps<T> {
|
|
129
|
+
/**
|
|
130
|
+
* Renders an item row. Spread `props` onto the element that is the row's
|
|
131
|
+
* height, so the virtualizer can measure it.
|
|
132
|
+
*
|
|
133
|
+
* The list re-renders on every scroll, and `props` is a new object each time.
|
|
134
|
+
* To let a row that did not change skip rendering, pass the row component
|
|
135
|
+
* `props['data-index']` and `props.ref` as separate props, which keep their
|
|
136
|
+
* identity, and rebuild the object inside it.
|
|
137
|
+
*/
|
|
138
|
+
renderRow: (row: VirtualRow<T>) => React.ReactNode;
|
|
139
|
+
/** The result of `useVirtualCollection`. */
|
|
140
|
+
virtual: VirtualCollection<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Renders a section around its rendered rows. Spread the section's `props`
|
|
143
|
+
* onto the element above its rows, such as the one holding its header.
|
|
144
|
+
* Required when the collection has sections; by default only the rows render.
|
|
145
|
+
*/
|
|
146
|
+
renderSection?: (section: VirtualRow<T>, rows: React.ReactNode) => React.ReactNode;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Renders the rows of `useVirtualCollection`, with each row inside its section
|
|
150
|
+
* and spacers in place of the unmounted rows. Render it inside the scroll
|
|
151
|
+
* element. Rows outside sections stay siblings, so they keep their elements
|
|
152
|
+
* when the list reorders.
|
|
153
|
+
*/
|
|
154
|
+
export declare function VirtualRows<T>({ virtual, renderRow, renderSection, }: VirtualRowsProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect } from "react";
|
|
3
|
+
import { getInteractionModality } from "@react-aria/interactions";
|
|
4
|
+
import { defaultRangeExtractor, observeElementRect } from "@tanstack/react-virtual";
|
|
5
|
+
import { Container } from "./layout/index.js";
|
|
6
|
+
import { useVirtualRows } from "./useVirtualRows.js";
|
|
7
|
+
import { estimateRowHeight, getMountedIndexes, getSectionIndexes, isAfterFirstInSection } from "./virtualCollectionLayout.js";
|
|
8
|
+
const DEFAULT_VIRTUALIZE_THRESHOLD = 150;
|
|
9
|
+
function flattenSections(nodes, hiddenKeys) {
|
|
10
|
+
const isVisible = (node)=>!hiddenKeys?.has(node.key);
|
|
11
|
+
return [
|
|
12
|
+
...nodes
|
|
13
|
+
].filter(isVisible).flatMap((node)=>'section' === node.type ? [
|
|
14
|
+
node,
|
|
15
|
+
...[
|
|
16
|
+
...node.childNodes
|
|
17
|
+
].filter(isVisible)
|
|
18
|
+
] : [
|
|
19
|
+
node
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
const observeViewportCappedRect = (instance, cb)=>observeElementRect(instance, (rect)=>cb({
|
|
23
|
+
width: rect.width,
|
|
24
|
+
height: Math.min(rect.height, instance.targetWindow?.innerHeight ?? rect.height)
|
|
25
|
+
}));
|
|
26
|
+
function useVirtualCollection({ collection, enabled, scrollRef, estimateSize, focusedKey, hiddenKeys, listPadding = 0, sectionRowSpace = 0, size = 'md', widestKey }) {
|
|
27
|
+
const nodes = flattenSections(collection, hiddenKeys);
|
|
28
|
+
const focusedIndex = enabled && null != focusedKey ? nodes.findIndex((node)=>node.key === focusedKey) : -1;
|
|
29
|
+
const widestIndex = enabled && null != widestKey ? nodes.findIndex((node)=>node.key === widestKey) : -1;
|
|
30
|
+
const sectionIndexes = getSectionIndexes(nodes);
|
|
31
|
+
const rangeExtractor = (range)=>getMountedIndexes({
|
|
32
|
+
windowIndexes: defaultRangeExtractor(range),
|
|
33
|
+
focusedIndex,
|
|
34
|
+
widestIndex,
|
|
35
|
+
sectionIndexes
|
|
36
|
+
});
|
|
37
|
+
const { virtualizer, virtualItems, totalSize } = useVirtualRows({
|
|
38
|
+
count: nodes.length,
|
|
39
|
+
enabled,
|
|
40
|
+
getScrollElement: ()=>scrollRef.current,
|
|
41
|
+
getItemKey: (index)=>nodes[index]?.key ?? index,
|
|
42
|
+
estimateSize: (index)=>{
|
|
43
|
+
const node = nodes[index];
|
|
44
|
+
return estimateSize && node ? estimateSize(node, index) : estimateRowHeight(node, nodes[sectionIndexes[index] ?? -1], size, sectionRowSpace);
|
|
45
|
+
},
|
|
46
|
+
estimateKey: `${size}-${sectionRowSpace}`,
|
|
47
|
+
paddingStart: listPadding,
|
|
48
|
+
scrollPaddingStart: listPadding,
|
|
49
|
+
scrollPaddingEnd: listPadding,
|
|
50
|
+
overscan: 1,
|
|
51
|
+
rangeExtractor,
|
|
52
|
+
observeElementRect: observeViewportCappedRect
|
|
53
|
+
});
|
|
54
|
+
useEffect(()=>{
|
|
55
|
+
if (-1 === focusedIndex || 'pointer' === getInteractionModality()) return;
|
|
56
|
+
virtualizer.scrollToIndex(focusedIndex, {
|
|
57
|
+
align: 'auto'
|
|
58
|
+
});
|
|
59
|
+
}, [
|
|
60
|
+
focusedIndex,
|
|
61
|
+
virtualizer
|
|
62
|
+
]);
|
|
63
|
+
const rows = enabled ? virtualItems.flatMap((item, position)=>{
|
|
64
|
+
const node = nodes[item.index];
|
|
65
|
+
if (!node) return [];
|
|
66
|
+
const previousEnd = virtualItems[position - 1]?.end ?? listPadding;
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
node,
|
|
70
|
+
props: {
|
|
71
|
+
'data-index': item.index,
|
|
72
|
+
ref: virtualizer.measureElement
|
|
73
|
+
},
|
|
74
|
+
spaceBefore: Math.max(0, item.start - previousEnd)
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
}) : nodes.map((node)=>({
|
|
78
|
+
node,
|
|
79
|
+
props: void 0,
|
|
80
|
+
spaceBefore: 0
|
|
81
|
+
}));
|
|
82
|
+
const last = virtualItems.at(-1);
|
|
83
|
+
return {
|
|
84
|
+
rows,
|
|
85
|
+
spaceAfter: enabled ? Math.max(0, totalSize - (last?.end ?? listPadding)) : 0
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function groupVirtualRows(rows) {
|
|
89
|
+
const groups = [];
|
|
90
|
+
for (const row of rows){
|
|
91
|
+
const group = groups.at(-1);
|
|
92
|
+
if ('section' === row.node.type) groups.push({
|
|
93
|
+
section: row,
|
|
94
|
+
rows: []
|
|
95
|
+
});
|
|
96
|
+
else if (group?.section && group.section.node.key === row.node.parentKey) group.rows.push(row);
|
|
97
|
+
else groups.push({
|
|
98
|
+
rows: [
|
|
99
|
+
row
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return groups;
|
|
104
|
+
}
|
|
105
|
+
function VirtualSpacer({ height }) {
|
|
106
|
+
if (height <= 0) return null;
|
|
107
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
108
|
+
as: "li",
|
|
109
|
+
"aria-hidden": true,
|
|
110
|
+
role: "presentation",
|
|
111
|
+
height: `${height}px`,
|
|
112
|
+
flexShrink: 0
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function renderSectionRows(_section, rows) {
|
|
116
|
+
return rows;
|
|
117
|
+
}
|
|
118
|
+
function VirtualRows({ virtual, renderRow, renderSection = renderSectionRows }) {
|
|
119
|
+
const renderWithSpacer = (row)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
120
|
+
children: [
|
|
121
|
+
/*#__PURE__*/ jsx(VirtualSpacer, {
|
|
122
|
+
height: row.spaceBefore
|
|
123
|
+
}),
|
|
124
|
+
renderRow(row)
|
|
125
|
+
]
|
|
126
|
+
}, row.node.key);
|
|
127
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
128
|
+
children: [
|
|
129
|
+
groupVirtualRows(virtual.rows).flatMap(({ section, rows })=>section ? /*#__PURE__*/ jsxs(Fragment, {
|
|
130
|
+
children: [
|
|
131
|
+
/*#__PURE__*/ jsx(VirtualSpacer, {
|
|
132
|
+
height: section.spaceBefore
|
|
133
|
+
}),
|
|
134
|
+
renderSection(section, rows.map(renderWithSpacer))
|
|
135
|
+
]
|
|
136
|
+
}, section.node.key) : rows.map(renderWithSpacer)),
|
|
137
|
+
/*#__PURE__*/ jsx(VirtualSpacer, {
|
|
138
|
+
height: virtual.spaceAfter
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export { DEFAULT_VIRTUALIZE_THRESHOLD, VirtualRows, estimateRowHeight, flattenSections, isAfterFirstInSection, useVirtualCollection };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Range, type Rect, type VirtualizerOptions } from '@tanstack/react-virtual';
|
|
2
|
+
export interface UseVirtualRowsOptions {
|
|
3
|
+
count: number;
|
|
4
|
+
estimateSize: (index: number) => number;
|
|
5
|
+
getScrollElement: () => HTMLElement | null;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
estimateKey?: unknown;
|
|
8
|
+
gap?: number;
|
|
9
|
+
getItemKey?: (index: number) => string | number | bigint;
|
|
10
|
+
initialRect?: Rect;
|
|
11
|
+
observeElementRect?: VirtualizerOptions<HTMLElement, Element>['observeElementRect'];
|
|
12
|
+
overscan?: number;
|
|
13
|
+
paddingEnd?: number;
|
|
14
|
+
paddingStart?: number;
|
|
15
|
+
rangeExtractor?: (range: Range) => number[];
|
|
16
|
+
scrollPaddingEnd?: number;
|
|
17
|
+
scrollPaddingStart?: number;
|
|
18
|
+
useAnimationFrameWithResizeObserver?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function useVirtualRows({ estimateKey, overscan, ...options }: UseVirtualRowsOptions): {
|
|
21
|
+
virtualizer: import("@tanstack/react-virtual").ReactVirtualizer<HTMLElement, Element>;
|
|
22
|
+
virtualItems: import("@tanstack/react-virtual").VirtualItem[];
|
|
23
|
+
paddingTop: number;
|
|
24
|
+
paddingBottom: number;
|
|
25
|
+
totalSize: number;
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
3
|
+
function useVirtualRows({ estimateKey, overscan = 5, ...options }) {
|
|
4
|
+
const virtualizer = useVirtualizer({
|
|
5
|
+
...options,
|
|
6
|
+
overscan
|
|
7
|
+
});
|
|
8
|
+
useLayoutEffect(()=>{
|
|
9
|
+
virtualizer.measure();
|
|
10
|
+
}, [
|
|
11
|
+
virtualizer,
|
|
12
|
+
estimateKey
|
|
13
|
+
]);
|
|
14
|
+
const virtualItems = virtualizer.getVirtualItems();
|
|
15
|
+
const totalSize = virtualizer.getTotalSize();
|
|
16
|
+
const first = virtualItems[0];
|
|
17
|
+
const last = virtualItems[virtualItems.length - 1];
|
|
18
|
+
return {
|
|
19
|
+
virtualizer,
|
|
20
|
+
virtualItems,
|
|
21
|
+
paddingTop: first ? Math.max(0, first.start) : 0,
|
|
22
|
+
paddingBottom: last ? Math.max(0, totalSize - last.end) : 0,
|
|
23
|
+
totalSize
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { useVirtualRows };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Node } from '@react-types/shared';
|
|
2
|
+
import type { FormSize } from './theme/index.js';
|
|
3
|
+
export declare const ROW_HEIGHT_ESTIMATES: {
|
|
4
|
+
readonly xs: {
|
|
5
|
+
readonly regular: 25;
|
|
6
|
+
readonly withDetails: 42;
|
|
7
|
+
};
|
|
8
|
+
readonly sm: {
|
|
9
|
+
readonly regular: 32;
|
|
10
|
+
readonly withDetails: 49;
|
|
11
|
+
};
|
|
12
|
+
readonly md: {
|
|
13
|
+
readonly regular: 36;
|
|
14
|
+
readonly withDetails: 53;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Index of the section row each node belongs to, if that section is in
|
|
19
|
+
* `nodes`. Undefined for a node that is not in a section.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSectionIndexes<T>(nodes: ReadonlyArray<Node<T>>): Array<number | undefined>;
|
|
22
|
+
interface MountedIndexesOptions {
|
|
23
|
+
/** Index of the focused row, or -1. */
|
|
24
|
+
focusedIndex: number;
|
|
25
|
+
/** Per node, the index of its section row. See `getSectionIndexes`. */
|
|
26
|
+
sectionIndexes: ReadonlyArray<number | undefined>;
|
|
27
|
+
/** Index of the row to keep mounted for the menu's width, or -1. */
|
|
28
|
+
widestIndex: number;
|
|
29
|
+
/** The rows in or near the viewport. */
|
|
30
|
+
windowIndexes: readonly number[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The rows to mount: those in the window, plus the focused row so it keeps DOM
|
|
34
|
+
* focus when scrolled out of view, the widest row so a list that sizes to its
|
|
35
|
+
* content does not widen while scrolling, and the section row of every mounted
|
|
36
|
+
* row, since the section's element wraps its children. Sorted by index.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getMountedIndexes({ windowIndexes, focusedIndex, widestIndex, sectionIndexes, }: MountedIndexesOptions): number[];
|
|
39
|
+
/**
|
|
40
|
+
* Whether `node` is an item of `section` other than its first. These are the
|
|
41
|
+
* items a menu spaces from the item above, see `DropdownMenuSection`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isAfterFirstInSection<T>(node: Node<T>, section: Node<T> | null | undefined): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Height to assume for a row that has not been measured. A row after the
|
|
46
|
+
* first in its section includes `sectionRowSpace`, which stands for padding on
|
|
47
|
+
* the row's own element: mounted rows are measured by their border box, so
|
|
48
|
+
* they include it too.
|
|
49
|
+
*/
|
|
50
|
+
export declare function estimateRowHeight<T>(node: Node<T> | undefined, section: Node<T> | undefined, size: FormSize, sectionRowSpace: number): number;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const ROW_HEIGHT_ESTIMATES = {
|
|
2
|
+
xs: {
|
|
3
|
+
regular: 25,
|
|
4
|
+
withDetails: 42
|
|
5
|
+
},
|
|
6
|
+
sm: {
|
|
7
|
+
regular: 32,
|
|
8
|
+
withDetails: 49
|
|
9
|
+
},
|
|
10
|
+
md: {
|
|
11
|
+
regular: 36,
|
|
12
|
+
withDetails: 53
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function getSectionIndexes(nodes) {
|
|
16
|
+
const indexByKey = new Map();
|
|
17
|
+
nodes.forEach((node, index)=>{
|
|
18
|
+
if ('section' === node.type) indexByKey.set(node.key, index);
|
|
19
|
+
});
|
|
20
|
+
return nodes.map((node)=>null === node.parentKey || void 0 === node.parentKey ? void 0 : indexByKey.get(node.parentKey));
|
|
21
|
+
}
|
|
22
|
+
function getMountedIndexes({ windowIndexes, focusedIndex, widestIndex, sectionIndexes }) {
|
|
23
|
+
const indexes = new Set(windowIndexes);
|
|
24
|
+
for (const index of [
|
|
25
|
+
focusedIndex,
|
|
26
|
+
widestIndex
|
|
27
|
+
])if (-1 !== index) indexes.add(index);
|
|
28
|
+
for (const index of [
|
|
29
|
+
...indexes
|
|
30
|
+
]){
|
|
31
|
+
const sectionIndex = sectionIndexes[index];
|
|
32
|
+
if (void 0 !== sectionIndex) indexes.add(sectionIndex);
|
|
33
|
+
}
|
|
34
|
+
return [
|
|
35
|
+
...indexes
|
|
36
|
+
].sort((a, b)=>a - b);
|
|
37
|
+
}
|
|
38
|
+
function isAfterFirstInSection(node, section) {
|
|
39
|
+
if (!section || node.parentKey !== section.key) return false;
|
|
40
|
+
const [first] = section.childNodes;
|
|
41
|
+
return void 0 !== first && first.key !== node.key;
|
|
42
|
+
}
|
|
43
|
+
function estimateRowHeight(node, section, size, sectionRowSpace) {
|
|
44
|
+
const heights = ROW_HEIGHT_ESTIMATES[size];
|
|
45
|
+
const props = node?.props;
|
|
46
|
+
const height = props?.details ? heights.withDetails : heights.regular;
|
|
47
|
+
return node && isAfterFirstInSection(node, section) ? height + sectionRowSpace : height;
|
|
48
|
+
}
|
|
49
|
+
export { ROW_HEIGHT_ESTIMATES, estimateRowHeight, getMountedIndexes, getSectionIndexes, isAfterFirstInSection };
|