@webority/mobile-ui 0.163.0 → 0.165.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.
Files changed (162) hide show
  1. package/LICENSE.txt +1 -1
  2. package/android/src/newarch/java/com/webority/mobileui/pdfrasterizer/PdfRasterizerModule.kt +4 -4
  3. package/dist/canvas-kit/kit.js +5 -5
  4. package/dist/canvas-kit/manifest.json +11 -1
  5. package/dist/canvas-kit/release.json +6 -6
  6. package/ios/PdfRasterizer.mm +3 -3
  7. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  8. package/lib/commonjs/components/Banner/Banner.js +1 -1
  9. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  10. package/lib/commonjs/components/Card/Card.js +1 -1
  11. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  12. package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
  13. package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
  14. package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
  15. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  16. package/lib/commonjs/components/Input/Input.js +1 -1
  17. package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
  18. package/lib/commonjs/components/Modal/Modal.js +1 -1
  19. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  20. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  21. package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  22. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  23. package/lib/commonjs/components/Screen/Screen.js +1 -1
  24. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  25. package/lib/commonjs/components/Slider/Slider.js +1 -1
  26. package/lib/commonjs/components/SliderField/SliderField.js +1 -1
  27. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  28. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  29. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  30. package/lib/commonjs/theme/merge.js +1 -1
  31. package/lib/commonjs/utils/warnUnknownProps.js +1 -1
  32. package/lib/module/components/Avatar/Avatar.js +1 -1
  33. package/lib/module/components/Banner/Banner.js +1 -1
  34. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  35. package/lib/module/components/Card/Card.js +1 -1
  36. package/lib/module/components/Carousel/Carousel.js +1 -1
  37. package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
  38. package/lib/module/components/FieldBase/FieldBase.js +1 -1
  39. package/lib/module/components/IconBadge/IconBadge.js +1 -1
  40. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  41. package/lib/module/components/Input/Input.js +1 -1
  42. package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
  43. package/lib/module/components/Modal/Modal.js +1 -1
  44. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  45. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  46. package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  47. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  48. package/lib/module/components/Screen/Screen.js +1 -1
  49. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  50. package/lib/module/components/Slider/Slider.js +1 -1
  51. package/lib/module/components/SliderField/SliderField.js +1 -1
  52. package/lib/module/components/TagInput/TagInput.js +1 -1
  53. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  54. package/lib/module/hooks/useDragToDismiss.js +1 -1
  55. package/lib/module/theme/merge.js +1 -1
  56. package/lib/module/utils/warnUnknownProps.js +1 -1
  57. package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +1 -0
  58. package/lib/typescript/commonjs/components/Autocomplete/Autocomplete.d.ts +1 -1
  59. package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +2 -1
  60. package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +5 -4
  61. package/lib/typescript/commonjs/components/Carousel/Carousel.d.ts +2 -1
  62. package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +4 -4
  63. package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +2 -1
  64. package/lib/typescript/commonjs/components/Descriptions/Descriptions.d.ts +2 -2
  65. package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +1 -1
  66. package/lib/typescript/commonjs/components/FieldBase/Chevron.d.ts +1 -1
  67. package/lib/typescript/commonjs/components/FieldBase/FieldBase.d.ts +14 -13
  68. package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +10 -10
  69. package/lib/typescript/commonjs/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +2 -2
  70. package/lib/typescript/commonjs/components/FormField/FormField.d.ts +1 -1
  71. package/lib/typescript/commonjs/components/IconButton/IconButton.d.ts +2 -2
  72. package/lib/typescript/commonjs/components/ImageGallery/ImageGallery.d.ts +2 -1
  73. package/lib/typescript/commonjs/components/InlineSelect/InlineSelect.d.ts +7 -7
  74. package/lib/typescript/commonjs/components/Input/Input.d.ts +3 -2
  75. package/lib/typescript/commonjs/components/Menu/Menu.d.ts +1 -1
  76. package/lib/typescript/commonjs/components/Modal/Modal.d.ts +2 -1
  77. package/lib/typescript/commonjs/components/NumberInput/NumberInput.d.ts +1 -0
  78. package/lib/typescript/commonjs/components/OptionSheet/OptionSheet.d.ts +5 -5
  79. package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -0
  80. package/lib/typescript/commonjs/components/PickerTrigger/PickerTrigger.d.ts +4 -4
  81. package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +2 -1
  82. package/lib/typescript/commonjs/components/ProgressBar/ProgressBar.d.ts +1 -1
  83. package/lib/typescript/commonjs/components/Radio/RadioDot.d.ts +2 -2
  84. package/lib/typescript/commonjs/components/Repeater/Repeater.d.ts +2 -2
  85. package/lib/typescript/commonjs/components/RichTextEditor/markdownActions.d.ts +3 -3
  86. package/lib/typescript/commonjs/components/Screen/Screen.d.ts +1 -0
  87. package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +2 -1
  88. package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +1 -1
  89. package/lib/typescript/commonjs/components/Select/Select.d.ts +6 -6
  90. package/lib/typescript/commonjs/components/Skeleton/Skeleton.d.ts +3 -3
  91. package/lib/typescript/commonjs/components/Skeleton/SkeletonClock.d.ts +3 -3
  92. package/lib/typescript/commonjs/components/Skeleton/SkeletonContent.d.ts +6 -6
  93. package/lib/typescript/commonjs/components/Skeleton/SkeletonList.d.ts +2 -2
  94. package/lib/typescript/commonjs/components/Skeleton/SkeletonProvider.d.ts +5 -5
  95. package/lib/typescript/commonjs/components/Skeleton/SkeletonSkip.d.ts +2 -2
  96. package/lib/typescript/commonjs/components/SlideToConfirm/SlideToConfirm.d.ts +1 -1
  97. package/lib/typescript/commonjs/components/Slider/Slider.d.ts +5 -0
  98. package/lib/typescript/commonjs/components/SliderField/SliderField.d.ts +1 -0
  99. package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +2 -2
  100. package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +2 -1
  101. package/lib/typescript/commonjs/components/Timeline/Timeline.d.ts +8 -8
  102. package/lib/typescript/commonjs/components/ZoomableImage/ZoomableImage.d.ts +4 -4
  103. package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +2 -0
  104. package/lib/typescript/commonjs/specs/NativePdfRasterizer.d.ts +4 -4
  105. package/lib/typescript/commonjs/theme/animatedValue.d.ts +4 -4
  106. package/lib/typescript/commonjs/theme/types.d.ts +9 -3
  107. package/lib/typescript/commonjs/utils/feedback.d.ts +3 -3
  108. package/lib/typescript/commonjs/utils/warnUnknownProps.d.ts +2 -2
  109. package/lib/typescript/module/components/AppBar/AppBar.d.ts +1 -0
  110. package/lib/typescript/module/components/Autocomplete/Autocomplete.d.ts +1 -1
  111. package/lib/typescript/module/components/Avatar/Avatar.d.ts +2 -1
  112. package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +5 -4
  113. package/lib/typescript/module/components/Carousel/Carousel.d.ts +2 -1
  114. package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +4 -4
  115. package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +2 -1
  116. package/lib/typescript/module/components/Descriptions/Descriptions.d.ts +2 -2
  117. package/lib/typescript/module/components/Drawer/Drawer.d.ts +1 -1
  118. package/lib/typescript/module/components/FieldBase/Chevron.d.ts +1 -1
  119. package/lib/typescript/module/components/FieldBase/FieldBase.d.ts +14 -13
  120. package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +10 -10
  121. package/lib/typescript/module/components/ForceUpdateDialog/ForceUpdateDialog.d.ts +2 -2
  122. package/lib/typescript/module/components/FormField/FormField.d.ts +1 -1
  123. package/lib/typescript/module/components/IconButton/IconButton.d.ts +2 -2
  124. package/lib/typescript/module/components/ImageGallery/ImageGallery.d.ts +2 -1
  125. package/lib/typescript/module/components/InlineSelect/InlineSelect.d.ts +7 -7
  126. package/lib/typescript/module/components/Input/Input.d.ts +3 -2
  127. package/lib/typescript/module/components/Menu/Menu.d.ts +1 -1
  128. package/lib/typescript/module/components/Modal/Modal.d.ts +2 -1
  129. package/lib/typescript/module/components/NumberInput/NumberInput.d.ts +1 -0
  130. package/lib/typescript/module/components/OptionSheet/OptionSheet.d.ts +5 -5
  131. package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -0
  132. package/lib/typescript/module/components/PickerTrigger/PickerTrigger.d.ts +4 -4
  133. package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +2 -1
  134. package/lib/typescript/module/components/ProgressBar/ProgressBar.d.ts +1 -1
  135. package/lib/typescript/module/components/Radio/RadioDot.d.ts +2 -2
  136. package/lib/typescript/module/components/Repeater/Repeater.d.ts +2 -2
  137. package/lib/typescript/module/components/RichTextEditor/markdownActions.d.ts +3 -3
  138. package/lib/typescript/module/components/Screen/Screen.d.ts +1 -0
  139. package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +2 -1
  140. package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +1 -1
  141. package/lib/typescript/module/components/Select/Select.d.ts +6 -6
  142. package/lib/typescript/module/components/Skeleton/Skeleton.d.ts +3 -3
  143. package/lib/typescript/module/components/Skeleton/SkeletonClock.d.ts +3 -3
  144. package/lib/typescript/module/components/Skeleton/SkeletonContent.d.ts +6 -6
  145. package/lib/typescript/module/components/Skeleton/SkeletonList.d.ts +2 -2
  146. package/lib/typescript/module/components/Skeleton/SkeletonProvider.d.ts +5 -5
  147. package/lib/typescript/module/components/Skeleton/SkeletonSkip.d.ts +2 -2
  148. package/lib/typescript/module/components/SlideToConfirm/SlideToConfirm.d.ts +1 -1
  149. package/lib/typescript/module/components/Slider/Slider.d.ts +5 -0
  150. package/lib/typescript/module/components/SliderField/SliderField.d.ts +1 -0
  151. package/lib/typescript/module/components/Tabs/Tabs.d.ts +2 -2
  152. package/lib/typescript/module/components/TagInput/TagInput.d.ts +2 -1
  153. package/lib/typescript/module/components/Timeline/Timeline.d.ts +8 -8
  154. package/lib/typescript/module/components/ZoomableImage/ZoomableImage.d.ts +4 -4
  155. package/lib/typescript/module/hooks/useDragToDismiss.d.ts +2 -0
  156. package/lib/typescript/module/specs/NativePdfRasterizer.d.ts +4 -4
  157. package/lib/typescript/module/theme/animatedValue.d.ts +4 -4
  158. package/lib/typescript/module/theme/types.d.ts +9 -3
  159. package/lib/typescript/module/utils/feedback.d.ts +3 -3
  160. package/lib/typescript/module/utils/warnUnknownProps.d.ts +2 -2
  161. package/package.json +9 -10
  162. package/src/specs/NativePdfRasterizer.ts +4 -4
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=exports.DEFAULT_IMAGE_GALLERY_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_Modal=require("../Modal/Modal.js"),_index4=require("../Skeleton/index.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,l=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=l&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?l(r,i,a):r[i]=e[i]);return r}const DEFAULT_IMAGE_GALLERY_LABELS=exports.DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"},MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:i=!0,enableLightbox:l=!0,enablePinchZoom:r=!0,onIndexChange:n,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d,labels:m})=>{const _=(0,_index.useTheme)(),h=(0,_react.useMemo)(()=>buildStyles(_),[_]),g=(0,_react.useMemo)(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...m}),[m]),[v,x]=(0,_react.useState)(clamp(t,0,Math.max(0,e.length-1))),[p,b]=(0,_react.useState)(!1),y=(0,_react.useCallback)(e=>{x(e),n?.(e)},[n]),R=(0,_react.useCallback)(()=>{if(!l)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!0)},[l,s]),S=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!1)},[s]),N=(0,_react.useCallback)((t,a)=>{const i=t.alt??g.imageOf(a+1,e.length);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:R,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:l?g.openFullscreen:void 0,style:h.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:t.source,style:h.image,resizeMode:"cover"})})},[l,e.length,R,h,g]),I=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:h.thumbnailImage,resizeMode:"cover"}),[h]),j=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[h.container,u],testID:d,accessibilityLabel:c??g.gallery,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:h.carouselWrap,accessibilityElementsHidden:p,importantForAccessibility:p?"no-hide-descendants":"auto",children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:N,showPagination:!1,showThumbnails:a,renderThumbnail:I,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:h.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:_.colors["on-scrim"]},accessibilityLabel:g.imageOf(v+1,e.length),children:`${v+1} / ${e.length}`})}):null]}),l?(0,_jsxRuntime.jsx)(Lightbox,{open:p,images:e,initialIndex:v,enablePinchZoom:r,showCounter:i,onClose:S,onIndexChange:y,haptic:s,labels:g}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:i,containerStyle:u,testID:d}):j};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:i,testID:l})=>{const r=(0,_index.useTheme)(),n=Math.min(e?.length||4,6),s=(0,_react.useMemo)(()=>Array.from({length:n},(e,t)=>({key:`sk-thumb-${t}`})),[n]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:l,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:r.space.md},children:s.map(e=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:i,showCounter:l,onClose:r,onIndexChange:n,haptic:s,labels:o})=>{const c=(0,_index.useTheme)(),u=(0,_react.useMemo)(()=>buildLightboxStyles(c),[c]),d=(0,_react.useRef)(null),[m,_]=(0,_react.useState)(a),h=(0,_react.useCallback)(e=>{if(e!==m){const t=(0,_index2.resolveHaptic)(s,"selection");t&&(0,_index2.triggerHaptic)(t),_(e),n(e)}},[m,n,s]),g=(0,_react.useCallback)((e,a)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:a,total:t.length,active:a===m,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s,imageLabel:o.imageOf}),[m,i,t.length,s,o]),v=t[m]?.caption;return(0,_jsxRuntime.jsx)(_Modal.Modal,{open:e,onClose:r,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:u.backdrop,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:d,data:t,defaultIndex:a,onIndexChange:h,renderItem:g,showPagination:!1,haptic:s}),l&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:u.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:o.imageOf(m+1,t.length),children:`${m+1} / ${t.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:o.closeGallery,style:u.closeButton,hitSlop:12,...(0,_hitSlop.hitSlopMarker)(12),children:(c.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),v?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:u.captionWrap,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:v})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:i,enabled:l,maxScale:r,minScale:n,doubleTapScale:s,haptic:o,imageLabel:c})=>{const u=_reactNative.Dimensions.get("window"),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_reactNativeReanimated.useSharedValue)(0),x=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=1,_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),g.value=0,v.value=0},[d,m,_,h,g,v]);_react.default.useEffect(()=>{i||(d.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),h.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),m.value=1,g.value=0,v.value=0)},[i,d,_,h,m,g,v]);const p=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),b=(0,_react.useMemo)(()=>({enabled:l,onActivate:()=>{"worklet";m.value=d.value},onUpdate:e=>{"worklet";const t=m.value*e.scale;d.value=t<n?n+.3*(t-n):t>r?r+.2*(t-r):t},onDeactivate:()=>{"worklet";return d.value<n?(d.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=n,g.value=0,void(v.value=0)):d.value>r?(d.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(m.value=r)):void(m.value=d.value)}}),[l,d,m,_,h,g,v,n,r]),y=(0,_reactNativeGestureHandler.usePinchGesture)(b),R=(0,_react.useMemo)(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";g.value=_.value,v.value=h.value},onUpdate:e=>{"worklet";d.value<=1||(_.value=g.value+e.translationX,h.value=v.value+e.translationY)},onDeactivate:()=>{"worklet";g.value=_.value,v.value=h.value}}),[d,_,h,g,v]),S=(0,_reactNativeGestureHandler.usePanGesture)(R),N=(0,_react.useMemo)(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";(0,_reactNativeWorklets.scheduleOnRN)(p),d.value>1?(d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=1,g.value=0,v.value=0):(d.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),m.value=s)}}),[d,m,_,h,g,v,p,s]),I=(0,_reactNativeGestureHandler.useTapGesture)(N),j=(0,_reactNativeGestureHandler.useCompetingGestures)(y,S,I),w=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:_.value},{translateY:h.value},{scale:d.value}]}),[_,h,d]);_react.default.useEffect(()=>{i||x()},[i,x]);const C=e.alt??c(t+1,a);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:j,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:u.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,w],accessibilityLabel:C,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,..._corners.smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>_reactNative.StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"]}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=exports.DEFAULT_IMAGE_GALLERY_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_reactNativeWorklets=require("react-native-worklets"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_Modal=require("../Modal/Modal.js"),_index4=require("../Skeleton/index.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,l=Object.defineProperty,r={__proto__:null,default:e};if(Object(e)!==e)return r;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,r)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=l&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?l(r,i,a):r[i]=e[i]);return r}const DEFAULT_IMAGE_GALLERY_LABELS=exports.DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"},MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:i=!0,enableLightbox:l=!0,enablePinchZoom:r=!0,onIndexChange:n,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d,labels:m})=>{const _=(0,_index.useTheme)(),h=(0,_react.useMemo)(()=>buildStyles(_),[_]),g=(0,_react.useMemo)(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...m}),[m]),[v,x]=(0,_react.useState)(clamp(t,0,Math.max(0,e.length-1))),[p,b]=(0,_react.useState)(!1),y=(0,_react.useCallback)(e=>{x(e),n?.(e)},[n]),R=(0,_react.useCallback)(()=>{if(!l)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!0)},[l,s]),S=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),b(!1)},[s]),I=(0,_react.useCallback)((t,a)=>{const i=t.alt??g.imageOf(a+1,e.length);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:R,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:l?g.openFullscreen:void 0,style:h.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:t.source,style:h.image,resizeMode:"cover"})})},[l,e.length,R,h,g]),N=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:h.thumbnailImage,resizeMode:"cover"}),[h]),j=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[h.container,u],testID:d,accessibilityLabel:c??g.gallery,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:h.carouselWrap,accessibilityElementsHidden:p,importantForAccessibility:p?"no-hide-descendants":"auto",children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:I,showPagination:!1,showThumbnails:a,renderThumbnail:N,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:h.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:_.colors["on-scrim"]},accessibilityLabel:g.imageOf(v+1,e.length),children:`${v+1} / ${e.length}`})}):null]}),l?(0,_jsxRuntime.jsx)(Lightbox,{open:p,images:e,initialIndex:v,enablePinchZoom:r,showCounter:i,onClose:S,onIndexChange:y,haptic:s,labels:g,testID:d}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:i,containerStyle:u,testID:d}):j};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:i,testID:l})=>{const r=(0,_index.useTheme)(),n=Math.min(e?.length||4,6),s=(0,_react.useMemo)(()=>Array.from({length:n},(e,t)=>({key:`sk-thumb-${t}`})),[n]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:l,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:r.space.md},children:s.map(e=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:r.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:i,showCounter:l,onClose:r,onIndexChange:n,haptic:s,labels:o,testID:c})=>{const u=(0,_index.useTheme)(),d=(0,_react.useMemo)(()=>buildLightboxStyles(u),[u]),m=(0,_react.useRef)(null),[_,h]=(0,_react.useState)(a),g=(0,_react.useCallback)(e=>{if(e!==_){const t=(0,_index2.resolveHaptic)(s,"selection");t&&(0,_index2.triggerHaptic)(t),h(e),n(e)}},[_,n,s]),v=(0,_react.useCallback)((e,a)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:a,total:t.length,active:a===_,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s,imageLabel:o.imageOf}),[_,i,t.length,s,o]),x=t[_]?.caption;return(0,_jsxRuntime.jsx)(_Modal.Modal,{open:e,onClose:r,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:d.backdrop,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:m,testID:c?`${c}-lightbox`:void 0,data:t,defaultIndex:a,onIndexChange:g,renderItem:v,showPagination:!1,haptic:s}),l&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:d.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"label",weight:"semibold",style:{color:u.colors["on-scrim"]},accessibilityLabel:o.imageOf(_+1,t.length),children:`${_+1} / ${t.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:o.closeGallery,style:d.closeButton,hitSlop:12,...(0,_hitSlop.hitSlopMarker)(12),children:(u.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:u.colors["on-scrim"]})}),x?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:d.captionWrap,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",align:"center",numberOfLines:3,style:d.captionText,children:x})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:i,enabled:l,maxScale:r,minScale:n,doubleTapScale:s,haptic:o,imageLabel:c})=>{const u=_reactNative.Dimensions.get("window"),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(1),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_reactNativeReanimated.useSharedValue)(0),x=(0,_react.useCallback)(()=>{d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=1,_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),g.value=0,v.value=0},[d,m,_,h,g,v]);_react.default.useEffect(()=>{i||(d.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),h.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),m.value=1,g.value=0,v.value=0)},[i,d,_,h,m,g,v]);const p=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),b=(0,_react.useMemo)(()=>({enabled:l,onActivate:()=>{"worklet";m.value=d.value},onUpdate:e=>{"worklet";const t=m.value*e.scale;d.value=t<n?n+.3*(t-n):t>r?r+.2*(t-r):t},onDeactivate:()=>{"worklet";return d.value<n?(d.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=n,g.value=0,void(v.value=0)):d.value>r?(d.value=(0,_reactNativeReanimated.withSpring)(r,SPRING_CONFIG),void(m.value=r)):void(m.value=d.value)}}),[l,d,m,_,h,g,v,n,r]),y=(0,_reactNativeGestureHandler.usePinchGesture)(b),R=(0,_react.useMemo)(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";g.value=_.value,v.value=h.value},onUpdate:e=>{"worklet";d.value<=1||(_.value=g.value+e.translationX,h.value=v.value+e.translationY)},onDeactivate:()=>{"worklet";g.value=_.value,v.value=h.value}}),[d,_,h,g,v]),S=(0,_reactNativeGestureHandler.usePanGesture)(R),I=(0,_react.useMemo)(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";(0,_reactNativeWorklets.scheduleOnRN)(p),d.value>1?(d.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),m.value=1,g.value=0,v.value=0):(d.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),m.value=s)}}),[d,m,_,h,g,v,p,s]),N=(0,_reactNativeGestureHandler.useTapGesture)(I),j=(0,_reactNativeGestureHandler.useCompetingGestures)(y,S,N),w=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:_.value},{translateY:h.value},{scale:d.value}]}),[_,h,d]);_react.default.useEffect(()=>{i||x()},[i,x]);const C=e.alt??c(t+1,a);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:j,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:u.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,w],accessibilityLabel:C,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,..._corners.smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>_reactNative.StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"]}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=exports.DEFAULT_INPUT_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_textInk=require("../Text/textInk.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_INPUT_LABELS=exports.DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"},Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:r,onChangeText:s,error:l,helperText:o,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:_,rightIcon:f,unit:g,unitStyle:m,prefix:v,prefixStyle:h,readOnly:y=!1,action:j,actionStyle:b,size:S="md",variant:I,labelMode:R,required:w=!1,maxLength:N,showCounter:T=!0,textAlign:V,format:F,parse:D,style:A,containerStyle:L,inputStyle:B,labelStyle:P,messageStyle:k,radius:z,onFocus:q,onBlur:C,accessibilityLabel:E,labels:H,testID:M,editable:O,...U}=e;(0,_assertValidValue.assertValidValue)("Input","variant",I,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("Input","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Input","labelMode",R,["float","top"]),(0,_assertValidValue.assertValidValue)("Input","type",e.type,["input","password","textarea"]);const G=(0,_react.useMemo)(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=(0,_index2.useTheme)(),$=(0,_react.useMemo)(()=>buildStyles(W),[W]),X=(0,_index2.resolveFieldSize)(W,S),J=W.components.input[S]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=I??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=R??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=(0,_react.useState)(!1),[te,ie]=(0,_react.useState)(!1),ne="password"===d||u||c,ae="password"===d||u,re="textarea"===d||p,se=re?Math.round(.1*X.text):0,le="string"==typeof r&&r.length>0,oe=(0,_FieldBase.hasFieldText)(l),de=!0===l||oe,ce=(0,_FieldBase.hasFieldText)(o),ue=oe||!de&&ce,xe=(0,_FieldBase.hasFieldText)(i),pe=(0,_FieldBase.hasFieldText)(v),fe=!x&&!1!==O,ge=Z||le||pe,me=(0,_react.useRef)(null),ve=(0,_react.useMemo)(()=>(0,_index3.mergeRefs)(me,t),[t]),he=(0,_react.useCallback)(()=>{fe&&me.current?.focus()},[fe]),ye=xe&&"float"===Y,je=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,be=(0,_react.useRef)((0,_index2.createAnimatedValue)(ue?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.timing(be,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:_reactNative.Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:_nativeDriver.nativeDriver});return e.start(),()=>e.stop()},[ue,be,W.motion.duration.fast,W.motion.ease["in-out"]]);const Se=(0,_index.useReducedMotion)(),Ie=W.settings.components.input?.shakeOnError??!1,Re=(0,_react.useRef)(de);(0,_react.useEffect)(()=>{if(!Ie)return void(Re.current=de);let e;return de&&!Re.current&&(Se||((0,_index2.setNativeValue)(je,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(je,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:0,duration:100,useNativeDriver:_nativeDriver.nativeDriver})]),e.start()),(0,_index3.triggerHaptic)("notificationError")),Re.current=de,()=>e?.stop()},[de,je,Ie,Se]);const we=(0,_react.useCallback)(e=>{ee(!0),q?.(e)},[q]),Ne=(0,_react.useCallback)(e=>{ee(!1),C?.(e)},[C]),Te=(0,_react.useCallback)(()=>{(0,_index3.triggerHaptic)("selection"),ie(e=>!e)},[]),Ve=W.colors["field-caret"],Fe=W.settings.components.input?.tintLabelOnFocus??!1,De=Z&&Fe?W.colors["field-border-focus"]:W.colors["field-label"],Ae=je.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Le=Boolean(f)||Boolean(g)||ae,Be="underline"===Q,Pe=_?X.icon+W.space.md+1+W.space.md:0,ke=(0,_useFloatingLabel.useFloatingLabel)({label:i,enabled:ye,floated:ge,required:w,variant:Q,sizeTokens:X,leadingOffset:Pe,trailingOffset:Le?X.icon+W.space.sm:0,textAlign:"center"===V||"right"===V?V:"left",paddingLeft:Be?W.space.none:X["padding-x"],lineHeight:re?K:void 0,restNudge:se,floatTrim:re?2:0,color:De,style:P}),ze=(0,_FieldBase.resolveFieldTextStyle)(W,{disabled:x}),qe=ze.color,Ce=ze.placeholderColor,Ee=w&&!xe&&!le&&"string"==typeof a&&a.length>0,He=de?l:o,Me=T&&"number"==typeof N&&"string"==typeof r?`${r.length} / ${N}`:null,Oe=de?W.colors["field-message"]:W.colors["text-muted"],Ue=(0,_textInk.useTextInk)(k,X["message-text"],Oe),Ge=E??(0,_FieldBase.fieldTextAsString)(i)??a,We=x?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:x,error:de,color:We,size:X.icon},renderSlot=e=>(0,_slotIcon.renderSlotIcon)(e,$e),Xe=(()=>{if(ae){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?_defaultIcons.defaultIcons.eyeOff:_defaultIcons.defaultIcons.eye);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,disabled:!fe,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:te?G.hidePassword:G.showPassword,children:e({size:X.icon,color:We})})}const e=g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.unit,{fontSize:X.text,color:Ce},m],children:g}):null,t=f?(0,_slotIcon.slotIconView)(f,renderSlot(f)):null;return e&&t?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=_?(0,_slotIcon.slotIconView)(_,renderSlot(_)):null,Ke=_reactNative.StyleSheet.flatten(h),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Ce,Ze=(0,_react.useMemo)(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=pe?"string"==typeof v||"number"==typeof v?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.prefix,{fontSize:X.text,color:Ce,marginRight:W.space.xs,lineHeight:re?K:void 0,paddingTop:re?se:void 0},h],children:v}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:re?K:void 0,justifyContent:"center",paddingTop:re?se:void 0}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.prefix,{fontSize:X.text,color:Ce,lineHeight:re?K:void 0},h],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:Ze,children:v})})}):null,tt=j?(0,_jsxRuntime.jsx)(_index4.Button,{variant:j.variant??"outline",tone:j.tone??"primary",size:S,label:j.label,leftIcon:j.icon,loading:j.loading,disabled:x||j.disabled,onPress:j.onPress,pressAnimation:!1,testID:j.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:re?"flex-start":"stretch"},b]}):null;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.container,{transform:[{translateX:Ae}]},A],children:[xe&&!ye?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:S,required:w,help:n,color:De,style:P,children:i}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:re?"flex-start":"stretch"}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.fieldWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:S,variant:Q,focused:Z,disabled:x,error:de,filled:le,minHeight:re?J:void 0,radius:z,leading:Je,leadingDivider:null!=_,paddingLeft:Be?W.space.none:void 0,trailing:Xe,slotAlign:re?"top":"center",slotLineHeight:re?K:void 0,topNotch:ke.topNotch,onPress:he,pressFeedback:!1,style:L,children:[et,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:ve,style:[$.input,{color:qe,fontSize:X.text,...ze.weightStyle,paddingLeft:Be?W.space.none:void 0,minHeight:re?J-2*X["padding-y"]:void 0,lineHeight:re?K:void 0,paddingTop:re?se:void 0,textAlignVertical:re?"top":"center"},B],textAlign:V,placeholder:ye&&!ge||Ee?void 0:a,placeholderTextColor:Ce,value:F&&null!=r?F(r):r,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:we,onBlur:Ne,editable:fe,readOnly:y,secureTextEntry:ne&&!te,multiline:re,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:N,selectionColor:Ve,accessibilityLabel:Ge,accessibilityState:{disabled:x},"aria-disabled":x,testID:M,...U}),Ee&&"string"==typeof a?(0,_jsxRuntime.jsx)(_FieldBase.RequiredPlaceholder,{text:a,color:Ce,fontSize:X.text,weightStyle:ze.weightStyle,align:re?"top":"center",paddingTop:re?se:void 0,textAlign:V}):null]})]}),ke.node]}),tt]}),ue||Me?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:be}],accessibilityLiveRegion:de?"polite":"none",children:[de?(0,_jsxRuntime.jsx)(_FieldBase.FieldErrorGlyph,{size:X["message-text"],color:Oe}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.messageText,{color:Oe,fontSize:X["message-text"],...(0,_index2.fontFor)(W,"normal")},k],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:Ue,children:He})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.footerSpacer}),Me?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...(0,_index2.fontFor)(W,"normal")}],children:Me}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});var _default=exports.default=Input;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=exports.DEFAULT_INPUT_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_textInk=require("../Text/textInk.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_INPUT_LABELS=exports.DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"},Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:r,onChangeText:s,error:l,helperText:o,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:_,rightIcon:f,unit:g,unitStyle:m,prefix:v,prefixStyle:h,readOnly:y=!1,action:j,actionStyle:b,size:I="md",variant:S,labelMode:R,required:w=!1,maxLength:N,showCounter:T=!0,textAlign:V,format:F,parse:D,style:A,containerStyle:L,inputStyle:B,labelStyle:P,messageStyle:k,radius:z,onFocus:q,onBlur:C,accessibilityLabel:E,labels:H,testID:M,editable:O,...U}=e;(0,_assertValidValue.assertValidValue)("Input","variant",S,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("Input","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("Input","labelMode",R,["float","top"]),(0,_assertValidValue.assertValidValue)("Input","type",e.type,["input","password","textarea"]);const G=(0,_react.useMemo)(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=(0,_index2.useTheme)(),$=(0,_react.useMemo)(()=>buildStyles(W),[W]),X=(0,_index2.resolveFieldSize)(W,I),J=W.components.input[I]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=S??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=R??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=(0,_react.useState)(!1),[te,ie]=(0,_react.useState)(!1),ne="password"===d||u||c,ae="password"===d||u,re="textarea"===d||p,se=re?Math.round(.1*X.text):0,le="string"==typeof r&&r.length>0,oe=(0,_FieldBase.hasFieldText)(l),de=!0===l||oe,ce=(0,_FieldBase.hasFieldText)(o),ue=oe||!de&&ce,xe=(0,_FieldBase.hasFieldText)(i),pe=(0,_FieldBase.hasFieldText)(v),fe=!x&&!1!==O,ge=Z||le||pe,me=(0,_react.useRef)(null),ve=(0,_react.useMemo)(()=>(0,_index3.mergeRefs)(me,t),[t]),he=(0,_react.useCallback)(()=>{fe&&me.current?.focus()},[fe]),ye=xe&&"float"===Y,je=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,be=(0,_react.useRef)((0,_index2.createAnimatedValue)(ue?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.timing(be,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:_reactNative.Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:_nativeDriver.nativeDriver});return e.start(),()=>e.stop()},[ue,be,W.motion.duration.fast,W.motion.ease["in-out"]]);const Ie=(0,_index.useReducedMotion)(),Se=W.settings.components.input?.shakeOnError??!1,Re=(0,_react.useRef)(de);(0,_react.useEffect)(()=>{if(!Se)return void(Re.current=de);let e;return de&&!Re.current&&(Ie||((0,_index2.setNativeValue)(je,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(je,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:-1,duration:50,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(je,{toValue:0,duration:100,useNativeDriver:_nativeDriver.nativeDriver})]),e.start()),(0,_index3.triggerHaptic)("notificationError")),Re.current=de,()=>e?.stop()},[de,je,Se,Ie]);const we=(0,_react.useCallback)(e=>{ee(!0),q?.(e)},[q]),Ne=(0,_react.useCallback)(e=>{ee(!1),C?.(e)},[C]),Te=(0,_react.useCallback)(()=>{(0,_index3.triggerHaptic)("selection"),ie(e=>!e)},[]),Ve=W.colors["field-caret"],Fe=W.settings.components.input?.tintLabelOnFocus??!1,De=Z&&Fe?W.colors["field-border-focus"]:W.colors["field-label"],Ae=je.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Le=Boolean(f)||Boolean(g)||ae,Be="underline"===Q,Pe=_?X.icon+W.space.md+1+W.space.md:0,ke=(0,_useFloatingLabel.useFloatingLabel)({label:i,enabled:ye,floated:ge,required:w,variant:Q,sizeTokens:X,leadingOffset:Pe,trailingOffset:Le?X.icon+W.space.sm:0,textAlign:"center"===V||"right"===V?V:"left",paddingLeft:Be?W.space.none:X["padding-x"],lineHeight:re?K:void 0,restNudge:se,floatTrim:re?2:0,color:De,style:P}),ze=(0,_FieldBase.resolveFieldTextStyle)(W,{disabled:x}),qe=ze.color,Ce=ze.placeholderColor,Ee=w&&!xe&&!le&&"string"==typeof a&&a.length>0,He=de?l:o,Me=T&&"number"==typeof N&&"string"==typeof r?`${r.length} / ${N}`:null,Oe=de?W.colors["field-message"]:W.colors["text-muted"],Ue=(0,_textInk.useTextInk)(k,X["message-text"],Oe),Ge=E??(0,_FieldBase.fieldTextAsString)(i)??a,We=x?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:x,error:de,color:We,size:X.icon},renderSlot=e=>(0,_slotIcon.renderSlotIcon)(e,$e),Xe=(()=>{if(ae){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?_defaultIcons.defaultIcons.eyeOff:_defaultIcons.defaultIcons.eye);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Te,disabled:!fe,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:te?G.hidePassword:G.showPassword,children:e({size:X.icon,color:We})})}const e=g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.unit,{fontSize:X.text,color:Ce},m],children:g}):null,t=f?(0,_slotIcon.slotIconView)(f,renderSlot(f)):null;return e&&t?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=_?(0,_slotIcon.slotIconView)(_,renderSlot(_)):null,Ke=_reactNative.StyleSheet.flatten(h),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Ce,Ze=(0,_react.useMemo)(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=pe?"string"==typeof v||"number"==typeof v?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.prefix,{fontSize:X.text,color:Ce,marginRight:W.space.xs,lineHeight:re?K:void 0,paddingTop:re?se:void 0},h],children:v}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:re?K:void 0,justifyContent:"center",paddingTop:re?se:void 0}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.prefix,{fontSize:X.text,color:Ce,lineHeight:re?K:void 0},h],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:Ze,children:v})})}):null,tt=j?(0,_jsxRuntime.jsx)(_index4.Button,{variant:j.variant??"outline",tone:j.tone??"primary",size:I,label:j.label,leftIcon:j.icon,loading:j.loading,disabled:x||j.disabled,onPress:j.onPress,pressAnimation:!1,testID:j.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:re?"flex-start":"stretch"},b]}):null;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.container,{transform:[{translateX:Ae}]},A],children:[xe&&!ye?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:I,required:w,help:n,color:De,style:P,children:i}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:re?"flex-start":"stretch"}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.fieldWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{testID:M?`${M}-field`:void 0,size:I,variant:Q,focused:Z,disabled:x,error:de,filled:le,minHeight:re?J:void 0,radius:z,leading:Je,leadingDivider:null!=_,paddingLeft:Be?W.space.none:void 0,trailing:Xe,slotAlign:re?"top":"center",slotLineHeight:re?K:void 0,topNotch:ke.topNotch,onPress:he,pressFeedback:!1,style:L,children:[et,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:ve,style:[$.input,{color:qe,fontSize:X.text,...ze.weightStyle,paddingLeft:Be?W.space.none:void 0,minHeight:re?J-2*X["padding-y"]:void 0,lineHeight:re?K:void 0,paddingTop:re?se:void 0,textAlignVertical:re?"top":"center"},B],textAlign:V,placeholder:ye&&!ge||Ee?void 0:a,placeholderTextColor:Ce,value:F&&null!=r?F(r):r,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:we,onBlur:Ne,editable:fe,readOnly:y,secureTextEntry:ne&&!te,multiline:re,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:N,selectionColor:Ve,accessibilityLabel:Ge,accessibilityState:{disabled:x},"aria-disabled":x,testID:M,...U}),Ee&&"string"==typeof a?(0,_jsxRuntime.jsx)(_FieldBase.RequiredPlaceholder,{text:a,color:Ce,fontSize:X.text,weightStyle:ze.weightStyle,align:re?"top":"center",paddingTop:re?se:void 0,textAlign:V}):null]})]}),ke.node]}),tt]}),ue||Me?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:be}],accessibilityLiveRegion:de?"polite":"none",children:[de?(0,_jsxRuntime.jsx)(_FieldBase.FieldErrorGlyph,{size:X["message-text"],color:Oe}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.messageText,{color:Oe,fontSize:X["message-text"],...(0,_index2.fontFor)(W,"normal")},k],children:(0,_jsxRuntime.jsx)(_textInk.TextInkContext.Provider,{value:Ue,children:He})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.footerSpacer}),Me?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...(0,_index2.fontFor)(W,"normal")}],children:Me}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});var _default=exports.default=Input;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.MessageBubble=exports.DEFAULT_MESSAGE_BUBBLE_LABELS=void 0;var _markdownCore=require("@webority/markdown-core"),_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index2=require("../AppIcon/index.js"),_index3=require("../Button/index.js"),_index4=require("../Markdown/index.js"),_useContextMenu=require("../Menu/useContextMenu.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_BUBBLE_LABELS=exports.DEFAULT_MESSAGE_BUBBLE_LABELS=Object.freeze({you:"You",sending:"Sending",sent:"Sent",delivered:"Delivered",read:"Read",failed:"Not sent",retry:"Try again",copy:"Copy",replyTo:e=>e?`Reply to ${e}`:"Reply"}),MAX_WIDTH="85%",STATUS_ICON=14,statusIcon=e=>{switch(e){case"sending":return"clock";case"sent":return"check";case"failed":return"alert-circle";default:return"check-check"}},statusColour=(e,s)=>{switch(s){case"read":return e.colors["info-text"];case"failed":return e.colors["danger-text"];default:return e.colors["text-subtle"]}},MessageBubble=({side:e,text:s,children:t,markdown:r,groupPosition:n="single",author:i,time:a,status:o,replyTo:l,streaming:u=!1,error:c,onRetry:d,actions:x,onCopy:b,onLongPress:m,footer:_,labels:p,haptic:y,style:h,testID:g})=>{(0,_assertValidValue.assertValidValue)("MessageBubble","side",e,["mine","theirs"]),(0,_assertValidValue.assertValidValue)("MessageBubble","groupPosition",n,["single","first","middle","last"]),(0,_assertValidValue.assertValidValue)("MessageBubble","status",o,["sending","sent","delivered","read","failed"]);const f=(0,_index.useTheme)(),j=(0,_react.useMemo)(()=>buildStyles(f),[f]),B=p?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...p}:DEFAULT_MESSAGE_BUBBLE_LABELS,L="mine"===e,T=!c&&(r??"theirs"===e),R="single"===n||"first"===n,v="single"===n||"last"===n,E=null==a?"":(0,_mobileCore.formatTime)(a),M=("failed"===o||Boolean(c))&&Boolean(d),S=L?B.you:i??"",A=(0,_react.useMemo)(()=>{const e=[];return b&&!x?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:B.copy,onPress:()=>b(s)}),x&&e.push(...x),l?.onPress&&e.push({name:"openReply",label:B.replyTo(l.author),onPress:l.onPress}),M&&d&&e.push({name:"retry",label:B.retry,onPress:d}),e},[x,b,s,l,M,d,B]),P=(x?.length??0)>0||Boolean(b),V=(0,_react.useMemo)(()=>P?{items:A.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[P,A]),C=(0,_useContextMenu.useContextMenu)(V,{haptic:y,testID:g}),k=C.hostProps.onLongPress,w=!t||(x?.length??0)>0,I=o&&L?B[o]:"",q=(0,_react.useMemo)(()=>T&&null==t?(0,_markdownCore.markdownToPlainText)(s):s,[T,t,s]),D=[S,E,q,l?`${B.replyTo(l.author)}: ${l.text}`:"",I].filter(Boolean).join(", "),$=(0,_react.useRef)(u);(0,_react.useEffect)(()=>{$.current&&!u&&!c&&s&&(0,_announce.announce)(S?`${S}, ${q}`:q),$.current=u},[u,c,s,q,S]);const U=(0,_react.useRef)(c);(0,_react.useEffect)(()=>{c&&c!==U.current&&(0,_announce.announce)(c,{polite:!1}),U.current=c},[c]);const N=(0,_react.useCallback)(e=>{k?.(e),m?.()},[k,m]),F=(0,_react.useCallback)(e=>{A.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[A]),z=f.radius.xl,H=f.radius.sm,O=L?{borderTopRightRadius:R?z:H,borderBottomRightRadius:v?z:H}:{borderTopLeftRadius:R?z:H,borderBottomLeftRadius:v?z:H},G=t??(T?(0,_jsxRuntime.jsx)(_index4.Markdown,{children:s}):(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",children:s})),W=l?(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${B.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,(0,_jsxRuntime.jsx)(_index5.Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,L?j.mine:j.theirs,O],Y=w?{accessible:!0,accessibilityLabel:D,accessibilityState:{busy:u},"aria-busy":u,accessibilityActions:A.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:F}:{accessible:!1},J=P?(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:C.hostRef,...C.hostProps,onLongPress:N,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[W,G]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[W,G]}),K=v&&(""!==E||L&&o);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[j.root,L?j.rootMine:j.rootTheirs,{marginTop:R?f.space.sm:f.space.xxs},h],accessibilityState:{busy:u},"aria-busy":u,testID:g,children:[!L&&R&&i?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:w?"no-hide-descendants":"auto",accessibilityElementsHidden:w,children:i}):null,J,C.renderSurface(),K?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[j.meta,L?j.metaMine:null],importantForAccessibility:w?"no-hide-descendants":"auto",accessibilityElementsHidden:w,children:[E?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",color:"tertiary",children:E}):null,L&&o?(0,_jsxRuntime.jsx)(_index2.AppIcon,{name:statusIcon(o),size:14,color:statusColour(f,o),accessibilityLabel:B[o],testID:g?`${g}-status-${o}`:void 0}):null]}):null,c?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"bodySmall",color:"danger",style:L?j.endText:null,children:c}):null,M?(0,_jsxRuntime.jsx)(_index3.Button,{label:B.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,_]})};exports.MessageBubble=MessageBubble;const buildStyles=e=>_reactNative.StyleSheet.create({root:{maxWidth:"85%",gap:e.space.xs},rootMine:{alignSelf:"flex-end",alignItems:"flex-end"},rootTheirs:{alignSelf:"flex-start",alignItems:"flex-start"},author:{paddingHorizontal:e.space.md},bubble:{borderRadius:e.radius.xl,..._corners.smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm,gap:e.space.xs},mine:{backgroundColor:e.colors["primary-soft"]},theirs:{backgroundColor:e.colors["bg-subtle"]},quote:{borderLeftWidth:3,borderLeftColor:e.colors.primary,paddingLeft:e.space.sm,paddingVertical:e.space.xs},meta:{flexDirection:"row",alignItems:"center",gap:e.space.xs,paddingHorizontal:e.space.xs},metaMine:{justifyContent:"flex-end"},endText:{textAlign:"right"}});var _default=exports.default=MessageBubble;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.MessageBubble=exports.DEFAULT_MESSAGE_BUBBLE_LABELS=void 0;var _markdownCore=require("@webority/markdown-core"),_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_index2=require("../AppIcon/index.js"),_index3=require("../Button/index.js"),_index4=require("../Markdown/index.js"),_useContextMenu=require("../Menu/useContextMenu.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_BUBBLE_LABELS=exports.DEFAULT_MESSAGE_BUBBLE_LABELS=Object.freeze({you:"You",sending:"Sending",sent:"Sent",delivered:"Delivered",read:"Read",failed:"Not sent",retry:"Try again",copy:"Copy",replyTo:e=>e?`Reply to ${e}`:"Reply"}),MAX_WIDTH="85%",STATUS_ICON=14,statusIcon=e=>{switch(e){case"sending":return"clock";case"sent":return"check";case"failed":return"alert-circle";default:return"check-check"}},statusColour=(e,s)=>{switch(s){case"read":return e.colors["info-text"];case"failed":return e.colors["danger-text"];default:return e.colors["text-subtle"]}},MessageBubble=({side:e,text:s,children:t,markdown:r,groupPosition:n="single",author:i,time:a,status:o,replyTo:l,streaming:u=!1,error:c,onRetry:d,actions:x,onCopy:b,onLongPress:m,footer:_,labels:p,haptic:y,style:h,testID:g})=>{(0,_assertValidValue.assertValidValue)("MessageBubble","side",e,["mine","theirs"]),(0,_assertValidValue.assertValidValue)("MessageBubble","groupPosition",n,["single","first","middle","last"]),(0,_assertValidValue.assertValidValue)("MessageBubble","status",o,["sending","sent","delivered","read","failed"]);const f=(0,_index.useTheme)(),j=(0,_react.useMemo)(()=>buildStyles(f),[f]),B=p?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...p}:DEFAULT_MESSAGE_BUBBLE_LABELS,L="mine"===e,T=!c&&(r??"theirs"===e),v="single"===n||"first"===n,R="single"===n||"last"===n,S=null==a?"":(0,_mobileCore.formatTime)(a),E=("failed"===o||Boolean(c))&&Boolean(d),M=L?B.you:i??"",P=(0,_react.useMemo)(()=>{const e=[];return b&&!x?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:B.copy,onPress:()=>b(s)}),x&&e.push(...x),l?.onPress&&e.push({name:"openReply",label:B.replyTo(l.author),onPress:l.onPress}),E&&d&&e.push({name:"retry",label:B.retry,onPress:d}),e},[x,b,s,l,E,d,B]),A=(x?.length??0)>0||Boolean(b),V=(0,_react.useMemo)(()=>A?{items:P.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[A,P]),C=(0,_useContextMenu.useContextMenu)(V,{haptic:y,testID:g}),k=C.hostProps.onLongPress,w=!t||(x?.length??0)>0,I=o&&L?B[o]:"",q=(0,_react.useMemo)(()=>T&&null==t?(0,_markdownCore.markdownToPlainText)(s):s,[T,t,s]),D=[M,S,q,l?`${B.replyTo(l.author)}: ${l.text}`:"",I].filter(Boolean).join(", "),$=(0,_react.useRef)(u);(0,_react.useEffect)(()=>{$.current&&!u&&!c&&s&&(0,_announce.announce)(M?`${M}, ${q}`:q),$.current=u},[u,c,s,q,M]);const N=(0,_react.useRef)(c);(0,_react.useEffect)(()=>{c&&c!==N.current&&(0,_announce.announce)(c,{polite:!1}),N.current=c},[c]);const U=(0,_react.useCallback)(e=>{k?.(e),m?.()},[k,m]),F=(0,_react.useCallback)(e=>{P.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[P]),O=f.radius.xl,z=f.radius.sm,H=L?{borderTopRightRadius:v?O:z,borderBottomRightRadius:R?O:z}:{borderTopLeftRadius:v?O:z,borderBottomLeftRadius:R?O:z},G=t??(T?(0,_jsxRuntime.jsx)(_index4.Markdown,{children:s}):(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",children:s})),W=l?(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${B.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,(0,_jsxRuntime.jsx)(_index5.Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,L?j.mine:j.theirs,H],Y=w?{accessible:!0,accessibilityLabel:D,accessibilityState:{busy:u},"aria-busy":u,accessibilityActions:P.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:F}:{accessible:!1},J=A?(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:C.hostRef,...C.hostProps,onLongPress:U,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[W,G]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[W,G]}),K=R&&(""!==S||L&&o);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[j.root,L?j.rootMine:j.rootTheirs,{marginTop:v?f.space.sm:f.space.xxs},h],accessibilityState:{busy:u},"aria-busy":u,testID:g,children:[!L&&v&&i?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:w?"no-hide-descendants":"auto",accessibilityElementsHidden:w,..."web"===_reactNative.Platform.OS?{"aria-hidden":!0}:null,children:i}):null,J,C.renderSurface(),K?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[j.meta,L?j.metaMine:null],importantForAccessibility:w?"no-hide-descendants":"auto",accessibilityElementsHidden:w,children:[S?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"caption",color:"tertiary",children:S}):null,L&&o?(0,_jsxRuntime.jsx)(_index2.AppIcon,{name:statusIcon(o),size:14,color:statusColour(f,o),accessibilityLabel:B[o],testID:g?`${g}-status-${o}`:void 0}):null]}):null,c?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"bodySmall",color:"danger",style:L?j.endText:null,children:c}):null,E?(0,_jsxRuntime.jsx)(_index3.Button,{label:B.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,_]})};exports.MessageBubble=MessageBubble;const buildStyles=e=>_reactNative.StyleSheet.create({root:{maxWidth:"85%",gap:e.space.xs},rootMine:{alignSelf:"flex-end",alignItems:"flex-end"},rootTheirs:{alignSelf:"flex-start",alignItems:"flex-start"},author:{paddingHorizontal:e.space.md},bubble:{borderRadius:e.radius.xl,..._corners.smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm,gap:e.space.xs},mine:{backgroundColor:e.colors["primary-soft"]},theirs:{backgroundColor:e.colors["bg-subtle"]},quote:{borderLeftWidth:3,borderLeftColor:e.colors.primary,paddingLeft:e.space.sm,paddingVertical:e.space.xs},meta:{flexDirection:"row",alignItems:"center",gap:e.space.xs,paddingHorizontal:e.space.xs},metaMine:{justifyContent:"flex-end"},endText:{textAlign:"right"}});var _default=exports.default=MessageBubble;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=exports.DEFAULT_MODAL_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_placement=require("../../utils/placement.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MODAL_LABELS=exports.DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"}),MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"],MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{(0,_assertValidValue.assertValidValue)("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:r,onClose:a,presentation:i="centered",backdropOpacity:n,backdropPressClose:o=!0,animationDuration:s,animateMount:c=!0,accessibilityLabel:l,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:p,onDismissed:f,haptic:v,labels:h,anchor:g,placement:b="auto",align:S="center",testID:A,bare:x=!1,onInsetsChange:M}=e,D=(0,_index.useTheme)(),y=(0,_react.useMemo)(()=>({...DEFAULT_MODAL_LABELS,...h}),[h]),N=(0,_usePresenceMotion.usePresenceMotion)(),[R,C]=(0,_ModalSafeArea.useModalInsets)();(0,_react.useEffect)(()=>{M?.(R)},[R,M]);const{width:j,height:w}=(0,_reactNative.useWindowDimensions)(),[E,L]=(0,_react.useState)({width:0,height:0}),V=s??N.duration("default"),T=_reactNative.Dimensions.get("window").height,q=(0,_react.useRef)(!c&&r),I=q.current,O=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:.9)).current,P=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:0)).current,F=(0,_react.useRef)((0,_index.createAnimatedValue)(I?0:T)).current,k=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:0)).current,z=(0,_react.useRef)(null),H=(0,_react.useRef)(!1),[W,U]=(0,_react.useState)(r),B=(0,_react.useMemo)(()=>buildStyles(D),[D]),G=(0,_react.useMemo)(()=>{if("anchored"!==i||void 0===g)return null;const e={width:j,height:w,insets:{top:R.top,bottom:R.bottom,left:0,right:0}},t=(0,_placement.computePlacement)(g,E,e,b,{align:S});return{...t,maxHeight:(0,_placement.placementMaxHeight)(t.placement,(0,_placement.placementRoom)(g,e))}},[i,g,E,b,S,j,w,R.top,R.bottom]),K=(0,_react.useMemo)(()=>{const e=D.colors.scrim;return"number"!=typeof n?"anchored"===i?(0,_color.transparentOf)(e):e:(0,_color.withAlpha)(e,n)??e},[D.colors.scrim,n,i]),Y=(0,_react.useMemo)(()=>k.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(K),K]}),[k,K]);(0,_react.useEffect)(()=>{r&&(_reactNative.Keyboard.dismiss(),U(!0))},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&W&&q.current)q.current=!1;else if(r&&W){const t=_reactNative.Animated.timing(k,{toValue:1,duration:N.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),N.reduced||"anchored"===i){P.setValue(0),F.setValue(0),O.setValue(1);const t=_reactNative.Animated.timing(P,{toValue:1,duration:V,useNativeDriver:_nativeDriver.nativeDriver});t.start(),e.push(t)}else if("bottom"===i){P.setValue(1);const t=_reactNative.Animated.spring(F,{toValue:0,damping:D.motion.spring.gentle.damping,stiffness:D.motion.spring.gentle.stiffness,mass:D.motion.spring.gentle.mass,useNativeDriver:_nativeDriver.nativeDriver});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(O,{toValue:1,damping:D.motion.spring.gentle.damping,stiffness:D.motion.spring.gentle.stiffness,mass:D.motion.spring.gentle.mass,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(P,{toValue:1,duration:V,useNativeDriver:_nativeDriver.nativeDriver})]);t.start(),e.push(t)}}else if(W){const t=N.duration("fast"),r=_reactNative.Easing.bezier(...D.motion.ease.accelerate),a=_reactNative.Animated.timing(P,{toValue:0,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}),n=N.reduced||"anchored"===i?a:"bottom"===i?_reactNative.Animated.timing(F,{toValue:T,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}):_reactNative.Animated.parallel([_reactNative.Animated.timing(O,{toValue:.9,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}),a]),o=_reactNative.Animated.parallel([n,_reactNative.Animated.timing(k,{toValue:0,duration:N.duration("default"),useNativeDriver:!1})]);o.start(({finished:e})=>{e&&(F.setValue(T),U(!1))}),e.push(o)}return()=>e.forEach(e=>{e.stop()})},[r,W,i,V,O,P,k,F,T,D.motion.spring.gentle.damping,D.motion.spring.gentle.stiffness,D.motion.spring.gentle.mass,N,D.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{z.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(z.current,"focus")},150),H.current=!0):H.current&&(H.current=!1,p?.current&&(t=setTimeout(()=>{const e=p.current;e&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(e,"focus")},V))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[r,V,p]);const J=(0,_react.useRef)(f);J.current=f;const Q=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{if(r)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),MODAL_DISMISS_GRACE_MS);return()=>clearTimeout(e)},[r]);const X=(0,_react.useCallback)(()=>{if(!o)return;const e=(0,_hapticUtils.resolveHaptic)(v,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),a()},[o,a,v]),Z=(0,_react.useCallback)(()=>{u&&a()},[u,a]),$=(0,_SquircleFill.useSquircle)(!x&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,D.radius.xl),ee=(0,_react.useCallback)(e=>{$.onLayout(e);const{width:t,height:r}=e.nativeEvent.layout;L(e=>e.width===t&&e.height===r?e:{width:t,height:r})},[$.onLayout]),te=(0,_react.useMemo)(()=>x?"bottom"===i?B.bottomContent:"fullScreen"===i?B.fullScreenContent:B.bareCentredContent:"anchored"===i?[B.anchoredContent,{left:G?.x,top:G?.y,maxHeight:G?.maxHeight,backgroundColor:D.colors.surface,borderRadius:D.radius.lg,..._corners.smoothCorners},D.shadow.modal]:"fullScreen"===i?[B.fullScreenContent,{backgroundColor:D.colors.surface}]:"bottom"===i?[B.bottomContent,{backgroundColor:D.colors.surface,borderTopLeftRadius:D.radius.xl,borderTopRightRadius:D.radius.xl,..._corners.smoothCorners,paddingTop:D.space.lg,paddingHorizontal:D.space.lg,paddingBottom:D.space.lg+R.bottom},D.shadow.modal]:[B.centeredContent,{backgroundColor:D.colors.surface,borderRadius:$.active&&$.size?(0,_squircle.squircleHostRadius)($.size.width,$.size.height,D.radius.xl):D.radius.xl,..._corners.smoothCorners,padding:D.space.xl},D.shadow.modal],[i,D,B,R.bottom,$.active,$.size,G,x]),re=(0,_react.useMemo)(()=>"anchored"===i?B.anchoredWrapper:"bottom"===i?B.bottomWrapper:"fullScreen"===i?B.fullScreenWrapper:B.centeredWrapper,[i,B]),ae=(0,_react.useMemo)(()=>"bottom"===i?{opacity:P,transform:[{translateY:F}]}:"fullScreen"===i||"anchored"===i?{opacity:P}:{opacity:P,transform:[{scale:O}]},[i,O,P,F]);if("anchored"===i&&void 0===g)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(x&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:W,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:A,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{z.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:B.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:l,children:(0,_jsxRuntime.jsxs)(_ModalSafeArea.ModalSafeArea,{onInsets:C,children:[(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{collapsable:!1,style:[_reactNative.StyleSheet.absoluteFill,re,{backgroundColor:Y},_],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:X,accessibilityRole:o?"button":void 0,accessibilityLabel:o?y.close:void 0,accessible:!!o&&void 0,importantForAccessibility:o?void 0:"no",disabled:!o}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[te,ae,E.height>0||"anchored"!==i?null:B.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:$.size.width,height:$.size.height,radius:D.radius.xl,fill:D.colors.surface}):null,d]})]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});var _default=exports.default=Modal;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=exports.DEFAULT_MODAL_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_nativeDriver=require("../../utils/nativeDriver.js"),_placement=require("../../utils/placement.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MODAL_LABELS=exports.DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"}),MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"],MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{(0,_assertValidValue.assertValidValue)("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:r,onClose:a,presentation:i="centered",backdropOpacity:n,backdropPressClose:o=!0,animationDuration:s,animateMount:c=!0,accessibilityLabel:l,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:p,onDismissed:f,haptic:v,labels:h,anchor:g,placement:b="auto",align:S="center",testID:A,bare:x=!1,onInsetsChange:M}=e,D=(0,_index.useTheme)(),y=(0,_react.useMemo)(()=>({...DEFAULT_MODAL_LABELS,...h}),[h]),N=(0,_usePresenceMotion.usePresenceMotion)(),[R,C]=(0,_ModalSafeArea.useModalInsets)();(0,_react.useEffect)(()=>{M?.(R)},[R,M]);const{width:j,height:w}=(0,_reactNative.useWindowDimensions)(),[E,L]=(0,_react.useState)({width:0,height:0}),V=s??N.duration("default"),T=_reactNative.Dimensions.get("window").height,q=(0,_react.useRef)(!c&&r),I=q.current,O=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:.9)).current,P=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:0)).current,k=(0,_react.useRef)((0,_index.createAnimatedValue)(I?0:T)).current,F=(0,_react.useRef)((0,_index.createAnimatedValue)(I?1:0)).current,z=(0,_react.useRef)(null),H=(0,_react.useRef)(!1),[W,U]=(0,_react.useState)(r),B=(0,_react.useMemo)(()=>buildStyles(D),[D]),G=(0,_react.useMemo)(()=>{if("anchored"!==i||void 0===g)return null;const e={width:j,height:w,insets:{top:R.top,bottom:R.bottom,left:0,right:0}},t=(0,_placement.computePlacement)(g,E,e,b,{align:S});return{...t,maxHeight:(0,_placement.placementMaxHeight)(t.placement,(0,_placement.placementRoom)(g,e))}},[i,g,E,b,S,j,w,R.top,R.bottom]),K=(0,_react.useMemo)(()=>{const e=D.colors.scrim;return"number"!=typeof n?"anchored"===i?(0,_color.transparentOf)(e):e:(0,_color.withAlpha)(e,n)??e},[D.colors.scrim,n,i]),Y=(0,_react.useMemo)(()=>F.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(K),K]}),[F,K]);(0,_react.useEffect)(()=>{r&&(_reactNative.Keyboard.dismiss(),U(!0))},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&W&&q.current)q.current=!1;else if(r&&W){const t=_reactNative.Animated.timing(F,{toValue:1,duration:N.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),N.reduced||"anchored"===i){P.setValue(0),k.setValue(0),O.setValue(1);const t=_reactNative.Animated.timing(P,{toValue:1,duration:V,useNativeDriver:_nativeDriver.nativeDriver});t.start(),e.push(t)}else if("bottom"===i){P.setValue(1);const t=_reactNative.Animated.spring(k,{toValue:0,damping:D.motion.spring.gentle.damping,stiffness:D.motion.spring.gentle.stiffness,mass:D.motion.spring.gentle.mass,useNativeDriver:_nativeDriver.nativeDriver});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(O,{toValue:1,damping:D.motion.spring.gentle.damping,stiffness:D.motion.spring.gentle.stiffness,mass:D.motion.spring.gentle.mass,useNativeDriver:_nativeDriver.nativeDriver}),_reactNative.Animated.timing(P,{toValue:1,duration:V,useNativeDriver:_nativeDriver.nativeDriver})]);t.start(),e.push(t)}}else if(W){const t=N.duration("fast"),r=_reactNative.Easing.bezier(...D.motion.ease.accelerate),a=_reactNative.Animated.timing(P,{toValue:0,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}),n=N.reduced||"anchored"===i?a:"bottom"===i?_reactNative.Animated.timing(k,{toValue:T,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}):_reactNative.Animated.parallel([_reactNative.Animated.timing(O,{toValue:.9,duration:t,easing:r,useNativeDriver:_nativeDriver.nativeDriver}),a]),o=_reactNative.Animated.parallel([n,_reactNative.Animated.timing(F,{toValue:0,duration:N.duration("default"),useNativeDriver:!1})]);o.start(({finished:e})=>{e&&(k.setValue(T),U(!1))}),e.push(o)}return()=>e.forEach(e=>{e.stop()})},[r,W,i,V,O,P,F,k,T,D.motion.spring.gentle.damping,D.motion.spring.gentle.stiffness,D.motion.spring.gentle.mass,N,D.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{z.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(z.current,"focus")},150),H.current=!0):H.current&&(H.current=!1,p?.current&&(t=setTimeout(()=>{const e=p.current;e&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(e,"focus")},V))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[r,V,p]);const $=(0,_react.useRef)(f);$.current=f;const J=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{if(r)return void(J.current=!0);if(!J.current)return;J.current=!1;const e=setTimeout(()=>$.current?.(),MODAL_DISMISS_GRACE_MS);return()=>clearTimeout(e)},[r]);const Q=(0,_react.useCallback)(()=>{if(!o)return;const e=(0,_hapticUtils.resolveHaptic)(v,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),a()},[o,a,v]),X=(0,_react.useCallback)(()=>{u&&a()},[u,a]),Z=(0,_SquircleFill.useSquircle)(!x&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,D.radius.xl),ee=(0,_react.useCallback)(e=>{Z.onLayout(e);const{width:t,height:r}=e.nativeEvent.layout;L(e=>e.width===t&&e.height===r?e:{width:t,height:r})},[Z.onLayout]),te=(0,_react.useMemo)(()=>x?"bottom"===i?B.bottomContent:"fullScreen"===i?B.fullScreenContent:B.bareCentredContent:"anchored"===i?[B.anchoredContent,{left:G?.x,top:G?.y,maxHeight:G?.maxHeight,backgroundColor:D.colors.surface,borderRadius:D.radius.lg,..._corners.smoothCorners},D.shadow.modal]:"fullScreen"===i?[B.fullScreenContent,{backgroundColor:D.colors.surface}]:"bottom"===i?[B.bottomContent,{backgroundColor:D.colors.surface,borderTopLeftRadius:D.radius.xl,borderTopRightRadius:D.radius.xl,..._corners.smoothCorners,paddingTop:D.space.lg,paddingHorizontal:D.space.lg,paddingBottom:D.space.lg+R.bottom},D.shadow.modal]:[B.centeredContent,{backgroundColor:D.colors.surface,borderRadius:Z.active&&Z.size?(0,_squircle.squircleHostRadius)(Z.size.width,Z.size.height,D.radius.xl):D.radius.xl,..._corners.smoothCorners,padding:D.space.xl},D.shadow.modal],[i,D,B,R.bottom,Z.active,Z.size,G,x]),re=(0,_react.useMemo)(()=>"anchored"===i?B.anchoredWrapper:"bottom"===i?B.bottomWrapper:"fullScreen"===i?B.fullScreenWrapper:B.centeredWrapper,[i,B]),ae=(0,_react.useMemo)(()=>"bottom"===i?{opacity:P,transform:[{translateY:k}]}:"fullScreen"===i||"anchored"===i?{opacity:P}:{opacity:P,transform:[{scale:O}]},[i,O,P,k]);if("anchored"===i&&void 0===g)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(x&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:W,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:X,testID:A,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{z.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:B.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:l,children:(0,_jsxRuntime.jsxs)(_ModalSafeArea.ModalSafeArea,{onInsets:C,children:[(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{collapsable:!1,style:[_reactNative.StyleSheet.absoluteFill,re,{backgroundColor:Y},_],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:Q,accessibilityRole:o?"button":void 0,accessibilityLabel:o?y.close:void 0,accessible:!!o&&void 0,importantForAccessibility:o?void 0:"no",disabled:!o,testID:A?`${A}-backdrop`:void 0}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[te,ae,E.height>0||"anchored"!==i?null:B.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[Z.active&&Z.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:Z.size.width,height:Z.size.height,radius:D.radius.xl,fill:D.colors.surface}):null,d]})]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});var _default=exports.default=Modal;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NumberInput=exports.DEFAULT_NUMBER_INPUT_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index4=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(s,r,i):s[r]=e[r]);return s}const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"],DEFAULT_NUMBER_INPUT_LABELS=exports.DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"}),DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=exports.NumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,min:s=Number.NEGATIVE_INFINITY,max:n=Number.POSITIVE_INFINITY,step:l=1,allowDecimal:c=!1,precision:u=0,label:o,help:d,helperText:_,error:b,disabled:m=!1,size:p="md",variant:x="inline",unit:f,haptic:N,labels:h,accessibilityLabel:y,style:I,containerStyle:T,inputStyle:j,buttonStyle:S,unitStyle:g,labelStyle:R,textInputProps:F,testID:v}=e;(0,_assertValidValue.assertValidValue)("NumberInput","size",e.size,NUMBER_INPUT_SIZES),(0,_assertValidValue.assertValidValue)("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const E=(0,_react.useMemo)(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...h}),[h]),[V,L]=(0,_index.useControllableState)({value:i,defaultValue:r??e.min??0,onChange:a}),P=(0,_index2.useTheme)(),B=(0,_index2.resolveFieldSize)(P,p),A=(0,_FieldBase.resolveFieldTextStyle)(P,{disabled:m}),U=(0,_react.useMemo)(()=>buildStyles(P),[P]),C=(0,_react.useRef)(null),[w,z]=(0,_react.useState)(formatValue(V,c,u)),[M,k]=(0,_react.useState)(!1),[D,O]=(0,_react.useState)(!1),q=(0,_react.useCallback)(()=>{m||C.current?.focus()},[m]),W=(0,_react.useRef)(null),H=(0,_react.useRef)(null),G=(0,_react.useCallback)(()=>{null!==W.current&&(clearTimeout(W.current),W.current=null),null!==H.current&&(clearInterval(H.current),H.current=null)},[]);(0,_react.useEffect)(()=>G,[G]),(0,_react.useEffect)(()=>{M||z(formatValue(V,c,u))},[V,c,u,M]);const Y=V<=s,Z=V>=n,$=!m,J=(0,_react.useCallback)(e=>{const t=roundToPrecision(e,c?u:0),i=clamp(t,s,n);i!==V&&L(i)},[c,n,s,L,u,V]),K=(0,_react.useCallback)(()=>{if(!$||Y)return;const e=(0,_index3.resolveHaptic)(N,"selection");e&&(0,_index3.triggerHaptic)(e),J(V-l)},[Y,$,N,J,l,V]),Q=(0,_react.useCallback)(()=>{if(!$||Z)return;const e=(0,_index3.resolveHaptic)(N,"selection");e&&(0,_index3.triggerHaptic)(e),J(V+l)},[Z,$,N,J,l,V]);_react.default.useImperativeHandle(t,()=>({focus:()=>C.current?.focus(),blur:()=>C.current?.blur(),clear:()=>{z(""),Number.isFinite(s)&&s>0?L(s):L(0<s?s:Math.min(n,0))}}),[n,s,L]);const X=(0,_react.useCallback)(e=>{$&&(G(),W.current=setTimeout(()=>{H.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[G,K,Q,$]),ee=(0,_react.useCallback)(e=>{const t=sanitizeTyped(e,c);z(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=s&&i<=n&&i!==V&&L(roundToPrecision(i,c?u:0))},[c,n,s,L,u,V]),te=(0,_react.useCallback)(()=>{k(!1),O(!1);const e=Number(w);if(""===w||!Number.isFinite(e))return void z(formatValue(V,c,u));const t=roundToPrecision(e,c?u:0),i=clamp(t,s,n);i!==V&&L(i),z(formatValue(i,c,u))},[c,w,n,s,L,u,V]),ie=(0,_react.useCallback)(()=>{k(!0),O(!0)},[]),re=Y||m?P.colors["text-disabled"]:P.colors["text-body"],ae=Z||m?P.colors["text-disabled"]:P.colors["text-body"],se=B.icon+8,renderStepper=(e,t,i,r,a,s)=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:G,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:se,height:se,alignItems:"center",justifyContent:"center",borderRadius:P.radius.pill,..._corners.smoothCorners},e&&!i?{backgroundColor:P.colors["surface-pressed"]}:null,S],testID:`${v??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:"semibold",style:{fontSize:B.icon,color:a,fontWeight:P.weight.semibold,lineHeight:B.icon+2},children:s})}),ne=y??(0,_FieldBase.fieldTextAsString)(o)??E.input,le=!0===b||(0,_FieldBase.hasFieldText)(b),ce=(0,_jsxRuntime.jsx)(_FieldBase.FieldBase,{size:p,disabled:m,error:le,filled:!0,focused:D,onPress:q,pressFeedback:!1,leading:renderStepper("dec",K,Y||m,E.decrease,re,"−"),trailing:renderStepper("inc",Q,Z||m,E.increase,ae,"+"),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:U.inputRow,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:C,value:w,onChangeText:ee,onFocus:ie,onBlur:te,editable:!m,keyboardType:c?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ne,accessibilityValue:{now:Number.isFinite(V)?V:0},accessibilityState:{disabled:m},"aria-disabled":m,accessibilityActions:[{name:"increment",label:E.increase},{name:"decrement",label:E.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[U.input,{fontSize:B.text,color:A.color,...A.weightStyle},j],...F}),f?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",style:[U.unit,{fontSize:B.text,color:A.placeholderColor},g],children:f}):null]})}),ue=(0,_FieldBase.hasFieldText)(o)?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:p,help:d,style:R,children:o}):null,oe=(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:p,error:le,text:le?b:_});return"horizontal"===x?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[U.horizontalContainer,T,I],testID:v,accessibilityState:{disabled:m},"aria-disabled":m,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:U.horizontalLabelWrap,children:ue}),(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[ce,oe]})]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[T,I],testID:v,accessibilityState:{disabled:m},"aria-disabled":m,children:[ue,ce,oe]})});NumberInput.displayName="NumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});var _default=exports.default=NumberInput;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.NumberInput=exports.DEFAULT_NUMBER_INPUT_LABELS=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_index4=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var i,r,a=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((i=a&&Object.getOwnPropertyDescriptor(e,r))&&(i.get||i.set)?a(s,r,i):s[r]=e[r]);return s}const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"],DEFAULT_NUMBER_INPUT_LABELS=exports.DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"}),DEFAULT_LONG_PRESS_DELAY=500,DEFAULT_LONG_PRESS_INTERVAL=80,roundToPrecision=(e,t)=>{if(!Number.isFinite(e))return 0;if(t<=0)return Math.round(e);const i=10**t;return Math.round(e*i)/i},clamp=(e,t,i)=>e<t?t:e>i?i:e,formatValue=(e,t,i)=>Number.isFinite(e)?t&&i>0?e.toFixed(i):String(Math.trunc(e)):"",sanitizeTyped=(e,t)=>{if(!e)return"";let i=e.replace(/[^0-9.-]/g,"");if(i=i.replace(/(?!^)-/g,""),t){const e=i.indexOf(".");-1!==e&&(i=i.slice(0,e+1)+i.slice(e+1).replace(/\./g,""))}else i=i.replace(/\./g,"");return i},NumberInput=exports.NumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:a,min:s=Number.NEGATIVE_INFINITY,max:n=Number.POSITIVE_INFINITY,step:l=1,allowDecimal:c=!1,precision:u=0,label:o,help:d,helperText:_,error:b,disabled:m=!1,size:p="md",variant:x="inline",unit:f,haptic:N,labels:h,accessibilityLabel:y,style:I,containerStyle:T,inputStyle:j,buttonStyle:S,unitStyle:g,labelStyle:R,textInputProps:v,testID:F}=e;(0,_assertValidValue.assertValidValue)("NumberInput","size",e.size,NUMBER_INPUT_SIZES),(0,_assertValidValue.assertValidValue)("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const E=(0,_react.useMemo)(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...h}),[h]),[V,L]=(0,_index.useControllableState)({value:i,defaultValue:r??e.min??0,onChange:a}),P=(0,_index2.useTheme)(),B=(0,_index2.resolveFieldSize)(P,p),A=(0,_FieldBase.resolveFieldTextStyle)(P,{disabled:m}),U=(0,_react.useMemo)(()=>buildStyles(P),[P]),C=(0,_react.useRef)(null),[w,z]=(0,_react.useState)(formatValue(V,c,u)),[M,D]=(0,_react.useState)(!1),[k,O]=(0,_react.useState)(!1),q=(0,_react.useCallback)(()=>{m||C.current?.focus()},[m]),W=(0,_react.useRef)(null),H=(0,_react.useRef)(null),G=(0,_react.useCallback)(()=>{null!==W.current&&(clearTimeout(W.current),W.current=null),null!==H.current&&(clearInterval(H.current),H.current=null)},[]);(0,_react.useEffect)(()=>G,[G]),(0,_react.useEffect)(()=>{M||z(formatValue(V,c,u))},[V,c,u,M]);const Y=V<=s,$=V>=n,Z=!m,J=(0,_react.useCallback)(e=>{const t=roundToPrecision(e,c?u:0),i=clamp(t,s,n);i!==V&&L(i)},[c,n,s,L,u,V]),K=(0,_react.useCallback)(()=>{if(!Z||Y)return;const e=(0,_index3.resolveHaptic)(N,"selection");e&&(0,_index3.triggerHaptic)(e),J(V-l)},[Y,Z,N,J,l,V]),Q=(0,_react.useCallback)(()=>{if(!Z||$)return;const e=(0,_index3.resolveHaptic)(N,"selection");e&&(0,_index3.triggerHaptic)(e),J(V+l)},[$,Z,N,J,l,V]);_react.default.useImperativeHandle(t,()=>({focus:()=>C.current?.focus(),blur:()=>C.current?.blur(),clear:()=>{z(""),Number.isFinite(s)&&s>0?L(s):L(0<s?s:Math.min(n,0))}}),[n,s,L]);const X=(0,_react.useCallback)(e=>{Z&&(G(),W.current=setTimeout(()=>{H.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[G,K,Q,Z]),ee=(0,_react.useCallback)(e=>{const t=sanitizeTyped(e,c);z(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=s&&i<=n&&i!==V&&L(roundToPrecision(i,c?u:0))},[c,n,s,L,u,V]),te=(0,_react.useCallback)(()=>{D(!1),O(!1);const e=Number(w);if(""===w||!Number.isFinite(e))return void z(formatValue(V,c,u));const t=roundToPrecision(e,c?u:0),i=clamp(t,s,n);i!==V&&L(i),z(formatValue(i,c,u))},[c,w,n,s,L,u,V]),ie=(0,_react.useCallback)(()=>{D(!0),O(!0)},[]),re=Y||m?P.colors["text-disabled"]:P.colors["text-body"],ae=$||m?P.colors["text-disabled"]:P.colors["text-body"],se=B.icon+8,renderStepper=(e,t,i,r,a,s)=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:G,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:se,height:se,alignItems:"center",justifyContent:"center",borderRadius:P.radius.pill,..._corners.smoothCorners},e&&!i?{backgroundColor:P.colors["surface-pressed"]}:null,S],testID:`${F??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:(0,_jsxRuntime.jsx)(_index4.Text,{variant:"body",weight:"semibold",style:{fontSize:B.icon,color:a,fontWeight:P.weight.semibold,lineHeight:B.icon+2},children:s})}),ne=y??(0,_FieldBase.fieldTextAsString)(o)??E.input,le=!0===b||(0,_FieldBase.hasFieldText)(b),ce=(0,_jsxRuntime.jsx)(_FieldBase.FieldBase,{testID:F?`${F}-field`:void 0,size:p,disabled:m,error:le,filled:!0,focused:k,onPress:q,pressFeedback:!1,leading:renderStepper("dec",K,Y||m,E.decrease,re,"−"),trailing:renderStepper("inc",Q,$||m,E.increase,ae,"+"),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:U.inputRow,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:C,value:w,onChangeText:ee,onFocus:ie,onBlur:te,editable:!m,keyboardType:c?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ne,accessibilityValue:{now:Number.isFinite(V)?V:0},accessibilityState:{disabled:m},"aria-disabled":m,accessibilityActions:[{name:"increment",label:E.increase},{name:"decrement",label:E.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[U.input,{fontSize:B.text,color:A.color,...A.weightStyle},j],...v}),f?(0,_jsxRuntime.jsx)(_index4.Text,{variant:"bodySmall",style:[U.unit,{fontSize:B.text,color:A.placeholderColor},g],children:f}):null]})}),ue=(0,_FieldBase.hasFieldText)(o)?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:p,help:d,style:R,children:o}):null,oe=(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:p,error:le,text:le?b:_});return"horizontal"===x?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[U.horizontalContainer,T,I],testID:F,accessibilityState:{disabled:m},"aria-disabled":m,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:U.horizontalLabelWrap,children:ue}),(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[ce,oe]})]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[T,I],testID:F,accessibilityState:{disabled:m},"aria-disabled":m,children:[ue,ce,oe]})});NumberInput.displayName="NumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({inputRow:{flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},input:{flex:1,textAlign:"center",padding:e.space.none,margin:e.space.none,includeFontPadding:!1},unit:{marginLeft:e.space.xs},label:{marginBottom:e.space.xs},helper:{marginTop:e.space.xs},horizontalContainer:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},horizontalLabelWrap:{flexShrink:1,paddingRight:e.space.md}});var _default=exports.default=NumberInput;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_OPTION_SHEET_LABELS=void 0,exports.OptionSheet=OptionSheet,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index2=require("../Modal/index.js"),_index3=require("../Text/index.js"),_optionAccessors=require("./optionAccessors.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,DEFAULT_OPTION_SHEET_LABELS=exports.DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`}),hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:r,sections:s,renderSectionHeader:o,renderOption:a,alphabetIndex:n=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:m,getOptionAction:x,value:_,onChange:g,multi:b=!1,searchable:y=!1,searchSelectionColor:j,accessibilityLabel:f,optionStyle:S,selectedOptionStyle:R,optionTextStyle:v,selectedOptionTextStyle:T,testID:w}=e,C=c??_optionAccessors.selectOptionLabel,N=d??_optionAccessors.selectOptionValue,L=u??_optionAccessors.selectOptionDescription,I=p??_optionAccessors.selectOptionDisabled,O=h??_optionAccessors.selectOptionIcon,k=x??_optionAccessors.selectOptionAction,D=(0,_index.useTheme)(),H=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),A=(0,_react.useMemo)(()=>buildStyles(D),[D]),[V,P]=(0,_react.useState)(""),E=_reactNative.Dimensions.get("window").height,M=Math.round(.7*E),B=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,{handleGesture:z,opacity:F}=(0,_useDragToDismiss.useDragToDismiss)({drag:B,travel:M,onDismiss:t}),q=(0,_reactNativeGestureHandler.useNativeGesture)(),W=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),G=Math.max(0,Math.round(W)),U=Math.max(H.top,_reactNative.StatusBar.currentHeight??0)+D.space.sm,$=G>0,K=$?Math.max(0,Math.min(M,E-G-U)):M,J=(0,_react.useMemo)(()=>{const e=y?V.trim().toLowerCase():"",matches=t=>0===e.length||C(t).toLowerCase().includes(e)||(L(t)??"").toLowerCase().includes(e);if(!s)return r.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return s.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[y,V,r,s,C,L]),Y=(0,_react.useCallback)(()=>{t()},[t]),Z=(0,_react.useRef)(null),Q=(0,_react.useMemo)(()=>{const e=new Map;if(!n)return e;let t=0;if(s)for(const[e,i]of J.entries())"header"===i.kind&&(t=e+1);for(const[i,r]of J.entries()){if(i<t||"option"!==r.kind)continue;const s=C(r.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(s)?s:"#";e.has(o)||e.set(o,i)}return e},[n,J,s,C]),X=n&&Q.size>0&&0===V.trim().length,ee=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Q.has("#")?["#"]:[]],[Q]),te=(0,_react.useCallback)(e=>{const t=Q.get(e);void 0!==t&&Z.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Q]),ie=(0,_react.useRef)(null),re=(0,_react.useCallback)(()=>{null!==ie.current&&(clearTimeout(ie.current),ie.current=null)},[]),se=(0,_react.useCallback)(e=>{Z.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),re(),ie.current=setTimeout(()=>{ie.current=null,Z.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[re]);(0,_react.useEffect)(()=>re,[re]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:A.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:w,accessibilityViewIsModal:!0,accessibilityLabel:f??i??l.fallbackName,style:[A.sheet,{maxHeight:K,marginBottom:G,paddingBottom:$?D.space.lg:H.bottom+D.space.lg,backgroundColor:D.colors.surface,borderTopLeftRadius:D.radius.xl,borderTopRightRadius:D.radius.xl,..._corners.smoothCorners,opacity:F,transform:[{translateY:B}],...D.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:z,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.sheetHandle,{backgroundColor:D.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",style:[A.sheetTitle,{paddingHorizontal:D.space.lg,marginBottom:D.space.sm}],children:i}):null]})}),y?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.searchWrap,{marginHorizontal:D.space.lg,marginBottom:D.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[A.searchBox,{backgroundColor:D.colors["bg-subtle"],borderColor:D.colors.border,borderRadius:D.radius.md,..._corners.smoothCorners,paddingHorizontal:D.space.md,gap:D.space.sm}],children:[(D.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:D.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:V,onChangeText:P,placeholder:l.searchPlaceholder,placeholderTextColor:D.colors["text-subtle"],selectionColor:j??D.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[A.searchInput,{color:D.colors["text-body"],fontSize:D.text.base.size,paddingVertical:D.space.sm}]}),V.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>P(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(D.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:D.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[A.listWrap,X?A.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:q,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:Z,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(N(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[A.sectionHeader,{paddingHorizontal:D.space.lg,paddingTop:D.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:A.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,r=C(i),s=N(i),n=L(i),l=O(i),c=(d=s,Array.isArray(_)?_.some(e=>String(e)===String(d)):null!=_&&String(_)===String(d));var d;const u=I(i),p=m?.(i)??!1,h=k(i);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{if(h)return h(),void Y();g(s,i)},disabled:u,android_ripple:{color:D.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:r,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[A.optionRow,{backgroundColor:c?D.colors["surface-selected"]:e?D.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:D.space.lg,paddingVertical:D.space.md},S,c?R:null],children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.optionTextWrap,children:a({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:A.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[A.optionLabel,v,c?T:null],children:r}),n?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:A.optionDescription,children:n}):null]})]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.checkbox,{borderColor:c?D.colors.primary:D.colors.border,backgroundColor:c?D.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.checkboxTick}):null}):c?"icon"===D.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.singleSelectedIcon,children:(D.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:D.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.singleSelectedDot,{backgroundColor:D.colors.primary}]}):null]})},onScrollToIndexFailed:se,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!X,style:X?A.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:D.space.xl},children:l.empty})})}),X?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.rail,{paddingRight:D.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=Q.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:l.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:A.railLetter,children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[A.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.sheetFooter,{borderTopColor:D.colors["border-subtle"],paddingHorizontal:D.space.lg,paddingVertical:D.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Y,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[A.doneButton,{backgroundColor:e?D.colors["primary-pressed"]:D.colors.primary,borderRadius:D.radius.md,..._corners.smoothCorners,paddingVertical:D.space.sm,paddingHorizontal:D.space.lg}],children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:"semibold",style:{color:D.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:r,labels:s,onClose:o,haptic:a,...n}=e,l=(0,_react.useMemo)(()=>({...DEFAULT_OPTION_SHEET_LABELS,...s}),[s]),c=(0,_react.useRef)(i);c.current=i;const d=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index2.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:r,haptic:a,contentStyle:hostStyle,labels:{close:l.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??l.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...n,onClose:o,labels:l})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_OPTION_SHEET_LABELS=void 0,exports.OptionSheet=OptionSheet,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_index=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index2=require("../Modal/index.js"),_index3=require("../Text/index.js"),_optionAccessors=require("./optionAccessors.js"),_jsxRuntime=require("react/jsx-runtime");const SEARCH_ICON_SIZE=18,DEFAULT_OPTION_SHEET_LABELS=exports.DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`}),hostStyle=_reactNative.StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:i,options:s,sections:r,renderSectionHeader:o,renderOption:a,alphabetIndex:n=!1,labels:l,getOptionLabel:c,getOptionValue:d,getOptionDescription:u,isOptionDisabled:p,getOptionIcon:h,destructiveOf:m,getOptionAction:x,value:_,onChange:g,multi:b=!1,searchable:y=!1,searchSelectionColor:j,accessibilityLabel:f,optionStyle:S,selectedOptionStyle:R,optionTextStyle:v,selectedOptionTextStyle:T,testID:w}=e,C=c??_optionAccessors.selectOptionLabel,N=d??_optionAccessors.selectOptionValue,L=u??_optionAccessors.selectOptionDescription,I=p??_optionAccessors.selectOptionDisabled,O=h??_optionAccessors.selectOptionIcon,k=x??_optionAccessors.selectOptionAction,D=(0,_index.useTheme)(),H=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),A=(0,_react.useMemo)(()=>buildStyles(D),[D]),[V,P]=(0,_react.useState)(""),E=_reactNative.Dimensions.get("window").height,M=Math.round(.7*E),B=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,{handleGesture:z,opacity:F}=(0,_useDragToDismiss.useDragToDismiss)({drag:B,travel:M,onDismiss:t,testID:w}),q=(0,_reactNativeGestureHandler.useNativeGesture)(),W=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),G=Math.max(0,Math.round(W)),U=Math.max(H.top,_reactNative.StatusBar.currentHeight??0)+D.space.sm,$=G>0,K=$?Math.max(0,Math.min(M,E-G-U)):M,J=(0,_react.useMemo)(()=>{const e=y?V.trim().toLowerCase():"",matches=t=>0===e.length||C(t).toLowerCase().includes(e)||(L(t)??"").toLowerCase().includes(e);if(!r)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return r.forEach((e,i)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:i})}}),t},[y,V,s,r,C,L]),Y=(0,_react.useCallback)(()=>{t()},[t]),Z=(0,_react.useRef)(null),Q=(0,_react.useMemo)(()=>{const e=new Map;if(!n)return e;let t=0;if(r)for(const[e,i]of J.entries())"header"===i.kind&&(t=e+1);for(const[i,s]of J.entries()){if(i<t||"option"!==s.kind)continue;const r=C(s.option).trim().charAt(0).toUpperCase(),o=/^[A-Z]$/.test(r)?r:"#";e.has(o)||e.set(o,i)}return e},[n,J,r,C]),X=n&&Q.size>0&&0===V.trim().length,ee=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Q.has("#")?["#"]:[]],[Q]),te=(0,_react.useCallback)(e=>{const t=Q.get(e);void 0!==t&&Z.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Q]),ie=(0,_react.useRef)(null),se=(0,_react.useCallback)(()=>{null!==ie.current&&(clearTimeout(ie.current),ie.current=null)},[]),re=(0,_react.useCallback)(e=>{Z.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),ie.current=setTimeout(()=>{ie.current=null,Z.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);(0,_react.useEffect)(()=>se,[se]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{style:A.gestureRoot,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:w,accessibilityViewIsModal:!0,accessibilityLabel:f??i??l.fallbackName,style:[A.sheet,{maxHeight:K,marginBottom:G,paddingBottom:$?D.space.lg:H.bottom+D.space.lg,backgroundColor:D.colors.surface,borderTopLeftRadius:D.radius.xl,borderTopRightRadius:D.radius.xl,..._corners.smoothCorners,opacity:F,transform:[{translateY:B}],...D.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:z,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.sheetHandle,{backgroundColor:D.colors.border}]})}),i?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"title",style:[A.sheetTitle,{paddingHorizontal:D.space.lg,marginBottom:D.space.sm}],children:i}):null]})}),y?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.searchWrap,{marginHorizontal:D.space.lg,marginBottom:D.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[A.searchBox,{backgroundColor:D.colors["bg-subtle"],borderColor:D.colors.border,borderRadius:D.radius.md,..._corners.smoothCorners,paddingHorizontal:D.space.md,gap:D.space.sm}],children:[(D.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:D.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:V,onChangeText:P,placeholder:l.searchPlaceholder,placeholderTextColor:D.colors["text-subtle"],selectionColor:j??D.colors["focus-ring"],accessibilityLabel:l.searchOptions,style:[A.searchInput,{color:D.colors["text-body"],fontSize:D.text.base.size,paddingVertical:D.space.sm}]}),V.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>P(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:l.clearSearch,children:(D.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:D.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[A.listWrap,X?A.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:q,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:Z,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(N(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[A.sectionHeader,{paddingHorizontal:D.space.lg,paddingTop:D.space.md}],children:o?o(e.title):(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:"tertiary",style:A.sectionTitle,children:e.title.toUpperCase()})});const i=e.option,s=C(i),r=N(i),n=L(i),l=O(i),c=(d=r,Array.isArray(_)?_.some(e=>String(e)===String(d)):null!=_&&String(_)===String(d));var d;const u=I(i),p=m?.(i)??!1,h=k(i);return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{if(h)return h(),void Y();g(r,i)},disabled:u,android_ripple:{color:D.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:u},"aria-selected":c,"aria-disabled":u,style:({pressed:e})=>[A.optionRow,{backgroundColor:c?D.colors["surface-selected"]:e?D.colors["surface-pressed"]:"transparent",opacity:u?.5:1,paddingHorizontal:D.space.lg,paddingVertical:D.space.md},S,c?R:null],children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.optionTextWrap,children:a({option:i,selected:c,disabled:u,index:t})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[l?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.optionIcon,children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:A.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:c?"semibold":"medium",color:p?"danger":c?"brand":void 0,style:[A.optionLabel,v,c?T:null],children:s}),n?(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:A.optionDescription,children:n}):null]})]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.checkbox,{borderColor:c?D.colors.primary:D.colors.border,backgroundColor:c?D.colors.primary:"transparent"}],children:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.checkboxTick}):null}):c?"icon"===D.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:A.singleSelectedIcon,children:(D.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:D.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.singleSelectedDot,{backgroundColor:D.colors.primary}]}):null]})},onScrollToIndexFailed:re,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!X,style:X?A.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:D.space.xl},children:l.empty})})}),X?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.rail,{paddingRight:D.space.xs}],accessibilityRole:"list",accessibilityLabel:l.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=Q.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:l.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:A.railLetter,children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[A.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),b?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[A.sheetFooter,{borderTopColor:D.colors["border-subtle"],paddingHorizontal:D.space.lg,paddingVertical:D.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Y,accessibilityRole:"button",accessibilityLabel:l.done,style:({pressed:e})=>[A.doneButton,{backgroundColor:e?D.colors["primary-pressed"]:D.colors.primary,borderRadius:D.radius.md,..._corners.smoothCorners,paddingVertical:D.space.sm,paddingHorizontal:D.space.lg}],children:(0,_jsxRuntime.jsx)(_index3.Text,{variant:"body",weight:"semibold",style:{color:D.colors["on-primary"]},children:l.done})})}):null]})})}function OptionSheet(e){const{open:t,onOpenChange:i,onAfterClose:s,labels:r,onClose:o,haptic:a,...n}=e,l=(0,_react.useMemo)(()=>({...DEFAULT_OPTION_SHEET_LABELS,...r}),[r]),c=(0,_react.useRef)(i);c.current=i;const d=(0,_react.useRef)(!1);return(0,_react.useEffect)(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),(0,_jsxRuntime.jsx)(_index2.Modal,{open:t,onClose:o,presentation:"bottom",onDismissed:s,haptic:a,contentStyle:hostStyle,labels:{close:l.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??l.fallbackName,children:(0,_jsxRuntime.jsx)(OptionSheetPanel,{...n,onClose:o,labels:l})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:Math.round(e.text.xs.size*e.leading.heading)},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index4=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`}),DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,a=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;a=o.slice(r.length)}const l=t.filter(e=>e.code===r),s=l.find(e=>e.iso===i)?.iso??l.find(e=>e.iso===n?.country)?.iso??n?.country??l[0]?.iso??"";return{callingCode:r,nationalNumber:a,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:a,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onComplete:c,onValidityChange:d,countries:b=ALL_CALLING_CODES,popularCountries:p,hiddenCountries:_,showFlag:m=!0,renderFlag:h,renderCountry:f,showAlphabetIndex:g,defaultCountry:x,validation:C="any",maxLength:N,formatAsYouType:y=!0,countryLocked:v=!1,label:S,labelMode:E="top",labelStyle:L,placeholder:I,helperText:T,error:j,invalidMessage:P,required:A,disabled:F=!1,size:O="md",variant:V,radius:R,labels:D,haptic:M,accessibilityLabel:U,countryAccessibilityLabel:B,onFocus:q,onBlur:w,style:z,testID:k}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const $=(0,_index2.useTheme)(),G=(0,_react.useMemo)(()=>buildStyles($),[$]),H=(0,_react.useRef)(null),W=(0,_react.useMemo)(()=>D?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...D}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[D]),Y=I??W.placeholder,K=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),Z=(0,_react.useMemo)(()=>_?.length?b.filter(e=>!_.includes(e.iso)):b,[b,_]),J=(0,_react.useMemo)(()=>{if(!p?.length)return;const e=p.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:W.popular,options:e},{title:W.allCountries,options:Z}]:void 0},[p,W.popular,W.allCountries,Z]),Q=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(h)return h(e);if(!m)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.flag,{fontSize:t}],testID:i,children:o}):null},[h,m,G.flag]),X=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(i,N):i},[N,C]),ee=(0,_react.useCallback)((e,t)=>e.slice(0,X(t)),[X]),te=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=b.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:ee(o.nationalNumber,n),iso:r?.iso??n}},[b,ee]);(0,_react.useState)(()=>assertDefaultCountryVisible(x,Z));const ie=(0,_react.useMemo)(()=>{const e=Z.find(e=>e.iso===(x??K))??Z[0]??b[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?te(o,t.iso)??t:o??t},[b,Z,x,K,o,te]),oe=(0,_react.useCallback)(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,re]=(0,_react.useState)(ie.iso),ae=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,b,ne):null;if(e)return{...e,nationalNumber:ee(e.nationalNumber,e.iso)};const t=b.find(e=>e.iso===ne);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:ne}},[r,b,ne,ie.callingCode,ee]),le=(0,_react.useCallback)(e=>{re(e.iso),n?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:b.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:oe(e)})},[n,a,b,oe]),[se,ue]=(0,_index.useControllableState)({value:i??ae,defaultValue:ie,onChange:le}),[ce,de]=(0,_react.useState)(!1),be=(0,_react.useCallback)(()=>{F||H.current?.focus()},[F]),[pe,me]=(0,_react.useState)(!1),[he,fe]=(0,_react.useState)(!1),[ge,xe]=(0,_react.useState)(!1),Ce=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{ge||(Ce.current=!1)},[ge]);const Ne=(0,_index2.resolveFieldSize)($,O),ye=(0,_index4.resolveFieldTextStyle)($,{disabled:F}),ve=V??$.settings.components.field?.defaultVariant??"outline",Se="underline"===ve,Ee=$.space.md,[Le,Ie]=(0,_react.useState)(0),Te=Le+Ee+1+Ee,je=se.nationalNumber.length>0,Pe=A&&!S&&!je&&Y.length>0,Ae=ce||je,Fe=Boolean(S)&&"float"===E&&Le>0,Oe=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Fe,floated:Ae,required:A,variant:ve,sizeTokens:Ne,leadingOffset:Te,paddingLeft:Se?$.space.none:Ne["padding-x"],color:$.colors["field-label"],style:L}),Ve=(0,_react.useMemo)(()=>b.find(e=>e.iso===se.iso),[b,se.iso]),Re=planOf(se.iso),De=y&&Re?(0,_mobileCore.formatPhoneAsTyped)(se.nationalNumber,Re):se.nationalNumber,Me=X(se.iso),Ue=0===se.nationalNumber.length||pe||!Number.isFinite(Me)?void 0:De.length+Math.max(0,Me-se.nationalNumber.length),Be=oe(se);(0,_react.useEffect)(()=>{je||fe(!1)},[je]);const qe=Re?(0,_mobileCore.maxNationalNumberLength)(Re,!1===C?"any":C):Number.POSITIVE_INFINITY,we=se.nationalNumber.length>=qe,ze=!1!==C&&!1!==P&&je&&!Be&&(he||we),ke="mobile"===C?W.invalidMobile:W.invalid,$e=(0,_index4.hasFieldText)(j)?j:ze?P||ke:void 0,Ge=!0===j||(0,_index4.hasFieldText)($e),He=(0,_react.useRef)(Be),We=(0,_react.useRef)(se);We.current=se,(0,_react.useEffect)(()=>{He.current!==Be&&(He.current=Be,d?.(Be),Be&&c?.(formatE164(We.current)))},[Be,c,d]);const Ye=(0,_react.useCallback)(e=>{if(e.includes("+")){const t=te(e,se.iso);if(t&&!v&&Z.some(e=>e.iso===t.iso))return void ue(t);if(t&&t.iso===se.iso)return void ue(t)}ue({...se,nationalNumber:ee(digitsOnly(e),se.iso)})},[Z,v,se,te,ee,ue]),Ke=(0,_react.useCallback)(e=>{ue({callingCode:e.code,iso:e.iso,nationalNumber:ee(se.nationalNumber,e.iso)}),xe(!1);const t=(0,_index3.resolveHaptic)(M,"selection");t&&(0,_index3.triggerHaptic)(t)},[se,M,ee,ue]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>H.current?.focus(),blur:()=>H.current?.blur(),clear:()=>ue({...We.current,nationalNumber:""}),isFocused:()=>H.current?.isFocused()??!1,getValue:()=>We.current,getE164:()=>formatE164(We.current),getFormatted:()=>{const e=We.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>oe(We.current),getCountry:()=>b.find(e=>e.iso===We.current.iso)}),[b,oe,ue]);const Ze=F||v,Je=(0,_jsxRuntime.jsx)(_index4.FieldBase,{size:O,variant:ve,radius:R,topNotch:Oe.topNotch,focused:ce,disabled:F,error:Ge,filled:je,onPress:be,pressFeedback:!1,leadingDivider:!0,paddingLeft:Se?$.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Ze||(Ce.current=!0,xe(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:B??W.countryButton(se.callingCode),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ie(e=>e===t?e:t)},style:G.codeTrigger,testID:k?`${k}-code`:void 0,children:[Q(Ve,Ne.text,k?`${k}-flag`:void 0),(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.codeText,{color:ye.color,fontSize:Ne.text}],children:`+${se.callingCode}`}),v?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:F?$.colors["field-icon-disabled"]:$.colors["field-icon"],size:Ne.icon,open:ge})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:H,value:De,maxLength:Ue,onChangeText:Ye,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;me(t!==i)},onFocus:()=>{de(!0),q?.()},onBlur:()=>{de(!1),je&&!Ce.current&&fe(!0),w?.()},editable:!F,placeholder:Fe&&!Ae||Pe?void 0:Y,placeholderTextColor:ye.placeholderColor,accessibilityLabel:U??S??Y,selectionColor:$.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[G.input,{color:ye.color,fontSize:Ne.text,...ye.weightStyle,paddingLeft:Se?$.space.none:void 0}],testID:k?`${k}-input`:void 0}),Pe?(0,_jsxRuntime.jsx)(_index4.RequiredPlaceholder,{text:Y,color:ye.placeholderColor,fontSize:Ne.text,weightStyle:ye.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:z,testID:k,children:[S&&"top"===E?(0,_jsxRuntime.jsx)(_index4.FieldLabel,{size:O,required:A,children:S}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrapper,children:[Je,Oe.node]}),(0,_jsxRuntime.jsx)(_index4.FieldMessage,{size:O,error:Ge,text:Ge?$e:T}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:ge,haptic:M,onClose:()=>xe(!1),title:W.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,$.text.lg.size),renderOption:f?({option:e,selected:t})=>f(e,{selected:t}):void 0,value:Ve?.iso,onChange:(e,t)=>Ke(t),searchable:Z.length>8,labels:{searchPlaceholder:W.countrySearchPlaceholder},alphabetIndex:g??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index2.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseE164=exports.formatE164=exports.default=exports.PhoneNumberInput=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_CALLING_CODES=exports.ALL_CALLING_CODES=void 0;var _mobileCore=require("@webority/mobile-core"),_countries=require("@webority/mobile-core/phone/countries"),_react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hitSlop=require("../../utils/hitSlop.js"),_index4=require("../FieldBase/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PHONE_NUMBER_INPUT_LABELS=exports.DEFAULT_PHONE_NUMBER_INPUT_LABELS=Object.freeze({placeholder:"Phone number",popular:"Popular",allCountries:"All countries",countrySheetTitle:"Country code",countrySearchPlaceholder:"Search…",invalid:"Enter a valid number",invalidMobile:"Enter a valid mobile number",countryButton:e=>`Country code, currently +${e}`}),DEFAULT_CALLING_CODES=exports.DEFAULT_CALLING_CODES=[{iso:"AU",code:"61",label:"Australia"},{iso:"CA",code:"1",label:"Canada"},{iso:"IN",code:"91",label:"India"},{iso:"SA",code:"966",label:"Saudi Arabia"},{iso:"SG",code:"65",label:"Singapore"},{iso:"AE",code:"971",label:"United Arab Emirates"},{iso:"GB",code:"44",label:"United Kingdom"},{iso:"US",code:"1",label:"United States"}],ALL_CALLING_CODES=exports.ALL_CALLING_CODES=(0,_mobileCore.getPhoneCountries)().map(e=>({iso:e.iso,code:e.callingCode,label:_countries.PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label)),digitsOnly=e=>e.replace(/[^0-9]/g,""),formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;exports.formatE164=formatE164;const parseE164=(e,t,i)=>{const o=e.replace(/[^0-9]/g,"");if(!o)return null;const n=(0,_mobileCore.splitPhoneNumber)(`+${o}`);let r=n?.callingCode,a=n?.nationalNumber??"";if(!r){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(r=e.find(e=>o.startsWith(e)),!r)return null;a=o.slice(r.length)}const l=t.filter(e=>e.code===r),s=l.find(e=>e.iso===i)?.iso??l.find(e=>e.iso===n?.country)?.iso??n?.country??l[0]?.iso??"";return{callingCode:r,nationalNumber:a,iso:s}};exports.parseE164=parseE164;const planOf=e=>(0,_mobileCore.isSupportedCountry)(e)?e:null,assertDefaultCountryVisible=(e,t)=>{if(void 0!==e&&!t.some(t=>t.iso===e))throw new RangeError(`PhoneNumberInput: defaultCountry "${e}" is not among the visible countries. Add it to countries, or remove it from hiddenCountries.`)},PhoneNumberInput=exports.PhoneNumberInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:o,onChange:n,e164:r,onChangeE164:a,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onComplete:c,onValidityChange:d,countries:b=ALL_CALLING_CODES,popularCountries:p,hiddenCountries:_,showFlag:m=!0,renderFlag:h,renderCountry:f,showAlphabetIndex:g,defaultCountry:x,validation:C="any",maxLength:N,formatAsYouType:y=!0,countryLocked:v=!1,label:S,labelMode:E="top",labelStyle:L,placeholder:I,helperText:T,error:j,invalidMessage:P,required:A,disabled:F=!1,size:O="md",variant:V,radius:R,labels:D,haptic:M,accessibilityLabel:U,countryAccessibilityLabel:B,onFocus:q,onBlur:w,style:z,testID:k}=e;(0,_assertValidValue.assertValidValue)("PhoneNumberInput","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),(0,_assertValidValue.assertValidValue)("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const $=(0,_index2.useTheme)(),G=(0,_react.useMemo)(()=>buildStyles($),[$]),H=(0,_react.useRef)(null),W=(0,_react.useMemo)(()=>D?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...D}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[D]),Y=I??W.placeholder,K=(0,_react.useMemo)(()=>/-([A-Za-z]{2})(?:-|$)/.exec((0,_mobileCore.getFormatterConfig)().locale)?.[1]?.toUpperCase(),[]),Z=(0,_react.useMemo)(()=>_?.length?b.filter(e=>!_.includes(e.iso)):b,[b,_]),J=(0,_react.useMemo)(()=>{if(!p?.length)return;const e=p.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:W.popular,options:e},{title:W.allCountries,options:Z}]:void 0},[p,W.popular,W.allCountries,Z]),Q=(0,_react.useCallback)((e,t,i)=>{if(!e)return null;if(h)return h(e);if(!m)return null;const o=(0,_mobileCore.countryFlagEmoji)(e.iso);return o?(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.flag,{fontSize:t}],testID:i,children:o}):null},[h,m,G.flag]),X=(0,_react.useCallback)(e=>{const t=planOf(e),i=t?(0,_mobileCore.maxNationalNumberLength)(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return N?Math.min(i,N):i},[N,C]),ee=(0,_react.useCallback)((e,t)=>e.slice(0,X(t)),[X]),te=(0,_react.useCallback)((e,t)=>{const i=planOf(t)??void 0,o=(0,_mobileCore.splitPhoneNumber)(e,i);if(!o)return null;const n=o.country??t,r=b.find(e=>e.iso===n);return{callingCode:r?.code??o.callingCode,nationalNumber:ee(o.nationalNumber,n),iso:r?.iso??n}},[b,ee]);(0,_react.useState)(()=>assertDefaultCountryVisible(x,Z));const ie=(0,_react.useMemo)(()=>{const e=Z.find(e=>e.iso===(x??K))??Z[0]??b[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof o?te(o,t.iso)??t:o??t},[b,Z,x,K,o,te]),oe=(0,_react.useCallback)(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?(0,_mobileCore.isValidNationalNumber)(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,re]=(0,_react.useState)(ie.iso),ae=(0,_react.useMemo)(()=>{if(void 0===r)return;const e=r?parseE164(r,b,ne):null;if(e)return{...e,nationalNumber:ee(e.nationalNumber,e.iso)};const t=b.find(e=>e.iso===ne);return{callingCode:t?.code??ie.callingCode,nationalNumber:"",iso:ne}},[r,b,ne,ie.callingCode,ee]),le=(0,_react.useCallback)(e=>{re(e.iso),n?.(e),a?.(e.nationalNumber?formatE164(e):"",{country:b.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:oe(e)})},[n,a,b,oe]),[se,ue]=(0,_index.useControllableState)({value:i??ae,defaultValue:ie,onChange:le}),[ce,de]=(0,_react.useState)(!1),be=(0,_react.useCallback)(()=>{F||H.current?.focus()},[F]),[pe,me]=(0,_react.useState)(!1),[he,fe]=(0,_react.useState)(!1),[ge,xe]=(0,_react.useState)(!1),Ce=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{ge||(Ce.current=!1)},[ge]);const Ne=(0,_index2.resolveFieldSize)($,O),ye=(0,_index4.resolveFieldTextStyle)($,{disabled:F}),ve=V??$.settings.components.field?.defaultVariant??"outline",Se="underline"===ve,Ee=$.space.md,[Le,Ie]=(0,_react.useState)(0),Te=Le+Ee+1+Ee,je=se.nationalNumber.length>0,Pe=A&&!S&&!je&&Y.length>0,Ae=ce||je,Fe=Boolean(S)&&"float"===E&&Le>0,Oe=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Fe,floated:Ae,required:A,variant:ve,sizeTokens:Ne,leadingOffset:Te,paddingLeft:Se?$.space.none:Ne["padding-x"],color:$.colors["field-label"],style:L}),Ve=(0,_react.useMemo)(()=>b.find(e=>e.iso===se.iso),[b,se.iso]),Re=planOf(se.iso),De=y&&Re?(0,_mobileCore.formatPhoneAsTyped)(se.nationalNumber,Re):se.nationalNumber,Me=X(se.iso),Ue=0===se.nationalNumber.length||pe||!Number.isFinite(Me)?void 0:De.length+Math.max(0,Me-se.nationalNumber.length),Be=oe(se);(0,_react.useEffect)(()=>{je||fe(!1)},[je]);const qe=Re?(0,_mobileCore.maxNationalNumberLength)(Re,!1===C?"any":C):Number.POSITIVE_INFINITY,we=se.nationalNumber.length>=qe,ze=!1!==C&&!1!==P&&je&&!Be&&(he||we),ke="mobile"===C?W.invalidMobile:W.invalid,$e=(0,_index4.hasFieldText)(j)?j:ze?P||ke:void 0,Ge=!0===j||(0,_index4.hasFieldText)($e),He=(0,_react.useRef)(Be),We=(0,_react.useRef)(se);We.current=se,(0,_react.useEffect)(()=>{He.current!==Be&&(He.current=Be,d?.(Be),Be&&c?.(formatE164(We.current)))},[Be,c,d]);const Ye=(0,_react.useCallback)(e=>{if(e.includes("+")){const t=te(e,se.iso);if(t&&!v&&Z.some(e=>e.iso===t.iso))return void ue(t);if(t&&t.iso===se.iso)return void ue(t)}ue({...se,nationalNumber:ee(digitsOnly(e),se.iso)})},[Z,v,se,te,ee,ue]),Ke=(0,_react.useCallback)(e=>{ue({callingCode:e.code,iso:e.iso,nationalNumber:ee(se.nationalNumber,e.iso)}),xe(!1);const t=(0,_index3.resolveHaptic)(M,"selection");t&&(0,_index3.triggerHaptic)(t)},[se,M,ee,ue]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>H.current?.focus(),blur:()=>H.current?.blur(),clear:()=>ue({...We.current,nationalNumber:""}),isFocused:()=>H.current?.isFocused()??!1,getValue:()=>We.current,getE164:()=>formatE164(We.current),getFormatted:()=>{const e=We.current,t=planOf(e.iso);return t?(0,_mobileCore.formatPhoneAsTyped)(e.nationalNumber,t):e.nationalNumber},isValid:()=>oe(We.current),getCountry:()=>b.find(e=>e.iso===We.current.iso)}),[b,oe,ue]);const Ze=F||v,Je=(0,_jsxRuntime.jsx)(_index4.FieldBase,{testID:k?`${k}-field`:void 0,size:O,variant:ve,radius:R,topNotch:Oe.topNotch,focused:ce,disabled:F,error:Ge,filled:je,onPress:be,pressFeedback:!1,leadingDivider:!0,paddingLeft:Se?$.space.none:void 0,leading:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>{Ze||(Ce.current=!0,xe(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:B??W.countryButton(se.callingCode),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Ie(e=>e===t?e:t)},style:G.codeTrigger,testID:k?`${k}-code`:void 0,children:[Q(Ve,Ne.text,k?`${k}-flag`:void 0),(0,_jsxRuntime.jsx)(_index5.Text,{variant:"body",style:[G.codeText,{color:ye.color,fontSize:Ne.text}],children:`+${se.callingCode}`}),v?null:(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:F?$.colors["field-icon-disabled"]:$.colors["field-icon"],size:Ne.icon,open:ge})]}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:H,value:De,maxLength:Ue,onChangeText:Ye,returnKeyType:l,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:i}=e.nativeEvent.selection;me(t!==i)},onFocus:()=>{de(!0),q?.()},onBlur:()=>{de(!1),je&&!Ce.current&&fe(!0),w?.()},editable:!F,placeholder:Fe&&!Ae||Pe?void 0:Y,placeholderTextColor:ye.placeholderColor,accessibilityLabel:U??S??Y,selectionColor:$.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[G.input,{color:ye.color,fontSize:Ne.text,...ye.weightStyle,paddingLeft:Se?$.space.none:void 0}],testID:k?`${k}-input`:void 0}),Pe?(0,_jsxRuntime.jsx)(_index4.RequiredPlaceholder,{text:Y,color:ye.placeholderColor,fontSize:Ne.text,weightStyle:ye.weightStyle}):null]})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:z,testID:k,children:[S&&"top"===E?(0,_jsxRuntime.jsx)(_index4.FieldLabel,{size:O,required:A,children:S}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrapper,children:[Je,Oe.node]}),(0,_jsxRuntime.jsx)(_index4.FieldMessage,{size:O,error:Ge,text:Ge?$e:T}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:ge,haptic:M,onClose:()=>xe(!1),title:W.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,$.text.lg.size),renderOption:f?({option:e,selected:t})=>f(e,{selected:t}):void 0,value:Ve?.iso,onChange:(e,t)=>Ke(t),searchable:Z.length>8,labels:{searchPlaceholder:W.countrySearchPlaceholder},alphabetIndex:g??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>_reactNative.StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...(0,_index2.fontFor)(e,"semibold"),fontWeight:"600",includeFontPadding:!1,writingDirection:"ltr"},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1,writingDirection:"ltr"},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"}});var _default=exports.default=PhoneNumberInput;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_PROFILE_PICKER_LABELS=void 0,exports.ProfilePicker=ProfilePicker,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_index3=require("../AppIcon/index.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Avatar/index.js"),_index5=require("../FieldBase/index.js"),_FilePicker=require("../FilePicker/FilePicker.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index6=require("../Spinner/index.js"),_index7=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PROFILE_PICKER_LABELS=exports.DEFAULT_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."}),DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,t)=>Math.min(t,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,t)=>{const i=toneFor(e,r),s=i.base,o=e.colors.bg,n="neutral"===r;let a;switch(t){case"soft":a={fill:n?e.colors["bg-muted"]:(0,_color.blendOf)(s,.14,o,e.colors["bg-subtle"]),ring:o,icon:s};break;case"outline":a={fill:o,ring:n?e.colors.border:s,icon:s};break;default:a={fill:s,ring:o,icon:i.on}}return a},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__";function ProfilePicker(e){const{ref:r,value:t,name:i,sources:s,onPick:o,onRemove:n,loading:a=!1,disabled:l=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:_="circle",badgeIcon:m="camera",tone:x,variant:p,avatarTone:g,avatarBackgroundColor:h,avatarColor:b,label:f,required:y=!1,helperText:v,error:j,layout:k="stacked",title:P,subtitle:C,ImageComponent:E,labels:R,haptic:I,onError:V,accessibilityLabel:S,style:T,testID:F}=e;(0,_assertValidValue.assertValidValue)("ProfilePicker","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","shape",e.shape,["circle","rounded","square"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","variant",e.variant,["solid","soft","outline"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const L=(0,_index.useTheme)(),A=L.settings.components["profile-picker"],w=x??A?.defaultTone??"primary",O=p??A?.defaultVariant??"solid",q=(0,_react.useMemo)(()=>badgeLookFor(L,w,O),[L,w,O]),M=g??A?.defaultAvatarTone,N=(0,_react.useMemo)(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...R}),[R]),[D,B]=(0,_react.useState)(null),[z,H]=(0,_react.useState)(null),[U,K]=(0,_react.useState)(!1),[Z,$]=(0,_react.useState)(t);t!==Z&&($(t),B(null));const W=a||l,G=D??t??null,X=(0,_react.useMemo)(()=>G?{uri:G}:void 0,[G]),Q=j??z??void 0,Y=!W&&(null!==D||Boolean(t)&&Boolean(n)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(_,ee),te=re*(1-Math.SQRT1_2),ie=clamp(Math.round(.28*ee),24,44),se=te-ie/2,oe=Math.max(0,-se),ne=(0,_react.useCallback)(e=>{H(e),V?.(e),!1!==I&&(0,_index2.triggerHaptic)("notificationError")},[V,I]),ae=(0,_react.useCallback)(async e=>{let r;try{r=await e.pick()}catch(e){return void ne(e instanceof Error?e.message:String(e))}const t=r?.[0];if(!t)return;if("number"==typeof d&&"number"==typeof t.size&&t.size>1024*d*1024)return void ne(N.errorTooLarge(d));if(t.type&&!(0,_FilePicker.matchesAccept)(t.type,c))return void ne(N.errorWrongType);H(null),B(t.uri);const i=(0,_index2.resolveHaptic)(I,"selection");i&&(0,_index2.triggerHaptic)(i),o?.(t)},[d,c,N,I,o,ne]),le=(0,_react.useCallback)(()=>{if(W)return;ue.current=null;const[e]=s;void 0===e||1!==s.length||Y?(s.length>0||Y)&&K(!0):ae(e)},[W,s,Y,ae]),ce=(0,_react.useCallback)(()=>{B(null),H(null);const e=(0,_index2.resolveHaptic)(I,"selection");e&&(0,_index2.triggerHaptic)(e),n?.()},[I,n]),de=(0,_react.useMemo)(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=(0,_react.useRef)(null),me=(0,_react.useCallback)(e=>{ue.current||(K(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),xe=(0,_react.useRef)(ae);xe.current=ae;const pe=(0,_react.useCallback)(()=>{const e=ue.current;ue.current=null,e&&xe.current(e)},[]),ge=F??"profile-picker",he=S??(J?N.pick:i),be=(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:ee,height:ee,marginBottom:oe,marginRight:oe},children:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:le,disabled:W||!J,accessibilityRole:J?"button":"image",accessibilityLabel:he,accessibilityHint:(0,_index5.fieldTextAsString)(Q),accessibilityState:J?{disabled:W,busy:a}:{busy:a},"aria-disabled":J?W:void 0,"aria-busy":a,testID:`${ge}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,..._corners.smoothCorners},{opacity:l?.55:e?.85:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index4.Avatar,{dimension:ee,shape:_,name:i||void 0,source:X,ImageComponent:E,tone:M,backgroundColor:h,color:b,placeholderIcon:"user"})}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.fill,styles.overlay,{borderRadius:re,..._corners.smoothCorners,backgroundColor:L.colors.scrim}],testID:`${ge}-loading`,children:(0,_jsxRuntime.jsx)(_index6.Spinner,{size:ee>=100?"md":"sm",color:L.colors["on-primary"]})}):null,!l&&J?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",testID:`${ge}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:ie,height:ie,borderRadius:L.radius.pill,..._corners.smoothCorners,right:se,bottom:se,backgroundColor:q.fill,borderColor:q.ring}],children:(0,_slotIcon.renderSlotIcon)(m,{color:q.icon,size:Math.round(.55*ie),disabled:!1})}):null]})}),fe="stacked"!==k?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.meta,"profile"===k?styles.metaCentred:null],children:[P?(0,_jsxRuntime.jsx)(_index7.Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===k?styles.textCentred:null],children:P}):null,C?(0,_jsxRuntime.jsx)(_index7.Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===k?styles.textCentred:null,{marginTop:L.space.xxs}],children:C}):null,(0,_jsxRuntime.jsx)(_index5.FieldMessage,{text:Q??v,error:(0,_index5.hasFieldText)(Q)})]}):(0,_jsxRuntime.jsx)(_index5.FieldMessage,{text:Q??v,error:(0,_index5.hasFieldText)(Q)});return(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:r,style:T,testID:F,children:[f?(0,_jsxRuntime.jsx)(_index5.FieldLabel,{required:y,children:f}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:"inline"===k?[styles.row,{columnGap:L.space.md}]:["profile"===k?styles.columnCentred:styles.column,{rowGap:L.space.xs}],children:[be,fe]}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:U,haptic:I,onClose:()=>K(!1),onAfterClose:pe,title:N.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?N.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?(0,_jsxRuntime.jsx)(_index3.AppIcon,{name:"trash",size:SHEET_ICON_SIZE,color:L.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})}ProfilePicker.displayName="ProfilePicker";const styles=_reactNative.StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{..._reactNative.StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});var _default=exports.default=ProfilePicker;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_PROFILE_PICKER_LABELS=void 0,exports.ProfilePicker=ProfilePicker,exports.default=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_index3=require("../AppIcon/index.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Avatar/index.js"),_index5=require("../FieldBase/index.js"),_FilePicker=require("../FilePicker/FilePicker.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index6=require("../Spinner/index.js"),_index7=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_PROFILE_PICKER_LABELS=exports.DEFAULT_PROFILE_PICKER_LABELS=Object.freeze({pick:"Change profile photo",remove:"Remove photo",sheetTitle:"Change photo",errorTooLarge:e=>`The photo is larger than ${e} MB.`,errorWrongType:"That file is not a supported image."}),DEFAULT_ACCEPT=["image/*"],SHEET_ICON_SIZE=20,SOFT_FILL_OPACITY=.14,SIZE_PX={sm:72,md:120,lg:160},clamp=(e,r,t)=>Math.min(t,Math.max(r,e)),toneFor=(e,r)=>{switch(r){case"success":return{base:e.colors.success,on:e.colors["on-success"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"]};case"info":return{base:e.colors.info,on:e.colors["on-info"]};case"neutral":return{base:e.colors["text-muted"],on:e.colors["on-neutral-strong"]};default:return{base:e.colors.primary,on:e.colors["on-primary"]}}},badgeLookFor=(e,r,t)=>{const i=toneFor(e,r),s=i.base,o=e.colors.bg,n="neutral"===r;let a;switch(t){case"soft":a={fill:n?e.colors["bg-muted"]:(0,_color.blendOf)(s,.14,o,e.colors["bg-subtle"]),ring:o,icon:s};break;case"outline":a={fill:o,ring:n?e.colors.border:s,icon:s};break;default:a={fill:s,ring:o,icon:i.on}}return a},resolveRadius=(e,r)=>"circle"===e?r/2:"rounded"===e?Math.max(6,Math.round(.22*r)):0,REMOVE_VALUE="__profile-picker-remove__";function ProfilePicker(e){const{ref:r,value:t,name:i,sources:s,onPick:o,onRemove:n,loading:a=!1,disabled:l=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:_="circle",badgeIcon:m="camera",tone:x,variant:p,avatarTone:g,avatarBackgroundColor:h,avatarColor:b,label:f,required:y=!1,helperText:v,error:j,layout:k="stacked",title:P,subtitle:C,ImageComponent:E,labels:I,haptic:R,onError:V,accessibilityLabel:S,style:T,testID:F}=e;(0,_assertValidValue.assertValidValue)("ProfilePicker","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","shape",e.shape,["circle","rounded","square"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","variant",e.variant,["solid","soft","outline"]),(0,_assertValidValue.assertValidValue)("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const L=(0,_index.useTheme)(),A=L.settings.components["profile-picker"],w=x??A?.defaultTone??"primary",O=p??A?.defaultVariant??"solid",q=(0,_react.useMemo)(()=>badgeLookFor(L,w,O),[L,w,O]),M=g??A?.defaultAvatarTone,D=(0,_react.useMemo)(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...I}),[I]),[N,B]=(0,_react.useState)(null),[z,H]=(0,_react.useState)(null),[U,$]=(0,_react.useState)(!1),[K,Z]=(0,_react.useState)(t);t!==K&&(Z(t),B(null));const W=a||l,G=N??t??null,X=(0,_react.useMemo)(()=>G?{uri:G}:void 0,[G]),Q=j??z??void 0,Y=!W&&(null!==N||Boolean(t)&&Boolean(n)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(_,ee),te=re*(1-Math.SQRT1_2),ie=clamp(Math.round(.28*ee),24,44),se=te-ie/2,oe=Math.max(0,-se),ne=(0,_react.useCallback)(e=>{H(e),V?.(e),!1!==R&&(0,_index2.triggerHaptic)("notificationError")},[V,R]),ae=(0,_react.useCallback)(async e=>{let r;try{r=await e.pick()}catch(e){return void ne(e instanceof Error?e.message:String(e))}const t=r?.[0];if(!t)return;if("number"==typeof d&&"number"==typeof t.size&&t.size>1024*d*1024)return void ne(D.errorTooLarge(d));if(t.type&&!(0,_FilePicker.matchesAccept)(t.type,c))return void ne(D.errorWrongType);H(null),B(t.uri);const i=(0,_index2.resolveHaptic)(R,"selection");i&&(0,_index2.triggerHaptic)(i),o?.(t)},[d,c,D,R,o,ne]),le=(0,_react.useCallback)(()=>{if(W)return;ue.current=null;const[e]=s;void 0===e||1!==s.length||Y?(s.length>0||Y)&&$(!0):ae(e)},[W,s,Y,ae]),ce=(0,_react.useCallback)(()=>{B(null),H(null);const e=(0,_index2.resolveHaptic)(R,"selection");e&&(0,_index2.triggerHaptic)(e),n?.()},[R,n]),de=(0,_react.useMemo)(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=(0,_react.useRef)(null),me=(0,_react.useCallback)(e=>{ue.current||($(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),xe=(0,_react.useRef)(ae);xe.current=ae;const pe=(0,_react.useCallback)(()=>{const e=ue.current;ue.current=null,e&&xe.current(e)},[]),ge=F??"profile-picker",he=S??(J?D.pick:i),be=(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:ee,height:ee,marginBottom:oe,marginRight:oe},children:(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:le,disabled:W||!J,accessibilityRole:J?"button":"image",accessibilityLabel:he,accessibilityHint:(0,_index5.fieldTextAsString)(Q),accessibilityState:J?{disabled:W,busy:a}:{busy:a},"aria-disabled":J?W:void 0,"aria-busy":a,testID:`${ge}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,..._corners.smoothCorners},{opacity:l?.55:e?.85:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_index4.Avatar,{testID:F?`${F}-avatar`:void 0,dimension:ee,shape:_,name:i||void 0,source:X,ImageComponent:E,tone:M,backgroundColor:h,color:b,placeholderIcon:"user"})}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[styles.fill,styles.overlay,{borderRadius:re,..._corners.smoothCorners,backgroundColor:L.colors.scrim}],testID:`${ge}-loading`,children:(0,_jsxRuntime.jsx)(_index6.Spinner,{size:ee>=100?"md":"sm",color:L.colors["on-primary"]})}):null,!l&&J?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",testID:`${ge}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:ie,height:ie,borderRadius:L.radius.pill,..._corners.smoothCorners,right:se,bottom:se,backgroundColor:q.fill,borderColor:q.ring}],children:(0,_slotIcon.renderSlotIcon)(m,{color:q.icon,size:Math.round(.55*ie),disabled:!1})}):null]})}),fe="stacked"!==k?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.meta,"profile"===k?styles.metaCentred:null],children:[P?(0,_jsxRuntime.jsx)(_index7.Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===k?styles.textCentred:null],children:P}):null,C?(0,_jsxRuntime.jsx)(_index7.Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===k?styles.textCentred:null,{marginTop:L.space.xxs}],children:C}):null,(0,_jsxRuntime.jsx)(_index5.FieldMessage,{text:Q??v,error:(0,_index5.hasFieldText)(Q)})]}):(0,_jsxRuntime.jsx)(_index5.FieldMessage,{text:Q??v,error:(0,_index5.hasFieldText)(Q)});return(0,_jsxRuntime.jsxs)(_reactNative.View,{ref:r,style:T,testID:F,children:[f?(0,_jsxRuntime.jsx)(_index5.FieldLabel,{required:y,children:f}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:"inline"===k?[styles.row,{columnGap:L.space.md}]:["profile"===k?styles.columnCentred:styles.column,{rowGap:L.space.xs}],children:[be,fe]}),(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:U,haptic:R,onClose:()=>$(!1),onAfterClose:pe,title:D.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?D.remove:e.source.label,getOptionValue:e=>"remove"===e.kind?REMOVE_VALUE:e.source.key,destructiveOf:e=>"remove"===e.kind,getOptionDescription:e=>"remove"===e.kind?void 0:e.source.description,getOptionIcon:e=>"remove"===e.kind?(0,_jsxRuntime.jsx)(_index3.AppIcon,{name:"trash",size:SHEET_ICON_SIZE,color:L.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})}ProfilePicker.displayName="ProfilePicker";const styles=_reactNative.StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{..._reactNative.StyleSheet.absoluteFill},badge:{position:"absolute",alignItems:"center",justifyContent:"center",borderWidth:2},row:{flexDirection:"row",alignItems:"center"},column:{alignItems:"flex-start"},columnCentred:{alignItems:"center"},meta:{flexShrink:1},metaCentred:{alignItems:"center"},title:{includeFontPadding:!1},subtitle:{includeFontPadding:!1},textCentred:{textAlign:"center"}});var _default=exports.default=ProfilePicker;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Screen=Screen;var _react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeReanimated=require("react-native-reanimated"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useRefreshControl=require("../../hooks/useRefreshControl.js"),_index=require("../../theme/index.js"),_index2=require("../AppBar/index.js"),_index3=require("../AsyncBlock/index.js"),_index4=require("../EmptyState/index.js"),_index5=require("../KeyboardAwareScrollView/index.js"),_index6=require("../KeyboardToolbar/index.js"),_index7=require("../PagedListFooter/index.js"),_ScrollHost=require("./ScrollHost.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},isElementFooter=e=>(0,_react.isValidElement)(e);function renderFooter(e){if(null==e)return null;if(isElementFooter(e))return e;const t=e;return(0,_jsxRuntime.jsx)(t,{})}const topPaddingOf=e=>{const t=_reactNative.StyleSheet.flatten(e),r=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof r?r:0},buildStyles=e=>_reactNative.StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:_reactNative.StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});function Screen(e){const{title:t,subtitle:r,largeTitle:o=!0,headerShadowOnScroll:n,onBack:a,rightActions:i,leading:s,trailing:l,children:c,onRefresh:d,refreshing:u=!1,footer:_,scroll:f=!0,list:x,edges:m=DEFAULT_EDGES,keyboardToolbar:p=!0,bottomInset:h=0,gutter:v,floatingAction:g,scrollRef:S,onScroll:y,contentContainerStyle:R,testID:j}=e,b=(0,_index.useTheme)(),C=v??void 0===x,E=b.space[b.components.screen.gutter],T=C?E:0,L=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),N=(0,_react.useMemo)(()=>buildStyles(b),[b]),[k]=(0,_react.useState)(()=>new _reactNative.Animated.Value(0)),[A,O]=(0,_react.useState)(0),[V,w]=(0,_react.useState)(0),F=void 0!==a,q=(0,_react.useRef)(a);q.current=a;const B=Boolean(t||r||a||s||l||i?.length),M=o&&void 0!==t,H=M&&(void 0!==x||f),P=H?A:0,D=B&&!H&&(n??b.settings.components.screen?.headerShadowOnScroll??!0),[K,z]=(0,_react.useState)(!1),I=(0,_react.useRef)(D);I.current=D;const headerGap=e=>e>0?e:B?b.space.lg:0,G=void 0!==_,U=x?.state,W="data"===U?.status||"empty"===U?.status?U:void 0,{refreshControl:Y}=(0,_useRefreshControl.useRefreshControl)({onRefresh:W?W.refresh:d??noop,refreshing:W?W.refreshing:u}),J=d||W?(0,_react.cloneElement)(Y,{progressViewOffset:P}):void 0,Q=(0,_reactNativeReanimated.useSharedValue)(0),X=(0,_reactNativeReanimated.useSharedValue)(0),Z=(0,_reactNativeReanimated.useSharedValue)(0),$=(0,_reactNativeReanimated.useSharedValue)(0),ee=(0,_react.useRef)(null),te=(0,_react.useRef)(0),re=(0,_react.useRef)(0),oe=(0,_react.useMemo)(()=>({top:Q,bottom:X,offset:Z,maxOffset:$,scrollTo:e=>{const t=ee.current;t instanceof _reactNative.FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[Q,X,Z,$]),ne=(0,_react.useCallback)(e=>{ee.current=e,"function"==typeof S?S(e):S&&(S.current=e)},[S]),ae=(0,_react.useCallback)(()=>{$.value=Math.max(0,te.current-re.current)},[$]),ie=(0,_react.useRef)(y);ie.current=y;const se=(0,_react.useMemo)(()=>_reactNative.Animated.event([{nativeEvent:{contentOffset:{y:k}}}],{useNativeDriver:!1,listener:e=>{if(Z.value=e.nativeEvent.contentOffset.y,I.current){const t=e.nativeEvent.contentOffset.y>0;z(e=>e===t?e:t)}ie.current?.(e)}}),[k,Z]),le=(0,_react.useCallback)(e=>{const{height:t}=e.nativeEvent.layout;O(e=>Math.max(e,t))},[]),ce=(0,_react.useCallback)(e=>{w(e.nativeEvent.layout.height)},[]);(0,_react.useEffect)(()=>{if(!F)return;const e=_reactNative.BackHandler.addEventListener("hardwareBackPress",()=>(q.current?.(),!0));return()=>e.remove()},[F]);const de=m.includes("left")?L.left:0,ue=m.includes("right")?L.right:0,fe=m.includes("bottom")?L.bottom:0,xe=m.includes("top")&&!B?L.top:0,me=b.space[b.components["floating-action-button"]["bottom-offset"]],pe=g?.props.bottomOffset??me,he=g?(0,_index.resolveFloatingActionButtonSize)(b,g.props.size??"md").diameter+pe+b.space.lg:0,ve=G?Math.max(0,V-L.bottom):h,ge=g?(0,_react.cloneElement)(g,{bottomOffset:pe+ve,position:g.props.position??"bottomRight"}):null,Se=G?he:Math.max(fe,g?he+L.bottom:0),ye=h+Se-(G?0:fe),Re=m.filter(e=>"top"!==e&&!("bottom"===e&&G)),je=B?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H?N.overlay:D?N.headerRaised:void 0,onLayout:H?le:void 0,children:(0,_jsxRuntime.jsx)(_index2.AppBar,{title:t,subtitle:r,variant:M?"large":"default",scrollY:H?k:void 0,elevated:D&&K,onBack:a,rightActions:i,leading:s,trailing:l,gutter:E})}):null,be=(0,_react.useCallback)(()=>{const e=ee.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,r,o)=>{re.current=o,Q.value=t+P,X.value=t+o,ae()})},[P,Q,X,ae]);(0,_react.useEffect)(()=>{be()},[be]);const Ce=(0,_react.useCallback)((e,t)=>{te.current=t,ae()},[ae]);let Ee;if(void 0!==x){const{state:e,paging:t,empty:r,skeleton:o,errorTitle:n,data:a,...i}=x,s=topPaddingOf([i.contentContainerStyle,R]),handleEndReached=e=>{t?.hasMore&&!t.loadingMore&&null==t.errorMore&&t.loadMore(),i.onEndReached?.(e)},renderList=(e,r)=>(0,_jsxRuntime.jsx)(_reactNative.FlatList,{data:e,keyboardShouldPersistTaps:"handled",onEndReachedThreshold:t?.5:void 0,...i,ref:ne,refreshControl:J,onScroll:se,onLayout:e=>{be(),i.onLayout?.(e)},onContentSizeChange:(e,t)=>{Ce(e,t),i.onContentSizeChange?.(e,t)},onEndReached:t?handleEndReached:i.onEndReached,ListEmptyComponent:r,ListFooterComponent:t||i.ListFooterComponent?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[renderFooter(i.ListFooterComponent),t?(0,_jsxRuntime.jsx)(_index7.PagedListFooter,{paging:t}):null]}):void 0,scrollEventThrottle:SCROLL_EVENT_THROTTLE,style:N.flex,contentContainerStyle:[{paddingTop:P,paddingLeft:de+T,paddingRight:ue+T},{paddingBottom:h+Se},i.contentContainerStyle,R,r?{flexGrow:1}:void 0,{paddingTop:P+headerGap(s)}]});Ee=(0,_jsxRuntime.jsx)(_ScrollHost.ScrollHostContext.Provider,{value:oe,children:"empty"===e?.status?renderList([],(0,_jsxRuntime.jsx)(_index4.EmptyState,{...r??{title:_index3.DEFAULT_ASYNC_BLOCK_LABELS.emptyTitle}})):e?(0,_jsxRuntime.jsx)(_index3.AsyncBlock,{state:e,skeleton:o,errorTitle:n,style:[N.flex,{paddingTop:P+headerGap(s)}],children:e=>renderList(e,void 0)}):renderList(a,r?(0,_jsxRuntime.jsx)(_index4.EmptyState,{...r}):void 0)})}else Ee=f?(0,_jsxRuntime.jsx)(_ScrollHost.ScrollHostContext.Provider,{value:oe,children:(0,_jsxRuntime.jsxs)(_index5.KeyboardAwareScrollView,{ref:ne,refreshControl:J,onScroll:se,scrollEventThrottle:SCROLL_EVENT_THROTTLE,onLayout:be,onContentSizeChange:Ce,safeAreaEdges:Re,style:N.flex,contentContainerStyle:[{paddingHorizontal:T},R,{paddingTop:P+headerGap(topPaddingOf(R))}],children:[c,ye>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:ye}}):null]})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[N.flex,{paddingLeft:de+T,paddingRight:ue+T,paddingBottom:h+Se},R],children:c});const Te=G?(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardStickyView,{onLayout:ce,style:[N.footer,{paddingLeft:de+E,paddingRight:ue+E,paddingBottom:fe+h}],children:_}):null;return(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:j,style:[N.root,{paddingTop:xe}],children:[H?null:je,Ee,Te,ge,void 0!==x?c:null,H?je:null,p?(0,_jsxRuntime.jsx)(_index6.KeyboardToolbar,{}):null]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Screen=Screen;var _react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeReanimated=require("react-native-reanimated"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useRefreshControl=require("../../hooks/useRefreshControl.js"),_index=require("../../theme/index.js"),_index2=require("../AppBar/index.js"),_index3=require("../AsyncBlock/index.js"),_index4=require("../EmptyState/index.js"),_index5=require("../KeyboardAwareScrollView/index.js"),_index6=require("../KeyboardToolbar/index.js"),_index7=require("../PagedListFooter/index.js"),_ScrollHost=require("./ScrollHost.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},isElementFooter=e=>(0,_react.isValidElement)(e);function renderFooter(e){if(null==e)return null;if(isElementFooter(e))return e;const t=e;return(0,_jsxRuntime.jsx)(t,{})}const topPaddingOf=e=>{const t=_reactNative.StyleSheet.flatten(e),r=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof r?r:0},buildStyles=e=>_reactNative.StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:_reactNative.StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});function Screen(e){const{title:t,subtitle:r,largeTitle:o=!0,headerShadowOnScroll:n,onBack:a,rightActions:i,leading:s,trailing:l,children:c,onRefresh:d,refreshing:u=!1,footer:_,scroll:f=!0,list:x,edges:m=DEFAULT_EDGES,keyboardToolbar:p=!0,bottomInset:h=0,gutter:v,floatingAction:g,scrollRef:S,onScroll:y,contentContainerStyle:R,testID:b}=e,j=(0,_index.useTheme)(),C=v??void 0===x,E=j.space[j.components.screen.gutter],T=C?E:0,L=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),N=(0,_react.useMemo)(()=>buildStyles(j),[j]),[k]=(0,_react.useState)(()=>new _reactNative.Animated.Value(0)),[A,O]=(0,_react.useState)(0),[V,w]=(0,_react.useState)(0),F=void 0!==a,q=(0,_react.useRef)(a);q.current=a;const B=Boolean(t||r||a||s||l||i?.length),M=o&&void 0!==t,H=M&&(void 0!==x||f),P=H?A:0,D=B&&!H&&(n??j.settings.components.screen?.headerShadowOnScroll??!0),[K,z]=(0,_react.useState)(!1),I=(0,_react.useRef)(D);I.current=D;const headerGap=e=>e>0?e:B?j.space.lg:0,G=void 0!==_,U=x?.state,W="data"===U?.status||"empty"===U?.status?U:void 0,{refreshControl:Y}=(0,_useRefreshControl.useRefreshControl)({onRefresh:W?W.refresh:d??noop,refreshing:W?W.refreshing:u}),$=d||W?(0,_react.cloneElement)(Y,{progressViewOffset:P}):void 0,J=(0,_reactNativeReanimated.useSharedValue)(0),Q=(0,_reactNativeReanimated.useSharedValue)(0),X=(0,_reactNativeReanimated.useSharedValue)(0),Z=(0,_reactNativeReanimated.useSharedValue)(0),ee=(0,_react.useRef)(null),te=(0,_react.useRef)(0),re=(0,_react.useRef)(0),oe=(0,_react.useMemo)(()=>({top:J,bottom:Q,offset:X,maxOffset:Z,scrollTo:e=>{const t=ee.current;t instanceof _reactNative.FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[J,Q,X,Z]),ne=(0,_react.useCallback)(e=>{ee.current=e,"function"==typeof S?S(e):S&&(S.current=e)},[S]),ae=(0,_react.useCallback)(()=>{Z.value=Math.max(0,te.current-re.current)},[Z]),ie=(0,_react.useRef)(y);ie.current=y;const se=(0,_react.useMemo)(()=>_reactNative.Animated.event([{nativeEvent:{contentOffset:{y:k}}}],{useNativeDriver:!1,listener:e=>{if(X.value=e.nativeEvent.contentOffset.y,I.current){const t=e.nativeEvent.contentOffset.y>0;z(e=>e===t?e:t)}ie.current?.(e)}}),[k,X]),le=(0,_react.useCallback)(e=>{const{height:t}=e.nativeEvent.layout;O(e=>Math.max(e,t))},[]),ce=(0,_react.useCallback)(e=>{w(e.nativeEvent.layout.height)},[]);(0,_react.useEffect)(()=>{if(!F)return;const e=_reactNative.BackHandler.addEventListener("hardwareBackPress",()=>(q.current?.(),!0));return()=>e.remove()},[F]);const de=m.includes("left")?L.left:0,ue=m.includes("right")?L.right:0,fe=m.includes("bottom")?L.bottom:0,xe=m.includes("top")&&!B?L.top:0,me=j.space[j.components["floating-action-button"]["bottom-offset"]],pe=g?.props.bottomOffset??me,he=g?(0,_index.resolveFloatingActionButtonSize)(j,g.props.size??"md").diameter+pe+j.space.lg:0,ve=G?Math.max(0,V-L.bottom):h,ge=g?(0,_react.cloneElement)(g,{bottomOffset:pe+ve,position:g.props.position??"bottomRight"}):null,Se=G?he:Math.max(fe,g?he+L.bottom:0),ye=h+Se-(G?0:fe),Re=m.filter(e=>"top"!==e&&!("bottom"===e&&G)),be=B?(0,_jsxRuntime.jsx)(_reactNative.View,{style:H?N.overlay:D?N.headerRaised:void 0,onLayout:H?le:void 0,children:(0,_jsxRuntime.jsx)(_index2.AppBar,{title:t,subtitle:r,variant:M?"large":"default",scrollY:H?k:void 0,elevated:D&&K,onBack:a,rightActions:i,leading:s,trailing:l,gutter:E,testID:b?`${b}-app-bar`:void 0})}):null,je=(0,_react.useCallback)(()=>{const e=ee.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,r,o)=>{re.current=o,J.value=t+P,Q.value=t+o,ae()})},[P,J,Q,ae]);(0,_react.useEffect)(()=>{je()},[je]);const Ce=(0,_react.useCallback)((e,t)=>{te.current=t,ae()},[ae]);let Ee;if(void 0!==x){const{state:e,paging:t,empty:r,skeleton:o,errorTitle:n,data:a,...i}=x,s=topPaddingOf([i.contentContainerStyle,R]),handleEndReached=e=>{t?.hasMore&&!t.loadingMore&&null==t.errorMore&&t.loadMore(),i.onEndReached?.(e)},renderList=(e,r)=>(0,_jsxRuntime.jsx)(_reactNative.FlatList,{data:e,keyboardShouldPersistTaps:"handled",onEndReachedThreshold:t?.5:void 0,...i,ref:ne,refreshControl:$,onScroll:se,onLayout:e=>{je(),i.onLayout?.(e)},onContentSizeChange:(e,t)=>{Ce(e,t),i.onContentSizeChange?.(e,t)},onEndReached:t?handleEndReached:i.onEndReached,ListEmptyComponent:r,ListFooterComponent:t||i.ListFooterComponent?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[renderFooter(i.ListFooterComponent),t?(0,_jsxRuntime.jsx)(_index7.PagedListFooter,{paging:t}):null]}):void 0,scrollEventThrottle:SCROLL_EVENT_THROTTLE,style:N.flex,contentContainerStyle:[{paddingTop:P,paddingLeft:de+T,paddingRight:ue+T},{paddingBottom:h+Se},i.contentContainerStyle,R,r?{flexGrow:1}:void 0,{paddingTop:P+headerGap(s)}]});Ee=(0,_jsxRuntime.jsx)(_ScrollHost.ScrollHostContext.Provider,{value:oe,children:"empty"===e?.status?renderList([],(0,_jsxRuntime.jsx)(_index4.EmptyState,{...r??{title:_index3.DEFAULT_ASYNC_BLOCK_LABELS.emptyTitle}})):e?(0,_jsxRuntime.jsx)(_index3.AsyncBlock,{state:e,skeleton:o,errorTitle:n,style:[N.flex,{paddingTop:P+headerGap(s)}],children:e=>renderList(e,void 0)}):renderList(a,r?(0,_jsxRuntime.jsx)(_index4.EmptyState,{...r}):void 0)})}else Ee=f?(0,_jsxRuntime.jsx)(_ScrollHost.ScrollHostContext.Provider,{value:oe,children:(0,_jsxRuntime.jsxs)(_index5.KeyboardAwareScrollView,{ref:ne,refreshControl:$,onScroll:se,scrollEventThrottle:SCROLL_EVENT_THROTTLE,onLayout:je,onContentSizeChange:Ce,safeAreaEdges:Re,style:N.flex,contentContainerStyle:[{paddingHorizontal:T},R,{paddingTop:P+headerGap(topPaddingOf(R))}],children:[c,ye>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:ye}}):null]})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[N.flex,{paddingLeft:de+T,paddingRight:ue+T,paddingBottom:h+Se},R],children:c});const Te=G?(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardStickyView,{onLayout:ce,style:[N.footer,{paddingLeft:de+E,paddingRight:ue+E,paddingBottom:fe+h}],children:_}):null;return(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:b,style:[N.root,{paddingTop:xe}],children:[H?null:be,Ee,Te,ge,void 0!==x?c:null,H?be:null,p?(0,_jsxRuntime.jsx)(_index6.KeyboardToolbar,{}):null]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SearchBar=exports.DEFAULT_SEARCH_BAR_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_useControllableState=require("../../hooks/useControllableState.js"),_useDebounce=require("../../hooks/useDebounce.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_hitSlop=require("../../utils/hitSlop.js"),_mergeRefs=require("../../utils/mergeRefs.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_SearchPanel=require("./SearchPanel.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SEARCH_BAR_LABELS=exports.DEFAULT_SEARCH_BAR_LABELS=Object.freeze({placeholder:"Search…",recents:"Recent searches",clearAll:"Clear all",clearAllRecents:"Clear all recent searches",searchAgain:"Searches again",removeRecent:e=>`Remove ${e} from recent searches`,scope:"Search scope",clearSearch:"Clear search",searching:e=>`Searching ${e}`,suggestionCount:e=>1===e?"1 suggestion":`${e} suggestions`,removed:e=>`Removed ${e}`,recentsCleared:"Recent searches cleared"}),DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=exports.SearchBar=(0,_react.forwardRef)((e,a)=>{const{value:t,onChangeText:s,onSubmit:l,onFocus:r,onBlur:c,placeholder:n,autoFocus:i=!1,disabled:o=!1,onClear:u,leftIcon:d,debounceMs:_,size:h="md",variant:b,radius:p,label:S,labelMode:g="top",labelStyle:f,scopes:m,scope:v,onScopeChange:x,recents:R,maxRecents:C=DEFAULT_PANEL_ROWS,onSelectRecent:j,onRemove:F,onClearRecents:B,suggestions:L,maxSuggestions:y=DEFAULT_PANEL_ROWS,onSelect:A,haptic:E,labels:V,style:k,inputStyle:q,accessibilityLabel:I,testID:T,...D}=e;(0,_assertValidValue.assertValidValue)("SearchBar","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("SearchBar","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("SearchBar","labelMode",e.labelMode,["top","float"]);const H=(0,_index.useTheme)(),N=(0,_react.useMemo)(()=>({...DEFAULT_SEARCH_BAR_LABELS,...V}),[V]),P=n??N.placeholder,z=b??H.settings.components["search-bar"]?.defaultVariant??H.settings.components.field?.defaultVariant??"filled",U="underline"===z,M=(0,_index.resolveFieldSize)(H,h),w=p??H.components["search-bar"][h].radius,O=(0,_FieldBase.resolveFieldTextStyle)(H,{disabled:o}),W=(0,_react.useRef)(null),$=(0,_react.useMemo)(()=>(0,_mergeRefs.mergeRefs)(W,a),[a]),K=(0,_react.useCallback)(()=>{o||W.current?.focus()},[o]),G=(0,_react.useMemo)(()=>buildStyles(H),[H]),J="string"==typeof t?t:"",[Q,X]=(0,_react.useState)(!1),Y=(0,_react.useCallback)(e=>{X(!0),r?.(e)},[r]),Z=(0,_react.useCallback)(e=>{X(!1),c?.(e)},[c]),[ee,ae]=(0,_react.useState)(J),te=(0,_react.useRef)(ee);te.current=ee;const se=(0,_useDebounce.useDebounce)(ee,_??0);(0,_react.useEffect)(()=>{void 0!==_&&J!==te.current&&ae(J)},[J,_]);const le=(0,_react.useRef)(J);(0,_react.useEffect)(()=>{void 0!==_&&se!==le.current&&(le.current=se,s(se))},[se,_,s]);const re=(0,_react.useCallback)(e=>{void 0===_?s(e):ae(e)},[_,s]),ce=(0,_react.useCallback)(()=>{const e=(0,_hapticUtils.resolveHaptic)(E,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),void 0!==_&&(ae(""),le.current=""),s(""),u?.()},[E,_,s,u]),ne=(0,_react.useCallback)(()=>{l?.(void 0!==_?ee:J)},[l,_,ee,J]),ie=void 0!==_?ee:J,oe=ie.length>0,[ue,de]=(0,_useControllableState.useControllableState)({value:v,defaultValue:m?.[0]?.value??"",onChange:x}),he=(0,_react.useCallback)(e=>{de(e);const a=m?.find(a=>a.value===e)?.label;a&&(0,_announce.announce)(N.searching(a))},[m,de,N]),[be,pe]=(0,_react.useState)(!1),Se=(0,_react.useRef)(null),ge=(0,_react.useCallback)(()=>{Se.current&&(clearTimeout(Se.current),Se.current=null)},[]),fe=(0,_react.useCallback)(()=>{ge(),pe(!0)},[ge]),me=(0,_react.useCallback)(()=>{ge(),Se.current=setTimeout(()=>pe(!1),50)},[ge]);(0,_react.useEffect)(()=>ge,[ge]);const ve=!o&&(Q||be),xe=(0,_react.useMemo)(()=>(R??[]).slice(0,C),[R,C]),Re=(0,_react.useMemo)(()=>(L??[]).slice(0,y).map(_SearchPanel.normalizeSuggestion),[L,y]),Ce=ve&&!oe&&xe.length>0,je=ve&&oe&&Re.length>0,Fe=je?Re.length:0,Be=Fe>0?N.suggestionCount(Fe):"";(0,_react.useEffect)(()=>{Be&&(0,_announce.announce)(Be)},[Be]);const Le=(0,_react.useCallback)(()=>{const e=(0,_hapticUtils.resolveHaptic)(E,"selection");e&&(0,_hapticUtils.triggerHaptic)(e)},[E]),ye=(0,_react.useCallback)(e=>{Le(),W.current?.blur(),pe(!1),j?.(e)},[Le,j]),Ae=(0,_react.useCallback)(e=>{Le(),W.current?.blur(),pe(!1),A?.(e)},[Le,A]),Ee=(0,_react.useCallback)(e=>{Le(),F?.(e),(0,_announce.announce)(N.removed(e)),K()},[Le,F,K,N]),Ve=(0,_react.useCallback)(()=>{Le(),B?.(),(0,_announce.announce)(N.recentsCleared),K()},[Le,B,K,N]),ke={size:M.icon,color:o?H.colors["text-disabled"]:H.colors["text-subtle"],disabled:o},qe=d?(0,_slotIcon.renderSlotIcon)(d,ke):(H.settings.icons.search??_defaultIcons.defaultIcons.search)(ke),Ie=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:qe}),Te=Boolean(S)&&"float"===g,De=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Te,floated:Q||oe,variant:z,sizeTokens:M,leadingOffset:M.icon+H.space.md,trailingOffset:oe?M.icon+H.space.md:0,paddingLeft:U?H.space.none:M["padding-x"],color:H.colors["field-label"],style:f}),He=oe&&!o?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ce,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:N.clearSearch,children:(H.settings.icons.close??_defaultIcons.defaultIcons.close)({size:M.icon,color:H.colors["text-muted"]})}):null;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:k,testID:T,children:[S&&!Te?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:h,style:f,children:S}):null,(0,_jsxRuntime.jsx)(_reactNative.View,{style:G.root,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrap,children:[(0,_jsxRuntime.jsx)(_FieldBase.FieldBase,{size:h,variant:z,focused:Q,disabled:o,filled:oe,minHeight:M["min-height"],paddingHorizontal:U?H.space.none:M["padding-x"],radius:w,leading:Ie,trailing:He,topNotch:De.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:I??P,children:(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:$,style:[G.input,{fontSize:M.text,color:O.color,...O.weightStyle},q],value:ie,onChangeText:re,onSubmitEditing:ne,onFocus:Y,onBlur:Z,placeholder:!Te||Q||oe?P:void 0,placeholderTextColor:O.placeholderColor,autoFocus:i,editable:!o,returnKeyType:"search",selectionColor:(0,_FieldBase.resolveVariantColors)(H,z).borderFocusedRepresentative,accessibilityLabel:I??P,accessibilityState:{disabled:o},"aria-disabled":o,...D})}),De.node]})}),m&&m.length>0?(0,_jsxRuntime.jsx)(_SearchPanel.SearchScopeBar,{scopes:m,scope:ue||(m[0]?.value??""),disabled:o,haptic:E,labels:N,onChange:he}):null,Ce?(0,_jsxRuntime.jsx)(_SearchPanel.SearchRecents,{recents:xe,labels:N,onSelect:ye,onRemove:F?Ee:void 0,onClear:B?Ve:void 0,onHold:fe,onRelease:me}):null,je?(0,_jsxRuntime.jsx)(_SearchPanel.SearchSuggestions,{suggestions:Re,query:ie,onSelect:Ae,onHold:fe,onRelease:me}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flexDirection:"row",alignItems:"center",width:"100%",position:"relative",overflow:"visible"},fieldWrap:{flex:1,position:"relative",overflow:"visible"},input:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});var _default=exports.default=SearchBar;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.SearchBar=exports.DEFAULT_SEARCH_BAR_LABELS=void 0;var _react=require("react"),_reactNative=require("react-native"),_useControllableState=require("../../hooks/useControllableState.js"),_useDebounce=require("../../hooks/useDebounce.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_assertValidValue=require("../../utils/assertValidValue.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_hitSlop=require("../../utils/hitSlop.js"),_mergeRefs=require("../../utils/mergeRefs.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_SearchPanel=require("./SearchPanel.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SEARCH_BAR_LABELS=exports.DEFAULT_SEARCH_BAR_LABELS=Object.freeze({placeholder:"Search…",recents:"Recent searches",clearAll:"Clear all",clearAllRecents:"Clear all recent searches",searchAgain:"Searches again",removeRecent:e=>`Remove ${e} from recent searches`,scope:"Search scope",clearSearch:"Clear search",searching:e=>`Searching ${e}`,suggestionCount:e=>1===e?"1 suggestion":`${e} suggestions`,removed:e=>`Removed ${e}`,recentsCleared:"Recent searches cleared"}),DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=exports.SearchBar=(0,_react.forwardRef)((e,a)=>{const{value:t,onChangeText:s,onSubmit:l,onFocus:r,onBlur:c,placeholder:i,autoFocus:n=!1,disabled:o=!1,onClear:u,leftIcon:d,debounceMs:_,size:h="md",variant:b,radius:p,label:S,labelMode:g="top",labelStyle:f,scopes:m,scope:v,onScopeChange:x,recents:R,maxRecents:C=DEFAULT_PANEL_ROWS,onSelectRecent:j,onRemove:F,onClearRecents:B,suggestions:L,maxSuggestions:y=DEFAULT_PANEL_ROWS,onSelect:A,haptic:E,labels:V,style:k,inputStyle:I,accessibilityLabel:q,testID:T,...D}=e;(0,_assertValidValue.assertValidValue)("SearchBar","size",e.size,["sm","md","lg"]),(0,_assertValidValue.assertValidValue)("SearchBar","variant",e.variant,["outline","filled","underline"]),(0,_assertValidValue.assertValidValue)("SearchBar","labelMode",e.labelMode,["top","float"]);const H=(0,_index.useTheme)(),N=(0,_react.useMemo)(()=>({...DEFAULT_SEARCH_BAR_LABELS,...V}),[V]),P=i??N.placeholder,z=b??H.settings.components["search-bar"]?.defaultVariant??H.settings.components.field?.defaultVariant??"filled",U="underline"===z,M=(0,_index.resolveFieldSize)(H,h),w=p??H.components["search-bar"][h].radius,O=(0,_FieldBase.resolveFieldTextStyle)(H,{disabled:o}),W=(0,_react.useRef)(null),$=(0,_react.useMemo)(()=>(0,_mergeRefs.mergeRefs)(W,a),[a]),K=(0,_react.useCallback)(()=>{o||W.current?.focus()},[o]),G=(0,_react.useMemo)(()=>buildStyles(H),[H]),J="string"==typeof t?t:"",[Q,X]=(0,_react.useState)(!1),Y=(0,_react.useCallback)(e=>{X(!0),r?.(e)},[r]),Z=(0,_react.useCallback)(e=>{X(!1),c?.(e)},[c]),[ee,ae]=(0,_react.useState)(J),te=(0,_react.useRef)(ee);te.current=ee;const se=(0,_useDebounce.useDebounce)(ee,_??0);(0,_react.useEffect)(()=>{void 0!==_&&J!==te.current&&ae(J)},[J,_]);const le=(0,_react.useRef)(J);(0,_react.useEffect)(()=>{void 0!==_&&se!==le.current&&(le.current=se,s(se))},[se,_,s]);const re=(0,_react.useCallback)(e=>{void 0===_?s(e):ae(e)},[_,s]),ce=(0,_react.useCallback)(()=>{const e=(0,_hapticUtils.resolveHaptic)(E,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),void 0!==_&&(ae(""),le.current=""),s(""),u?.()},[E,_,s,u]),ie=(0,_react.useCallback)(()=>{l?.(void 0!==_?ee:J)},[l,_,ee,J]),ne=void 0!==_?ee:J,oe=ne.length>0,[ue,de]=(0,_useControllableState.useControllableState)({value:v,defaultValue:m?.[0]?.value??"",onChange:x}),he=(0,_react.useCallback)(e=>{de(e);const a=m?.find(a=>a.value===e)?.label;a&&(0,_announce.announce)(N.searching(a))},[m,de,N]),[be,pe]=(0,_react.useState)(!1),Se=(0,_react.useRef)(null),ge=(0,_react.useCallback)(()=>{Se.current&&(clearTimeout(Se.current),Se.current=null)},[]),fe=(0,_react.useCallback)(()=>{ge(),pe(!0)},[ge]),me=(0,_react.useCallback)(()=>{ge(),Se.current=setTimeout(()=>pe(!1),50)},[ge]);(0,_react.useEffect)(()=>ge,[ge]);const ve=!o&&(Q||be),xe=(0,_react.useMemo)(()=>(R??[]).slice(0,C),[R,C]),Re=(0,_react.useMemo)(()=>(L??[]).slice(0,y).map(_SearchPanel.normalizeSuggestion),[L,y]),Ce=ve&&!oe&&xe.length>0,je=ve&&oe&&Re.length>0,Fe=je?Re.length:0,Be=Fe>0?N.suggestionCount(Fe):"";(0,_react.useEffect)(()=>{Be&&(0,_announce.announce)(Be)},[Be]);const Le=(0,_react.useCallback)(()=>{const e=(0,_hapticUtils.resolveHaptic)(E,"selection");e&&(0,_hapticUtils.triggerHaptic)(e)},[E]),ye=(0,_react.useCallback)(e=>{Le(),W.current?.blur(),pe(!1),j?.(e)},[Le,j]),Ae=(0,_react.useCallback)(e=>{Le(),W.current?.blur(),pe(!1),A?.(e)},[Le,A]),Ee=(0,_react.useCallback)(e=>{Le(),F?.(e),(0,_announce.announce)(N.removed(e)),K()},[Le,F,K,N]),Ve=(0,_react.useCallback)(()=>{Le(),B?.(),(0,_announce.announce)(N.recentsCleared),K()},[Le,B,K,N]),ke={size:M.icon,color:o?H.colors["text-disabled"]:H.colors["text-subtle"],disabled:o},Ie=d?(0,_slotIcon.renderSlotIcon)(d,ke):(H.settings.icons.search??_defaultIcons.defaultIcons.search)(ke),qe=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Ie}),Te=Boolean(S)&&"float"===g,De=(0,_useFloatingLabel.useFloatingLabel)({label:S,enabled:Te,floated:Q||oe,variant:z,sizeTokens:M,leadingOffset:M.icon+H.space.md,trailingOffset:oe?M.icon+H.space.md:0,paddingLeft:U?H.space.none:M["padding-x"],color:H.colors["field-label"],style:f}),He=oe&&!o?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ce,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:N.clearSearch,children:(H.settings.icons.close??_defaultIcons.defaultIcons.close)({size:M.icon,color:H.colors["text-muted"]})}):null;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:k,testID:T,children:[S&&!Te?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:h,style:f,children:S}):null,(0,_jsxRuntime.jsx)(_reactNative.View,{style:G.root,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:G.fieldWrap,children:[(0,_jsxRuntime.jsx)(_FieldBase.FieldBase,{testID:T?`${T}-field`:void 0,size:h,variant:z,focused:Q,disabled:o,filled:oe,minHeight:M["min-height"],paddingHorizontal:U?H.space.none:M["padding-x"],radius:w,leading:qe,trailing:He,topNotch:De.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:q??P,children:(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:$,style:[G.input,{fontSize:M.text,color:O.color,...O.weightStyle},I],value:ne,onChangeText:re,onSubmitEditing:ie,onFocus:Y,onBlur:Z,placeholder:!Te||Q||oe?P:void 0,placeholderTextColor:O.placeholderColor,autoFocus:n,editable:!o,returnKeyType:"search",selectionColor:(0,_FieldBase.resolveVariantColors)(H,z).borderFocusedRepresentative,accessibilityLabel:q??P,accessibilityState:{disabled:o},"aria-disabled":o,...D})}),De.node]})}),m&&m.length>0?(0,_jsxRuntime.jsx)(_SearchPanel.SearchScopeBar,{scopes:m,scope:ue||(m[0]?.value??""),disabled:o,haptic:E,labels:N,onChange:he}):null,Ce?(0,_jsxRuntime.jsx)(_SearchPanel.SearchRecents,{recents:xe,labels:N,onSelect:ye,onRemove:F?Ee:void 0,onClear:B?Ve:void 0,onHold:fe,onRelease:me}):null,je?(0,_jsxRuntime.jsx)(_SearchPanel.SearchSuggestions,{suggestions:Re,query:ne,onSelect:Ae,onHold:fe,onRelease:me}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flexDirection:"row",alignItems:"center",width:"100%",position:"relative",overflow:"visible"},fieldWrap:{flex:1,position:"relative",overflow:"visible"},input:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});var _default=exports.default=SearchBar;