@vritti/quantum-ui 0.3.3 → 0.3.5
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/Alert.js +1 -1
- package/dist/Avatar.js +4 -4
- package/dist/Badge2.js +2 -2
- package/dist/Breadcrumb.js +1 -1
- package/dist/Button2.js +2 -2
- package/dist/Checkbox2.js +6 -6
- package/dist/Combination.js +3 -3
- package/dist/DateTimePicker.js +2 -2
- package/dist/Dialog.js +1 -1
- package/dist/Label.js +1 -1
- package/dist/Progress.js +2 -2
- package/dist/RadioGroup.js +8 -8
- package/dist/Select.js +2 -2
- package/dist/SelectFilter.js +2 -2
- package/dist/Sidebar.js +3 -3
- package/dist/SingleSelect.js +1 -1
- package/dist/Sonner.js +1 -1
- package/dist/Switch.js +5 -5
- package/dist/TabsSkeleton.js +1 -1
- package/dist/Toggle.js +2 -2
- package/dist/assets/quantum-ui.css +296 -392
- package/dist/calendar2.js +1 -1
- package/dist/cells.js +2 -2
- package/dist/collapsible2.js +1 -1
- package/dist/components/FormattedDate.js +2 -2
- package/dist/components/RichTextEditor.js +1 -1
- package/dist/components/Select.js +4 -4
- package/dist/components/TreeView.js +7 -7
- package/dist/dropdown-menu.js +9 -9
- package/dist/field.js +1 -1
- package/dist/image-component.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index10.js +1499 -102
- package/dist/index10.js.map +1 -1
- package/dist/index11.js +37 -1499
- package/dist/index11.js.map +1 -1
- package/dist/index12.js +476 -29
- package/dist/index12.js.map +1 -1
- package/dist/index13.js +230 -426
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +1073 -214
- package/dist/index14.js.map +1 -1
- package/dist/index15.js +14 -1139
- package/dist/index15.js.map +1 -1
- package/dist/index16.js +20 -14
- package/dist/index16.js.map +1 -1
- package/dist/index17.js +180 -25
- package/dist/index17.js.map +1 -1
- package/dist/index18.js +201 -173
- package/dist/index18.js.map +1 -1
- package/dist/index19.js +69 -203
- package/dist/index19.js.map +1 -1
- package/dist/index20.js +211 -70
- package/dist/index20.js.map +1 -1
- package/dist/index21.js +117 -207
- package/dist/index21.js.map +1 -1
- package/dist/index22.js +71 -123
- package/dist/index22.js.map +1 -1
- package/dist/index23.js +11 -74
- package/dist/index23.js.map +1 -1
- package/dist/index24.js +1134 -13
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +2733 -1103
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +24 -2755
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +4 -32
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +37 -4
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +310 -36
- package/dist/index29.js.map +1 -1
- package/dist/index30.js +7 -309
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +30 -8
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +59 -29
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +10 -59
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +35 -10
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +36810 -27
- package/dist/index35.js.map +1 -1
- package/dist/index4.js +136 -86
- package/dist/index4.js.map +1 -1
- package/dist/index5.js +315 -36745
- package/dist/index5.js.map +1 -1
- package/dist/index6.js +12 -141
- package/dist/index6.js.map +1 -1
- package/dist/index7.js +82 -382
- package/dist/index7.js.map +1 -1
- package/dist/index8.js +42 -12
- package/dist/index8.js.map +1 -1
- package/dist/index9.js +102 -42
- package/dist/index9.js.map +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/popover.js +1 -1
- package/dist/select2.js +1 -1
- package/dist/separator2.js +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/useTimer.js +1 -1
- package/dist/utils/axios.js +1 -1
- package/dist/utils/currency.js +2 -2
- package/dist/utils/format.js +2 -2
- package/dist/utils/money.js +1 -1
- package/dist/utils/timezone.js +1 -1
- package/package.json +1 -1
package/dist/index14.js
CHANGED
|
@@ -1,291 +1,1150 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { u as
|
|
4
|
-
import { c as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
3
|
+
import { u as useControllableState, P as Primitive, c as composeEventHandlers, b as createSlot } from './index18.js';
|
|
4
|
+
import { u as useDirection, c as createCollection } from './index22.js';
|
|
5
|
+
import { u as useComposedRefs } from './index11.js';
|
|
6
|
+
import { c as createContextScope } from './index19.js';
|
|
7
|
+
import { R as Root2$1, A as Anchor, P as Portal$1, c as createPopperScope, D as DismissableLayer, C as Content, a as Arrow } from './index25.js';
|
|
8
|
+
import { h as hideOthers, u as useFocusGuards, R as ReactRemoveScroll, F as FocusScope } from './Combination.js';
|
|
9
|
+
import { u as useId } from './index23.js';
|
|
10
|
+
import { u as useCallbackRef } from './index30.js';
|
|
11
|
+
import { u as useLayoutEffect2 } from './index27.js';
|
|
12
|
+
import { u as usePrevious } from './index33.js';
|
|
13
|
+
import { V as VISUALLY_HIDDEN_STYLES } from './index26.js';
|
|
14
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
// packages/core/number/src/number.ts
|
|
17
|
+
function clamp(value, [min, max]) {
|
|
18
|
+
return Math.min(max, Math.max(min, value));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var OPEN_KEYS = [" ", "Enter", "ArrowUp", "ArrowDown"];
|
|
22
|
+
var SELECTION_KEYS = [" ", "Enter"];
|
|
23
|
+
var SELECT_NAME = "Select";
|
|
24
|
+
var [Collection, useCollection, createCollectionScope] = createCollection(SELECT_NAME);
|
|
25
|
+
var [createSelectContext] = createContextScope(SELECT_NAME, [
|
|
26
|
+
createCollectionScope,
|
|
13
27
|
createPopperScope
|
|
14
28
|
]);
|
|
15
29
|
var usePopperScope = createPopperScope();
|
|
16
|
-
var [
|
|
17
|
-
var
|
|
30
|
+
var [SelectProvider, useSelectContext] = createSelectContext(SELECT_NAME);
|
|
31
|
+
var [SelectNativeOptionsProvider, useSelectNativeOptionsContext] = createSelectContext(SELECT_NAME);
|
|
32
|
+
var Select = (props) => {
|
|
18
33
|
const {
|
|
19
|
-
|
|
34
|
+
__scopeSelect,
|
|
20
35
|
children,
|
|
21
36
|
open: openProp,
|
|
22
37
|
defaultOpen,
|
|
23
38
|
onOpenChange,
|
|
24
|
-
|
|
39
|
+
value: valueProp,
|
|
40
|
+
defaultValue,
|
|
41
|
+
onValueChange,
|
|
42
|
+
dir,
|
|
43
|
+
name,
|
|
44
|
+
autoComplete,
|
|
45
|
+
disabled,
|
|
46
|
+
required,
|
|
47
|
+
form
|
|
25
48
|
} = props;
|
|
26
|
-
const popperScope = usePopperScope(
|
|
27
|
-
const
|
|
28
|
-
const [
|
|
49
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
50
|
+
const [trigger, setTrigger] = React.useState(null);
|
|
51
|
+
const [valueNode, setValueNode] = React.useState(null);
|
|
52
|
+
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
|
|
53
|
+
const direction = useDirection(dir);
|
|
29
54
|
const [open, setOpen] = useControllableState({
|
|
30
55
|
prop: openProp,
|
|
31
56
|
defaultProp: defaultOpen ?? false,
|
|
32
57
|
onChange: onOpenChange,
|
|
33
|
-
caller:
|
|
58
|
+
caller: SELECT_NAME
|
|
59
|
+
});
|
|
60
|
+
const [value, setValue] = useControllableState({
|
|
61
|
+
prop: valueProp,
|
|
62
|
+
defaultProp: defaultValue,
|
|
63
|
+
onChange: onValueChange,
|
|
64
|
+
caller: SELECT_NAME
|
|
34
65
|
});
|
|
35
|
-
|
|
36
|
-
|
|
66
|
+
const triggerPointerDownPosRef = React.useRef(null);
|
|
67
|
+
const isFormControl = trigger ? form || !!trigger.closest("form") : true;
|
|
68
|
+
const [nativeOptionsSet, setNativeOptionsSet] = React.useState(/* @__PURE__ */ new Set());
|
|
69
|
+
const nativeSelectKey = Array.from(nativeOptionsSet).map((option) => option.props.value).join(";");
|
|
70
|
+
return /* @__PURE__ */ jsx(Root2$1, { ...popperScope, children: /* @__PURE__ */ jsxs(
|
|
71
|
+
SelectProvider,
|
|
37
72
|
{
|
|
38
|
-
|
|
73
|
+
required,
|
|
74
|
+
scope: __scopeSelect,
|
|
75
|
+
trigger,
|
|
76
|
+
onTriggerChange: setTrigger,
|
|
77
|
+
valueNode,
|
|
78
|
+
onValueNodeChange: setValueNode,
|
|
79
|
+
valueNodeHasChildren,
|
|
80
|
+
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
39
81
|
contentId: useId(),
|
|
40
|
-
|
|
82
|
+
value,
|
|
83
|
+
onValueChange: setValue,
|
|
41
84
|
open,
|
|
42
85
|
onOpenChange: setOpen,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
86
|
+
dir: direction,
|
|
87
|
+
triggerPointerDownPosRef,
|
|
88
|
+
disabled,
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ jsx(Collection.Provider, { scope: __scopeSelect, children: /* @__PURE__ */ jsx(
|
|
91
|
+
SelectNativeOptionsProvider,
|
|
92
|
+
{
|
|
93
|
+
scope: props.__scopeSelect,
|
|
94
|
+
onNativeOptionAdd: React.useCallback((option) => {
|
|
95
|
+
setNativeOptionsSet((prev) => new Set(prev).add(option));
|
|
96
|
+
}, []),
|
|
97
|
+
onNativeOptionRemove: React.useCallback((option) => {
|
|
98
|
+
setNativeOptionsSet((prev) => {
|
|
99
|
+
const optionsSet = new Set(prev);
|
|
100
|
+
optionsSet.delete(option);
|
|
101
|
+
return optionsSet;
|
|
102
|
+
});
|
|
103
|
+
}, []),
|
|
104
|
+
children
|
|
105
|
+
}
|
|
106
|
+
) }),
|
|
107
|
+
isFormControl ? /* @__PURE__ */ jsxs(
|
|
108
|
+
SelectBubbleInput,
|
|
109
|
+
{
|
|
110
|
+
"aria-hidden": true,
|
|
111
|
+
required,
|
|
112
|
+
tabIndex: -1,
|
|
113
|
+
name,
|
|
114
|
+
autoComplete,
|
|
115
|
+
value,
|
|
116
|
+
onChange: (event) => setValue(event.target.value),
|
|
117
|
+
disabled,
|
|
118
|
+
form,
|
|
119
|
+
children: [
|
|
120
|
+
value === void 0 ? /* @__PURE__ */ jsx("option", { value: "" }) : null,
|
|
121
|
+
Array.from(nativeOptionsSet)
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
nativeSelectKey
|
|
125
|
+
) : null
|
|
126
|
+
]
|
|
49
127
|
}
|
|
50
128
|
) });
|
|
51
129
|
};
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
(props, forwardedRef) => {
|
|
56
|
-
const { __scopePopover, ...anchorProps } = props;
|
|
57
|
-
const context = usePopoverContext(ANCHOR_NAME, __scopePopover);
|
|
58
|
-
const popperScope = usePopperScope(__scopePopover);
|
|
59
|
-
const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
|
|
60
|
-
React.useEffect(() => {
|
|
61
|
-
onCustomAnchorAdd();
|
|
62
|
-
return () => onCustomAnchorRemove();
|
|
63
|
-
}, [onCustomAnchorAdd, onCustomAnchorRemove]);
|
|
64
|
-
return /* @__PURE__ */ jsx(Anchor, { ...popperScope, ...anchorProps, ref: forwardedRef });
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
PopoverAnchor.displayName = ANCHOR_NAME;
|
|
68
|
-
var TRIGGER_NAME = "PopoverTrigger";
|
|
69
|
-
var PopoverTrigger = React.forwardRef(
|
|
130
|
+
Select.displayName = SELECT_NAME;
|
|
131
|
+
var TRIGGER_NAME = "SelectTrigger";
|
|
132
|
+
var SelectTrigger = React.forwardRef(
|
|
70
133
|
(props, forwardedRef) => {
|
|
71
|
-
const {
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
134
|
+
const { __scopeSelect, disabled = false, ...triggerProps } = props;
|
|
135
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
136
|
+
const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
|
|
137
|
+
const isDisabled = context.disabled || disabled;
|
|
138
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onTriggerChange);
|
|
139
|
+
const getItems = useCollection(__scopeSelect);
|
|
140
|
+
const pointerTypeRef = React.useRef("touch");
|
|
141
|
+
const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
|
|
142
|
+
const enabledItems = getItems().filter((item) => !item.disabled);
|
|
143
|
+
const currentItem = enabledItems.find((item) => item.value === context.value);
|
|
144
|
+
const nextItem = findNextItem(enabledItems, search, currentItem);
|
|
145
|
+
if (nextItem !== void 0) {
|
|
146
|
+
context.onValueChange(nextItem.value);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const handleOpen = (pointerEvent) => {
|
|
150
|
+
if (!isDisabled) {
|
|
151
|
+
context.onOpenChange(true);
|
|
152
|
+
resetTypeahead();
|
|
153
|
+
}
|
|
154
|
+
if (pointerEvent) {
|
|
155
|
+
context.triggerPointerDownPosRef.current = {
|
|
156
|
+
x: Math.round(pointerEvent.pageX),
|
|
157
|
+
y: Math.round(pointerEvent.pageY)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return /* @__PURE__ */ jsx(Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ jsx(
|
|
76
162
|
Primitive.button,
|
|
77
163
|
{
|
|
78
164
|
type: "button",
|
|
79
|
-
|
|
80
|
-
"aria-expanded": context.open,
|
|
165
|
+
role: "combobox",
|
|
81
166
|
"aria-controls": context.contentId,
|
|
82
|
-
"
|
|
167
|
+
"aria-expanded": context.open,
|
|
168
|
+
"aria-required": context.required,
|
|
169
|
+
"aria-autocomplete": "none",
|
|
170
|
+
dir: context.dir,
|
|
171
|
+
"data-state": context.open ? "open" : "closed",
|
|
172
|
+
disabled: isDisabled,
|
|
173
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
174
|
+
"data-placeholder": shouldShowPlaceholder(context.value) ? "" : void 0,
|
|
83
175
|
...triggerProps,
|
|
84
|
-
ref: composedTriggerRef,
|
|
85
|
-
onClick: composeEventHandlers(props.onClick, context.onOpenToggle)
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
return context.hasCustomAnchor ? trigger : /* @__PURE__ */ jsx(Anchor, { asChild: true, ...popperScope, children: trigger });
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
PopoverTrigger.displayName = TRIGGER_NAME;
|
|
92
|
-
var PORTAL_NAME = "PopoverPortal";
|
|
93
|
-
var [PortalProvider, usePortalContext] = createPopoverContext(PORTAL_NAME, {
|
|
94
|
-
forceMount: void 0
|
|
95
|
-
});
|
|
96
|
-
var PopoverPortal = (props) => {
|
|
97
|
-
const { __scopePopover, forceMount, children, container } = props;
|
|
98
|
-
const context = usePopoverContext(PORTAL_NAME, __scopePopover);
|
|
99
|
-
return /* @__PURE__ */ jsx(PortalProvider, { scope: __scopePopover, forceMount, children: /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(Portal$1, { asChild: true, container, children }) }) });
|
|
100
|
-
};
|
|
101
|
-
PopoverPortal.displayName = PORTAL_NAME;
|
|
102
|
-
var CONTENT_NAME = "PopoverContent";
|
|
103
|
-
var PopoverContent = React.forwardRef(
|
|
104
|
-
(props, forwardedRef) => {
|
|
105
|
-
const portalContext = usePortalContext(CONTENT_NAME, props.__scopePopover);
|
|
106
|
-
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
107
|
-
const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
|
|
108
|
-
return /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ jsx(PopoverContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(PopoverContentNonModal, { ...contentProps, ref: forwardedRef }) });
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
PopoverContent.displayName = CONTENT_NAME;
|
|
112
|
-
var Slot = createSlot("PopoverContent.RemoveScroll");
|
|
113
|
-
var PopoverContentModal = React.forwardRef(
|
|
114
|
-
(props, forwardedRef) => {
|
|
115
|
-
const context = usePopoverContext(CONTENT_NAME, props.__scopePopover);
|
|
116
|
-
const contentRef = React.useRef(null);
|
|
117
|
-
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
118
|
-
const isRightClickOutsideRef = React.useRef(false);
|
|
119
|
-
React.useEffect(() => {
|
|
120
|
-
const content = contentRef.current;
|
|
121
|
-
if (content) return hideOthers(content);
|
|
122
|
-
}, []);
|
|
123
|
-
return /* @__PURE__ */ jsx(ReactRemoveScroll, { as: Slot, allowPinchZoom: true, children: /* @__PURE__ */ jsx(
|
|
124
|
-
PopoverContentImpl,
|
|
125
|
-
{
|
|
126
|
-
...props,
|
|
127
176
|
ref: composedRefs,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
177
|
+
onClick: composeEventHandlers(triggerProps.onClick, (event) => {
|
|
178
|
+
event.currentTarget.focus();
|
|
179
|
+
if (pointerTypeRef.current !== "mouse") {
|
|
180
|
+
handleOpen(event);
|
|
181
|
+
}
|
|
133
182
|
}),
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
183
|
+
onPointerDown: composeEventHandlers(triggerProps.onPointerDown, (event) => {
|
|
184
|
+
pointerTypeRef.current = event.pointerType;
|
|
185
|
+
const target = event.target;
|
|
186
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
187
|
+
target.releasePointerCapture(event.pointerId);
|
|
188
|
+
}
|
|
189
|
+
if (event.button === 0 && event.ctrlKey === false && event.pointerType === "mouse") {
|
|
190
|
+
handleOpen(event);
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
}
|
|
193
|
+
}),
|
|
194
|
+
onKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {
|
|
195
|
+
const isTypingAhead = searchRef.current !== "";
|
|
196
|
+
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
|
|
197
|
+
if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
|
|
198
|
+
if (isTypingAhead && event.key === " ") return;
|
|
199
|
+
if (OPEN_KEYS.includes(event.key)) {
|
|
200
|
+
handleOpen();
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
}
|
|
203
|
+
})
|
|
149
204
|
}
|
|
150
205
|
) });
|
|
151
206
|
}
|
|
152
207
|
);
|
|
153
|
-
|
|
208
|
+
SelectTrigger.displayName = TRIGGER_NAME;
|
|
209
|
+
var VALUE_NAME = "SelectValue";
|
|
210
|
+
var SelectValue = React.forwardRef(
|
|
154
211
|
(props, forwardedRef) => {
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
212
|
+
const { __scopeSelect, className, style, children, placeholder = "", ...valueProps } = props;
|
|
213
|
+
const context = useSelectContext(VALUE_NAME, __scopeSelect);
|
|
214
|
+
const { onValueNodeHasChildrenChange } = context;
|
|
215
|
+
const hasChildren = children !== void 0;
|
|
216
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
|
|
217
|
+
useLayoutEffect2(() => {
|
|
218
|
+
onValueNodeHasChildrenChange(hasChildren);
|
|
219
|
+
}, [onValueNodeHasChildrenChange, hasChildren]);
|
|
158
220
|
return /* @__PURE__ */ jsx(
|
|
159
|
-
|
|
221
|
+
Primitive.span,
|
|
160
222
|
{
|
|
161
|
-
...
|
|
162
|
-
ref:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
onCloseAutoFocus: (event) => {
|
|
166
|
-
props.onCloseAutoFocus?.(event);
|
|
167
|
-
if (!event.defaultPrevented) {
|
|
168
|
-
if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
|
|
169
|
-
event.preventDefault();
|
|
170
|
-
}
|
|
171
|
-
hasInteractedOutsideRef.current = false;
|
|
172
|
-
hasPointerDownOutsideRef.current = false;
|
|
173
|
-
},
|
|
174
|
-
onInteractOutside: (event) => {
|
|
175
|
-
props.onInteractOutside?.(event);
|
|
176
|
-
if (!event.defaultPrevented) {
|
|
177
|
-
hasInteractedOutsideRef.current = true;
|
|
178
|
-
if (event.detail.originalEvent.type === "pointerdown") {
|
|
179
|
-
hasPointerDownOutsideRef.current = true;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const target = event.target;
|
|
183
|
-
const targetIsTrigger = context.triggerRef.current?.contains(target);
|
|
184
|
-
if (targetIsTrigger) event.preventDefault();
|
|
185
|
-
if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
|
|
186
|
-
event.preventDefault();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
223
|
+
...valueProps,
|
|
224
|
+
ref: composedRefs,
|
|
225
|
+
style: { pointerEvents: "none" },
|
|
226
|
+
children: shouldShowPlaceholder(context.value) ? /* @__PURE__ */ jsx(Fragment, { children: placeholder }) : children
|
|
189
227
|
}
|
|
190
228
|
);
|
|
191
229
|
}
|
|
192
230
|
);
|
|
193
|
-
|
|
231
|
+
SelectValue.displayName = VALUE_NAME;
|
|
232
|
+
var ICON_NAME = "SelectIcon";
|
|
233
|
+
var SelectIcon = React.forwardRef(
|
|
234
|
+
(props, forwardedRef) => {
|
|
235
|
+
const { __scopeSelect, children, ...iconProps } = props;
|
|
236
|
+
return /* @__PURE__ */ jsx(Primitive.span, { "aria-hidden": true, ...iconProps, ref: forwardedRef, children: children || "\u25BC" });
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
SelectIcon.displayName = ICON_NAME;
|
|
240
|
+
var PORTAL_NAME = "SelectPortal";
|
|
241
|
+
var SelectPortal = (props) => {
|
|
242
|
+
return /* @__PURE__ */ jsx(Portal$1, { asChild: true, ...props });
|
|
243
|
+
};
|
|
244
|
+
SelectPortal.displayName = PORTAL_NAME;
|
|
245
|
+
var CONTENT_NAME = "SelectContent";
|
|
246
|
+
var SelectContent = React.forwardRef(
|
|
247
|
+
(props, forwardedRef) => {
|
|
248
|
+
const context = useSelectContext(CONTENT_NAME, props.__scopeSelect);
|
|
249
|
+
const [fragment, setFragment] = React.useState();
|
|
250
|
+
useLayoutEffect2(() => {
|
|
251
|
+
setFragment(new DocumentFragment());
|
|
252
|
+
}, []);
|
|
253
|
+
if (!context.open) {
|
|
254
|
+
const frag = fragment;
|
|
255
|
+
return frag ? ReactDOM.createPortal(
|
|
256
|
+
/* @__PURE__ */ jsx(SelectContentProvider, { scope: props.__scopeSelect, children: /* @__PURE__ */ jsx(Collection.Slot, { scope: props.__scopeSelect, children: /* @__PURE__ */ jsx("div", { children: props.children }) }) }),
|
|
257
|
+
frag
|
|
258
|
+
) : null;
|
|
259
|
+
}
|
|
260
|
+
return /* @__PURE__ */ jsx(SelectContentImpl, { ...props, ref: forwardedRef });
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
SelectContent.displayName = CONTENT_NAME;
|
|
264
|
+
var CONTENT_MARGIN = 10;
|
|
265
|
+
var [SelectContentProvider, useSelectContentContext] = createSelectContext(CONTENT_NAME);
|
|
266
|
+
var CONTENT_IMPL_NAME = "SelectContentImpl";
|
|
267
|
+
var Slot = createSlot("SelectContent.RemoveScroll");
|
|
268
|
+
var SelectContentImpl = React.forwardRef(
|
|
194
269
|
(props, forwardedRef) => {
|
|
195
270
|
const {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
onOpenAutoFocus,
|
|
271
|
+
__scopeSelect,
|
|
272
|
+
position = "item-aligned",
|
|
199
273
|
onCloseAutoFocus,
|
|
200
|
-
disableOutsidePointerEvents,
|
|
201
274
|
onEscapeKeyDown,
|
|
202
275
|
onPointerDownOutside,
|
|
203
|
-
|
|
204
|
-
|
|
276
|
+
//
|
|
277
|
+
// PopperContent props
|
|
278
|
+
side,
|
|
279
|
+
sideOffset,
|
|
280
|
+
align,
|
|
281
|
+
alignOffset,
|
|
282
|
+
arrowPadding,
|
|
283
|
+
collisionBoundary,
|
|
284
|
+
collisionPadding,
|
|
285
|
+
sticky,
|
|
286
|
+
hideWhenDetached,
|
|
287
|
+
avoidCollisions,
|
|
288
|
+
//
|
|
205
289
|
...contentProps
|
|
206
290
|
} = props;
|
|
207
|
-
const context =
|
|
208
|
-
const
|
|
291
|
+
const context = useSelectContext(CONTENT_NAME, __scopeSelect);
|
|
292
|
+
const [content, setContent] = React.useState(null);
|
|
293
|
+
const [viewport, setViewport] = React.useState(null);
|
|
294
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
|
|
295
|
+
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
296
|
+
const [selectedItemText, setSelectedItemText] = React.useState(
|
|
297
|
+
null
|
|
298
|
+
);
|
|
299
|
+
const getItems = useCollection(__scopeSelect);
|
|
300
|
+
const [isPositioned, setIsPositioned] = React.useState(false);
|
|
301
|
+
const firstValidItemFoundRef = React.useRef(false);
|
|
302
|
+
React.useEffect(() => {
|
|
303
|
+
if (content) return hideOthers(content);
|
|
304
|
+
}, [content]);
|
|
209
305
|
useFocusGuards();
|
|
306
|
+
const focusFirst = React.useCallback(
|
|
307
|
+
(candidates) => {
|
|
308
|
+
const [firstItem, ...restItems] = getItems().map((item) => item.ref.current);
|
|
309
|
+
const [lastItem] = restItems.slice(-1);
|
|
310
|
+
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
|
311
|
+
for (const candidate of candidates) {
|
|
312
|
+
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
313
|
+
candidate?.scrollIntoView({ block: "nearest" });
|
|
314
|
+
if (candidate === firstItem && viewport) viewport.scrollTop = 0;
|
|
315
|
+
if (candidate === lastItem && viewport) viewport.scrollTop = viewport.scrollHeight;
|
|
316
|
+
candidate?.focus();
|
|
317
|
+
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
[getItems, viewport]
|
|
321
|
+
);
|
|
322
|
+
const focusSelectedItem = React.useCallback(
|
|
323
|
+
() => focusFirst([selectedItem, content]),
|
|
324
|
+
[focusFirst, selectedItem, content]
|
|
325
|
+
);
|
|
326
|
+
React.useEffect(() => {
|
|
327
|
+
if (isPositioned) {
|
|
328
|
+
focusSelectedItem();
|
|
329
|
+
}
|
|
330
|
+
}, [isPositioned, focusSelectedItem]);
|
|
331
|
+
const { onOpenChange, triggerPointerDownPosRef } = context;
|
|
332
|
+
React.useEffect(() => {
|
|
333
|
+
if (content) {
|
|
334
|
+
let pointerMoveDelta = { x: 0, y: 0 };
|
|
335
|
+
const handlePointerMove = (event) => {
|
|
336
|
+
pointerMoveDelta = {
|
|
337
|
+
x: Math.abs(Math.round(event.pageX) - (triggerPointerDownPosRef.current?.x ?? 0)),
|
|
338
|
+
y: Math.abs(Math.round(event.pageY) - (triggerPointerDownPosRef.current?.y ?? 0))
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
const handlePointerUp = (event) => {
|
|
342
|
+
if (pointerMoveDelta.x <= 10 && pointerMoveDelta.y <= 10) {
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
} else {
|
|
345
|
+
if (!content.contains(event.target)) {
|
|
346
|
+
onOpenChange(false);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
350
|
+
triggerPointerDownPosRef.current = null;
|
|
351
|
+
};
|
|
352
|
+
if (triggerPointerDownPosRef.current !== null) {
|
|
353
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
354
|
+
document.addEventListener("pointerup", handlePointerUp, { capture: true, once: true });
|
|
355
|
+
}
|
|
356
|
+
return () => {
|
|
357
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
358
|
+
document.removeEventListener("pointerup", handlePointerUp, { capture: true });
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}, [content, onOpenChange, triggerPointerDownPosRef]);
|
|
362
|
+
React.useEffect(() => {
|
|
363
|
+
const close = () => onOpenChange(false);
|
|
364
|
+
window.addEventListener("blur", close);
|
|
365
|
+
window.addEventListener("resize", close);
|
|
366
|
+
return () => {
|
|
367
|
+
window.removeEventListener("blur", close);
|
|
368
|
+
window.removeEventListener("resize", close);
|
|
369
|
+
};
|
|
370
|
+
}, [onOpenChange]);
|
|
371
|
+
const [searchRef, handleTypeaheadSearch] = useTypeaheadSearch((search) => {
|
|
372
|
+
const enabledItems = getItems().filter((item) => !item.disabled);
|
|
373
|
+
const currentItem = enabledItems.find((item) => item.ref.current === document.activeElement);
|
|
374
|
+
const nextItem = findNextItem(enabledItems, search, currentItem);
|
|
375
|
+
if (nextItem) {
|
|
376
|
+
setTimeout(() => nextItem.ref.current.focus());
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
const itemRefCallback = React.useCallback(
|
|
380
|
+
(node, value, disabled) => {
|
|
381
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
382
|
+
const isSelectedItem = context.value !== void 0 && context.value === value;
|
|
383
|
+
if (isSelectedItem || isFirstValidItem) {
|
|
384
|
+
setSelectedItem(node);
|
|
385
|
+
if (isFirstValidItem) firstValidItemFoundRef.current = true;
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
[context.value]
|
|
389
|
+
);
|
|
390
|
+
const handleItemLeave = React.useCallback(() => content?.focus(), [content]);
|
|
391
|
+
const itemTextRefCallback = React.useCallback(
|
|
392
|
+
(node, value, disabled) => {
|
|
393
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
394
|
+
const isSelectedItem = context.value !== void 0 && context.value === value;
|
|
395
|
+
if (isSelectedItem || isFirstValidItem) {
|
|
396
|
+
setSelectedItemText(node);
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
[context.value]
|
|
400
|
+
);
|
|
401
|
+
const SelectPosition = position === "popper" ? SelectPopperPosition : SelectItemAlignedPosition;
|
|
402
|
+
const popperContentProps = SelectPosition === SelectPopperPosition ? {
|
|
403
|
+
side,
|
|
404
|
+
sideOffset,
|
|
405
|
+
align,
|
|
406
|
+
alignOffset,
|
|
407
|
+
arrowPadding,
|
|
408
|
+
collisionBoundary,
|
|
409
|
+
collisionPadding,
|
|
410
|
+
sticky,
|
|
411
|
+
hideWhenDetached,
|
|
412
|
+
avoidCollisions
|
|
413
|
+
} : {};
|
|
210
414
|
return /* @__PURE__ */ jsx(
|
|
211
|
-
|
|
415
|
+
SelectContentProvider,
|
|
212
416
|
{
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
417
|
+
scope: __scopeSelect,
|
|
418
|
+
content,
|
|
419
|
+
viewport,
|
|
420
|
+
onViewportChange: setViewport,
|
|
421
|
+
itemRefCallback,
|
|
422
|
+
selectedItem,
|
|
423
|
+
onItemLeave: handleItemLeave,
|
|
424
|
+
itemTextRefCallback,
|
|
425
|
+
focusSelectedItem,
|
|
426
|
+
selectedItemText,
|
|
427
|
+
position,
|
|
428
|
+
isPositioned,
|
|
429
|
+
searchRef,
|
|
430
|
+
children: /* @__PURE__ */ jsx(ReactRemoveScroll, { as: Slot, allowPinchZoom: true, children: /* @__PURE__ */ jsx(
|
|
431
|
+
FocusScope,
|
|
220
432
|
{
|
|
221
433
|
asChild: true,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
434
|
+
trapped: context.open,
|
|
435
|
+
onMountAutoFocus: (event) => {
|
|
436
|
+
event.preventDefault();
|
|
437
|
+
},
|
|
438
|
+
onUnmountAutoFocus: composeEventHandlers(onCloseAutoFocus, (event) => {
|
|
439
|
+
context.trigger?.focus({ preventScroll: true });
|
|
440
|
+
event.preventDefault();
|
|
441
|
+
}),
|
|
228
442
|
children: /* @__PURE__ */ jsx(
|
|
229
|
-
|
|
443
|
+
DismissableLayer,
|
|
230
444
|
{
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
"
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
445
|
+
asChild: true,
|
|
446
|
+
disableOutsidePointerEvents: true,
|
|
447
|
+
onEscapeKeyDown,
|
|
448
|
+
onPointerDownOutside,
|
|
449
|
+
onFocusOutside: (event) => event.preventDefault(),
|
|
450
|
+
onDismiss: () => context.onOpenChange(false),
|
|
451
|
+
children: /* @__PURE__ */ jsx(
|
|
452
|
+
SelectPosition,
|
|
453
|
+
{
|
|
454
|
+
role: "listbox",
|
|
455
|
+
id: context.contentId,
|
|
456
|
+
"data-state": context.open ? "open" : "closed",
|
|
457
|
+
dir: context.dir,
|
|
458
|
+
onContextMenu: (event) => event.preventDefault(),
|
|
459
|
+
...contentProps,
|
|
460
|
+
...popperContentProps,
|
|
461
|
+
onPlaced: () => setIsPositioned(true),
|
|
462
|
+
ref: composedRefs,
|
|
463
|
+
style: {
|
|
464
|
+
// flex layout so we can place the scroll buttons properly
|
|
465
|
+
display: "flex",
|
|
466
|
+
flexDirection: "column",
|
|
467
|
+
// reset the outline by default as the content MAY get focused
|
|
468
|
+
outline: "none",
|
|
469
|
+
...contentProps.style
|
|
470
|
+
},
|
|
471
|
+
onKeyDown: composeEventHandlers(contentProps.onKeyDown, (event) => {
|
|
472
|
+
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
|
|
473
|
+
if (event.key === "Tab") event.preventDefault();
|
|
474
|
+
if (!isModifierKey && event.key.length === 1) handleTypeaheadSearch(event.key);
|
|
475
|
+
if (["ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)) {
|
|
476
|
+
const items = getItems().filter((item) => !item.disabled);
|
|
477
|
+
let candidateNodes = items.map((item) => item.ref.current);
|
|
478
|
+
if (["ArrowUp", "End"].includes(event.key)) {
|
|
479
|
+
candidateNodes = candidateNodes.slice().reverse();
|
|
480
|
+
}
|
|
481
|
+
if (["ArrowUp", "ArrowDown"].includes(event.key)) {
|
|
482
|
+
const currentElement = event.target;
|
|
483
|
+
const currentIndex = candidateNodes.indexOf(currentElement);
|
|
484
|
+
candidateNodes = candidateNodes.slice(currentIndex + 1);
|
|
485
|
+
}
|
|
486
|
+
setTimeout(() => focusFirst(candidateNodes));
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
}
|
|
489
|
+
})
|
|
246
490
|
}
|
|
247
|
-
|
|
491
|
+
)
|
|
248
492
|
}
|
|
249
493
|
)
|
|
250
494
|
}
|
|
251
|
-
)
|
|
495
|
+
) })
|
|
252
496
|
}
|
|
253
497
|
);
|
|
254
498
|
}
|
|
255
499
|
);
|
|
256
|
-
|
|
257
|
-
var
|
|
500
|
+
SelectContentImpl.displayName = CONTENT_IMPL_NAME;
|
|
501
|
+
var ITEM_ALIGNED_POSITION_NAME = "SelectItemAlignedPosition";
|
|
502
|
+
var SelectItemAlignedPosition = React.forwardRef((props, forwardedRef) => {
|
|
503
|
+
const { __scopeSelect, onPlaced, ...popperProps } = props;
|
|
504
|
+
const context = useSelectContext(CONTENT_NAME, __scopeSelect);
|
|
505
|
+
const contentContext = useSelectContentContext(CONTENT_NAME, __scopeSelect);
|
|
506
|
+
const [contentWrapper, setContentWrapper] = React.useState(null);
|
|
507
|
+
const [content, setContent] = React.useState(null);
|
|
508
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
|
|
509
|
+
const getItems = useCollection(__scopeSelect);
|
|
510
|
+
const shouldExpandOnScrollRef = React.useRef(false);
|
|
511
|
+
const shouldRepositionRef = React.useRef(true);
|
|
512
|
+
const { viewport, selectedItem, selectedItemText, focusSelectedItem } = contentContext;
|
|
513
|
+
const position = React.useCallback(() => {
|
|
514
|
+
if (context.trigger && context.valueNode && contentWrapper && content && viewport && selectedItem && selectedItemText) {
|
|
515
|
+
const triggerRect = context.trigger.getBoundingClientRect();
|
|
516
|
+
const contentRect = content.getBoundingClientRect();
|
|
517
|
+
const valueNodeRect = context.valueNode.getBoundingClientRect();
|
|
518
|
+
const itemTextRect = selectedItemText.getBoundingClientRect();
|
|
519
|
+
if (context.dir !== "rtl") {
|
|
520
|
+
const itemTextOffset = itemTextRect.left - contentRect.left;
|
|
521
|
+
const left = valueNodeRect.left - itemTextOffset;
|
|
522
|
+
const leftDelta = triggerRect.left - left;
|
|
523
|
+
const minContentWidth = triggerRect.width + leftDelta;
|
|
524
|
+
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
525
|
+
const rightEdge = window.innerWidth - CONTENT_MARGIN;
|
|
526
|
+
const clampedLeft = clamp(left, [
|
|
527
|
+
CONTENT_MARGIN,
|
|
528
|
+
// Prevents the content from going off the starting edge of the
|
|
529
|
+
// viewport. It may still go off the ending edge, but this can be
|
|
530
|
+
// controlled by the user since they may want to manage overflow in a
|
|
531
|
+
// specific way.
|
|
532
|
+
// https://github.com/radix-ui/primitives/issues/2049
|
|
533
|
+
Math.max(CONTENT_MARGIN, rightEdge - contentWidth)
|
|
534
|
+
]);
|
|
535
|
+
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
536
|
+
contentWrapper.style.left = clampedLeft + "px";
|
|
537
|
+
} else {
|
|
538
|
+
const itemTextOffset = contentRect.right - itemTextRect.right;
|
|
539
|
+
const right = window.innerWidth - valueNodeRect.right - itemTextOffset;
|
|
540
|
+
const rightDelta = window.innerWidth - triggerRect.right - right;
|
|
541
|
+
const minContentWidth = triggerRect.width + rightDelta;
|
|
542
|
+
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
543
|
+
const leftEdge = window.innerWidth - CONTENT_MARGIN;
|
|
544
|
+
const clampedRight = clamp(right, [
|
|
545
|
+
CONTENT_MARGIN,
|
|
546
|
+
Math.max(CONTENT_MARGIN, leftEdge - contentWidth)
|
|
547
|
+
]);
|
|
548
|
+
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
549
|
+
contentWrapper.style.right = clampedRight + "px";
|
|
550
|
+
}
|
|
551
|
+
const items = getItems();
|
|
552
|
+
const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
|
|
553
|
+
const itemsHeight = viewport.scrollHeight;
|
|
554
|
+
const contentStyles = window.getComputedStyle(content);
|
|
555
|
+
const contentBorderTopWidth = parseInt(contentStyles.borderTopWidth, 10);
|
|
556
|
+
const contentPaddingTop = parseInt(contentStyles.paddingTop, 10);
|
|
557
|
+
const contentBorderBottomWidth = parseInt(contentStyles.borderBottomWidth, 10);
|
|
558
|
+
const contentPaddingBottom = parseInt(contentStyles.paddingBottom, 10);
|
|
559
|
+
const fullContentHeight = contentBorderTopWidth + contentPaddingTop + itemsHeight + contentPaddingBottom + contentBorderBottomWidth;
|
|
560
|
+
const minContentHeight = Math.min(selectedItem.offsetHeight * 5, fullContentHeight);
|
|
561
|
+
const viewportStyles = window.getComputedStyle(viewport);
|
|
562
|
+
const viewportPaddingTop = parseInt(viewportStyles.paddingTop, 10);
|
|
563
|
+
const viewportPaddingBottom = parseInt(viewportStyles.paddingBottom, 10);
|
|
564
|
+
const topEdgeToTriggerMiddle = triggerRect.top + triggerRect.height / 2 - CONTENT_MARGIN;
|
|
565
|
+
const triggerMiddleToBottomEdge = availableHeight - topEdgeToTriggerMiddle;
|
|
566
|
+
const selectedItemHalfHeight = selectedItem.offsetHeight / 2;
|
|
567
|
+
const itemOffsetMiddle = selectedItem.offsetTop + selectedItemHalfHeight;
|
|
568
|
+
const contentTopToItemMiddle = contentBorderTopWidth + contentPaddingTop + itemOffsetMiddle;
|
|
569
|
+
const itemMiddleToContentBottom = fullContentHeight - contentTopToItemMiddle;
|
|
570
|
+
const willAlignWithoutTopOverflow = contentTopToItemMiddle <= topEdgeToTriggerMiddle;
|
|
571
|
+
if (willAlignWithoutTopOverflow) {
|
|
572
|
+
const isLastItem = items.length > 0 && selectedItem === items[items.length - 1].ref.current;
|
|
573
|
+
contentWrapper.style.bottom = "0px";
|
|
574
|
+
const viewportOffsetBottom = content.clientHeight - viewport.offsetTop - viewport.offsetHeight;
|
|
575
|
+
const clampedTriggerMiddleToBottomEdge = Math.max(
|
|
576
|
+
triggerMiddleToBottomEdge,
|
|
577
|
+
selectedItemHalfHeight + // viewport might have padding bottom, include it to avoid a scrollable viewport
|
|
578
|
+
(isLastItem ? viewportPaddingBottom : 0) + viewportOffsetBottom + contentBorderBottomWidth
|
|
579
|
+
);
|
|
580
|
+
const height = contentTopToItemMiddle + clampedTriggerMiddleToBottomEdge;
|
|
581
|
+
contentWrapper.style.height = height + "px";
|
|
582
|
+
} else {
|
|
583
|
+
const isFirstItem = items.length > 0 && selectedItem === items[0].ref.current;
|
|
584
|
+
contentWrapper.style.top = "0px";
|
|
585
|
+
const clampedTopEdgeToTriggerMiddle = Math.max(
|
|
586
|
+
topEdgeToTriggerMiddle,
|
|
587
|
+
contentBorderTopWidth + viewport.offsetTop + // viewport might have padding top, include it to avoid a scrollable viewport
|
|
588
|
+
(isFirstItem ? viewportPaddingTop : 0) + selectedItemHalfHeight
|
|
589
|
+
);
|
|
590
|
+
const height = clampedTopEdgeToTriggerMiddle + itemMiddleToContentBottom;
|
|
591
|
+
contentWrapper.style.height = height + "px";
|
|
592
|
+
viewport.scrollTop = contentTopToItemMiddle - topEdgeToTriggerMiddle + viewport.offsetTop;
|
|
593
|
+
}
|
|
594
|
+
contentWrapper.style.margin = `${CONTENT_MARGIN}px 0`;
|
|
595
|
+
contentWrapper.style.minHeight = minContentHeight + "px";
|
|
596
|
+
contentWrapper.style.maxHeight = availableHeight + "px";
|
|
597
|
+
onPlaced?.();
|
|
598
|
+
requestAnimationFrame(() => shouldExpandOnScrollRef.current = true);
|
|
599
|
+
}
|
|
600
|
+
}, [
|
|
601
|
+
getItems,
|
|
602
|
+
context.trigger,
|
|
603
|
+
context.valueNode,
|
|
604
|
+
contentWrapper,
|
|
605
|
+
content,
|
|
606
|
+
viewport,
|
|
607
|
+
selectedItem,
|
|
608
|
+
selectedItemText,
|
|
609
|
+
context.dir,
|
|
610
|
+
onPlaced
|
|
611
|
+
]);
|
|
612
|
+
useLayoutEffect2(() => position(), [position]);
|
|
613
|
+
const [contentZIndex, setContentZIndex] = React.useState();
|
|
614
|
+
useLayoutEffect2(() => {
|
|
615
|
+
if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
|
|
616
|
+
}, [content]);
|
|
617
|
+
const handleScrollButtonChange = React.useCallback(
|
|
618
|
+
(node) => {
|
|
619
|
+
if (node && shouldRepositionRef.current === true) {
|
|
620
|
+
position();
|
|
621
|
+
focusSelectedItem?.();
|
|
622
|
+
shouldRepositionRef.current = false;
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
[position, focusSelectedItem]
|
|
626
|
+
);
|
|
627
|
+
return /* @__PURE__ */ jsx(
|
|
628
|
+
SelectViewportProvider,
|
|
629
|
+
{
|
|
630
|
+
scope: __scopeSelect,
|
|
631
|
+
contentWrapper,
|
|
632
|
+
shouldExpandOnScrollRef,
|
|
633
|
+
onScrollButtonChange: handleScrollButtonChange,
|
|
634
|
+
children: /* @__PURE__ */ jsx(
|
|
635
|
+
"div",
|
|
636
|
+
{
|
|
637
|
+
ref: setContentWrapper,
|
|
638
|
+
style: {
|
|
639
|
+
display: "flex",
|
|
640
|
+
flexDirection: "column",
|
|
641
|
+
position: "fixed",
|
|
642
|
+
zIndex: contentZIndex
|
|
643
|
+
},
|
|
644
|
+
children: /* @__PURE__ */ jsx(
|
|
645
|
+
Primitive.div,
|
|
646
|
+
{
|
|
647
|
+
...popperProps,
|
|
648
|
+
ref: composedRefs,
|
|
649
|
+
style: {
|
|
650
|
+
// When we get the height of the content, it includes borders. If we were to set
|
|
651
|
+
// the height without having `boxSizing: 'border-box'` it would be too big.
|
|
652
|
+
boxSizing: "border-box",
|
|
653
|
+
// We need to ensure the content doesn't get taller than the wrapper
|
|
654
|
+
maxHeight: "100%",
|
|
655
|
+
...popperProps.style
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
)
|
|
659
|
+
}
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
);
|
|
663
|
+
});
|
|
664
|
+
SelectItemAlignedPosition.displayName = ITEM_ALIGNED_POSITION_NAME;
|
|
665
|
+
var POPPER_POSITION_NAME = "SelectPopperPosition";
|
|
666
|
+
var SelectPopperPosition = React.forwardRef((props, forwardedRef) => {
|
|
667
|
+
const {
|
|
668
|
+
__scopeSelect,
|
|
669
|
+
align = "start",
|
|
670
|
+
collisionPadding = CONTENT_MARGIN,
|
|
671
|
+
...popperProps
|
|
672
|
+
} = props;
|
|
673
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
674
|
+
return /* @__PURE__ */ jsx(
|
|
675
|
+
Content,
|
|
676
|
+
{
|
|
677
|
+
...popperScope,
|
|
678
|
+
...popperProps,
|
|
679
|
+
ref: forwardedRef,
|
|
680
|
+
align,
|
|
681
|
+
collisionPadding,
|
|
682
|
+
style: {
|
|
683
|
+
// Ensure border-box for floating-ui calculations
|
|
684
|
+
boxSizing: "border-box",
|
|
685
|
+
...popperProps.style,
|
|
686
|
+
// re-namespace exposed content custom properties
|
|
687
|
+
...{
|
|
688
|
+
"--radix-select-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
689
|
+
"--radix-select-content-available-width": "var(--radix-popper-available-width)",
|
|
690
|
+
"--radix-select-content-available-height": "var(--radix-popper-available-height)",
|
|
691
|
+
"--radix-select-trigger-width": "var(--radix-popper-anchor-width)",
|
|
692
|
+
"--radix-select-trigger-height": "var(--radix-popper-anchor-height)"
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
});
|
|
698
|
+
SelectPopperPosition.displayName = POPPER_POSITION_NAME;
|
|
699
|
+
var [SelectViewportProvider, useSelectViewportContext] = createSelectContext(CONTENT_NAME, {});
|
|
700
|
+
var VIEWPORT_NAME = "SelectViewport";
|
|
701
|
+
var SelectViewport = React.forwardRef(
|
|
702
|
+
(props, forwardedRef) => {
|
|
703
|
+
const { __scopeSelect, nonce, ...viewportProps } = props;
|
|
704
|
+
const contentContext = useSelectContentContext(VIEWPORT_NAME, __scopeSelect);
|
|
705
|
+
const viewportContext = useSelectViewportContext(VIEWPORT_NAME, __scopeSelect);
|
|
706
|
+
const composedRefs = useComposedRefs(forwardedRef, contentContext.onViewportChange);
|
|
707
|
+
const prevScrollTopRef = React.useRef(0);
|
|
708
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
709
|
+
/* @__PURE__ */ jsx(
|
|
710
|
+
"style",
|
|
711
|
+
{
|
|
712
|
+
dangerouslySetInnerHTML: {
|
|
713
|
+
__html: `[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`
|
|
714
|
+
},
|
|
715
|
+
nonce
|
|
716
|
+
}
|
|
717
|
+
),
|
|
718
|
+
/* @__PURE__ */ jsx(Collection.Slot, { scope: __scopeSelect, children: /* @__PURE__ */ jsx(
|
|
719
|
+
Primitive.div,
|
|
720
|
+
{
|
|
721
|
+
"data-radix-select-viewport": "",
|
|
722
|
+
role: "presentation",
|
|
723
|
+
...viewportProps,
|
|
724
|
+
ref: composedRefs,
|
|
725
|
+
style: {
|
|
726
|
+
// we use position: 'relative' here on the `viewport` so that when we call
|
|
727
|
+
// `selectedItem.offsetTop` in calculations, the offset is relative to the viewport
|
|
728
|
+
// (independent of the scrollUpButton).
|
|
729
|
+
position: "relative",
|
|
730
|
+
flex: 1,
|
|
731
|
+
// Viewport should only be scrollable in the vertical direction.
|
|
732
|
+
// This won't work in vertical writing modes, so we'll need to
|
|
733
|
+
// revisit this if/when that is supported
|
|
734
|
+
// https://developer.chrome.com/blog/vertical-form-controls
|
|
735
|
+
overflow: "hidden auto",
|
|
736
|
+
...viewportProps.style
|
|
737
|
+
},
|
|
738
|
+
onScroll: composeEventHandlers(viewportProps.onScroll, (event) => {
|
|
739
|
+
const viewport = event.currentTarget;
|
|
740
|
+
const { contentWrapper, shouldExpandOnScrollRef } = viewportContext;
|
|
741
|
+
if (shouldExpandOnScrollRef?.current && contentWrapper) {
|
|
742
|
+
const scrolledBy = Math.abs(prevScrollTopRef.current - viewport.scrollTop);
|
|
743
|
+
if (scrolledBy > 0) {
|
|
744
|
+
const availableHeight = window.innerHeight - CONTENT_MARGIN * 2;
|
|
745
|
+
const cssMinHeight = parseFloat(contentWrapper.style.minHeight);
|
|
746
|
+
const cssHeight = parseFloat(contentWrapper.style.height);
|
|
747
|
+
const prevHeight = Math.max(cssMinHeight, cssHeight);
|
|
748
|
+
if (prevHeight < availableHeight) {
|
|
749
|
+
const nextHeight = prevHeight + scrolledBy;
|
|
750
|
+
const clampedNextHeight = Math.min(availableHeight, nextHeight);
|
|
751
|
+
const heightDiff = nextHeight - clampedNextHeight;
|
|
752
|
+
contentWrapper.style.height = clampedNextHeight + "px";
|
|
753
|
+
if (contentWrapper.style.bottom === "0px") {
|
|
754
|
+
viewport.scrollTop = heightDiff > 0 ? heightDiff : 0;
|
|
755
|
+
contentWrapper.style.justifyContent = "flex-end";
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
prevScrollTopRef.current = viewport.scrollTop;
|
|
761
|
+
})
|
|
762
|
+
}
|
|
763
|
+
) })
|
|
764
|
+
] });
|
|
765
|
+
}
|
|
766
|
+
);
|
|
767
|
+
SelectViewport.displayName = VIEWPORT_NAME;
|
|
768
|
+
var GROUP_NAME = "SelectGroup";
|
|
769
|
+
var [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
|
|
770
|
+
var SelectGroup = React.forwardRef(
|
|
771
|
+
(props, forwardedRef) => {
|
|
772
|
+
const { __scopeSelect, ...groupProps } = props;
|
|
773
|
+
const groupId = useId();
|
|
774
|
+
return /* @__PURE__ */ jsx(SelectGroupContextProvider, { scope: __scopeSelect, id: groupId, children: /* @__PURE__ */ jsx(Primitive.div, { role: "group", "aria-labelledby": groupId, ...groupProps, ref: forwardedRef }) });
|
|
775
|
+
}
|
|
776
|
+
);
|
|
777
|
+
SelectGroup.displayName = GROUP_NAME;
|
|
778
|
+
var LABEL_NAME = "SelectLabel";
|
|
779
|
+
var SelectLabel = React.forwardRef(
|
|
258
780
|
(props, forwardedRef) => {
|
|
259
|
-
const {
|
|
260
|
-
const
|
|
781
|
+
const { __scopeSelect, ...labelProps } = props;
|
|
782
|
+
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
783
|
+
return /* @__PURE__ */ jsx(Primitive.div, { id: groupContext.id, ...labelProps, ref: forwardedRef });
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
SelectLabel.displayName = LABEL_NAME;
|
|
787
|
+
var ITEM_NAME = "SelectItem";
|
|
788
|
+
var [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
|
|
789
|
+
var SelectItem = React.forwardRef(
|
|
790
|
+
(props, forwardedRef) => {
|
|
791
|
+
const {
|
|
792
|
+
__scopeSelect,
|
|
793
|
+
value,
|
|
794
|
+
disabled = false,
|
|
795
|
+
textValue: textValueProp,
|
|
796
|
+
...itemProps
|
|
797
|
+
} = props;
|
|
798
|
+
const context = useSelectContext(ITEM_NAME, __scopeSelect);
|
|
799
|
+
const contentContext = useSelectContentContext(ITEM_NAME, __scopeSelect);
|
|
800
|
+
const isSelected = context.value === value;
|
|
801
|
+
const [textValue, setTextValue] = React.useState(textValueProp ?? "");
|
|
802
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
803
|
+
const composedRefs = useComposedRefs(
|
|
804
|
+
forwardedRef,
|
|
805
|
+
(node) => contentContext.itemRefCallback?.(node, value, disabled)
|
|
806
|
+
);
|
|
807
|
+
const textId = useId();
|
|
808
|
+
const pointerTypeRef = React.useRef("touch");
|
|
809
|
+
const handleSelect = () => {
|
|
810
|
+
if (!disabled) {
|
|
811
|
+
context.onValueChange(value);
|
|
812
|
+
context.onOpenChange(false);
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
if (value === "") {
|
|
816
|
+
throw new Error(
|
|
817
|
+
"A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder."
|
|
818
|
+
);
|
|
819
|
+
}
|
|
261
820
|
return /* @__PURE__ */ jsx(
|
|
262
|
-
|
|
821
|
+
SelectItemContextProvider,
|
|
263
822
|
{
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
823
|
+
scope: __scopeSelect,
|
|
824
|
+
value,
|
|
825
|
+
disabled,
|
|
826
|
+
textId,
|
|
827
|
+
isSelected,
|
|
828
|
+
onItemTextChange: React.useCallback((node) => {
|
|
829
|
+
setTextValue((prevTextValue) => prevTextValue || (node?.textContent ?? "").trim());
|
|
830
|
+
}, []),
|
|
831
|
+
children: /* @__PURE__ */ jsx(
|
|
832
|
+
Collection.ItemSlot,
|
|
833
|
+
{
|
|
834
|
+
scope: __scopeSelect,
|
|
835
|
+
value,
|
|
836
|
+
disabled,
|
|
837
|
+
textValue,
|
|
838
|
+
children: /* @__PURE__ */ jsx(
|
|
839
|
+
Primitive.div,
|
|
840
|
+
{
|
|
841
|
+
role: "option",
|
|
842
|
+
"aria-labelledby": textId,
|
|
843
|
+
"data-highlighted": isFocused ? "" : void 0,
|
|
844
|
+
"aria-selected": isSelected && isFocused,
|
|
845
|
+
"data-state": isSelected ? "checked" : "unchecked",
|
|
846
|
+
"aria-disabled": disabled || void 0,
|
|
847
|
+
"data-disabled": disabled ? "" : void 0,
|
|
848
|
+
tabIndex: disabled ? void 0 : -1,
|
|
849
|
+
...itemProps,
|
|
850
|
+
ref: composedRefs,
|
|
851
|
+
onFocus: composeEventHandlers(itemProps.onFocus, () => setIsFocused(true)),
|
|
852
|
+
onBlur: composeEventHandlers(itemProps.onBlur, () => setIsFocused(false)),
|
|
853
|
+
onClick: composeEventHandlers(itemProps.onClick, () => {
|
|
854
|
+
if (pointerTypeRef.current !== "mouse") handleSelect();
|
|
855
|
+
}),
|
|
856
|
+
onPointerUp: composeEventHandlers(itemProps.onPointerUp, () => {
|
|
857
|
+
if (pointerTypeRef.current === "mouse") handleSelect();
|
|
858
|
+
}),
|
|
859
|
+
onPointerDown: composeEventHandlers(itemProps.onPointerDown, (event) => {
|
|
860
|
+
pointerTypeRef.current = event.pointerType;
|
|
861
|
+
}),
|
|
862
|
+
onPointerMove: composeEventHandlers(itemProps.onPointerMove, (event) => {
|
|
863
|
+
pointerTypeRef.current = event.pointerType;
|
|
864
|
+
if (disabled) {
|
|
865
|
+
contentContext.onItemLeave?.();
|
|
866
|
+
} else if (pointerTypeRef.current === "mouse") {
|
|
867
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
868
|
+
}
|
|
869
|
+
}),
|
|
870
|
+
onPointerLeave: composeEventHandlers(itemProps.onPointerLeave, (event) => {
|
|
871
|
+
if (event.currentTarget === document.activeElement) {
|
|
872
|
+
contentContext.onItemLeave?.();
|
|
873
|
+
}
|
|
874
|
+
}),
|
|
875
|
+
onKeyDown: composeEventHandlers(itemProps.onKeyDown, (event) => {
|
|
876
|
+
const isTypingAhead = contentContext.searchRef?.current !== "";
|
|
877
|
+
if (isTypingAhead && event.key === " ") return;
|
|
878
|
+
if (SELECTION_KEYS.includes(event.key)) handleSelect();
|
|
879
|
+
if (event.key === " ") event.preventDefault();
|
|
880
|
+
})
|
|
881
|
+
}
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
)
|
|
268
885
|
}
|
|
269
886
|
);
|
|
270
887
|
}
|
|
271
888
|
);
|
|
272
|
-
|
|
273
|
-
var
|
|
274
|
-
var
|
|
889
|
+
SelectItem.displayName = ITEM_NAME;
|
|
890
|
+
var ITEM_TEXT_NAME = "SelectItemText";
|
|
891
|
+
var SelectItemText = React.forwardRef(
|
|
892
|
+
(props, forwardedRef) => {
|
|
893
|
+
const { __scopeSelect, className, style, ...itemTextProps } = props;
|
|
894
|
+
const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
895
|
+
const contentContext = useSelectContentContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
896
|
+
const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
897
|
+
const nativeOptionsContext = useSelectNativeOptionsContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
898
|
+
const [itemTextNode, setItemTextNode] = React.useState(null);
|
|
899
|
+
const composedRefs = useComposedRefs(
|
|
900
|
+
forwardedRef,
|
|
901
|
+
(node) => setItemTextNode(node),
|
|
902
|
+
itemContext.onItemTextChange,
|
|
903
|
+
(node) => contentContext.itemTextRefCallback?.(node, itemContext.value, itemContext.disabled)
|
|
904
|
+
);
|
|
905
|
+
const textContent = itemTextNode?.textContent;
|
|
906
|
+
const nativeOption = React.useMemo(
|
|
907
|
+
() => /* @__PURE__ */ jsx("option", { value: itemContext.value, disabled: itemContext.disabled, children: textContent }, itemContext.value),
|
|
908
|
+
[itemContext.disabled, itemContext.value, textContent]
|
|
909
|
+
);
|
|
910
|
+
const { onNativeOptionAdd, onNativeOptionRemove } = nativeOptionsContext;
|
|
911
|
+
useLayoutEffect2(() => {
|
|
912
|
+
onNativeOptionAdd(nativeOption);
|
|
913
|
+
return () => onNativeOptionRemove(nativeOption);
|
|
914
|
+
}, [onNativeOptionAdd, onNativeOptionRemove, nativeOption]);
|
|
915
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
916
|
+
/* @__PURE__ */ jsx(Primitive.span, { id: itemContext.textId, ...itemTextProps, ref: composedRefs }),
|
|
917
|
+
itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? ReactDOM.createPortal(itemTextProps.children, context.valueNode) : null
|
|
918
|
+
] });
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
SelectItemText.displayName = ITEM_TEXT_NAME;
|
|
922
|
+
var ITEM_INDICATOR_NAME = "SelectItemIndicator";
|
|
923
|
+
var SelectItemIndicator = React.forwardRef(
|
|
924
|
+
(props, forwardedRef) => {
|
|
925
|
+
const { __scopeSelect, ...itemIndicatorProps } = props;
|
|
926
|
+
const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
|
|
927
|
+
return itemContext.isSelected ? /* @__PURE__ */ jsx(Primitive.span, { "aria-hidden": true, ...itemIndicatorProps, ref: forwardedRef }) : null;
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
|
|
931
|
+
var SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton";
|
|
932
|
+
var SelectScrollUpButton = React.forwardRef((props, forwardedRef) => {
|
|
933
|
+
const contentContext = useSelectContentContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
|
|
934
|
+
const viewportContext = useSelectViewportContext(SCROLL_UP_BUTTON_NAME, props.__scopeSelect);
|
|
935
|
+
const [canScrollUp, setCanScrollUp] = React.useState(false);
|
|
936
|
+
const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
|
|
937
|
+
useLayoutEffect2(() => {
|
|
938
|
+
if (contentContext.viewport && contentContext.isPositioned) {
|
|
939
|
+
let handleScroll2 = function() {
|
|
940
|
+
const canScrollUp2 = viewport.scrollTop > 0;
|
|
941
|
+
setCanScrollUp(canScrollUp2);
|
|
942
|
+
};
|
|
943
|
+
const viewport = contentContext.viewport;
|
|
944
|
+
handleScroll2();
|
|
945
|
+
viewport.addEventListener("scroll", handleScroll2);
|
|
946
|
+
return () => viewport.removeEventListener("scroll", handleScroll2);
|
|
947
|
+
}
|
|
948
|
+
}, [contentContext.viewport, contentContext.isPositioned]);
|
|
949
|
+
return canScrollUp ? /* @__PURE__ */ jsx(
|
|
950
|
+
SelectScrollButtonImpl,
|
|
951
|
+
{
|
|
952
|
+
...props,
|
|
953
|
+
ref: composedRefs,
|
|
954
|
+
onAutoScroll: () => {
|
|
955
|
+
const { viewport, selectedItem } = contentContext;
|
|
956
|
+
if (viewport && selectedItem) {
|
|
957
|
+
viewport.scrollTop = viewport.scrollTop - selectedItem.offsetHeight;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
) : null;
|
|
962
|
+
});
|
|
963
|
+
SelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;
|
|
964
|
+
var SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton";
|
|
965
|
+
var SelectScrollDownButton = React.forwardRef((props, forwardedRef) => {
|
|
966
|
+
const contentContext = useSelectContentContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
|
|
967
|
+
const viewportContext = useSelectViewportContext(SCROLL_DOWN_BUTTON_NAME, props.__scopeSelect);
|
|
968
|
+
const [canScrollDown, setCanScrollDown] = React.useState(false);
|
|
969
|
+
const composedRefs = useComposedRefs(forwardedRef, viewportContext.onScrollButtonChange);
|
|
970
|
+
useLayoutEffect2(() => {
|
|
971
|
+
if (contentContext.viewport && contentContext.isPositioned) {
|
|
972
|
+
let handleScroll2 = function() {
|
|
973
|
+
const maxScroll = viewport.scrollHeight - viewport.clientHeight;
|
|
974
|
+
const canScrollDown2 = Math.ceil(viewport.scrollTop) < maxScroll;
|
|
975
|
+
setCanScrollDown(canScrollDown2);
|
|
976
|
+
};
|
|
977
|
+
const viewport = contentContext.viewport;
|
|
978
|
+
handleScroll2();
|
|
979
|
+
viewport.addEventListener("scroll", handleScroll2);
|
|
980
|
+
return () => viewport.removeEventListener("scroll", handleScroll2);
|
|
981
|
+
}
|
|
982
|
+
}, [contentContext.viewport, contentContext.isPositioned]);
|
|
983
|
+
return canScrollDown ? /* @__PURE__ */ jsx(
|
|
984
|
+
SelectScrollButtonImpl,
|
|
985
|
+
{
|
|
986
|
+
...props,
|
|
987
|
+
ref: composedRefs,
|
|
988
|
+
onAutoScroll: () => {
|
|
989
|
+
const { viewport, selectedItem } = contentContext;
|
|
990
|
+
if (viewport && selectedItem) {
|
|
991
|
+
viewport.scrollTop = viewport.scrollTop + selectedItem.offsetHeight;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
) : null;
|
|
996
|
+
});
|
|
997
|
+
SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
|
|
998
|
+
var SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
|
|
999
|
+
const { __scopeSelect, onAutoScroll, ...scrollIndicatorProps } = props;
|
|
1000
|
+
const contentContext = useSelectContentContext("SelectScrollButton", __scopeSelect);
|
|
1001
|
+
const autoScrollTimerRef = React.useRef(null);
|
|
1002
|
+
const getItems = useCollection(__scopeSelect);
|
|
1003
|
+
const clearAutoScrollTimer = React.useCallback(() => {
|
|
1004
|
+
if (autoScrollTimerRef.current !== null) {
|
|
1005
|
+
window.clearInterval(autoScrollTimerRef.current);
|
|
1006
|
+
autoScrollTimerRef.current = null;
|
|
1007
|
+
}
|
|
1008
|
+
}, []);
|
|
1009
|
+
React.useEffect(() => {
|
|
1010
|
+
return () => clearAutoScrollTimer();
|
|
1011
|
+
}, [clearAutoScrollTimer]);
|
|
1012
|
+
useLayoutEffect2(() => {
|
|
1013
|
+
const activeItem = getItems().find((item) => item.ref.current === document.activeElement);
|
|
1014
|
+
activeItem?.ref.current?.scrollIntoView({ block: "nearest" });
|
|
1015
|
+
}, [getItems]);
|
|
1016
|
+
return /* @__PURE__ */ jsx(
|
|
1017
|
+
Primitive.div,
|
|
1018
|
+
{
|
|
1019
|
+
"aria-hidden": true,
|
|
1020
|
+
...scrollIndicatorProps,
|
|
1021
|
+
ref: forwardedRef,
|
|
1022
|
+
style: { flexShrink: 0, ...scrollIndicatorProps.style },
|
|
1023
|
+
onPointerDown: composeEventHandlers(scrollIndicatorProps.onPointerDown, () => {
|
|
1024
|
+
if (autoScrollTimerRef.current === null) {
|
|
1025
|
+
autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
1026
|
+
}
|
|
1027
|
+
}),
|
|
1028
|
+
onPointerMove: composeEventHandlers(scrollIndicatorProps.onPointerMove, () => {
|
|
1029
|
+
contentContext.onItemLeave?.();
|
|
1030
|
+
if (autoScrollTimerRef.current === null) {
|
|
1031
|
+
autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
1032
|
+
}
|
|
1033
|
+
}),
|
|
1034
|
+
onPointerLeave: composeEventHandlers(scrollIndicatorProps.onPointerLeave, () => {
|
|
1035
|
+
clearAutoScrollTimer();
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
);
|
|
1039
|
+
});
|
|
1040
|
+
var SEPARATOR_NAME = "SelectSeparator";
|
|
1041
|
+
var SelectSeparator = React.forwardRef(
|
|
1042
|
+
(props, forwardedRef) => {
|
|
1043
|
+
const { __scopeSelect, ...separatorProps } = props;
|
|
1044
|
+
return /* @__PURE__ */ jsx(Primitive.div, { "aria-hidden": true, ...separatorProps, ref: forwardedRef });
|
|
1045
|
+
}
|
|
1046
|
+
);
|
|
1047
|
+
SelectSeparator.displayName = SEPARATOR_NAME;
|
|
1048
|
+
var ARROW_NAME = "SelectArrow";
|
|
1049
|
+
var SelectArrow = React.forwardRef(
|
|
275
1050
|
(props, forwardedRef) => {
|
|
276
|
-
const {
|
|
277
|
-
const popperScope = usePopperScope(
|
|
278
|
-
|
|
1051
|
+
const { __scopeSelect, ...arrowProps } = props;
|
|
1052
|
+
const popperScope = usePopperScope(__scopeSelect);
|
|
1053
|
+
const context = useSelectContext(ARROW_NAME, __scopeSelect);
|
|
1054
|
+
const contentContext = useSelectContentContext(ARROW_NAME, __scopeSelect);
|
|
1055
|
+
return context.open && contentContext.position === "popper" ? /* @__PURE__ */ jsx(Arrow, { ...popperScope, ...arrowProps, ref: forwardedRef }) : null;
|
|
1056
|
+
}
|
|
1057
|
+
);
|
|
1058
|
+
SelectArrow.displayName = ARROW_NAME;
|
|
1059
|
+
var BUBBLE_INPUT_NAME = "SelectBubbleInput";
|
|
1060
|
+
var SelectBubbleInput = React.forwardRef(
|
|
1061
|
+
({ __scopeSelect, value, ...props }, forwardedRef) => {
|
|
1062
|
+
const ref = React.useRef(null);
|
|
1063
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
1064
|
+
const prevValue = usePrevious(value);
|
|
1065
|
+
React.useEffect(() => {
|
|
1066
|
+
const select = ref.current;
|
|
1067
|
+
if (!select) return;
|
|
1068
|
+
const selectProto = window.HTMLSelectElement.prototype;
|
|
1069
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
1070
|
+
selectProto,
|
|
1071
|
+
"value"
|
|
1072
|
+
);
|
|
1073
|
+
const setValue = descriptor.set;
|
|
1074
|
+
if (prevValue !== value && setValue) {
|
|
1075
|
+
const event = new Event("change", { bubbles: true });
|
|
1076
|
+
setValue.call(select, value);
|
|
1077
|
+
select.dispatchEvent(event);
|
|
1078
|
+
}
|
|
1079
|
+
}, [prevValue, value]);
|
|
1080
|
+
return /* @__PURE__ */ jsx(
|
|
1081
|
+
Primitive.select,
|
|
1082
|
+
{
|
|
1083
|
+
...props,
|
|
1084
|
+
style: { ...VISUALLY_HIDDEN_STYLES, ...props.style },
|
|
1085
|
+
ref: composedRefs,
|
|
1086
|
+
defaultValue: value
|
|
1087
|
+
}
|
|
1088
|
+
);
|
|
279
1089
|
}
|
|
280
1090
|
);
|
|
281
|
-
|
|
282
|
-
function
|
|
283
|
-
return
|
|
1091
|
+
SelectBubbleInput.displayName = BUBBLE_INPUT_NAME;
|
|
1092
|
+
function shouldShowPlaceholder(value) {
|
|
1093
|
+
return value === "" || value === void 0;
|
|
1094
|
+
}
|
|
1095
|
+
function useTypeaheadSearch(onSearchChange) {
|
|
1096
|
+
const handleSearchChange = useCallbackRef(onSearchChange);
|
|
1097
|
+
const searchRef = React.useRef("");
|
|
1098
|
+
const timerRef = React.useRef(0);
|
|
1099
|
+
const handleTypeaheadSearch = React.useCallback(
|
|
1100
|
+
(key) => {
|
|
1101
|
+
const search = searchRef.current + key;
|
|
1102
|
+
handleSearchChange(search);
|
|
1103
|
+
(function updateSearch(value) {
|
|
1104
|
+
searchRef.current = value;
|
|
1105
|
+
window.clearTimeout(timerRef.current);
|
|
1106
|
+
if (value !== "") timerRef.current = window.setTimeout(() => updateSearch(""), 1e3);
|
|
1107
|
+
})(search);
|
|
1108
|
+
},
|
|
1109
|
+
[handleSearchChange]
|
|
1110
|
+
);
|
|
1111
|
+
const resetTypeahead = React.useCallback(() => {
|
|
1112
|
+
searchRef.current = "";
|
|
1113
|
+
window.clearTimeout(timerRef.current);
|
|
1114
|
+
}, []);
|
|
1115
|
+
React.useEffect(() => {
|
|
1116
|
+
return () => window.clearTimeout(timerRef.current);
|
|
1117
|
+
}, []);
|
|
1118
|
+
return [searchRef, handleTypeaheadSearch, resetTypeahead];
|
|
1119
|
+
}
|
|
1120
|
+
function findNextItem(items, search, currentItem) {
|
|
1121
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
1122
|
+
const normalizedSearch = isRepeated ? search[0] : search;
|
|
1123
|
+
const currentItemIndex = currentItem ? items.indexOf(currentItem) : -1;
|
|
1124
|
+
let wrappedItems = wrapArray(items, Math.max(currentItemIndex, 0));
|
|
1125
|
+
const excludeCurrentItem = normalizedSearch.length === 1;
|
|
1126
|
+
if (excludeCurrentItem) wrappedItems = wrappedItems.filter((v) => v !== currentItem);
|
|
1127
|
+
const nextItem = wrappedItems.find(
|
|
1128
|
+
(item) => item.textValue.toLowerCase().startsWith(normalizedSearch.toLowerCase())
|
|
1129
|
+
);
|
|
1130
|
+
return nextItem !== currentItem ? nextItem : void 0;
|
|
1131
|
+
}
|
|
1132
|
+
function wrapArray(array, startIndex) {
|
|
1133
|
+
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
|
284
1134
|
}
|
|
285
|
-
var Root2 =
|
|
286
|
-
var Trigger =
|
|
287
|
-
var
|
|
288
|
-
var
|
|
1135
|
+
var Root2 = Select;
|
|
1136
|
+
var Trigger = SelectTrigger;
|
|
1137
|
+
var Value = SelectValue;
|
|
1138
|
+
var Icon = SelectIcon;
|
|
1139
|
+
var Portal = SelectPortal;
|
|
1140
|
+
var Content2 = SelectContent;
|
|
1141
|
+
var Viewport = SelectViewport;
|
|
1142
|
+
var Group = SelectGroup;
|
|
1143
|
+
var Item = SelectItem;
|
|
1144
|
+
var ItemText = SelectItemText;
|
|
1145
|
+
var ItemIndicator = SelectItemIndicator;
|
|
1146
|
+
var ScrollUpButton = SelectScrollUpButton;
|
|
1147
|
+
var ScrollDownButton = SelectScrollDownButton;
|
|
289
1148
|
|
|
290
|
-
export { Content2 as C, Portal as P, Root2 as R, Trigger as T,
|
|
1149
|
+
export { Content2 as C, Group as G, Icon as I, Portal as P, Root2 as R, ScrollUpButton as S, Trigger as T, Value as V, Viewport as a, Item as b, ItemIndicator as c, ItemText as d, ScrollDownButton as e, clamp as f };
|
|
291
1150
|
//# sourceMappingURL=index14.js.map
|