tfy-web-components 0.0.44 → 0.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Button-BdNaawKV.js → Button-HHEfL8b9.js} +5 -4
- package/dist/{Button-BdNaawKV.js.map → Button-HHEfL8b9.js.map} +1 -1
- package/dist/CSPContext-Cldo9QDp.js +13 -0
- package/dist/CSPContext-Cldo9QDp.js.map +1 -0
- package/dist/{CompositeItem-EOSJycCk.js → CompositeItem-GNejxLcK.js} +3 -3
- package/dist/{CompositeItem-EOSJycCk.js.map → CompositeItem-GNejxLcK.js.map} +1 -1
- package/dist/{CompositeRoot-DnijP7Jm.js → CompositeRoot-7_u1HqDT.js} +9 -47
- package/dist/CompositeRoot-7_u1HqDT.js.map +1 -0
- package/dist/DropdownMenu-Crlf-J4E.js +3304 -0
- package/dist/DropdownMenu-Crlf-J4E.js.map +1 -0
- package/dist/{Input-D0UuCXLs.js → Input-BS9fWUAf.js} +3 -3
- package/dist/{Input-D0UuCXLs.js.map → Input-BS9fWUAf.js.map} +1 -1
- package/dist/{Modal-BFnf68oS.js → Modal-DaHG8mjy.js} +10 -10
- package/dist/{Modal-BFnf68oS.js.map → Modal-DaHG8mjy.js.map} +1 -1
- package/dist/Popover-A8IyEt2w.js +400 -0
- package/dist/Popover-A8IyEt2w.js.map +1 -0
- package/dist/{Popover-B6z7exNd.js → PopoverPopup-teGm7D5T.js} +25 -498
- package/dist/PopoverPopup-teGm7D5T.js.map +1 -0
- package/dist/{PrehydrationScript--08s8Mfl.js → PrehydrationScript-B3u_PP2W.js} +5 -12
- package/dist/PrehydrationScript-B3u_PP2W.js.map +1 -0
- package/dist/Select-BtX40h2K.js +2187 -0
- package/dist/Select-BtX40h2K.js.map +1 -0
- package/dist/{useValueAsRef-BfFRcMg6.js → addEventListener-D-i9O6BG.js} +8 -8
- package/dist/addEventListener-D-i9O6BG.js.map +1 -0
- package/dist/clamp-D7_nsB8C.js +30 -0
- package/dist/clamp-D7_nsB8C.js.map +1 -0
- package/dist/components/atoms/Accordion.es.js +9 -9
- package/dist/components/atoms/Avatar.es.js +9 -9
- package/dist/components/atoms/Avatar.es.js.map +1 -1
- package/dist/components/atoms/Badge.d.ts +5 -6
- package/dist/components/atoms/Badge.es.js +80 -43
- package/dist/components/atoms/Badge.es.js.map +1 -1
- package/dist/components/atoms/Button.d.ts +1 -1
- package/dist/components/atoms/Button.es.js +2 -2
- package/dist/components/atoms/ButtonGroup.es.js +1 -1
- package/dist/components/atoms/Combobox.d.ts +34 -0
- package/dist/components/atoms/Combobox.es.js +3252 -0
- package/dist/components/atoms/Combobox.es.js.map +1 -0
- package/dist/components/atoms/ContextMenu.d.ts +12 -0
- package/dist/components/atoms/ContextMenu.es.js +259 -0
- package/dist/components/atoms/ContextMenu.es.js.map +1 -0
- package/dist/components/atoms/DropdownMenu.d.ts +51 -0
- package/dist/components/atoms/DropdownMenu.es.js +31 -0
- package/dist/components/atoms/DropdownMenu.es.js.map +1 -0
- package/dist/components/atoms/IconButton.d.ts +1 -1
- package/dist/components/atoms/IconButton.es.js +3 -3
- package/dist/components/atoms/IconButton.es.js.map +1 -1
- package/dist/components/atoms/IconProvider.es.js +3 -1
- package/dist/components/atoms/IconProvider.es.js.map +1 -1
- package/dist/components/atoms/Modal.es.js +1 -1
- package/dist/components/atoms/OverflowButton.es.js +2 -2
- package/dist/components/atoms/PaginationDot.d.ts +14 -0
- package/dist/components/atoms/PaginationDot.es.js +58 -0
- package/dist/components/atoms/PaginationDot.es.js.map +1 -0
- package/dist/components/atoms/PaginationItem.d.ts +15 -0
- package/dist/components/atoms/PaginationItem.es.js +87 -0
- package/dist/components/atoms/PaginationItem.es.js.map +1 -0
- package/dist/components/atoms/Popover.d.ts +10 -0
- package/dist/components/atoms/Popover.es.js +50 -0
- package/dist/components/atoms/Popover.es.js.map +1 -0
- package/dist/components/atoms/Select.d.ts +63 -0
- package/dist/components/atoms/Select.es.js +23 -0
- package/dist/components/atoms/Select.es.js.map +1 -0
- package/dist/components/atoms/Switch.es.js +7 -6
- package/dist/components/atoms/Switch.es.js.map +1 -1
- package/dist/components/atoms/TabButton.es.js +14 -12
- package/dist/components/atoms/TabButton.es.js.map +1 -1
- package/dist/components/atoms/Tag.d.ts +2 -2
- package/dist/components/atoms/Tag.es.js +66 -33
- package/dist/components/atoms/Tag.es.js.map +1 -1
- package/dist/components/atoms/Tooltip.es.js +1153 -19
- package/dist/components/atoms/Tooltip.es.js.map +1 -1
- package/dist/components/atoms/stories/OverlayThemePanels.d.ts +8 -0
- package/dist/components/molecules/Alert.es.js +3 -3
- package/dist/components/molecules/CopyField.es.js +2 -2
- package/dist/components/molecules/CustomDrawer.es.js +1 -1
- package/dist/components/molecules/Dialog.es.js +1 -1
- package/dist/components/molecules/ImagesPreview.es.js +2 -2
- package/dist/components/molecules/Input.es.js +2 -2
- package/dist/components/molecules/Markdown.es.js +1 -1
- package/dist/components/molecules/Pagination.d.ts +58 -0
- package/dist/components/molecules/Pagination.es.js +272 -0
- package/dist/components/molecules/Pagination.es.js.map +1 -0
- package/dist/components/molecules/SimpleCodeEditor.es.js +3 -3
- package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -1
- package/dist/components/molecules/TagGroup.d.ts +11 -0
- package/dist/components/molecules/TagGroup.es.js +59 -0
- package/dist/components/molecules/TagGroup.es.js.map +1 -0
- package/dist/components/molecules/ToggleButton.es.js +2 -2
- package/dist/components/molecules/agent-chat/AssistantMessage.d.ts +3 -1
- package/dist/components/molecules/agent-chat.es.js +4 -3
- package/dist/components/molecules/agent-chat.es.js.map +1 -1
- package/dist/composite-DnShFmi7.js +551 -0
- package/dist/composite-DnShFmi7.js.map +1 -0
- package/dist/{composite-BDBV1Jsx.js → composite-IA--dSel.js} +2 -2
- package/dist/{composite-BDBV1Jsx.js.map → composite-IA--dSel.js.map} +1 -1
- package/dist/constants-BaUKmVF_.js +103 -0
- package/dist/constants-BaUKmVF_.js.map +1 -0
- package/dist/{index-B6xFUIBK.js → element-B1vbc-LG.js} +69 -111
- package/dist/element-B1vbc-LG.js.map +1 -0
- package/dist/error-nCTLdGUr.js +6 -0
- package/dist/{error-FX4R42W-.js.map → error-nCTLdGUr.js.map} +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.es.js +61 -11
- package/dist/index.es.js.map +1 -1
- package/dist/{inertValue-IJM5NA30.js → inertValue-C1Ml1s55.js} +2 -2
- package/dist/{inertValue-IJM5NA30.js.map → inertValue-C1Ml1s55.js.map} +1 -1
- package/dist/isElementDisabled-lq1fKien.js +47 -0
- package/dist/isElementDisabled-lq1fKien.js.map +1 -0
- package/dist/new-components/atoms/Alert.d.ts +7 -1
- package/dist/new-components/atoms/Alert.es.js +23 -4
- package/dist/new-components/atoms/Alert.es.js.map +1 -1
- package/dist/new-components/atoms/Checkbox.es.js +8 -7
- package/dist/new-components/atoms/Checkbox.es.js.map +1 -1
- package/dist/new-components/atoms/EmptyState.d.ts +3 -0
- package/dist/new-components/atoms/EmptyState.es.js +9 -4
- package/dist/new-components/atoms/EmptyState.es.js.map +1 -1
- package/dist/new-components/atoms/Popover.es.js +3 -2
- package/dist/new-components/atoms/Popover.es.js.map +1 -1
- package/dist/new-components/atoms/Radio.es.js +13 -24
- package/dist/new-components/atoms/Radio.es.js.map +1 -1
- package/dist/new-components/atoms/SegmentedControl.es.js +7 -7
- package/dist/new-components/atoms/Slider.es.js +14 -43
- package/dist/new-components/atoms/Slider.es.js.map +1 -1
- package/dist/new-components/atoms/Toast.d.ts +8 -12
- package/dist/new-components/atoms/Toast.es.js +202 -145
- package/dist/new-components/atoms/Toast.es.js.map +1 -1
- package/dist/new-components/atoms/Toggletip.es.js +3 -2
- package/dist/new-components/atoms/Toggletip.es.js.map +1 -1
- package/dist/new-components/atoms/stories/ThemeComparison.d.ts +2 -1
- package/dist/serializeValue-BLvnTy3o.js +17 -0
- package/dist/serializeValue-BLvnTy3o.js.map +1 -0
- package/dist/stringifyLocale-DOx30wH1.js +13 -0
- package/dist/stringifyLocale-DOx30wH1.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tokens.css +3 -0
- package/dist/{useAnimationFrame-DwhymJoW.js → useAnimationFrame-DqvuRtgK.js} +2 -2
- package/dist/{useAnimationFrame-DwhymJoW.js.map → useAnimationFrame-DqvuRtgK.js.map} +1 -1
- package/dist/{useAriaLabelledBy-C9SDiruE.js → useAriaLabelledBy-CP4wKTYs.js} +3 -3
- package/dist/{useAriaLabelledBy-C9SDiruE.js.map → useAriaLabelledBy-CP4wKTYs.js.map} +1 -1
- package/dist/{useBaseUiId-jtgiQp--.js → useBaseUiId-CYT1vFMG.js} +57 -37
- package/dist/{useBaseUiId-jtgiQp--.js.map → useBaseUiId-CYT1vFMG.js.map} +1 -1
- package/dist/{useButton-BalOc_EL.js → useButton-BlHadUfM.js} +4 -4
- package/dist/{useButton-BalOc_EL.js.map → useButton-BlHadUfM.js.map} +1 -1
- package/dist/{CompositeList-D4xmSZ5V.js → useCompositeListItem-DlAKWsHE.js} +59 -59
- package/dist/useCompositeListItem-DlAKWsHE.js.map +1 -0
- package/dist/{useControlled-BSyYkg5C.js → useControlled-DMDWXIzj.js} +2 -2
- package/dist/{useControlled-BSyYkg5C.js.map → useControlled-DMDWXIzj.js.map} +1 -1
- package/dist/useFocus-C__7iwl1.js +137 -0
- package/dist/useFocus-C__7iwl1.js.map +1 -0
- package/dist/{useIsoLayoutEffect-e9VA-ICd.js → useIsoLayoutEffect-D2lpsB9D.js} +8 -4
- package/dist/{useIsoLayoutEffect-e9VA-ICd.js.map → useIsoLayoutEffect-D2lpsB9D.js.map} +1 -1
- package/dist/{usePopupHandleStore-DYUo-Fyk.js → usePopupHandleStore-C_Vw7xcw.js} +1966 -2002
- package/dist/usePopupHandleStore-C_Vw7xcw.js.map +1 -0
- package/dist/{Tooltip-6R-t7wt1.js → usePositioner-BmYVsMO_.js} +17 -1403
- package/dist/usePositioner-BmYVsMO_.js.map +1 -0
- package/dist/{useOpenInteractionType-BnUZ2Eio.js → useScrollLock-By-42HSc.js} +74 -58
- package/dist/useScrollLock-By-42HSc.js.map +1 -0
- package/dist/{useLabelableId-CQqNbBk1.js → useSetFieldFocused-CcdG6FNp.js} +27 -35
- package/dist/useSetFieldFocused-CcdG6FNp.js.map +1 -0
- package/dist/{useTimeout-BXf1hDIL.js → useTimeout-D1vYJgq4.js} +3 -3
- package/dist/{useTimeout-BXf1hDIL.js.map → useTimeout-D1vYJgq4.js.map} +1 -1
- package/dist/{useTransitionStatus-C9gg_XJ-.js → useTransitionStatus-CHrs3i5F.js} +3 -3
- package/dist/{useTransitionStatus-C9gg_XJ-.js.map → useTransitionStatus-CHrs3i5F.js.map} +1 -1
- package/dist/useTriggerFocusGuards-CXAhW8P6.js +100 -0
- package/dist/useTriggerFocusGuards-CXAhW8P6.js.map +1 -0
- package/dist/useValueChanged-BnlOop8k.js +16 -0
- package/dist/useValueChanged-BnlOop8k.js.map +1 -0
- package/package.json +1 -1
- package/dist/CompositeList-D4xmSZ5V.js.map +0 -1
- package/dist/CompositeRoot-DnijP7Jm.js.map +0 -1
- package/dist/Popover-B6z7exNd.js.map +0 -1
- package/dist/PrehydrationScript--08s8Mfl.js.map +0 -1
- package/dist/Tooltip-6R-t7wt1.js.map +0 -1
- package/dist/composite-rAI4IlWK.js +0 -66
- package/dist/composite-rAI4IlWK.js.map +0 -1
- package/dist/error-FX4R42W-.js +0 -6
- package/dist/index-B6xFUIBK.js.map +0 -1
- package/dist/shadowDom-CRvvf3qf.js +0 -52
- package/dist/shadowDom-CRvvf3qf.js.map +0 -1
- package/dist/useLabelableId-CQqNbBk1.js.map +0 -1
- package/dist/useOpenInteractionType-BnUZ2Eio.js.map +0 -1
- package/dist/usePopupHandleStore-DYUo-Fyk.js.map +0 -1
- package/dist/useValueAsRef-BfFRcMg6.js.map +0 -1
|
@@ -0,0 +1,2187 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { c as cva } from "./index-DSVg79g-.js";
|
|
4
|
+
import { E as useListNavigation, G as useTypeahead, H as isMouseWithinBounds, b as dropdownListVariants, t as dropdownPanelVariants, d as dropdownItemVariants, a as dropdownLabelVariants, u as dropdownSeparatorVariants } from "./DropdownMenu-Crlf-J4E.js";
|
|
5
|
+
import IconProvider from "./components/atoms/IconProvider.es.js";
|
|
6
|
+
import { c as classNames } from "./classNames-B1XpQHle.js";
|
|
7
|
+
import { v as visuallyHiddenInput, a as visuallyHidden } from "./visuallyHidden-B6H2X3_Y.js";
|
|
8
|
+
import { e as useRefWithInit, u as useIsoLayoutEffect, b as useRenderElement, f as formatErrorMessage, d as EMPTY_OBJECT, N as NOOP, a as useStableCallback, m as mergeProps, c as useMergedRefs, E as EMPTY_ARRAY } from "./useIsoLayoutEffect-D2lpsB9D.js";
|
|
9
|
+
import { i as isElementDisabled } from "./isElementDisabled-lq1fKien.js";
|
|
10
|
+
import { u as useControlled } from "./useControlled-DMDWXIzj.js";
|
|
11
|
+
import { u as useValueAsRef, a as addEventListener } from "./addEventListener-D-i9O6BG.js";
|
|
12
|
+
import { u as useFormContext, a as useFieldRootContext, d as useLabelableId, e as useRegisterFieldControl, b as useLabelableContext, c as useSetFieldFocused, f as fieldValidityMapping } from "./useSetFieldFocused-CcdG6FNp.js";
|
|
13
|
+
import { e as useFloatingParentNodeId, f as FloatingRootStore, P as PopupTriggerMap, R as ReactStore, u as useUnmountAfterClose, a as attachPreventUnmountOnClose, b as useDismiss, F as FOCUSABLE_POPUP_PROPS, p as pressableTriggerOpenStateMapping, c as FloatingPortal, D as DROPDOWN_COLLISION_AVOIDANCE, w as webkit, d as popupStateMapping } from "./usePopupHandleStore-C_Vw7xcw.js";
|
|
14
|
+
import { a as areArraysEqual, c as clamp, r as resolveAriaLabelledBy } from "./clamp-D7_nsB8C.js";
|
|
15
|
+
import { s as serializeValue } from "./serializeValue-BLvnTy3o.js";
|
|
16
|
+
import { j as useId, A as isElement, s as focusOut, v as outsidePress, c as createChangeEventDetails, n as none, y as imperativeAction, k as cancelOpen, b as getWindow, F as windowResize, w as itemPress, u as useBaseUiId } from "./useBaseUiId-CYT1vFMG.js";
|
|
17
|
+
import { u as useValueChanged } from "./useValueChanged-BnlOop8k.js";
|
|
18
|
+
import { u as useOpenInteractionType, a as useClick, I as InternalBackdrop, F as FloatingFocusManager } from "./useScrollLock-By-42HSc.js";
|
|
19
|
+
import { i as inertValue } from "./inertValue-C1Ml1s55.js";
|
|
20
|
+
import { C as CompositeList, u as useCompositeListItem } from "./useCompositeListItem-DlAKWsHE.js";
|
|
21
|
+
import { u as useAnchorPositioning, a as usePositioner, p as platform, g as getDisabledMountTransitionStyles } from "./usePositioner-BmYVsMO_.js";
|
|
22
|
+
import { u as useAnchoredPopupScrollLock } from "./useTriggerFocusGuards-CXAhW8P6.js";
|
|
23
|
+
import { c as rectToClientRect, d as isVirtualClick } from "./composite-DnShFmi7.js";
|
|
24
|
+
import { g as getFloatingFocusElement, o as ownerDocument } from "./element-B1vbc-LG.js";
|
|
25
|
+
import { u as useAnimationFrame } from "./useAnimationFrame-DqvuRtgK.js";
|
|
26
|
+
import { u as useTransitionStatus, a as useOpenChangeComplete, t as transitionStatusMapping } from "./useTransitionStatus-CHrs3i5F.js";
|
|
27
|
+
import { u as useToolbarRootContext } from "./ToolbarRootContext-B_HxjkNI.js";
|
|
28
|
+
import { C as COMPOSITE_KEYS } from "./composite-IA--dSel.js";
|
|
29
|
+
import { u as useCSPContext } from "./CSPContext-Cldo9QDp.js";
|
|
30
|
+
import { u as useDirection } from "./DirectionContext-Pb9yafF5.js";
|
|
31
|
+
import { a as useButton } from "./useButton-BlHadUfM.js";
|
|
32
|
+
import { u as useTimeout } from "./useTimeout-D1vYJgq4.js";
|
|
33
|
+
import { c as contains } from "./constants-BaUKmVF_.js";
|
|
34
|
+
function useOnFirstRender(fn) {
|
|
35
|
+
const ref = React.useRef(true);
|
|
36
|
+
if (ref.current) {
|
|
37
|
+
ref.current = false;
|
|
38
|
+
fn();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function useFloatingRootContext(options) {
|
|
42
|
+
const {
|
|
43
|
+
open = false,
|
|
44
|
+
onOpenChange,
|
|
45
|
+
elements = {}
|
|
46
|
+
} = options;
|
|
47
|
+
const floatingId = useId();
|
|
48
|
+
const nested = useFloatingParentNodeId() != null;
|
|
49
|
+
if (process.env.NODE_ENV !== "production") {
|
|
50
|
+
const optionDomReference = elements.reference;
|
|
51
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
52
|
+
console.error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `context.setPositionReference()`", "instead.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const store = useRefWithInit(() => new FloatingRootStore({
|
|
56
|
+
open,
|
|
57
|
+
transitionStatus: void 0,
|
|
58
|
+
onOpenChange,
|
|
59
|
+
referenceElement: elements.reference ?? null,
|
|
60
|
+
floatingElement: elements.floating ?? null,
|
|
61
|
+
triggerElements: new PopupTriggerMap(),
|
|
62
|
+
floatingId,
|
|
63
|
+
syncOnly: false,
|
|
64
|
+
nested
|
|
65
|
+
})).current;
|
|
66
|
+
useIsoLayoutEffect(() => {
|
|
67
|
+
const valuesToSync = {
|
|
68
|
+
open,
|
|
69
|
+
floatingId
|
|
70
|
+
};
|
|
71
|
+
if (elements.reference !== void 0) {
|
|
72
|
+
valuesToSync.referenceElement = elements.reference;
|
|
73
|
+
valuesToSync.domReferenceElement = isElement(elements.reference) ? elements.reference : null;
|
|
74
|
+
}
|
|
75
|
+
if (elements.floating !== void 0) {
|
|
76
|
+
valuesToSync.floatingElement = elements.floating;
|
|
77
|
+
}
|
|
78
|
+
store.update(valuesToSync);
|
|
79
|
+
}, [open, floatingId, elements.reference, elements.floating, store]);
|
|
80
|
+
store.context.onOpenChange = onOpenChange;
|
|
81
|
+
store.context.nested = nested;
|
|
82
|
+
return store;
|
|
83
|
+
}
|
|
84
|
+
const defaultItemEquality = (itemValue, selectedValue) => Object.is(itemValue, selectedValue);
|
|
85
|
+
function compareItemEquality(itemValue, selectedValue, comparer) {
|
|
86
|
+
if (itemValue == null || selectedValue == null) {
|
|
87
|
+
return Object.is(itemValue, selectedValue);
|
|
88
|
+
}
|
|
89
|
+
return comparer(itemValue, selectedValue);
|
|
90
|
+
}
|
|
91
|
+
function isSelectedValueDirty(currentValue, initialValue, comparer) {
|
|
92
|
+
if (Array.isArray(currentValue) && Array.isArray(initialValue)) {
|
|
93
|
+
return !areArraysEqual(currentValue, initialValue, (itemValue, initialItemValue) => compareItemEquality(itemValue, initialItemValue, comparer));
|
|
94
|
+
}
|
|
95
|
+
return currentValue !== initialValue;
|
|
96
|
+
}
|
|
97
|
+
function selectedValueIncludes(selectedValues, itemValue, comparer) {
|
|
98
|
+
if (!selectedValues) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return selectedValues.some((selectedValue) => {
|
|
102
|
+
if (selectedValue === void 0) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return compareItemEquality(itemValue, selectedValue, comparer);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function findItemIndex(itemValues, selectedValue, comparer) {
|
|
109
|
+
if (!itemValues) {
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
return itemValues.findIndex((itemValue) => {
|
|
113
|
+
if (itemValue === void 0) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return compareItemEquality(itemValue, selectedValue, comparer);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function createSelectionMatcher(selectedValues, comparer) {
|
|
120
|
+
if (comparer !== defaultItemEquality) {
|
|
121
|
+
return (itemValue) => selectedValueIncludes(selectedValues, itemValue, comparer);
|
|
122
|
+
}
|
|
123
|
+
const index = new Set(selectedValues);
|
|
124
|
+
index.delete(void 0);
|
|
125
|
+
return (itemValue) => index.has(itemValue) && (itemValue !== 0 || selectedValues.some((v) => Object.is(itemValue, v)));
|
|
126
|
+
}
|
|
127
|
+
function findSelectionIndex(itemValues, selectedValue, comparer, multiple) {
|
|
128
|
+
const index = multiple && Array.isArray(selectedValue) ? (
|
|
129
|
+
// Anchor to the first selected item in rendered order so the index does not depend
|
|
130
|
+
// on the order in which the values were added to the array.
|
|
131
|
+
itemValues.findIndex(createSelectionMatcher(selectedValue, comparer))
|
|
132
|
+
) : findItemIndex(itemValues, selectedValue, comparer);
|
|
133
|
+
return index === -1 ? null : index;
|
|
134
|
+
}
|
|
135
|
+
function resolveSelectedIndex(index, itemValue, registry, selectedValues, comparer, currentIndex) {
|
|
136
|
+
if (selectedValueIncludes(selectedValues, itemValue, comparer)) {
|
|
137
|
+
return currentIndex != null && index > currentIndex && selectedValueIncludes(selectedValues, registry[currentIndex], comparer) ? currentIndex : index;
|
|
138
|
+
}
|
|
139
|
+
return index === currentIndex ? findSelectionIndex(registry, selectedValues, comparer, true) : currentIndex;
|
|
140
|
+
}
|
|
141
|
+
function removeItem(selectedValues, itemValue, comparer) {
|
|
142
|
+
return selectedValues.filter((selectedValue) => !compareItemEquality(itemValue, selectedValue, comparer));
|
|
143
|
+
}
|
|
144
|
+
function isGroup(item) {
|
|
145
|
+
return typeof item === "object" && item != null && Array.isArray(item.items);
|
|
146
|
+
}
|
|
147
|
+
function isGroupedItems(items) {
|
|
148
|
+
return isGroup(items == null ? void 0 : items[0]);
|
|
149
|
+
}
|
|
150
|
+
function flattenLeafItems(items) {
|
|
151
|
+
return isGroupedItems(items) ? items.flatMap((group) => group.items) : items;
|
|
152
|
+
}
|
|
153
|
+
function hasNullItemLabel(items) {
|
|
154
|
+
if (!Array.isArray(items)) {
|
|
155
|
+
return items != null && "null" in items;
|
|
156
|
+
}
|
|
157
|
+
const arrayItems = items;
|
|
158
|
+
if (isGroupedItems(arrayItems)) {
|
|
159
|
+
for (const group of arrayItems) {
|
|
160
|
+
for (const item of group.items) {
|
|
161
|
+
if (item && item.value == null && item.label != null) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
for (const item of arrayItems) {
|
|
169
|
+
if (item && item.value == null && item.label != null) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
function stringifyAsLabel(item, itemToStringLabel) {
|
|
176
|
+
if (itemToStringLabel && item != null) {
|
|
177
|
+
return itemToStringLabel(item) ?? "";
|
|
178
|
+
}
|
|
179
|
+
if (item && typeof item === "object") {
|
|
180
|
+
if ("label" in item && item.label != null) {
|
|
181
|
+
return String(item.label);
|
|
182
|
+
}
|
|
183
|
+
if ("value" in item) {
|
|
184
|
+
return String(item.value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return serializeValue(item);
|
|
188
|
+
}
|
|
189
|
+
function stringifyAsValue(item, itemToStringValue) {
|
|
190
|
+
if (itemToStringValue && item != null) {
|
|
191
|
+
return itemToStringValue(item) ?? "";
|
|
192
|
+
}
|
|
193
|
+
if (item && typeof item === "object" && "value" in item && "label" in item) {
|
|
194
|
+
return serializeValue(item.value);
|
|
195
|
+
}
|
|
196
|
+
return serializeValue(item);
|
|
197
|
+
}
|
|
198
|
+
function resolveSelectedLabel(value, items, itemToStringLabel) {
|
|
199
|
+
function fallback() {
|
|
200
|
+
return stringifyAsLabel(value, itemToStringLabel);
|
|
201
|
+
}
|
|
202
|
+
if (itemToStringLabel && value != null) {
|
|
203
|
+
return itemToStringLabel(value);
|
|
204
|
+
}
|
|
205
|
+
if (value && typeof value === "object" && "label" in value && value.label != null) {
|
|
206
|
+
return value.label;
|
|
207
|
+
}
|
|
208
|
+
if (items && !Array.isArray(items)) {
|
|
209
|
+
const label = Object.hasOwn(items, value) ? items[value] : void 0;
|
|
210
|
+
return label ?? fallback();
|
|
211
|
+
}
|
|
212
|
+
if (Array.isArray(items)) {
|
|
213
|
+
const arrayItems = items;
|
|
214
|
+
const flatItems = flattenLeafItems(arrayItems);
|
|
215
|
+
if (value == null || typeof value !== "object") {
|
|
216
|
+
const match = flatItems.find((item) => item.value === value);
|
|
217
|
+
if (match && match.label != null) {
|
|
218
|
+
return match.label;
|
|
219
|
+
}
|
|
220
|
+
return fallback();
|
|
221
|
+
}
|
|
222
|
+
if ("value" in value) {
|
|
223
|
+
const match = flatItems.find((item) => item && item.value === value.value);
|
|
224
|
+
if (match && match.label != null) {
|
|
225
|
+
return match.label;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return fallback();
|
|
230
|
+
}
|
|
231
|
+
function resolveMultipleLabels(values, items, itemToStringLabel) {
|
|
232
|
+
return values.reduce((acc, value, index) => {
|
|
233
|
+
if (index > 0) {
|
|
234
|
+
acc.push(", ");
|
|
235
|
+
}
|
|
236
|
+
acc.push(/* @__PURE__ */ jsx(React.Fragment, {
|
|
237
|
+
children: resolveSelectedLabel(value, items, itemToStringLabel)
|
|
238
|
+
}, index));
|
|
239
|
+
return acc;
|
|
240
|
+
}, []);
|
|
241
|
+
}
|
|
242
|
+
const ItemIndicator = /* @__PURE__ */ React.memo(/* @__PURE__ */ React.forwardRef(function ItemIndicator2(componentProps, forwardedRef) {
|
|
243
|
+
const {
|
|
244
|
+
render,
|
|
245
|
+
className,
|
|
246
|
+
style,
|
|
247
|
+
keepMounted,
|
|
248
|
+
selected,
|
|
249
|
+
...elementProps
|
|
250
|
+
} = componentProps;
|
|
251
|
+
const indicatorRef = React.useRef(null);
|
|
252
|
+
const {
|
|
253
|
+
transitionStatus,
|
|
254
|
+
setMounted
|
|
255
|
+
} = useTransitionStatus(selected);
|
|
256
|
+
const state = {
|
|
257
|
+
selected,
|
|
258
|
+
transitionStatus
|
|
259
|
+
};
|
|
260
|
+
const element = useRenderElement("span", componentProps, {
|
|
261
|
+
ref: [forwardedRef, indicatorRef],
|
|
262
|
+
state,
|
|
263
|
+
props: [{
|
|
264
|
+
"aria-hidden": true,
|
|
265
|
+
children: "✔️"
|
|
266
|
+
}, elementProps],
|
|
267
|
+
stateAttributesMapping: transitionStatusMapping
|
|
268
|
+
});
|
|
269
|
+
useOpenChangeComplete({
|
|
270
|
+
batch: true,
|
|
271
|
+
enabled: !selected,
|
|
272
|
+
open: selected,
|
|
273
|
+
ref: indicatorRef,
|
|
274
|
+
onComplete() {
|
|
275
|
+
if (!selected) {
|
|
276
|
+
setMounted(false);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return element;
|
|
281
|
+
}));
|
|
282
|
+
if (process.env.NODE_ENV !== "production") ItemIndicator.displayName = "ItemIndicator";
|
|
283
|
+
const ListboxSeparator = /* @__PURE__ */ React.forwardRef(function ListboxSeparator2(componentProps, forwardedRef) {
|
|
284
|
+
const {
|
|
285
|
+
className,
|
|
286
|
+
render,
|
|
287
|
+
orientation = "horizontal",
|
|
288
|
+
style,
|
|
289
|
+
...elementProps
|
|
290
|
+
} = componentProps;
|
|
291
|
+
const state = {
|
|
292
|
+
orientation
|
|
293
|
+
};
|
|
294
|
+
return useRenderElement("div", componentProps, {
|
|
295
|
+
state,
|
|
296
|
+
ref: forwardedRef,
|
|
297
|
+
props: [{
|
|
298
|
+
role: "presentation"
|
|
299
|
+
}, elementProps]
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
if (process.env.NODE_ENV !== "production") ListboxSeparator.displayName = "ListboxSeparator";
|
|
303
|
+
function usePreviousValue(value) {
|
|
304
|
+
const [state, setState] = React.useState({
|
|
305
|
+
current: value,
|
|
306
|
+
previous: null
|
|
307
|
+
});
|
|
308
|
+
if (!Object.is(value, state.current)) {
|
|
309
|
+
setState({
|
|
310
|
+
current: value,
|
|
311
|
+
previous: state.current
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return state.previous;
|
|
315
|
+
}
|
|
316
|
+
const SelectRootContext = /* @__PURE__ */ React.createContext(void 0);
|
|
317
|
+
if (process.env.NODE_ENV !== "production") SelectRootContext.displayName = "SelectRootContext";
|
|
318
|
+
const SelectFloatingContext = /* @__PURE__ */ React.createContext(void 0);
|
|
319
|
+
if (process.env.NODE_ENV !== "production") SelectFloatingContext.displayName = "SelectFloatingContext";
|
|
320
|
+
function useSelectRootContext() {
|
|
321
|
+
const store = React.useContext(SelectRootContext);
|
|
322
|
+
if (store === void 0) {
|
|
323
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SelectRootContext is missing. Select parts must be placed within <Select.Root>." : formatErrorMessage(60));
|
|
324
|
+
}
|
|
325
|
+
return store;
|
|
326
|
+
}
|
|
327
|
+
function useSelectFloatingContext() {
|
|
328
|
+
const context = React.useContext(SelectFloatingContext);
|
|
329
|
+
if (context === void 0) {
|
|
330
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SelectFloatingContext is missing. Select parts must be placed within <Select.Root>." : formatErrorMessage(61));
|
|
331
|
+
}
|
|
332
|
+
return context;
|
|
333
|
+
}
|
|
334
|
+
const selectors = {
|
|
335
|
+
id: (state) => state.id,
|
|
336
|
+
labelId: (state) => state.labelId,
|
|
337
|
+
modal: (state) => state.modal,
|
|
338
|
+
multiple: (state) => state.multiple,
|
|
339
|
+
disabled: (state) => state.disabled,
|
|
340
|
+
readOnly: (state) => state.readOnly,
|
|
341
|
+
required: (state) => state.required,
|
|
342
|
+
highlightItemOnHover: (state) => state.highlightItemOnHover,
|
|
343
|
+
items: (state) => state.items,
|
|
344
|
+
itemToStringLabel: (state) => state.itemToStringLabel,
|
|
345
|
+
isItemEqualToValue: (state) => state.isItemEqualToValue,
|
|
346
|
+
value: (state) => state.value,
|
|
347
|
+
hasSelectedValue: (state) => {
|
|
348
|
+
const {
|
|
349
|
+
value,
|
|
350
|
+
multiple,
|
|
351
|
+
itemToStringValue
|
|
352
|
+
} = state;
|
|
353
|
+
if (value == null) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
if (multiple && Array.isArray(value)) {
|
|
357
|
+
return value.length > 0;
|
|
358
|
+
}
|
|
359
|
+
return stringifyAsValue(value, itemToStringValue) !== "";
|
|
360
|
+
},
|
|
361
|
+
hasNullItemLabel: (state, enabled) => {
|
|
362
|
+
return enabled ? hasNullItemLabel(state.items) : false;
|
|
363
|
+
},
|
|
364
|
+
open: (state) => state.open,
|
|
365
|
+
mounted: (state) => state.mounted,
|
|
366
|
+
forceMount: (state) => state.forceMount,
|
|
367
|
+
transitionStatus: (state) => state.transitionStatus,
|
|
368
|
+
openMethod: (state) => state.openMethod,
|
|
369
|
+
activeIndex: (state) => state.activeIndex,
|
|
370
|
+
selectedIndex: (state) => state.selectedIndex,
|
|
371
|
+
isActive: (state, index) => state.activeIndex === index,
|
|
372
|
+
isSelected: (state, itemValue) => {
|
|
373
|
+
const comparer = state.isItemEqualToValue;
|
|
374
|
+
const storeValue = state.value;
|
|
375
|
+
if (state.multiple) {
|
|
376
|
+
return Array.isArray(storeValue) && storeValue.some((selectedItem) => compareItemEquality(itemValue, selectedItem, comparer));
|
|
377
|
+
}
|
|
378
|
+
return compareItemEquality(itemValue, storeValue, comparer);
|
|
379
|
+
},
|
|
380
|
+
isSelectedByFocus: (state, index) => {
|
|
381
|
+
return state.selectedIndex === index;
|
|
382
|
+
},
|
|
383
|
+
popupProps: (state) => state.popupProps,
|
|
384
|
+
triggerProps: (state) => state.triggerProps,
|
|
385
|
+
itemRoot: (state) => state.itemRoot,
|
|
386
|
+
triggerElement: (state) => state.triggerElement,
|
|
387
|
+
positionerElement: (state) => state.positionerElement,
|
|
388
|
+
listElement: (state) => state.listElement,
|
|
389
|
+
popupSide: (state) => state.popupSide,
|
|
390
|
+
scrollUpArrowVisible: (state) => state.scrollUpArrowVisible,
|
|
391
|
+
scrollDownArrowVisible: (state) => state.scrollDownArrowVisible,
|
|
392
|
+
hasScrollArrows: (state) => state.hasScrollArrows
|
|
393
|
+
};
|
|
394
|
+
const SCROLL_EDGE_TOLERANCE_PX = 1;
|
|
395
|
+
function getMaxScrollOffset(scrollSize, clientSize) {
|
|
396
|
+
return Math.max(0, scrollSize - clientSize);
|
|
397
|
+
}
|
|
398
|
+
function normalizeScrollOffset(value, max) {
|
|
399
|
+
if (max <= 0) {
|
|
400
|
+
return 0;
|
|
401
|
+
}
|
|
402
|
+
const clamped = clamp(value, 0, max);
|
|
403
|
+
const startDistance = clamped;
|
|
404
|
+
const endDistance = max - clamped;
|
|
405
|
+
const withinStartTolerance = startDistance <= SCROLL_EDGE_TOLERANCE_PX;
|
|
406
|
+
const withinEndTolerance = endDistance <= SCROLL_EDGE_TOLERANCE_PX;
|
|
407
|
+
if (withinStartTolerance && withinEndTolerance) {
|
|
408
|
+
return startDistance <= endDistance ? 0 : max;
|
|
409
|
+
}
|
|
410
|
+
if (withinStartTolerance) {
|
|
411
|
+
return 0;
|
|
412
|
+
}
|
|
413
|
+
if (withinEndTolerance) {
|
|
414
|
+
return max;
|
|
415
|
+
}
|
|
416
|
+
return clamped;
|
|
417
|
+
}
|
|
418
|
+
function SelectRoot(props) {
|
|
419
|
+
const {
|
|
420
|
+
id,
|
|
421
|
+
value: valueProp,
|
|
422
|
+
defaultValue = null,
|
|
423
|
+
onValueChange,
|
|
424
|
+
open: openProp,
|
|
425
|
+
defaultOpen = false,
|
|
426
|
+
onOpenChange,
|
|
427
|
+
name: nameProp,
|
|
428
|
+
form,
|
|
429
|
+
autoComplete,
|
|
430
|
+
disabled: disabledProp = false,
|
|
431
|
+
readOnly = false,
|
|
432
|
+
required = false,
|
|
433
|
+
modal = true,
|
|
434
|
+
actionsRef,
|
|
435
|
+
inputRef,
|
|
436
|
+
onOpenChangeComplete,
|
|
437
|
+
items,
|
|
438
|
+
multiple = false,
|
|
439
|
+
itemToStringLabel,
|
|
440
|
+
itemToStringValue,
|
|
441
|
+
isItemEqualToValue = defaultItemEquality,
|
|
442
|
+
highlightItemOnHover = true,
|
|
443
|
+
children
|
|
444
|
+
} = props;
|
|
445
|
+
const {
|
|
446
|
+
clearErrors
|
|
447
|
+
} = useFormContext();
|
|
448
|
+
const {
|
|
449
|
+
setDirty,
|
|
450
|
+
setTouched,
|
|
451
|
+
setFocused,
|
|
452
|
+
validityData,
|
|
453
|
+
setFilled,
|
|
454
|
+
name: fieldName,
|
|
455
|
+
disabled: fieldDisabled,
|
|
456
|
+
validation,
|
|
457
|
+
validationMode
|
|
458
|
+
} = useFieldRootContext();
|
|
459
|
+
const generatedId = useLabelableId({
|
|
460
|
+
id
|
|
461
|
+
});
|
|
462
|
+
const disabled = fieldDisabled || disabledProp;
|
|
463
|
+
const name = fieldName ?? nameProp;
|
|
464
|
+
const [value, setValueUnwrapped] = useControlled({
|
|
465
|
+
controlled: valueProp,
|
|
466
|
+
default: multiple ? defaultValue ?? EMPTY_ARRAY : defaultValue,
|
|
467
|
+
name: "Select",
|
|
468
|
+
state: "value"
|
|
469
|
+
});
|
|
470
|
+
const [open, setOpenUnwrapped] = useControlled({
|
|
471
|
+
controlled: openProp,
|
|
472
|
+
default: defaultOpen,
|
|
473
|
+
name: "Select",
|
|
474
|
+
state: "open"
|
|
475
|
+
});
|
|
476
|
+
const listRef = React.useRef([]);
|
|
477
|
+
const labelsRef = React.useRef([]);
|
|
478
|
+
const popupRef = React.useRef(null);
|
|
479
|
+
const scrollHandlerRef = React.useRef(null);
|
|
480
|
+
const scrollArrowsMountedCountRef = React.useRef(0);
|
|
481
|
+
const valueRef = React.useRef(null);
|
|
482
|
+
const valuesRef = React.useRef([]);
|
|
483
|
+
const typingRef = React.useRef(false);
|
|
484
|
+
const firstItemTextRef = React.useRef(null);
|
|
485
|
+
const selectedItemTextRef = React.useRef(null);
|
|
486
|
+
const selectionRef = React.useRef({
|
|
487
|
+
allowSelectedMouseUp: false,
|
|
488
|
+
allowUnselectedMouseUp: false,
|
|
489
|
+
dragY: 0
|
|
490
|
+
});
|
|
491
|
+
const alignItemWithTriggerActiveRef = React.useRef(false);
|
|
492
|
+
const initialValueRef = React.useRef(value);
|
|
493
|
+
const {
|
|
494
|
+
openMethod,
|
|
495
|
+
triggerProps: interactionTypeProps
|
|
496
|
+
} = useOpenInteractionType(open);
|
|
497
|
+
const store = useRefWithInit(() => new ReactStore({
|
|
498
|
+
id: generatedId,
|
|
499
|
+
labelId: void 0,
|
|
500
|
+
modal,
|
|
501
|
+
multiple,
|
|
502
|
+
disabled,
|
|
503
|
+
readOnly,
|
|
504
|
+
required,
|
|
505
|
+
highlightItemOnHover,
|
|
506
|
+
itemToStringLabel,
|
|
507
|
+
itemToStringValue,
|
|
508
|
+
isItemEqualToValue,
|
|
509
|
+
value,
|
|
510
|
+
open,
|
|
511
|
+
// Seeded with the initial values of `useUnmountAfterClose`, which is called after the
|
|
512
|
+
// store because its unmount cleanup writes to it. `useSyncedValues` keeps them in sync.
|
|
513
|
+
mounted: open,
|
|
514
|
+
transitionStatus: void 0,
|
|
515
|
+
items,
|
|
516
|
+
forceMount: false,
|
|
517
|
+
openMethod: null,
|
|
518
|
+
activeIndex: null,
|
|
519
|
+
selectedIndex: null,
|
|
520
|
+
popupProps: EMPTY_OBJECT,
|
|
521
|
+
triggerProps: EMPTY_OBJECT,
|
|
522
|
+
itemRoot: {
|
|
523
|
+
props: EMPTY_OBJECT,
|
|
524
|
+
multiple,
|
|
525
|
+
disabled,
|
|
526
|
+
readOnly,
|
|
527
|
+
isItemEqualToValue
|
|
528
|
+
},
|
|
529
|
+
triggerElement: null,
|
|
530
|
+
positionerElement: null,
|
|
531
|
+
listElement: null,
|
|
532
|
+
popupSide: null,
|
|
533
|
+
scrollUpArrowVisible: false,
|
|
534
|
+
scrollDownArrowVisible: false,
|
|
535
|
+
hasScrollArrows: false
|
|
536
|
+
}, {
|
|
537
|
+
setValue: NOOP,
|
|
538
|
+
setOpen: NOOP,
|
|
539
|
+
handleScrollArrowVisibility: NOOP,
|
|
540
|
+
onOpenChangeComplete: NOOP,
|
|
541
|
+
listRef,
|
|
542
|
+
popupRef,
|
|
543
|
+
scrollHandlerRef,
|
|
544
|
+
scrollArrowsMountedCountRef,
|
|
545
|
+
valueRef,
|
|
546
|
+
valuesRef,
|
|
547
|
+
labelsRef,
|
|
548
|
+
typingRef,
|
|
549
|
+
selectionRef,
|
|
550
|
+
firstItemTextRef,
|
|
551
|
+
selectedItemTextRef,
|
|
552
|
+
alignItemWithTriggerActiveRef,
|
|
553
|
+
initialValueRef
|
|
554
|
+
}, selectors)).current;
|
|
555
|
+
const [preventUnmountOnClose, setPreventUnmountOnClose] = React.useState(false);
|
|
556
|
+
const {
|
|
557
|
+
mounted,
|
|
558
|
+
transitionStatus,
|
|
559
|
+
forceUnmount: handleUnmount
|
|
560
|
+
} = useUnmountAfterClose({
|
|
561
|
+
open,
|
|
562
|
+
ref: popupRef,
|
|
563
|
+
preventUnmountOnClose,
|
|
564
|
+
setPreventUnmountOnClose,
|
|
565
|
+
onUnmount() {
|
|
566
|
+
store.update({
|
|
567
|
+
activeIndex: null,
|
|
568
|
+
openMethod: null,
|
|
569
|
+
scrollUpArrowVisible: false,
|
|
570
|
+
scrollDownArrowVisible: false
|
|
571
|
+
});
|
|
572
|
+
onOpenChangeComplete == null ? void 0 : onOpenChangeComplete(false);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
const activeIndex = store.useState("activeIndex");
|
|
576
|
+
const selectedIndex = store.useState("selectedIndex");
|
|
577
|
+
const triggerElement = store.useState("triggerElement");
|
|
578
|
+
const positionerElement = store.useState("positionerElement");
|
|
579
|
+
const previousOpenMethod = usePreviousValue(openMethod);
|
|
580
|
+
const renderedOpenMethod = openMethod ?? previousOpenMethod;
|
|
581
|
+
const serializedValue = React.useMemo(() => {
|
|
582
|
+
if (multiple) {
|
|
583
|
+
return "";
|
|
584
|
+
}
|
|
585
|
+
return stringifyAsValue(value, itemToStringValue);
|
|
586
|
+
}, [multiple, value, itemToStringValue]);
|
|
587
|
+
const fieldStringValue = React.useMemo(() => {
|
|
588
|
+
if (multiple && Array.isArray(value)) {
|
|
589
|
+
return value.map((currentValue) => stringifyAsValue(currentValue, itemToStringValue));
|
|
590
|
+
}
|
|
591
|
+
return stringifyAsValue(value, itemToStringValue);
|
|
592
|
+
}, [multiple, value, itemToStringValue]);
|
|
593
|
+
const controlRef = useValueAsRef(triggerElement);
|
|
594
|
+
const getStringifiedValueForForm = useStableCallback(() => fieldStringValue);
|
|
595
|
+
useRegisterFieldControl(controlRef, generatedId, value, getStringifiedValueForForm, !disabled, nameProp);
|
|
596
|
+
const hasSelectedValue = multiple ? Array.isArray(value) && value.length > 0 : value != null && serializedValue !== "";
|
|
597
|
+
useIsoLayoutEffect(() => {
|
|
598
|
+
setFilled(hasSelectedValue);
|
|
599
|
+
}, [hasSelectedValue, setFilled]);
|
|
600
|
+
useIsoLayoutEffect(function syncSelectedIndex() {
|
|
601
|
+
const nextIndex = findSelectionIndex(valuesRef.current, value, isItemEqualToValue, multiple);
|
|
602
|
+
if (nextIndex === null) {
|
|
603
|
+
selectedItemTextRef.current = null;
|
|
604
|
+
}
|
|
605
|
+
if (open) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
store.set("selectedIndex", nextIndex);
|
|
609
|
+
}, [multiple, open, value, isItemEqualToValue, store]);
|
|
610
|
+
useValueChanged(value, () => {
|
|
611
|
+
clearErrors(name);
|
|
612
|
+
setDirty(isSelectedValueDirty(value, validityData.initialValue, isItemEqualToValue));
|
|
613
|
+
validation.change(value);
|
|
614
|
+
});
|
|
615
|
+
const setOpen = useStableCallback((nextOpen, eventDetails) => {
|
|
616
|
+
const openEventDetails = eventDetails;
|
|
617
|
+
const shouldPreventUnmountOnClose = attachPreventUnmountOnClose(openEventDetails);
|
|
618
|
+
onOpenChange == null ? void 0 : onOpenChange(nextOpen, openEventDetails);
|
|
619
|
+
if (eventDetails.isCanceled) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (!nextOpen) {
|
|
623
|
+
setPreventUnmountOnClose(shouldPreventUnmountOnClose());
|
|
624
|
+
}
|
|
625
|
+
setOpenUnwrapped(nextOpen);
|
|
626
|
+
if (!nextOpen && (eventDetails.reason === focusOut || eventDetails.reason === outsidePress)) {
|
|
627
|
+
setTouched(true);
|
|
628
|
+
setFocused(false);
|
|
629
|
+
if (validationMode === "onBlur") {
|
|
630
|
+
validation.commit(value);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
React.useImperativeHandle(actionsRef, () => ({
|
|
635
|
+
unmount: handleUnmount,
|
|
636
|
+
close: () => {
|
|
637
|
+
if (store.state.open) {
|
|
638
|
+
setOpen(false, createChangeEventDetails(imperativeAction));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}), [handleUnmount, setOpen, store]);
|
|
642
|
+
const setValue = useStableCallback((nextValue, eventDetails) => {
|
|
643
|
+
onValueChange == null ? void 0 : onValueChange(nextValue, eventDetails);
|
|
644
|
+
if (eventDetails.isCanceled) {
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
setValueUnwrapped(nextValue);
|
|
648
|
+
});
|
|
649
|
+
const handleScrollArrowVisibility = useStableCallback((scroller) => {
|
|
650
|
+
const maxScrollTop = getMaxScrollOffset(scroller.scrollHeight, scroller.clientHeight);
|
|
651
|
+
const scrollTop = normalizeScrollOffset(scroller.scrollTop, maxScrollTop);
|
|
652
|
+
const shouldShowUp = scrollTop > 0;
|
|
653
|
+
const shouldShowDown = scrollTop < maxScrollTop;
|
|
654
|
+
store.set("scrollUpArrowVisible", shouldShowUp);
|
|
655
|
+
store.set("scrollDownArrowVisible", shouldShowDown);
|
|
656
|
+
});
|
|
657
|
+
const floatingContext = useFloatingRootContext({
|
|
658
|
+
open,
|
|
659
|
+
onOpenChange: setOpen,
|
|
660
|
+
elements: {
|
|
661
|
+
reference: triggerElement,
|
|
662
|
+
floating: positionerElement
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
const click = useClick(floatingContext, {
|
|
666
|
+
enabled: !disabled,
|
|
667
|
+
event: "mousedown"
|
|
668
|
+
});
|
|
669
|
+
const dismiss = useDismiss(floatingContext);
|
|
670
|
+
const listNavigation = useListNavigation(floatingContext, {
|
|
671
|
+
enabled: !disabled,
|
|
672
|
+
listRef,
|
|
673
|
+
activeIndex,
|
|
674
|
+
selectedIndex,
|
|
675
|
+
disabledIndices: EMPTY_ARRAY,
|
|
676
|
+
onNavigate(nextActiveIndex) {
|
|
677
|
+
if (nextActiveIndex === null && !open) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
store.set("activeIndex", nextActiveIndex);
|
|
681
|
+
},
|
|
682
|
+
focusItemOnHover: highlightItemOnHover
|
|
683
|
+
});
|
|
684
|
+
const typeahead = useTypeahead(floatingContext, {
|
|
685
|
+
// Typeahead on an open popup only moves the highlight, so it remains available while
|
|
686
|
+
// `readOnly`. The closed-trigger variant commits a value instead, so it doesn't.
|
|
687
|
+
enabled: !disabled && (open || !readOnly && !multiple),
|
|
688
|
+
listRef: labelsRef,
|
|
689
|
+
activeIndex,
|
|
690
|
+
selectedIndex,
|
|
691
|
+
// Skip disabled items while matching so typeahead advances to the next selectable item
|
|
692
|
+
// (a click can never select a disabled item and native `<select>` skips them too). Resolve
|
|
693
|
+
// the disabled state from the element via the attribute-only `isElementDisabled` so the
|
|
694
|
+
// hidden, force-mounted items used for closed-trigger typeahead aren't dropped by the
|
|
695
|
+
// `elementsRef`/visibility filter that `disabledIndices` deliberately sidesteps.
|
|
696
|
+
disabledIndices: (index) => isElementDisabled(listRef.current[index]),
|
|
697
|
+
onMatch(index) {
|
|
698
|
+
if (open) {
|
|
699
|
+
store.set("activeIndex", index);
|
|
700
|
+
} else {
|
|
701
|
+
setValue(valuesRef.current[index], createChangeEventDetails(none));
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
onTyping(typing) {
|
|
705
|
+
typingRef.current = typing;
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
const mergedTriggerProps = React.useMemo(() => mergeProps(typeahead.reference, listNavigation.reference, dismiss.reference, click.reference, interactionTypeProps), [click.reference, typeahead.reference, listNavigation.reference, dismiss.reference, interactionTypeProps]);
|
|
709
|
+
const popupProps = React.useMemo(() => mergeProps(FOCUSABLE_POPUP_PROPS, typeahead.floating, listNavigation.floating, dismiss.floating), [typeahead.floating, listNavigation.floating, dismiss.floating]);
|
|
710
|
+
const itemProps = listNavigation.item ?? EMPTY_OBJECT;
|
|
711
|
+
const itemRoot = React.useMemo(() => ({
|
|
712
|
+
props: itemProps,
|
|
713
|
+
multiple,
|
|
714
|
+
disabled,
|
|
715
|
+
readOnly,
|
|
716
|
+
isItemEqualToValue
|
|
717
|
+
}), [itemProps, multiple, disabled, readOnly, isItemEqualToValue]);
|
|
718
|
+
store.useContextCallback("setValue", setValue);
|
|
719
|
+
store.useContextCallback("setOpen", setOpen);
|
|
720
|
+
store.useContextCallback("handleScrollArrowVisibility", handleScrollArrowVisibility);
|
|
721
|
+
store.useContextCallback("onOpenChangeComplete", onOpenChangeComplete);
|
|
722
|
+
useOnFirstRender(() => {
|
|
723
|
+
store.update({
|
|
724
|
+
popupProps,
|
|
725
|
+
triggerProps: mergedTriggerProps,
|
|
726
|
+
itemRoot
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
store.useSyncedValues({
|
|
730
|
+
id: generatedId,
|
|
731
|
+
modal,
|
|
732
|
+
multiple,
|
|
733
|
+
disabled,
|
|
734
|
+
readOnly,
|
|
735
|
+
required,
|
|
736
|
+
highlightItemOnHover,
|
|
737
|
+
value,
|
|
738
|
+
open,
|
|
739
|
+
mounted,
|
|
740
|
+
transitionStatus,
|
|
741
|
+
popupProps,
|
|
742
|
+
triggerProps: mergedTriggerProps,
|
|
743
|
+
itemRoot,
|
|
744
|
+
items,
|
|
745
|
+
itemToStringLabel,
|
|
746
|
+
itemToStringValue,
|
|
747
|
+
isItemEqualToValue,
|
|
748
|
+
openMethod: renderedOpenMethod
|
|
749
|
+
});
|
|
750
|
+
const ref = useMergedRefs(inputRef, validation.inputRef);
|
|
751
|
+
const hiddenInputName = multiple ? void 0 : name;
|
|
752
|
+
const hiddenInputs = React.useMemo(() => {
|
|
753
|
+
if (!multiple || !Array.isArray(value) || !name) {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
return value.map((v) => {
|
|
757
|
+
const currentSerializedValue = stringifyAsValue(v, itemToStringValue);
|
|
758
|
+
return /* @__PURE__ */ jsx("input", {
|
|
759
|
+
type: "hidden",
|
|
760
|
+
form,
|
|
761
|
+
name,
|
|
762
|
+
value: currentSerializedValue,
|
|
763
|
+
disabled
|
|
764
|
+
}, currentSerializedValue);
|
|
765
|
+
});
|
|
766
|
+
}, [multiple, value, form, name, itemToStringValue, disabled]);
|
|
767
|
+
return /* @__PURE__ */ jsxs(SelectRootContext.Provider, {
|
|
768
|
+
value: store,
|
|
769
|
+
children: [/* @__PURE__ */ jsx(SelectFloatingContext.Provider, {
|
|
770
|
+
value: floatingContext,
|
|
771
|
+
children
|
|
772
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
773
|
+
...validation.getValidationProps(disabled, {
|
|
774
|
+
onFocus() {
|
|
775
|
+
var _a;
|
|
776
|
+
(_a = store.state.triggerElement) == null ? void 0 : _a.focus({
|
|
777
|
+
// Supported in Chrome from 144 (January 2026)
|
|
778
|
+
focusVisible: true
|
|
779
|
+
});
|
|
780
|
+
},
|
|
781
|
+
// Handle browser autofill.
|
|
782
|
+
onChange(event) {
|
|
783
|
+
if (event.nativeEvent.defaultPrevented || disabled || readOnly) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
const nextValue = event.currentTarget.value;
|
|
787
|
+
const details = createChangeEventDetails(none, event.nativeEvent);
|
|
788
|
+
function handleChange() {
|
|
789
|
+
if (multiple) {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const nextValueLower = nextValue.toLowerCase();
|
|
793
|
+
let matchingIndex = valuesRef.current.findIndex((candidate) => stringifyAsValue(candidate, itemToStringValue).toLowerCase() === nextValueLower || stringifyAsLabel(candidate, itemToStringLabel).toLowerCase() === nextValueLower);
|
|
794
|
+
if (matchingIndex === -1) {
|
|
795
|
+
matchingIndex = valuesRef.current.findIndex((_, index) => {
|
|
796
|
+
const renderedLabel = labelsRef.current[index];
|
|
797
|
+
return renderedLabel != null && renderedLabel.toLowerCase() === nextValueLower;
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
const matchingValue = valuesRef.current[matchingIndex];
|
|
801
|
+
if (matchingValue != null) {
|
|
802
|
+
setValue(matchingValue, details);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
store.set("forceMount", true);
|
|
806
|
+
queueMicrotask(handleChange);
|
|
807
|
+
}
|
|
808
|
+
}),
|
|
809
|
+
id: generatedId && hiddenInputName == null ? `${generatedId}-hidden-input` : void 0,
|
|
810
|
+
form,
|
|
811
|
+
name: hiddenInputName,
|
|
812
|
+
autoComplete,
|
|
813
|
+
value: serializedValue,
|
|
814
|
+
disabled,
|
|
815
|
+
required: required && !(multiple && hasSelectedValue),
|
|
816
|
+
readOnly,
|
|
817
|
+
ref,
|
|
818
|
+
style: name ? visuallyHiddenInput : visuallyHidden,
|
|
819
|
+
tabIndex: -1,
|
|
820
|
+
"aria-hidden": true,
|
|
821
|
+
suppressHydrationWarning: true
|
|
822
|
+
}), hiddenInputs]
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
const popupSide = "data-popup-side";
|
|
826
|
+
const SELECTED_DELAY = 400;
|
|
827
|
+
const stateAttributesMapping$2 = {
|
|
828
|
+
...pressableTriggerOpenStateMapping,
|
|
829
|
+
...fieldValidityMapping,
|
|
830
|
+
popupSide: (side) => side ? {
|
|
831
|
+
[popupSide]: side
|
|
832
|
+
} : null,
|
|
833
|
+
value: () => null
|
|
834
|
+
};
|
|
835
|
+
const SelectTrigger$1 = /* @__PURE__ */ React.forwardRef(function SelectTrigger(componentProps, forwardedRef) {
|
|
836
|
+
var _a;
|
|
837
|
+
const {
|
|
838
|
+
render,
|
|
839
|
+
className,
|
|
840
|
+
id: idProp,
|
|
841
|
+
disabled: disabledProp = false,
|
|
842
|
+
nativeButton = true,
|
|
843
|
+
style,
|
|
844
|
+
...elementProps
|
|
845
|
+
} = componentProps;
|
|
846
|
+
const {
|
|
847
|
+
setTouched,
|
|
848
|
+
validationMode,
|
|
849
|
+
validation,
|
|
850
|
+
state: fieldState,
|
|
851
|
+
disabled: fieldDisabled
|
|
852
|
+
} = useFieldRootContext();
|
|
853
|
+
const {
|
|
854
|
+
labelId: fieldLabelId
|
|
855
|
+
} = useLabelableContext();
|
|
856
|
+
const store = useSelectRootContext();
|
|
857
|
+
const readOnly = store.useState("readOnly");
|
|
858
|
+
const required = store.useState("required");
|
|
859
|
+
const selectDisabled = store.useState("disabled");
|
|
860
|
+
const disabled = fieldDisabled || selectDisabled || disabledProp;
|
|
861
|
+
const open = store.useState("open");
|
|
862
|
+
const mounted = store.useState("mounted");
|
|
863
|
+
const value = store.useState("value");
|
|
864
|
+
const triggerProps = store.useState("triggerProps");
|
|
865
|
+
const positionerElement = store.useState("positionerElement");
|
|
866
|
+
const listElement = store.useState("listElement");
|
|
867
|
+
const popupSideValue = store.useState("popupSide");
|
|
868
|
+
const rootId = store.useState("id");
|
|
869
|
+
const selectLabelId = store.useState("labelId");
|
|
870
|
+
const hasSelectedValue = store.useState("hasSelectedValue");
|
|
871
|
+
const popupSide2 = mounted && positionerElement ? popupSideValue : null;
|
|
872
|
+
const id = idProp ?? rootId;
|
|
873
|
+
const ariaLabelledBy = resolveAriaLabelledBy(fieldLabelId, selectLabelId);
|
|
874
|
+
useLabelableId({
|
|
875
|
+
id: idProp
|
|
876
|
+
});
|
|
877
|
+
const positionerRef = useValueAsRef(positionerElement);
|
|
878
|
+
const triggerRef = React.useRef(null);
|
|
879
|
+
const setFocused = useSetFieldFocused(disabled, triggerRef);
|
|
880
|
+
const {
|
|
881
|
+
getButtonProps,
|
|
882
|
+
buttonRef
|
|
883
|
+
} = useButton({
|
|
884
|
+
disabled,
|
|
885
|
+
native: nativeButton
|
|
886
|
+
});
|
|
887
|
+
const setTriggerElement = store.useStateSetter("triggerElement");
|
|
888
|
+
const timeoutFocus = useTimeout();
|
|
889
|
+
const timeoutMouseDown = useTimeout();
|
|
890
|
+
const selectedDelayTimeout = useTimeout();
|
|
891
|
+
React.useEffect(() => {
|
|
892
|
+
if (open) {
|
|
893
|
+
selectedDelayTimeout.start(SELECTED_DELAY, () => {
|
|
894
|
+
store.context.selectionRef.current.allowUnselectedMouseUp = true;
|
|
895
|
+
store.context.selectionRef.current.allowSelectedMouseUp = true;
|
|
896
|
+
});
|
|
897
|
+
return () => {
|
|
898
|
+
selectedDelayTimeout.clear();
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
store.context.selectionRef.current = {
|
|
902
|
+
allowSelectedMouseUp: false,
|
|
903
|
+
allowUnselectedMouseUp: false,
|
|
904
|
+
dragY: 0
|
|
905
|
+
};
|
|
906
|
+
timeoutMouseDown.clear();
|
|
907
|
+
return void 0;
|
|
908
|
+
}, [open, store, timeoutMouseDown, selectedDelayTimeout]);
|
|
909
|
+
const mergedProps = mergeProps(triggerProps, {
|
|
910
|
+
id,
|
|
911
|
+
role: "combobox",
|
|
912
|
+
"aria-expanded": open,
|
|
913
|
+
"aria-haspopup": "listbox",
|
|
914
|
+
"aria-controls": open ? (listElement == null ? void 0 : listElement.id) ?? ((_a = getFloatingFocusElement(positionerElement)) == null ? void 0 : _a.id) : void 0,
|
|
915
|
+
"aria-labelledby": ariaLabelledBy,
|
|
916
|
+
"aria-readonly": readOnly || void 0,
|
|
917
|
+
"aria-required": required || void 0,
|
|
918
|
+
tabIndex: disabled ? -1 : 0,
|
|
919
|
+
onFocus(event) {
|
|
920
|
+
setFocused(true);
|
|
921
|
+
if (open && store.context.alignItemWithTriggerActiveRef.current) {
|
|
922
|
+
store.context.setOpen(false, createChangeEventDetails(none, event.nativeEvent));
|
|
923
|
+
}
|
|
924
|
+
timeoutFocus.start(0, () => {
|
|
925
|
+
store.set("forceMount", true);
|
|
926
|
+
});
|
|
927
|
+
},
|
|
928
|
+
onBlur(event) {
|
|
929
|
+
if (contains(positionerElement, event.relatedTarget)) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
setTouched(true);
|
|
933
|
+
setFocused(false);
|
|
934
|
+
if (validationMode === "onBlur") {
|
|
935
|
+
validation.commit(value);
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
onMouseDown(event) {
|
|
939
|
+
if (open) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
const doc = ownerDocument(event.currentTarget);
|
|
943
|
+
function handleMouseUp(mouseEvent) {
|
|
944
|
+
if (!triggerRef.current) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const mouseUpTarget = mouseEvent.target;
|
|
948
|
+
if (contains(triggerRef.current, mouseUpTarget) || contains(positionerRef.current, mouseUpTarget)) {
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
if (isMouseWithinBounds(mouseEvent, triggerRef.current)) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
store.context.setOpen(false, createChangeEventDetails(cancelOpen, mouseEvent));
|
|
955
|
+
}
|
|
956
|
+
timeoutMouseDown.start(0, () => {
|
|
957
|
+
doc.addEventListener("mouseup", handleMouseUp, {
|
|
958
|
+
once: true
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
}, elementProps, getButtonProps);
|
|
963
|
+
const props = validation.getValidationProps(disabled, mergedProps);
|
|
964
|
+
props.role = "combobox";
|
|
965
|
+
const state = {
|
|
966
|
+
...fieldState,
|
|
967
|
+
open,
|
|
968
|
+
disabled,
|
|
969
|
+
value,
|
|
970
|
+
readOnly,
|
|
971
|
+
popupSide: popupSide2,
|
|
972
|
+
placeholder: !hasSelectedValue
|
|
973
|
+
};
|
|
974
|
+
return useRenderElement("button", componentProps, {
|
|
975
|
+
ref: [forwardedRef, triggerRef, buttonRef, setTriggerElement],
|
|
976
|
+
state,
|
|
977
|
+
stateAttributesMapping: stateAttributesMapping$2,
|
|
978
|
+
props
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
if (process.env.NODE_ENV !== "production") SelectTrigger$1.displayName = "SelectTrigger";
|
|
982
|
+
const stateAttributesMapping$1 = {
|
|
983
|
+
value: () => null
|
|
984
|
+
};
|
|
985
|
+
const SelectValue$1 = /* @__PURE__ */ React.forwardRef(function SelectValue(componentProps, forwardedRef) {
|
|
986
|
+
const {
|
|
987
|
+
className,
|
|
988
|
+
render,
|
|
989
|
+
children: childrenProp,
|
|
990
|
+
placeholder,
|
|
991
|
+
style,
|
|
992
|
+
...elementProps
|
|
993
|
+
} = componentProps;
|
|
994
|
+
const store = useSelectRootContext();
|
|
995
|
+
const value = store.useState("value");
|
|
996
|
+
const items = store.useState("items");
|
|
997
|
+
const itemToStringLabel = store.useState("itemToStringLabel");
|
|
998
|
+
const hasSelectedValue = store.useState("hasSelectedValue");
|
|
999
|
+
const shouldCheckNullItemLabel = !hasSelectedValue && placeholder != null && childrenProp == null;
|
|
1000
|
+
const hasNullLabel = store.useState("hasNullItemLabel", shouldCheckNullItemLabel);
|
|
1001
|
+
const state = {
|
|
1002
|
+
value,
|
|
1003
|
+
placeholder: !hasSelectedValue
|
|
1004
|
+
};
|
|
1005
|
+
let children = null;
|
|
1006
|
+
if (typeof childrenProp === "function") {
|
|
1007
|
+
children = childrenProp(value);
|
|
1008
|
+
} else if (childrenProp != null) {
|
|
1009
|
+
children = childrenProp;
|
|
1010
|
+
} else if (shouldCheckNullItemLabel && !hasNullLabel) {
|
|
1011
|
+
children = placeholder;
|
|
1012
|
+
} else if (Array.isArray(value)) {
|
|
1013
|
+
children = resolveMultipleLabels(value, items, itemToStringLabel);
|
|
1014
|
+
} else {
|
|
1015
|
+
children = resolveSelectedLabel(value, items, itemToStringLabel);
|
|
1016
|
+
}
|
|
1017
|
+
const element = useRenderElement("span", componentProps, {
|
|
1018
|
+
state,
|
|
1019
|
+
ref: [forwardedRef, store.context.valueRef],
|
|
1020
|
+
props: [{
|
|
1021
|
+
children
|
|
1022
|
+
}, elementProps],
|
|
1023
|
+
stateAttributesMapping: stateAttributesMapping$1
|
|
1024
|
+
});
|
|
1025
|
+
return element;
|
|
1026
|
+
});
|
|
1027
|
+
if (process.env.NODE_ENV !== "production") SelectValue$1.displayName = "SelectValue";
|
|
1028
|
+
const SelectPortal = /* @__PURE__ */ React.forwardRef(function SelectPortal2(portalProps, forwardedRef) {
|
|
1029
|
+
const store = useSelectRootContext();
|
|
1030
|
+
const mounted = store.useState("mounted");
|
|
1031
|
+
const forceMount = store.useState("forceMount");
|
|
1032
|
+
const shouldRender = mounted || forceMount;
|
|
1033
|
+
if (!shouldRender) {
|
|
1034
|
+
return null;
|
|
1035
|
+
}
|
|
1036
|
+
return /* @__PURE__ */ jsx(FloatingPortal, {
|
|
1037
|
+
ref: forwardedRef,
|
|
1038
|
+
...portalProps
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
if (process.env.NODE_ENV !== "production") SelectPortal.displayName = "SelectPortal";
|
|
1042
|
+
const SelectPositionerContext = /* @__PURE__ */ React.createContext(void 0);
|
|
1043
|
+
if (process.env.NODE_ENV !== "production") SelectPositionerContext.displayName = "SelectPositionerContext";
|
|
1044
|
+
function useSelectPositionerContext() {
|
|
1045
|
+
const context = React.useContext(SelectPositionerContext);
|
|
1046
|
+
if (!context) {
|
|
1047
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SelectPositionerContext is missing. SelectPositioner parts must be placed within <Select.Positioner>." : formatErrorMessage(59));
|
|
1048
|
+
}
|
|
1049
|
+
return context;
|
|
1050
|
+
}
|
|
1051
|
+
function clearStyles(element, originalStyles) {
|
|
1052
|
+
if (element) {
|
|
1053
|
+
Object.assign(element.style, originalStyles);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
const LIST_FUNCTIONAL_STYLES = {
|
|
1057
|
+
position: "relative",
|
|
1058
|
+
maxHeight: "100%",
|
|
1059
|
+
overflowX: "hidden",
|
|
1060
|
+
overflowY: "auto"
|
|
1061
|
+
};
|
|
1062
|
+
const FIXED = {
|
|
1063
|
+
position: "fixed"
|
|
1064
|
+
};
|
|
1065
|
+
const SelectPositioner = /* @__PURE__ */ React.forwardRef(function SelectPositioner2(componentProps, forwardedRef) {
|
|
1066
|
+
const {
|
|
1067
|
+
anchor,
|
|
1068
|
+
className,
|
|
1069
|
+
render,
|
|
1070
|
+
// `useAnchorPositioning` applies the same defaults to the undefined values; the names
|
|
1071
|
+
// remain destructured to exclude the props from `elementProps`.
|
|
1072
|
+
positionMethod,
|
|
1073
|
+
side,
|
|
1074
|
+
align,
|
|
1075
|
+
sideOffset,
|
|
1076
|
+
alignOffset,
|
|
1077
|
+
collisionBoundary = "clipping-ancestors",
|
|
1078
|
+
collisionPadding,
|
|
1079
|
+
arrowPadding,
|
|
1080
|
+
sticky,
|
|
1081
|
+
disableAnchorTracking,
|
|
1082
|
+
alignItemWithTrigger = true,
|
|
1083
|
+
collisionAvoidance = DROPDOWN_COLLISION_AVOIDANCE,
|
|
1084
|
+
style,
|
|
1085
|
+
...elementProps
|
|
1086
|
+
} = componentProps;
|
|
1087
|
+
const store = useSelectRootContext();
|
|
1088
|
+
const floatingRootContext = useSelectFloatingContext();
|
|
1089
|
+
const open = store.useState("open");
|
|
1090
|
+
const mounted = store.useState("mounted");
|
|
1091
|
+
const modal = store.useState("modal");
|
|
1092
|
+
const value = store.useState("value");
|
|
1093
|
+
const openMethod = store.useState("openMethod");
|
|
1094
|
+
const positionerElement = store.useState("positionerElement");
|
|
1095
|
+
const triggerElement = store.useState("triggerElement");
|
|
1096
|
+
const isItemEqualToValue = store.useState("isItemEqualToValue");
|
|
1097
|
+
const transitionStatus = store.useState("transitionStatus");
|
|
1098
|
+
const scrollUpArrowRef = React.useRef(null);
|
|
1099
|
+
const scrollDownArrowRef = React.useRef(null);
|
|
1100
|
+
const [controlledAlignItemWithTrigger, setControlledAlignItemWithTrigger] = React.useState(alignItemWithTrigger);
|
|
1101
|
+
const alignItemWithTriggerActive = mounted && controlledAlignItemWithTrigger && openMethod !== "touch";
|
|
1102
|
+
if (!mounted && controlledAlignItemWithTrigger !== alignItemWithTrigger) {
|
|
1103
|
+
setControlledAlignItemWithTrigger(alignItemWithTrigger);
|
|
1104
|
+
}
|
|
1105
|
+
React.useImperativeHandle(store.context.alignItemWithTriggerActiveRef, () => alignItemWithTriggerActive);
|
|
1106
|
+
useAnchoredPopupScrollLock((alignItemWithTriggerActive || modal) && open, openMethod === "touch", positionerElement, triggerElement);
|
|
1107
|
+
const positioning = useAnchorPositioning({
|
|
1108
|
+
anchor,
|
|
1109
|
+
floatingRootContext,
|
|
1110
|
+
positionMethod,
|
|
1111
|
+
mounted,
|
|
1112
|
+
side,
|
|
1113
|
+
sideOffset,
|
|
1114
|
+
align,
|
|
1115
|
+
alignOffset,
|
|
1116
|
+
arrowPadding,
|
|
1117
|
+
collisionBoundary,
|
|
1118
|
+
collisionPadding,
|
|
1119
|
+
sticky,
|
|
1120
|
+
disableAnchorTracking: disableAnchorTracking ?? alignItemWithTriggerActive,
|
|
1121
|
+
collisionAvoidance,
|
|
1122
|
+
keepMounted: true
|
|
1123
|
+
});
|
|
1124
|
+
const renderedSide = alignItemWithTriggerActive ? "none" : positioning.side;
|
|
1125
|
+
const positionerStyles = alignItemWithTriggerActive ? FIXED : positioning.positionerStyles;
|
|
1126
|
+
const state = {
|
|
1127
|
+
open,
|
|
1128
|
+
side: renderedSide,
|
|
1129
|
+
align: positioning.align,
|
|
1130
|
+
anchorHidden: positioning.anchorHidden
|
|
1131
|
+
};
|
|
1132
|
+
useIsoLayoutEffect(() => {
|
|
1133
|
+
store.set("popupSide", positioning.side);
|
|
1134
|
+
}, [store, positioning.side]);
|
|
1135
|
+
const setPositionerElement = store.useStateSetter("positionerElement");
|
|
1136
|
+
const element = usePositioner(componentProps, state, {
|
|
1137
|
+
styles: positionerStyles,
|
|
1138
|
+
transitionStatus,
|
|
1139
|
+
props: elementProps,
|
|
1140
|
+
refs: [forwardedRef, setPositionerElement],
|
|
1141
|
+
hidden: !mounted,
|
|
1142
|
+
inert: !open
|
|
1143
|
+
});
|
|
1144
|
+
const prevMapSizeRef = React.useRef(0);
|
|
1145
|
+
const onMapChange = useStableCallback((map) => {
|
|
1146
|
+
if (store.context.valuesRef.current.length === 0) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
const prevSize = prevMapSizeRef.current;
|
|
1150
|
+
prevMapSizeRef.current = map.size;
|
|
1151
|
+
const eventDetails = createChangeEventDetails(none);
|
|
1152
|
+
if (prevSize !== 0 && !store.state.multiple && value !== null) {
|
|
1153
|
+
const selectedValueIndex = findItemIndex(store.context.valuesRef.current, value, isItemEqualToValue);
|
|
1154
|
+
if (selectedValueIndex === -1) {
|
|
1155
|
+
const initialSelectedValue = store.context.initialValueRef.current;
|
|
1156
|
+
const hasInitial = initialSelectedValue != null && findItemIndex(store.context.valuesRef.current, initialSelectedValue, isItemEqualToValue) !== -1;
|
|
1157
|
+
const nextValue = hasInitial ? initialSelectedValue : null;
|
|
1158
|
+
store.context.setValue(nextValue, eventDetails);
|
|
1159
|
+
if (nextValue === null) {
|
|
1160
|
+
store.set("selectedIndex", null);
|
|
1161
|
+
store.context.selectedItemTextRef.current = null;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
if (prevSize !== 0 && store.state.multiple && Array.isArray(value)) {
|
|
1166
|
+
const nextValue = value.filter((selectedItemValue) => findItemIndex(store.context.valuesRef.current, selectedItemValue, isItemEqualToValue) !== -1);
|
|
1167
|
+
if (nextValue.length !== value.length) {
|
|
1168
|
+
store.context.setValue(nextValue, eventDetails);
|
|
1169
|
+
if (nextValue.length === 0) {
|
|
1170
|
+
store.set("selectedIndex", null);
|
|
1171
|
+
store.context.selectedItemTextRef.current = null;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
if (open && alignItemWithTriggerActive) {
|
|
1176
|
+
store.update({
|
|
1177
|
+
scrollUpArrowVisible: false,
|
|
1178
|
+
scrollDownArrowVisible: false
|
|
1179
|
+
});
|
|
1180
|
+
const stylesToClear = {
|
|
1181
|
+
height: ""
|
|
1182
|
+
};
|
|
1183
|
+
clearStyles(positionerElement, stylesToClear);
|
|
1184
|
+
clearStyles(store.context.popupRef.current, stylesToClear);
|
|
1185
|
+
}
|
|
1186
|
+
});
|
|
1187
|
+
const contextValue = React.useMemo(() => ({
|
|
1188
|
+
...positioning,
|
|
1189
|
+
side: renderedSide,
|
|
1190
|
+
alignItemWithTriggerActive,
|
|
1191
|
+
setControlledAlignItemWithTrigger,
|
|
1192
|
+
scrollUpArrowRef,
|
|
1193
|
+
scrollDownArrowRef
|
|
1194
|
+
}), [positioning, renderedSide, alignItemWithTriggerActive, setControlledAlignItemWithTrigger]);
|
|
1195
|
+
return /* @__PURE__ */ jsx(CompositeList, {
|
|
1196
|
+
elementsRef: store.context.listRef,
|
|
1197
|
+
labelsRef: store.context.labelsRef,
|
|
1198
|
+
onMapChange,
|
|
1199
|
+
children: /* @__PURE__ */ jsxs(SelectPositionerContext.Provider, {
|
|
1200
|
+
value: contextValue,
|
|
1201
|
+
children: [mounted && modal && /* @__PURE__ */ jsx(InternalBackdrop, {
|
|
1202
|
+
inert: inertValue(!open),
|
|
1203
|
+
cutout: triggerElement
|
|
1204
|
+
}), element]
|
|
1205
|
+
})
|
|
1206
|
+
});
|
|
1207
|
+
});
|
|
1208
|
+
if (process.env.NODE_ENV !== "production") SelectPositioner.displayName = "SelectPositioner";
|
|
1209
|
+
const DISABLE_SCROLLBAR_CLASS_NAME = "base-ui-disable-scrollbar";
|
|
1210
|
+
const styleDisableScrollbar = {
|
|
1211
|
+
className: DISABLE_SCROLLBAR_CLASS_NAME,
|
|
1212
|
+
getElement(nonce) {
|
|
1213
|
+
return /* @__PURE__ */ jsx("style", {
|
|
1214
|
+
nonce,
|
|
1215
|
+
href: DISABLE_SCROLLBAR_CLASS_NAME,
|
|
1216
|
+
precedence: "base-ui:low",
|
|
1217
|
+
children: `.${DISABLE_SCROLLBAR_CLASS_NAME}{scrollbar-width:none}.${DISABLE_SCROLLBAR_CLASS_NAME}::-webkit-scrollbar{display:none}`
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
if (process.env.NODE_ENV !== "production") styleDisableScrollbar.getElement.displayName = "styleDisableScrollbar.getElement";
|
|
1222
|
+
const transformOrigin = "--transform-origin";
|
|
1223
|
+
const stateAttributesMapping = {
|
|
1224
|
+
...popupStateMapping,
|
|
1225
|
+
...transitionStatusMapping
|
|
1226
|
+
};
|
|
1227
|
+
const SelectPopup = /* @__PURE__ */ React.forwardRef(function SelectPopup2(componentProps, forwardedRef) {
|
|
1228
|
+
const {
|
|
1229
|
+
render,
|
|
1230
|
+
className,
|
|
1231
|
+
style,
|
|
1232
|
+
finalFocus,
|
|
1233
|
+
...elementProps
|
|
1234
|
+
} = componentProps;
|
|
1235
|
+
const store = useSelectRootContext();
|
|
1236
|
+
const multiple = store.useState("multiple");
|
|
1237
|
+
const readOnly = store.useState("readOnly");
|
|
1238
|
+
const highlightItemOnHover = store.useState("highlightItemOnHover");
|
|
1239
|
+
const floatingRootContext = useSelectFloatingContext();
|
|
1240
|
+
const {
|
|
1241
|
+
side,
|
|
1242
|
+
align,
|
|
1243
|
+
alignItemWithTriggerActive,
|
|
1244
|
+
isPositioned,
|
|
1245
|
+
setControlledAlignItemWithTrigger
|
|
1246
|
+
} = useSelectPositionerContext();
|
|
1247
|
+
const insideToolbar = useToolbarRootContext() != null;
|
|
1248
|
+
const direction = useDirection();
|
|
1249
|
+
const {
|
|
1250
|
+
nonce,
|
|
1251
|
+
disableStyleElements
|
|
1252
|
+
} = useCSPContext();
|
|
1253
|
+
const id = store.useState("id");
|
|
1254
|
+
const open = store.useState("open");
|
|
1255
|
+
const openMethod = store.useState("openMethod");
|
|
1256
|
+
const mounted = store.useState("mounted");
|
|
1257
|
+
const popupProps = store.useState("popupProps");
|
|
1258
|
+
const transitionStatus = store.useState("transitionStatus");
|
|
1259
|
+
const triggerElement = store.useState("triggerElement");
|
|
1260
|
+
const positionerElement = store.useState("positionerElement");
|
|
1261
|
+
const listElement = store.useState("listElement");
|
|
1262
|
+
const reachedMaxHeightRef = React.useRef(false);
|
|
1263
|
+
const initialPlacedRef = React.useRef(false);
|
|
1264
|
+
const originalPositionerStylesRef = React.useRef({});
|
|
1265
|
+
const scrollArrowFrame = useAnimationFrame();
|
|
1266
|
+
const handleScroll = useStableCallback((scroller) => {
|
|
1267
|
+
if (!positionerElement || !store.context.popupRef.current || !initialPlacedRef.current) {
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
const isTopPositioned = positionerElement.style.top === "0px";
|
|
1271
|
+
const isBottomPositioned = positionerElement.style.bottom === "0px";
|
|
1272
|
+
if (reachedMaxHeightRef.current || !alignItemWithTriggerActive || !isTopPositioned && !isBottomPositioned) {
|
|
1273
|
+
store.context.handleScrollArrowVisibility(scroller);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
const scale = getScale(positionerElement);
|
|
1277
|
+
const currentHeight = normalizeSize(positionerElement.getBoundingClientRect().height, "y", scale);
|
|
1278
|
+
const doc = ownerDocument(positionerElement);
|
|
1279
|
+
const win = getWindow(positionerElement);
|
|
1280
|
+
const positionerStyles = win.getComputedStyle(positionerElement);
|
|
1281
|
+
const marginTop = parseFloat(positionerStyles.marginTop);
|
|
1282
|
+
const marginBottom = parseFloat(positionerStyles.marginBottom);
|
|
1283
|
+
const maxPopupHeight = getMaxPopupHeight(win.getComputedStyle(store.context.popupRef.current));
|
|
1284
|
+
const maxAvailableHeight = Math.min(doc.documentElement.clientHeight - marginTop - marginBottom, maxPopupHeight);
|
|
1285
|
+
const scrollTop = scroller.scrollTop;
|
|
1286
|
+
const maxScrollTop = getMaxScrollTop(scroller);
|
|
1287
|
+
let nextScrollTop = null;
|
|
1288
|
+
const setHeight = (height) => {
|
|
1289
|
+
positionerElement.style.height = `${height}px`;
|
|
1290
|
+
};
|
|
1291
|
+
const diff = isTopPositioned ? maxScrollTop - scrollTop : scrollTop;
|
|
1292
|
+
const nextHeight = Math.min(currentHeight + diff, maxAvailableHeight);
|
|
1293
|
+
if (diff <= SCROLL_EDGE_TOLERANCE_PX) {
|
|
1294
|
+
const heightDelta = clamp(diff, 0, maxAvailableHeight - currentHeight);
|
|
1295
|
+
if (heightDelta > 0) {
|
|
1296
|
+
setHeight(currentHeight + heightDelta);
|
|
1297
|
+
}
|
|
1298
|
+
scroller.scrollTop = isTopPositioned ? maxScrollTop : 0;
|
|
1299
|
+
if (maxAvailableHeight - (currentHeight + heightDelta) <= SCROLL_EDGE_TOLERANCE_PX) {
|
|
1300
|
+
reachedMaxHeightRef.current = true;
|
|
1301
|
+
}
|
|
1302
|
+
store.context.handleScrollArrowVisibility(scroller);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
if (maxAvailableHeight - nextHeight > SCROLL_EDGE_TOLERANCE_PX) {
|
|
1306
|
+
nextScrollTop = isTopPositioned ? Infinity : 0;
|
|
1307
|
+
} else if (isBottomPositioned && scrollTop < maxScrollTop) {
|
|
1308
|
+
const overshoot = currentHeight + diff - maxAvailableHeight;
|
|
1309
|
+
nextScrollTop = scrollTop - (diff - overshoot);
|
|
1310
|
+
}
|
|
1311
|
+
const nextPositionerHeight = Math.ceil(nextHeight);
|
|
1312
|
+
if (nextPositionerHeight !== 0) {
|
|
1313
|
+
setHeight(nextPositionerHeight);
|
|
1314
|
+
}
|
|
1315
|
+
if (nextScrollTop != null) {
|
|
1316
|
+
const target = clamp(nextScrollTop, 0, getMaxScrollTop(scroller));
|
|
1317
|
+
if (Math.abs(scroller.scrollTop - target) > SCROLL_EDGE_TOLERANCE_PX) {
|
|
1318
|
+
scroller.scrollTop = target;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
if (nextPositionerHeight >= maxAvailableHeight - SCROLL_EDGE_TOLERANCE_PX) {
|
|
1322
|
+
reachedMaxHeightRef.current = true;
|
|
1323
|
+
}
|
|
1324
|
+
store.context.handleScrollArrowVisibility(scroller);
|
|
1325
|
+
});
|
|
1326
|
+
React.useImperativeHandle(store.context.scrollHandlerRef, () => handleScroll, [handleScroll]);
|
|
1327
|
+
useOpenChangeComplete({
|
|
1328
|
+
open,
|
|
1329
|
+
ref: store.context.popupRef,
|
|
1330
|
+
onComplete() {
|
|
1331
|
+
if (open) {
|
|
1332
|
+
store.context.onOpenChangeComplete(true);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
const state = {
|
|
1337
|
+
open,
|
|
1338
|
+
transitionStatus,
|
|
1339
|
+
side,
|
|
1340
|
+
align
|
|
1341
|
+
};
|
|
1342
|
+
useIsoLayoutEffect(() => {
|
|
1343
|
+
if (!positionerElement || !store.context.popupRef.current || Object.keys(originalPositionerStylesRef.current).length) {
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
originalPositionerStylesRef.current = {
|
|
1347
|
+
top: positionerElement.style.top || "0",
|
|
1348
|
+
left: positionerElement.style.left || "0",
|
|
1349
|
+
right: positionerElement.style.right,
|
|
1350
|
+
height: positionerElement.style.height,
|
|
1351
|
+
bottom: positionerElement.style.bottom,
|
|
1352
|
+
minHeight: positionerElement.style.minHeight,
|
|
1353
|
+
maxHeight: positionerElement.style.maxHeight,
|
|
1354
|
+
marginTop: positionerElement.style.marginTop,
|
|
1355
|
+
marginBottom: positionerElement.style.marginBottom
|
|
1356
|
+
};
|
|
1357
|
+
}, [store, positionerElement]);
|
|
1358
|
+
useIsoLayoutEffect(() => {
|
|
1359
|
+
if (open || alignItemWithTriggerActive) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
initialPlacedRef.current = false;
|
|
1363
|
+
reachedMaxHeightRef.current = false;
|
|
1364
|
+
clearStyles(positionerElement, originalPositionerStylesRef.current);
|
|
1365
|
+
}, [open, alignItemWithTriggerActive, positionerElement]);
|
|
1366
|
+
useIsoLayoutEffect(() => {
|
|
1367
|
+
var _a, _b;
|
|
1368
|
+
const popupElement = store.context.popupRef.current;
|
|
1369
|
+
if (!open || !triggerElement || !positionerElement || !popupElement || alignItemWithTriggerActive && !isPositioned || store.state.transitionStatus === "ending") {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
initialPlacedRef.current = true;
|
|
1373
|
+
popupElement.style.removeProperty(transformOrigin);
|
|
1374
|
+
if (!alignItemWithTriggerActive) {
|
|
1375
|
+
scrollArrowFrame.request(() => store.context.handleScrollArrowVisibility(listElement || popupElement));
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
const restoreTransformStyles = unsetTransformStyles(popupElement);
|
|
1379
|
+
try {
|
|
1380
|
+
let textElement = store.context.selectedItemTextRef.current;
|
|
1381
|
+
if (!(textElement == null ? void 0 : textElement.isConnected)) {
|
|
1382
|
+
const hasSelectedValue = store.select("hasSelectedValue");
|
|
1383
|
+
textElement = !hasSelectedValue && ((_a = store.context.firstItemTextRef.current) == null ? void 0 : _a.isConnected) ? store.context.firstItemTextRef.current : null;
|
|
1384
|
+
}
|
|
1385
|
+
const valueElement = store.context.valueRef.current;
|
|
1386
|
+
const win = getWindow(positionerElement);
|
|
1387
|
+
const positionerStyles = win.getComputedStyle(positionerElement);
|
|
1388
|
+
const popupStyles = win.getComputedStyle(popupElement);
|
|
1389
|
+
const doc = ownerDocument(triggerElement);
|
|
1390
|
+
const scale = getScale(triggerElement);
|
|
1391
|
+
const triggerRect = normalizeRect(triggerElement.getBoundingClientRect(), scale);
|
|
1392
|
+
const positionerRect = normalizeRect(positionerElement.getBoundingClientRect(), scale);
|
|
1393
|
+
const triggerHeight = triggerRect.height;
|
|
1394
|
+
const scroller = listElement || popupElement;
|
|
1395
|
+
const scrollHeight = scroller.scrollHeight;
|
|
1396
|
+
const borderBottom = parseFloat(popupStyles.borderBottomWidth);
|
|
1397
|
+
const marginTop = parseFloat(positionerStyles.marginTop) || 10;
|
|
1398
|
+
const marginBottom = parseFloat(positionerStyles.marginBottom) || 10;
|
|
1399
|
+
const minHeight = parseFloat(positionerStyles.minHeight) || 100;
|
|
1400
|
+
const maxPopupHeight = getMaxPopupHeight(popupStyles);
|
|
1401
|
+
const paddingLeft = 5;
|
|
1402
|
+
const paddingRight = 5;
|
|
1403
|
+
const triggerCollisionThreshold = 20;
|
|
1404
|
+
const viewportHeight = doc.documentElement.clientHeight - marginTop - marginBottom;
|
|
1405
|
+
const viewportWidth = doc.documentElement.clientWidth;
|
|
1406
|
+
const availableSpaceBeneathTrigger = viewportHeight - triggerRect.bottom + triggerHeight;
|
|
1407
|
+
let textRect;
|
|
1408
|
+
let alignedLeft = direction === "rtl" ? triggerRect.right - positionerRect.width : triggerRect.left;
|
|
1409
|
+
let offsetY = 0;
|
|
1410
|
+
if (textElement && valueElement) {
|
|
1411
|
+
const valueRect = normalizeRect(valueElement.getBoundingClientRect(), scale);
|
|
1412
|
+
textRect = normalizeRect(textElement.getBoundingClientRect(), scale);
|
|
1413
|
+
alignedLeft = positionerRect.left + (direction === "rtl" ? valueRect.right - textRect.right : valueRect.left - textRect.left);
|
|
1414
|
+
const valueCenterFromTriggerTop = valueRect.top - triggerRect.top + valueRect.height / 2;
|
|
1415
|
+
const textCenterFromPositionerTop = textRect.top - positionerRect.top + textRect.height / 2;
|
|
1416
|
+
offsetY = textCenterFromPositionerTop - valueCenterFromTriggerTop;
|
|
1417
|
+
}
|
|
1418
|
+
const idealHeight = availableSpaceBeneathTrigger + offsetY + marginBottom + borderBottom;
|
|
1419
|
+
let height = Math.min(viewportHeight, idealHeight);
|
|
1420
|
+
const maxHeight = viewportHeight - marginTop - marginBottom;
|
|
1421
|
+
const scrollTop = idealHeight - height;
|
|
1422
|
+
const maxRight = viewportWidth - paddingRight;
|
|
1423
|
+
positionerElement.style.left = `${clamp(alignedLeft, paddingLeft, maxRight - positionerRect.width)}px`;
|
|
1424
|
+
positionerElement.style.height = `${height}px`;
|
|
1425
|
+
positionerElement.style.maxHeight = "none";
|
|
1426
|
+
positionerElement.style.marginTop = `${marginTop}px`;
|
|
1427
|
+
positionerElement.style.marginBottom = `${marginBottom}px`;
|
|
1428
|
+
popupElement.style.height = "100%";
|
|
1429
|
+
const maxScrollTop = getMaxScrollTop(scroller);
|
|
1430
|
+
const isTopPositioned = scrollTop >= maxScrollTop - SCROLL_EDGE_TOLERANCE_PX;
|
|
1431
|
+
if (isTopPositioned) {
|
|
1432
|
+
height = Math.min(viewportHeight, positionerRect.height) - (scrollTop - maxScrollTop);
|
|
1433
|
+
}
|
|
1434
|
+
const fallbackToAlignPopupToTrigger = triggerRect.top < triggerCollisionThreshold || triggerRect.bottom > viewportHeight - triggerCollisionThreshold || Math.ceil(height) + SCROLL_EDGE_TOLERANCE_PX < Math.min(scrollHeight, minHeight);
|
|
1435
|
+
const isPinchZoomed = (((_b = win.visualViewport) == null ? void 0 : _b.scale) ?? 1) !== 1 && webkit;
|
|
1436
|
+
if (fallbackToAlignPopupToTrigger || isPinchZoomed) {
|
|
1437
|
+
clearStyles(positionerElement, originalPositionerStylesRef.current);
|
|
1438
|
+
setControlledAlignItemWithTrigger(false);
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
const initialHeight = Math.max(minHeight, height);
|
|
1442
|
+
if (isTopPositioned) {
|
|
1443
|
+
const topOffset = Math.max(0, viewportHeight - idealHeight);
|
|
1444
|
+
positionerElement.style.top = positionerRect.height >= maxHeight ? "0" : `${topOffset}px`;
|
|
1445
|
+
positionerElement.style.height = `${height}px`;
|
|
1446
|
+
scroller.scrollTop = getMaxScrollTop(scroller);
|
|
1447
|
+
} else {
|
|
1448
|
+
positionerElement.style.bottom = "0";
|
|
1449
|
+
scroller.scrollTop = scrollTop;
|
|
1450
|
+
}
|
|
1451
|
+
if (textRect) {
|
|
1452
|
+
const popupTop = positionerRect.top;
|
|
1453
|
+
const popupHeight = positionerRect.height;
|
|
1454
|
+
const textCenterY = textRect.top + textRect.height / 2;
|
|
1455
|
+
const clampedY = clamp(popupHeight > 0 ? (textCenterY - popupTop) / popupHeight * 100 : 50, 0, 100);
|
|
1456
|
+
popupElement.style.setProperty(transformOrigin, `50% ${clampedY}%`);
|
|
1457
|
+
}
|
|
1458
|
+
if (initialHeight === viewportHeight || height >= maxPopupHeight) {
|
|
1459
|
+
reachedMaxHeightRef.current = true;
|
|
1460
|
+
}
|
|
1461
|
+
store.context.handleScrollArrowVisibility(scroller);
|
|
1462
|
+
if (highlightItemOnHover && store.state.selectedIndex === null && store.state.activeIndex === null && store.context.listRef.current[0] != null) {
|
|
1463
|
+
store.set("activeIndex", 0);
|
|
1464
|
+
}
|
|
1465
|
+
} finally {
|
|
1466
|
+
restoreTransformStyles();
|
|
1467
|
+
}
|
|
1468
|
+
}, [store, open, positionerElement, triggerElement, alignItemWithTriggerActive, setControlledAlignItemWithTrigger, scrollArrowFrame, listElement, highlightItemOnHover, direction, isPositioned]);
|
|
1469
|
+
React.useEffect(() => {
|
|
1470
|
+
if (!alignItemWithTriggerActive || !positionerElement || !open) {
|
|
1471
|
+
return void 0;
|
|
1472
|
+
}
|
|
1473
|
+
const win = getWindow(positionerElement);
|
|
1474
|
+
function handleResize(event) {
|
|
1475
|
+
store.context.setOpen(false, createChangeEventDetails(windowResize, event));
|
|
1476
|
+
}
|
|
1477
|
+
return addEventListener(win, "resize", handleResize);
|
|
1478
|
+
}, [store, alignItemWithTriggerActive, positionerElement, open]);
|
|
1479
|
+
const defaultProps = {
|
|
1480
|
+
...listElement ? {
|
|
1481
|
+
role: "presentation"
|
|
1482
|
+
} : {
|
|
1483
|
+
role: "listbox",
|
|
1484
|
+
"aria-multiselectable": multiple || void 0,
|
|
1485
|
+
"aria-readonly": readOnly || void 0,
|
|
1486
|
+
id: `${id}-list`
|
|
1487
|
+
},
|
|
1488
|
+
onKeyDown(event) {
|
|
1489
|
+
if (insideToolbar && COMPOSITE_KEYS.has(event.key)) {
|
|
1490
|
+
event.stopPropagation();
|
|
1491
|
+
}
|
|
1492
|
+
},
|
|
1493
|
+
onScroll(event) {
|
|
1494
|
+
if (listElement) {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
handleScroll(event.currentTarget);
|
|
1498
|
+
},
|
|
1499
|
+
...alignItemWithTriggerActive && {
|
|
1500
|
+
style: listElement ? {
|
|
1501
|
+
height: "100%"
|
|
1502
|
+
} : LIST_FUNCTIONAL_STYLES
|
|
1503
|
+
},
|
|
1504
|
+
className: !listElement && alignItemWithTriggerActive ? styleDisableScrollbar.className : void 0
|
|
1505
|
+
};
|
|
1506
|
+
const element = useRenderElement("div", componentProps, {
|
|
1507
|
+
ref: [forwardedRef, store.context.popupRef],
|
|
1508
|
+
state,
|
|
1509
|
+
stateAttributesMapping,
|
|
1510
|
+
props: [popupProps, defaultProps, getDisabledMountTransitionStyles(transitionStatus), elementProps]
|
|
1511
|
+
});
|
|
1512
|
+
return /* @__PURE__ */ jsxs(React.Fragment, {
|
|
1513
|
+
children: [!disableStyleElements && styleDisableScrollbar.getElement(nonce), /* @__PURE__ */ jsx(FloatingFocusManager, {
|
|
1514
|
+
context: floatingRootContext,
|
|
1515
|
+
modal: false,
|
|
1516
|
+
disabled: !mounted,
|
|
1517
|
+
openInteractionType: openMethod,
|
|
1518
|
+
returnFocus: finalFocus,
|
|
1519
|
+
restoreFocus: true,
|
|
1520
|
+
children: element
|
|
1521
|
+
})]
|
|
1522
|
+
});
|
|
1523
|
+
});
|
|
1524
|
+
if (process.env.NODE_ENV !== "production") SelectPopup.displayName = "SelectPopup";
|
|
1525
|
+
function getMaxPopupHeight(popupStyles) {
|
|
1526
|
+
const maxHeightStyle = popupStyles.maxHeight;
|
|
1527
|
+
return maxHeightStyle.endsWith("px") ? parseFloat(maxHeightStyle) || Infinity : Infinity;
|
|
1528
|
+
}
|
|
1529
|
+
function getMaxScrollTop(scroller) {
|
|
1530
|
+
return getMaxScrollOffset(scroller.scrollHeight, scroller.clientHeight);
|
|
1531
|
+
}
|
|
1532
|
+
function getScale(element) {
|
|
1533
|
+
return platform.getScale(element);
|
|
1534
|
+
}
|
|
1535
|
+
function normalizeSize(size, axis, scale) {
|
|
1536
|
+
return size / scale[axis];
|
|
1537
|
+
}
|
|
1538
|
+
function normalizeRect(rect, scale) {
|
|
1539
|
+
return rectToClientRect({
|
|
1540
|
+
x: normalizeSize(rect.x, "x", scale),
|
|
1541
|
+
y: normalizeSize(rect.y, "y", scale),
|
|
1542
|
+
width: normalizeSize(rect.width, "x", scale),
|
|
1543
|
+
height: normalizeSize(rect.height, "y", scale)
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
const TRANSFORM_STYLE_RESETS = [["transform", "none"], ["scale", "1"], ["translate", "0 0"]];
|
|
1547
|
+
function unsetTransformStyles(popupElement) {
|
|
1548
|
+
const {
|
|
1549
|
+
style
|
|
1550
|
+
} = popupElement;
|
|
1551
|
+
const originalStyles = {};
|
|
1552
|
+
for (const [property, value] of TRANSFORM_STYLE_RESETS) {
|
|
1553
|
+
originalStyles[property] = style.getPropertyValue(property);
|
|
1554
|
+
style.setProperty(property, value, "important");
|
|
1555
|
+
}
|
|
1556
|
+
return () => {
|
|
1557
|
+
for (const [property] of TRANSFORM_STYLE_RESETS) {
|
|
1558
|
+
const originalValue = originalStyles[property];
|
|
1559
|
+
if (originalValue) {
|
|
1560
|
+
style.setProperty(property, originalValue);
|
|
1561
|
+
} else {
|
|
1562
|
+
style.removeProperty(property);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
const SelectList = /* @__PURE__ */ React.forwardRef(function SelectList2(componentProps, forwardedRef) {
|
|
1568
|
+
const {
|
|
1569
|
+
render,
|
|
1570
|
+
className,
|
|
1571
|
+
style,
|
|
1572
|
+
...elementProps
|
|
1573
|
+
} = componentProps;
|
|
1574
|
+
const store = useSelectRootContext();
|
|
1575
|
+
const multiple = store.useState("multiple");
|
|
1576
|
+
const readOnly = store.useState("readOnly");
|
|
1577
|
+
const {
|
|
1578
|
+
alignItemWithTriggerActive
|
|
1579
|
+
} = useSelectPositionerContext();
|
|
1580
|
+
const hasScrollArrows = store.useState("hasScrollArrows");
|
|
1581
|
+
const openMethod = store.useState("openMethod");
|
|
1582
|
+
const id = store.useState("id");
|
|
1583
|
+
const defaultProps = {
|
|
1584
|
+
id: `${id}-list`,
|
|
1585
|
+
role: "listbox",
|
|
1586
|
+
"aria-multiselectable": multiple || void 0,
|
|
1587
|
+
"aria-readonly": readOnly || void 0,
|
|
1588
|
+
onScroll(event) {
|
|
1589
|
+
var _a, _b;
|
|
1590
|
+
(_b = (_a = store.context.scrollHandlerRef).current) == null ? void 0 : _b.call(_a, event.currentTarget);
|
|
1591
|
+
},
|
|
1592
|
+
...alignItemWithTriggerActive && {
|
|
1593
|
+
style: LIST_FUNCTIONAL_STYLES
|
|
1594
|
+
},
|
|
1595
|
+
className: hasScrollArrows && openMethod !== "touch" ? styleDisableScrollbar.className : void 0
|
|
1596
|
+
};
|
|
1597
|
+
const setListElement = store.useStateSetter("listElement");
|
|
1598
|
+
return useRenderElement("div", componentProps, {
|
|
1599
|
+
ref: [forwardedRef, setListElement],
|
|
1600
|
+
props: [defaultProps, elementProps]
|
|
1601
|
+
});
|
|
1602
|
+
});
|
|
1603
|
+
if (process.env.NODE_ENV !== "production") SelectList.displayName = "SelectList";
|
|
1604
|
+
const SelectItemContext = /* @__PURE__ */ React.createContext(void 0);
|
|
1605
|
+
if (process.env.NODE_ENV !== "production") SelectItemContext.displayName = "SelectItemContext";
|
|
1606
|
+
function useSelectItemContext() {
|
|
1607
|
+
const context = React.useContext(SelectItemContext);
|
|
1608
|
+
if (!context) {
|
|
1609
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SelectItemContext is missing. SelectItem parts must be placed within <Select.Item>." : formatErrorMessage(57));
|
|
1610
|
+
}
|
|
1611
|
+
return context;
|
|
1612
|
+
}
|
|
1613
|
+
const SelectItem$1 = /* @__PURE__ */ React.memo(/* @__PURE__ */ React.forwardRef(function SelectItem(componentProps, forwardedRef) {
|
|
1614
|
+
const {
|
|
1615
|
+
render,
|
|
1616
|
+
className,
|
|
1617
|
+
style,
|
|
1618
|
+
value: itemValue = null,
|
|
1619
|
+
label,
|
|
1620
|
+
disabled: disabledProp = false,
|
|
1621
|
+
nativeButton = false,
|
|
1622
|
+
...elementProps
|
|
1623
|
+
} = componentProps;
|
|
1624
|
+
const textRef = React.useRef(null);
|
|
1625
|
+
const listItem = useCompositeListItem({
|
|
1626
|
+
guess: true,
|
|
1627
|
+
label,
|
|
1628
|
+
textRef
|
|
1629
|
+
});
|
|
1630
|
+
const store = useSelectRootContext();
|
|
1631
|
+
const {
|
|
1632
|
+
props: itemProps,
|
|
1633
|
+
multiple,
|
|
1634
|
+
disabled: selectDisabled,
|
|
1635
|
+
readOnly,
|
|
1636
|
+
isItemEqualToValue
|
|
1637
|
+
} = store.useState("itemRoot");
|
|
1638
|
+
const disabled = selectDisabled || disabledProp;
|
|
1639
|
+
const highlighted = store.useState("isActive", listItem.index);
|
|
1640
|
+
const open = store.useState("open");
|
|
1641
|
+
const selected = store.useState("isSelected", itemValue);
|
|
1642
|
+
const selectedByFocus = store.useState("isSelectedByFocus", listItem.index);
|
|
1643
|
+
const index = listItem.index;
|
|
1644
|
+
const itemRef = React.useRef(null);
|
|
1645
|
+
useIsoLayoutEffect(() => {
|
|
1646
|
+
const values = store.context.valuesRef.current;
|
|
1647
|
+
values[index] = itemValue;
|
|
1648
|
+
return () => {
|
|
1649
|
+
delete values[index];
|
|
1650
|
+
};
|
|
1651
|
+
}, [index, itemValue, store]);
|
|
1652
|
+
useIsoLayoutEffect(() => {
|
|
1653
|
+
const selectedValue = store.state.value;
|
|
1654
|
+
const currentIndex = store.state.selectedIndex;
|
|
1655
|
+
let nextIndex = currentIndex;
|
|
1656
|
+
let claims;
|
|
1657
|
+
if (multiple && Array.isArray(selectedValue)) {
|
|
1658
|
+
nextIndex = resolveSelectedIndex(index, itemValue, store.context.valuesRef.current, selectedValue, isItemEqualToValue, currentIndex);
|
|
1659
|
+
claims = nextIndex === index;
|
|
1660
|
+
if (index === currentIndex && !claims) {
|
|
1661
|
+
store.context.selectedItemTextRef.current = null;
|
|
1662
|
+
}
|
|
1663
|
+
} else {
|
|
1664
|
+
claims = selectedValue !== void 0 && compareItemEquality(itemValue, selectedValue, isItemEqualToValue);
|
|
1665
|
+
if (claims) {
|
|
1666
|
+
nextIndex = index;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
store.set("selectedIndex", nextIndex);
|
|
1670
|
+
if (claims && textRef.current) {
|
|
1671
|
+
store.context.selectedItemTextRef.current = textRef.current;
|
|
1672
|
+
}
|
|
1673
|
+
}, [index, multiple, isItemEqualToValue, store, itemValue]);
|
|
1674
|
+
const pointerTypeRef = React.useRef("mouse");
|
|
1675
|
+
const allowMouseSelectionRef = React.useRef(false);
|
|
1676
|
+
const {
|
|
1677
|
+
getButtonProps,
|
|
1678
|
+
buttonRef
|
|
1679
|
+
} = useButton({
|
|
1680
|
+
disabled,
|
|
1681
|
+
focusableWhenDisabled: true,
|
|
1682
|
+
native: nativeButton,
|
|
1683
|
+
composite: true
|
|
1684
|
+
});
|
|
1685
|
+
const state = {
|
|
1686
|
+
disabled,
|
|
1687
|
+
selected,
|
|
1688
|
+
highlighted
|
|
1689
|
+
};
|
|
1690
|
+
function commitSelection(event) {
|
|
1691
|
+
if (selectDisabled || readOnly) {
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
const selectedValue = store.state.value;
|
|
1695
|
+
if (multiple) {
|
|
1696
|
+
const currentValue = Array.isArray(selectedValue) ? selectedValue : [];
|
|
1697
|
+
const nextValue = selected ? removeItem(currentValue, itemValue, isItemEqualToValue) : [...currentValue, itemValue];
|
|
1698
|
+
store.context.setValue(nextValue, createChangeEventDetails(itemPress, event));
|
|
1699
|
+
} else {
|
|
1700
|
+
store.context.setValue(itemValue, createChangeEventDetails(itemPress, event));
|
|
1701
|
+
store.context.setOpen(false, createChangeEventDetails(itemPress, event));
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
function resetDragMovement() {
|
|
1705
|
+
store.context.selectionRef.current.dragY = 0;
|
|
1706
|
+
}
|
|
1707
|
+
const defaultProps = {
|
|
1708
|
+
role: "option",
|
|
1709
|
+
"aria-selected": selected,
|
|
1710
|
+
tabIndex: open && highlighted ? 0 : -1,
|
|
1711
|
+
onKeyDown(event) {
|
|
1712
|
+
store.set("activeIndex", index);
|
|
1713
|
+
if (event.key === " " && store.context.typingRef.current) {
|
|
1714
|
+
event.preventDefault();
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1717
|
+
onClick(event) {
|
|
1718
|
+
const isMouseClick = pointerTypeRef.current !== "touch";
|
|
1719
|
+
const clickPointerType = event.nativeEvent.pointerType;
|
|
1720
|
+
const isVirtualMouseClick = isMouseClick && isVirtualClick(event.nativeEvent) && // Generic no-pointer `detail === 0` clicks stay tied to highlight state. Virtual
|
|
1721
|
+
// clicks that carry browser pointer data, including an empty string from assistive
|
|
1722
|
+
// technology, can activate unhighlighted items.
|
|
1723
|
+
(clickPointerType !== void 0 || highlighted);
|
|
1724
|
+
const isInvalidMouseClick = isMouseClick && !isVirtualMouseClick && !allowMouseSelectionRef.current;
|
|
1725
|
+
allowMouseSelectionRef.current = false;
|
|
1726
|
+
if (disabled || isInvalidMouseClick) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
commitSelection(event.nativeEvent);
|
|
1730
|
+
},
|
|
1731
|
+
onPointerEnter(event) {
|
|
1732
|
+
pointerTypeRef.current = event.pointerType;
|
|
1733
|
+
},
|
|
1734
|
+
onPointerMove(event) {
|
|
1735
|
+
if (event.pointerType === "mouse" && event.buttons === 1) {
|
|
1736
|
+
const selection = store.context.selectionRef.current;
|
|
1737
|
+
selection.dragY += event.movementY;
|
|
1738
|
+
if (selection.dragY ** 2 >= 64) {
|
|
1739
|
+
selection.allowUnselectedMouseUp = true;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
},
|
|
1743
|
+
onPointerDown(event) {
|
|
1744
|
+
pointerTypeRef.current = event.pointerType;
|
|
1745
|
+
allowMouseSelectionRef.current = true;
|
|
1746
|
+
resetDragMovement();
|
|
1747
|
+
},
|
|
1748
|
+
onMouseUp() {
|
|
1749
|
+
var _a;
|
|
1750
|
+
resetDragMovement();
|
|
1751
|
+
if (disabled || pointerTypeRef.current === "touch") {
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
if (allowMouseSelectionRef.current) {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
const disallowSelectedMouseUp = !store.context.selectionRef.current.allowSelectedMouseUp && selected;
|
|
1758
|
+
const disallowUnselectedMouseUp = !store.context.selectionRef.current.allowUnselectedMouseUp && !selected;
|
|
1759
|
+
if (disallowSelectedMouseUp || disallowUnselectedMouseUp) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
allowMouseSelectionRef.current = true;
|
|
1763
|
+
(_a = itemRef.current) == null ? void 0 : _a.click();
|
|
1764
|
+
allowMouseSelectionRef.current = false;
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
const element = useRenderElement("div", componentProps, {
|
|
1768
|
+
ref: [buttonRef, forwardedRef, listItem.ref, itemRef],
|
|
1769
|
+
state,
|
|
1770
|
+
props: [itemProps, defaultProps, elementProps, getButtonProps]
|
|
1771
|
+
});
|
|
1772
|
+
const contextValue = React.useMemo(() => ({
|
|
1773
|
+
selected,
|
|
1774
|
+
index,
|
|
1775
|
+
textRef,
|
|
1776
|
+
selectedByFocus
|
|
1777
|
+
}), [selected, index, textRef, selectedByFocus]);
|
|
1778
|
+
return /* @__PURE__ */ jsx(SelectItemContext.Provider, {
|
|
1779
|
+
value: contextValue,
|
|
1780
|
+
children: element
|
|
1781
|
+
});
|
|
1782
|
+
}));
|
|
1783
|
+
if (process.env.NODE_ENV !== "production") SelectItem$1.displayName = "SelectItem";
|
|
1784
|
+
const SelectItemIndicator = /* @__PURE__ */ React.forwardRef(function SelectItemIndicator2(componentProps, forwardedRef) {
|
|
1785
|
+
const {
|
|
1786
|
+
selected
|
|
1787
|
+
} = useSelectItemContext();
|
|
1788
|
+
const shouldRender = componentProps.keepMounted || selected;
|
|
1789
|
+
if (!shouldRender) {
|
|
1790
|
+
return null;
|
|
1791
|
+
}
|
|
1792
|
+
return /* @__PURE__ */ jsx(ItemIndicator, {
|
|
1793
|
+
...componentProps,
|
|
1794
|
+
selected,
|
|
1795
|
+
ref: forwardedRef
|
|
1796
|
+
});
|
|
1797
|
+
});
|
|
1798
|
+
if (process.env.NODE_ENV !== "production") SelectItemIndicator.displayName = "SelectItemIndicator";
|
|
1799
|
+
const SelectItemText = /* @__PURE__ */ React.memo(/* @__PURE__ */ React.forwardRef(function SelectItemText2(componentProps, forwardedRef) {
|
|
1800
|
+
const {
|
|
1801
|
+
index,
|
|
1802
|
+
textRef,
|
|
1803
|
+
selectedByFocus
|
|
1804
|
+
} = useSelectItemContext();
|
|
1805
|
+
const store = useSelectRootContext();
|
|
1806
|
+
const {
|
|
1807
|
+
render,
|
|
1808
|
+
className,
|
|
1809
|
+
style,
|
|
1810
|
+
...elementProps
|
|
1811
|
+
} = componentProps;
|
|
1812
|
+
const localRef = React.useCallback((node) => {
|
|
1813
|
+
if (!node) {
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
if (index === 0) {
|
|
1817
|
+
store.context.firstItemTextRef.current = node;
|
|
1818
|
+
}
|
|
1819
|
+
if (selectedByFocus) {
|
|
1820
|
+
store.context.selectedItemTextRef.current = node;
|
|
1821
|
+
}
|
|
1822
|
+
}, [store, index, selectedByFocus]);
|
|
1823
|
+
const element = useRenderElement("div", componentProps, {
|
|
1824
|
+
ref: [localRef, forwardedRef, textRef],
|
|
1825
|
+
props: elementProps
|
|
1826
|
+
});
|
|
1827
|
+
return element;
|
|
1828
|
+
}));
|
|
1829
|
+
if (process.env.NODE_ENV !== "production") SelectItemText.displayName = "SelectItemText";
|
|
1830
|
+
const SelectGroupContext = /* @__PURE__ */ React.createContext(void 0);
|
|
1831
|
+
if (process.env.NODE_ENV !== "production") SelectGroupContext.displayName = "SelectGroupContext";
|
|
1832
|
+
function useSelectGroupContext() {
|
|
1833
|
+
const context = React.useContext(SelectGroupContext);
|
|
1834
|
+
if (context === void 0) {
|
|
1835
|
+
throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SelectGroupContext is missing. SelectGroup parts must be placed within <Select.Group>." : formatErrorMessage(56));
|
|
1836
|
+
}
|
|
1837
|
+
return context;
|
|
1838
|
+
}
|
|
1839
|
+
const SelectGroup$1 = /* @__PURE__ */ React.forwardRef(function SelectGroup(componentProps, forwardedRef) {
|
|
1840
|
+
const {
|
|
1841
|
+
render,
|
|
1842
|
+
className,
|
|
1843
|
+
style,
|
|
1844
|
+
...elementProps
|
|
1845
|
+
} = componentProps;
|
|
1846
|
+
const [labelId, setLabelId] = React.useState();
|
|
1847
|
+
const contextValue = React.useMemo(() => ({
|
|
1848
|
+
labelId,
|
|
1849
|
+
setLabelId
|
|
1850
|
+
}), [labelId, setLabelId]);
|
|
1851
|
+
const element = useRenderElement("div", componentProps, {
|
|
1852
|
+
ref: forwardedRef,
|
|
1853
|
+
props: [{
|
|
1854
|
+
role: "group",
|
|
1855
|
+
"aria-labelledby": labelId
|
|
1856
|
+
}, elementProps]
|
|
1857
|
+
});
|
|
1858
|
+
return /* @__PURE__ */ jsx(SelectGroupContext.Provider, {
|
|
1859
|
+
value: contextValue,
|
|
1860
|
+
children: element
|
|
1861
|
+
});
|
|
1862
|
+
});
|
|
1863
|
+
if (process.env.NODE_ENV !== "production") SelectGroup$1.displayName = "SelectGroup";
|
|
1864
|
+
const SelectGroupLabel = /* @__PURE__ */ React.forwardRef(function SelectGroupLabel2(componentProps, forwardedRef) {
|
|
1865
|
+
const {
|
|
1866
|
+
render,
|
|
1867
|
+
className,
|
|
1868
|
+
style,
|
|
1869
|
+
id: idProp,
|
|
1870
|
+
...elementProps
|
|
1871
|
+
} = componentProps;
|
|
1872
|
+
const {
|
|
1873
|
+
setLabelId
|
|
1874
|
+
} = useSelectGroupContext();
|
|
1875
|
+
const id = useBaseUiId(idProp);
|
|
1876
|
+
useIsoLayoutEffect(() => {
|
|
1877
|
+
setLabelId(id);
|
|
1878
|
+
return () => {
|
|
1879
|
+
setLabelId((currentId) => currentId === id ? void 0 : currentId);
|
|
1880
|
+
};
|
|
1881
|
+
}, [id, setLabelId]);
|
|
1882
|
+
const element = useRenderElement("div", componentProps, {
|
|
1883
|
+
ref: forwardedRef,
|
|
1884
|
+
props: [{
|
|
1885
|
+
id,
|
|
1886
|
+
"aria-hidden": true
|
|
1887
|
+
}, elementProps]
|
|
1888
|
+
});
|
|
1889
|
+
return element;
|
|
1890
|
+
});
|
|
1891
|
+
if (process.env.NODE_ENV !== "production") SelectGroupLabel.displayName = "SelectGroupLabel";
|
|
1892
|
+
const SelectSeparator$1 = ListboxSeparator;
|
|
1893
|
+
const selectTriggerVariants = cva(
|
|
1894
|
+
"flex h-8 w-full min-w-0 items-center gap-space-8 rounded-md border bg-background-input px-space-10 text-left font-lab text-body-md text-text-primary",
|
|
1895
|
+
{
|
|
1896
|
+
variants: {
|
|
1897
|
+
invalid: {
|
|
1898
|
+
true: "border-status-border-error-bold",
|
|
1899
|
+
false: "border-border-default"
|
|
1900
|
+
},
|
|
1901
|
+
// borderless: for a trigger that sits inside another surface (table cell, joined field) and owns no chrome.
|
|
1902
|
+
variant: {
|
|
1903
|
+
default: "",
|
|
1904
|
+
borderless: "border-transparent bg-transparent hover:bg-background-ghost-hover"
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
defaultVariants: {
|
|
1908
|
+
invalid: false,
|
|
1909
|
+
variant: "default"
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
);
|
|
1913
|
+
const selectAttachedClasses = {
|
|
1914
|
+
start: "rounded-l-none border-l-0",
|
|
1915
|
+
end: "rounded-r-none border-r-0",
|
|
1916
|
+
top: "rounded-t-none border-t-0",
|
|
1917
|
+
bottom: "rounded-b-none border-b-0"
|
|
1918
|
+
};
|
|
1919
|
+
function selectAttachedClass(attached) {
|
|
1920
|
+
if (!attached) return void 0;
|
|
1921
|
+
return (Array.isArray(attached) ? attached : [attached]).map((edge) => selectAttachedClasses[edge]);
|
|
1922
|
+
}
|
|
1923
|
+
const selectChipVariants = cva(
|
|
1924
|
+
"inline-flex h-5 shrink-0 items-center gap-space-4 rounded-sm border border-border-secondary px-space-8 font-lab text-label-sm whitespace-nowrap text-text-secondary",
|
|
1925
|
+
{
|
|
1926
|
+
variants: {
|
|
1927
|
+
tone: {
|
|
1928
|
+
default: "bg-background-raised hover:border-border-default hover:bg-background-ghost-hover",
|
|
1929
|
+
more: "bg-background-item-selected"
|
|
1930
|
+
}
|
|
1931
|
+
},
|
|
1932
|
+
defaultVariants: {
|
|
1933
|
+
tone: "default"
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
);
|
|
1937
|
+
const SelectDisabledContext = React.createContext(false);
|
|
1938
|
+
function Select({
|
|
1939
|
+
disabled,
|
|
1940
|
+
...props
|
|
1941
|
+
}) {
|
|
1942
|
+
return /* @__PURE__ */ jsx(SelectDisabledContext, { value: disabled ?? false, children: /* @__PURE__ */ jsx(SelectRoot, { disabled, ...props }) });
|
|
1943
|
+
}
|
|
1944
|
+
function SelectTrailing({ clearLabel, disabled, invalid, onClear, showClear }) {
|
|
1945
|
+
return /* @__PURE__ */ jsxs("span", { className: "pointer-events-none absolute inset-y-0 right-space-10 flex items-center gap-space-8", children: [
|
|
1946
|
+
invalid ? /* @__PURE__ */ jsx(IconProvider, { icon: "triangle-exclamation", size: "16", className: "text-status-text-error" }) : null,
|
|
1947
|
+
showClear ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1948
|
+
/* @__PURE__ */ jsx(
|
|
1949
|
+
"button",
|
|
1950
|
+
{
|
|
1951
|
+
type: "button",
|
|
1952
|
+
"aria-label": clearLabel,
|
|
1953
|
+
disabled,
|
|
1954
|
+
onClick: onClear,
|
|
1955
|
+
className: "pointer-events-auto flex size-4 items-center justify-center rounded-sm text-icon-primary focus-ring disabled:pointer-events-none",
|
|
1956
|
+
children: /* @__PURE__ */ jsx(IconProvider, { icon: "xmark", size: "12" })
|
|
1957
|
+
}
|
|
1958
|
+
),
|
|
1959
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "h-4 w-px bg-border-subtle" })
|
|
1960
|
+
] }) : null,
|
|
1961
|
+
/* @__PURE__ */ jsx(
|
|
1962
|
+
IconProvider,
|
|
1963
|
+
{
|
|
1964
|
+
icon: "chevron-down",
|
|
1965
|
+
size: "16",
|
|
1966
|
+
className: "text-icon-secondary transition-transform group-has-[[data-popup-open]]/select:rotate-180"
|
|
1967
|
+
}
|
|
1968
|
+
)
|
|
1969
|
+
] });
|
|
1970
|
+
}
|
|
1971
|
+
const trailingPadding = { plain: "pr-8.5", invalid: "pr-14.5", clear: "pr-16.75", invalidClear: "pr-22.75" };
|
|
1972
|
+
function SelectTrigger2({
|
|
1973
|
+
attached,
|
|
1974
|
+
className,
|
|
1975
|
+
clearLabel = "Clear selection",
|
|
1976
|
+
invalid,
|
|
1977
|
+
onClear,
|
|
1978
|
+
showClear = false,
|
|
1979
|
+
variant,
|
|
1980
|
+
wrapperClassName,
|
|
1981
|
+
...props
|
|
1982
|
+
}) {
|
|
1983
|
+
const isInvalid = invalid ?? false;
|
|
1984
|
+
const disabled = React.useContext(SelectDisabledContext);
|
|
1985
|
+
const padding = isInvalid ? showClear ? trailingPadding.invalidClear : trailingPadding.invalid : showClear ? trailingPadding.clear : trailingPadding.plain;
|
|
1986
|
+
return /* @__PURE__ */ jsxs(
|
|
1987
|
+
"div",
|
|
1988
|
+
{
|
|
1989
|
+
"data-slot": "select-trigger-wrapper",
|
|
1990
|
+
className: classNames("group/select relative w-80 max-w-full has-[[data-disabled]]:opacity-50", wrapperClassName),
|
|
1991
|
+
children: [
|
|
1992
|
+
/* @__PURE__ */ jsx(
|
|
1993
|
+
SelectTrigger$1,
|
|
1994
|
+
{
|
|
1995
|
+
"data-slot": "select-trigger",
|
|
1996
|
+
"aria-invalid": isInvalid || void 0,
|
|
1997
|
+
className: classNames(
|
|
1998
|
+
selectTriggerVariants({ invalid: isInvalid, variant }),
|
|
1999
|
+
padding,
|
|
2000
|
+
selectAttachedClass(attached),
|
|
2001
|
+
"cursor-pointer focus-ring data-disabled:cursor-not-allowed data-popup-open:outline-2 data-popup-open:outline-offset-2 data-popup-open:outline-border-focus",
|
|
2002
|
+
className
|
|
2003
|
+
),
|
|
2004
|
+
...props
|
|
2005
|
+
}
|
|
2006
|
+
),
|
|
2007
|
+
/* @__PURE__ */ jsx(
|
|
2008
|
+
SelectTrailing,
|
|
2009
|
+
{
|
|
2010
|
+
clearLabel,
|
|
2011
|
+
disabled,
|
|
2012
|
+
invalid: isInvalid,
|
|
2013
|
+
onClear,
|
|
2014
|
+
showClear
|
|
2015
|
+
}
|
|
2016
|
+
)
|
|
2017
|
+
]
|
|
2018
|
+
}
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
function SelectChipRemove({ label, onRemove }) {
|
|
2022
|
+
const disabled = React.useContext(SelectDisabledContext);
|
|
2023
|
+
const stop = (event) => {
|
|
2024
|
+
event.stopPropagation();
|
|
2025
|
+
};
|
|
2026
|
+
return /* @__PURE__ */ jsx(
|
|
2027
|
+
"span",
|
|
2028
|
+
{
|
|
2029
|
+
role: "button",
|
|
2030
|
+
"aria-label": label,
|
|
2031
|
+
"aria-disabled": disabled || void 0,
|
|
2032
|
+
tabIndex: -1,
|
|
2033
|
+
onPointerDown: stop,
|
|
2034
|
+
onMouseDown: stop,
|
|
2035
|
+
onClick: (event) => {
|
|
2036
|
+
event.stopPropagation();
|
|
2037
|
+
if (!disabled) onRemove();
|
|
2038
|
+
},
|
|
2039
|
+
className: "flex size-2.25 shrink-0 cursor-pointer items-center justify-center rounded-sm text-icon-secondary hover:text-icon-primary aria-disabled:pointer-events-none",
|
|
2040
|
+
children: /* @__PURE__ */ jsx(IconProvider, { icon: "xmark", size: 0.75 })
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
function SelectValue2({
|
|
2045
|
+
children,
|
|
2046
|
+
className,
|
|
2047
|
+
countLabel = "Selected",
|
|
2048
|
+
display = "text",
|
|
2049
|
+
formatValue = String,
|
|
2050
|
+
maxChips = 2,
|
|
2051
|
+
onRemoveAll,
|
|
2052
|
+
onRemoveValue,
|
|
2053
|
+
placeholder,
|
|
2054
|
+
removeLabel = "Remove",
|
|
2055
|
+
...props
|
|
2056
|
+
}) {
|
|
2057
|
+
const renderValue = (value) => {
|
|
2058
|
+
const values = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
2059
|
+
if (values.length === 0) return /* @__PURE__ */ jsx("span", { className: "text-text-placeholder", children: placeholder });
|
|
2060
|
+
if (display === "count") {
|
|
2061
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-space-8", children: [
|
|
2062
|
+
/* @__PURE__ */ jsxs("span", { className: selectChipVariants(), children: [
|
|
2063
|
+
values.length,
|
|
2064
|
+
onRemoveAll ? /* @__PURE__ */ jsx(SelectChipRemove, { label: removeLabel, onRemove: onRemoveAll }) : null
|
|
2065
|
+
] }),
|
|
2066
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: countLabel })
|
|
2067
|
+
] });
|
|
2068
|
+
}
|
|
2069
|
+
const visible = values.slice(0, maxChips);
|
|
2070
|
+
const overflow = values.length - visible.length;
|
|
2071
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-space-4 overflow-hidden", children: [
|
|
2072
|
+
visible.map((item, index) => /* @__PURE__ */ jsxs("span", { className: selectChipVariants(), children: [
|
|
2073
|
+
formatValue(item),
|
|
2074
|
+
onRemoveValue ? /* @__PURE__ */ jsx(SelectChipRemove, { label: removeLabel, onRemove: () => onRemoveValue(item) }) : null
|
|
2075
|
+
] }, index)),
|
|
2076
|
+
overflow > 0 ? /* @__PURE__ */ jsxs("span", { className: selectChipVariants({ tone: "more" }), children: [
|
|
2077
|
+
"+",
|
|
2078
|
+
overflow
|
|
2079
|
+
] }) : null
|
|
2080
|
+
] });
|
|
2081
|
+
};
|
|
2082
|
+
return /* @__PURE__ */ jsx(
|
|
2083
|
+
SelectValue$1,
|
|
2084
|
+
{
|
|
2085
|
+
"data-slot": "select-value",
|
|
2086
|
+
placeholder,
|
|
2087
|
+
className: classNames("min-w-0 flex-1 truncate data-placeholder:text-text-placeholder", className),
|
|
2088
|
+
...props,
|
|
2089
|
+
children: children ?? (display === "text" ? void 0 : renderValue)
|
|
2090
|
+
}
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
function SelectContent({
|
|
2094
|
+
align = "start",
|
|
2095
|
+
children,
|
|
2096
|
+
className,
|
|
2097
|
+
collisionAvoidance,
|
|
2098
|
+
container,
|
|
2099
|
+
positionerClassName,
|
|
2100
|
+
side = "bottom",
|
|
2101
|
+
sideOffset = 8,
|
|
2102
|
+
...props
|
|
2103
|
+
}) {
|
|
2104
|
+
return /* @__PURE__ */ jsx(SelectPortal, { container, children: /* @__PURE__ */ jsx(
|
|
2105
|
+
SelectPositioner,
|
|
2106
|
+
{
|
|
2107
|
+
"data-slot": "select-positioner",
|
|
2108
|
+
align,
|
|
2109
|
+
alignItemWithTrigger: false,
|
|
2110
|
+
collisionAvoidance,
|
|
2111
|
+
side,
|
|
2112
|
+
sideOffset,
|
|
2113
|
+
className: classNames("isolate z-[1600] outline-none", positionerClassName),
|
|
2114
|
+
children: /* @__PURE__ */ jsx(
|
|
2115
|
+
SelectPopup,
|
|
2116
|
+
{
|
|
2117
|
+
"data-slot": "select-content",
|
|
2118
|
+
className: classNames(dropdownPanelVariants({ motion: "select", width: "trigger" }), className),
|
|
2119
|
+
...props,
|
|
2120
|
+
children: /* @__PURE__ */ jsx(SelectList, { className: dropdownListVariants(), children })
|
|
2121
|
+
}
|
|
2122
|
+
)
|
|
2123
|
+
}
|
|
2124
|
+
) });
|
|
2125
|
+
}
|
|
2126
|
+
function SelectItem2({ children, className, ...props }) {
|
|
2127
|
+
return /* @__PURE__ */ jsxs(SelectItem$1, { "data-slot": "select-item", className: classNames(dropdownItemVariants(), className), ...props, children: [
|
|
2128
|
+
/* @__PURE__ */ jsx(SelectItemText, { className: "flex min-w-0 flex-1 items-center gap-space-8 truncate", children }),
|
|
2129
|
+
/* @__PURE__ */ jsx(SelectItemIndicator, { className: "flex shrink-0 text-icon-brand", children: /* @__PURE__ */ jsx(IconProvider, { icon: "check", size: "16" }) })
|
|
2130
|
+
] });
|
|
2131
|
+
}
|
|
2132
|
+
function SelectGroup2({ className, ...props }) {
|
|
2133
|
+
return /* @__PURE__ */ jsx(SelectGroup$1, { "data-slot": "select-group", className: classNames("flex flex-col gap-space-2", className), ...props });
|
|
2134
|
+
}
|
|
2135
|
+
function SelectLabel({ caps, className, ...props }) {
|
|
2136
|
+
return /* @__PURE__ */ jsx(
|
|
2137
|
+
SelectGroupLabel,
|
|
2138
|
+
{
|
|
2139
|
+
"data-slot": "select-label",
|
|
2140
|
+
className: classNames(dropdownLabelVariants({ caps }), className),
|
|
2141
|
+
...props
|
|
2142
|
+
}
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
function SelectSeparator({ className, ...props }) {
|
|
2146
|
+
return /* @__PURE__ */ jsx(
|
|
2147
|
+
SelectSeparator$1,
|
|
2148
|
+
{
|
|
2149
|
+
"data-slot": "select-separator",
|
|
2150
|
+
className: classNames(dropdownSeparatorVariants(), className),
|
|
2151
|
+
...props
|
|
2152
|
+
}
|
|
2153
|
+
);
|
|
2154
|
+
}
|
|
2155
|
+
export {
|
|
2156
|
+
SelectTrailing as A,
|
|
2157
|
+
ItemIndicator as I,
|
|
2158
|
+
ListboxSeparator as L,
|
|
2159
|
+
Select as S,
|
|
2160
|
+
SelectContent as a,
|
|
2161
|
+
SelectGroup2 as b,
|
|
2162
|
+
SelectItem2 as c,
|
|
2163
|
+
SelectLabel as d,
|
|
2164
|
+
SelectSeparator as e,
|
|
2165
|
+
SelectTrigger2 as f,
|
|
2166
|
+
selectTriggerVariants as g,
|
|
2167
|
+
SelectValue2 as h,
|
|
2168
|
+
compareItemEquality as i,
|
|
2169
|
+
hasNullItemLabel as j,
|
|
2170
|
+
stringifyAsLabel as k,
|
|
2171
|
+
defaultItemEquality as l,
|
|
2172
|
+
flattenLeafItems as m,
|
|
2173
|
+
isGroupedItems as n,
|
|
2174
|
+
findSelectionIndex as o,
|
|
2175
|
+
stringifyAsValue as p,
|
|
2176
|
+
selectedValueIncludes as q,
|
|
2177
|
+
removeItem as r,
|
|
2178
|
+
selectChipVariants as s,
|
|
2179
|
+
findItemIndex as t,
|
|
2180
|
+
useFloatingRootContext as u,
|
|
2181
|
+
useOnFirstRender as v,
|
|
2182
|
+
isSelectedValueDirty as w,
|
|
2183
|
+
resolveSelectedIndex as x,
|
|
2184
|
+
selectAttachedClass as y,
|
|
2185
|
+
trailingPadding as z
|
|
2186
|
+
};
|
|
2187
|
+
//# sourceMappingURL=Select-BtX40h2K.js.map
|