@tamagui/select 3.0.0-beta.922.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Select.cjs +23 -25
- package/dist/cjs/Select.native.cjs +27 -26
- package/dist/cjs/Select.native.js +27 -26
- package/dist/cjs/Select.native.js.map +1 -1
- package/dist/cjs/SelectImpl.cjs +56 -50
- package/dist/cjs/SelectItem.cjs +49 -60
- package/dist/cjs/SelectItem.native.cjs +51 -79
- package/dist/cjs/SelectItem.native.js +51 -79
- package/dist/cjs/SelectItem.native.js.map +1 -1
- package/dist/cjs/SelectScrollButton.cjs +2 -2
- package/dist/cjs/SelectTrigger.cjs +22 -5
- package/dist/cjs/SelectTrigger.native.cjs +15 -5
- package/dist/cjs/SelectTrigger.native.js +15 -5
- package/dist/cjs/SelectTrigger.native.js.map +1 -1
- package/dist/cjs/SelectViewport.cjs +22 -30
- package/dist/cjs/SelectViewport.native.cjs +2 -2
- package/dist/cjs/SelectViewport.native.js +2 -2
- package/dist/cjs/SelectViewport.native.js.map +1 -1
- package/dist/cjs/selectionController.cjs +15 -5
- package/dist/cjs/selectionController.native.cjs +20 -15
- package/dist/cjs/selectionController.native.js +20 -15
- package/dist/cjs/selectionController.native.js.map +1 -1
- package/dist/esm/Select.mjs +27 -28
- package/dist/esm/Select.mjs.map +1 -1
- package/dist/esm/Select.native.js +31 -29
- package/dist/esm/Select.native.js.map +1 -1
- package/dist/esm/SelectImpl.mjs +56 -50
- package/dist/esm/SelectImpl.mjs.map +1 -1
- package/dist/esm/SelectItem.mjs +50 -61
- package/dist/esm/SelectItem.mjs.map +1 -1
- package/dist/esm/SelectItem.native.js +52 -80
- package/dist/esm/SelectItem.native.js.map +1 -1
- package/dist/esm/SelectScrollButton.mjs +2 -2
- package/dist/esm/SelectScrollButton.mjs.map +1 -1
- package/dist/esm/SelectTrigger.mjs +16 -5
- package/dist/esm/SelectTrigger.mjs.map +1 -1
- package/dist/esm/SelectTrigger.native.js +15 -4
- package/dist/esm/SelectTrigger.native.js.map +1 -1
- package/dist/esm/SelectViewport.mjs +22 -30
- package/dist/esm/SelectViewport.mjs.map +1 -1
- package/dist/esm/SelectViewport.native.js +3 -3
- package/dist/esm/SelectViewport.native.js.map +1 -1
- package/dist/esm/selectionController.mjs +15 -5
- package/dist/esm/selectionController.mjs.map +1 -1
- package/dist/esm/selectionController.native.js +20 -15
- package/dist/esm/selectionController.native.js.map +1 -1
- package/dist/jsx/Select.mjs +27 -28
- package/dist/jsx/Select.mjs.map +1 -1
- package/dist/jsx/Select.native.cjs +27 -26
- package/dist/jsx/Select.native.js +27 -26
- package/dist/jsx/Select.native.js.map +1 -1
- package/dist/jsx/SelectImpl.mjs +56 -50
- package/dist/jsx/SelectImpl.mjs.map +1 -1
- package/dist/jsx/SelectItem.mjs +50 -61
- package/dist/jsx/SelectItem.mjs.map +1 -1
- package/dist/jsx/SelectItem.native.cjs +51 -79
- package/dist/jsx/SelectItem.native.js +51 -79
- package/dist/jsx/SelectItem.native.js.map +1 -1
- package/dist/jsx/SelectScrollButton.mjs +2 -2
- package/dist/jsx/SelectScrollButton.mjs.map +1 -1
- package/dist/jsx/SelectTrigger.mjs +16 -5
- package/dist/jsx/SelectTrigger.mjs.map +1 -1
- package/dist/jsx/SelectTrigger.native.cjs +15 -5
- package/dist/jsx/SelectTrigger.native.js +15 -5
- package/dist/jsx/SelectTrigger.native.js.map +1 -1
- package/dist/jsx/SelectViewport.mjs +22 -30
- package/dist/jsx/SelectViewport.mjs.map +1 -1
- package/dist/jsx/SelectViewport.native.cjs +2 -2
- package/dist/jsx/SelectViewport.native.js +2 -2
- package/dist/jsx/SelectViewport.native.js.map +1 -1
- package/dist/jsx/selectionController.mjs +15 -5
- package/dist/jsx/selectionController.mjs.map +1 -1
- package/dist/jsx/selectionController.native.cjs +20 -15
- package/dist/jsx/selectionController.native.js +20 -15
- package/dist/jsx/selectionController.native.js.map +1 -1
- package/package.json +30 -29
- package/src/Select.tsx +41 -41
- package/src/SelectImpl.tsx +83 -81
- package/src/SelectItem.tsx +66 -91
- package/src/SelectScrollButton.tsx +2 -2
- package/src/SelectTrigger.tsx +19 -2
- package/src/SelectViewport.native.tsx +4 -4
- package/src/SelectViewport.tsx +21 -27
- package/src/selectionController.ts +20 -5
- package/src/types.tsx +26 -21
- package/types/Select.d.ts +42 -81
- package/types/Select.d.ts.map +1 -1
- package/types/SelectImpl.d.ts.map +1 -1
- package/types/SelectItem.d.ts +3 -5
- package/types/SelectItem.d.ts.map +1 -1
- package/types/SelectItemText.d.ts +3 -5
- package/types/SelectItemText.d.ts.map +1 -1
- package/types/SelectScrollButton.d.ts +5 -9
- package/types/SelectScrollButton.d.ts.map +1 -1
- package/types/SelectScrollButton.native.d.ts +5 -9
- package/types/SelectScrollButton.native.d.ts.map +1 -1
- package/types/SelectTrigger.d.ts +3 -5
- package/types/SelectTrigger.d.ts.map +1 -1
- package/types/SelectViewport.d.ts +4 -9
- package/types/SelectViewport.d.ts.map +1 -1
- package/types/SelectViewport.native.d.ts +4 -9
- package/types/SelectViewport.native.d.ts.map +1 -1
- package/types/selectionController.d.ts +2 -0
- package/types/selectionController.d.ts.map +1 -1
- package/types/types.d.ts +30 -21
- package/types/types.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectItem.native.js","names":[],"sources":["esm/SelectItem.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { useAdaptIsActive } from \"@tamagui/adapt\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createChangeEventDetails, createStyledHOC, createStyledContext, styled, View } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { getSelectOptionProps } from \"./selectionController\";\nfunction _instanceof(left, right) {\n if (right != null && typeof Symbol !== \"undefined\" && right[Symbol.hasInstance]) {\n return !!right[Symbol.hasInstance](left);\n } else {\n return left instanceof right;\n }\n}\nvar ITEM_NAME = \"SelectItem\";\nvar { Provider: SelectItemContextProvider, useStyledContext: useSelectItemContext } = createStyledContext(null, ITEM_NAME);\nvar SelectItemFrame = styled(View, {\n displayName: ITEM_NAME,\n alignItems: \"center\",\n flexDirection: \"row\"\n});\nvar SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, forwardedRef) {\n var { scope, value, disabled: disabledProp, \"aria-disabled\": ariaDisabled, textValue: textValueProp, ...restProps } = props;\n var disabled = disabledProp !== null && disabledProp !== void 0 ? disabledProp : ariaDisabled === true;\n var context = useSelectItemParentContext(scope);\n var selectContext = useSelectContext(scope);\n var isAdapted = useAdaptIsActive(selectContext.adaptScope);\n var { listRef, registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, interactions, shouldRenderWebNative, setActiveIndexFast, moveActive, search } = context;\n var isSelected = selectedValues.includes(value);\n var pendingMouseUpSelectionRef = React.useRef(false);\n var itemNodeRef = React.useRef(null);\n var [, rerenderRegistry] = React.useReducer(function(version) {\n return version + 1;\n }, 0);\n var registrationRef = React.useRef(null);\n var initialRegistration = React.useRef({\n value,\n disabled,\n textValue: textValueProp\n });\n useIsomorphicLayoutEffect(function() {\n return registry.subscribe(function() {\n return rerenderRegistry();\n });\n }, [\n registry\n ]);\n useIsomorphicLayoutEffect(function() {\n var registration = registry.registerItem(initialRegistration.current);\n registrationRef.current = registration;\n var registeredNode = itemNodeRef.current;\n registration.setNode(registeredNode);\n var registeredIndex = registry.getItems().findIndex(function(item) {\n return item.id === registration.id;\n });\n if (isWeb && listRef && registeredIndex >= 0 && _instanceof(registeredNode, HTMLElement)) {\n listRef.current[registeredIndex] = registeredNode;\n }\n return function() {\n var currentIndex = registry.getItems().findIndex(function(item) {\n return item.id === registration.id;\n });\n if (listRef && currentIndex >= 0 && listRef.current[currentIndex] === registeredNode) {\n listRef.current[currentIndex] = null;\n }\n registrationRef.current = null;\n registration.unregister();\n };\n }, [\n registry\n ]);\n useIsomorphicLayoutEffect(function() {\n var _registrationRef_current;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.update({\n value,\n disabled,\n textValue: textValueProp\n });\n }, [\n disabled,\n textValueProp,\n value\n ]);\n useIsomorphicLayoutEffect(function() {\n var _registrationRef_current;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(itemNodeRef.current);\n });\n var index = registry.getIndex(value);\n React.useEffect(function() {\n var handleActiveIndex = function(i) {\n if (index === i) {\n if (isWeb) {\n requestAnimationFrame(function() {\n var _listRef_current_index;\n listRef === null || listRef === void 0 ? void 0 : (_listRef_current_index = listRef.current[index]) === null || _listRef_current_index === void 0 ? void 0 : _listRef_current_index.focus();\n });\n }\n }\n };\n var currentActiveIndex = activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current;\n if (currentActiveIndex !== null && currentActiveIndex !== void 0) {\n handleActiveIndex(currentActiveIndex);\n }\n return activeIndexSubscribe(handleActiveIndex);\n }, [\n activeIndexRef,\n activeIndexSubscribe,\n index,\n listRef\n ]);\n var textId = React.useId();\n var refCallback = React.useCallback(function(node) {\n var _registrationRef_current;\n itemNodeRef.current = node;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(node);\n if (!isWeb) return;\n if (listRef && index >= 0) {\n listRef.current[index] = _instanceof(node, HTMLElement) ? node : null;\n }\n }, [\n index,\n listRef\n ]);\n var composedRefs = useComposedRefs(forwardedRef, refCallback);\n var handleSelect = React.useCallback(function(event) {\n var reason = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : \"item-press\";\n if (disabled) return;\n var nativeEvent = (event === null || event === void 0 ? void 0 : event.nativeEvent) || event;\n selectValue(value, createChangeEventDetails(reason, nativeEvent, event === null || event === void 0 ? void 0 : event.currentTarget));\n }, [\n disabled,\n selectValue,\n value\n ]);\n var handleKeyDown = React.useCallback(function(event) {\n var _event_key;\n if (disabled) return;\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n handleSelect(event, \"keyboard\");\n return;\n }\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n event.stopPropagation();\n moveActive(event.key === \"ArrowDown\" ? 1 : -1, event.nativeEvent || event);\n return;\n }\n if (!interactions && ((_event_key = event.key) === null || _event_key === void 0 ? void 0 : _event_key.length) === 1 && !event.metaKey && !event.ctrlKey) {\n search(event.key, event.nativeEvent || event);\n }\n if (allowSelectRef) {\n allowSelectRef.current = true;\n }\n }, [\n allowSelectRef,\n disabled,\n handleSelect,\n interactions,\n moveActive,\n search\n ]);\n var selectItemProps = React.useMemo(function() {\n if (interactions) {\n var { onTouchMove, onTouchEnd, onKeyDown, onClick, onMouseUp, onMouseMove, onPress, ...itemProps } = restProps;\n var interactionProps = interactions.getItemProps({\n ...itemProps,\n onTouchMove() {\n allowSelectRef.current = true;\n allowMouseUpRef.current = false;\n },\n onTouchEnd() {\n allowSelectRef.current = false;\n allowMouseUpRef.current = true;\n },\n onMouseMove(event) {\n if (disabled || index < 0) return;\n setActiveIndexFast === null || setActiveIndexFast === void 0 ? void 0 : setActiveIndexFast(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n },\n onKeyDown: handleKeyDown,\n onClick(event) {\n if (disabled) return;\n var shouldSelect = pendingMouseUpSelectionRef.current || allowSelectRef.current;\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n if (shouldSelect) {\n handleSelect(event);\n }\n },\n onMouseUp(event) {\n if (disabled) return;\n if (!allowMouseUpRef.current) {\n allowMouseUpRef.current = true;\n allowSelectRef.current = true;\n return;\n }\n pendingMouseUpSelectionRef.current = allowSelectRef.current;\n clearTimeout(selectTimeoutRef.current);\n selectTimeoutRef.current = setTimeout(function() {\n allowSelectRef.current = true;\n if (pendingMouseUpSelectionRef.current) {\n pendingMouseUpSelectionRef.current = false;\n handleSelect(event);\n }\n });\n }\n });\n return {\n ...interactionProps,\n onTouchMove: composeEventHandlers(onTouchMove, interactionProps.onTouchMove),\n onTouchEnd: composeEventHandlers(onTouchEnd, interactionProps.onTouchEnd),\n onKeyDown: composeEventHandlers(onKeyDown, interactionProps.onKeyDown),\n onClick(event) {\n var _interactionProps_onClick;\n onClick === null || onClick === void 0 ? void 0 : onClick(event);\n if (event.defaultPrevented) {\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n return;\n }\n (_interactionProps_onClick = interactionProps.onClick) === null || _interactionProps_onClick === void 0 ? void 0 : _interactionProps_onClick.call(interactionProps, event);\n },\n onMouseUp: composeEventHandlers(onMouseUp, interactionProps.onMouseUp),\n onMouseMove: composeEventHandlers(onMouseMove, interactionProps.onMouseMove),\n onPress\n };\n }\n return {\n ...restProps,\n onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),\n onMouseMove: composeEventHandlers(restProps.onMouseMove, function(event) {\n if (disabled || index < 0) return;\n setActiveIndexFast === null || setActiveIndexFast === void 0 ? void 0 : setActiveIndexFast(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n }),\n onPress: composeEventHandlers(restProps.onPress, handleSelect)\n };\n }, [\n allowMouseUpRef,\n allowSelectRef,\n disabled,\n handleKeyDown,\n handleSelect,\n index,\n interactions,\n restProps,\n selectTimeoutRef,\n setActiveIndexFast\n ]);\n var accessibilityProps = getSelectOptionProps(mode, isSelected, disabled, isWeb ? \"web\" : \"native\");\n var _selectContext_activeIndex;\n return /* @__PURE__ */ _jsx(SelectItemContextProvider, {\n scope,\n value,\n textId: textId || \"\",\n textValue: textValueProp,\n isSelected,\n children: shouldRenderWebNative ? /* @__PURE__ */ _jsx(\"option\", {\n value,\n disabled,\n children: props.children\n }) : /* @__PURE__ */ _jsx(SelectItemFrame, {\n render: \"div\",\n ref: composedRefs,\n \"aria-labelledby\": textId,\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-disabled\": disabled ? \"\" : void 0,\n tabIndex: disabled ? void 0 : isWeb && isAdapted ? index === ((_selectContext_activeIndex = selectContext.activeIndex) !== null && _selectContext_activeIndex !== void 0 ? _selectContext_activeIndex : selectContext.selectedIndex) ? 0 : -1 : -1,\n zIndex: 100,\n ...selectItemProps,\n ...accessibilityProps\n })\n });\n}, {\n disableTheme: true\n});\nexport {\n SelectItem,\n SelectItemContextProvider,\n SelectItemFrame,\n useSelectItemContext\n};\n//# sourceMappingURL=SelectItem.js.map\n"],"mappings":";;;;;;;;;;;AASA,SAAS,YAAY,MAAM,OAAO;CAChC,IAAI,SAAS,QAAQ,OAAO,WAAW,eAAe,MAAM,OAAO,cAAc;EAC/E,OAAO,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,IAAI;CACzC,OAAO;EACL,OAAO,gBAAgB;CACzB;AACF;AACA,IAAI,YAAY;AAChB,IAAI,EAAE,UAAU,2BAA2B,kBAAkB,yBAAyB,oBAAoB,MAAM,SAAS;AACzH,IAAI,kBAAkB,OAAO,MAAM;CACjC,aAAa;CACb,YAAY;CACZ,eAAe;AACjB,CAAC;AACD,IAAI,aAAa,gBAAgB,iBAAiB,SAAS,YAAY,OAAO,cAAc;CAC1F,IAAI,EAAE,OAAO,OAAO,UAAU,cAAc,iBAAiB,cAAc,WAAW,eAAe,GAAG,cAAc;CACtH,IAAI,WAAW,iBAAiB,QAAQ,iBAAiB,KAAK,IAAI,eAAe,iBAAiB;CAClG,IAAI,UAAU,2BAA2B,KAAK;CAC9C,IAAI,gBAAgB,iBAAiB,KAAK;CAC1C,IAAI,YAAY,iBAAiB,cAAc,UAAU;CACzD,IAAI,EAAE,SAAS,UAAU,MAAM,gBAAgB,aA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ACH,WAAW,qBAAqB,UAAU,WAAW,aAAa;GAClE,aAAa,qBAAqB,UAAU,aAAa,SAAS,OAAO;IACvE,IAAI,YAAY,QAAQ,GAAG;IAC3B,uBAAuB,QAAQ,uBAAuB,KAAK,IAAI,KAAK,IAAI,mBAAmB,OAAO;KAChG,QAAQ;KACR,OAAO,MAAM,eAAe;KAC5B,SAAS,MAAM;KACf;IACF,CAAC;GACH,CAAC;GACD,SAAS,qBAAqB,UAAU,SAAS,YAAY;EAC/D;CACF,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,IAAI,qBAAqB,qBAAqB,MAAM,YAAY,UAAU,QAAQ,QAAQ,QAAQ;CAClG,IAAI;CACJ,OAAuB,oBAAK,2BAA2B;EACrD;EACA;EACA,QAAQ,UAAU;EAClB,WAAW;EACX;EACA,UAAU,wBAAwC,oBAAK,UAAU;GAC/D;GACA;GACA,UAAU,MAAM;EAClB,CAAC,IAAoB,oBAAK,iBAAiB;GACzC,QAAQ;GACR,KAAK;GACL,mBAAmB;GACnB,cAAc,aAAa,WAAW;GACtC,iBAAiB,WAAW,KAAK,KAAK;GACtC,UAAU,WAAW,KAAK,IAAI,SAAS,YAAY,YAAY,6BAA6B,cAAc,iBAAiB,QAAQ,+BAA+B,KAAK,IAAI,6BAA6B,cAAc,iBAAiB,IAAI,CAAC,IAAI,CAAC;GACjP,QAAQ;GACR,GAAG;GACH,GAAG;EACL,CAAC;CACH,CAAC;AACH,GAAG,EACD,cAAc,KAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"SelectItem.native.js","names":[],"sources":["esm/SelectItem.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { useAdaptIsActive } from \"@tamagui/adapt\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createChangeEventDetails, createStyledHOC, createStyledContext, styled, View } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectItemParentContext } from \"./context\";\nimport { getSelectOptionProps } from \"./selectionController\";\nvar ITEM_NAME = \"SelectItem\";\nvar { Provider: SelectItemContextProvider, useStyledContext: useSelectItemContext } = createStyledContext(null, ITEM_NAME);\nvar SelectItemFrame = styled(View, {\n displayName: ITEM_NAME,\n alignItems: \"center\",\n flexDirection: \"row\"\n});\nvar SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, forwardedRef) {\n var { scope, value, disabled: disabledProp, \"aria-disabled\": ariaDisabled, textValue: textValueProp, ...restProps } = props;\n var disabled = disabledProp !== null && disabledProp !== void 0 ? disabledProp : ariaDisabled === true;\n var context = useSelectItemParentContext(scope);\n var isAdapted = useAdaptIsActive(context.adaptScope);\n var { registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, getItemProps, shouldRenderWebNative, setActiveIndex, lastPointerRef, moveActive, search } = context;\n var isSelected = selectedValues.includes(value);\n var pendingMouseUpSelectionRef = React.useRef(false);\n var itemNodeRef = React.useRef(null);\n var registrationRef = React.useRef(null);\n var initialRegistration = React.useRef({\n value,\n disabled,\n textValue: textValueProp\n });\n useIsomorphicLayoutEffect(function() {\n var registration = registry.registerItem(initialRegistration.current);\n registrationRef.current = registration;\n registration.setNode(itemNodeRef.current);\n return function() {\n registrationRef.current = null;\n registration.unregister();\n };\n }, [\n registry\n ]);\n useIsomorphicLayoutEffect(function() {\n var _registrationRef_current;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.update({\n value,\n disabled,\n textValue: textValueProp\n });\n }, [\n disabled,\n textValueProp,\n value\n ]);\n useIsomorphicLayoutEffect(function() {\n var _registrationRef_current;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(itemNodeRef.current);\n });\n var [isActive, setIsActive] = React.useState(false);\n var isActiveRef = React.useRef(false);\n React.useEffect(function() {\n var handleActiveIndex = function(i) {\n var next = i != null && registry.getIndex(value) === i;\n if (next !== isActiveRef.current) {\n isActiveRef.current = next;\n setIsActive(next);\n }\n if (next && isWeb) {\n requestAnimationFrame(function() {\n var _itemNodeRef_current_focus, _itemNodeRef_current;\n (_itemNodeRef_current = itemNodeRef.current) === null || _itemNodeRef_current === void 0 ? void 0 : (_itemNodeRef_current_focus = _itemNodeRef_current.focus) === null || _itemNodeRef_current_focus === void 0 ? void 0 : _itemNodeRef_current_focus.call(_itemNodeRef_current);\n });\n }\n };\n var _activeIndexRef_current;\n handleActiveIndex((_activeIndexRef_current = activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current) !== null && _activeIndexRef_current !== void 0 ? _activeIndexRef_current : null);\n return activeIndexSubscribe(handleActiveIndex);\n }, [\n activeIndexRef,\n activeIndexSubscribe,\n registry,\n value\n ]);\n var textId = React.useId();\n var refCallback = React.useCallback(function(node) {\n var _registrationRef_current;\n itemNodeRef.current = node;\n (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(node);\n }, []);\n var composedRefs = useComposedRefs(forwardedRef, refCallback);\n var handleSelect = React.useCallback(function(event) {\n var reason = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : \"item-press\";\n if (disabled) return;\n var nativeEvent = (event === null || event === void 0 ? void 0 : event.nativeEvent) || event;\n selectValue(value, createChangeEventDetails(reason, nativeEvent, event === null || event === void 0 ? void 0 : event.currentTarget));\n }, [\n disabled,\n selectValue,\n value\n ]);\n var handleMouseMove = React.useCallback(function(event) {\n if (disabled) return;\n var index = registry.getIndex(value);\n if (index < 0) return;\n var last = lastPointerRef.current;\n if (event.clientX === last.x && event.clientY === last.y) return;\n last.x = event.clientX;\n last.y = event.clientY;\n setActiveIndex(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n }, [\n disabled,\n lastPointerRef,\n registry,\n setActiveIndex,\n value\n ]);\n var handleKeyDown = React.useCallback(function(event) {\n var _event_key;\n if (disabled) return;\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n handleSelect(event, \"keyboard\");\n return;\n }\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n event.stopPropagation();\n moveActive(event.key === \"ArrowDown\" ? 1 : -1, event.nativeEvent || event);\n return;\n }\n if (!getItemProps && ((_event_key = event.key) === null || _event_key === void 0 ? void 0 : _event_key.length) === 1 && !event.metaKey && !event.ctrlKey) {\n search(event.key, event.nativeEvent || event);\n }\n if (allowSelectRef) {\n allowSelectRef.current = true;\n }\n }, [\n allowSelectRef,\n disabled,\n handleSelect,\n getItemProps,\n moveActive,\n search\n ]);\n var selectItemProps = React.useMemo(function() {\n if (getItemProps) {\n var { onTouchMove, onTouchEnd, onKeyDown, onClick, onMouseUp, onMouseMove, onPress, ...itemProps } = restProps;\n var interactionProps = getItemProps({\n ...itemProps,\n onTouchMove() {\n allowSelectRef.current = true;\n allowMouseUpRef.current = false;\n },\n onTouchEnd() {\n allowSelectRef.current = false;\n allowMouseUpRef.current = true;\n },\n onMouseMove: handleMouseMove,\n onKeyDown: handleKeyDown,\n onClick(event) {\n if (disabled) return;\n var shouldSelect = pendingMouseUpSelectionRef.current || allowSelectRef.current;\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n if (shouldSelect) {\n handleSelect(event);\n }\n },\n onMouseUp(event) {\n if (disabled) return;\n if (!allowMouseUpRef.current) {\n allowMouseUpRef.current = true;\n allowSelectRef.current = true;\n return;\n }\n pendingMouseUpSelectionRef.current = allowSelectRef.current;\n clearTimeout(selectTimeoutRef.current);\n selectTimeoutRef.current = setTimeout(function() {\n allowSelectRef.current = true;\n if (pendingMouseUpSelectionRef.current) {\n pendingMouseUpSelectionRef.current = false;\n handleSelect(event);\n }\n });\n }\n });\n return {\n ...interactionProps,\n onTouchMove: composeEventHandlers(onTouchMove, interactionProps.onTouchMove),\n onTouchEnd: composeEventHandlers(onTouchEnd, interactionProps.onTouchEnd),\n onKeyDown: composeEventHandlers(onKeyDown, interactionProps.onKeyDown),\n onClick(event) {\n var _interactionProps_onClick;\n onClick === null || onClick === void 0 ? void 0 : onClick(event);\n if (event.defaultPrevented) {\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n return;\n }\n (_interactionProps_onClick = interactionProps.onClick) === null || _interactionProps_onClick === void 0 ? void 0 : _interactionProps_onClick.call(interactionProps, event);\n },\n onMouseUp: composeEventHandlers(onMouseUp, interactionProps.onMouseUp),\n onMouseMove: composeEventHandlers(onMouseMove, interactionProps.onMouseMove),\n onPress\n };\n }\n return {\n ...restProps,\n onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),\n onMouseMove: composeEventHandlers(restProps.onMouseMove, handleMouseMove),\n onPress: composeEventHandlers(restProps.onPress, handleSelect)\n };\n }, [\n allowMouseUpRef,\n allowSelectRef,\n disabled,\n handleKeyDown,\n handleMouseMove,\n handleSelect,\n getItemProps,\n restProps,\n selectTimeoutRef\n ]);\n var accessibilityProps = getSelectOptionProps(mode, isSelected, disabled, isWeb ? \"web\" : \"native\");\n return /* @__PURE__ */ _jsx(SelectItemContextProvider, {\n scope,\n value,\n textId: textId || \"\",\n textValue: textValueProp,\n isSelected,\n children: shouldRenderWebNative ? /* @__PURE__ */ _jsx(\"option\", {\n value,\n disabled,\n children: props.children\n }) : /* @__PURE__ */ _jsx(SelectItemFrame, {\n render: \"div\",\n ref: composedRefs,\n \"aria-labelledby\": textId,\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-disabled\": disabled ? \"\" : void 0,\n tabIndex: disabled ? void 0 : isWeb && isAdapted && (isActive || (activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current) == null && isSelected) ? 0 : -1,\n zIndex: 100,\n ...selectItemProps,\n ...accessibilityProps\n })\n });\n}, {\n disableTheme: true\n});\nexport {\n SelectItem,\n SelectItemContextProvider,\n SelectItemFrame,\n useSelectItemContext\n};\n//# sourceMappingURL=SelectItem.js.map\n"],"mappings":";;;;;;;;;;;AASA,IAAI,YAAY;AAChB,IAAI,EAAE,UAAU,2BAA2B,kBAAkB,yBAAyB,oBAAoB,MAAM,SAAS;AACzH,IAAI,kBAAkB,OAAO,MAAM;CACjC,aAAa;CACb,YAAY;CACZ,eAAe;AACjB,CAAC;AACD,IAAI,aAAa,gBAAgB,iBAAiB,SAAS,YAAY,OAAO,cAAc;CAC1F,IAAI,EAAE,OAAO,OAAO,UAAU,cAAc,iBAAiB,cAAc,WAAW,eAAe,GAAG,cAAc;CACtH,IAAI,WAAW,iBAAiB,QAAQ,iBAAiB,KAAK,IAAI,eAAe,iBAAiB;CAClG,IAAI,UAAU,2BAA2B,KAAK;CAC9C,IAAI,YAAY,iBAAiB,QAAQ,UAAU;CACnD,IAAI,EAAE,UAAU,MAAM,gBAAgB,aAAa,sBAAsB,gBAAgB,iBAAiB,gBAAgB,kBAAkB,cAAc,uBAAuB,gBAAgB,gBAAgB,YAAY,WAAW;CACxO,IAAI,aAAa,eAAe,SAAS,KAAK;CAC9C,IAAI,6BAA6B,MAAM,OAAO,KAAK;CACnD,IAAI,cAAc,MAAM,OAAO,IAAI;CACnC,IAAI,kBAAkB,MAAM,OAAO,IAAI;CACvC,IAAI,sBAAsB,MAAM,OAAO;EACrC;EACA;EACA,WAAW;CACb,CAAC;CACD,0BAA0B,WAAW;EACnC,IAAI,eAAe,SAAS,aAAa,oBAAoB,OAAO;EACpE,gBAAgB,UAAU;EAC1B,aAAa,QAAQ,YAAY,OAAO;EACxC,OAAO,WAAW;GAChB,gBAAgB,UAAU;GAC1B,aAAa,WAAW;EAC1B;CACF,GAAG,CACD,QACF,CAAC;CACD,0BAA0B,WAAW;EACnC,IAAI;EACJ,CAAC,2BAA2B,gBAA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2BAA2B,UAAU;MACrC,aAAa,iBAAiB,OAAO;MACrC,eAAe,UAAU;MACzB;KACF;KACA,CAAC,4BAA4B,iBAAiB,aAAa,QAAQ,8BAA8B,KAAK,IAAI,KAAK,IAAI,0BAA0B,KAAK,kBAAkB,KAAK;IAC3K;IACA,WAAW,qBAAqB,WAAW,iBAAiB,SAAS;IACrE,aAAa,qBAAqB,aAAa,iBAAiB,WAAW;IAC3E;GACF;EACF;EACA,OAAO;GACL,GAAG;GACH,WAAW,qBAAqB,UAAU,WAAW,aAAa;GAClE,aAAa,qBAAqB,UAAU,aAAa,eAAe;GACxE,SAAS,qBAAqB,UAAU,SAAS,YAAY;EAC/D;CACF,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,IAAI,qBAAqB,qBAAqB,MAAM,YAAY,UAAU,QAAQ,QAAQ,QAAQ;CAClG,OAAuB,oBAAK,2BAA2B;EACrD;EACA;EACA,QAAQ,UAAU;EAClB,WAAW;EACX;EACA,UAAU,wBAAwC,oBAAK,UAAU;GAC/D;GACA;GACA,UAAU,MAAM;EAClB,CAAC,IAAoB,oBAAK,iBAAiB;GACzC,QAAQ;GACR,KAAK;GACL,mBAAmB;GACnB,cAAc,aAAa,WAAW;GACtC,iBAAiB,WAAW,KAAK,KAAK;GACtC,UAAU,WAAW,KAAK,IAAI,SAAS,cAAc,aAAa,mBAAmB,QAAQ,mBAAmB,KAAK,IAAI,KAAK,IAAI,eAAe,YAAY,QAAQ,cAAc,IAAI,CAAC;GACxL,QAAQ;GACR,GAAG;GACH,GAAG;EACL,CAAC;CACH,CAAC;AACH,GAAG,EACD,cAAc,KAChB,CAAC"}
|
|
@@ -31,7 +31,7 @@ SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
|
|
|
31
31
|
const SelectScrollButtonImpl = React.memo(createStyledHOC(SelectScrollButtonFrame, (props, forwardedRef) => {
|
|
32
32
|
const { scope, dir, partClassName, ...scrollIndicatorProps } = props;
|
|
33
33
|
const { className, onPointerEnter, onPointerLeave, ...frameProps } = scrollIndicatorProps;
|
|
34
|
-
const { open, fallback,
|
|
34
|
+
const { open, fallback, updateScrollArrows, setInnerOffset, ...context } = useSelectContext(scope);
|
|
35
35
|
const floatingRef = context.floatingContext?.refs.floating;
|
|
36
36
|
const statusRef = React.useRef("idle");
|
|
37
37
|
const isVisible = context[dir === "down" ? "canScrollDown" : "canScrollUp"];
|
|
@@ -60,7 +60,7 @@ const SelectScrollButtonImpl = React.memo(createStyledHOC(SelectScrollButtonFram
|
|
|
60
60
|
if (fallback) {
|
|
61
61
|
if (floating.current) {
|
|
62
62
|
floating.current.scrollTop -= amount;
|
|
63
|
-
|
|
63
|
+
updateScrollArrows();
|
|
64
64
|
}
|
|
65
65
|
} else {
|
|
66
66
|
flushSync(() => setInnerOffset((value) => value - amount));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectScrollButton.js","names":["useFloating"],"sources":["esm/SelectScrollButton.js"],"sourcesContent":["import { createStyledHOC, styled, View } from \"@tamagui/core\";\nimport { autoUpdate, offset, useFloatingRaw as useFloating } from \"@tamagui/floating\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useSelectContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\nconst SCROLL_UP_BUTTON_NAME = \"SelectScrollUpButton\";\nconst SelectScrollButtonFrame = styled(View, {\n displayName: \"SelectScrollButton\"\n});\nconst SelectScrollUpButton = createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n return /* @__PURE__ */ jsx(\n SelectScrollButtonImpl,\n {\n partClassName: `is_${SCROLL_UP_BUTTON_NAME}`,\n ...props,\n dir: \"up\",\n ref: forwardedRef\n }\n );\n }\n);\nSelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;\nconst SCROLL_DOWN_BUTTON_NAME = \"SelectScrollDownButton\";\nconst SelectScrollDownButton = createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n return /* @__PURE__ */ jsx(\n SelectScrollButtonImpl,\n {\n partClassName: `is_${SCROLL_DOWN_BUTTON_NAME}`,\n ...props,\n dir: \"down\",\n ref: forwardedRef\n }\n );\n }\n);\nSelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;\nconst SelectScrollButtonImpl = React.memo(\n createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n const { scope, dir, partClassName, ...scrollIndicatorProps } = props;\n const { className, onPointerEnter, onPointerLeave, ...frameProps } = scrollIndicatorProps;\n const { open, fallback,
|
|
1
|
+
{"version":3,"file":"SelectScrollButton.js","names":["useFloating"],"sources":["esm/SelectScrollButton.js"],"sourcesContent":["import { createStyledHOC, styled, View } from \"@tamagui/core\";\nimport { autoUpdate, offset, useFloatingRaw as useFloating } from \"@tamagui/floating\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useSelectContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\nconst SCROLL_UP_BUTTON_NAME = \"SelectScrollUpButton\";\nconst SelectScrollButtonFrame = styled(View, {\n displayName: \"SelectScrollButton\"\n});\nconst SelectScrollUpButton = createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n return /* @__PURE__ */ jsx(\n SelectScrollButtonImpl,\n {\n partClassName: `is_${SCROLL_UP_BUTTON_NAME}`,\n ...props,\n dir: \"up\",\n ref: forwardedRef\n }\n );\n }\n);\nSelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;\nconst SCROLL_DOWN_BUTTON_NAME = \"SelectScrollDownButton\";\nconst SelectScrollDownButton = createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n return /* @__PURE__ */ jsx(\n SelectScrollButtonImpl,\n {\n partClassName: `is_${SCROLL_DOWN_BUTTON_NAME}`,\n ...props,\n dir: \"down\",\n ref: forwardedRef\n }\n );\n }\n);\nSelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;\nconst SelectScrollButtonImpl = React.memo(\n createStyledHOC(\n SelectScrollButtonFrame,\n (props, forwardedRef) => {\n const { scope, dir, partClassName, ...scrollIndicatorProps } = props;\n const { className, onPointerEnter, onPointerLeave, ...frameProps } = scrollIndicatorProps;\n const { open, fallback, updateScrollArrows, setInnerOffset, ...context } = useSelectContext(scope);\n const floatingRef = context.floatingContext?.refs.floating;\n const statusRef = React.useRef(\"idle\");\n const isVisible = context[dir === \"down\" ? \"canScrollDown\" : \"canScrollUp\"];\n const frameRef = React.useRef(null);\n const { x, y, refs, strategy } = useFloating({\n open: open && isVisible,\n strategy: \"fixed\",\n elements: {\n reference: floatingRef?.current\n },\n placement: dir === \"up\" ? \"top\" : \"bottom\",\n middleware: [offset(({ rects }) => -rects.floating.height)],\n whileElementsMounted: (...args) => autoUpdate(...args, { animationFrame: true })\n });\n const setFloatingRef = React.useCallback(\n (node) => {\n refs.setFloating(node);\n },\n [refs.setFloating]\n );\n const composedRef = useComposedRefs(forwardedRef, setFloatingRef);\n React.useEffect(() => {\n return () => cancelAnimationFrame(frameRef.current);\n }, []);\n if (!isVisible) {\n return null;\n }\n const onScroll = (amount) => {\n const floating = floatingRef;\n if (!floating) return;\n if (fallback) {\n if (floating.current) {\n floating.current.scrollTop -= amount;\n updateScrollArrows();\n }\n } else {\n flushSync(() => setInnerOffset((value) => value - amount));\n }\n };\n return /* @__PURE__ */ jsx(\n SelectScrollButtonFrame,\n {\n ref: composedRef,\n className: `${partClassName} ${className || \"\"}`.trim(),\n \"aria-hidden\": true,\n ...frameProps,\n zIndex: 1e3,\n position: strategy,\n left: x || 0,\n top: y || 0,\n width: `calc(${(floatingRef?.current?.offsetWidth ?? 0) - 2}px)`,\n onPointerEnter: composeEventHandlers(onPointerEnter, () => {\n statusRef.current = \"active\";\n let prevNow = Date.now();\n function frame() {\n const element = floatingRef?.current;\n if (element) {\n const currentNow = Date.now();\n const msElapsed = currentNow - prevNow;\n prevNow = currentNow;\n const pixelsToScroll = msElapsed / 2;\n const remainingPixels = dir === \"up\" ? element.scrollTop : element.scrollHeight - element.clientHeight - element.scrollTop;\n const scrollRemaining = dir === \"up\" ? element.scrollTop - pixelsToScroll > 0 : element.scrollTop + pixelsToScroll < element.scrollHeight - element.clientHeight;\n onScroll(\n dir === \"up\" ? Math.min(pixelsToScroll, remainingPixels) : Math.max(-pixelsToScroll, -remainingPixels)\n );\n if (scrollRemaining) {\n frameRef.current = requestAnimationFrame(frame);\n }\n }\n }\n cancelAnimationFrame(frameRef.current);\n frameRef.current = requestAnimationFrame(frame);\n }),\n onPointerLeave: composeEventHandlers(onPointerLeave, () => {\n statusRef.current = \"idle\";\n cancelAnimationFrame(frameRef.current);\n })\n }\n );\n }\n )\n);\nexport {\n SelectScrollButtonFrame,\n SelectScrollDownButton,\n SelectScrollUpButton\n};\n//# sourceMappingURL=SelectScrollButton.js.map\n"],"mappings":";;;;;;;;;;AAQA,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B,OAAO,MAAM,EAC3C,aAAa,qBACf,CAAC;AACD,MAAM,uBAAuB,gBAC3B,0BACC,OAAO,iBAAiB;CACvB,OAAuB,oBACrB,wBACA;EACE,eAAe,MAAM;EACrB,GAAG;EACH,KAAK;EACL,KAAK;CACP,CACF;AACF,CACF;AACA,qBAAqB,cAAc;AACnC,MAAM,0BAA0B;AAChC,MAAM,yBAAyB,gBAC7B,0BACC,OAAO,iBAAiB;CACvB,OAAuB,oBACrB,wBACA;EACE,eAAe,MAAM;EACrB,GAAG;EACH,KAAK;EACL,KAAK;CACP,CACF;AACF,CACF;AACA,uBAAuB,cAAc;AACrC,MAAM,yBAAyB,MAAM,KACnC,gBACE,0BACC,OAAO,iBAAiB;CACvB,MAAM,EAAE,OAAO,KAAK,eAAe,GA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;EACV,OAAO,SAAS,aAAa,SAAS,eAAe,KAAK,EAAE;EAC5D,gBAAgB,qBAAqB,sBAAsB;GACzD,UAAU,UAAU;GACpB,IAAI,UAAU,KAAK,IAAI;GACvB,SAAS,QAAQ;IACf,MAAM,UAAU,aAAa;IAC7B,IAAI,SAAS;KACX,MAAM,aAAa,KAAK,IAAI;KAC5B,MAAM,YAAY,aAAa;KAC/B,UAAU;KACV,MAAM,iBAAiB,YAAY;KACnC,MAAM,kBAAkB,QAAQ,OAAO,QAAQ,YAAY,QAAQ,eAAe,QAAQ,eAAe,QAAQ;KACjH,MAAM,kBAAkB,QAAQ,OAAO,QAAQ,YAAY,iBAAiB,IAAI,QAAQ,YAAY,iBAAiB,QAAQ,eAAe,QAAQ;KACpJ,SACE,QAAQ,OAAO,KAAK,IAAI,gBAAgB,eAAe,IAAI,KAAK,IAAI,CAAC,gBAAgB,CAAC,eAAe,CACvG;KACA,IAAI,iBAAiB;MACnB,SAAS,UAAU,sBAAsB,KAAK;KAChD;IACF;GACF;GACA,qBAAqB,SAAS,OAAO;GACrC,SAAS,UAAU,sBAAsB,KAAK;EAChD,CAAC;EACD,gBAAgB,qBAAqB,sBAAsB;GACzD,UAAU,UAAU;GACpB,qBAAqB,SAAS,OAAO;EACvC,CAAC;CACH,CACF;AACF,CACF,CACF"}
|
|
@@ -2,6 +2,7 @@ import { useComposedRefs } from "@tamagui/compose-refs";
|
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
3
|
import { View, createChangeEventDetails, createStyledHOC, styled } from "@tamagui/core";
|
|
4
4
|
import { composeEventHandlers } from "@tamagui/helpers";
|
|
5
|
+
import * as React from "react";
|
|
5
6
|
import { useSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
|
|
@@ -16,19 +17,29 @@ const SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger
|
|
|
16
17
|
const context = useSelectContext(scope);
|
|
17
18
|
const itemParentContext = useSelectItemParentContext(scope);
|
|
18
19
|
const composedRefs = useComposedRefs(forwardedRef, context.floatingContext?.refs.setReference);
|
|
20
|
+
const pressIsTouch = React.useRef(false);
|
|
19
21
|
if (itemParentContext.shouldRenderWebNative) return null;
|
|
20
22
|
const toggleOpen = (event, reason = "trigger-press") => {
|
|
21
23
|
if (!disabled) itemParentContext.requestOpenChange(!context.open, createChangeEventDetails(reason, event?.nativeEvent || event, event?.currentTarget));
|
|
22
24
|
};
|
|
23
|
-
const interactionProps =
|
|
25
|
+
const interactionProps = context.interactions ? context.interactions.getReferenceProps({
|
|
24
26
|
...triggerProps,
|
|
25
27
|
onMouseDown: composeEventHandlers(triggerProps.onMouseDown, () => context.floatingContext?.update?.())
|
|
26
28
|
}) : {
|
|
27
29
|
...triggerProps,
|
|
28
|
-
...isWeb ? {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
...isWeb ? {
|
|
31
|
+
onMouseDown: composeEventHandlers(triggerProps.onMouseDown, (event) => {
|
|
32
|
+
pressIsTouch.current = event.type === "touchstart";
|
|
33
|
+
if (pressIsTouch.current) return;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
toggleOpen(event);
|
|
36
|
+
}),
|
|
37
|
+
onPress: composeEventHandlers(triggerProps.onPress, (event) => {
|
|
38
|
+
if (!pressIsTouch.current) return;
|
|
39
|
+
pressIsTouch.current = false;
|
|
40
|
+
toggleOpen(event);
|
|
41
|
+
})
|
|
42
|
+
} : { onPress: composeEventHandlers(triggerProps.onPress, toggleOpen) },
|
|
32
43
|
onKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {
|
|
33
44
|
if (event.key === "Enter" || event.key === " ") {
|
|
34
45
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectTrigger.js","names":[],"sources":["esm/SelectTrigger.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { View, createChangeEventDetails, createStyledHOC, styled } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\n\nconst SelectTriggerFrame = styled(View, {\n\tdisplayName: \"SelectTrigger\",\n\talignItems: \"center\",\n\tflexDirection: \"row\",\n\trender: /* @__PURE__ */ jsx(\"button\", { type: \"button\" })\n});\nconst SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger2(props, forwardedRef) {\n\tconst { scope, disabled = false, ...triggerProps } = props;\n\tconst context = useSelectContext(scope);\n\tconst itemParentContext = useSelectItemParentContext(scope);\n\tconst composedRefs = useComposedRefs(forwardedRef, context.floatingContext?.refs.setReference);\n\tif (itemParentContext.shouldRenderWebNative) return null;\n\tconst toggleOpen = (event, reason = \"trigger-press\") => {\n\t\tif (!disabled) itemParentContext.requestOpenChange(!context.open, createChangeEventDetails(reason, event?.nativeEvent || event, event?.currentTarget));\n\t};\n\tconst interactionProps =
|
|
1
|
+
{"version":3,"file":"SelectTrigger.js","names":[],"sources":["esm/SelectTrigger.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { View, createChangeEventDetails, createStyledHOC, styled } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\n\nconst SelectTriggerFrame = styled(View, {\n\tdisplayName: \"SelectTrigger\",\n\talignItems: \"center\",\n\tflexDirection: \"row\",\n\trender: /* @__PURE__ */ jsx(\"button\", { type: \"button\" })\n});\nconst SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger2(props, forwardedRef) {\n\tconst { scope, disabled = false, ...triggerProps } = props;\n\tconst context = useSelectContext(scope);\n\tconst itemParentContext = useSelectItemParentContext(scope);\n\tconst composedRefs = useComposedRefs(forwardedRef, context.floatingContext?.refs.setReference);\n\tconst pressIsTouch = React.useRef(false);\n\tif (itemParentContext.shouldRenderWebNative) return null;\n\tconst toggleOpen = (event, reason = \"trigger-press\") => {\n\t\tif (!disabled) itemParentContext.requestOpenChange(!context.open, createChangeEventDetails(reason, event?.nativeEvent || event, event?.currentTarget));\n\t};\n\tconst interactionProps = context.interactions ? context.interactions.getReferenceProps({\n\t\t...triggerProps,\n\t\tonMouseDown: composeEventHandlers(triggerProps.onMouseDown, () => context.floatingContext?.update?.())\n\t}) : {\n\t\t...triggerProps,\n\t\t...isWeb ? {\n\t\t\tonMouseDown: composeEventHandlers(triggerProps.onMouseDown, (event) => {\n\t\t\t\tpressIsTouch.current = event.type === \"touchstart\";\n\t\t\t\tif (pressIsTouch.current) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleOpen(event);\n\t\t\t}),\n\t\t\tonPress: composeEventHandlers(triggerProps.onPress, (event) => {\n\t\t\t\tif (!pressIsTouch.current) return;\n\t\t\t\tpressIsTouch.current = false;\n\t\t\t\ttoggleOpen(event);\n\t\t\t})\n\t\t} : { onPress: composeEventHandlers(triggerProps.onPress, toggleOpen) },\n\t\tonKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {\n\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleOpen(event, \"keyboard\");\n\t\t\t}\n\t\t})\n\t};\n\treturn /* @__PURE__ */ jsx(SelectTriggerFrame, {\n\t\ttype: \"button\",\n\t\tid: itemParentContext.id,\n\t\trole: \"combobox\",\n\t\t\"aria-haspopup\": \"listbox\",\n\t\t\"aria-expanded\": context.open,\n\t\t\"data-state\": context.open ? \"open\" : \"closed\",\n\t\t\"aria-autocomplete\": \"none\",\n\t\taccessibilityRole: isWeb ? void 0 : \"button\",\n\t\taccessibilityState: isWeb ? void 0 : {\n\t\t\texpanded: context.open,\n\t\t\tdisabled\n\t\t},\n\t\tdir: context.dir,\n\t\tdisabled,\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...interactionProps,\n\t\tref: composedRefs\n\t});\n});\n\nexport { SelectTrigger, SelectTriggerFrame };"],"mappings":";;;;;;;;;AAQA,MAAM,qBAAqB,OAAO,MAAM;CACvC,aAAa;CACb,YAAY;CACZ,eAAe;CACf,QAAwB,oBAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACzD,CAAC;AACD,MAAM,gBAAgB,gBAAgB,oBAAoB,SAAS,eAAe,OAAO,cAAc;CACtG,MAAM,EAAE,OAAO,WAAW,OAAO,GAAG,iBAAiB;CACrD,MAAM,UAAU,iBAAiB,KAAK;CACtC,MAAM,oBAAoB,2BAA2B,KAAK;CAC1D,MAAM,eAAe,gBAAgB,cAAc,QAAQ,iBAAiB,KAAK,YAAY;CAC7F,MAAM,eAAe,MAAM,OAAO,KAAK;CACvC,IAAI,kBAAkB,uBAAuB,OAAO;CACpD,MAAM,cAAc,OAAO,SAAS,oBAAoB;EACvD,IAAI,CAAC,UAAU,kBAAkB,kBAAkB,CAAC,QAAQ,MAAM,yBAAyB,QAAQ,OAAO,eAAe,OAAO,OAAO,aAAa,CAAC;CACtJ;CACA,MAAM,mBAAmB,QAAQ,eAAe,QAAQ,aAAa,kBAAkB;EACtF,GAAG;EACH,aAAa,qBAAqB,aAAa,mBAAmB,QAAQ,iBAAiB,SAAS,CAAC;CACtG,CAAC,IAAI;EACJ,GAAG;EACH,GAAG,QAAQ;GACV,aAAa,qBAAqB,aAAa,cAAc,UAAU;IACtE,aAAa,UAAU,MAAM,SAAS;IACtC,IAAI,aAAa,SAAS;IAC1B,MAAM,eAAe;IACrB,WAAW,KAAK;GACjB,CAAC;GACD,SAAS,qBAAqB,aAAa,UAAU,UAAU;IAC9D,IAAI,CAAC,aAAa,SAAS;IAC3B,aAAa,UAAU;IACvB,WAAW,KAAK;GACjB,CAAC;EACF,IAAI,EAAE,SAAS,qBAAqB,aAAa,SAAS,UAAU,EAAE;EACtE,WAAW,qBAAqB,aAAa,YAAY,UAAU;GAClE,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;IAC/C,MAAM,eAAe;IACrB,WAAW,OAAO,UAAU;GAC7B;EACD,CAAC;CACF;CACA,OAAuB,oBAAI,oBAAoB;EAC9C,MAAM;EACN,IAAI,kBAAkB;EACtB,MAAM;EACN,iBAAiB;EACjB,iBAAiB,QAAQ;EACzB,cAAc,QAAQ,OAAO,SAAS;EACtC,qBAAqB;EACrB,mBAAmB,QAAQ,KAAK,IAAI;EACpC,oBAAoB,QAAQ,KAAK,IAAI;GACpC,UAAU,QAAQ;GAClB;EACD;EACA,KAAK,QAAQ;EACb;EACA,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;EACH,KAAK;CACN,CAAC;AACF,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { useComposedRefs } from "@tamagui/compose-refs";
|
|
|
3
3
|
import { isWeb } from "@tamagui/constants";
|
|
4
4
|
import { View, createChangeEventDetails, createStyledHOC, styled } from "@tamagui/core";
|
|
5
5
|
import { composeEventHandlers } from "@tamagui/helpers";
|
|
6
|
+
import * as React from "react";
|
|
6
7
|
import { useSelectContext, useSelectItemParentContext } from "./context.native.js";
|
|
7
8
|
|
|
8
9
|
var SelectTriggerFrame = styled(View, {
|
|
@@ -17,6 +18,7 @@ var SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger2(
|
|
|
17
18
|
var context = useSelectContext(scope);
|
|
18
19
|
var itemParentContext = useSelectItemParentContext(scope);
|
|
19
20
|
var composedRefs = useComposedRefs(forwardedRef, (_context_floatingContext = context.floatingContext) === null || _context_floatingContext === void 0 ? void 0 : _context_floatingContext.refs.setReference);
|
|
21
|
+
var pressIsTouch = React.useRef(false);
|
|
20
22
|
if (itemParentContext.shouldRenderWebNative) return null;
|
|
21
23
|
var toggleOpen = function(event) {
|
|
22
24
|
var reason = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "trigger-press";
|
|
@@ -24,10 +26,19 @@ var SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger2(
|
|
|
24
26
|
};
|
|
25
27
|
var interactionProps = {
|
|
26
28
|
...triggerProps,
|
|
27
|
-
...isWeb ? {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
...isWeb ? {
|
|
30
|
+
onMouseDown: composeEventHandlers(triggerProps.onMouseDown, function(event) {
|
|
31
|
+
pressIsTouch.current = event.type === "touchstart";
|
|
32
|
+
if (pressIsTouch.current) return;
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
toggleOpen(event);
|
|
35
|
+
}),
|
|
36
|
+
onPress: composeEventHandlers(triggerProps.onPress, function(event) {
|
|
37
|
+
if (!pressIsTouch.current) return;
|
|
38
|
+
pressIsTouch.current = false;
|
|
39
|
+
toggleOpen(event);
|
|
40
|
+
})
|
|
41
|
+
} : { onPress: composeEventHandlers(triggerProps.onPress, toggleOpen) },
|
|
31
42
|
onKeyDown: composeEventHandlers(triggerProps.onKeyDown, function(event) {
|
|
32
43
|
if (event.key === "Enter" || event.key === " ") {
|
|
33
44
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectTrigger.native.js","names":[],"sources":["esm/SelectTrigger.native.js"],"sourcesContent":["import { jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { View, createChangeEventDetails, createStyledHOC, styled } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\
|
|
1
|
+
{"version":3,"file":"SelectTrigger.native.js","names":[],"sources":["esm/SelectTrigger.native.js"],"sourcesContent":["import { jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { View, createChangeEventDetails, createStyledHOC, styled } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectContext, useSelectItemParentContext } from \"./context\";\n\nvar SelectTriggerFrame = styled(View, {\n\tdisplayName: \"SelectTrigger\",\n\talignItems: \"center\",\n\tflexDirection: \"row\",\n\trender: /* @__PURE__ */ jsx(\"button\", { type: \"button\" })\n});\nvar SelectTrigger = createStyledHOC(SelectTriggerFrame, function SelectTrigger2(props, forwardedRef) {\n\tvar _context_floatingContext;\n\tvar { scope, disabled = false, ...triggerProps } = props;\n\tvar context = useSelectContext(scope);\n\tvar itemParentContext = useSelectItemParentContext(scope);\n\tvar composedRefs = useComposedRefs(forwardedRef, (_context_floatingContext = context.floatingContext) === null || _context_floatingContext === void 0 ? void 0 : _context_floatingContext.refs.setReference);\n\tvar pressIsTouch = React.useRef(false);\n\tif (itemParentContext.shouldRenderWebNative) return null;\n\tvar toggleOpen = function(event) {\n\t\tvar reason = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : \"trigger-press\";\n\t\tif (!disabled) itemParentContext.requestOpenChange(!context.open, createChangeEventDetails(reason, (event === null || event === void 0 ? void 0 : event.nativeEvent) || event, event === null || event === void 0 ? void 0 : event.currentTarget));\n\t};\n\tvar interactionProps = {\n\t\t...triggerProps,\n\t\t...isWeb ? {\n\t\t\tonMouseDown: composeEventHandlers(triggerProps.onMouseDown, function(event) {\n\t\t\t\tpressIsTouch.current = event.type === \"touchstart\";\n\t\t\t\tif (pressIsTouch.current) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleOpen(event);\n\t\t\t}),\n\t\t\tonPress: composeEventHandlers(triggerProps.onPress, function(event) {\n\t\t\t\tif (!pressIsTouch.current) return;\n\t\t\t\tpressIsTouch.current = false;\n\t\t\t\ttoggleOpen(event);\n\t\t\t})\n\t\t} : { onPress: composeEventHandlers(triggerProps.onPress, toggleOpen) },\n\t\tonKeyDown: composeEventHandlers(triggerProps.onKeyDown, function(event) {\n\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleOpen(event, \"keyboard\");\n\t\t\t}\n\t\t})\n\t};\n\treturn /* @__PURE__ */ jsx(SelectTriggerFrame, {\n\t\ttype: \"button\",\n\t\tid: itemParentContext.id,\n\t\trole: \"combobox\",\n\t\t\"aria-haspopup\": \"listbox\",\n\t\t\"aria-expanded\": context.open,\n\t\t\"aria-autocomplete\": \"none\",\n\t\taccessibilityRole: isWeb ? void 0 : \"button\",\n\t\taccessibilityState: isWeb ? void 0 : {\n\t\t\texpanded: context.open,\n\t\t\tdisabled\n\t\t},\n\t\tdir: context.dir,\n\t\tdisabled,\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...interactionProps,\n\t\tref: composedRefs\n\t});\n});\n\nexport { SelectTrigger, SelectTriggerFrame };"],"mappings":";;;;;;;;;AAQA,IAAI,qBAAqB,OAAO,MAAM;CACrC,aAAa;CACb,YAAY;CACZ,eAAe;CACf,QAAwB,oBAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACzD,CAAC;AACD,IAAI,gBAAgB,gBAAgB,oBAAoB,SAAS,eAAe,OAAO,cAAc;CACpG,IAAI;CACJ,IAAI,EAAE,OAAO,WAAW,OAAO,GAAG,iBAAiB;CACnD,IAAI,UAAU,iBAAiB,KAAK;CACpC,IAAI,oBAAoB,2BAA2B,KAAK;CACxD,IAAI,eAAe,gBAAgB,eAAe,2BAA2B,QAAQ,qBAAqB,QAAQ,6BAA6B,KAAK,IAAI,KAAK,IAAI,yBAAyB,KAAK,YAAY;CAC3M,IAAI,eAAe,MAAM,OAAO,KAAK;CACrC,IAAI,kBAAkB,uBAAuB,OAAO;CACpD,IAAI,aAAa,SAAS,OAAO;EAChC,IAAI,SAAS,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;EAC9E,IAAI,CAAC,UAAU,kBAAkB,kBAAkB,CAAC,QAAQ,MAAM,yBAAyB,SAAS,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,gBAAgB,OAAO,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,aAAa,CAAC;CAClP;CACA,IAAI,mBAAmB;EACtB,GAAG;EACH,GAAG,QAAQ;GACV,aAAa,qBAAqB,aAAa,aAAa,SAAS,OAAO;IAC3E,aAAa,UAAU,MAAM,SAAS;IACtC,IAAI,aAAa,SAAS;IAC1B,MAAM,eAAe;IACrB,WAAW,KAAK;GACjB,CAAC;GACD,SAAS,qBAAqB,aAAa,SAAS,SAAS,OAAO;IACnE,IAAI,CAAC,aAAa,SAAS;IAC3B,aAAa,UAAU;IACvB,WAAW,KAAK;GACjB,CAAC;EACF,IAAI,EAAE,SAAS,qBAAqB,aAAa,SAAS,UAAU,EAAE;EACtE,WAAW,qBAAqB,aAAa,WAAW,SAAS,OAAO;GACvE,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;IAC/C,MAAM,eAAe;IACrB,WAAW,OAAO,UAAU;GAC7B;EACD,CAAC;CACF;CACA,OAAuB,oBAAI,oBAAoB;EAC9C,MAAM;EACN,IAAI,kBAAkB;EACtB,MAAM;EACN,iBAAiB;EACjB,iBAAiB,QAAQ;EACzB,qBAAqB;EACrB,mBAAmB,QAAQ,KAAK,IAAI;EACpC,oBAAoB,QAAQ,KAAK,IAAI;GACpC,UAAU,QAAQ;GAClB;EACD;EACA,KAAK,QAAQ;EACb;EACA,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;EACH,KAAK;CACN,CAAC;AACF,CAAC"}
|
|
@@ -5,7 +5,6 @@ import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
|
5
5
|
import { View, createStyledHOC, styled } from "@tamagui/core";
|
|
6
6
|
import { needsPortalRepropagation } from "@tamagui/portal";
|
|
7
7
|
import { YStack } from "@tamagui/stacks";
|
|
8
|
-
import { startTransition } from "@tamagui/start-transition";
|
|
9
8
|
import * as React from "react";
|
|
10
9
|
import { VIEWPORT_NAME } from "./constants.mjs";
|
|
11
10
|
import { ForwardSelectContext, useSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
@@ -24,19 +23,9 @@ const SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewp
|
|
|
24
23
|
const isAdapted = useAdaptIsActive(context.adaptScope);
|
|
25
24
|
const viewportRef = React.useRef(null);
|
|
26
25
|
const registeredItemCount = itemContext.registry.getItems().length;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!context.open) return;
|
|
31
|
-
if (lazyMounted) return;
|
|
32
|
-
startTransition(() => {
|
|
33
|
-
setLazyMounted(true);
|
|
34
|
-
});
|
|
35
|
-
}, [
|
|
36
|
-
context.lazyMount,
|
|
37
|
-
context.open,
|
|
38
|
-
lazyMounted
|
|
39
|
-
]);
|
|
26
|
+
const hasOpenedRef = React.useRef(!context.lazyMount);
|
|
27
|
+
if (context.open) hasOpenedRef.current = true;
|
|
28
|
+
const lazyMounted = hasOpenedRef.current;
|
|
40
29
|
React.useEffect(() => {
|
|
41
30
|
if (!isWeb || !isAdapted || !context.open) return;
|
|
42
31
|
const frame = requestAnimationFrame(() => {
|
|
@@ -46,7 +35,6 @@ const SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewp
|
|
|
46
35
|
});
|
|
47
36
|
return () => cancelAnimationFrame(frame);
|
|
48
37
|
}, [
|
|
49
|
-
context.activeIndex,
|
|
50
38
|
context.open,
|
|
51
39
|
isAdapted,
|
|
52
40
|
registeredItemCount
|
|
@@ -58,11 +46,11 @@ const SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewp
|
|
|
58
46
|
}
|
|
59
47
|
}, [isAdapted]);
|
|
60
48
|
React.useEffect(() => {
|
|
61
|
-
if (context.lazyMount &&
|
|
49
|
+
if (context.lazyMount && context.open && context.update) {
|
|
62
50
|
const frame = requestAnimationFrame(context.update);
|
|
63
51
|
return () => cancelAnimationFrame(frame);
|
|
64
52
|
}
|
|
65
|
-
}, [
|
|
53
|
+
}, [context.open, registeredItemCount]);
|
|
66
54
|
if (itemContext.shouldRenderWebNative) {
|
|
67
55
|
return /* @__PURE__ */ jsx(YStack, {
|
|
68
56
|
position: "relative",
|
|
@@ -89,23 +77,27 @@ const SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewp
|
|
|
89
77
|
children: content
|
|
90
78
|
});
|
|
91
79
|
}
|
|
92
|
-
if (!
|
|
80
|
+
if (!context.interactions) {
|
|
93
81
|
return null;
|
|
94
82
|
}
|
|
95
|
-
const
|
|
83
|
+
const floatingProps = context.interactions.getFloatingProps();
|
|
96
84
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
97
85
|
!disableScroll && /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: selectViewportCSS } }),
|
|
98
|
-
/* @__PURE__ */ jsx(AnimatePresence, {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
86
|
+
/* @__PURE__ */ jsx(AnimatePresence, {
|
|
87
|
+
presenceAffectsLayout: false,
|
|
88
|
+
children: context.open ? /* @__PURE__ */ jsx(SelectViewportFrame, {
|
|
89
|
+
"data-select-viewport": "",
|
|
90
|
+
...isWeb && { "data-state": context.open ? "open" : "closed" },
|
|
91
|
+
...viewportProps,
|
|
92
|
+
...context.floatingPosition,
|
|
93
|
+
outlineWidth: 0,
|
|
94
|
+
...floatingProps,
|
|
95
|
+
...getSelectListboxProps(itemContext.mode),
|
|
96
|
+
overflowY: disableScroll ? void 0 : "auto",
|
|
97
|
+
ref: composedRefs,
|
|
98
|
+
children: lazyMounted ? children : null
|
|
99
|
+
}, "select-viewport") : null
|
|
100
|
+
}),
|
|
109
101
|
!context.open && !(context.lazyMount && context.renderValue) && lazyMounted && /* @__PURE__ */ jsx("div", {
|
|
110
102
|
style: { display: "none" },
|
|
111
103
|
children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectViewport.js","names":[],"sources":["esm/SelectViewport.js"],"sourcesContent":["import { AdaptPortalContents, useAdaptIsActive } from \"@tamagui/adapt\";\nimport { AnimatePresence } from \"@tamagui/animate-presence\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createStyledHOC, styled, View } from \"@tamagui/core\";\nimport { needsPortalRepropagation } from \"@tamagui/portal\";\nimport { YStack } from \"@tamagui/stacks\";\nimport
|
|
1
|
+
{"version":3,"file":"SelectViewport.js","names":[],"sources":["esm/SelectViewport.js"],"sourcesContent":["import { AdaptPortalContents, useAdaptIsActive } from \"@tamagui/adapt\";\nimport { AnimatePresence } from \"@tamagui/animate-presence\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createStyledHOC, styled, View } from \"@tamagui/core\";\nimport { needsPortalRepropagation } from \"@tamagui/portal\";\nimport { YStack } from \"@tamagui/stacks\";\nimport * as React from \"react\";\nimport { VIEWPORT_NAME } from \"./constants\";\nimport {\n ForwardSelectContext,\n useSelectContext,\n useSelectItemParentContext\n} from \"./context\";\nimport { getSelectListboxProps } from \"./selectionController\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst SelectViewportFrame = styled(View, {\n displayName: VIEWPORT_NAME,\n position: \"relative\"\n});\nconst needsRepropagation = needsPortalRepropagation();\nconst SelectViewport = createStyledHOC(\n SelectViewportFrame,\n function SelectViewport2(props, forwardedRef) {\n const { scope, children, disableScroll, ...viewportProps } = props;\n const context = useSelectContext(scope);\n const itemContext = useSelectItemParentContext(scope);\n const isAdapted = useAdaptIsActive(context.adaptScope);\n const viewportRef = React.useRef(null);\n const registeredItemCount = itemContext.registry.getItems().length;\n const hasOpenedRef = React.useRef(!context.lazyMount);\n if (context.open) hasOpenedRef.current = true;\n const lazyMounted = hasOpenedRef.current;\n React.useEffect(() => {\n if (!isWeb || !isAdapted || !context.open) return;\n const frame = requestAnimationFrame(() => {\n const index = context.activeIndexRef.current ?? itemContext.registry.firstEnabledIndex();\n const activeItem = viewportRef.current?.querySelector(\n '[role=\"option\"][tabindex=\"0\"]'\n ) ?? (index >= 0 ? itemContext.listRef?.current[index] : null);\n activeItem?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }, [context.open, isAdapted, registeredItemCount]);\n const composedRefs = useComposedRefs(\n // @ts-ignore react 19 ref type mismatch\n forwardedRef,\n viewportRef,\n context.floatingContext?.refs.setFloating\n );\n useIsomorphicLayoutEffect(() => {\n if (context.update) {\n context.update();\n }\n }, [isAdapted]);\n React.useEffect(() => {\n if (context.lazyMount && context.open && context.update) {\n const frame = requestAnimationFrame(context.update);\n return () => cancelAnimationFrame(frame);\n }\n }, [context.open, registeredItemCount]);\n if (itemContext.shouldRenderWebNative) {\n return /* @__PURE__ */ jsx(YStack, { position: \"relative\", children });\n }\n if (isAdapted || !isWeb) {\n let content = /* @__PURE__ */ jsx(\n SelectViewportFrame,\n {\n ...viewportProps,\n ...isWeb ? getSelectListboxProps(itemContext.mode) : {},\n \"data-select-viewport\": \"\",\n ref: composedRefs,\n children: lazyMounted ? children : null\n }\n );\n if (needsRepropagation) {\n content = /* @__PURE__ */ jsx(ForwardSelectContext, { itemContext, context, children: content });\n }\n return /* @__PURE__ */ jsx(AdaptPortalContents, { scope: context.adaptScope, children: content });\n }\n if (!context.interactions) {\n return null;\n }\n const floatingProps = context.interactions.getFloatingProps();\n return /* @__PURE__ */ jsxs(Fragment, { children: [\n !disableScroll && /* @__PURE__ */ jsx(\n \"style\",\n {\n dangerouslySetInnerHTML: {\n __html: selectViewportCSS\n }\n }\n ),\n /* @__PURE__ */ jsx(AnimatePresence, { presenceAffectsLayout: false, children: context.open ? /* @__PURE__ */ jsx(\n SelectViewportFrame,\n {\n \"data-select-viewport\": \"\",\n ...isWeb && {\n \"data-state\": context.open ? \"open\" : \"closed\"\n },\n ...viewportProps,\n ...context.floatingPosition,\n outlineWidth: 0,\n ...floatingProps,\n ...getSelectListboxProps(itemContext.mode),\n overflowY: disableScroll ? void 0 : \"auto\",\n ref: composedRefs,\n children: lazyMounted ? children : null\n },\n \"select-viewport\"\n ) : null }),\n !context.open && !(context.lazyMount && context.renderValue) && lazyMounted && /* @__PURE__ */ jsx(\"div\", { style: { display: \"none\" }, children })\n ] });\n }\n);\nconst selectViewportCSS = `\n[data-select-viewport] {\n scrollbar-width: none;\n -webkit-overflow-scrolling: touch;\n overscroll-behavior: contain;\n}\n\n[data-select-viewport]::-webkit-scrollbar{\n display:none\n}\n`;\nexport {\n SelectViewport,\n SelectViewportFrame\n};\n//# sourceMappingURL=SelectViewport.js.map\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,sBAAsB,OAAO,MAAM;CACvC,aAAa;CACb,UAAU;AACZ,CAAC;AACD,MAAM,qBAAqB,yBAAyB;AACpD,MAAM,iBAAiB,gBACrB,qBACA,SAAS,gBAAgB,OAAO,cAAc;CAC5C,MAAM,EAAE,OAAO,UAAU,eAAe,GAAG,kBAAkB;CAC7D,MAAM,UAAU,iBAAiB,KAAK;CACtC,MAAM,cAAc,2BAA2B,KAAK;CACpD,MAAM,YAAY,iBAAiB,QAAQ,UAAU;CACrD,MAAM,cAAc,MAAM,OAAO,IAAI;CACrC,MAAM,sBAAsB,YAAY,SAAS,SAAS,CAAC,CAAC;CAC5D,MAAM,eAAe,MAAM,OAAO,CAAC,QAAQ,SAAS;CACpD,IAAI,QAAQ,MAAM,aAAa,UAAU;CACzC,MAAM,cAAc,aAAa;CACjC,MAAM,gBAAgB;EACpB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,MAAM;EAC3C,MAAM,QAAQ,4BAA4B;GACxC,MAAM,QAAQ,QAAQ,eAAe,WAAW,YAAY,SAAS,kBAAkB;GACvF,MAAM,aAAa,YAAY,SAAS,cACtC,mCACF,MAAM,SAAS,IAAI,Y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S,EACV,cAAc,QAAQ,OAAO,SAAS,SACxC;IACA,GAAG;IACH,GAAG,QAAQ;IACX,cAAc;IACd,GAAG;IACH,GAAG,sBAAsB,YAAY,IAAI;IACzC,WAAW,gBAAgB,KAAK,IAAI;IACpC,KAAK;IACL,UAAU,cAAc,WAAW;GACrC,GACA,iBACF,IAAI;EAAK,CAAC;EACV,CAAC,QAAQ,QAAQ,EAAE,QAAQ,aAAa,QAAQ,gBAAgB,eAA+B,oBAAI,OAAO;GAAE,OAAO,EAAE,SAAS,OAAO;GAAG;EAAS,CAAC;CACpJ,EAAE,CAAC;AACL,CACF;AACA,MAAM,oBAAoB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive } from "@tamagui/adapt";
|
|
3
3
|
import { Theme, View, createStyledHOC, styled, useThemeName } from "@tamagui/core";
|
|
4
4
|
import { VIEWPORT_NAME } from "./constants.native.js";
|
|
5
5
|
import { ForwardSelectContext, useSelectContext, useSelectItemParentContext } from "./context.native.js";
|
|
@@ -13,14 +13,14 @@ var SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewpor
|
|
|
13
13
|
var context = useSelectContext(scope);
|
|
14
14
|
var itemParentContext = useSelectItemParentContext(scope);
|
|
15
15
|
var themeName = useThemeName();
|
|
16
|
-
var adaptContext = useAdaptContext();
|
|
16
|
+
var adaptContext = useAdaptContext(context.adaptScope);
|
|
17
17
|
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
18
18
|
var contents = /* @__PURE__ */ jsx(Theme, {
|
|
19
19
|
name: themeName,
|
|
20
20
|
children: /* @__PURE__ */ jsx(ForwardSelectContext, {
|
|
21
21
|
itemContext: itemParentContext,
|
|
22
22
|
context,
|
|
23
|
-
children: /* @__PURE__ */ jsx(
|
|
23
|
+
children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
|
|
24
24
|
...adaptContext,
|
|
25
25
|
children: /* @__PURE__ */ jsx(SelectViewportFrame, {
|
|
26
26
|
...viewportProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectViewport.native.js","names":[],"sources":["esm/SelectViewport.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport {
|
|
1
|
+
{"version":3,"file":"SelectViewport.native.js","names":[],"sources":["esm/SelectViewport.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { AdaptPortalContents, ProvideAdaptContext, useAdaptContext, useAdaptIsActive } from \"@tamagui/adapt\";\nimport { createStyledHOC, styled, Theme, useThemeName, View } from \"@tamagui/core\";\nimport { VIEWPORT_NAME } from \"./constants\";\nimport { ForwardSelectContext, useSelectContext, useSelectItemParentContext } from \"./context\";\nvar SelectViewportFrame = styled(View, {\n displayName: VIEWPORT_NAME,\n position: \"relative\"\n});\nvar SelectViewport = createStyledHOC(SelectViewportFrame, function SelectViewport2(props, forwardedRef) {\n var { scope, children, disableScroll: _disableScroll, ...viewportProps } = props;\n var context = useSelectContext(scope);\n var itemParentContext = useSelectItemParentContext(scope);\n var themeName = useThemeName();\n var adaptContext = useAdaptContext(context.adaptScope);\n var isAdapted = useAdaptIsActive(context.adaptScope);\n var contents = /* @__PURE__ */ _jsx(Theme, {\n name: themeName,\n children: /* @__PURE__ */ _jsx(ForwardSelectContext, {\n itemContext: itemParentContext,\n context,\n children: /* @__PURE__ */ _jsx(ProvideAdaptContext, {\n ...adaptContext,\n children: /* @__PURE__ */ _jsx(SelectViewportFrame, {\n ...viewportProps,\n ref: forwardedRef,\n children\n })\n })\n })\n });\n if (!context.open) {\n if (context.lazyMount && context.renderValue) return null;\n return /* @__PURE__ */ _jsx(SelectViewportFrame, {\n display: \"none\",\n children: contents\n });\n }\n return isAdapted ? /* @__PURE__ */ _jsx(AdaptPortalContents, {\n scope: context.adaptScope,\n children: contents\n }) : contents;\n});\nSelectViewport.displayName = VIEWPORT_NAME;\nexport {\n SelectViewport,\n SelectViewportFrame\n};\n//# sourceMappingURL=SelectViewport.native.js.map\n"],"mappings":";;;;;;;AAKA,IAAI,sBAAsB,OAAO,MAAM;CACrC,aAAa;CACb,UAAU;AACZ,CAAC;AACD,IAAI,iBAAiB,gBAAgB,qBAAqB,SAAS,gBAAgB,OAAO,cAAc;CACtG,IAAI,EAAE,OAAO,UAAU,eAAe,gBAAgB,GAAG,kBAAkB;CAC3E,IAAI,UAAU,iBAAiB,KAAK;CACpC,IAAI,oBAAoB,2BAA2B,KAAK;CACxD,IAAI,YAAY,aAAa;CAC7B,IAAI,eAAe,gBAAgB,QAAQ,UAAU;CACrD,IAAI,YAAY,iBAAiB,QAAQ,UAAU;CACnD,IAAI,WAA2B,oBAAK,OAAO;EACzC,MAAM;EACN,UAA0B,oBAAK,sBAAsB;GACnD,aAAa;GACb;GACA,UAA0B,oBAAK,qBAAqB;IAClD,GAAG;IACH,UAA0B,oBAAK,qBAAqB;KAClD,GAAG;KACH,KAAK;KACL;IACF,CAAC;GACH,CAAC;EACH,CAAC;CACH,CAAC;CACD,IAAI,CAAC,QAAQ,MAAM;EACjB,IAAI,QAAQ,aAAa,QAAQ,aAAa,OAAO;EACrD,OAAuB,oBAAK,qBAAqB;GAC/C,SAAS;GACT,UAAU;EACZ,CAAC;CACH;CACA,OAAO,YAA4B,oBAAK,qBAAqB;EAC3D,OAAO,QAAQ;EACf,UAAU;CACZ,CAAC,IAAI;AACP,CAAC;AACD,eAAe,cAAc"}
|
|
@@ -16,13 +16,24 @@ function createSelectItemRegistry(onChange) {
|
|
|
16
16
|
const explicitTextValues = /* @__PURE__ */ new Map();
|
|
17
17
|
const itemNodes = /* @__PURE__ */ new Map();
|
|
18
18
|
const listeners = /* @__PURE__ */ new Set();
|
|
19
|
+
let indexByValue = null;
|
|
19
20
|
const notify = () => {
|
|
21
|
+
indexByValue = null;
|
|
20
22
|
onChange?.();
|
|
21
23
|
listeners.forEach((listener) => listener());
|
|
22
24
|
};
|
|
23
25
|
const getItems = () => items;
|
|
24
26
|
const getItem = (value) => items.find((item) => item.value === value);
|
|
25
|
-
const getIndex = (value) =>
|
|
27
|
+
const getIndex = (value) => {
|
|
28
|
+
if (!indexByValue) {
|
|
29
|
+
indexByValue = /* @__PURE__ */ new Map();
|
|
30
|
+
items.forEach((item, index) => {
|
|
31
|
+
if (!indexByValue.has(item.value)) indexByValue.set(item.value, index);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return indexByValue.get(value) ?? -1;
|
|
35
|
+
};
|
|
36
|
+
const getNodes = () => items.map((item) => itemNodes.get(item.id) ?? null);
|
|
26
37
|
const getRegisteredLabel = (value) => {
|
|
27
38
|
const registrations = labelRegistrations.get(value);
|
|
28
39
|
if (!registrations?.size) return void 0;
|
|
@@ -45,7 +56,6 @@ function createSelectItemRegistry(onChange) {
|
|
|
45
56
|
if (changed) notify();
|
|
46
57
|
};
|
|
47
58
|
const syncNodeOrder = () => {
|
|
48
|
-
const previousOrder = items.map((item) => item.id);
|
|
49
59
|
items.sort((a, b) => {
|
|
50
60
|
const aNode = itemNodes.get(a.id);
|
|
51
61
|
const bNode = itemNodes.get(b.id);
|
|
@@ -57,9 +67,6 @@ function createSelectItemRegistry(onChange) {
|
|
|
57
67
|
if (position & 2) return 1;
|
|
58
68
|
return 0;
|
|
59
69
|
});
|
|
60
|
-
if (items.some((item, index) => item.id !== previousOrder[index])) {
|
|
61
|
-
notify();
|
|
62
|
-
}
|
|
63
70
|
};
|
|
64
71
|
const registerItem = (item) => {
|
|
65
72
|
const id = Symbol(item.value);
|
|
@@ -99,12 +106,14 @@ function createSelectItemRegistry(onChange) {
|
|
|
99
106
|
notify();
|
|
100
107
|
},
|
|
101
108
|
setNode(node) {
|
|
109
|
+
if ((itemNodes.get(id) ?? null) === (node ?? null)) return;
|
|
102
110
|
if (node) {
|
|
103
111
|
itemNodes.set(id, node);
|
|
104
112
|
syncNodeOrder();
|
|
105
113
|
} else {
|
|
106
114
|
itemNodes.delete(id);
|
|
107
115
|
}
|
|
116
|
+
notify();
|
|
108
117
|
},
|
|
109
118
|
unregister() {
|
|
110
119
|
const index = items.findIndex((current) => current.id === id);
|
|
@@ -179,6 +188,7 @@ function createSelectItemRegistry(onChange) {
|
|
|
179
188
|
getItems,
|
|
180
189
|
getItem,
|
|
181
190
|
getIndex,
|
|
191
|
+
getNodes,
|
|
182
192
|
firstEnabledIndex,
|
|
183
193
|
nextEnabledIndex,
|
|
184
194
|
findTypeaheadIndex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectionController.js","names":[],"sources":["esm/selectionController.js"],"sourcesContent":["function getSelectLabelText(label) {\n if (typeof label === \"string\" || typeof label === \"number\") {\n return String(label);\n }\n if (Array.isArray(label)) {\n return label.map(getSelectLabelText).join(\"\");\n }\n if (label && typeof label === \"object\" && \"props\" in label) {\n return getSelectLabelText(label.props?.children);\n }\n return \"\";\n}\nfunction createSelectItemRegistry(onChange) {\n const items = [];\n const labelRegistrations = /* @__PURE__ */ new Map();\n const explicitTextValues = /* @__PURE__ */ new Map();\n const itemNodes = /* @__PURE__ */ new Map();\n const listeners = /* @__PURE__ */ new Set();\n const notify = () => {\n onChange?.();\n listeners.forEach((listener) => listener());\n };\n const getItems = () => items;\n const getItem = (value) => items.find((item) => item.value === value);\n const getIndex = (value) => items.findIndex((item) => item.value === value);\n const getRegisteredLabel = (value) => {\n const registrations = labelRegistrations.get(value);\n if (!registrations?.size) return void 0;\n const values = Array.from(registrations.values());\n return values[values.length - 1];\n };\n const applyRegisteredLabel = (value) => {\n const registeredLabel = getRegisteredLabel(value);\n let changed = false;\n for (const item of items) {\n if (item.value !== value) continue;\n const nextLabel = registeredLabel?.label;\n const nextTextValue = explicitTextValues.get(item.id) || registeredLabel?.textValue;\n if (item.label !== nextLabel || item.textValue !== nextTextValue) {\n item.label = nextLabel;\n item.textValue = nextTextValue;\n changed = true;\n }\n }\n if (changed) notify();\n };\n const syncNodeOrder = () => {\n const previousOrder = items.map((item) => item.id);\n items.sort((a, b) => {\n const aNode = itemNodes.get(a.id);\n const bNode = itemNodes.get(b.id);\n if (!aNode || !bNode || typeof aNode.compareDocumentPosition !== \"function\") {\n return 0;\n }\n const position = aNode.compareDocumentPosition(bNode);\n if (position & 4) return -1;\n if (position & 2) return 1;\n return 0;\n });\n if (items.some((item, index) => item.id !== previousOrder[index])) {\n notify();\n }\n };\n const registerItem = (item) => {\n const id = Symbol(item.value);\n const registeredLabel = getRegisteredLabel(item.value);\n const registeredItem = {\n ...item,\n ...registeredLabel,\n textValue: item.textValue ?? registeredLabel?.textValue,\n id\n };\n explicitTextValues.set(id, item.textValue);\n items.push(registeredItem);\n notify();\n return {\n id,\n update(next) {\n const index = items.findIndex((current2) => current2.id === id);\n if (index < 0) return;\n const current = items[index];\n if (\"textValue\" in next) {\n explicitTextValues.set(id, next.textValue);\n }\n const nextItem = { ...current, ...next };\n if (next.value !== void 0 && next.value !== current.value) {\n const nextLabel = getRegisteredLabel(next.value);\n nextItem.label = nextLabel?.label;\n }\n const explicitTextValue = explicitTextValues.get(id);\n nextItem.textValue = explicitTextValue || getSelectLabelText(nextItem.label) || (nextItem.label ? nextItem.value : void 0);\n const changed = Object.entries(next).some(\n ([key, value]) => current[key] !== value\n );\n const textValueChanged = current.textValue !== nextItem.textValue;\n if (!changed && !textValueChanged) return;\n items[index] = nextItem;\n notify();\n },\n setNode(node) {\n if (node) {\n itemNodes.set(id, node);\n syncNodeOrder();\n } else {\n itemNodes.delete(id);\n }\n },\n unregister() {\n const index = items.findIndex((current) => current.id === id);\n if (index < 0) return;\n items.splice(index, 1);\n explicitTextValues.delete(id);\n itemNodes.delete(id);\n notify();\n }\n };\n };\n const registerLabel = (value, label, textValue) => {\n const id = Symbol(value);\n const normalizedTextValue = textValue || getSelectLabelText(label) || value;\n const registrations = labelRegistrations.get(value) ?? (() => {\n const next = /* @__PURE__ */ new Map();\n labelRegistrations.set(value, next);\n return next;\n })();\n registrations.set(id, { label, textValue: normalizedTextValue });\n applyRegisteredLabel(value);\n return () => {\n registrations.delete(id);\n if (!registrations.size) {\n labelRegistrations.delete(value);\n }\n applyRegisteredLabel(value);\n };\n };\n const firstEnabledIndex = () => items.findIndex((item) => !item.disabled);\n const nextEnabledIndex = (fromIndex, direction) => {\n if (!items.length) return -1;\n if (fromIndex == null || fromIndex < 0 || fromIndex >= items.length) {\n if (direction === 1) return firstEnabledIndex();\n for (let index = items.length - 1; index >= 0; index--) {\n if (!items[index].disabled) return index;\n }\n return -1;\n }\n for (let offset = 1; offset <= items.length; offset++) {\n const index = (fromIndex + direction * offset + items.length) % items.length;\n if (!items[index]?.disabled) return index;\n }\n return -1;\n };\n const findTypeaheadIndex = (search, fromIndex) => {\n const normalizedSearch = search.trim().toLocaleLowerCase();\n if (!normalizedSearch) return -1;\n const start = fromIndex == null || fromIndex < 0 ? -1 : fromIndex;\n for (let offset = 1; offset <= items.length; offset++) {\n const index = (start + offset) % items.length;\n const item = items[index];\n const label = item.textValue || getSelectLabelText(item.label) || item.value;\n if (!item.disabled && label.toLocaleLowerCase().startsWith(normalizedSearch)) {\n return index;\n }\n }\n return -1;\n };\n return {\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n registerItem,\n registerLabel,\n getItems,\n getItem,\n getIndex,\n firstEnabledIndex,\n nextEnabledIndex,\n findTypeaheadIndex,\n getDisabledIndices: () => items.flatMap((item, index) => item.disabled ? [index] : []),\n getTypeaheadLabels: () => items.map((item) => item.textValue || getSelectLabelText(item.label) || item.value)\n };\n}\nfunction normalizeSelectSelection(mode, value) {\n if (mode === \"single\") {\n return typeof value === \"string\" ? value : \"\";\n }\n const values = Array.isArray(value) ? value : [];\n return [...new Set(values)];\n}\nfunction selectedValuesFromSelection(mode, value) {\n const normalized = normalizeSelectSelection(mode, value);\n return mode === \"multiple\" ? normalized : normalized ? [normalized] : [];\n}\nfunction createSelectSelectionController({\n mode: initialMode,\n value: initialValue,\n registry\n}) {\n let mode = initialMode;\n let value = normalizeSelectSelection(mode, initialValue);\n let activeIndex = null;\n const selectedValues = () => selectedValuesFromSelection(mode, value);\n const setMode = (nextMode) => {\n if (mode === nextMode) return value;\n mode = nextMode;\n value = normalizeSelectSelection(mode, value);\n return value;\n };\n const setValue = (nextValue) => {\n value = normalizeSelectSelection(mode, nextValue);\n return value;\n };\n const isSelected = (itemValue) => selectedValues().includes(itemValue);\n const toggle = (itemValue) => {\n const item = registry.getItem(itemValue);\n if (!item || item.disabled) return value;\n if (mode === \"single\") {\n value = itemValue;\n return value;\n }\n const current = selectedValues();\n value = current.includes(itemValue) ? current.filter((currentValue) => currentValue !== itemValue) : [...current, itemValue];\n return value;\n };\n const selectionAnchor = () => {\n const values = selectedValues();\n for (let index = values.length - 1; index >= 0; index--) {\n const item = registry.getItem(values[index]);\n if (item) return item;\n }\n const firstEnabledIndex = registry.firstEnabledIndex();\n return firstEnabledIndex < 0 ? void 0 : registry.getItems()[firstEnabledIndex];\n };\n const selectionAnchorIndex = () => {\n const anchor = selectionAnchor();\n return anchor ? registry.getIndex(anchor.value) : -1;\n };\n const initialActiveIndex = () => {\n const anchorIndex = selectionAnchorIndex();\n const anchor = anchorIndex < 0 ? void 0 : registry.getItems()[anchorIndex];\n return anchor && !anchor.disabled ? anchorIndex : registry.firstEnabledIndex();\n };\n const moveActive = (direction) => {\n const nextIndex = registry.nextEnabledIndex(activeIndex, direction);\n activeIndex = nextIndex < 0 ? null : nextIndex;\n return activeIndex == null ? void 0 : registry.getItems()[activeIndex];\n };\n return {\n registry,\n get mode() {\n return mode;\n },\n get value() {\n return value;\n },\n get activeIndex() {\n return activeIndex;\n },\n get activeItem() {\n return activeIndex == null ? void 0 : registry.getItems()[activeIndex];\n },\n get shouldCloseOnSelect() {\n return mode === \"single\";\n },\n setMode,\n setValue,\n isSelected,\n toggle,\n selectionAnchor,\n selectionAnchorIndex,\n initialActiveIndex,\n setActiveIndex(index) {\n activeIndex = index;\n },\n moveActive\n };\n}\nfunction getSelectListboxProps(mode) {\n return {\n role: \"listbox\",\n \"aria-multiselectable\": mode === \"multiple\" ? true : void 0\n };\n}\nfunction getSelectOptionProps(mode, selected, disabled, platform) {\n if (platform === \"native\") {\n return {\n accessibilityRole: mode === \"multiple\" ? \"checkbox\" : \"button\",\n accessibilityState: {\n selected: mode === \"single\" ? selected : void 0,\n checked: mode === \"multiple\" ? selected : void 0,\n disabled\n }\n };\n }\n return {\n role: \"option\",\n \"aria-selected\": selected,\n \"aria-disabled\": disabled || void 0\n };\n}\nexport {\n createSelectItemRegistry,\n createSelectSelectionController,\n getSelectLabelText,\n getSelectListboxProps,\n getSelectOptionProps,\n normalizeSelectSelection,\n selectedValuesFromSelection\n};\n//# sourceMappingURL=selectionController.js.map\n"],"mappings":";AAAA,SAAS,mBAAmB,OAAO;CACjC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU;EAC1D,OAAO,OAAO,KAAK;CACrB;CACA,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,OAAO,MAAM,IAAI,kBAAkB,CAAC,CAAC,KAAK,EAAE;CAC9C;CACA,IAAI,SAAS,OAAO,UAAU,YAAY,WAAW,OAAO;EAC1D,OAAO,mBAAmB,MAAM,OAAO,QAAQ;CACjD;CACA,OAAO;AACT;AACA,SAAS,yBAAyB,UAAU;CAC1C,MAAM,QAAQ,CAAC;CACf,MAAM,qCAAqC,IAAI,IAAI;CACnD,MAAM,qCAAqC,IAAI,IAAI;CACnD,MAAM,4BAA4B,IAAI,IAAI;CAC1C,MAAM,4BAA4B,IAAI,IAAI;CAC1C,MAAM,eAAe;EACnB,WAAW;EACX,UAAU,SAAS,aAAa,SAAS,CAAC;CAC5C;CACA,MAAM,iBAAiB;CACvB,MAAM,WAAW,UAAU,MAAM,MAAM,SAAS,KAAK,UAAU,KAAK;CACpE,MAAM,YAAY,UAAU,MAAM,WAAW,SAAS,KAAK,UAAU,KAAK;CAC1E,MAAM,sBAAsB,UAAU;E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AAS;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,eAAe,OAAO;GACpB,cAAc;EAChB;EACA;CACF;AACF;AACA,SAAS,sBAAsB,MAAM;CACnC,OAAO;EACL,MAAM;EACN,wBAAwB,SAAS,aAAa,OAAO,KAAK;CAC5D;AACF;AACA,SAAS,qBAAqB,MAAM,UAAU,UAAU,UAAU;CAChE,IAAI,aAAa,UAAU;EACzB,OAAO;GACL,mBAAmB,SAAS,aAAa,aAAa;GACtD,oBAAoB;IAClB,UAAU,SAAS,WAAW,WAAW,KAAK;IAC9C,SAAS,SAAS,aAAa,WAAW,KAAK;IAC/C;GACF;EACF;CACF;CACA,OAAO;EACL,MAAM;EACN,iBAAiB;EACjB,iBAAiB,YAAY,KAAK;CACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"selectionController.js","names":[],"sources":["esm/selectionController.js"],"sourcesContent":["function getSelectLabelText(label) {\n if (typeof label === \"string\" || typeof label === \"number\") {\n return String(label);\n }\n if (Array.isArray(label)) {\n return label.map(getSelectLabelText).join(\"\");\n }\n if (label && typeof label === \"object\" && \"props\" in label) {\n return getSelectLabelText(label.props?.children);\n }\n return \"\";\n}\nfunction createSelectItemRegistry(onChange) {\n const items = [];\n const labelRegistrations = /* @__PURE__ */ new Map();\n const explicitTextValues = /* @__PURE__ */ new Map();\n const itemNodes = /* @__PURE__ */ new Map();\n const listeners = /* @__PURE__ */ new Set();\n let indexByValue = null;\n const notify = () => {\n indexByValue = null;\n onChange?.();\n listeners.forEach((listener) => listener());\n };\n const getItems = () => items;\n const getItem = (value) => items.find((item) => item.value === value);\n const getIndex = (value) => {\n if (!indexByValue) {\n indexByValue = /* @__PURE__ */ new Map();\n items.forEach((item, index) => {\n if (!indexByValue.has(item.value)) indexByValue.set(item.value, index);\n });\n }\n return indexByValue.get(value) ?? -1;\n };\n const getNodes = () => items.map((item) => itemNodes.get(item.id) ?? null);\n const getRegisteredLabel = (value) => {\n const registrations = labelRegistrations.get(value);\n if (!registrations?.size) return void 0;\n const values = Array.from(registrations.values());\n return values[values.length - 1];\n };\n const applyRegisteredLabel = (value) => {\n const registeredLabel = getRegisteredLabel(value);\n let changed = false;\n for (const item of items) {\n if (item.value !== value) continue;\n const nextLabel = registeredLabel?.label;\n const nextTextValue = explicitTextValues.get(item.id) || registeredLabel?.textValue;\n if (item.label !== nextLabel || item.textValue !== nextTextValue) {\n item.label = nextLabel;\n item.textValue = nextTextValue;\n changed = true;\n }\n }\n if (changed) notify();\n };\n const syncNodeOrder = () => {\n items.sort((a, b) => {\n const aNode = itemNodes.get(a.id);\n const bNode = itemNodes.get(b.id);\n if (!aNode || !bNode || typeof aNode.compareDocumentPosition !== \"function\") {\n return 0;\n }\n const position = aNode.compareDocumentPosition(bNode);\n if (position & 4) return -1;\n if (position & 2) return 1;\n return 0;\n });\n };\n const registerItem = (item) => {\n const id = Symbol(item.value);\n const registeredLabel = getRegisteredLabel(item.value);\n const registeredItem = {\n ...item,\n ...registeredLabel,\n textValue: item.textValue ?? registeredLabel?.textValue,\n id\n };\n explicitTextValues.set(id, item.textValue);\n items.push(registeredItem);\n notify();\n return {\n id,\n update(next) {\n const index = items.findIndex((current2) => current2.id === id);\n if (index < 0) return;\n const current = items[index];\n if (\"textValue\" in next) {\n explicitTextValues.set(id, next.textValue);\n }\n const nextItem = { ...current, ...next };\n if (next.value !== void 0 && next.value !== current.value) {\n const nextLabel = getRegisteredLabel(next.value);\n nextItem.label = nextLabel?.label;\n }\n const explicitTextValue = explicitTextValues.get(id);\n nextItem.textValue = explicitTextValue || getSelectLabelText(nextItem.label) || (nextItem.label ? nextItem.value : void 0);\n const changed = Object.entries(next).some(\n ([key, value]) => current[key] !== value\n );\n const textValueChanged = current.textValue !== nextItem.textValue;\n if (!changed && !textValueChanged) return;\n items[index] = nextItem;\n notify();\n },\n setNode(node) {\n if ((itemNodes.get(id) ?? null) === (node ?? null)) return;\n if (node) {\n itemNodes.set(id, node);\n syncNodeOrder();\n } else {\n itemNodes.delete(id);\n }\n notify();\n },\n unregister() {\n const index = items.findIndex((current) => current.id === id);\n if (index < 0) return;\n items.splice(index, 1);\n explicitTextValues.delete(id);\n itemNodes.delete(id);\n notify();\n }\n };\n };\n const registerLabel = (value, label, textValue) => {\n const id = Symbol(value);\n const normalizedTextValue = textValue || getSelectLabelText(label) || value;\n const registrations = labelRegistrations.get(value) ?? (() => {\n const next = /* @__PURE__ */ new Map();\n labelRegistrations.set(value, next);\n return next;\n })();\n registrations.set(id, { label, textValue: normalizedTextValue });\n applyRegisteredLabel(value);\n return () => {\n registrations.delete(id);\n if (!registrations.size) {\n labelRegistrations.delete(value);\n }\n applyRegisteredLabel(value);\n };\n };\n const firstEnabledIndex = () => items.findIndex((item) => !item.disabled);\n const nextEnabledIndex = (fromIndex, direction) => {\n if (!items.length) return -1;\n if (fromIndex == null || fromIndex < 0 || fromIndex >= items.length) {\n if (direction === 1) return firstEnabledIndex();\n for (let index = items.length - 1; index >= 0; index--) {\n if (!items[index].disabled) return index;\n }\n return -1;\n }\n for (let offset = 1; offset <= items.length; offset++) {\n const index = (fromIndex + direction * offset + items.length) % items.length;\n if (!items[index]?.disabled) return index;\n }\n return -1;\n };\n const findTypeaheadIndex = (search, fromIndex) => {\n const normalizedSearch = search.trim().toLocaleLowerCase();\n if (!normalizedSearch) return -1;\n const start = fromIndex == null || fromIndex < 0 ? -1 : fromIndex;\n for (let offset = 1; offset <= items.length; offset++) {\n const index = (start + offset) % items.length;\n const item = items[index];\n const label = item.textValue || getSelectLabelText(item.label) || item.value;\n if (!item.disabled && label.toLocaleLowerCase().startsWith(normalizedSearch)) {\n return index;\n }\n }\n return -1;\n };\n return {\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n registerItem,\n registerLabel,\n getItems,\n getItem,\n getIndex,\n getNodes,\n firstEnabledIndex,\n nextEnabledIndex,\n findTypeaheadIndex,\n getDisabledIndices: () => items.flatMap((item, index) => item.disabled ? [index] : []),\n getTypeaheadLabels: () => items.map((item) => item.textValue || getSelectLabelText(item.label) || item.value)\n };\n}\nfunction normalizeSelectSelection(mode, value) {\n if (mode === \"single\") {\n return typeof value === \"string\" ? value : \"\";\n }\n const values = Array.isArray(value) ? value : [];\n return [...new Set(values)];\n}\nfunction selectedValuesFromSelection(mode, value) {\n const normalized = normalizeSelectSelection(mode, value);\n return mode === \"multiple\" ? normalized : normalized ? [normalized] : [];\n}\nfunction createSelectSelectionController({\n mode: initialMode,\n value: initialValue,\n registry\n}) {\n let mode = initialMode;\n let value = normalizeSelectSelection(mode, initialValue);\n let activeIndex = null;\n const selectedValues = () => selectedValuesFromSelection(mode, value);\n const setMode = (nextMode) => {\n if (mode === nextMode) return value;\n mode = nextMode;\n value = normalizeSelectSelection(mode, value);\n return value;\n };\n const setValue = (nextValue) => {\n value = normalizeSelectSelection(mode, nextValue);\n return value;\n };\n const isSelected = (itemValue) => selectedValues().includes(itemValue);\n const toggle = (itemValue) => {\n const item = registry.getItem(itemValue);\n if (!item || item.disabled) return value;\n if (mode === \"single\") {\n value = itemValue;\n return value;\n }\n const current = selectedValues();\n value = current.includes(itemValue) ? current.filter((currentValue) => currentValue !== itemValue) : [...current, itemValue];\n return value;\n };\n const selectionAnchor = () => {\n const values = selectedValues();\n for (let index = values.length - 1; index >= 0; index--) {\n const item = registry.getItem(values[index]);\n if (item) return item;\n }\n const firstEnabledIndex = registry.firstEnabledIndex();\n return firstEnabledIndex < 0 ? void 0 : registry.getItems()[firstEnabledIndex];\n };\n const selectionAnchorIndex = () => {\n const anchor = selectionAnchor();\n return anchor ? registry.getIndex(anchor.value) : -1;\n };\n const initialActiveIndex = () => {\n const anchorIndex = selectionAnchorIndex();\n const anchor = anchorIndex < 0 ? void 0 : registry.getItems()[anchorIndex];\n return anchor && !anchor.disabled ? anchorIndex : registry.firstEnabledIndex();\n };\n const moveActive = (direction) => {\n const nextIndex = registry.nextEnabledIndex(activeIndex, direction);\n activeIndex = nextIndex < 0 ? null : nextIndex;\n return activeIndex == null ? void 0 : registry.getItems()[activeIndex];\n };\n return {\n registry,\n get mode() {\n return mode;\n },\n get value() {\n return value;\n },\n get activeIndex() {\n return activeIndex;\n },\n get activeItem() {\n return activeIndex == null ? void 0 : registry.getItems()[activeIndex];\n },\n get shouldCloseOnSelect() {\n return mode === \"single\";\n },\n setMode,\n setValue,\n isSelected,\n toggle,\n selectionAnchor,\n selectionAnchorIndex,\n initialActiveIndex,\n setActiveIndex(index) {\n activeIndex = index;\n },\n moveActive\n };\n}\nfunction getSelectListboxProps(mode) {\n return {\n role: \"listbox\",\n \"aria-multiselectable\": mode === \"multiple\" ? true : void 0\n };\n}\nfunction getSelectOptionProps(mode, selected, disabled, platform) {\n if (platform === \"native\") {\n return {\n accessibilityRole: mode === \"multiple\" ? \"checkbox\" : \"button\",\n accessibilityState: {\n selected: mode === \"single\" ? selected : void 0,\n checked: mode === \"multiple\" ? selected : void 0,\n disabled\n }\n };\n }\n return {\n role: \"option\",\n \"aria-selected\": selected,\n \"aria-disabled\": disabled || void 0\n };\n}\nexport {\n createSelectItemRegistry,\n createSelectSelectionController,\n getSelectLabelText,\n getSelectListboxProps,\n getSelectOptionProps,\n normalizeSelectSelection,\n selectedValuesFromSelection\n};\n//# sourceMappingURL=selectionController.js.map\n"],"mappings":";AAAA,SAAS,mBAAmB,OAAO;CACjC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU;EAC1D,OAAO,OAAO,KAAK;CACrB;CACA,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,OAAO,MAAM,IAAI,kBAAkB,CAAC,CAAC,KAAK,EAAE;CAC9C;CACA,IAAI,SAAS,OAAO,UAAU,YAAY,WAAW,OAAO;EAC1D,OAAO,mBAAmB,MAAM,OAAO,QAAQ;CACjD;CACA,OAAO;AACT;AACA,SAAS,yBAAyB,UAAU;CAC1C,MAAM,QAAQ,CAAC;CACf,MAAM,qCAAqC,IAAI,IAAI;CACnD,MAAM,qCAAqC,IAAI,IAAI;CACnD,MAAM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