@webority/mobile-ui 0.164.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 (95) hide show
  1. package/LICENSE.txt +1 -1
  2. package/dist/canvas-kit/kit.js +5 -5
  3. package/dist/canvas-kit/manifest.json +6 -1
  4. package/dist/canvas-kit/release.json +6 -6
  5. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  6. package/lib/commonjs/components/Banner/Banner.js +1 -1
  7. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  8. package/lib/commonjs/components/Card/Card.js +1 -1
  9. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  10. package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +1 -1
  11. package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
  12. package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
  13. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  14. package/lib/commonjs/components/Input/Input.js +1 -1
  15. package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
  16. package/lib/commonjs/components/Modal/Modal.js +1 -1
  17. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  18. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  19. package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  20. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  21. package/lib/commonjs/components/Screen/Screen.js +1 -1
  22. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  23. package/lib/commonjs/components/Slider/Slider.js +1 -1
  24. package/lib/commonjs/components/SliderField/SliderField.js +1 -1
  25. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  26. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  27. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  28. package/lib/commonjs/theme/merge.js +1 -1
  29. package/lib/module/components/Avatar/Avatar.js +1 -1
  30. package/lib/module/components/Banner/Banner.js +1 -1
  31. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  32. package/lib/module/components/Card/Card.js +1 -1
  33. package/lib/module/components/Carousel/Carousel.js +1 -1
  34. package/lib/module/components/DateRangePicker/DateRangePicker.js +1 -1
  35. package/lib/module/components/FieldBase/FieldBase.js +1 -1
  36. package/lib/module/components/IconBadge/IconBadge.js +1 -1
  37. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  38. package/lib/module/components/Input/Input.js +1 -1
  39. package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
  40. package/lib/module/components/Modal/Modal.js +1 -1
  41. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  42. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  43. package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
  44. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  45. package/lib/module/components/Screen/Screen.js +1 -1
  46. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  47. package/lib/module/components/Slider/Slider.js +1 -1
  48. package/lib/module/components/SliderField/SliderField.js +1 -1
  49. package/lib/module/components/TagInput/TagInput.js +1 -1
  50. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  51. package/lib/module/hooks/useDragToDismiss.js +1 -1
  52. package/lib/module/theme/merge.js +1 -1
  53. package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +1 -0
  54. package/lib/typescript/commonjs/components/Avatar/Avatar.d.ts +1 -0
  55. package/lib/typescript/commonjs/components/BottomSheet/BottomSheet.d.ts +1 -0
  56. package/lib/typescript/commonjs/components/Carousel/Carousel.d.ts +1 -0
  57. package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +1 -0
  58. package/lib/typescript/commonjs/components/FieldBase/FieldBase.d.ts +1 -0
  59. package/lib/typescript/commonjs/components/ImageGallery/ImageGallery.d.ts +1 -0
  60. package/lib/typescript/commonjs/components/Input/Input.d.ts +1 -0
  61. package/lib/typescript/commonjs/components/Menu/Menu.d.ts +1 -1
  62. package/lib/typescript/commonjs/components/Modal/Modal.d.ts +1 -0
  63. package/lib/typescript/commonjs/components/NumberInput/NumberInput.d.ts +1 -0
  64. package/lib/typescript/commonjs/components/OptionSheet/OptionSheet.d.ts +1 -1
  65. package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -0
  66. package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +1 -0
  67. package/lib/typescript/commonjs/components/Screen/Screen.d.ts +1 -0
  68. package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +1 -0
  69. package/lib/typescript/commonjs/components/Slider/Slider.d.ts +5 -0
  70. package/lib/typescript/commonjs/components/SliderField/SliderField.d.ts +1 -0
  71. package/lib/typescript/commonjs/components/TagInput/TagInput.d.ts +1 -0
  72. package/lib/typescript/commonjs/hooks/useDragToDismiss.d.ts +2 -0
  73. package/lib/typescript/commonjs/theme/types.d.ts +9 -3
  74. package/lib/typescript/module/components/AppBar/AppBar.d.ts +1 -0
  75. package/lib/typescript/module/components/Avatar/Avatar.d.ts +1 -0
  76. package/lib/typescript/module/components/BottomSheet/BottomSheet.d.ts +1 -0
  77. package/lib/typescript/module/components/Carousel/Carousel.d.ts +1 -0
  78. package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +1 -0
  79. package/lib/typescript/module/components/FieldBase/FieldBase.d.ts +1 -0
  80. package/lib/typescript/module/components/ImageGallery/ImageGallery.d.ts +1 -0
  81. package/lib/typescript/module/components/Input/Input.d.ts +1 -0
  82. package/lib/typescript/module/components/Menu/Menu.d.ts +1 -1
  83. package/lib/typescript/module/components/Modal/Modal.d.ts +1 -0
  84. package/lib/typescript/module/components/NumberInput/NumberInput.d.ts +1 -0
  85. package/lib/typescript/module/components/OptionSheet/OptionSheet.d.ts +1 -1
  86. package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -0
  87. package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +1 -0
  88. package/lib/typescript/module/components/Screen/Screen.d.ts +1 -0
  89. package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +1 -0
  90. package/lib/typescript/module/components/Slider/Slider.d.ts +5 -0
  91. package/lib/typescript/module/components/SliderField/SliderField.d.ts +1 -0
  92. package/lib/typescript/module/components/TagInput/TagInput.d.ts +1 -0
  93. package/lib/typescript/module/hooks/useDragToDismiss.d.ts +2 -0
  94. package/lib/typescript/module/theme/types.d.ts +9 -3
  95. package/package.json +9 -10
@@ -1 +1 @@
1
- "use strict";import{forwardRef}from"react";import{StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{squirclePath}from"../../squircle.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:56,icon:28}},FILL_OPACITY=.14,HALO_FILL_OPACITY=.16,inkFor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},IconBadge=forwardRef((e,r)=>{const{icon:t,iconVariant:s,size:o="md",tone:i="primary",color:a,fill:n="tint",shape:l="circle",dimension:c,accessibilityLabel:d,pointerEvents:u,style:m,testID:h}=e;assertValidValue("IconBadge","size",e.size,["sm","md","lg"]),assertValidValue("IconBadge","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("IconBadge","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]),assertValidValue("IconBadge","fill",e.fill,["tint","halo","surface"]),assertValidValue("IconBadge","shape",e.shape,["circle","squircle"]);const g=useTheme(),f=SIZE_MAP[o],p=a??inkFor(g,i),I=c??f.diameter,y=null!=c?Math.round(c/2):f.icon,V="surface"===n?g.colors.surface:void 0===a&&"neutral"===i?g.colors["bg-muted"]:tintOf(p,"halo"===n?.16:.14,g.colors["bg-muted"]),b={color:p,size:y,disabled:!1},j=void 0!==d,w="squircle"===l;return _jsxs(View,{ref:r,testID:h,pointerEvents:u,accessible:j,accessibilityRole:j?"image":void 0,accessibilityLabel:d,importantForAccessibility:j?"yes":"no",style:[styles.base,w?{width:I,height:I}:{width:I,height:I,borderRadius:I/2,...smoothCorners,backgroundColor:V},m],children:[w?_jsx(Svg,{style:styles.overlay,width:I,height:I,viewBox:`0 0 ${I} ${I}`,children:_jsx(Path,{d:squirclePath({width:I,height:I,radius:g.radius.lg,smoothing:g.cornerSmoothing}),fill:V})}):null,renderSlotIcon(t,b,s)]})});IconBadge.displayName="IconBadge";const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},overlay:{position:"absolute",top:0,left:0}});export{IconBadge};export default IconBadge;
1
+ "use strict";import{forwardRef}from"react";import{Platform,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{squirclePath}from"../../squircle.js";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:56,icon:28}},FILL_OPACITY=.14,HALO_FILL_OPACITY=.16,inkFor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["text-muted"];default:return e.colors.primary}},IconBadge=forwardRef((e,r)=>{const{icon:t,iconVariant:o,size:s="md",tone:i="primary",color:a,fill:n="tint",shape:l="circle",dimension:c,accessibilityLabel:d,pointerEvents:u,style:m,testID:h}=e;assertValidValue("IconBadge","size",e.size,["sm","md","lg"]),assertValidValue("IconBadge","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("IconBadge","iconVariant",e.iconVariant,["linear","bold","broken","bulk","outline","twotone"]),assertValidValue("IconBadge","fill",e.fill,["tint","halo","surface"]),assertValidValue("IconBadge","shape",e.shape,["circle","squircle"]);const f=useTheme(),g=SIZE_MAP[s],p=a??inkFor(f,i),I=c??g.diameter,y=null!=c?Math.round(c/2):g.icon,b="surface"===n?f.colors.surface:void 0===a&&"neutral"===i?f.colors["bg-muted"]:tintOf(p,"halo"===n?.16:.14,f.colors["bg-muted"]),V={color:p,size:y,disabled:!1},j=void 0!==d,w="squircle"===l;return _jsxs(View,{ref:r,testID:h,pointerEvents:u,accessible:j,accessibilityRole:j?"image":void 0,accessibilityLabel:d,importantForAccessibility:j?"yes":"no",..."web"!==Platform.OS||j?null:{"aria-hidden":!0},style:[styles.base,w?{width:I,height:I}:{width:I,height:I,borderRadius:I/2,...smoothCorners,backgroundColor:b},m],children:[w?_jsx(Svg,{style:styles.overlay,width:I,height:I,viewBox:`0 0 ${I} ${I}`,children:_jsx(Path,{d:squirclePath({width:I,height:I,radius:f.radius.lg,smoothing:f.cornerSmoothing}),fill:b})}):null,renderSlotIcon(t,V,o)]})});IconBadge.displayName="IconBadge";const styles=StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},overlay:{position:"absolute",top:0,left:0}});export{IconBadge};export default IconBadge;
@@ -1 +1 @@
1
- "use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,usePinchGesture,useTapGesture}from"react-native-gesture-handler";import Animated,{useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{scheduleOnRN}from"react-native-worklets";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const 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:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:u,containerStyle:c,testID:m,labels:h})=>{const d=useTheme(),g=useMemo(()=>buildStyles(d),[d]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...h}),[h]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[v,x]=useState(!1),y=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,c],testID:m,accessibilityLabel:u??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:v,importantForAccessibility:v?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:d.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:v,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:y,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:c,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6),n=useMemo(()=>Array.from({length:o},(e,t)=>({key:`sk-thumb-${t}`})),[o]);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:n.map(e=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const u=useTheme(),c=useMemo(()=>buildLightboxStyles(u),[u]),m=useRef(null),[h,d]=useState(a),g=useCallback(e=>{if(e!==h){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),d(e),o(e)}},[h,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===h,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[h,l,t.length,n,r]),b=t[h]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:c.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:c.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:u.colors["on-scrim"]},accessibilityLabel:r.imageOf(h+1,t.length),children:`${h+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:c.closeButton,hitSlop:12,...hitSlopMarker(12),children:(u.settings.icons.close??defaultIcons.close)({size:24,color:u.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:c.captionWrap,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:c.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:u})=>{const c=Dimensions.get("window"),m=useSharedValue(1),h=useSharedValue(1),d=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),h.value=1,d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,h,d,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),d.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),h.value=1,p.value=0,b.value=0)},[l,m,d,g,h,p,b]);const v=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),x=useMemo(()=>({enabled:i,onActivate:()=>{"worklet";h.value=m.value},onUpdate:e=>{"worklet";const t=h.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t},onDeactivate:()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(h.value=s)):void(h.value=m.value)}}),[i,m,h,d,g,p,b,o,s]),y=usePinchGesture(x),I=useMemo(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";p.value=d.value,b.value=g.value},onUpdate:e=>{"worklet";m.value<=1||(d.value=p.value+e.translationX,g.value=b.value+e.translationY)},onDeactivate:()=>{"worklet";p.value=d.value,b.value=g.value}}),[m,d,g,p,b]),w=usePanGesture(I),C=useMemo(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";scheduleOnRN(v),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),h.value=n)}}),[m,h,d,g,p,b,v,n]),_=useTapGesture(C),f=useCompetingGestures(y,w,_),G=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:g.value},{scale:m.value}]}),[d,g,m]);React.useEffect(()=>{l||S()},[l,S]);const j=e.alt??u(t+1,a);return _jsx(GestureDetector,{gesture:f,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:c.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,G],accessibilityLabel:j,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>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,...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,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>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,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...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=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
1
+ "use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,useCompetingGestures,usePanGesture,usePinchGesture,useTapGesture}from"react-native-gesture-handler";import Animated,{useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{scheduleOnRN}from"react-native-worklets";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const 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:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:u,containerStyle:c,testID:m,labels:h})=>{const d=useTheme(),g=useMemo(()=>buildStyles(d),[d]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...h}),[h]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[v,x]=useState(!1),y=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),x(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,c],testID:m,accessibilityLabel:u??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:v,importantForAccessibility:v?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:y,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:d.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:v,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:y,haptic:n,labels:p,testID:m}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:c,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6),n=useMemo(()=>Array.from({length:o},(e,t)=>({key:`sk-thumb-${t}`})),[o]);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:n.map(e=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},e.key))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r,testID:u})=>{const c=useTheme(),m=useMemo(()=>buildLightboxStyles(c),[c]),h=useRef(null),[d,g]=useState(a),p=useCallback(e=>{if(e!==d){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),g(e),o(e)}},[d,o,n]),b=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[d,l,t.length,n,r]),S=t[d]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:m.backdrop,children:[_jsx(Carousel,{ref:h,testID:u?`${u}-lightbox`:void 0,data:t,defaultIndex:a,onIndexChange:p,renderItem:b,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:m.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:r.imageOf(d+1,t.length),children:`${d+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:m.closeButton,hitSlop:12,...hitSlopMarker(12),children:(c.settings.icons.close??defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),S?_jsx(Animated.View,{style:m.captionWrap,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:m.captionText,children:S})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:u})=>{const c=Dimensions.get("window"),m=useSharedValue(1),h=useSharedValue(1),d=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),h.value=1,d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,h,d,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),d.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),h.value=1,p.value=0,b.value=0)},[l,m,d,g,h,p,b]);const v=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),x=useMemo(()=>({enabled:i,onActivate:()=>{"worklet";h.value=m.value},onUpdate:e=>{"worklet";const t=h.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t},onDeactivate:()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(h.value=s)):void(h.value=m.value)}}),[i,m,h,d,g,p,b,o,s]),y=usePinchGesture(x),I=useMemo(()=>({minPointers:1,maxPointers:1,onActivate:()=>{"worklet";p.value=d.value,b.value=g.value},onUpdate:e=>{"worklet";m.value<=1||(d.value=p.value+e.translationX,g.value=b.value+e.translationY)},onDeactivate:()=>{"worklet";p.value=d.value,b.value=g.value}}),[m,d,g,p,b]),w=usePanGesture(I),C=useMemo(()=>({numberOfTaps:2,onDeactivate:()=>{"worklet";scheduleOnRN(v),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),d.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),h.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),h.value=n)}}),[m,h,d,g,p,b,v,n]),_=useTapGesture(C),f=useCompetingGestures(y,w,_),G=useAnimatedStyle(()=>({transform:[{translateX:d.value},{translateY:g.value},{scale:m.value}]}),[d,g,m]);React.useEffect(()=>{l||S()},[l,S]);const j=e.alt??u(t+1,a);return _jsx(GestureDetector,{gesture:f,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:c.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,G],accessibilityLabel:j,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>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,...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,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>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,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...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=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:y,prefixStyle:v,readOnly:b=!1,action:S,actionStyle:w,size:T="md",variant:j,labelMode:I,required:V=!1,maxLength:F,showCounter:_=!0,textAlign:A,format:R,parse:D,style:z,containerStyle:L,inputStyle:k,labelStyle:P,messageStyle:C,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;assertValidValue("Input","variant",j,["outline","filled","underline"]),assertValidValue("Input","size",e.size,["sm","md","lg"]),assertValidValue("Input","labelMode",I,["float","top"]),assertValidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,T),J=W.components.input[T]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=j??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=I??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(y),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ye=useCallback(()=>{me&&ge.current?.focus()},[me]),ve=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Te=W.settings.components.input?.shakeOnError??!1,je=useRef(de);useEffect(()=>{if(!Te)return void(je.current=de);let e;return de&&!je.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:nativeDriver})]),e.start()),triggerHaptic("notificationError")),je.current=de,()=>e?.stop()},[de,be,Te,we]);const Ie=useCallback(e=>{ee(!0),E?.(e)},[E]),Ve=useCallback(e=>{ee(!1),B?.(e)},[B]),Fe=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,De=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],ze=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Le=Boolean(x)||Boolean(g)||oe,ke="underline"===Q,Pe=m?X.icon+W.space.md+1+W.space.md:0,Ce=useFloatingLabel({label:i,enabled:ve,floated:xe,required:V,variant:Q,sizeTokens:X,leadingOffset:Pe,trailingOffset:Le?X.icon+W.space.sm:0,textAlign:"center"===A||"right"===A?A:"left",paddingLeft:ke?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:De,style:P}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=V&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof F&&"string"==typeof l?`${l.length} / ${F}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(C,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Fe,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(v),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},v],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},v],children:_jsx(TextInkContext.Provider,{value:Ze,children:y})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:T,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:ze}]},z],children:[pe&&!ve?_jsx(FieldLabel,{size:T,required:V,help:n,color:De,style:P,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:T,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:ke?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:Ce.topNotch,onPress:ye,pressFeedback:!1,style:L,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:ke?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},k],textAlign:A,placeholder:ve&&!xe||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:Ie,onBlur:Ve,editable:me,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:F,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me&&"string"==typeof o?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),Ce.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},C],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>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}});export{Input};export default Input;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:v,prefixStyle:y,readOnly:b=!1,action:S,actionStyle:w,size:T="md",variant:j,labelMode:I,required:V=!1,maxLength:F,showCounter:_=!0,textAlign:A,format:R,parse:D,style:z,containerStyle:L,inputStyle:k,labelStyle:P,messageStyle:C,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;assertValidValue("Input","variant",j,["outline","filled","underline"]),assertValidValue("Input","size",e.size,["sm","md","lg"]),assertValidValue("Input","labelMode",I,["float","top"]),assertValidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,T),J=W.components.input[T]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=j??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=I??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(v),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ve=useCallback(()=>{me&&ge.current?.focus()},[me]),ye=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Te=W.settings.components.input?.shakeOnError??!1,je=useRef(de);useEffect(()=>{if(!Te)return void(je.current=de);let e;return de&&!je.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:nativeDriver})]),e.start()),triggerHaptic("notificationError")),je.current=de,()=>e?.stop()},[de,be,Te,we]);const Ie=useCallback(e=>{ee(!0),E?.(e)},[E]),Ve=useCallback(e=>{ee(!1),B?.(e)},[B]),Fe=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,De=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],ze=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Le=Boolean(x)||Boolean(g)||oe,ke="underline"===Q,Pe=m?X.icon+W.space.md+1+W.space.md:0,Ce=useFloatingLabel({label:i,enabled:ye,floated:xe,required:V,variant:Q,sizeTokens:X,leadingOffset:Pe,trailingOffset:Le?X.icon+W.space.sm:0,textAlign:"center"===A||"right"===A?A:"left",paddingLeft:ke?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:De,style:P}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=V&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof F&&"string"==typeof l?`${l.length} / ${F}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(C,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Fe,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(y),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof v||"number"==typeof v?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},y],children:v}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},y],children:_jsx(TextInkContext.Provider,{value:Ze,children:v})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:T,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:ze}]},z],children:[pe&&!ye?_jsx(FieldLabel,{size:T,required:V,help:n,color:De,style:P,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{testID:O?`${O}-field`:void 0,size:T,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:ke?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:Ce.topNotch,onPress:ve,pressFeedback:!1,style:L,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:ke?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},k],textAlign:A,placeholder:ye&&!xe||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:Ie,onBlur:Ve,editable:me,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:F,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me&&"string"==typeof o?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),Ce.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},C],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>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}});export{Input};export default Input;
@@ -1 +1 @@
1
- "use strict";import{markdownToPlainText}from"@webority/markdown-core";import{formatTime}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{Markdown}from"../Markdown/index.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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"});const 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"]}};export const MessageBubble=({side:e,text:s,children:t,markdown:o,groupPosition:r="single",author:n,time:i,status:a,replyTo:l,streaming:c=!1,error:u,onRetry:d,actions:m,onCopy:b,onLongPress:p,footer:x,labels:y,haptic:f,style:h,testID:g})=>{assertValidValue("MessageBubble","side",e,["mine","theirs"]),assertValidValue("MessageBubble","groupPosition",r,["single","first","middle","last"]),assertValidValue("MessageBubble","status",a,["sending","sent","delivered","read","failed"]);const T=useTheme(),j=useMemo(()=>buildStyles(T),[T]),L=y?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...y}:DEFAULT_MESSAGE_BUBBLE_LABELS,_="mine"===e,B=!u&&(o??"theirs"===e),P="single"===r||"first"===r,S="single"===r||"last"===r,M=null==i?"":formatTime(i),E=("failed"===a||Boolean(u))&&Boolean(d),A=_?L.you:n??"",k=useMemo(()=>{const e=[];return b&&!m?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:L.copy,onPress:()=>b(s)}),m&&e.push(...m),l?.onPress&&e.push({name:"openReply",label:L.replyTo(l.author),onPress:l.onPress}),E&&d&&e.push({name:"retry",label:L.retry,onPress:d}),e},[m,b,s,l,E,d,L]),v=(m?.length??0)>0||Boolean(b),w=useMemo(()=>v?{items:k.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[v,k]),I=useContextMenu(w,{haptic:f,testID:g}),C=I.hostProps.onLongPress,R=!t||(m?.length??0)>0,V=a&&_?L[a]:"",D=useMemo(()=>B&&null==t?markdownToPlainText(s):s,[B,t,s]),$=[A,M,D,l?`${L.replyTo(l.author)}: ${l.text}`:"",V].filter(Boolean).join(", "),U=useRef(c);useEffect(()=>{U.current&&!c&&!u&&s&&announce(A?`${A}, ${D}`:D),U.current=c},[c,u,s,D,A]);const z=useRef(u);useEffect(()=>{u&&u!==z.current&&announce(u,{polite:!1}),z.current=u},[u]);const H=useCallback(e=>{C?.(e),p?.()},[C,p]),F=useCallback(e=>{k.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[k]),O=T.radius.xl,G=T.radius.sm,N=_?{borderTopRightRadius:P?O:G,borderBottomRightRadius:S?O:G}:{borderTopLeftRadius:P?O:G,borderBottomLeftRadius:S?O:G},W=t??(B?_jsx(Markdown,{children:s}):_jsx(Text,{variant:"body",children:s})),q=l?_jsxs(Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${L.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?_jsx(Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,_jsx(Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,_?j.mine:j.theirs,N],Y=R?{accessible:!0,accessibilityLabel:$,accessibilityState:{busy:c},"aria-busy":c,accessibilityActions:k.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:F}:{accessible:!1},J=v?_jsxs(Pressable,{ref:I.hostRef,...I.hostProps,onLongPress:H,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}):_jsxs(View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}),K=S&&(""!==M||_&&a);return _jsxs(View,{style:[j.root,_?j.rootMine:j.rootTheirs,{marginTop:P?T.space.sm:T.space.xxs},h],accessibilityState:{busy:c},"aria-busy":c,testID:g,children:[!_&&P&&n?_jsx(Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:n}):null,J,I.renderSurface(),K?_jsxs(View,{style:[j.meta,_?j.metaMine:null],importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:[M?_jsx(Text,{variant:"caption",color:"tertiary",children:M}):null,_&&a?_jsx(AppIcon,{name:statusIcon(a),size:14,color:statusColour(T,a),accessibilityLabel:L[a],testID:g?`${g}-status-${a}`:void 0}):null]}):null,u?_jsx(Text,{variant:"bodySmall",color:"danger",style:_?j.endText:null,children:u}):null,E?_jsx(Button,{label:L.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,x]})};const buildStyles=e=>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,...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"}});export default MessageBubble;
1
+ "use strict";import{markdownToPlainText}from"@webority/markdown-core";import{formatTime}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{Markdown}from"../Markdown/index.js";import{useContextMenu}from"../Menu/useContextMenu.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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"});const 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"]}};export const MessageBubble=({side:e,text:s,children:t,markdown:o,groupPosition:r="single",author:n,time:a,status:i,replyTo:l,streaming:c=!1,error:u,onRetry:d,actions:m,onCopy:b,onLongPress:p,footer:x,labels:f,haptic:y,style:h,testID:g})=>{assertValidValue("MessageBubble","side",e,["mine","theirs"]),assertValidValue("MessageBubble","groupPosition",r,["single","first","middle","last"]),assertValidValue("MessageBubble","status",i,["sending","sent","delivered","read","failed"]);const T=useTheme(),j=useMemo(()=>buildStyles(T),[T]),P=f?{...DEFAULT_MESSAGE_BUBBLE_LABELS,...f}:DEFAULT_MESSAGE_BUBBLE_LABELS,L="mine"===e,S=!u&&(o??"theirs"===e),_="single"===r||"first"===r,B="single"===r||"last"===r,M=null==a?"":formatTime(a),E=("failed"===i||Boolean(u))&&Boolean(d),A=L?P.you:n??"",k=useMemo(()=>{const e=[];return b&&!m?.some(e=>"copy"===e.name)&&e.push({name:"copy",label:P.copy,onPress:()=>b(s)}),m&&e.push(...m),l?.onPress&&e.push({name:"openReply",label:P.replyTo(l.author),onPress:l.onPress}),E&&d&&e.push({name:"retry",label:P.retry,onPress:d}),e},[m,b,s,l,E,d,P]),v=(m?.length??0)>0||Boolean(b),w=useMemo(()=>v?{items:k.map(({name:e,label:s,onPress:t})=>({key:e,label:s,onPress:t}))}:void 0,[v,k]),I=useContextMenu(w,{haptic:y,testID:g}),C=I.hostProps.onLongPress,R=!t||(m?.length??0)>0,V=i&&L?P[i]:"",D=useMemo(()=>S&&null==t?markdownToPlainText(s):s,[S,t,s]),$=[A,M,D,l?`${P.replyTo(l.author)}: ${l.text}`:"",V].filter(Boolean).join(", "),U=useRef(c);useEffect(()=>{U.current&&!c&&!u&&s&&announce(A?`${A}, ${D}`:D),U.current=c},[c,u,s,D,A]);const z=useRef(u);useEffect(()=>{u&&u!==z.current&&announce(u,{polite:!1}),z.current=u},[u]);const H=useCallback(e=>{C?.(e),p?.()},[C,p]),O=useCallback(e=>{k.find(s=>s.name===e.nativeEvent.actionName)?.onPress()},[k]),F=T.radius.xl,G=T.radius.sm,N=L?{borderTopRightRadius:_?F:G,borderBottomRightRadius:B?F:G}:{borderTopLeftRadius:_?F:G,borderBottomLeftRadius:B?F:G},W=t??(S?_jsx(Markdown,{children:s}):_jsx(Text,{variant:"body",children:s})),q=l?_jsxs(Pressable,{onPress:l.onPress,disabled:!l.onPress,accessibilityRole:l.onPress?"button":void 0,accessibilityLabel:`${P.replyTo(l.author)}: ${l.text}`,style:j.quote,children:[l.author?_jsx(Text,{variant:"caption",weight:"semibold",color:"link",numberOfLines:1,children:l.author}):null,_jsx(Text,{variant:"bodySmall",color:"secondary",numberOfLines:2,children:l.text})]}):null,X=[j.bubble,L?j.mine:j.theirs,N],Y=R?{accessible:!0,accessibilityLabel:$,accessibilityState:{busy:c},"aria-busy":c,accessibilityActions:k.map(({name:e,label:s})=>({name:e,label:s})),onAccessibilityAction:O}:{accessible:!1},J=v?_jsxs(Pressable,{ref:I.hostRef,...I.hostProps,onLongPress:H,delayLongPress:350,style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}):_jsxs(View,{style:X,testID:g?`${g}-bubble`:void 0,...Y,children:[q,W]}),K=B&&(""!==M||L&&i);return _jsxs(View,{style:[j.root,L?j.rootMine:j.rootTheirs,{marginTop:_?T.space.sm:T.space.xxs},h],accessibilityState:{busy:c},"aria-busy":c,testID:g,children:[!L&&_&&n?_jsx(Text,{variant:"caption",color:"secondary",style:j.author,numberOfLines:1,importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,..."web"===Platform.OS?{"aria-hidden":!0}:null,children:n}):null,J,I.renderSurface(),K?_jsxs(View,{style:[j.meta,L?j.metaMine:null],importantForAccessibility:R?"no-hide-descendants":"auto",accessibilityElementsHidden:R,children:[M?_jsx(Text,{variant:"caption",color:"tertiary",children:M}):null,L&&i?_jsx(AppIcon,{name:statusIcon(i),size:14,color:statusColour(T,i),accessibilityLabel:P[i],testID:g?`${g}-status-${i}`:void 0}):null]}):null,u?_jsx(Text,{variant:"bodySmall",color:"danger",style:L?j.endText:null,children:u}):null,E?_jsx(Button,{label:P.retry,variant:"link",size:"sm",leftIcon:"refresh-cw",onPress:d,testID:g?`${g}-retry`:void 0}):null,x]})};const buildStyles=e=>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,...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"}});export default MessageBubble;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{assertValidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:A="center",testID:y,bare:x=!1,onInsetsChange:M}=e,C=useTheme(),w=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),D=usePresenceMotion(),[R,V]=useModalInsets();useEffect(()=>{M?.(R)},[R,M]);const{width:j,height:E}=useWindowDimensions(),[T,_]=useState({width:0,height:0}),L=a??D.duration("default"),N=Dimensions.get("window").height,H=useRef(!l&&o),I=H.current,P=useRef(createAnimatedValue(I?1:.9)).current,k=useRef(createAnimatedValue(I?1:0)).current,O=useRef(createAnimatedValue(I?0:N)).current,z=useRef(createAnimatedValue(I?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(C),[C]),K=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:R.top,bottom:R.bottom,left:0,right:0}},t=computePlacement(v,T,e,S,{align:A});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,T,S,A,j,E,R.top,R.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&H.current)H.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:D.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),D.reduced||"anchored"===i){k.setValue(0),O.setValue(0),P.setValue(1);const t=Animated.timing(k,{toValue:1,duration:L,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){k.setValue(1);const t=Animated.spring(O,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(P,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(k,{toValue:1,duration:L,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(F){const t=D.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(k,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=D.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(O,{toValue:N,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(P,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(z,{toValue:0,duration:D.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(O.setValue(N),B(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,F,i,L,P,k,z,O,N,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,D,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const J=useRef(h);J.current=h;const Q=useRef(!1);useEffect(()=>{if(o)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),300);return()=>clearTimeout(e)},[o]);const X=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),$=useSquircle(!x&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),ee=useCallback(e=>{$.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[$.onLayout]),te=useMemo(()=>x?"bottom"===i?U.bottomContent:"fullScreen"===i?U.fullScreenContent:U.bareCentredContent:"anchored"===i?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[U.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[U.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+R.bottom},C.shadow.modal]:[U.centeredContent,{backgroundColor:C.colors.surface,borderRadius:$.active&&$.size?squircleHostRadius($.size.width,$.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,U,R.bottom,$.active,$.size,K,x]),oe=useMemo(()=>"anchored"===i?U.anchoredWrapper:"bottom"===i?U.bottomWrapper:"fullScreen"===i?U.fullScreenWrapper:U.centeredWrapper,[i,U]),re=useMemo(()=>"bottom"===i?{opacity:k,transform:[{translateY:O}]}:"fullScreen"===i||"anchored"===i?{opacity:k}:{opacity:k,transform:[{scale:P}]},[i,P,k,O]);if("anchored"===i&&void 0===v)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 _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:y,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:V,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:X,accessibilityRole:n?"button":void 0,accessibilityLabel:n?w.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n}),_jsxs(Animated.View,{style:[te,re,T.height>0||"anchored"!==i?null:U.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?_jsx(SquircleFill,{width:$.size.width,height:$.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>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"}});export{Modal};export default Modal;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{assertValidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:A="center",testID:y,bare:x=!1,onInsetsChange:M}=e,C=useTheme(),w=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),D=usePresenceMotion(),[R,V]=useModalInsets();useEffect(()=>{M?.(R)},[R,M]);const{width:j,height:E}=useWindowDimensions(),[T,_]=useState({width:0,height:0}),L=a??D.duration("default"),I=Dimensions.get("window").height,N=useRef(!l&&o),k=N.current,H=useRef(createAnimatedValue(k?1:.9)).current,P=useRef(createAnimatedValue(k?1:0)).current,O=useRef(createAnimatedValue(k?0:I)).current,z=useRef(createAnimatedValue(k?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(C),[C]),K=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:R.top,bottom:R.bottom,left:0,right:0}},t=computePlacement(v,T,e,S,{align:A});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,T,S,A,j,E,R.top,R.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&N.current)N.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:D.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),D.reduced||"anchored"===i){P.setValue(0),O.setValue(0),H.setValue(1);const t=Animated.timing(P,{toValue:1,duration:L,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){P.setValue(1);const t=Animated.spring(O,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(H,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:1,duration:L,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(F){const t=D.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(P,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=D.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(O,{toValue:I,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(H,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(z,{toValue:0,duration:D.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(O.setValue(I),B(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,F,i,L,H,P,z,O,I,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,D,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const $=useRef(h);$.current=h;const J=useRef(!1);useEffect(()=>{if(o)return void(J.current=!0);if(!J.current)return;J.current=!1;const e=setTimeout(()=>$.current?.(),300);return()=>clearTimeout(e)},[o]);const Q=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),X=useCallback(()=>{u&&r()},[u,r]),Z=useSquircle(!x&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),ee=useCallback(e=>{Z.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[Z.onLayout]),te=useMemo(()=>x?"bottom"===i?U.bottomContent:"fullScreen"===i?U.fullScreenContent:U.bareCentredContent:"anchored"===i?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[U.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[U.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+R.bottom},C.shadow.modal]:[U.centeredContent,{backgroundColor:C.colors.surface,borderRadius:Z.active&&Z.size?squircleHostRadius(Z.size.width,Z.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,U,R.bottom,Z.active,Z.size,K,x]),oe=useMemo(()=>"anchored"===i?U.anchoredWrapper:"bottom"===i?U.bottomWrapper:"fullScreen"===i?U.fullScreenWrapper:U.centeredWrapper,[i,U]),re=useMemo(()=>"bottom"===i?{opacity:P,transform:[{translateY:O}]}:"fullScreen"===i||"anchored"===i?{opacity:P}:{opacity:P,transform:[{scale:H}]},[i,H,P,O]);if("anchored"===i&&void 0===v)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 _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:X,testID:y,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:V,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:Q,accessibilityRole:n?"button":void 0,accessibilityLabel:n?w.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n,testID:y?`${y}-backdrop`:void 0}),_jsxs(Animated.View,{style:[te,re,T.height>0||"anchored"!==i?null:U.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[Z.active&&Z.size?_jsx(SquircleFill,{width:Z.size.width,height:Z.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>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"}});export{Modal};export default Modal;
@@ -1 +1 @@
1
- "use strict";import React,{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"];export const DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"});const 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=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:l,min:r=Number.NEGATIVE_INFINITY,max:a=Number.POSITIVE_INFINITY,step:n=1,allowDecimal:o=!1,precision:c=0,label:u,help:d,helperText:b,error:m,disabled:p=!1,size:f="md",variant:x="inline",unit:h,haptic:y,labels:S,accessibilityLabel:T,style:N,containerStyle:g,inputStyle:I,buttonStyle:_,unitStyle:F,labelStyle:j,textInputProps:E,testID:V}=e;assertValidValue("NumberInput","size",e.size,NUMBER_INPUT_SIZES),assertValidValue("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const R=useMemo(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...S}),[S]),[v,C]=useControllableState({value:i,defaultValue:s??e.min??0,onChange:l}),L=useTheme(),P=resolveFieldSize(L,f),z=resolveFieldTextStyle(L,{disabled:p}),A=useMemo(()=>buildStyles(L),[L]),w=useRef(null),[U,k]=useState(formatValue(v,o,c)),[M,B]=useState(!1),[D,H]=useState(!1),O=useCallback(()=>{p||w.current?.focus()},[p]),G=useRef(null),W=useRef(null),Y=useCallback(()=>{null!==G.current&&(clearTimeout(G.current),G.current=null),null!==W.current&&(clearInterval(W.current),W.current=null)},[]);useEffect(()=>Y,[Y]),useEffect(()=>{M||k(formatValue(v,o,c))},[v,o,c,M]);const Z=v<=r,$=v>=a,q=!p,J=useCallback(e=>{const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==v&&C(i)},[o,a,r,C,c,v]),K=useCallback(()=>{if(!q||Z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(v-n)},[Z,q,y,J,n,v]),Q=useCallback(()=>{if(!q||$)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(v+n)},[$,q,y,J,n,v]);React.useImperativeHandle(t,()=>({focus:()=>w.current?.focus(),blur:()=>w.current?.blur(),clear:()=>{k(""),Number.isFinite(r)&&r>0?C(r):C(0<r?r:Math.min(a,0))}}),[a,r,C]);const X=useCallback(e=>{q&&(Y(),G.current=setTimeout(()=>{W.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[Y,K,Q,q]),ee=useCallback(e=>{const t=sanitizeTyped(e,o);k(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=r&&i<=a&&i!==v&&C(roundToPrecision(i,o?c:0))},[o,a,r,C,c,v]),te=useCallback(()=>{B(!1),H(!1);const e=Number(U);if(""===U||!Number.isFinite(e))return void k(formatValue(v,o,c));const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==v&&C(i),k(formatValue(i,o,c))},[o,U,a,r,C,c,v]),ie=useCallback(()=>{B(!0),H(!0)},[]),se=Z||p?L.colors["text-disabled"]:L.colors["text-body"],le=$||p?L.colors["text-disabled"]:L.colors["text-body"],re=P.icon+8,renderStepper=(e,t,i,s,l,r)=>_jsx(Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:Y,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:re,height:re,alignItems:"center",justifyContent:"center",borderRadius:L.radius.pill,...smoothCorners},e&&!i?{backgroundColor:L.colors["surface-pressed"]}:null,_],testID:`${V??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:_jsx(Text,{variant:"body",weight:"semibold",style:{fontSize:P.icon,color:l,fontWeight:L.weight.semibold,lineHeight:P.icon+2},children:r})}),ae=T??fieldTextAsString(u)??R.input,ne=!0===m||hasFieldText(m),oe=_jsx(FieldBase,{size:f,disabled:p,error:ne,filled:!0,focused:D,onPress:O,pressFeedback:!1,leading:renderStepper("dec",K,Z||p,R.decrease,se,"−"),trailing:renderStepper("inc",Q,$||p,R.increase,le,"+"),children:_jsxs(View,{style:A.inputRow,children:[_jsx(TextInput,{ref:w,value:U,onChangeText:ee,onFocus:ie,onBlur:te,editable:!p,keyboardType:o?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ae,accessibilityValue:{now:Number.isFinite(v)?v:0},accessibilityState:{disabled:p},"aria-disabled":p,accessibilityActions:[{name:"increment",label:R.increase},{name:"decrement",label:R.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[A.input,{fontSize:P.text,color:z.color,...z.weightStyle},I],...E}),h?_jsx(Text,{variant:"bodySmall",style:[A.unit,{fontSize:P.text,color:z.placeholderColor},F],children:h}):null]})}),ce=hasFieldText(u)?_jsx(FieldLabel,{size:f,help:d,style:j,children:u}):null,ue=_jsx(FieldMessage,{size:f,error:ne,text:ne?m:b});return _jsxs(View,"horizontal"===x?{style:[A.horizontalContainer,g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[_jsx(View,{style:A.horizontalLabelWrap,children:ce}),_jsxs(View,{children:[oe,ue]})]}:{style:[g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[ce,oe,ue]})});NumberInput.displayName="NumberInput";const buildStyles=e=>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}});export{NumberInput};export default NumberInput;
1
+ "use strict";import React,{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const NUMBER_INPUT_SIZES=["sm","md","lg"],NUMBER_INPUT_VARIANTS=["inline","horizontal"];export const DEFAULT_NUMBER_INPUT_LABELS=Object.freeze({decrease:"Decrease",increase:"Increase",input:"Number input"});const 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=forwardRef((e,t)=>{const{value:i,defaultValue:s,onChange:l,min:r=Number.NEGATIVE_INFINITY,max:a=Number.POSITIVE_INFINITY,step:n=1,allowDecimal:o=!1,precision:c=0,label:u,help:d,helperText:b,error:m,disabled:p=!1,size:f="md",variant:x="inline",unit:h,haptic:y,labels:S,accessibilityLabel:T,style:N,containerStyle:g,inputStyle:I,buttonStyle:_,unitStyle:F,labelStyle:j,textInputProps:E,testID:V}=e;assertValidValue("NumberInput","size",e.size,NUMBER_INPUT_SIZES),assertValidValue("NumberInput","variant",e.variant,NUMBER_INPUT_VARIANTS);const v=useMemo(()=>({...DEFAULT_NUMBER_INPUT_LABELS,...S}),[S]),[R,C]=useControllableState({value:i,defaultValue:s??e.min??0,onChange:l}),L=useTheme(),P=resolveFieldSize(L,f),z=resolveFieldTextStyle(L,{disabled:p}),A=useMemo(()=>buildStyles(L),[L]),w=useRef(null),[U,k]=useState(formatValue(R,o,c)),[M,B]=useState(!1),[D,H]=useState(!1),O=useCallback(()=>{p||w.current?.focus()},[p]),G=useRef(null),W=useRef(null),Y=useCallback(()=>{null!==G.current&&(clearTimeout(G.current),G.current=null),null!==W.current&&(clearInterval(W.current),W.current=null)},[]);useEffect(()=>Y,[Y]),useEffect(()=>{M||k(formatValue(R,o,c))},[R,o,c,M]);const $=R<=r,Z=R>=a,q=!p,J=useCallback(e=>{const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==R&&C(i)},[o,a,r,C,c,R]),K=useCallback(()=>{if(!q||$)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(R-n)},[$,q,y,J,n,R]),Q=useCallback(()=>{if(!q||Z)return;const e=resolveHaptic(y,"selection");e&&triggerHaptic(e),J(R+n)},[Z,q,y,J,n,R]);React.useImperativeHandle(t,()=>({focus:()=>w.current?.focus(),blur:()=>w.current?.blur(),clear:()=>{k(""),Number.isFinite(r)&&r>0?C(r):C(0<r?r:Math.min(a,0))}}),[a,r,C]);const X=useCallback(e=>{q&&(Y(),G.current=setTimeout(()=>{W.current=setInterval(()=>{"inc"===e?Q():K()},80)},500))},[Y,K,Q,q]),ee=useCallback(e=>{const t=sanitizeTyped(e,o);k(t);const i=Number(t);""!==t&&"-"!==t&&"."!==t&&Number.isFinite(i)&&i>=r&&i<=a&&i!==R&&C(roundToPrecision(i,o?c:0))},[o,a,r,C,c,R]),te=useCallback(()=>{B(!1),H(!1);const e=Number(U);if(""===U||!Number.isFinite(e))return void k(formatValue(R,o,c));const t=roundToPrecision(e,o?c:0),i=clamp(t,r,a);i!==R&&C(i),k(formatValue(i,o,c))},[o,U,a,r,C,c,R]),ie=useCallback(()=>{B(!0),H(!0)},[]),se=$||p?L.colors["text-disabled"]:L.colors["text-body"],le=Z||p?L.colors["text-disabled"]:L.colors["text-body"],re=P.icon+8,renderStepper=(e,t,i,s,l,r)=>_jsx(Pressable,{onPress:t,onLongPress:()=>X(e),onPressOut:Y,delayLongPress:500,disabled:i,accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{disabled:i},"aria-disabled":i,style:({pressed:e})=>[{width:re,height:re,alignItems:"center",justifyContent:"center",borderRadius:L.radius.pill,...smoothCorners},e&&!i?{backgroundColor:L.colors["surface-pressed"]}:null,_],testID:`${V??"numberinput"}-${"inc"===e?"plus":"minus"}`,children:_jsx(Text,{variant:"body",weight:"semibold",style:{fontSize:P.icon,color:l,fontWeight:L.weight.semibold,lineHeight:P.icon+2},children:r})}),ae=T??fieldTextAsString(u)??v.input,ne=!0===m||hasFieldText(m),oe=_jsx(FieldBase,{testID:V?`${V}-field`:void 0,size:f,disabled:p,error:ne,filled:!0,focused:D,onPress:O,pressFeedback:!1,leading:renderStepper("dec",K,$||p,v.decrease,se,"−"),trailing:renderStepper("inc",Q,Z||p,v.increase,le,"+"),children:_jsxs(View,{style:A.inputRow,children:[_jsx(TextInput,{ref:w,value:U,onChangeText:ee,onFocus:ie,onBlur:te,editable:!p,keyboardType:o?"decimal-pad":"number-pad",selectTextOnFocus:!0,accessibilityRole:"adjustable",accessibilityLabel:ae,accessibilityValue:{now:Number.isFinite(R)?R:0},accessibilityState:{disabled:p},"aria-disabled":p,accessibilityActions:[{name:"increment",label:v.increase},{name:"decrement",label:v.decrease}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName&&Q(),"decrement"===e.nativeEvent.actionName&&K()},style:[A.input,{fontSize:P.text,color:z.color,...z.weightStyle},I],...E}),h?_jsx(Text,{variant:"bodySmall",style:[A.unit,{fontSize:P.text,color:z.placeholderColor},F],children:h}):null]})}),ce=hasFieldText(u)?_jsx(FieldLabel,{size:f,help:d,style:j,children:u}):null,ue=_jsx(FieldMessage,{size:f,error:ne,text:ne?m:b});return _jsxs(View,"horizontal"===x?{style:[A.horizontalContainer,g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[_jsx(View,{style:A.horizontalLabelWrap,children:ce}),_jsxs(View,{children:[oe,ue]})]}:{style:[g,N],testID:V,accessibilityState:{disabled:p},"aria-disabled":p,children:[ce,oe,ue]})});NumberInput.displayName="NumberInput";const buildStyles=e=>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}});export{NumberInput};export default NumberInput;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionAction,selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const 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}`});const hostStyle=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:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,getOptionAction:g,value:b,onChange:x,multi:y=!1,searchable:f=!1,searchSelectionColor:S,accessibilityLabel:T,optionStyle:j,selectedOptionStyle:w,optionTextStyle:C,selectedOptionTextStyle:_,testID:k}=e,L=c??selectOptionLabel,O=d??selectOptionValue,I=p??selectOptionDescription,R=u??selectOptionDisabled,V=h??selectOptionIcon,D=g??selectOptionAction,v=useTheme(),P=useSafeAreaInsets(),H=useMemo(()=>buildStyles(v),[v]),[M,A]=useState(""),B=Dimensions.get("window").height,z=Math.round(.7*B),E=useRef(createAnimatedValue(0)).current,{handleGesture:F,opacity:W}=useDragToDismiss({drag:E,travel:z,onDismiss:t}),N=useNativeGesture(),G=useKeyboardState(e=>e.height),U=Math.max(0,Math.round(G)),$=Math.max(P.top,StatusBar.currentHeight??0)+v.space.sm,J=U>0,K=J?Math.max(0,Math.min(z,B-U-$)):z,Y=useMemo(()=>{const e=f?M.trim().toLowerCase():"",matches=t=>0===e.length||L(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{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:o})}}),t},[f,M,s,i,L,I]),Z=useCallback(()=>{t()},[t]),Q=useRef(null),X=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of Y.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of Y.entries()){if(o<t||"option"!==s.kind)continue;const i=L(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,Y,i,L]),q=n&&X.size>0&&0===M.trim().length,ee=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...X.has("#")?["#"]:[]],[X]),te=useCallback(e=>{const t=X.get(e);void 0!==t&&Q.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[X]),oe=useRef(null),se=useCallback(()=>{null!==oe.current&&(clearTimeout(oe.current),oe.current=null)},[]),ie=useCallback(e=>{Q.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),oe.current=setTimeout(()=>{oe.current=null,Q.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);useEffect(()=>se,[se]);return _jsx(GestureHandlerRootView,{style:H.gestureRoot,children:_jsxs(Animated.View,{testID:k,accessibilityViewIsModal:!0,accessibilityLabel:T??o??a.fallbackName,style:[H.sheet,{maxHeight:K,marginBottom:U,paddingBottom:J?v.space.lg:P.bottom+v.space.lg,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,opacity:W,transform:[{translateY:E}],...v.shadow.modal}],children:[_jsx(GestureDetector,{gesture:F,children:_jsxs(View,{children:[_jsx(View,{style:H.sheetHandleRow,children:_jsx(View,{style:[H.sheetHandle,{backgroundColor:v.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[H.sheetTitle,{paddingHorizontal:v.space.lg,marginBottom:v.space.sm}],children:o}):null]})}),f?_jsx(View,{style:[H.searchWrap,{marginHorizontal:v.space.lg,marginBottom:v.space.sm}],children:_jsxs(View,{style:[H.searchBox,{backgroundColor:v.colors["bg-subtle"],borderColor:v.colors.border,borderRadius:v.radius.md,...smoothCorners,paddingHorizontal:v.space.md,gap:v.space.sm}],children:[(v.settings.icons.search??defaultIcons.search)({size:18,color:v.colors["text-subtle"]}),_jsx(TextInput,{value:M,onChangeText:A,placeholder:a.searchPlaceholder,placeholderTextColor:v.colors["text-subtle"],selectionColor:S??v.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[H.searchInput,{color:v.colors["text-body"],fontSize:v.text.base.size,paddingVertical:v.space.sm}]}),M.length>0?_jsx(Pressable,{onPress:()=>A(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(v.settings.icons.close??defaultIcons.close)({size:18,color:v.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[H.listWrap,q?H.listRow:null],children:[_jsx(GestureDetector,{gesture:N,children:_jsx(FlatList,{ref:Q,data:Y,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(O(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[H.sectionHeader,{paddingHorizontal:v.space.lg,paddingTop:v.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:H.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=L(o),i=O(o),n=I(o),a=V(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=R(o),u=m?.(o)??!1,h=D(o);return _jsxs(Pressable,{onPress:()=>{if(h)return h(),void Z();x(i,o)},disabled:p,android_ripple:{color:v.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[H.optionRow,{backgroundColor:c?v.colors["surface-selected"]:e?v.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:v.space.lg,paddingVertical:v.space.md},j,c?w:null],children:[l?_jsx(View,{style:H.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:H.optionIcon,children:a}):null,_jsxs(View,{style:H.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[H.optionLabel,C,c?_:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:H.optionDescription,children:n}):null]})]}),y?_jsx(View,{style:[H.checkbox,{borderColor:c?v.colors.primary:v.colors.border,backgroundColor:c?v.colors.primary:"transparent"}],children:c?_jsx(View,{style:H.checkboxTick}):null}):c?"icon"===v.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:H.singleSelectedIcon,children:(v.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:v.colors.primary})}):_jsx(View,{style:[H.singleSelectedDot,{backgroundColor:v.colors.primary}]}):null]})},onScrollToIndexFailed:ie,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!q,style:q?H.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:v.space.xl},children:a.empty})})}),q?_jsx(View,{style:[H.rail,{paddingRight:v.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=X.has(e);return _jsx(Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:H.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[H.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),y?_jsx(View,{style:[H.sheetFooter,{borderTopColor:v.colors["border-subtle"],paddingHorizontal:v.space.lg,paddingVertical:v.space.md}],children:_jsx(Pressable,{onPress:Z,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[H.doneButton,{backgroundColor:e?v.colors["primary-pressed"]:v.colors.primary,borderRadius:v.radius.md,...smoothCorners,paddingVertical:v.space.sm,paddingHorizontal:v.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:v.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>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,...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,...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,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{GestureDetector,GestureHandlerRootView,useNativeGesture}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{selectOptionAction,selectOptionDescription,selectOptionDisabled,selectOptionIcon,selectOptionLabel,selectOptionValue}from"./optionAccessors.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const 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}`});const hostStyle=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:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,getOptionAction:g,value:b,onChange:x,multi:y=!1,searchable:f=!1,searchSelectionColor:S,accessibilityLabel:T,optionStyle:j,selectedOptionStyle:w,optionTextStyle:C,selectedOptionTextStyle:_,testID:k}=e,I=c??selectOptionLabel,L=d??selectOptionValue,O=p??selectOptionDescription,R=u??selectOptionDisabled,D=h??selectOptionIcon,V=g??selectOptionAction,v=useTheme(),P=useSafeAreaInsets(),H=useMemo(()=>buildStyles(v),[v]),[M,A]=useState(""),B=Dimensions.get("window").height,z=Math.round(.7*B),E=useRef(createAnimatedValue(0)).current,{handleGesture:F,opacity:W}=useDragToDismiss({drag:E,travel:z,onDismiss:t,testID:k}),N=useNativeGesture(),G=useKeyboardState(e=>e.height),U=Math.max(0,Math.round(G)),$=Math.max(P.top,StatusBar.currentHeight??0)+v.space.sm,J=U>0,K=J?Math.max(0,Math.min(z,B-U-$)):z,Y=useMemo(()=>{const e=f?M.trim().toLowerCase():"",matches=t=>0===e.length||I(t).toLowerCase().includes(e)||(O(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{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:o})}}),t},[f,M,s,i,I,O]),Z=useCallback(()=>{t()},[t]),Q=useRef(null),X=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of Y.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of Y.entries()){if(o<t||"option"!==s.kind)continue;const i=I(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,Y,i,I]),q=n&&X.size>0&&0===M.trim().length,ee=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...X.has("#")?["#"]:[]],[X]),te=useCallback(e=>{const t=X.get(e);void 0!==t&&Q.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[X]),oe=useRef(null),se=useCallback(()=>{null!==oe.current&&(clearTimeout(oe.current),oe.current=null)},[]),ie=useCallback(e=>{Q.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),se(),oe.current=setTimeout(()=>{oe.current=null,Q.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[se]);useEffect(()=>se,[se]);return _jsx(GestureHandlerRootView,{style:H.gestureRoot,children:_jsxs(Animated.View,{testID:k,accessibilityViewIsModal:!0,accessibilityLabel:T??o??a.fallbackName,style:[H.sheet,{maxHeight:K,marginBottom:U,paddingBottom:J?v.space.lg:P.bottom+v.space.lg,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,opacity:W,transform:[{translateY:E}],...v.shadow.modal}],children:[_jsx(GestureDetector,{gesture:F,children:_jsxs(View,{children:[_jsx(View,{style:H.sheetHandleRow,children:_jsx(View,{style:[H.sheetHandle,{backgroundColor:v.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[H.sheetTitle,{paddingHorizontal:v.space.lg,marginBottom:v.space.sm}],children:o}):null]})}),f?_jsx(View,{style:[H.searchWrap,{marginHorizontal:v.space.lg,marginBottom:v.space.sm}],children:_jsxs(View,{style:[H.searchBox,{backgroundColor:v.colors["bg-subtle"],borderColor:v.colors.border,borderRadius:v.radius.md,...smoothCorners,paddingHorizontal:v.space.md,gap:v.space.sm}],children:[(v.settings.icons.search??defaultIcons.search)({size:18,color:v.colors["text-subtle"]}),_jsx(TextInput,{value:M,onChangeText:A,placeholder:a.searchPlaceholder,placeholderTextColor:v.colors["text-subtle"],selectionColor:S??v.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[H.searchInput,{color:v.colors["text-body"],fontSize:v.text.base.size,paddingVertical:v.space.sm}]}),M.length>0?_jsx(Pressable,{onPress:()=>A(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(v.settings.icons.close??defaultIcons.close)({size:18,color:v.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[H.listWrap,q?H.listRow:null],children:[_jsx(GestureDetector,{gesture:N,children:_jsx(FlatList,{ref:Q,data:Y,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[H.sectionHeader,{paddingHorizontal:v.space.lg,paddingTop:v.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:H.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=I(o),i=L(o),n=O(o),a=D(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=R(o),u=m?.(o)??!1,h=V(o);return _jsxs(Pressable,{onPress:()=>{if(h)return h(),void Z();x(i,o)},disabled:p,android_ripple:{color:v.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[H.optionRow,{backgroundColor:c?v.colors["surface-selected"]:e?v.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:v.space.lg,paddingVertical:v.space.md},j,c?w:null],children:[l?_jsx(View,{style:H.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:H.optionIcon,children:a}):null,_jsxs(View,{style:H.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[H.optionLabel,C,c?_:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:H.optionDescription,children:n}):null]})]}),y?_jsx(View,{style:[H.checkbox,{borderColor:c?v.colors.primary:v.colors.border,backgroundColor:c?v.colors.primary:"transparent"}],children:c?_jsx(View,{style:H.checkboxTick}):null}):c?"icon"===v.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:H.singleSelectedIcon,children:(v.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:v.colors.primary})}):_jsx(View,{style:[H.singleSelectedDot,{backgroundColor:v.colors.primary}]}):null]})},onScrollToIndexFailed:ie,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!q,style:q?H.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:v.space.xl},children:a.empty})})}),q?_jsx(View,{style:[H.rail,{paddingRight:v.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:ee.map(e=>{const t=X.has(e);return _jsx(Pressable,{onPress:()=>te(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:H.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[H.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),y?_jsx(View,{style:[H.sheetFooter,{borderTopColor:v.colors["border-subtle"],paddingHorizontal:v.space.lg,paddingVertical:v.space.md}],children:_jsx(Pressable,{onPress:Z,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[H.doneButton,{backgroundColor:e?v.colors["primary-pressed"]:v.colors.primary,borderRadius:v.radius.md,...smoothCorners,paddingVertical:v.space.sm,paddingHorizontal:v.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:v.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>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,...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,...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,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
@@ -1 +1 @@
1
- "use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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}`});export const 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"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const i=e.replace(/[^0-9]/g,"");if(!i)return null;const n=splitPhoneNumber(`+${i}`);let l=n?.callingCode,r=n?.nationalNumber??"";if(!l){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(l=e.find(e=>i.startsWith(e)),!l)return null;r=i.slice(l.length)}const a=t.filter(e=>e.code===l),s=a.find(e=>e.iso===o)?.iso??a.find(e=>e.iso===n?.country)?.iso??n?.country??a[0]?.iso??"";return{callingCode:l,nationalNumber:r,iso:s}};const planOf=e=>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.`)};export const PhoneNumberInput=forwardRef((e,t)=>{const{value:o,defaultValue:i,onChange:n,e164:l,onChangeE164:r,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:p=ALL_CALLING_CODES,popularCountries:m,hiddenCountries:b,showFlag:f=!0,renderFlag:h,renderCountry:g,showAlphabetIndex:y,defaultCountry:N,validation:C="any",maxLength:x,formatAsYouType:S=!0,countryLocked:v=!1,label:E,labelMode:T="top",labelStyle:F,placeholder:P,helperText:I,error:L,invalidMessage:_,required:j,disabled:A=!1,size:O="md",variant:V,radius:M,labels:w,haptic:B,accessibilityLabel:D,countryAccessibilityLabel:U,onFocus:k,onBlur:z,style:R,testID:$}=e;assertValidValue("PhoneNumberInput","size",e.size,["sm","md","lg"]),assertValidValue("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),assertValidValue("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),assertValidValue("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const H=useTheme(),W=useMemo(()=>buildStyles(H),[H]),q=useRef(null),G=useMemo(()=>w?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...w}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[w]),Y=P??G.placeholder,K=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),Z=useMemo(()=>b?.length?p.filter(e=>!b.includes(e.iso)):p,[p,b]),J=useMemo(()=>{if(!m?.length)return;const e=m.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:G.popular,options:e},{title:G.allCountries,options:Z}]:void 0},[m,G.popular,G.allCountries,Z]),Q=useCallback((e,t,o)=>{if(!e)return null;if(h)return h(e);if(!f)return null;const i=countryFlagEmoji(e.iso);return i?_jsx(Text,{variant:"body",style:[W.flag,{fontSize:t}],testID:o,children:i}):null},[h,f,W.flag]),X=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return x?Math.min(o,x):o},[x,C]),ee=useCallback((e,t)=>e.slice(0,X(t)),[X]),te=useCallback((e,t)=>{const o=planOf(t)??void 0,i=splitPhoneNumber(e,o);if(!i)return null;const n=i.country??t,l=p.find(e=>e.iso===n);return{callingCode:l?.code??i.callingCode,nationalNumber:ee(i.nationalNumber,n),iso:l?.iso??n}},[p,ee]);useState(()=>assertDefaultCountryVisible(N,Z));const oe=useMemo(()=>{const e=Z.find(e=>e.iso===(N??K))??Z[0]??p[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof i?te(i,t.iso)??t:i??t},[p,Z,N,K,i,te]),ie=useCallback(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,le]=useState(oe.iso),re=useMemo(()=>{if(void 0===l)return;const e=l?parseE164(l,p,ne):null;if(e)return{...e,nationalNumber:ee(e.nationalNumber,e.iso)};const t=p.find(e=>e.iso===ne);return{callingCode:t?.code??oe.callingCode,nationalNumber:"",iso:ne}},[l,p,ne,oe.callingCode,ee]),ae=useCallback(e=>{le(e.iso),n?.(e),r?.(e.nationalNumber?formatE164(e):"",{country:p.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ie(e)})},[n,r,p,ie]),[se,ue]=useControllableState({value:o??re,defaultValue:oe,onChange:ae}),[de,ce]=useState(!1),pe=useCallback(()=>{A||q.current?.focus()},[A]),[me,be]=useState(!1),[fe,he]=useState(!1),[ge,ye]=useState(!1),Ne=useRef(!1);useEffect(()=>{ge||(Ne.current=!1)},[ge]);const Ce=resolveFieldSize(H,O),xe=resolveFieldTextStyle(H,{disabled:A}),Se=V??H.settings.components.field?.defaultVariant??"outline",ve="underline"===Se,Ee=H.space.md,[Te,Fe]=useState(0),Pe=Te+Ee+1+Ee,Ie=se.nationalNumber.length>0,Le=j&&!E&&!Ie&&Y.length>0,je=de||Ie,Ae=Boolean(E)&&"float"===T&&Te>0,Oe=useFloatingLabel({label:E,enabled:Ae,floated:je,required:j,variant:Se,sizeTokens:Ce,leadingOffset:Pe,paddingLeft:ve?H.space.none:Ce["padding-x"],color:H.colors["field-label"],style:F}),Ve=useMemo(()=>p.find(e=>e.iso===se.iso),[p,se.iso]),Me=planOf(se.iso),we=S&&Me?formatPhoneAsTyped(se.nationalNumber,Me):se.nationalNumber,Be=X(se.iso),De=0===se.nationalNumber.length||me||!Number.isFinite(Be)?void 0:we.length+Math.max(0,Be-se.nationalNumber.length),Ue=ie(se);useEffect(()=>{Ie||he(!1)},[Ie]);const ke=Me?maxNationalNumberLength(Me,!1===C?"any":C):Number.POSITIVE_INFINITY,ze=se.nationalNumber.length>=ke,Re=!1!==C&&!1!==_&&Ie&&!Ue&&(fe||ze),$e="mobile"===C?G.invalidMobile:G.invalid,He=hasFieldText(L)?L:Re?_||$e:void 0,We=!0===L||hasFieldText(He),qe=useRef(Ue),Ge=useRef(se);Ge.current=se,useEffect(()=>{qe.current!==Ue&&(qe.current=Ue,c?.(Ue),Ue&&d?.(formatE164(Ge.current)))},[Ue,d,c]);const Ye=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=useCallback(e=>{ue({callingCode:e.code,iso:e.iso,nationalNumber:ee(se.nationalNumber,e.iso)}),ye(!1);const t=resolveHaptic(B,"selection");t&&triggerHaptic(t)},[se,B,ee,ue]);useImperativeHandle(t,()=>({focus:()=>q.current?.focus(),blur:()=>q.current?.blur(),clear:()=>ue({...Ge.current,nationalNumber:""}),isFocused:()=>q.current?.isFocused()??!1,getValue:()=>Ge.current,getE164:()=>formatE164(Ge.current),getFormatted:()=>{const e=Ge.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>ie(Ge.current),getCountry:()=>p.find(e=>e.iso===Ge.current.iso)}),[p,ie,ue]);const Ze=A||v,Je=_jsx(FieldBase,{size:O,variant:Se,radius:M,topNotch:Oe.topNotch,focused:de,disabled:A,error:We,filled:Ie,onPress:pe,pressFeedback:!1,leadingDivider:!0,paddingLeft:ve?H.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Ze||(Ne.current=!0,ye(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:U??G.countryButton(se.callingCode),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Fe(e=>e===t?e:t)},style:W.codeTrigger,testID:$?`${$}-code`:void 0,children:[Q(Ve,Ce.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[W.codeText,{color:xe.color,fontSize:Ce.text}],children:`+${se.callingCode}`}),v?null:_jsx(Chevron,{color:A?H.colors["field-icon-disabled"]:H.colors["field-icon"],size:Ce.icon,open:ge})]}),children:_jsxs(View,{style:W.inputWrap,children:[_jsx(TextInput,{ref:q,value:we,maxLength:De,onChangeText:Ye,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;be(t!==o)},onFocus:()=>{ce(!0),k?.()},onBlur:()=>{ce(!1),Ie&&!Ne.current&&he(!0),z?.()},editable:!A,placeholder:Ae&&!je||Le?void 0:Y,placeholderTextColor:xe.placeholderColor,accessibilityLabel:D??E??Y,selectionColor:H.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[W.input,{color:xe.color,fontSize:Ce.text,...xe.weightStyle,paddingLeft:ve?H.space.none:void 0}],testID:$?`${$}-input`:void 0}),Le?_jsx(RequiredPlaceholder,{text:Y,color:xe.placeholderColor,fontSize:Ce.text,weightStyle:xe.weightStyle}):null]})});return _jsxs(View,{style:R,testID:$,children:[E&&"top"===T?_jsx(FieldLabel,{size:O,required:j,children:E}):null,_jsxs(View,{style:W.fieldWrapper,children:[Je,Oe.node]}),_jsx(FieldMessage,{size:O,error:We,text:We?He:I}),_jsx(OptionSheet,{open:ge,haptic:B,onClose:()=>ye(!1),title:G.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,H.text.lg.size),renderOption:g?({option:e,selected:t})=>g(e,{selected:t}):void 0,value:Ve?.iso,onChange:(e,t)=>Ke(t),searchable:Z.length>8,labels:{searchPlaceholder:G.countrySearchPlaceholder},alphabetIndex:y??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...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"}});export default PhoneNumberInput;
1
+ "use strict";import{countryFlagEmoji,formatPhoneAsTyped,getFormatterConfig,getPhoneCountries,isSupportedCountry,isValidNationalNumber,maxNationalNumberLength,splitPhoneNumber}from"@webority/mobile-core";import{PHONE_COUNTRY_NAMES}from"@webority/mobile-core/phone/countries";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{fontFor,resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/index.js";import{Chevron}from"../FieldBase/Chevron.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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}`});export const 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"}];export const ALL_CALLING_CODES=getPhoneCountries().map(e=>({iso:e.iso,code:e.callingCode,label:PHONE_COUNTRY_NAMES[e.iso]??e.iso})).sort((e,t)=>e.label.localeCompare(t.label));const digitsOnly=e=>e.replace(/[^0-9]/g,"");export const formatE164=e=>`+${e.callingCode}${e.nationalNumber}`;export const parseE164=(e,t,o)=>{const i=e.replace(/[^0-9]/g,"");if(!i)return null;const n=splitPhoneNumber(`+${i}`);let l=n?.callingCode,r=n?.nationalNumber??"";if(!l){const e=Array.from(new Set(t.map(e=>e.code))).sort((e,t)=>t.length-e.length);if(l=e.find(e=>i.startsWith(e)),!l)return null;r=i.slice(l.length)}const a=t.filter(e=>e.code===l),s=a.find(e=>e.iso===o)?.iso??a.find(e=>e.iso===n?.country)?.iso??n?.country??a[0]?.iso??"";return{callingCode:l,nationalNumber:r,iso:s}};const planOf=e=>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.`)};export const PhoneNumberInput=forwardRef((e,t)=>{const{value:o,defaultValue:i,onChange:n,e164:l,onChangeE164:r,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onComplete:d,onValidityChange:c,countries:p=ALL_CALLING_CODES,popularCountries:m,hiddenCountries:b,showFlag:f=!0,renderFlag:h,renderCountry:g,showAlphabetIndex:y,defaultCountry:N,validation:C="any",maxLength:x,formatAsYouType:v=!0,countryLocked:S=!1,label:E,labelMode:T="top",labelStyle:F,placeholder:I,helperText:P,error:L,invalidMessage:_,required:j,disabled:A=!1,size:O="md",variant:V,radius:M,labels:w,haptic:B,accessibilityLabel:D,countryAccessibilityLabel:U,onFocus:k,onBlur:z,style:R,testID:$}=e;assertValidValue("PhoneNumberInput","size",e.size,["sm","md","lg"]),assertValidValue("PhoneNumberInput","variant",e.variant,["outline","filled","underline"]),assertValidValue("PhoneNumberInput","labelMode",e.labelMode,["top","float"]),assertValidValue("PhoneNumberInput","validation",!1===e.validation?void 0:e.validation,["any","mobile"]);const H=useTheme(),W=useMemo(()=>buildStyles(H),[H]),q=useRef(null),G=useMemo(()=>w?{...DEFAULT_PHONE_NUMBER_INPUT_LABELS,...w}:DEFAULT_PHONE_NUMBER_INPUT_LABELS,[w]),Y=I??G.placeholder,K=useMemo(()=>/-([A-Za-z]{2})(?:-|$)/.exec(getFormatterConfig().locale)?.[1]?.toUpperCase(),[]),Z=useMemo(()=>b?.length?p.filter(e=>!b.includes(e.iso)):p,[p,b]),J=useMemo(()=>{if(!m?.length)return;const e=m.map(e=>Z.find(t=>t.iso===e)).filter(e=>void 0!==e);return e.length?[{title:G.popular,options:e},{title:G.allCountries,options:Z}]:void 0},[m,G.popular,G.allCountries,Z]),Q=useCallback((e,t,o)=>{if(!e)return null;if(h)return h(e);if(!f)return null;const i=countryFlagEmoji(e.iso);return i?_jsx(Text,{variant:"body",style:[W.flag,{fontSize:t}],testID:o,children:i}):null},[h,f,W.flag]),X=useCallback(e=>{const t=planOf(e),o=t?maxNationalNumberLength(t,!1===C?"any":C):Number.POSITIVE_INFINITY;return x?Math.min(o,x):o},[x,C]),ee=useCallback((e,t)=>e.slice(0,X(t)),[X]),te=useCallback((e,t)=>{const o=planOf(t)??void 0,i=splitPhoneNumber(e,o);if(!i)return null;const n=i.country??t,l=p.find(e=>e.iso===n);return{callingCode:l?.code??i.callingCode,nationalNumber:ee(i.nationalNumber,n),iso:l?.iso??n}},[p,ee]);useState(()=>assertDefaultCountryVisible(N,Z));const oe=useMemo(()=>{const e=Z.find(e=>e.iso===(N??K))??Z[0]??p[0],t={callingCode:e?.code??"",nationalNumber:"",iso:e?.iso??""};return"string"==typeof i?te(i,t.iso)??t:i??t},[p,Z,N,K,i,te]),ie=useCallback(e=>{if(!1===C)return e.nationalNumber.length>0;const t=planOf(e.iso);return t?isValidNationalNumber(e.nationalNumber,t,C):e.nationalNumber.length>0},[C]),[ne,le]=useState(oe.iso),re=useMemo(()=>{if(void 0===l)return;const e=l?parseE164(l,p,ne):null;if(e)return{...e,nationalNumber:ee(e.nationalNumber,e.iso)};const t=p.find(e=>e.iso===ne);return{callingCode:t?.code??oe.callingCode,nationalNumber:"",iso:ne}},[l,p,ne,oe.callingCode,ee]),ae=useCallback(e=>{le(e.iso),n?.(e),r?.(e.nationalNumber?formatE164(e):"",{country:p.find(t=>t.iso===e.iso),national:e.nationalNumber,valid:ie(e)})},[n,r,p,ie]),[se,ue]=useControllableState({value:o??re,defaultValue:oe,onChange:ae}),[de,ce]=useState(!1),pe=useCallback(()=>{A||q.current?.focus()},[A]),[me,be]=useState(!1),[fe,he]=useState(!1),[ge,ye]=useState(!1),Ne=useRef(!1);useEffect(()=>{ge||(Ne.current=!1)},[ge]);const Ce=resolveFieldSize(H,O),xe=resolveFieldTextStyle(H,{disabled:A}),ve=V??H.settings.components.field?.defaultVariant??"outline",Se="underline"===ve,Ee=H.space.md,[Te,Fe]=useState(0),Ie=Te+Ee+1+Ee,Pe=se.nationalNumber.length>0,Le=j&&!E&&!Pe&&Y.length>0,je=de||Pe,Ae=Boolean(E)&&"float"===T&&Te>0,Oe=useFloatingLabel({label:E,enabled:Ae,floated:je,required:j,variant:ve,sizeTokens:Ce,leadingOffset:Ie,paddingLeft:Se?H.space.none:Ce["padding-x"],color:H.colors["field-label"],style:F}),Ve=useMemo(()=>p.find(e=>e.iso===se.iso),[p,se.iso]),Me=planOf(se.iso),we=v&&Me?formatPhoneAsTyped(se.nationalNumber,Me):se.nationalNumber,Be=X(se.iso),De=0===se.nationalNumber.length||me||!Number.isFinite(Be)?void 0:we.length+Math.max(0,Be-se.nationalNumber.length),Ue=ie(se);useEffect(()=>{Pe||he(!1)},[Pe]);const ke=Me?maxNationalNumberLength(Me,!1===C?"any":C):Number.POSITIVE_INFINITY,ze=se.nationalNumber.length>=ke,Re=!1!==C&&!1!==_&&Pe&&!Ue&&(fe||ze),$e="mobile"===C?G.invalidMobile:G.invalid,He=hasFieldText(L)?L:Re?_||$e:void 0,We=!0===L||hasFieldText(He),qe=useRef(Ue),Ge=useRef(se);Ge.current=se,useEffect(()=>{qe.current!==Ue&&(qe.current=Ue,c?.(Ue),Ue&&d?.(formatE164(Ge.current)))},[Ue,d,c]);const Ye=useCallback(e=>{if(e.includes("+")){const t=te(e,se.iso);if(t&&!S&&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,S,se,te,ee,ue]),Ke=useCallback(e=>{ue({callingCode:e.code,iso:e.iso,nationalNumber:ee(se.nationalNumber,e.iso)}),ye(!1);const t=resolveHaptic(B,"selection");t&&triggerHaptic(t)},[se,B,ee,ue]);useImperativeHandle(t,()=>({focus:()=>q.current?.focus(),blur:()=>q.current?.blur(),clear:()=>ue({...Ge.current,nationalNumber:""}),isFocused:()=>q.current?.isFocused()??!1,getValue:()=>Ge.current,getE164:()=>formatE164(Ge.current),getFormatted:()=>{const e=Ge.current,t=planOf(e.iso);return t?formatPhoneAsTyped(e.nationalNumber,t):e.nationalNumber},isValid:()=>ie(Ge.current),getCountry:()=>p.find(e=>e.iso===Ge.current.iso)}),[p,ie,ue]);const Ze=A||S,Je=_jsx(FieldBase,{testID:$?`${$}-field`:void 0,size:O,variant:ve,radius:M,topNotch:Oe.topNotch,focused:de,disabled:A,error:We,filled:Pe,onPress:pe,pressFeedback:!1,leadingDivider:!0,paddingLeft:Se?H.space.none:void 0,leading:_jsxs(Pressable,{onPress:()=>{Ze||(Ne.current=!0,ye(!0))},disabled:Ze,accessibilityRole:"button",accessibilityLabel:U??G.countryButton(se.callingCode),accessibilityState:{disabled:Ze},"aria-disabled":Ze,hitSlop:6,...hitSlopMarker(6),onLayout:e=>{const{width:t}=e.nativeEvent.layout;Fe(e=>e===t?e:t)},style:W.codeTrigger,testID:$?`${$}-code`:void 0,children:[Q(Ve,Ce.text,$?`${$}-flag`:void 0),_jsx(Text,{variant:"body",style:[W.codeText,{color:xe.color,fontSize:Ce.text}],children:`+${se.callingCode}`}),S?null:_jsx(Chevron,{color:A?H.colors["field-icon-disabled"]:H.colors["field-icon"],size:Ce.icon,open:ge})]}),children:_jsxs(View,{style:W.inputWrap,children:[_jsx(TextInput,{ref:q,value:we,maxLength:De,onChangeText:Ye,returnKeyType:a,submitBehavior:s,onSubmitEditing:u,onSelectionChange:e=>{const{start:t,end:o}=e.nativeEvent.selection;be(t!==o)},onFocus:()=>{ce(!0),k?.()},onBlur:()=>{ce(!1),Pe&&!Ne.current&&he(!0),z?.()},editable:!A,placeholder:Ae&&!je||Le?void 0:Y,placeholderTextColor:xe.placeholderColor,accessibilityLabel:D??E??Y,selectionColor:H.colors["field-caret"],keyboardType:"phone-pad",textContentType:"telephoneNumber",autoComplete:"tel",style:[W.input,{color:xe.color,fontSize:Ce.text,...xe.weightStyle,paddingLeft:Se?H.space.none:void 0}],testID:$?`${$}-input`:void 0}),Le?_jsx(RequiredPlaceholder,{text:Y,color:xe.placeholderColor,fontSize:Ce.text,weightStyle:xe.weightStyle}):null]})});return _jsxs(View,{style:R,testID:$,children:[E&&"top"===T?_jsx(FieldLabel,{size:O,required:j,children:E}):null,_jsxs(View,{style:W.fieldWrapper,children:[Je,Oe.node]}),_jsx(FieldMessage,{size:O,error:We,text:We?He:P}),_jsx(OptionSheet,{open:ge,haptic:B,onClose:()=>ye(!1),title:G.countrySheetTitle,options:Z,sections:J,getOptionLabel:e=>`${e.label} (+${e.code})`,getOptionValue:e=>e.iso,getOptionIcon:e=>Q(e,H.text.lg.size),renderOption:g?({option:e,selected:t})=>g(e,{selected:t}):void 0,value:Ve?.iso,onChange:(e,t)=>Ke(t),searchable:Z.length>8,labels:{searchPlaceholder:G.countrySearchPlaceholder},alphabetIndex:y??Z.length>20})]})});PhoneNumberInput.displayName="PhoneNumberInput";const buildStyles=e=>StyleSheet.create({fieldWrapper:{position:"relative",overflow:"visible"},codeTrigger:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},flag:{includeFontPadding:!1,marginRight:e.space.xs},codeText:{...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"}});export default PhoneNumberInput;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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."});const 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 o=toneFor(e,r),s=o.base,i=e.colors.bg,n="neutral"===r;let l;switch(t){case"soft":l={fill:n?e.colors["bg-muted"]:blendOf(s,.14,i,e.colors["bg-subtle"]),ring:i,icon:s};break;case"outline":l={fill:i,ring:n?e.colors.border:s,icon:s};break;default:l={fill:s,ring:i,icon:o.on}}return l},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:o,sources:s,onPick:i,onRemove:n,loading:l=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:h,avatarTone:f,avatarBackgroundColor:b,avatarColor:y,label:x,required:k=!1,helperText:v,error:C,layout:_="stacked",title:j,subtitle:P,ImageComponent:S,labels:T,haptic:I,onError:E,accessibilityLabel:F,style:V,testID:A}=e;assertValidValue("ProfilePicker","size",e.size,["sm","md","lg"]),assertValidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),assertValidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),assertValidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const w=useTheme(),L=w.settings.components["profile-picker"],M=g??L?.defaultTone??"primary",O=h??L?.defaultVariant??"solid",R=useMemo(()=>badgeLookFor(w,M,O),[w,M,O]),D=f??L?.defaultAvatarTone,H=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...T}),[T]),[z,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(t);t!==Z&&(G(t),B(null));const K=l||a,N=z??t??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==z||Boolean(t)&&Boolean(n)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),te=re*(1-Math.SQRT1_2),oe=clamp(Math.round(.28*ee),24,44),se=te-oe/2,ie=Math.max(0,-se),ne=useCallback(e=>{$(e),E?.(e),!1!==I&&triggerHaptic("notificationError")},[E,I]),le=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(H.errorTooLarge(d));if(t.type&&!matchesAccept(t.type,c))return void ne(H.errorWrongType);$(null),B(t.uri);const o=resolveHaptic(I,"selection");o&&triggerHaptic(o),i?.(t)},[d,c,H,I,i,ne]),ae=useCallback(()=>{if(K)return;ue.current=null;const[e]=s;void 0===e||1!==s.length||Y?(s.length>0||Y)&&W(!0):le(e)},[K,s,Y,le]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(I,"selection");e&&triggerHaptic(e),n?.()},[I,n]),de=useMemo(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(le);pe.current=le;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),he=A??"profile-picker",fe=F??(J?H.pick:o),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:ie,marginRight:ie},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:fe,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:l}:{busy:l},"aria-disabled":J?K:void 0,"aria-busy":l,testID:`${he}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{dimension:ee,shape:m,name:o||void 0,source:X,ImageComponent:S,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),l?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:w.colors.scrim}],testID:`${he}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:w.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${he}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:oe,height:oe,borderRadius:w.radius.pill,...smoothCorners,right:se,bottom:se,backgroundColor:R.fill,borderColor:R.ring}],children:renderSlotIcon(p,{color:R.icon,size:Math.round(.55*oe),disabled:!1})}):null]})}),ye="stacked"!==_?_jsxs(View,{style:[styles.meta,"profile"===_?styles.metaCentred:null],children:[j?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===_?styles.textCentred:null],children:j}):null,P?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===_?styles.textCentred:null,{marginTop:w.space.xxs}],children:P}):null,_jsx(FieldMessage,{text:Q??v,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??v,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:V,testID:A,children:[x?_jsx(FieldLabel,{required:k,children:x}):null,_jsxs(View,{style:"inline"===_?[styles.row,{columnGap:w.space.md}]:["profile"===_?styles.columnCentred:styles.column,{rowGap:w.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:I,onClose:()=>W(!1),onAfterClose:ge,title:H.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?H.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?_jsx(AppIcon,{name:"trash",size:20,color:w.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})}ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...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"}});export{ProfilePicker};export default ProfilePicker;
1
+ "use strict";import{useCallback,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{AppIcon}from"../AppIcon/index.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Avatar}from"../Avatar/index.js";import{FieldLabel,FieldMessage,fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{matchesAccept}from"../FilePicker/FilePicker.js";import{OptionSheet}from"../OptionSheet/OptionSheet.js";import{Spinner}from"../Spinner/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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."});const 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 o=toneFor(e,r),s=o.base,i=e.colors.bg,n="neutral"===r;let l;switch(t){case"soft":l={fill:n?e.colors["bg-muted"]:blendOf(s,.14,i,e.colors["bg-subtle"]),ring:i,icon:s};break;case"outline":l={fill:i,ring:n?e.colors.border:s,icon:s};break;default:l={fill:s,ring:i,icon:o.on}}return l},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:o,sources:s,onPick:i,onRemove:n,loading:l=!1,disabled:a=!1,accept:c=DEFAULT_ACCEPT,maxSizeMB:d,size:u="md",shape:m="circle",badgeIcon:p="camera",tone:g,variant:h,avatarTone:f,avatarBackgroundColor:b,avatarColor:y,label:x,required:v=!1,helperText:k,error:C,layout:_="stacked",title:j,subtitle:P,ImageComponent:S,labels:I,haptic:T,onError:E,accessibilityLabel:F,style:V,testID:A}=e;assertValidValue("ProfilePicker","size",e.size,["sm","md","lg"]),assertValidValue("ProfilePicker","shape",e.shape,["circle","rounded","square"]),assertValidValue("ProfilePicker","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("ProfilePicker","variant",e.variant,["solid","soft","outline"]),assertValidValue("ProfilePicker","layout",e.layout,["stacked","inline","profile"]);const w=useTheme(),L=w.settings.components["profile-picker"],M=g??L?.defaultTone??"primary",O=h??L?.defaultVariant??"solid",R=useMemo(()=>badgeLookFor(w,M,O),[w,M,O]),D=f??L?.defaultAvatarTone,H=useMemo(()=>({...DEFAULT_PROFILE_PICKER_LABELS,...I}),[I]),[z,B]=useState(null),[U,$]=useState(null),[q,W]=useState(!1),[Z,G]=useState(t);t!==Z&&(G(t),B(null));const K=l||a,N=z??t??null,X=useMemo(()=>N?{uri:N}:void 0,[N]),Q=C??U??void 0,Y=!K&&(null!==z||Boolean(t)&&Boolean(n)),J=s.length>0||Y,ee=SIZE_PX[u],re=resolveRadius(m,ee),te=re*(1-Math.SQRT1_2),oe=clamp(Math.round(.28*ee),24,44),se=te-oe/2,ie=Math.max(0,-se),ne=useCallback(e=>{$(e),E?.(e),!1!==T&&triggerHaptic("notificationError")},[E,T]),le=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(H.errorTooLarge(d));if(t.type&&!matchesAccept(t.type,c))return void ne(H.errorWrongType);$(null),B(t.uri);const o=resolveHaptic(T,"selection");o&&triggerHaptic(o),i?.(t)},[d,c,H,T,i,ne]),ae=useCallback(()=>{if(K)return;ue.current=null;const[e]=s;void 0===e||1!==s.length||Y?(s.length>0||Y)&&W(!0):le(e)},[K,s,Y,le]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(T,"selection");e&&triggerHaptic(e),n?.()},[T,n]),de=useMemo(()=>{const e=s.map(e=>({kind:"source",source:e}));return Y&&e.push({kind:"remove"}),e},[s,Y]),ue=useRef(null),me=useCallback(e=>{ue.current||(W(!1),"remove"===e.kind?ce():ue.current=e.source)},[ce]),pe=useRef(le);pe.current=le;const ge=useCallback(()=>{const e=ue.current;ue.current=null,e&&pe.current(e)},[]),he=A??"profile-picker",fe=F??(J?H.pick:o),be=_jsx(View,{style:{width:ee,height:ee,marginBottom:ie,marginRight:ie},children:_jsxs(Pressable,{onPress:ae,disabled:K||!J,accessibilityRole:J?"button":"image",accessibilityLabel:fe,accessibilityHint:fieldTextAsString(Q),accessibilityState:J?{disabled:K,busy:l}:{busy:l},"aria-disabled":J?K:void 0,"aria-busy":l,testID:`${he}-button`,style:({pressed:e})=>[{width:ee,height:ee,borderRadius:re,...smoothCorners},{opacity:a?.55:e?.85:1}],children:[_jsx(View,{importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,pointerEvents:"none",children:_jsx(Avatar,{testID:A?`${A}-avatar`:void 0,dimension:ee,shape:m,name:o||void 0,source:X,ImageComponent:S,tone:D,backgroundColor:b,color:y,placeholderIcon:"user"})}),l?_jsx(View,{style:[styles.fill,styles.overlay,{borderRadius:re,...smoothCorners,backgroundColor:w.colors.scrim}],testID:`${he}-loading`,children:_jsx(Spinner,{size:ee>=100?"md":"sm",color:w.colors["on-primary"]})}):null,!a&&J?_jsx(View,{pointerEvents:"none",testID:`${he}-badge`,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,style:[styles.badge,{width:oe,height:oe,borderRadius:w.radius.pill,...smoothCorners,right:se,bottom:se,backgroundColor:R.fill,borderColor:R.ring}],children:renderSlotIcon(p,{color:R.icon,size:Math.round(.55*oe),disabled:!1})}):null]})}),ye="stacked"!==_?_jsxs(View,{style:[styles.meta,"profile"===_?styles.metaCentred:null],children:[j?_jsx(Text,{variant:"body",weight:"semibold",style:[styles.title,"profile"===_?styles.textCentred:null],children:j}):null,P?_jsx(Text,{variant:"bodySmall",color:"secondary",style:[styles.subtitle,"profile"===_?styles.textCentred:null,{marginTop:w.space.xxs}],children:P}):null,_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)})]}):_jsx(FieldMessage,{text:Q??k,error:hasFieldText(Q)});return _jsxs(View,{ref:r,style:V,testID:A,children:[x?_jsx(FieldLabel,{required:v,children:x}):null,_jsxs(View,{style:"inline"===_?[styles.row,{columnGap:w.space.md}]:["profile"===_?styles.columnCentred:styles.column,{rowGap:w.space.xs}],children:[be,ye]}),_jsx(OptionSheet,{open:q,haptic:T,onClose:()=>W(!1),onAfterClose:ge,title:H.sheetTitle,options:de,getOptionLabel:e=>"remove"===e.kind?H.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?_jsx(AppIcon,{name:"trash",size:20,color:w.colors["danger-text"]}):e.source.icon,onChange:(e,r)=>me(r)})]})}ProfilePicker.displayName="ProfilePicker";const styles=StyleSheet.create({fill:{alignItems:"center",justifyContent:"center",overflow:"hidden"},overlay:{...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"}});export{ProfilePicker};export default ProfilePicker;
@@ -1 +1 @@
1
- "use strict";import{cloneElement,isValidElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{AppBar}from"../AppBar/index.js";import{AsyncBlock,DEFAULT_ASYNC_BLOCK_LABELS}from"../AsyncBlock/index.js";import{EmptyState}from"../EmptyState/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedListFooter}from"../PagedListFooter/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},isElementFooter=e=>isValidElement(e);function renderFooter(e){if(null==e)return null;if(isElementFooter(e))return e;return _jsx(e,{})}const topPaddingOf=e=>{const t=StyleSheet.flatten(e),o=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof o?o:0},buildStyles=e=>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:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:s,rightActions:a,leading:l,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:m=!0,list:p,edges:h=DEFAULT_EDGES,keyboardToolbar:g=!0,bottomInset:S=0,gutter:y,floatingAction:v,scrollRef:b,onScroll:x,contentContainerStyle:E,testID:C}=e,T=useTheme(),L=y??void 0===p,j=T.space[T.components.screen.gutter],_=L?j:0,A=useSafeAreaInsets(),R=useMemo(()=>buildStyles(T),[T]),[k]=useState(()=>new Animated.Value(0)),[F,B]=useState(0),[V,w]=useState(0),O=void 0!==s,M=useRef(s);M.current=s;const K=Boolean(t||o||s||l||i||a?.length),P=n&&void 0!==t,D=P&&(void 0!==p||m),z=D?F:0,H=K&&!D&&(r??T.settings.components.screen?.headerShadowOnScroll??!0),[I,N]=useState(!1),U=useRef(H);U.current=H;const headerGap=e=>e>0?e:K?T.space.lg:0,G=void 0!==f,W=p?.state,Y="data"===W?.status||"empty"===W?.status?W:void 0,{refreshControl:q}=useRefreshControl({onRefresh:Y?Y.refresh:c??noop,refreshing:Y?Y.refreshing:u}),J=c||Y?cloneElement(q,{progressViewOffset:z}):void 0,Q=useSharedValue(0),X=useSharedValue(0),Z=useSharedValue(0),$=useSharedValue(0),ee=useRef(null),te=useRef(0),oe=useRef(0),ne=useMemo(()=>({top:Q,bottom:X,offset:Z,maxOffset:$,scrollTo:e=>{const t=ee.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[Q,X,Z,$]),re=useCallback(e=>{ee.current=e,"function"==typeof b?b(e):b&&(b.current=e)},[b]),se=useCallback(()=>{$.value=Math.max(0,te.current-oe.current)},[$]),ae=useRef(x);ae.current=x;const le=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:k}}}],{useNativeDriver:!1,listener:e=>{if(Z.value=e.nativeEvent.contentOffset.y,U.current){const t=e.nativeEvent.contentOffset.y>0;N(e=>e===t?e:t)}ae.current?.(e)}}),[k,Z]),ie=useCallback(e=>{const{height:t}=e.nativeEvent.layout;B(e=>Math.max(e,t))},[]),de=useCallback(e=>{w(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!O)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(M.current?.(),!0));return()=>e.remove()},[O]);const ce=h.includes("left")?A.left:0,ue=h.includes("right")?A.right:0,fe=h.includes("bottom")?A.bottom:0,me=h.includes("top")&&!K?A.top:0,pe=T.space[T.components["floating-action-button"]["bottom-offset"]],he=v?.props.bottomOffset??pe,ge=v?resolveFloatingActionButtonSize(T,v.props.size??"md").diameter+he+T.space.lg:0,Se=G?Math.max(0,V-A.bottom):S,ye=v?cloneElement(v,{bottomOffset:he+Se,position:v.props.position??"bottomRight"}):null,ve=G?ge:Math.max(fe,v?ge+A.bottom:0),be=S+ve-(G?0:fe),xe=h.filter(e=>"top"!==e&&!("bottom"===e&&G)),Ee=K?_jsx(View,{style:D?R.overlay:H?R.headerRaised:void 0,onLayout:D?ie:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:P?"large":"default",scrollY:D?k:void 0,elevated:H&&I,onBack:s,rightActions:a,leading:l,trailing:i,gutter:j})}):null,Ce=useCallback(()=>{const e=ee.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{oe.current=n,Q.value=t+z,X.value=t+n,se()})},[z,Q,X,se]);useEffect(()=>{Ce()},[Ce]);const Te=useCallback((e,t)=>{te.current=t,se()},[se]);let Le;if(void 0!==p){const{state:e,paging:t,empty:o,skeleton:n,errorTitle:r,data:s,...a}=p,l=topPaddingOf([a.contentContainerStyle,E]),handleEndReached=e=>{t?.hasMore&&!t.loadingMore&&null==t.errorMore&&t.loadMore(),a.onEndReached?.(e)},renderList=(e,o)=>_jsx(FlatList,{data:e,keyboardShouldPersistTaps:"handled",onEndReachedThreshold:t?.5:void 0,...a,ref:re,refreshControl:J,onScroll:le,onLayout:e=>{Ce(),a.onLayout?.(e)},onContentSizeChange:(e,t)=>{Te(e,t),a.onContentSizeChange?.(e,t)},onEndReached:t?handleEndReached:a.onEndReached,ListEmptyComponent:o,ListFooterComponent:t||a.ListFooterComponent?_jsxs(_Fragment,{children:[renderFooter(a.ListFooterComponent),t?_jsx(PagedListFooter,{paging:t}):null]}):void 0,scrollEventThrottle:16,style:R.flex,contentContainerStyle:[{paddingTop:z,paddingLeft:ce+_,paddingRight:ue+_},{paddingBottom:S+ve},a.contentContainerStyle,E,o?{flexGrow:1}:void 0,{paddingTop:z+headerGap(l)}]});Le=_jsx(ScrollHostContext.Provider,{value:ne,children:"empty"===e?.status?renderList([],_jsx(EmptyState,{...o??{title:DEFAULT_ASYNC_BLOCK_LABELS.emptyTitle}})):e?_jsx(AsyncBlock,{state:e,skeleton:n,errorTitle:r,style:[R.flex,{paddingTop:z+headerGap(l)}],children:e=>renderList(e,void 0)}):renderList(s,o?_jsx(EmptyState,{...o}):void 0)})}else Le=m?_jsx(ScrollHostContext.Provider,{value:ne,children:_jsxs(KeyboardAwareScrollView,{ref:re,refreshControl:J,onScroll:le,scrollEventThrottle:16,onLayout:Ce,onContentSizeChange:Te,safeAreaEdges:xe,style:R.flex,contentContainerStyle:[{paddingHorizontal:_},E,{paddingTop:z+headerGap(topPaddingOf(E))}],children:[d,be>0?_jsx(View,{style:{height:be}}):null]})}):_jsx(View,{style:[R.flex,{paddingLeft:ce+_,paddingRight:ue+_,paddingBottom:S+ve},E],children:d});const je=G?_jsx(KeyboardStickyView,{onLayout:de,style:[R.footer,{paddingLeft:ce+j,paddingRight:ue+j,paddingBottom:fe+S}],children:f}):null;return _jsxs(View,{testID:C,style:[R.root,{paddingTop:me}],children:[D?null:Ee,Le,je,ye,void 0!==p?d:null,D?Ee:null,g?_jsx(KeyboardToolbar,{}):null]})}
1
+ "use strict";import{cloneElement,isValidElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{AppBar}from"../AppBar/index.js";import{AsyncBlock,DEFAULT_ASYNC_BLOCK_LABELS}from"../AsyncBlock/index.js";import{EmptyState}from"../EmptyState/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedListFooter}from"../PagedListFooter/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},isElementFooter=e=>isValidElement(e);function renderFooter(e){if(null==e)return null;if(isElementFooter(e))return e;return _jsx(e,{})}const topPaddingOf=e=>{const t=StyleSheet.flatten(e),o=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof o?o:0},buildStyles=e=>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:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:a,rightActions:s,leading:l,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:p=!0,list:m,edges:h=DEFAULT_EDGES,keyboardToolbar:g=!0,bottomInset:S=0,gutter:y,floatingAction:v,scrollRef:b,onScroll:x,contentContainerStyle:E,testID:C}=e,T=useTheme(),L=y??void 0===m,j=T.space[T.components.screen.gutter],_=L?j:0,A=useSafeAreaInsets(),R=useMemo(()=>buildStyles(T),[T]),[k]=useState(()=>new Animated.Value(0)),[F,B]=useState(0),[V,w]=useState(0),O=void 0!==a,M=useRef(a);M.current=a;const D=Boolean(t||o||a||l||i||s?.length),K=n&&void 0!==t,P=K&&(void 0!==m||p),z=P?F:0,H=D&&!P&&(r??T.settings.components.screen?.headerShadowOnScroll??!0),[I,N]=useState(!1),U=useRef(H);U.current=H;const headerGap=e=>e>0?e:D?T.space.lg:0,G=void 0!==f,W=m?.state,Y="data"===W?.status||"empty"===W?.status?W:void 0,{refreshControl:$}=useRefreshControl({onRefresh:Y?Y.refresh:c??noop,refreshing:Y?Y.refreshing:u}),q=c||Y?cloneElement($,{progressViewOffset:z}):void 0,J=useSharedValue(0),Q=useSharedValue(0),X=useSharedValue(0),Z=useSharedValue(0),ee=useRef(null),te=useRef(0),oe=useRef(0),ne=useMemo(()=>({top:J,bottom:Q,offset:X,maxOffset:Z,scrollTo:e=>{const t=ee.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[J,Q,X,Z]),re=useCallback(e=>{ee.current=e,"function"==typeof b?b(e):b&&(b.current=e)},[b]),ae=useCallback(()=>{Z.value=Math.max(0,te.current-oe.current)},[Z]),se=useRef(x);se.current=x;const le=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:k}}}],{useNativeDriver:!1,listener:e=>{if(X.value=e.nativeEvent.contentOffset.y,U.current){const t=e.nativeEvent.contentOffset.y>0;N(e=>e===t?e:t)}se.current?.(e)}}),[k,X]),ie=useCallback(e=>{const{height:t}=e.nativeEvent.layout;B(e=>Math.max(e,t))},[]),de=useCallback(e=>{w(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!O)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(M.current?.(),!0));return()=>e.remove()},[O]);const ce=h.includes("left")?A.left:0,ue=h.includes("right")?A.right:0,fe=h.includes("bottom")?A.bottom:0,pe=h.includes("top")&&!D?A.top:0,me=T.space[T.components["floating-action-button"]["bottom-offset"]],he=v?.props.bottomOffset??me,ge=v?resolveFloatingActionButtonSize(T,v.props.size??"md").diameter+he+T.space.lg:0,Se=G?Math.max(0,V-A.bottom):S,ye=v?cloneElement(v,{bottomOffset:he+Se,position:v.props.position??"bottomRight"}):null,ve=G?ge:Math.max(fe,v?ge+A.bottom:0),be=S+ve-(G?0:fe),xe=h.filter(e=>"top"!==e&&!("bottom"===e&&G)),Ee=D?_jsx(View,{style:P?R.overlay:H?R.headerRaised:void 0,onLayout:P?ie:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:K?"large":"default",scrollY:P?k:void 0,elevated:H&&I,onBack:a,rightActions:s,leading:l,trailing:i,gutter:j,testID:C?`${C}-app-bar`:void 0})}):null,Ce=useCallback(()=>{const e=ee.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{oe.current=n,J.value=t+z,Q.value=t+n,ae()})},[z,J,Q,ae]);useEffect(()=>{Ce()},[Ce]);const Te=useCallback((e,t)=>{te.current=t,ae()},[ae]);let Le;if(void 0!==m){const{state:e,paging:t,empty:o,skeleton:n,errorTitle:r,data:a,...s}=m,l=topPaddingOf([s.contentContainerStyle,E]),handleEndReached=e=>{t?.hasMore&&!t.loadingMore&&null==t.errorMore&&t.loadMore(),s.onEndReached?.(e)},renderList=(e,o)=>_jsx(FlatList,{data:e,keyboardShouldPersistTaps:"handled",onEndReachedThreshold:t?.5:void 0,...s,ref:re,refreshControl:q,onScroll:le,onLayout:e=>{Ce(),s.onLayout?.(e)},onContentSizeChange:(e,t)=>{Te(e,t),s.onContentSizeChange?.(e,t)},onEndReached:t?handleEndReached:s.onEndReached,ListEmptyComponent:o,ListFooterComponent:t||s.ListFooterComponent?_jsxs(_Fragment,{children:[renderFooter(s.ListFooterComponent),t?_jsx(PagedListFooter,{paging:t}):null]}):void 0,scrollEventThrottle:16,style:R.flex,contentContainerStyle:[{paddingTop:z,paddingLeft:ce+_,paddingRight:ue+_},{paddingBottom:S+ve},s.contentContainerStyle,E,o?{flexGrow:1}:void 0,{paddingTop:z+headerGap(l)}]});Le=_jsx(ScrollHostContext.Provider,{value:ne,children:"empty"===e?.status?renderList([],_jsx(EmptyState,{...o??{title:DEFAULT_ASYNC_BLOCK_LABELS.emptyTitle}})):e?_jsx(AsyncBlock,{state:e,skeleton:n,errorTitle:r,style:[R.flex,{paddingTop:z+headerGap(l)}],children:e=>renderList(e,void 0)}):renderList(a,o?_jsx(EmptyState,{...o}):void 0)})}else Le=p?_jsx(ScrollHostContext.Provider,{value:ne,children:_jsxs(KeyboardAwareScrollView,{ref:re,refreshControl:q,onScroll:le,scrollEventThrottle:16,onLayout:Ce,onContentSizeChange:Te,safeAreaEdges:xe,style:R.flex,contentContainerStyle:[{paddingHorizontal:_},E,{paddingTop:z+headerGap(topPaddingOf(E))}],children:[d,be>0?_jsx(View,{style:{height:be}}):null]})}):_jsx(View,{style:[R.flex,{paddingLeft:ce+_,paddingRight:ue+_,paddingBottom:S+ve},E],children:d});const je=G?_jsx(KeyboardStickyView,{onLayout:de,style:[R.footer,{paddingLeft:ce+j,paddingRight:ue+j,paddingBottom:fe+S}],children:f}):null;return _jsxs(View,{testID:C,style:[R.root,{paddingTop:pe}],children:[P?null:Ee,Le,je,ye,void 0!==m?d:null,P?Ee:null,g?_jsx(KeyboardToolbar,{}):null]})}
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldBase,FieldLabel,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{normalizeSuggestion,SearchRecents,SearchScopeBar,SearchSuggestions}from"./SearchPanel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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"});const DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=forwardRef((e,s)=>{const{value:l,onChangeText:a,onSubmit:t,onFocus:o,onBlur:r,placeholder:n,autoFocus:i=!1,disabled:c=!1,onClear:u,leftIcon:d,debounceMs:p,size:h="md",variant:b,radius:m,label:f,labelMode:S="top",labelStyle:g,scopes:v,scope:C,onScopeChange:x,recents:R,maxRecents:j=DEFAULT_PANEL_ROWS,onSelectRecent:y,onRemove:F,onClearRecents:_,suggestions:L,maxSuggestions:k=DEFAULT_PANEL_ROWS,onSelect:B,haptic:E,labels:A,style:V,inputStyle:T,accessibilityLabel:z,testID:I,...H}=e;assertValidValue("SearchBar","size",e.size,["sm","md","lg"]),assertValidValue("SearchBar","variant",e.variant,["outline","filled","underline"]),assertValidValue("SearchBar","labelMode",e.labelMode,["top","float"]);const M=useTheme(),w=useMemo(()=>({...DEFAULT_SEARCH_BAR_LABELS,...A}),[A]),D=n??w.placeholder,P=b??M.settings.components["search-bar"]?.defaultVariant??M.settings.components.field?.defaultVariant??"filled",O="underline"===P,N=resolveFieldSize(M,h),U=m??M.components["search-bar"][h].radius,W=resolveFieldTextStyle(M,{disabled:c}),$=useRef(null),q=useMemo(()=>mergeRefs($,s),[s]),K=useCallback(()=>{c||$.current?.focus()},[c]),G=useMemo(()=>buildStyles(M),[M]),J="string"==typeof l?l:"",[Q,X]=useState(!1),Y=useCallback(e=>{X(!0),o?.(e)},[o]),Z=useCallback(e=>{X(!1),r?.(e)},[r]),[ee,se]=useState(J),le=useRef(ee);le.current=ee;const ae=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==le.current&&se(J)},[J,p]);const te=useRef(J);useEffect(()=>{void 0!==p&&ae!==te.current&&(te.current=ae,a(ae))},[ae,p,a]);const oe=useCallback(e=>{void 0===p?a(e):se(e)},[p,a]),re=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(se(""),te.current=""),a(""),u?.()},[E,p,a,u]),ne=useCallback(()=>{t?.(void 0!==p?ee:J)},[t,p,ee,J]),ie=void 0!==p?ee:J,ce=ie.length>0,[ue,de]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),pe=useCallback(e=>{de(e);const s=v?.find(s=>s.value===e)?.label;s&&announce(w.searching(s))},[v,de,w]),[he,be]=useState(!1),me=useRef(null),fe=useCallback(()=>{me.current&&(clearTimeout(me.current),me.current=null)},[]),Se=useCallback(()=>{fe(),be(!0)},[fe]),ge=useCallback(()=>{fe(),me.current=setTimeout(()=>be(!1),50)},[fe]);useEffect(()=>fe,[fe]);const ve=!c&&(Q||he),Ce=useMemo(()=>(R??[]).slice(0,j),[R,j]),xe=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),Re=ve&&!ce&&Ce.length>0,je=ve&&ce&&xe.length>0,ye=je?xe.length:0,Fe=ye>0?w.suggestionCount(ye):"";useEffect(()=>{Fe&&announce(Fe)},[Fe]);const Le=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),ke=useCallback(e=>{Le(),$.current?.blur(),be(!1),y?.(e)},[Le,y]),Be=useCallback(e=>{Le(),$.current?.blur(),be(!1),B?.(e)},[Le,B]),Ee=useCallback(e=>{Le(),F?.(e),announce(w.removed(e)),K()},[Le,F,K,w]),Ae=useCallback(()=>{Le(),_?.(),announce(w.recentsCleared),K()},[Le,_,K,w]),Ve={size:N.icon,color:c?M.colors["text-disabled"]:M.colors["text-subtle"],disabled:c},Te=d?renderSlotIcon(d,Ve):(M.settings.icons.search??defaultIcons.search)(Ve),ze=_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Te}),Ie=Boolean(f)&&"float"===S,He=useFloatingLabel({label:f,enabled:Ie,floated:Q||ce,variant:P,sizeTokens:N,leadingOffset:N.icon+M.space.md,trailingOffset:ce?N.icon+M.space.md:0,paddingLeft:O?M.space.none:N["padding-x"],color:M.colors["field-label"],style:g}),Me=ce&&!c?_jsx(Pressable,{onPress:re,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:w.clearSearch,children:(M.settings.icons.close??defaultIcons.close)({size:N.icon,color:M.colors["text-muted"]})}):null;return _jsxs(View,{style:V,testID:I,children:[f&&!Ie?_jsx(FieldLabel,{size:h,style:g,children:f}):null,_jsx(View,{style:G.root,children:_jsxs(View,{style:G.fieldWrap,children:[_jsx(FieldBase,{size:h,variant:P,focused:Q,disabled:c,filled:ce,minHeight:N["min-height"],paddingHorizontal:O?M.space.none:N["padding-x"],radius:U,leading:ze,trailing:Me,topNotch:He.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:z??D,children:_jsx(TextInput,{ref:q,style:[G.input,{fontSize:N.text,color:W.color,...W.weightStyle},T],value:ie,onChangeText:oe,onSubmitEditing:ne,onFocus:Y,onBlur:Z,placeholder:!Ie||Q||ce?D:void 0,placeholderTextColor:W.placeholderColor,autoFocus:i,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(M,P).borderFocusedRepresentative,accessibilityLabel:z??D,accessibilityState:{disabled:c},"aria-disabled":c,...H})}),He.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ue||(v[0]?.value??""),disabled:c,haptic:E,labels:w,onChange:pe}):null,Re?_jsx(SearchRecents,{recents:Ce,labels:w,onSelect:ke,onRemove:F?Ee:void 0,onClear:_?Ae:void 0,onHold:Se,onRelease:ge}):null,je?_jsx(SearchSuggestions,{suggestions:xe,query:ie,onSelect:Be,onHold:Se,onRelease:ge}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>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}});export{SearchBar};export default SearchBar;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldBase,FieldLabel,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{normalizeSuggestion,SearchRecents,SearchScopeBar,SearchSuggestions}from"./SearchPanel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const 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"});const DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=forwardRef((e,s)=>{const{value:l,onChangeText:a,onSubmit:t,onFocus:o,onBlur:r,placeholder:n,autoFocus:i=!1,disabled:c=!1,onClear:u,leftIcon:d,debounceMs:p,size:h="md",variant:b,radius:m,label:f,labelMode:S="top",labelStyle:g,scopes:v,scope:C,onScopeChange:x,recents:R,maxRecents:j=DEFAULT_PANEL_ROWS,onSelectRecent:y,onRemove:F,onClearRecents:_,suggestions:L,maxSuggestions:k=DEFAULT_PANEL_ROWS,onSelect:B,haptic:E,labels:A,style:V,inputStyle:T,accessibilityLabel:I,testID:z,...H}=e;assertValidValue("SearchBar","size",e.size,["sm","md","lg"]),assertValidValue("SearchBar","variant",e.variant,["outline","filled","underline"]),assertValidValue("SearchBar","labelMode",e.labelMode,["top","float"]);const D=useTheme(),M=useMemo(()=>({...DEFAULT_SEARCH_BAR_LABELS,...A}),[A]),w=n??M.placeholder,P=b??D.settings.components["search-bar"]?.defaultVariant??D.settings.components.field?.defaultVariant??"filled",O="underline"===P,N=resolveFieldSize(D,h),U=m??D.components["search-bar"][h].radius,W=resolveFieldTextStyle(D,{disabled:c}),$=useRef(null),q=useMemo(()=>mergeRefs($,s),[s]),K=useCallback(()=>{c||$.current?.focus()},[c]),G=useMemo(()=>buildStyles(D),[D]),J="string"==typeof l?l:"",[Q,X]=useState(!1),Y=useCallback(e=>{X(!0),o?.(e)},[o]),Z=useCallback(e=>{X(!1),r?.(e)},[r]),[ee,se]=useState(J),le=useRef(ee);le.current=ee;const ae=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==le.current&&se(J)},[J,p]);const te=useRef(J);useEffect(()=>{void 0!==p&&ae!==te.current&&(te.current=ae,a(ae))},[ae,p,a]);const oe=useCallback(e=>{void 0===p?a(e):se(e)},[p,a]),re=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(se(""),te.current=""),a(""),u?.()},[E,p,a,u]),ne=useCallback(()=>{t?.(void 0!==p?ee:J)},[t,p,ee,J]),ie=void 0!==p?ee:J,ce=ie.length>0,[ue,de]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),pe=useCallback(e=>{de(e);const s=v?.find(s=>s.value===e)?.label;s&&announce(M.searching(s))},[v,de,M]),[he,be]=useState(!1),me=useRef(null),fe=useCallback(()=>{me.current&&(clearTimeout(me.current),me.current=null)},[]),Se=useCallback(()=>{fe(),be(!0)},[fe]),ge=useCallback(()=>{fe(),me.current=setTimeout(()=>be(!1),50)},[fe]);useEffect(()=>fe,[fe]);const ve=!c&&(Q||he),Ce=useMemo(()=>(R??[]).slice(0,j),[R,j]),xe=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),Re=ve&&!ce&&Ce.length>0,je=ve&&ce&&xe.length>0,ye=je?xe.length:0,Fe=ye>0?M.suggestionCount(ye):"";useEffect(()=>{Fe&&announce(Fe)},[Fe]);const Le=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),ke=useCallback(e=>{Le(),$.current?.blur(),be(!1),y?.(e)},[Le,y]),Be=useCallback(e=>{Le(),$.current?.blur(),be(!1),B?.(e)},[Le,B]),Ee=useCallback(e=>{Le(),F?.(e),announce(M.removed(e)),K()},[Le,F,K,M]),Ae=useCallback(()=>{Le(),_?.(),announce(M.recentsCleared),K()},[Le,_,K,M]),Ve={size:N.icon,color:c?D.colors["text-disabled"]:D.colors["text-subtle"],disabled:c},Te=d?renderSlotIcon(d,Ve):(D.settings.icons.search??defaultIcons.search)(Ve),Ie=_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Te}),ze=Boolean(f)&&"float"===S,He=useFloatingLabel({label:f,enabled:ze,floated:Q||ce,variant:P,sizeTokens:N,leadingOffset:N.icon+D.space.md,trailingOffset:ce?N.icon+D.space.md:0,paddingLeft:O?D.space.none:N["padding-x"],color:D.colors["field-label"],style:g}),De=ce&&!c?_jsx(Pressable,{onPress:re,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:M.clearSearch,children:(D.settings.icons.close??defaultIcons.close)({size:N.icon,color:D.colors["text-muted"]})}):null;return _jsxs(View,{style:V,testID:z,children:[f&&!ze?_jsx(FieldLabel,{size:h,style:g,children:f}):null,_jsx(View,{style:G.root,children:_jsxs(View,{style:G.fieldWrap,children:[_jsx(FieldBase,{testID:z?`${z}-field`:void 0,size:h,variant:P,focused:Q,disabled:c,filled:ce,minHeight:N["min-height"],paddingHorizontal:O?D.space.none:N["padding-x"],radius:U,leading:Ie,trailing:De,topNotch:He.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:I??w,children:_jsx(TextInput,{ref:q,style:[G.input,{fontSize:N.text,color:W.color,...W.weightStyle},T],value:ie,onChangeText:oe,onSubmitEditing:ne,onFocus:Y,onBlur:Z,placeholder:!ze||Q||ce?w:void 0,placeholderTextColor:W.placeholderColor,autoFocus:i,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(D,P).borderFocusedRepresentative,accessibilityLabel:I??w,accessibilityState:{disabled:c},"aria-disabled":c,...H})}),He.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ue||(v[0]?.value??""),disabled:c,haptic:E,labels:M,onChange:pe}):null,Re?_jsx(SearchRecents,{recents:Ce,labels:M,onSelect:ke,onRemove:F?Ee:void 0,onClear:_?Ae:void 0,onHold:Se,onRelease:ge}):null,je?_jsx(SearchSuggestions,{suggestions:xe,query:ie,onSelect:Be,onHold:Se,onRelease:ge}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>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}});export{SearchBar};export default SearchBar;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{scheduleOnRN}from"react-native-worklets";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,s=String(i).split(".")[1]?.length??0,n=s>0?Number(r.toFixed(s)):r;return clamp(n,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),isPair=e=>Array.isArray(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:s=!1,tone:n="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:g,containerStyle:f,trackStyle:p,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;assertValidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Slider","size",e.size,["sm","md","lg"]),assertValidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const A=useTheme(),V=useMemo(()=>{const e=resolveSliderSize(A,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[A,o]),j=useMemo(()=>"default"===l?V:VARIANT_SIZE_MAP[l][o],[V,o,l]),M="inset"===l?j.trackHeight/2:0,_=A.settings.components.slider?.thumbPressAnimation??!1,D=S??1.1,R=k??A.motion.duration.fast,H=C??1,E=useMemo(()=>buildStyles(A,j),[A,j]),O=useMemo(()=>({damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass}),[A.motion.spring.snappy]),[T,P]=useState(0),N=A.colors[n],I=sliderToneInk(A,n),W=!0===e.range,L=useCallback(t=>{if(!0!==e.range){if(Array.isArray(t))throw new Error("Slider received a range value in single mode.");e.onChange?.(t)}else{if(!Array.isArray(t))throw new Error("Slider received a single value in range mode.");e.onChange?.(t)}},[e.onChange,e.range]),[X,B]=useControllableState({value:e.value,defaultValue:e.defaultValue??(W?[a,i]:a),onChange:L}),F=useSharedValue(0),G=useSharedValue(0),z=useSharedValue(isPair(X)?X[0]:X),U=useSharedValue(isPair(X)?X[1]:X),Z=useSharedValue(0),$=useSharedValue(0),J=useSharedValue(1),q=useSharedValue(1),K="always"===u,Q=useSharedValue(K?1:0),Y=useSharedValue(K?1:0),ee=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(F),cancelAnimation(G),cancelAnimation(J),cancelAnimation(q),cancelAnimation(Q),cancelAnimation(Y)},[F,G,J,q,Q,Y]);const te=useCallback((e,t)=>{const r=t-2*M;return i===a||r<=0?M:M+(e-a)/(i-a)*r},[a,i,M]),ae=useCallback((e,t)=>{const s=t-2*M;if(s<=0)return a;const n=clamp((e-M)/s,0,1);return snapToStep(a+n*(i-a),a,i,r)},[a,i,r,M]),ie=useRef(!1),re=A.motion.duration.fast,se=useRef(X);se.current=X;const ne=useRef(T);ne.current=T;const oe=useCallback((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:re,easing:Easing.out(Easing.cubic)}):t,a=se.current;if(isPair(a)){const[e,i]=a,r=Math.min(e,i),s=Math.max(e,i);z.value=r,U.value=s,F.value=place(te(r,t)),G.value=place(te(s,t))}else{const e=a;z.value=e,U.value=e,F.value=place(te(e,t))}},[te,z,U,F,G,re]),[le,ue]=useState(0),ce=useRef(!1),de=useCallback(e=>{ie.current=e,e||(ce.current=!0,ue(e=>e+1))},[]);useEffect(()=>{if(ie.current)return;const e=ce.current;ce.current=!1,oe(e)},[JSON.stringify(X),T,le,oe]);const me=useCallback(e=>{const t=e.nativeEvent.layout.width;$.value=t,P(t)},[$]),he=useCallback((e,t)=>{B(W?[e,t]:e)},[W,B]),be=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),ge=useRef(he);ge.current=he;const fe=useRef(be);fe.current=be;const pe=useCallback((e,t)=>ge.current(e,t),[]),ve=useCallback(()=>fe.current(),[]),we=Math.max(0,(44-j.thumbDiameter)/2),ye=we>0?we:void 0,Se=useCallback(e=>{const t="low"===e?F:G,n="low"===e?z:U,o="low"===e?U:z,l="low"===e?J:q,d="low"===e?Q:Y,m="low"===e,h=a,b=i,g=r,f=ee,p=W,v=D,w=_,y=!0===u,S=c,k=H,C=R,x=O,A=M,follow=e=>{"worklet";const a=$.value-2*A;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(Z.value+e,A),$.value-A);let r=h+(i-A)/a*(b-h);g>0&&(r=Math.round((r-h)/g)*g+h,r=Math.round(r*f)/f),r=Math.min(Math.max(r,h),b),p&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?A:A+(r-h)/(b-h)*a:p?m?Math.min(i,G.value):Math.max(i,F.value):i,r!==n.value&&(n.value=r,r!==h&&r!==b||scheduleOnRN(ve),scheduleOnRN(pe,z.value,U.value))};return{enabled:!s,minDistance:0,...void 0===ye?{}:{hitSlop:ye},onActivate:()=>{"worklet";scheduleOnRN(de,!0),Z.value=t.value,w&&(l.value=withSpring(v,x)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),scheduleOnRN(ve)},onUpdate:e=>{"worklet";follow(e.translationX)},onDeactivate:e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,x)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))},onFinalize:()=>{"worklet";scheduleOnRN(de,!1)}}},[s,a,i,r,ee,W,D,_,u,c,H,R,O,M,ye,pe,ve,de,F,G,z,U,J,q,Q,Y,Z,$]),ke=useMemo(()=>Se("low"),[Se]),Ce=useMemo(()=>Se("high"),[Se]),xe=usePanGesture(ke),Ae=usePanGesture(Ce),Ve=useCallback(e=>{if(s||W||T<=0)return;const t=clamp(e.nativeEvent.locationX,0,T),a=ae(t,T);a!==z.value&&(be(),z.value=a,F.value=withTiming(te(a,T),{duration:A.motion.duration.fast,easing:Easing.out(Easing.cubic)}),he(a,a))},[s,W,T,ae,te,he,be,F,z,A.motion.duration.fast]),je=useCallback(e=>{if(s)return;const t="increment"===e.nativeEvent.actionName?r:-r,n=r>0?Math.round(t*ee)/ee:t;if(W){const e=Math.round((z.value+n)*ee)/ee,t=clamp(e,a,U.value);t!==z.value&&(z.value=t,F.value=te(t,T),be(),he(t,U.value))}else{const e=Math.round((z.value+n)*ee)/ee,t=clamp(e,a,i);t!==z.value&&(z.value=t,F.value=te(t,T),be(),he(t,t))}},[s,r,ee,W,a,i,te,T,F,z,U,he,be]),Me=j.thumbDiameter/2,De=s?A.colors["surface-disabled"]:N,Re="inset"===l?{backgroundColor:De,borderColor:A.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:De,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:A.colors.surface,borderColor:De},He=useAnimatedStyle(()=>{const e=$.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=s?.55:1;if(W){const a=Math.max(0,G.value-F.value+2*M);return{opacity:t,transform:[{translateX:F.value-M},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:F.value+M-e},{scaleX:1}]}},[$,s,W,G,F,M]),Ee=useAnimatedStyle(()=>({transform:[{translateX:F.value-Me},{scale:J.value}]}),[F,Me,J]),Oe=useAnimatedStyle(()=>({transform:[{translateX:G.value-Me},{scale:q.value}]}),[G,Me,q]),Te=useAnimatedStyle(()=>({opacity:Q.value}),[Q]),Pe=useAnimatedStyle(()=>({opacity:Y.value}),[Y]),clampDisplay=e=>clamp(e,a,i),Ne=clampDisplay(isPair(X)?Math.min(...X):X),Ie=clampDisplay(isPair(X)?Math.max(...X):X);return _jsx(View,{ref:t,style:[E.container,f,g],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityValue:W?{min:a,max:i,now:Ne,text:`${Ne} to ${Ie}`}:{min:a,max:i,now:Ne},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:je,children:_jsx(Pressable,{onPress:Ve,disabled:s||W,style:E.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:E.trackWrap,onLayout:me,children:[_jsxs(View,{style:E.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[E.track,{backgroundColor:s?A.colors["surface-disabled"]:A.colors.border},p]}),_jsx(Animated.View,{style:[E.fill,{backgroundColor:s?A.colors["surface-disabled"]:N},v,He]})]}),_jsx(GestureDetector,{gesture:xe,children:_jsx(Animated.View,{style:[E.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Me,...smoothCorners,opacity:s?.55:1},Re,w,Ee],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[E.bubbleWrap,Te],pointerEvents:"none",children:[_jsx(View,{style:[E.bubble,{backgroundColor:N}],children:m?m(Ne):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:I},y],numberOfLines:1,children:d(Ne)})}),_jsx(View,{style:[E.bubbleCaret,{backgroundColor:N}]})]}):null})}),W?_jsx(GestureDetector,{gesture:Ae,children:_jsx(Animated.View,{style:[E.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Me,...smoothCorners,opacity:s?.55:1},Re,w,Oe],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[E.bubbleWrap,Pe],pointerEvents:"none",children:[_jsx(View,{style:[E.bubble,{backgroundColor:N}],children:m?m(Ie):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:I},y],numberOfLines:1,children:d(Ie)})}),_jsx(View,{style:[E.bubbleCaret,{backgroundColor:N}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{scheduleOnRN}from"react-native-worklets";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,s=String(i).split(".")[1]?.length??0,n=s>0?Number(r.toFixed(s)):r;return clamp(n,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),isPair=e=>Array.isArray(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:s=!1,tone:n="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:g,containerStyle:p,trackStyle:f,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;assertValidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Slider","size",e.size,["sm","md","lg"]),assertValidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const A=useTheme(),V=useMemo(()=>{const e=resolveSliderSize(A,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[A,o]),D=useMemo(()=>"default"===l?V:VARIANT_SIZE_MAP[l][o],[V,o,l]),j="inset"===l?D.trackHeight/2:0,M=A.settings.components.slider?.thumbPressAnimation??!1,_=S??1.1,R=k??A.motion.duration.fast,H=C??1,E=useMemo(()=>buildStyles(A,D),[A,D]),O=useMemo(()=>({damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass}),[A.motion.spring.snappy]),[T,I]=useState(0),P=A.colors[n],N=sliderToneInk(A,n),W=!0===e.range,L=useCallback(t=>{if(!0!==e.range){if(Array.isArray(t))throw new Error("Slider received a range value in single mode.");e.onChange?.(t)}else{if(!Array.isArray(t))throw new Error("Slider received a single value in range mode.");e.onChange?.(t)}},[e.onChange,e.range]),[X,B]=useControllableState({value:e.value,defaultValue:e.defaultValue??(W?[a,i]:a),onChange:L}),F=useSharedValue(0),G=useSharedValue(0),z=useSharedValue(isPair(X)?X[0]:X),$=useSharedValue(isPair(X)?X[1]:X),U=useSharedValue(0),Z=useSharedValue(0),J=useSharedValue(1),q=useSharedValue(1),K="always"===u,Q=useSharedValue(K?1:0),Y=useSharedValue(K?1:0),ee=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(F),cancelAnimation(G),cancelAnimation(J),cancelAnimation(q),cancelAnimation(Q),cancelAnimation(Y)},[F,G,J,q,Q,Y]);const te=useCallback((e,t)=>{const r=t-2*j;return i===a||r<=0?j:j+(e-a)/(i-a)*r},[a,i,j]),ae=useCallback((e,t)=>{const s=t-2*j;if(s<=0)return a;const n=clamp((e-j)/s,0,1);return snapToStep(a+n*(i-a),a,i,r)},[a,i,r,j]),ie=useRef(!1),re=A.motion.duration.fast,se=useRef(X);se.current=X;const ne=useRef(T);ne.current=T;const oe=useCallback((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:re,easing:Easing.out(Easing.cubic)}):t,a=se.current;if(isPair(a)){const[e,i]=a,r=Math.min(e,i),s=Math.max(e,i);z.value=r,$.value=s,F.value=place(te(r,t)),G.value=place(te(s,t))}else{const e=a;z.value=e,$.value=e,F.value=place(te(e,t))}},[te,z,$,F,G,re]),[le,ue]=useState(0),ce=useRef(!1),de=useCallback(e=>{ie.current=e,e||(ce.current=!0,ue(e=>e+1))},[]);useEffect(()=>{if(ie.current)return;const e=ce.current;ce.current=!1,oe(e)},[JSON.stringify(X),T,le,oe]);const me=useCallback(e=>{const t=e.nativeEvent.layout.width;Z.value=t,I(t)},[Z]),he=useCallback((e,t)=>{B(W?[e,t]:e)},[W,B]),be=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),ge=useRef(he);ge.current=he;const pe=useRef(be);pe.current=be;const fe=useCallback((e,t)=>ge.current(e,t),[]),ve=useCallback(()=>pe.current(),[]),we=Math.max(0,(44-D.thumbDiameter)/2),ye=we>0?we:void 0,Se=useCallback(e=>{const t="low"===e?F:G,n="low"===e?z:$,o="low"===e?$:z,l="low"===e?J:q,d="low"===e?Q:Y,m="low"===e,h=a,b=i,g=r,p=ee,f=W,v=_,w=M,y=!0===u,S=c,k=H,C=R,A=O,V=j,D=m&&x?`${x}-pan`:void 0,follow=e=>{"worklet";const a=Z.value-2*V;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(U.value+e,V),Z.value-V);let r=h+(i-V)/a*(b-h);g>0&&(r=Math.round((r-h)/g)*g+h,r=Math.round(r*p)/p),r=Math.min(Math.max(r,h),b),f&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?V:V+(r-h)/(b-h)*a:f?m?Math.min(i,G.value):Math.max(i,F.value):i,r!==n.value&&(n.value=r,r!==h&&r!==b||scheduleOnRN(ve),scheduleOnRN(fe,z.value,$.value))};return{enabled:!s,minDistance:0,testID:D,...void 0===ye?{}:{hitSlop:ye},onActivate:()=>{"worklet";scheduleOnRN(de,!0),U.value=t.value,w&&(l.value=withSpring(v,A)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),scheduleOnRN(ve)},onUpdate:e=>{"worklet";follow(e.translationX)},onDeactivate:e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,A)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))},onFinalize:()=>{"worklet";scheduleOnRN(de,!1)}}},[s,a,i,r,ee,W,_,M,u,c,H,R,O,j,ye,x,fe,ve,de,F,G,z,$,J,q,Q,Y,U,Z]),ke=useMemo(()=>Se("low"),[Se]),Ce=useMemo(()=>Se("high"),[Se]),xe=usePanGesture(ke),Ae=usePanGesture(Ce),Ve=useCallback(e=>{if(s||W||T<=0)return;const t=clamp(e.nativeEvent.locationX,0,T),a=ae(t,T);a!==z.value&&(be(),z.value=a,F.value=withTiming(te(a,T),{duration:A.motion.duration.fast,easing:Easing.out(Easing.cubic)}),he(a,a))},[s,W,T,ae,te,he,be,F,z,A.motion.duration.fast]),De=useCallback(e=>{if(s)return;const t="increment"===e.nativeEvent.actionName?r:-r,n=r>0?Math.round(t*ee)/ee:t;if(W){const e=Math.round((z.value+n)*ee)/ee,t=clamp(e,a,$.value);t!==z.value&&(z.value=t,F.value=te(t,T),be(),he(t,$.value))}else{const e=Math.round((z.value+n)*ee)/ee,t=clamp(e,a,i);t!==z.value&&(z.value=t,F.value=te(t,T),be(),he(t,t))}},[s,r,ee,W,a,i,te,T,F,z,$,he,be]),je=D.thumbDiameter/2,Me=s?A.colors["surface-disabled"]:P,Re="inset"===l?{backgroundColor:Me,borderColor:A.colors.surface,borderWidth:Math.max(2,Math.round(.3*D.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:Me,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:A.colors.surface,borderColor:Me},He=useAnimatedStyle(()=>{const e=Z.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=s?.55:1;if(W){const a=Math.max(0,G.value-F.value+2*j);return{opacity:t,transform:[{translateX:F.value-j},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:F.value+j-e},{scaleX:1}]}},[Z,s,W,G,F,j]),Ee=useAnimatedStyle(()=>({transform:[{translateX:F.value-je},{scale:J.value}]}),[F,je,J]),Oe=useAnimatedStyle(()=>({transform:[{translateX:G.value-je},{scale:q.value}]}),[G,je,q]),Te=useAnimatedStyle(()=>({opacity:Q.value}),[Q]),Ie=useAnimatedStyle(()=>({opacity:Y.value}),[Y]),clampDisplay=e=>clamp(e,a,i),Pe=clampDisplay(isPair(X)?Math.min(...X):X),Ne=clampDisplay(isPair(X)?Math.max(...X):X);return _jsx(View,{ref:t,style:[E.container,p,g],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityValue:W?{min:a,max:i,now:Pe,text:`${Pe} to ${Ne}`}:{min:a,max:i,now:Pe},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:De,children:_jsx(Pressable,{onPress:Ve,disabled:s||W,style:E.trackTouch,testID:x?`${x}-track-press`:void 0,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:E.trackWrap,onLayout:me,testID:x?`${x}-track`:void 0,children:[_jsxs(View,{style:E.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[E.track,{backgroundColor:s?A.colors["surface-disabled"]:A.colors.border},f]}),_jsx(Animated.View,{style:[E.fill,{backgroundColor:s?A.colors["surface-disabled"]:P},v,He],testID:x?`${x}-fill`:void 0})]}),_jsx(GestureDetector,{gesture:xe,children:_jsx(Animated.View,{style:[E.thumb,{width:D.thumbDiameter,height:D.thumbDiameter,borderRadius:je,...smoothCorners,opacity:s?.55:1},Re,w,Ee],testID:x?`${x}-thumb`:void 0,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[E.bubbleWrap,Te],pointerEvents:"none",children:[_jsx(View,{style:[E.bubble,{backgroundColor:P}],children:m?m(Pe):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:N},y],numberOfLines:1,children:d(Pe)})}),_jsx(View,{style:[E.bubbleCaret,{backgroundColor:P}]})]}):null})}),W?_jsx(GestureDetector,{gesture:Ae,children:_jsx(Animated.View,{style:[E.thumb,{width:D.thumbDiameter,height:D.thumbDiameter,borderRadius:je,...smoothCorners,opacity:s?.55:1},Re,w,Oe],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[E.bubbleWrap,Ie],pointerEvents:"none",children:[_jsx(View,{style:[E.bubble,{backgroundColor:P}],children:m?m(Ne):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:N},y],numberOfLines:1,children:d(Ne)})}),_jsx(View,{style:[E.bubbleCaret,{backgroundColor:P}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;