@webority/mobile-ui 0.156.0 → 0.158.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 (111) hide show
  1. package/canvas-kit.json +1 -1
  2. package/dist/canvas-kit/kit.js +5 -5
  3. package/dist/canvas-kit/manifest.json +17 -12
  4. package/dist/canvas-kit/release.json +7 -7
  5. package/lib/commonjs/components/AppBar/AppBar.js +1 -1
  6. package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
  7. package/lib/commonjs/components/AppIcon/index.js +1 -1
  8. package/lib/commonjs/components/Banner/Banner.js +1 -1
  9. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  10. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  11. package/lib/commonjs/components/Button/Button.js +1 -1
  12. package/lib/commonjs/components/Button/index.js +1 -1
  13. package/lib/commonjs/components/Carousel/Carousel.js +1 -1
  14. package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
  15. package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
  16. package/lib/commonjs/components/Confetti/Confetti.js +1 -1
  17. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  18. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  19. package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
  20. package/lib/commonjs/components/MessageList/MessageList.js +1 -1
  21. package/lib/commonjs/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
  22. package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
  23. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  24. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  25. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  26. package/lib/commonjs/components/Radio/Radio.js +1 -1
  27. package/lib/commonjs/components/Radio/RadioGroup.js +1 -1
  28. package/lib/commonjs/components/Rating/Rating.js +1 -1
  29. package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
  30. package/lib/commonjs/components/SearchBar/useRecentSearches.js +1 -1
  31. package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
  32. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  33. package/lib/commonjs/components/Skeleton/SkeletonList.js +1 -1
  34. package/lib/commonjs/components/Slider/valueText.js +1 -1
  35. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  36. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  37. package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
  38. package/lib/commonjs/components/Toast/Toast.js +1 -1
  39. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  40. package/lib/commonjs/hooks/useControllableState.js +1 -1
  41. package/lib/commonjs/icons.js +1 -1
  42. package/lib/commonjs/index.js +1 -1
  43. package/lib/module/components/AppBar/AppBar.js +1 -1
  44. package/lib/module/components/AppIcon/AppIcon.js +1 -1
  45. package/lib/module/components/AppIcon/index.js +1 -1
  46. package/lib/module/components/Banner/Banner.js +1 -1
  47. package/lib/module/components/BarChart/BarChart.js +1 -1
  48. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  49. package/lib/module/components/Button/Button.js +1 -1
  50. package/lib/module/components/Button/index.js +1 -1
  51. package/lib/module/components/Carousel/Carousel.js +1 -1
  52. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  53. package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
  54. package/lib/module/components/Confetti/Confetti.js +1 -1
  55. package/lib/module/components/Drawer/Drawer.js +1 -1
  56. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  57. package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
  58. package/lib/module/components/MessageList/MessageList.js +1 -1
  59. package/lib/module/components/NonModalBottomSheet/NonModalBottomSheet.js +1 -1
  60. package/lib/module/components/NumberInput/NumberInput.js +1 -1
  61. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  62. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  63. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  64. package/lib/module/components/Radio/Radio.js +1 -1
  65. package/lib/module/components/Radio/RadioGroup.js +1 -1
  66. package/lib/module/components/Rating/Rating.js +1 -1
  67. package/lib/module/components/SearchBar/SearchBar.js +1 -1
  68. package/lib/module/components/SearchBar/useRecentSearches.js +1 -1
  69. package/lib/module/components/Skeleton/Skeleton.js +1 -1
  70. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  71. package/lib/module/components/Skeleton/SkeletonList.js +1 -1
  72. package/lib/module/components/Slider/valueText.js +1 -1
  73. package/lib/module/components/Stepper/Stepper.js +1 -1
  74. package/lib/module/components/TagInput/TagInput.js +1 -1
  75. package/lib/module/components/TimePicker/TimePicker.js +1 -1
  76. package/lib/module/components/Toast/Toast.js +1 -1
  77. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  78. package/lib/module/hooks/useControllableState.js +1 -1
  79. package/lib/module/icons.js +1 -1
  80. package/lib/module/index.js +1 -1
  81. package/lib/typescript/commonjs/components/AppIcon/AppIcon.d.ts +2 -0
  82. package/lib/typescript/commonjs/components/AppIcon/index.d.ts +1 -1
  83. package/lib/typescript/commonjs/components/Button/Button.d.ts +4 -0
  84. package/lib/typescript/commonjs/components/Button/index.d.ts +1 -1
  85. package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +7 -4
  86. package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +14 -6
  87. package/lib/typescript/commonjs/components/FieldBase/ChoiceText.d.ts +6 -5
  88. package/lib/typescript/commonjs/components/FilePicker/FilePicker.d.ts +2 -2
  89. package/lib/typescript/commonjs/components/ProfilePicker/ProfilePicker.d.ts +15 -9
  90. package/lib/typescript/commonjs/components/Radio/Radio.d.ts +7 -4
  91. package/lib/typescript/commonjs/components/Radio/RadioGroup.d.ts +5 -0
  92. package/lib/typescript/commonjs/components/Switch/Switch.d.ts +4 -4
  93. package/lib/typescript/commonjs/hooks/useControllableState.d.ts +23 -8
  94. package/lib/typescript/commonjs/icons.d.ts +1 -1
  95. package/lib/typescript/commonjs/index.d.ts +2 -1
  96. package/lib/typescript/module/components/AppIcon/AppIcon.d.ts +2 -0
  97. package/lib/typescript/module/components/AppIcon/index.d.ts +1 -1
  98. package/lib/typescript/module/components/Button/Button.d.ts +4 -0
  99. package/lib/typescript/module/components/Button/index.d.ts +1 -1
  100. package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +7 -4
  101. package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +14 -6
  102. package/lib/typescript/module/components/FieldBase/ChoiceText.d.ts +6 -5
  103. package/lib/typescript/module/components/FilePicker/FilePicker.d.ts +2 -2
  104. package/lib/typescript/module/components/ProfilePicker/ProfilePicker.d.ts +15 -9
  105. package/lib/typescript/module/components/Radio/Radio.d.ts +7 -4
  106. package/lib/typescript/module/components/Radio/RadioGroup.d.ts +5 -0
  107. package/lib/typescript/module/components/Switch/Switch.d.ts +4 -4
  108. package/lib/typescript/module/hooks/useControllableState.d.ts +23 -8
  109. package/lib/typescript/module/icons.d.ts +1 -1
  110. package/lib/typescript/module/index.d.ts +2 -1
  111. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){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["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:f,accessibilityHint:b,haptic:g,style:h,containerStyle:y,labelStyle:A,testID:S}=e;assertValidValue("FloatingActionButton","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",e.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const v=!u&&!d,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),E=useMemo(()=>buildStyles(x),[x]),{scale:R,opacity:I,pressIn:F,pressOut:C}=usePressAnimation({enabled:v}),V=usePresenceMotion(),j=x.space[x.components["floating-action-button"]["edge-offset"]],T=x.space[x.components["floating-action-button"]["bottom-offset"]],B=useRef(createAnimatedValue(1)).current,P=V.duration("default");useEffect(()=>{if(!m)return void setNativeValue(B,1);const e=Animated.timing(B,{toValue:p?0:1,duration:P,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[m,p,B,P,x.motion.ease["in-out"]]);const k=w.diameter+(c??T)+_.bottom+j,D=B.interpolate({inputRange:[0,1],outputRange:V.range(k,0)}),O=useMemo(()=>Animated.multiply(B,I),[B,I]),L="string"==typeof i&&i.length>0,N=L&&s,z=V.reduced,M=x.space.sm,G=w["label-padding-x"],H=x.motion.duration.fast,$=x.motion.ease["in-out"],U=useSharedValue(N?1:0),[W,Y]=useState(null);useEffect(()=>{const e=N?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[N,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)}),[G,U]),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}},[U,W,M]),X=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:w.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??T)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:j}}},[l,c,_.bottom,T,j]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:D},{scale:R}],opacity:O},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!v)return;const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!v,accessibilityRole:"button",accessibilityLabel:f,accessibilityHint:b,accessibilityState:{disabled:!v,busy:d},"aria-disabled":!v,"aria-busy":d,testID:S,style:[E.base,L?{height:w.diameter,minWidth:w.diameter,borderRadius:w.diameter/2,...smoothCorners}:{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&v?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:w.diameter/2,...smoothCorners}]}):null,L?_jsxs(Reanimated.View,{style:[E.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[E.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[E.label,{color:J,fontSize:w.text,fontWeight:x.weight.semibold,marginLeft:M},A],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:f=!1,containerStyle:b,secondaryActionStyle:g,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),v=d??S.quickActions,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,u),[x,u]),E=useMemo(()=>buildGroupStyles(x),[x]),R=usePresenceMotion(),I=R.duration("default"),F=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],V=x.space[x.components["floating-action-button"]["secondary-gap"]],j=x.components["floating-action-button"]["stagger-ms"],T=useMemo(()=>n.slice(0,6),[n]),B=T.length,P=useMemo(()=>T.map((e,t)=>({action:e,index:t})).reverse(),[T]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const D="boolean"==typeof i,[O,L]=useState(s),N="boolean"==typeof i?i:O,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:f?0:1,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[p,f,z,I,x.motion.ease["in-out"]]);const M=p&&f;useEffect(()=>{M&&N&&(D||L(!1),r?.(!1))},[M,N,D,r]);const G=w.diameter+(c??C)+_.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),$=z,U=useRef(createAnimatedValue(N?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==B){if(e.length<B){const t=e.slice();for(let o=e.length;o<B;o+=1)t.push(new Animated.Value(N?1:0));W.current=t}else W.current=e.slice(0,B);Z(e=>e+1)}},[B]),useEffect(()=>{const e=Animated.timing(U,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver})),o=N?t:[...t].reverse(),n=Animated.stagger(j,o);return n.start(),()=>{e.stop(),n.stop()}},[N,U,I,x.motion.ease["in-out"],B,Y,j]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),D||L(e),r?.(e)},[D,r,m]),Q=useRef(null),X=useRef(N),J=useRef(!1);useEffect(()=>{if(X.current===N)return;X.current=N;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?"focus"in t&&"function"==typeof t.focus&&t.focus():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(N?S.expanded(v,B):S.collapsed(v))},[N,M,v,B,S]);const K=useCallback(()=>{q(!N)},[N,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),D||L(!1),r?.(!1)},[D,r,m]),te=useCallback(()=>{N&&q(!1)},[N,q]);useEffect(()=>{if(!N)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[N,q]),useEffect(()=>{if(!N||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[N,q]);const oe=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,C,F]),slotOffset=e=>-(w.diameter+V)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),ie=.78*w.diameter,se=useMemo(()=>{const e=ie+x.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:w.diameter/2+ie/2+x.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,ie,w.diameter,x.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[N?_jsx(Animated.View,{pointerEvents:N?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:x.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},b],accessibilityRole:"menu",testID:A,children:[P.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),s=toneBackground(x,e.tone??"primary"),r=toneForeground(x,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[E.labelSlot,se],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[E.labelPill,x.shadow.card,{backgroundColor:x.colors.surface,paddingHorizontal:x.space.sm,paddingVertical:x.space.xs,borderRadius:x.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:x.colors["text-body"],fontSize:x.text.sm.size,fontWeight:x.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:N?"auto":"none",accessibilityElementsHidden:!N,importantForAccessibility:N?"auto":"no-hide-descendants","aria-hidden":!N,style:[E.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:N,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[E.fabBase,x.shadow.elevated,{width:ie,height:ie,borderRadius:ie/2,...smoothCorners,backgroundColor:s},g],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,e.tone??"primary"),borderRadius:ie/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:w.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:v,accessibilityState:{expanded:N},"aria-expanded":N,style:[E.fabBase,x.shadow.popover,{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners,backgroundColor:x.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:w.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(N&&o?o:t,{color:x.colors["on-primary"],size:w.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){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["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:f,accessibilityHint:b,haptic:g,style:h,containerStyle:y,labelStyle:A,testID:S}=e;assertValidValue("FloatingActionButton","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButton","tone",e.tone,FAB_TONES),assertValidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const v=!u&&!d,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),E=useMemo(()=>buildStyles(x),[x]),{scale:R,opacity:I,pressIn:F,pressOut:C}=usePressAnimation({enabled:v}),V=usePresenceMotion(),j=x.space[x.components["floating-action-button"]["edge-offset"]],T=x.space[x.components["floating-action-button"]["bottom-offset"]],B=useRef(createAnimatedValue(1)).current,P=V.duration("default");useEffect(()=>{if(!m)return void setNativeValue(B,1);const e=Animated.timing(B,{toValue:p?0:1,duration:P,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[m,p,B,P,x.motion.ease["in-out"]]);const k=w.diameter+(c??T)+_.bottom+j,D=B.interpolate({inputRange:[0,1],outputRange:V.range(k,0)}),O=useMemo(()=>Animated.multiply(B,I),[B,I]),L="string"==typeof i&&i.length>0,N=L&&s,z=V.reduced,M=x.space.sm,G=w["label-padding-x"],H=x.motion.duration.fast,$=x.motion.ease["in-out"],U=useSharedValue(N?1:0),[W,Y]=useState(null);useEffect(()=>{const e=N?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[N,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)}),[G,U]),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}},[U,W,M]),X=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:w.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??T)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:j};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:j}}},[l,c,_.bottom,T,j]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:D},{scale:R}],opacity:O},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!v)return;const t=resolveHaptic(g,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!v,accessibilityRole:"button",accessibilityLabel:f,accessibilityHint:b,accessibilityState:{disabled:!v,busy:d},"aria-disabled":!v,"aria-busy":d,testID:S,style:[E.base,L?{height:w.diameter,minWidth:w.diameter,borderRadius:w.diameter/2,...smoothCorners}:{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&v?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:w.diameter/2,...smoothCorners}]}):null,L?_jsxs(Reanimated.View,{style:[E.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[E.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[E.label,{color:J,fontSize:w.text,fontWeight:x.weight.semibold,marginLeft:M},A],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:f=!1,containerStyle:b,secondaryActionStyle:g,labelPillStyle:h,labelStyle:y,testID:A}=e;assertValidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),assertValidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),v=d??S.quickActions,x=useTheme(),_=useSafeAreaInsets(),w=useMemo(()=>resolveFloatingActionButtonSize(x,u),[x,u]),E=useMemo(()=>buildGroupStyles(x),[x]),R=usePresenceMotion(),I=R.duration("default"),F=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],V=x.space[x.components["floating-action-button"]["secondary-gap"]],j=x.components["floating-action-button"]["stagger-ms"],T=useMemo(()=>n.slice(0,6),[n]),B=T.length,P=useMemo(()=>T.map((e,t)=>({action:e,index:t})).reverse(),[T]);n.forEach(e=>{assertValidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const D="boolean"==typeof i,[O,L]=useState(s),N="boolean"==typeof i?i:O,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:f?0:1,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[p,f,z,I,x.motion.ease["in-out"]]);const M=p&&f;useEffect(()=>{M&&N&&(D||L(!1),r?.(!1))},[M,N,D,r]);const G=w.diameter+(c??C)+_.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:R.range(G,0)}),$=z,U=useRef(createAnimatedValue(N?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==B){if(e.length<B){const t=e.slice();for(let o=e.length;o<B;o+=1)t.push(new Animated.Value(N?1:0));W.current=t}else W.current=e.slice(0,B);Z(e=>e+1)}},[B,N]),useEffect(()=>{const e=Animated.timing(U,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:N?1:0,duration:I,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:nativeDriver})),o=N?t:[...t].reverse(),n=Animated.stagger(j,o);return n.start(),()=>{e.stop(),n.stop()}},[N,U,I,x.motion.ease["in-out"],B,Y,j]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),D||L(e),r?.(e)},[D,r,m]),Q=useRef(null),X=useRef(N),J=useRef(!1);useEffect(()=>{if(X.current===N)return;X.current=N;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?"focus"in t&&"function"==typeof t.focus&&t.focus():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(N?S.expanded(v,B):S.collapsed(v))},[N,M,v,B,S]);const K=useCallback(()=>{q(!N)},[N,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),D||L(!1),r?.(!1)},[D,r,m]),te=useCallback(()=>{N&&q(!1)},[N,q]);useEffect(()=>{if(!N)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[N,q]),useEffect(()=>{if(!N||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[N,q]);const oe=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,C,F]),slotOffset=e=>-(w.diameter+V)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),ie=.78*w.diameter,se=useMemo(()=>{const e=ie+x.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:w.diameter/2+ie/2+x.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,ie,w.diameter,x.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(R.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[N?_jsx(Animated.View,{pointerEvents:N?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:x.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},b],accessibilityRole:"menu",testID:A,children:[P.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:R.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:R.range(.6,1)}),s=toneBackground(x,e.tone??"primary"),r=toneForeground(x,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[E.labelSlot,se],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[E.labelPill,x.shadow.card,{backgroundColor:x.colors.surface,paddingHorizontal:x.space.sm,paddingVertical:x.space.xs,borderRadius:x.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:x.colors["text-body"],fontSize:x.text.sm.size,fontWeight:x.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:N?"auto":"none",accessibilityElementsHidden:!N,importantForAccessibility:N?"auto":"no-hide-descendants","aria-hidden":!N,style:[E.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:N,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[E.fabBase,x.shadow.elevated,{width:ie,height:ie,borderRadius:ie/2,...smoothCorners,backgroundColor:s},g],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:pressedTintFor(x,e.tone??"primary"),borderRadius:ie/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:w.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:v,accessibilityState:{expanded:N},"aria-expanded":N,style:[E.fabBase,x.shadow.popover,{width:w.diameter,height:w.diameter,borderRadius:w.diameter/2,...smoothCorners,backgroundColor:x.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[E.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:w.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(N&&o?o:t,{color:x.colors["on-primary"],size:w.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
@@ -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,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";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);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:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):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";runOnJS(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,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";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";runOnJS(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{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"});const JUMP_AT=160,FOLLOW_AT=48,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:160},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";export function MessageList({messages:e,keyExtractor:t,renderMessage:o,getAuthorKey:s,getDate:n,firstUnreadKey:r,onLoadOlder:a,loadingOlder:i=!1,hasOlder:l=!0,typing:d,empty:u,getAnnouncement:c,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:y,now:x,onScroll:g,onContentSizeChange:b,contentContainerStyle:S,style:h,testID:j,...w}){const L=useTheme(),_=useSafeAreaInsets(),v=useReducedMotion(),C=useMemo(()=>buildStyles(L),[L]),E=useMemo(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...y}),[y]),T=f??_.bottom,O=useRef(null),I=useRef(!1),k=useRef(!0),M=useRef(0),[A,D]=useState(!1),[V,P]=useState(0),R=useMemo(()=>{const o=n?e.map(e=>formatDate(n(e))):null,a=s?e.map(s):null,i=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,s)=>{const r=s===e.length-1,l=null!==o&&(r||o[s]!==o[s+1]),d=null!==a&&!r&&a[s+1]===a[s]&&!l&&s!==i,u=null!==a&&s>0&&a[s-1]===a[s]&&(null===o||o[s-1]===o[s])&&s-1!==i;return{groupPosition:positionOf(d,u),day:l&&n?dayLabel(n(t),{now:x,labels:E}):null,unread:s===i}})},[e,n,s,r,t,x,E]),B=useCallback(()=>{k.current=!0,O.current?.scrollToOffset({offset:0,animated:!v}),P(0)},[v]),F=e[0],z=void 0===F?null:t(F),K=useRef(z);useEffect(()=>{const o=K.current;if(K.current=z,null===o||null===z||o===z)return;const s=e.findIndex(e=>t(e)===o);if(-1===s)return void P(0);const n=e.slice(0,s).reverse();for(const e of n){const t=c?.(e);t&&announce(t)}m&&n.some(m)?B():I.current&&P(e=>e+n.length)},[z]);const N=useCallback(e=>{k.current=e.nativeEvent.contentOffset.y<=48;const t=e.nativeEvent.contentOffset.y>160;t!==I.current&&(I.current=t,D(t),t||P(0)),g?.(e)},[g]),U=useCallback((e,t)=>{const o=t>M.current;M.current=t,o&&k.current&&O.current?.scrollToOffset({offset:0,animated:!1}),b?.(e,t)},[b]),$=useCallback(()=>{l&&!i&&a?.()},[l,i,a]),G=useCallback(({item:e,index:t})=>{const s=R[t];return _jsxs(View,{children:[s?.day?_jsx(DateSeparator,{label:s.day}):null,s?.unread?_jsx(DateSeparator,{label:E.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:s?.groupPosition??"single"})]})},[R,E.unread,o]),H=useCallback(e=>t(e),[t]),J=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:T}),[T]),W=V>0?`${E.newMessages(V)}. ${E.jumpToLatest}`:E.jumpToLatest;return _jsxs(View,{style:[C.root,h],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...w,ref:O,data:e,renderItem:G,keyExtractor:H,inverted:!0,onScroll:N,onContentSizeChange:U,onEndReached:a?$:void 0,ListHeaderComponent:d?_jsx(View,{children:d}):void 0,ListFooterComponent:i?_jsx(Spinner,{size:"sm",accessibilityLabel:E.loadingOlder,style:C.older}):void 0,ListEmptyComponent:u?_jsx(View,{style:C.fill,children:u}):void 0,renderScrollComponent:p?J:void 0,contentContainerStyle:[C.content,0===e.length?C.grow:null,S],testID:j}),A?_jsxs(View,{style:C.jump,pointerEvents:"box-none",children:[_jsx(View,{style:C.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:W,variant:"ghost",tone:"neutral",onPress:B,testID:j?`${j}-jump`:void 0})}),V>0?_jsx(View,{style:C.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:_jsx(Badge,{value:V,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});export default MessageList;
1
+ "use strict";import{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"});const JUMP_AT=160,FOLLOW_AT=48,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:160},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";export function MessageList({messages:e,keyExtractor:t,renderMessage:o,getAuthorKey:s,getDate:n,firstUnreadKey:r,onLoadOlder:a,loadingOlder:i=!1,hasOlder:l=!0,typing:d,empty:u,getAnnouncement:c,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:y,now:x,onScroll:g,onContentSizeChange:b,contentContainerStyle:S,style:h,testID:j,...w}){const L=useTheme(),_=useSafeAreaInsets(),v=useReducedMotion(),C=useMemo(()=>buildStyles(L),[L]),E=useMemo(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...y}),[y]),T=f??_.bottom,O=useRef(null),I=useRef(!1),k=useRef(!0),M=useRef(0),[A,D]=useState(!1),[V,P]=useState(0),R=useMemo(()=>{const o=n?e.map(e=>formatDate(n(e))):null,a=s?e.map(s):null,i=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,s)=>{const r=s===e.length-1,l=null!==o&&(r||o[s]!==o[s+1]),d=null!==a&&!r&&a[s+1]===a[s]&&!l&&s!==i,u=null!==a&&s>0&&a[s-1]===a[s]&&(null===o||o[s-1]===o[s])&&s-1!==i;return{groupPosition:positionOf(d,u),day:l&&n?dayLabel(n(t),{now:x,labels:E}):null,unread:s===i}})},[e,n,s,r,t,x,E]),B=useCallback(()=>{k.current=!0,O.current?.scrollToOffset({offset:0,animated:!v}),P(0)},[v]),F=e[0],z=void 0===F?null:t(F),K=useRef(z);useEffect(()=>{const o=K.current;if(K.current=z,null===o||null===z||o===z)return;const s=e.findIndex(e=>t(e)===o);if(-1===s)return void P(0);const n=e.slice(0,s).reverse();for(const e of n){const t=c?.(e);t&&announce(t)}m&&n.some(m)?B():I.current&&P(e=>e+n.length)},[z,e,t,c,m,B]);const N=useCallback(e=>{k.current=e.nativeEvent.contentOffset.y<=48;const t=e.nativeEvent.contentOffset.y>160;t!==I.current&&(I.current=t,D(t),t||P(0)),g?.(e)},[g]),U=useCallback((e,t)=>{const o=t>M.current;M.current=t,o&&k.current&&O.current?.scrollToOffset({offset:0,animated:!1}),b?.(e,t)},[b]),$=useCallback(()=>{l&&!i&&a?.()},[l,i,a]),G=useCallback(({item:e,index:t})=>{const s=R[t];return _jsxs(View,{children:[s?.day?_jsx(DateSeparator,{label:s.day}):null,s?.unread?_jsx(DateSeparator,{label:E.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:s?.groupPosition??"single"})]})},[R,E.unread,o]),H=useCallback(e=>t(e),[t]),J=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:T}),[T]),W=V>0?`${E.newMessages(V)}. ${E.jumpToLatest}`:E.jumpToLatest;return _jsxs(View,{style:[C.root,h],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...w,ref:O,data:e,renderItem:G,keyExtractor:H,inverted:!0,onScroll:N,onContentSizeChange:U,onEndReached:a?$:void 0,ListHeaderComponent:d?_jsx(View,{children:d}):void 0,ListFooterComponent:i?_jsx(Spinner,{size:"sm",accessibilityLabel:E.loadingOlder,style:C.older}):void 0,ListEmptyComponent:u?_jsx(View,{style:C.fill,children:u}):void 0,renderScrollComponent:p?J:void 0,contentContainerStyle:[C.content,0===e.length?C.grow:null,S],testID:j}),A?_jsxs(View,{style:C.jump,pointerEvents:"box-none",children:[_jsx(View,{style:C.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:W,variant:"ghost",tone:"neutral",onPress:B,testID:j?`${j}-jump`:void 0})}),V>0?_jsx(View,{style:C.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:_jsx(Badge,{value:V,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});export default MessageList;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useEffectEvent,useMemo,useRef,useState}from"react";import{Dimensions,ScrollView,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=Object.freeze({dragHandle:"Drag handle"});const ERROR_PREFIX="[@webority/mobile-ui] NonModalBottomSheet: ",SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,OVERSHOOT_TO_CLOSE=80,PERCENT_PATTERN=/^(\d+(?:\.\d+)?|\.\d+)%$/,parsePercent=e=>{if("string"!=typeof e)return;const t=PERCENT_PATTERN.exec(e);if(!t)return;const n=Number(t[1]);return n>0&&n<=100?n:void 0},isValidSnapPoint=e=>"number"==typeof e?Number.isFinite(e)&&e>0:void 0!==parsePercent(e),validateProps=(e,t)=>{if(0===e.length)throw new Error(`${ERROR_PREFIX}snapPoints needs at least one snap point.`);for(const t of e)if(!isValidSnapPoint(t))throw new Error(`${ERROR_PREFIX}snap point ${String(t)} is not a positive number or a percentage up to 100%.`);if(null!=t&&(!Number.isInteger(t)||t<0||t>=e.length))throw new Error(`${ERROR_PREFIX}snapIndex ${t} is outside the snap points.`)},resolveNonModalSnapPoints=(e,t)=>e.map(e=>"number"==typeof e?e:parseFloat(e)/100*t).sort((e,t)=>e-t),topAt=(e,t,n)=>{const o=e[n];if(void 0===o)throw new Error(`${ERROR_PREFIX}snap index ${n} has no snap point.`);return Math.max(0,t-o)},NonModalBottomSheet=e=>{const{open:t,onClose:n,snapPoints:o,snapIndex:s,onSnapChange:r,enablePanDownToClose:i=!0,scrollable:a=!1,title:l,header:c,footer:u,labels:d,handleIndicatorStyle:h,containerStyle:m,children:p,accessibilityLabel:f,testID:E}=e;validateProps(o,s);const S=useMemo(()=>({...DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS,...d}),[d]),v=useTheme(),b=usePresenceMotion(),g=b.reduced,R=useMemo(()=>buildStyles(v),[v]),[_,w]=useState(()=>Dimensions.get("window").height),x=useCallback(e=>{const t=e.nativeEvent.layout.height;t>0&&w(t)},[]),y=useMemo(()=>resolveNonModalSnapPoints(o,_),[o,_]),O=y[y.length-1]??0,T=_,C=Math.max(0,_-O),N=useCallback(e=>topAt(y,_,e),[y,_]),[P,M]=useState(!1),[I,A]=useState(-1),j=useRef(-1),D=useRef(n);D.current=n;const V=useRef(r);V.current=r;const L=useSharedValue(T),k=useSharedValue(T),F=useCallback(()=>{j.current<0&&M(!1)},[]),$=useCallback(()=>{if(j.current=-1,A(-1),g)return L.value=T,void F();L.value=withTiming(T,{duration:b.duration("fast"),easing:Easing.bezier(...v.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(F)()})},[T,b,g,v.motion.ease.accelerate,L,F]),B=useCallback(e=>{const t=N(e);L.value=g?t:withSpring(t,SPRING_CONFIG)},[g,N,L]),G=useCallback((e,t)=>{e!==j.current&&(j.current=e,A(e),B(e),t&&V.current?.(e))},[B]),H=useEffectEvent(e=>{if(!e)return void(j.current>=0&&$());const t=s??0;M(!0);const n=N(t);g?L.value=n:(L.value=T,L.value=withSpring(n,SPRING_CONFIG)),j.current=t,A(t)});useEffect(()=>{H(t)},[t]);const J=useEffectEvent(e=>{t&&P&&e!==j.current&&G(e,!1)});useEffect(()=>{null!=s&&J(s)},[s]);const U=useEffectEvent(e=>{const t=j.current;t>=0&&(L.value=topAt(y,e,t))});useEffect(()=>{U(_)},[_]);const X=useCallback(e=>{if(e<0)return triggerHaptic("selection"),$(),void D.current();e!==j.current?G(e,!0):B(e)},[G,B,$]),Y=useCallback(e=>{const t=j.current;t<0||G(Math.min(Math.max(t+e,0),y.length-1),!0)},[G,y.length]),z=useMemo(()=>y.map(e=>_-e),[y,_]),q=useMemo(()=>{const e=z,t=C,n=i;return{testID:E?`${E}-pan-gesture`:"non-modal-bottom-sheet-pan-gesture",activeOffsetY:[-10,10],onActivate:()=>{"worklet";k.value=L.value},onUpdate:e=>{"worklet";const n=k.value+e.translationY;L.value=n<t?t+.25*(n-t):n},onDeactivate:t=>{"worklet";const o=L.value,s=e[0];if(void 0===s)return;if(t.velocityY>1e3)return void runOnJS(X)(n?-1:0);if(n&&o-s>80)return void runOnJS(X)(-1);let r=0,i=1/0,a=0;for(const t of e){const e=Math.abs(o-t);e<i&&(i=e,r=a),a++}runOnJS(X)(r)}}},[k,i,X,C,z,E,L]),K=usePanGesture(q),Q=useAnimatedStyle(()=>({top:L.value<C?C:L.value}),[C]),W=useAnimatedStyle(()=>{const e=L.value<C?C:L.value,t=_-e;return{height:t<0?0:t>O?O:t}},[_,O,C]);return P?_jsx(View,{collapsable:!1,style:StyleSheet.absoluteFill,pointerEvents:"box-none",onLayout:x,testID:E,children:_jsx(Animated.View,{accessibilityLabel:f,testID:E?`${E}-sheet`:void 0,style:[R.sheet,{height:O,backgroundColor:v.colors.surface,borderTopLeftRadius:v.radius.xl,borderTopRightRadius:v.radius.xl,...smoothCorners,...v.shadow.modal},m,Q],children:_jsxs(Animated.View,{style:[R.body,W],children:[_jsx(GestureDetector,{gesture:K,children:_jsx(View,{style:R.handleRow,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:S.dragHandle,accessibilityHint:"Swipe up or down to change the height of the sheet",accessibilityValue:{text:`Snap point ${I+1} of ${y.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName?Y(1):"decrement"===e.nativeEvent.actionName&&Y(-1)},testID:E?`${E}-handle`:void 0,children:_jsx(View,{style:[R.handle,{backgroundColor:v.colors.border},h]})})}),null!=l?_jsx(Text,{variant:"title",accessibilityRole:"header",children:l}):null,c,a?_jsx(ScrollView,{style:R.scrollContent,children:p}):_jsx(View,{style:R.content,children:p}),u]})})}):null};NonModalBottomSheet.displayName="NonModalBottomSheet";const buildStyles=e=>StyleSheet.create({sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1}});export{NonModalBottomSheet};export default NonModalBottomSheet;
1
+ "use strict";import{useCallback,useEffect,useEffectEvent,useMemo,useRef,useState}from"react";import{Dimensions,ScrollView,StyleSheet,View}from"react-native";import{GestureDetector,usePanGesture}from"react-native-gesture-handler";import Animated,{Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{PRESENCE_REDUCE_MOTION,usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS=Object.freeze({dragHandle:"Drag handle"});const ERROR_PREFIX="[@webority/mobile-ui] NonModalBottomSheet: ",SPRING_CONFIG={damping:20,stiffness:240,mass:1},CLOSE_VELOCITY_THRESHOLD=1e3,DRAG_ACTIVATION_OFFSET=10,OVERSHOOT_TO_CLOSE=80,PERCENT_PATTERN=/^(\d+(?:\.\d+)?|\.\d+)%$/,parsePercent=e=>{if("string"!=typeof e)return;const t=PERCENT_PATTERN.exec(e);if(!t)return;const n=Number(t[1]);return n>0&&n<=100?n:void 0},isValidSnapPoint=e=>"number"==typeof e?Number.isFinite(e)&&e>0:void 0!==parsePercent(e),validateProps=(e,t)=>{if(0===e.length)throw new Error(`${ERROR_PREFIX}snapPoints needs at least one snap point.`);for(const t of e)if(!isValidSnapPoint(t))throw new Error(`${ERROR_PREFIX}snap point ${String(t)} is not a positive number or a percentage up to 100%.`);if(null!=t&&(!Number.isInteger(t)||t<0||t>=e.length))throw new Error(`${ERROR_PREFIX}snapIndex ${t} is outside the snap points.`)},resolveNonModalSnapPoints=(e,t)=>e.map(e=>"number"==typeof e?e:parseFloat(e)/100*t).sort((e,t)=>e-t),topAt=(e,t,n)=>{const o=e[n];if(void 0===o)throw new Error(`${ERROR_PREFIX}snap index ${n} has no snap point.`);return Math.max(0,t-o)},NonModalBottomSheet=e=>{const{open:t,onClose:n,snapPoints:o,snapIndex:s,onSnapChange:r,enablePanDownToClose:a=!0,scrollable:i=!1,title:l,header:c,footer:u,labels:d,handleIndicatorStyle:h,containerStyle:m,children:p,accessibilityLabel:f,testID:E}=e;validateProps(o,s);const S=useMemo(()=>({...DEFAULT_NON_MODAL_BOTTOM_SHEET_LABELS,...d}),[d]),b=useTheme(),v=usePresenceMotion(),g=v.reduced,R=useMemo(()=>buildStyles(b),[b]),[_,x]=useState(()=>Dimensions.get("window").height),w=useCallback(e=>{const t=e.nativeEvent.layout.height;t>0&&x(t)},[]),y=useMemo(()=>resolveNonModalSnapPoints(o,_),[o,_]),O=y[y.length-1]??0,T=_,C=Math.max(0,_-O),M=useCallback(e=>topAt(y,_,e),[y,_]),[N,P]=useState(!1),[I,A]=useState(-1),j=useRef(-1),D=useRef(n);D.current=n;const V=useRef(r);V.current=r;const L=useSharedValue(T),k=useSharedValue(T),F=useCallback(()=>{j.current<0&&P(!1)},[]),$=useCallback(()=>{if(j.current=-1,A(-1),g)return L.value=T,void F();L.value=withTiming(T,{duration:v.duration("fast"),easing:Easing.bezier(...b.motion.ease.accelerate),reduceMotion:PRESENCE_REDUCE_MOTION},e=>{"worklet";e&&runOnJS(F)()})},[T,v,g,b.motion.ease.accelerate,L,F]),B=useCallback(e=>{const t=M(e);L.value=g?t:withSpring(t,SPRING_CONFIG)},[g,M,L]),G=useCallback((e,t)=>{e!==j.current&&(j.current=e,A(e),B(e),t&&V.current?.(e))},[B]),H=useEffectEvent(e=>{if(!e)return void(j.current>=0&&$());const t=s??0;P(!0);const n=M(t);g?L.value=n:(L.value=T,L.value=withSpring(n,SPRING_CONFIG)),j.current=t,A(t)});useEffect(()=>{H(t)},[t]);const J=useEffectEvent(e=>{t&&N&&e!==j.current&&G(e,!1)});useEffect(()=>{null!=s&&J(s)},[s]);const U=useEffectEvent(e=>{const t=j.current;t>=0&&(L.value=topAt(y,e,t))});useEffect(()=>{U(_)},[_]);const X=useCallback(e=>{if(e<0)return triggerHaptic("selection"),$(),void D.current();e!==j.current?G(e,!0):B(e)},[G,B,$]),Y=useCallback(e=>{const t=j.current;t<0||G(Math.min(Math.max(t+e,0),y.length-1),!0)},[G,y.length]),z=useMemo(()=>y.map(e=>_-e),[y,_]),q=useMemo(()=>{const e=z,t=C,n=a;return{testID:E?`${E}-pan-gesture`:"non-modal-bottom-sheet-pan-gesture",activeOffsetY:[-10,10],onActivate:()=>{"worklet";k.value=L.value},onUpdate:e=>{"worklet";const n=k.value+e.translationY;L.value=n<t?t+.25*(n-t):n},onDeactivate:t=>{"worklet";const o=L.value,s=e[0];if(void 0===s)return;if(t.velocityY>1e3)return void runOnJS(X)(n?-1:0);if(n&&o-s>80)return void runOnJS(X)(-1);let r=0,a=1/0,i=0;for(const t of e){const e=Math.abs(o-t);e<a&&(a=e,r=i),i++}runOnJS(X)(r)}}},[k,a,X,C,z,E,L]),K=usePanGesture(q),Q=useAnimatedStyle(()=>({top:Math.max(L.value,C)}),[C]),W=useAnimatedStyle(()=>{const e=Math.max(L.value,C),t=_-e;return{height:Math.max(0,Math.min(t,O))}},[_,O,C]);return N?_jsx(View,{collapsable:!1,style:StyleSheet.absoluteFill,pointerEvents:"box-none",onLayout:w,testID:E,children:_jsx(Animated.View,{accessibilityLabel:f,testID:E?`${E}-sheet`:void 0,style:[R.sheet,{height:O,backgroundColor:b.colors.surface,borderTopLeftRadius:b.radius.xl,borderTopRightRadius:b.radius.xl,...smoothCorners,...b.shadow.modal},m,Q],children:_jsxs(Animated.View,{style:[R.body,W],children:[_jsx(GestureDetector,{gesture:K,children:_jsx(View,{style:R.handleRow,accessible:!0,accessibilityRole:"adjustable",accessibilityLabel:S.dragHandle,accessibilityHint:"Swipe up or down to change the height of the sheet",accessibilityValue:{text:`Snap point ${I+1} of ${y.length}`},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:e=>{"increment"===e.nativeEvent.actionName?Y(1):"decrement"===e.nativeEvent.actionName&&Y(-1)},testID:E?`${E}-handle`:void 0,children:_jsx(View,{style:[R.handle,{backgroundColor:b.colors.border},h]})})}),null!=l?_jsx(Text,{variant:"title",accessibilityRole:"header",children:l}):null,c,i?_jsx(ScrollView,{style:R.scrollContent,children:p}):_jsx(View,{style:R.content,children:p}),u]})})}):null};NonModalBottomSheet.displayName="NonModalBottomSheet";const buildStyles=e=>StyleSheet.create({sheet:{position:"absolute",left:0,right:0,overflow:"hidden"},body:{overflow:"hidden"},handleRow:{alignItems:"center",justifyContent:"center",alignSelf:"stretch",paddingTop:e.space.md,paddingBottom:e.space.xl},handle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},content:{flex:1,overflow:"hidden"},scrollContent:{flex:1}});export{NonModalBottomSheet};export default NonModalBottomSheet;
@@ -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)),[B,M]=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(()=>{B||k(formatValue(v,o,c))},[v,o,c,B]);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:0>a?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(()=>{M(!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(()=>{M(!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 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 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const cellAt=(e,t)=>{const n=e[t];if(void 0===n)throw new Error(`OTP cell ${t} is outside the ${e.length} cells.`);return n},sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:i,onChange:r,onComplete:s,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:v,textStyle:x,testID:T}=e;assertValidValue("OTPInput","size",e.size,["sm","md","lg"]),assertValidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[A,V]=useControllableState({value:n,defaultValue:i??"",onChange:r}),E=useTheme(),C=useMemo(()=>buildStyles(E),[E]),S=resolveOtpInputSize(E,m),k=E.components["otp-input"][m].radius,w=useRef([]),[I,_]=useState(-1),[D,F]=useState(0),O=useRef(null),P=useRef(createAnimatedValue(0)).current,z=useRef(new Map),M=useMemo(()=>{const e=z.current,t=[];for(let n=0;n<a;n+=1){let i=e.get(n);i||(i=new Animated.Value(0),e.set(n,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),R=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===O.current||!B||O.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(P,0),e=Animated.sequence([Animated.timing(P,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver})]),e.start())),O.current=B,()=>e?.stop()},[B,P,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=R.current;if(R.current=I,e===I)return;if(-1===e&&-1===I)return;const t=[];return M.forEach((n,i)=>{const r=i===I?1:0;if(i!==I&&i!==e)return;const s=Animated.timing(n,{toValue:r,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:nativeDriver});s.start(),t.push(s)}),()=>t.forEach(e=>{e.stop()})},[I,M,E]);const H=useCallback(e=>{const t=w.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=w.current[I>=0?I:0];e?.blur()},clear:()=>{V(""),H(0)}}),[H,I,V]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>H(0),u);return()=>clearTimeout(e)}},[l,u,c,H]);const U=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(A.length,a);t+=1)e[t]=A.charAt(t);return e},[A,a]),W=useCallback(e=>{const t=e.slice(0,a);t!==A&&(V(t),t.length===a&&s&&s(t))},[a,V,s,A]),$=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),i=sanitizeChar(n,o);if(!i){const t=U.slice(),n=cellAt(U,e).length>0;if(t[e]="",W(t.join("").slice(0,a)),!n&&e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}return}const r=cellAt(U,e),s=r&&i.length>a&&i.startsWith(r)?i.slice(r.length):i;if(s.length>=a){const t=s.slice(0,a),n=A.length;return W(t),t.length!==n&&f&&triggerHaptic(f),void w.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<i.length&&u<a;e+=1)l[u]=i.charAt(e),u+=1;const c=l.join("").slice(0,a),d=A.length;W(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?w.current[e]?.blur():H(m)},[U,H,o,a,f,W,A]),q=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===cellAt(U,e).length){if(e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}}else{const t=U.slice();t[e]="",W(t.join(""))}},[U,H,W]),G=useCallback((e,t)=>{_(e),h?.(t)},[h]),K=useCallback(()=>{_(-1)},[]),X=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),J=useCallback(e=>{F(e.nativeEvent.layout.width)},[]),Q=b??j.field(a),Y=D>0?Math.max(24,Math.min(S.cell,Math.floor((D-S.gap*(a-1))/a))):S.cell,Z=P.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:y,onLayout:J,accessible:!0,accessibilityRole:"none",accessibilityLabel:Q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:T,children:[_jsx(Pressable,{onPress:X,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[C.row,{columnGap:S.gap,transform:[{translateX:Z}]}],children:U.map((e,t)=>{const n=I===t,i=e.length>0,r=B?E.colors["danger-border"]:E.colors["focus-ring"],s=M[t];if(!s)return null;const l=p&&i?"●":e;return _jsxs(View,{style:C.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Y,height:Y,radius:k,borderWidth:1.5,focused:n,error:B,filled:i,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:v,children:[_jsx(TextInput,{ref:e=>{w.current[t]=e},value:(p&&i?"":e)||"​",onChangeText:e=>$(t,e),onKeyPress:e=>q(t,e),onFocus:e=>G(t,e),onBlur:K,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:i,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[C.input,{fontSize:S.text,color:E.colors["text-body"],...fontFor(E,"semibold")},x]}),p&&i?_jsx(View,{pointerEvents:"none",style:C.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:S.text},x],children:l})}):null]}),_jsx(Animated.View,{style:[C.underline,{backgroundColor:r,opacity:s}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const cellAt=(e,t)=>{const n=e[t];if(void 0===n)throw new Error(`OTP cell ${t} is outside the ${e.length} cells.`);return n},sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:i,onChange:r,onComplete:s,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:x,textStyle:v,testID:T}=e;assertValidValue("OTPInput","size",e.size,["sm","md","lg"]),assertValidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[A,V]=useControllableState({value:n,defaultValue:i??"",onChange:r}),E=useTheme(),C=useMemo(()=>buildStyles(E),[E]),k=resolveOtpInputSize(E,m),S=E.components["otp-input"][m].radius,w=useRef([]),[I,_]=useState(-1),[D,F]=useState(0),O=useRef(null),P=useRef(createAnimatedValue(0)).current,M=useRef(new Map),z=useMemo(()=>{const e=M.current,t=[];for(let n=0;n<a;n+=1){let i=e.get(n);i||(i=new Animated.Value(0),e.set(n,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),R=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===O.current||!B||O.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(P,0),e=Animated.sequence([Animated.timing(P,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver}),Animated.timing(P,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:nativeDriver})]),e.start())),O.current=B,()=>e?.stop()},[B,P,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=R.current;if(R.current=I,e===I)return;if(-1===e&&-1===I)return;const t=[];return z.forEach((n,i)=>{const r=i===I?1:0;if(i!==I&&i!==e)return;const s=Animated.timing(n,{toValue:r,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:nativeDriver});s.start(),t.push(s)}),()=>t.forEach(e=>{e.stop()})},[I,z,E]);const H=useCallback(e=>{const t=w.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=w.current[Math.max(I,0)];e?.blur()},clear:()=>{V(""),H(0)}}),[H,I,V]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>H(0),u);return()=>clearTimeout(e)}},[l,u,c,H]);const U=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(A.length,a);t+=1)e[t]=A.charAt(t);return e},[A,a]),W=useMemo(()=>U.map((e,t)=>({key:`otp-cell-${t}`,index:t,char:e})),[U]),$=useCallback(e=>{const t=e.slice(0,a);t!==A&&(V(t),t.length===a&&s&&s(t))},[a,V,s,A]),q=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),i=sanitizeChar(n,o);if(!i){const t=U.slice(),n=cellAt(U,e).length>0;if(t[e]="",$(t.join("").slice(0,a)),!n&&e>0){const t=U.slice();t[e-1]="",$(t.join("")),H(e-1)}return}const r=cellAt(U,e),s=r&&i.length>a&&i.startsWith(r)?i.slice(r.length):i;if(s.length>=a){const t=s.slice(0,a),n=A.length;return $(t),t.length!==n&&f&&triggerHaptic(f),void w.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<i.length&&u<a;e+=1)l[u]=i.charAt(e),u+=1;const c=l.join("").slice(0,a),d=A.length;$(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?w.current[e]?.blur():H(m)},[U,H,o,a,f,$,A]),G=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===cellAt(U,e).length){if(e>0){const t=U.slice();t[e-1]="",$(t.join("")),H(e-1)}}else{const t=U.slice();t[e]="",$(t.join(""))}},[U,H,$]),K=useCallback((e,t)=>{_(e),h?.(t)},[h]),X=useCallback(()=>{_(-1)},[]),J=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),Q=useCallback(e=>{F(e.nativeEvent.layout.width)},[]),Y=b??j.field(a),Z=D>0?Math.max(24,Math.min(k.cell,Math.floor((D-k.gap*(a-1))/a))):k.cell,ee=P.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:y,onLayout:Q,accessible:!0,accessibilityRole:"none",accessibilityLabel:Y,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:T,children:[_jsx(Pressable,{onPress:J,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[C.row,{columnGap:k.gap,transform:[{translateX:ee}]}],children:W.map(({key:e,index:t,char:n})=>{const i=I===t,r=n.length>0,s=B?E.colors["danger-border"]:E.colors["focus-ring"],l=z[t];if(!l)return null;const u=p&&r?"●":n;return _jsxs(View,{style:C.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Z,height:Z,radius:S,borderWidth:1.5,focused:i,error:B,filled:r,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{w.current[t]=e},value:(p&&r?"":n)||"​",onChangeText:e=>q(t,e),onKeyPress:e=>G(t,e),onFocus:e=>K(t,e),onBlur:X,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:r,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[C.input,{fontSize:k.text,color:E.colors["text-body"],...fontFor(E,"semibold")},v]}),p&&r?_jsx(View,{pointerEvents:"none",style:C.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:k.text},v],children:u})}):null]}),_jsx(Animated.View,{style:[C.underline,{backgroundColor:s,opacity:l}]})]},e)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,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__",ProfilePicker=forwardRef((e,r)=>{const{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"],R=g??L?.defaultTone??"primary",M=h??L?.defaultVariant??"solid",O=useMemo(()=>badgeLookFor(w,R,M),[w,R,M]),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:O.fill,borderColor:O.ring}],children:renderSlotIcon(p,{color:O.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: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 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,Gradient,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROGRESS_BAR_LABELS=Object.freeze({loading:"Loading"});const toneColor=(e,t)=>{switch(t){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.neutral;case"primary":return e.colors.primary}},DETERMINATE_ANIMATION_DURATION=400,INDETERMINATE_LOOP_DURATION=1500,INDETERMINATE_WIDTH="30%",GLOW_LOCATIONS=[0,.35,.5,.65,1],glowOf=e=>{const t=tintOf(e,0,"transparent"),r=tintOf(e,.6,e);return{colors:[t,r,e,r,t],locations:GLOW_LOCATIONS,start:{x:0,y:.5},end:{x:1,y:.5}}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)||e<0?0:e>1?1:e,ProgressBar=forwardRef((e,t)=>{const r=useTheme(),s=useReducedMotion(),{progress:i,label:n,showPercent:a=!1,valueLabel:o,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:g,gradient:p,segments:f,animated:h=!0,style:y,containerStyle:b,barStyle:w,accessibilityLabel:x,labels:R,testID:A}=e;assertValidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const j=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),v=l??"number"!=typeof i,_=clampProgress(i),V=useRef(createAnimatedValue(_)).current,E=useRef(createAnimatedValue(0)).current,O=useRef(createAnimatedValue(0)).current,S=useRef(0),T=useMemo(()=>buildStyles(r),[r]),N=c??r.radius.pill,D=m??r.colors["surface-disabled"],B=g??toneColor(r,d),L=useMemo(()=>{if(null==p)return null;if("string"!=typeof p)return p;const e=r.settings.gradients[p];if(void 0===e){const e=Object.keys(r.settings.gradients);throw new RangeError(`[@webority/mobile-ui] <ProgressBar> received gradient="${p}", which is not a gradient in theme.settings.gradients (${e.length>0?`known: ${e.map(e=>`"${e}"`).join(", ")}`:"the theme defines none"}). Pass a known gradient name or a GradientDefinition, or omit the prop.`)}return e},[p,r.settings.gradients]),I=useMemo(()=>glowOf(B),[B]),P=Array.isArray(f)&&f.length>0;useEffect(()=>{v||(h?Animated.timing(V,{toValue:_,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():V.setValue(_))},[h,_,V,v,r]),useEffect(()=>{if(!v)return;setNativeValue(E,0);const e=Animated.loop(Animated.timing(E,{toValue:1,duration:1500,easing:Easing.inOut(Easing.ease),useNativeDriver:nativeDriver}));return e.start(),()=>{e.stop()}},[v,E]);const C=V.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),M=E.interpolate({inputRange:[0,1],outputRange:[-1,1]}),k=E.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),G=a&&!v&&!P,F=null!=n||G||null!=o,$=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:x??("string"==typeof n?n:void 0),accessibilityValue:v?{text:j.loading}:{min:0,max:100,now:Math.round(100*_)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;S.current=t,setNativeValue(O,t)},style:[T.track,{height:u,borderRadius:N,...smoothCorners,backgroundColor:D},b,y],children:P?_jsx(View,{style:[T.segments,{height:u}],children:(f??[]).map((e,t)=>_jsx(View,{style:{width:100*clampProgress(e.value)+"%",height:u,backgroundColor:e.color??toneColor(r,e.tone??"primary")}},t))}):_jsx(Animated.View,v?{style:[T.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?k:1,transform:s?[]:[{translateX:Animated.multiply(M,O)}]},w],children:_jsx(Gradient,{gradient:I,style:StyleSheet.absoluteFill})}:{style:[T.determinateBar,{height:u,borderRadius:N,...smoothCorners,backgroundColor:L?"transparent":B,width:C,overflow:L?"hidden":void 0},w],children:L?_jsx(Gradient,{gradient:L,style:StyleSheet.absoluteFill}):null})});return F?_jsxs(View,{style:T.wrapper,children:[_jsxs(View,{style:[T.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"primary",style:T.label,children:n}):_jsx(View,{style:T.label,children:n}),null!=o?"string"==typeof o||"number"==typeof o?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:o}):o:G?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*_)}%`}):null]}),$]}):$});ProgressBar.displayName="ProgressBar";const buildStyles=e=>StyleSheet.create({wrapper:{width:"100%"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},label:{flexShrink:1},track:{width:"100%",overflow:"hidden"},determinateBar:{position:"absolute",left:0,top:0},indeterminateBar:{position:"absolute",left:0,top:0},segments:{flexDirection:"row",width:"100%"}});export{ProgressBar};export default ProgressBar;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,Gradient,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_PROGRESS_BAR_LABELS=Object.freeze({loading:"Loading"});const toneColor=(e,t)=>{switch(t){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.neutral;case"primary":return e.colors.primary}},DETERMINATE_ANIMATION_DURATION=400,INDETERMINATE_LOOP_DURATION=1500,INDETERMINATE_WIDTH="30%",GLOW_LOCATIONS=[0,.35,.5,.65,1],glowOf=e=>{const t=tintOf(e,0,"transparent"),r=tintOf(e,.6,e);return{colors:[t,r,e,r,t],locations:GLOW_LOCATIONS,start:{x:0,y:.5},end:{x:1,y:.5}}},clampProgress=e=>"number"!=typeof e||Number.isNaN(e)||e<0?0:e>1?1:e,ProgressBar=forwardRef((e,t)=>{const r=useTheme(),s=useReducedMotion(),{progress:i,label:n,showPercent:a=!1,valueLabel:o,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:g,gradient:p,segments:f,animated:h=!0,style:y,containerStyle:b,barStyle:w,accessibilityLabel:x,labels:R,testID:A}=e;assertValidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const j=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),v=l??"number"!=typeof i,_=clampProgress(i),V=useRef(createAnimatedValue(_)).current,E=useRef(createAnimatedValue(0)).current,O=useRef(createAnimatedValue(0)).current,S=useRef(0),T=useMemo(()=>buildStyles(r),[r]),N=c??r.radius.pill,D=m??r.colors["surface-disabled"],B=g??toneColor(r,d),L=useMemo(()=>{if(null==p)return null;if("string"!=typeof p)return p;const e=r.settings.gradients[p];if(void 0===e){const e=Object.keys(r.settings.gradients);throw new RangeError(`[@webority/mobile-ui] <ProgressBar> received gradient="${p}", which is not a gradient in theme.settings.gradients (${e.length>0?`known: ${e.map(e=>`"${e}"`).join(", ")}`:"the theme defines none"}). Pass a known gradient name or a GradientDefinition, or omit the prop.`)}return e},[p,r.settings.gradients]),I=useMemo(()=>glowOf(B),[B]),M=Array.isArray(f)&&f.length>0,P=useMemo(()=>(f??[]).map((e,t)=>({key:`segment-${t}`,segment:e})),[f]);useEffect(()=>{v||(h?Animated.timing(V,{toValue:_,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():V.setValue(_))},[h,_,V,v,r]),useEffect(()=>{if(!v)return;setNativeValue(E,0);const e=Animated.loop(Animated.timing(E,{toValue:1,duration:1500,easing:Easing.inOut(Easing.ease),useNativeDriver:nativeDriver}));return e.start(),()=>{e.stop()}},[v,E]);const C=V.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),k=E.interpolate({inputRange:[0,1],outputRange:[-1,1]}),G=E.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),F=a&&!v&&!M,$=null!=n||F||null!=o,U=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:x??("string"==typeof n?n:void 0),accessibilityValue:v?{text:j.loading}:{min:0,max:100,now:Math.round(100*_)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;S.current=t,setNativeValue(O,t)},style:[T.track,{height:u,borderRadius:N,...smoothCorners,backgroundColor:D},b,y],children:M?_jsx(View,{style:[T.segments,{height:u}],children:P.map(({key:e,segment:t})=>_jsx(View,{style:{width:100*clampProgress(t.value)+"%",height:u,backgroundColor:t.color??toneColor(r,t.tone??"primary")}},e))}):_jsx(Animated.View,v?{style:[T.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?G:1,transform:s?[]:[{translateX:Animated.multiply(k,O)}]},w],children:_jsx(Gradient,{gradient:I,style:StyleSheet.absoluteFill})}:{style:[T.determinateBar,{height:u,borderRadius:N,...smoothCorners,backgroundColor:L?"transparent":B,width:C,overflow:L?"hidden":void 0},w],children:L?_jsx(Gradient,{gradient:L,style:StyleSheet.absoluteFill}):null})});return $?_jsxs(View,{style:T.wrapper,children:[_jsxs(View,{style:[T.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"primary",style:T.label,children:n}):_jsx(View,{style:T.label,children:n}),null!=o?"string"==typeof o||"number"==typeof o?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:o}):o:F?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*_)}%`}):null]}),U]}):U});ProgressBar.displayName="ProgressBar";const buildStyles=e=>StyleSheet.create({wrapper:{width:"100%"},labelRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},label:{flexShrink:1},track:{width:"100%",overflow:"hidden"},determinateBar:{position:"absolute",left:0,top:0},indeterminateBar:{position:"absolute",left:0,top:0},segments:{flexDirection:"row",width:"100%"}});export{ProgressBar};export default ProgressBar;
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{spaceOf,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){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.neutral;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:r,selected:o,onChange:i,disabled:s=!1,label:a,helperText:l,description:c,error:n,size:d="md",tone:p="primary",accessibilityLabel:u,haptic:m,style:h,containerStyle:x,circleStyle:f,dotStyle:b,labelStyle:y,testID:g,hitSlop:S,...R}=e;assertValidValue("Radio","size",e.size,["sm","md","lg"]),assertValidValue("Radio","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const w=useTheme(),C=useMemo(()=>buildStyles(w),[w]),j=useRadioGroup();__DEV__&&void 0===r&&Logger.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const T=j?j.selectedValue===r:!!o,V=j&&j.disabled||s,D=toneColor(w,p),_=spaceOf(w,w.components.radio["label-gap"]),v=S??6,H=u??fieldTextAsString(a),k="string"==typeof n?n:void 0,L={description:c,helperText:l,error:k},z=!0===j?.error||!0===n||hasFieldText(n);return _jsxs(Pressable,{ref:t,onPress:e=>{if(V)return;const t=resolveHaptic(m,"selection");t&&triggerHaptic(t),j?j.onChange(r):i?.(r)},disabled:V,accessibilityRole:"radio",accessibilityLabel:H,accessibilityHint:R.accessibilityHint??fieldTextAsString(l??c),accessibilityState:{checked:T,disabled:V},"aria-checked":T,"aria-disabled":V,testID:g,hitSlop:v,...hitSlopMarker(v),...R,style:({pressed:e})=>[C.row,hasChoiceDetail(L)?C.rowTop:null,{opacity:V?.55:e?.85:1},x,h],children:[_jsx(RadioDot,{selected:T,color:D,disabled:V&&!T,size:d,style:[!z||T||V?null:{borderColor:w.colors["field-border-error"]},f],dotStyle:b}),_jsx(ChoiceText,{label:a,helperText:l,description:c,error:k,disabled:V,style:{marginLeft:_},labelStyle:y})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{spaceOf,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/index.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){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.neutral;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:r,selected:o,onChange:i,disabled:s=!1,label:a,helperText:l,description:c,error:n,size:d="md",tone:p="primary",accessibilityLabel:u,haptic:m,style:h,containerStyle:x,circleStyle:f,dotStyle:b,labelStyle:g,testID:y,hitSlop:S,...R}=e;assertValidValue("Radio","size",e.size,["sm","md","lg"]),assertValidValue("Radio","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const w=useTheme(),C=useMemo(()=>buildStyles(w),[w]),T=useRadioGroup();__DEV__&&void 0===r&&Logger.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const j=T?T.selectedValue===r:!!o,V=T&&T.disabled||s,D=toneColor(w,p),_=spaceOf(w,w.components.radio["label-gap"]),v=S??6,H=u??fieldTextAsString(a),k="string"==typeof n?n:void 0,L={description:c,helperText:l,error:k},z=!0===T?.error||!0===n||hasFieldText(n);return _jsxs(Pressable,{ref:t,onPress:e=>{if(V)return;const t=resolveHaptic(m,"selection");t&&triggerHaptic(t),T?T.onChange(r):i?.(r)},disabled:V,accessibilityRole:"radio",accessibilityLabel:H,accessibilityHint:R.accessibilityHint??fieldTextAsString(l)??fieldTextAsString(c),accessibilityState:{checked:j,disabled:V},"aria-checked":j,"aria-disabled":V,testID:y,hitSlop:v,...hitSlopMarker(v),...R,style:({pressed:e})=>[C.row,hasChoiceDetail(L)?C.rowTop:null,{opacity:V?.55:e?.85:1},x,h],children:[_jsx(RadioDot,{selected:j,color:D,disabled:V&&!j,size:d,style:[!z||j||V?null:{borderColor:w.colors["field-border-error"]},f],dotStyle:b}),_jsx(ChoiceText,{label:a,helperText:l,description:c,error:k,disabled:V,style:{marginLeft:_},labelStyle:g})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
@@ -1 +1 @@
1
- "use strict";import{useCallback,useMemo}from"react";import{View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{hasFieldText}from"../FieldBase/index.js";import{ChoiceText}from"../FieldBase/ChoiceText.js";import{RadioGroupContext}from"./Radio.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RadioGroup=({value:e,defaultValue:o,onChange:i,children:r,disabled:a=!1,error:t,accessibilityLabel:s,style:l,testID:d})=>{const u=useCallback(e=>{if("string"!=typeof e&&"number"!=typeof e)throw new Error("RadioGroup received a missing value in single mode.");i?.(e)},[i]),[n,c]=useControllableState({value:e,defaultValue:o??void 0,onChange:u}),p=!0===t||hasFieldText(t),m=useMemo(()=>({selectedValue:n,onChange:c,disabled:a,error:p}),[n,c,a,p]);return _jsxs(RadioGroupContext.Provider,{value:m,children:[_jsx(View,{accessibilityRole:"radiogroup",accessibilityLabel:s,accessibilityState:{disabled:a},"aria-disabled":a,testID:d,style:l,children:r}),_jsx(ChoiceText,{error:"string"==typeof t?t:void 0})]})};RadioGroup.displayName="RadioGroup";export{RadioGroup};export default RadioGroup;
1
+ "use strict";import{useCallback,useMemo}from"react";import{View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{hasFieldText}from"../FieldBase/index.js";import{ChoiceText}from"../FieldBase/ChoiceText.js";import{RadioGroupContext}from"./Radio.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RadioGroup=e=>{const{value:o,defaultValue:i,onChange:r,children:a,disabled:t=!1,error:s,accessibilityLabel:l,style:d,testID:u}=e,n=useCallback(e=>{if("string"!=typeof e&&"number"!=typeof e)throw new Error("RadioGroup received a missing value in single mode.");r?.(e)},[r]),[c,p]=useControllableState({controlled:"value"in e,value:o,defaultValue:i??void 0,onChange:n}),m=!0===s||hasFieldText(s),x=useMemo(()=>({selectedValue:c,onChange:p,disabled:t,error:m}),[c,p,t,m]);return _jsxs(RadioGroupContext.Provider,{value:x,children:[_jsx(View,{accessibilityRole:"radiogroup",accessibilityLabel:l,accessibilityState:{disabled:t},"aria-disabled":t,testID:u,style:d,children:a}),_jsx(ChoiceText,{error:"string"==typeof s?s:void 0})]})};RadioGroup.displayName="RadioGroup";export{RadioGroup};export default RadioGroup;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RATING_SIZES=["sm","md","lg"],RATING_TONES=["primary","success","warning","danger","info","neutral"];export const DEFAULT_RATING_LABELS=Object.freeze({value:(e,t)=>`${e} of ${t} stars`});const sizePxMap={sm:16,md:24,lg:32},resolveSize=e=>sizePxMap[e],PULSE_SCALE=1.2,toneColorFor=(e,t)=>{switch(t){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.neutral;case"primary":return e.colors.primary}},clampToStep=(e,t,s)=>{const i=Math.max(0,Math.min(t,e)),r=Math.round(i/s)*s;return Number(r.toFixed(2))},Star=({index:e,filled:t,size:s,filledColor:i,emptyColor:r,scale:a})=>{const n=Math.max(0,Math.min(1,t-e));return _jsxs(Animated.View,{style:[starStyles.starWrap,{width:s,height:s,transform:[{scale:a}]}],children:[_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:r,fontSize:s,lineHeight:s}],accessible:!1,children:"☆"}),n>0?_jsx(View,{pointerEvents:"none",style:[starStyles.fillClip,{width:s*n,height:s}],children:_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:i,fontSize:s,lineHeight:s}],accessible:!1,children:"★"})}):null]})},RatingRoot=forwardRef((e,t)=>{const{value:s,onChange:i,max:r=5,allowHalf:a=!0,readonly:n=!1,size:o="md",tone:l="warning",label:c,loading:m=!1,haptic:u,labels:d,accessibilityLabel:p,style:g,containerStyle:y,starContainerStyle:f,testID:h}=e;assertValidValue("Rating","size",e.size,RATING_SIZES),assertValidValue("Rating","tone",e.tone,RATING_TONES);const x=useMemo(()=>({...DEFAULT_RATING_LABELS,...d}),[d]),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),v=!n&&"function"==typeof i,w=a?.5:1,R=resolveSize(o),j=toneColorFor(S,l),_=S.colors.border,A=useRef(R),k=useCallback(e=>{A.current=e.nativeEvent.layout.width},[]),T=useRef(new Map),V=useMemo(()=>{const e=T.current,t=[];for(let s=0;s<r;s+=1){let i=e.get(s);i||(i=new Animated.Value(1),e.set(s,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=r&&e.delete(t);return t},[r]),C=S.settings.components.rating?.pulseOnPress??!1,E=useCallback(e=>{const t=V[e];if(!t)throw new Error(`Rating has no star at index ${e}; the pulse index must be below max.`);Animated.sequence([Animated.timing(t,{toValue:1.2,duration:S.motion.duration.fast,easing:Easing.bezier(...S.motion.ease["in-out"]),useNativeDriver:nativeDriver}),Animated.spring(t,{toValue:1,damping:S.motion.spring.bouncy.damping,stiffness:S.motion.spring.bouncy.stiffness,mass:S.motion.spring.bouncy.mass,useNativeDriver:nativeDriver})]).start()},[S.motion,V]),M=useCallback((e,t)=>{if(!v||!i)return;const s=clampToStep(e,r,w),a=resolveHaptic(u,"selection");a&&triggerHaptic(a),C&&"number"==typeof t&&E(t),i(s)},[v,i,r,w,E,u,C]),z=useCallback(e=>t=>{if(!v)return;const s=A.current||R,i=t.nativeEvent.locationX??s;let r;r=a&&i<s/2?e+.5:e+1,M(r,e)},[v,R,a,M]),N=useCallback(e=>{v&&("increment"===e.nativeEvent.actionName?M(s+w):"decrement"===e.nativeEvent.actionName&&M(s-w))},[v,s,w,M]),D=x.value(s,r),I=p??c??D,L=[];for(const[e,t]of V.entries()){const i=_jsx(Star,{index:e,filled:s,size:R,filledColor:j,emptyColor:_,scale:t},e);L.push(v?_jsx(Pressable,{onPress:z(e),onLayout:0===e?k:void 0,hitSlop:4,...hitSlopMarker(4),accessible:!1,style:b.starPress,children:i},e):_jsx(View,{onLayout:0===e?k:void 0,style:b.starPress,children:i},e))}const P=_jsxs(View,{style:[b.wrapper,y,g],ref:t,testID:h,children:[c?_jsx(Text,{variant:"bodySmall",color:"secondary",style:b.label,children:c}):null,_jsx(View,{style:[b.row,f],accessible:!0,accessibilityRole:v?"adjustable":"text",accessibilityLabel:I,accessibilityValue:v?{min:0,max:r,now:s,text:D}:void 0,accessibilityActions:v?[{name:"increment"},{name:"decrement"}]:void 0,onAccessibilityAction:v?N:void 0,children:L})]});return m?_jsx(RatingSkeleton,{...e}):P});RatingRoot.displayName="Rating";const RatingSkeleton=({max:e=5,size:t="md",label:s,containerStyle:i,starContainerStyle:r,style:a})=>{const n=useTheme(),o=resolveSize(t),l=Math.max(1,e);return _jsxs(View,{style:[{alignItems:"flex-start"},i,a],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==s?_jsx(Skeleton,{shape:"text",width:80,height:14,style:{marginBottom:n.space.xs}}):null,_jsx(View,{style:[{flexDirection:"row"},r],children:Array.from({length:l}).map((e,t)=>_jsx(Skeleton,{width:o,height:o,radius:Math.round(.25*o),style:t<l-1?{marginRight:n.space.xs}:void 0},`sk-star-${t}`))})]})};RatingSkeleton.displayName="RatingSkeleton";const Rating=Object.assign(RatingRoot,{Skeleton:RatingSkeleton}),starStyles=StyleSheet.create({starWrap:{position:"relative",alignItems:"flex-start",justifyContent:"center"},glyph:{textAlign:"left",includeFontPadding:!1},fillClip:{position:"absolute",top:0,left:0,overflow:"hidden"}}),buildStyles=e=>StyleSheet.create({wrapper:{flexDirection:"column"},row:{flexDirection:"row",alignItems:"center"},starPress:{marginRight:e.space.xs},label:{marginBottom:e.space.xs}});export{Rating};export default Rating;
1
+ "use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const RATING_SIZES=["sm","md","lg"],RATING_TONES=["primary","success","warning","danger","info","neutral"];export const DEFAULT_RATING_LABELS=Object.freeze({value:(e,t)=>`${e} of ${t} stars`});const sizePxMap={sm:16,md:24,lg:32},resolveSize=e=>sizePxMap[e],PULSE_SCALE=1.2,toneColorFor=(e,t)=>{switch(t){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.neutral;case"primary":return e.colors.primary}},clampToStep=(e,t,s)=>{const i=Math.max(0,Math.min(t,e)),r=Math.round(i/s)*s;return Number(r.toFixed(2))},Star=({index:e,filled:t,size:s,filledColor:i,emptyColor:r,scale:a})=>{const n=Math.max(0,Math.min(1,t-e));return _jsxs(Animated.View,{style:[starStyles.starWrap,{width:s,height:s,transform:[{scale:a}]}],children:[_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:r,fontSize:s,lineHeight:s}],accessible:!1,children:"☆"}),n>0?_jsx(View,{pointerEvents:"none",style:[starStyles.fillClip,{width:s*n,height:s}],children:_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:i,fontSize:s,lineHeight:s}],accessible:!1,children:"★"})}):null]})},RatingRoot=forwardRef((e,t)=>{const{value:s,onChange:i,max:r=5,allowHalf:a=!0,readonly:n=!1,size:o="md",tone:l="warning",label:c,loading:m=!1,haptic:u,labels:d,accessibilityLabel:p,style:y,containerStyle:g,starContainerStyle:f,testID:h}=e;assertValidValue("Rating","size",e.size,RATING_SIZES),assertValidValue("Rating","tone",e.tone,RATING_TONES);const x=useMemo(()=>({...DEFAULT_RATING_LABELS,...d}),[d]),S=useTheme(),b=useMemo(()=>buildStyles(S),[S]),v=!n&&"function"==typeof i,w=a?.5:1,R=resolveSize(o),j=toneColorFor(S,l),_=S.colors.border,A=useRef(R),k=useCallback(e=>{A.current=e.nativeEvent.layout.width},[]),T=useRef(new Map),V=useMemo(()=>{const e=T.current,t=[];for(let s=0;s<r;s+=1){let i=e.get(s);i||(i=new Animated.Value(1),e.set(s,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=r&&e.delete(t);return t},[r]),C=S.settings.components.rating?.pulseOnPress??!1,E=useCallback(e=>{const t=V[e];if(!t)throw new Error(`Rating has no star at index ${e}; the pulse index must be below max.`);Animated.sequence([Animated.timing(t,{toValue:1.2,duration:S.motion.duration.fast,easing:Easing.bezier(...S.motion.ease["in-out"]),useNativeDriver:nativeDriver}),Animated.spring(t,{toValue:1,damping:S.motion.spring.bouncy.damping,stiffness:S.motion.spring.bouncy.stiffness,mass:S.motion.spring.bouncy.mass,useNativeDriver:nativeDriver})]).start()},[S.motion,V]),M=useCallback((e,t)=>{if(!v||!i)return;const s=clampToStep(e,r,w),a=resolveHaptic(u,"selection");a&&triggerHaptic(a),C&&"number"==typeof t&&E(t),i(s)},[v,i,r,w,E,u,C]),z=useCallback(e=>t=>{if(!v)return;const s=A.current||R,i=t.nativeEvent.locationX??s;let r;r=a&&i<s/2?e+.5:e+1,M(r,e)},[v,R,a,M]),N=useCallback(e=>{v&&("increment"===e.nativeEvent.actionName?M(s+w):"decrement"===e.nativeEvent.actionName&&M(s-w))},[v,s,w,M]),D=x.value(s,r),I=p??c??D,L=[];for(const[e,t]of V.entries()){const i=_jsx(Star,{index:e,filled:s,size:R,filledColor:j,emptyColor:_,scale:t},e);L.push(v?_jsx(Pressable,{onPress:z(e),onLayout:0===e?k:void 0,hitSlop:4,...hitSlopMarker(4),accessible:!1,style:b.starPress,children:i},e):_jsx(View,{onLayout:0===e?k:void 0,style:b.starPress,children:i},e))}const P=_jsxs(View,{style:[b.wrapper,g,y],ref:t,testID:h,children:[c?_jsx(Text,{variant:"bodySmall",color:"secondary",style:b.label,children:c}):null,_jsx(View,{style:[b.row,f],accessible:!0,accessibilityRole:v?"adjustable":"text",accessibilityLabel:I,accessibilityValue:v?{min:0,max:r,now:s,text:D}:void 0,accessibilityActions:v?[{name:"increment"},{name:"decrement"}]:void 0,onAccessibilityAction:v?N:void 0,children:L})]});return m?_jsx(RatingSkeleton,{...e}):P});RatingRoot.displayName="Rating";const RatingSkeleton=({max:e=5,size:t="md",label:s,containerStyle:i,starContainerStyle:r,style:a})=>{const n=useTheme(),o=resolveSize(t),l=Math.max(1,e),c=useMemo(()=>Array.from({length:l},(e,t)=>({key:`sk-star-${t}`,index:t})),[l]);return _jsxs(View,{style:[{alignItems:"flex-start"},i,a],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==s?_jsx(Skeleton,{shape:"text",width:80,height:14,style:{marginBottom:n.space.xs}}):null,_jsx(View,{style:[{flexDirection:"row"},r],children:c.map(({key:e,index:t})=>_jsx(Skeleton,{width:o,height:o,radius:Math.round(.25*o),style:t<l-1?{marginRight:n.space.xs}:void 0},e))})]})};RatingSkeleton.displayName="RatingSkeleton";const Rating=Object.assign(RatingRoot,{Skeleton:RatingSkeleton}),starStyles=StyleSheet.create({starWrap:{position:"relative",alignItems:"flex-start",justifyContent:"center"},glyph:{textAlign:"left",includeFontPadding:!1},fillClip:{position:"absolute",top:0,left:0,overflow:"hidden"}}),buildStyles=e=>StyleSheet.create({wrapper:{flexDirection:"column"},row:{flexDirection:"row",alignItems:"center"},starPress:{marginRight:e.space.xs},label:{marginBottom:e.space.xs}});export{Rating};export default Rating;
@@ -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:i,autoFocus:n=!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=i??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=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==ee&&se(J)},[J,p]);const ae=useRef(J);useEffect(()=>{void 0!==p&&le!==ae.current&&(ae.current=le,a(le))},[le,p,a]);const te=useCallback(e=>{void 0===p?a(e):se(e)},[p,a]),oe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(se(""),ae.current=""),a(""),u?.()},[E,p,a,u]),re=useCallback(()=>{t?.(void 0!==p?ee:J)},[t,p,ee,J]),ie=void 0!==p?ee:J,ne=ie.length>0,[ce,ue]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),de=useCallback(e=>{ue(e);const s=v?.find(s=>s.value===e)?.label;s&&announce(w.searching(s))},[v,ue,w]),[pe,he]=useState(!1),be=useRef(null),me=useCallback(()=>{be.current&&(clearTimeout(be.current),be.current=null)},[]),fe=useCallback(()=>{me(),he(!0)},[me]),Se=useCallback(()=>{me(),be.current=setTimeout(()=>he(!1),50)},[me]);useEffect(()=>me,[me]);const ge=!c&&(Q||pe),ve=useMemo(()=>(R??[]).slice(0,j),[R,j]),Ce=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),xe=ge&&!ne&&ve.length>0,Re=ge&&ne&&Ce.length>0,je=Re?Ce.length:0,ye=je>0?w.suggestionCount(je):"";useEffect(()=>{ye&&announce(ye)},[ye]);const Fe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),Le=useCallback(e=>{Fe(),$.current?.blur(),he(!1),y?.(e)},[Fe,y]),ke=useCallback(e=>{Fe(),$.current?.blur(),he(!1),B?.(e)},[Fe,B]),Be=useCallback(e=>{Fe(),F?.(e),announce(w.removed(e)),K()},[Fe,F,K,w]),Ee=useCallback(()=>{Fe(),_?.(),announce(w.recentsCleared),K()},[Fe,_,K,w]),Ae={size:N.icon,color:c?M.colors["text-disabled"]:M.colors["text-subtle"],disabled:c},Ve=d?renderSlotIcon(d,Ae):(M.settings.icons.search??defaultIcons.search)(Ae),Te=_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Ve}),ze=Boolean(f)&&"float"===S,Ie=useFloatingLabel({label:f,enabled:ze,floated:Q||ne,variant:P,sizeTokens:N,leadingOffset:N.icon+M.space.md,trailingOffset:ne?N.icon+M.space.md:0,paddingLeft:O?M.space.none:N["padding-x"],color:M.colors["field-label"],style:g}),He=ne&&!c?_jsx(Pressable,{onPress:oe,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&&!ze?_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:ne,minHeight:N["min-height"],paddingHorizontal:O?M.space.none:N["padding-x"],radius:U,leading:Te,trailing:He,topNotch:Ie.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:te,onSubmitEditing:re,onFocus:Y,onBlur:Z,placeholder:!ze||Q||ne?D:void 0,placeholderTextColor:W.placeholderColor,autoFocus:n,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(M,P).borderFocusedRepresentative,accessibilityLabel:z??D,accessibilityState:{disabled:c},"aria-disabled":c,...H})}),Ie.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ce||(v[0]?.value??""),disabled:c,haptic:E,labels:w,onChange:de}):null,xe?_jsx(SearchRecents,{recents:ve,labels:w,onSelect:Le,onRemove:F?Be:void 0,onClear:_?Ee:void 0,onHold:fe,onRelease:Se}):null,Re?_jsx(SearchSuggestions,{suggestions:Ce,query:ie,onSelect:ke,onHold:fe,onRelease:Se}):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: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 +1 @@
1
- "use strict";import{Storage}from"@webority/mobile-core";import{useCallback,useEffect,useRef,useState}from"react";const DEFAULT_MAX=8,isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),parseStringList=e=>isStringList(e)?e:null;export const useRecentSearches=(e,r)=>{const t=r?.max??8,[s,c]=useState([]),n=useRef([]),u=useRef(!1);useEffect(()=>{let r=!1;return u.current=!1,n.current=[],c([]),Storage.getJson(e,parseStringList).then(e=>{if(r||u.current||null===e)return;const s=e.slice(0,t);n.current=s,c(s)}),()=>{r=!0}},[e]);const a=useCallback(r=>{u.current=!0,n.current=r,c(r),Storage.setJson(e,r)},[e]);return{recents:s,add:useCallback(e=>{const r=e.trim();if(!r)return;const s=r.toLowerCase(),c=n.current.filter(e=>e.toLowerCase()!==s);a([r,...c].slice(0,t))},[a,t]),remove:useCallback(e=>{a(n.current.filter(r=>r!==e))},[a]),clear:useCallback(()=>{const e=n.current;return a([]),e},[a]),replace:useCallback(e=>{a(e.slice(0,t))},[a,t])}};
1
+ "use strict";import{Storage}from"@webority/mobile-core";import{useCallback,useEffect,useRef,useState}from"react";const DEFAULT_MAX=8,isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),parseStringList=e=>isStringList(e)?e:null;export const useRecentSearches=(e,r)=>{const t=r?.max??8,s=useRef(t);s.current=t;const[c,n]=useState([]),u=useRef([]),a=useRef(!1);useEffect(()=>{let r=!1;const t=s.current;return a.current=!1,u.current=[],n([]),Storage.getJson(e,parseStringList).then(e=>{if(r||a.current||null===e)return;const s=e.slice(0,t);u.current=s,n(s)}),()=>{r=!0}},[e]);const o=useCallback(r=>{a.current=!0,u.current=r,n(r),Storage.setJson(e,r)},[e]);return{recents:c,add:useCallback(e=>{const r=e.trim();if(!r)return;const s=r.toLowerCase(),c=u.current.filter(e=>e.toLowerCase()!==s);o([r,...c].slice(0,t))},[o,t]),remove:useCallback(e=>{o(u.current.filter(r=>r!==e))},[o]),clear:useCallback(()=>{const e=u.current;return o([]),e},[o]),replace:useCallback(e=>{o(e.slice(0,t))},[o,t])}};
@@ -1 +1 @@
1
- "use strict";import{useMemo,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{toBackgroundImage}from"../../theme/Gradient.js";import{useScreenDimensions}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{useSkeletonClock}from"./SkeletonClock.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_SKELETON_LABELS=Object.freeze({loading:"Loading"});const resolveRadius=(e,t)=>"number"==typeof t?t:e.radius[t],resolveWidth=e=>void 0===e?"100%":e,radiusForShape=(e,t,s,o,i)=>{if(void 0!==i)return resolveRadius(e,i);switch(t){case"circle":return"number"==typeof s?Math.min(s,o)/2:o/2;case"rounded":return e.radius.md;default:return e.radius.sm}},Skeleton=e=>{const{shape:t="rect",width:s="100%",height:o=16,radius:i,variant:r,colors:n,labels:a,style:l,testID:u}=e;assertValidValue("Skeleton","shape",e.shape,["rect","rounded","circle","text"]),assertValidValue("Skeleton","variant",e.variant,["shimmer","pulse","none"]);const m=useTheme(),d=useSkeletonDefaults(),c=useSkeletonClock(),h=useReducedMotion(),p=r??d.variant??"shimmer",S=h&&"auto"===(d.animation??"auto");let k=p;c.enabled?S&&"shimmer"===p&&(k="pulse"):k="none";const g=n?.background??d.colors?.background??m.colors.skeleton,y=n?.highlight??d.colors?.highlight??m.colors["skeleton-highlight"],{responsive:b}=useScreenDimensions(),x=useMemo(()=>buildStyles(),[]),f=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...a}),[a]),v=resolveWidth(s),j=b.size(o),w=radiusForShape(m,t,v,j,i),[L,V]=useState(0),M=useMemo(()=>L<=0?0:Math.max(48,.7*L),[L]),R=useMemo(()=>L<=0?0:c.shimmer.interpolate({inputRange:[0,1],outputRange:[-M,L]}),[c.shimmer,M,L]),_=useMemo(()=>"none"===k?null:"pulse"===k?_jsx(Animated.View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{backgroundColor:y,opacity:c.pulse.interpolate({inputRange:[0,1],outputRange:[0,.55]})}]}):L<=0?null:_jsx(Animated.View,{pointerEvents:"none",style:[x.shimmerBand,{width:M,transform:[{translateX:R}],experimental_backgroundImage:[toBackgroundImage({colors:["transparent",y,"transparent"],locations:[0,.5,1],start:{x:0,y:.5},end:{x:1,y:.5}})]}]}),[k,y,c.pulse,L,x.shimmerBand,M,R]);return _jsx(View,{onLayout:e=>{const t=e.nativeEvent.layout.width;t!==L&&V(t)},accessible:!0,accessibilityLabel:f.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",testID:u,style:[x.base,{width:v,height:j,borderRadius:w,...smoothCorners,backgroundColor:g},l],children:_})};Skeleton.displayName="Skeleton";const SkeletonCircle=({size:e,style:t,...s})=>{const{responsive:o}=useScreenDimensions(),i=o.size(e);return _jsx(Skeleton,{...s,shape:"circle",width:i,height:e,style:t})};SkeletonCircle.displayName="SkeletonCircle";const SkeletonText=({lines:e=3,lastLineWidth:t="60%",spacing:s,fontSize:o,variant:i,radius:r="sm",width:n="100%",labels:a,style:l,testID:u})=>{const m=useTheme(),d=s??m.space.xs,c=Math.max(1,e);return _jsx(View,{style:l,testID:u,children:Array.from({length:c}).map((e,s)=>_jsx(Skeleton,{shape:"text",width:s===c-1&&c>1?t:n,height:o??m.text.base.size,radius:r,variant:i,labels:a,style:s<c-1?{marginBottom:d}:void 0},s))})};SkeletonText.displayName="SkeletonText";const buildStyles=()=>StyleSheet.create({base:{overflow:"hidden"},shimmerBand:{position:"absolute",top:0,bottom:0,left:0}});export{Skeleton,SkeletonCircle,SkeletonText};export default Skeleton;
1
+ "use strict";import{useMemo,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{toBackgroundImage}from"../../theme/Gradient.js";import{useScreenDimensions}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{useSkeletonClock}from"./SkeletonClock.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_SKELETON_LABELS=Object.freeze({loading:"Loading"});const resolveRadius=(e,t)=>"number"==typeof t?t:e.radius[t],resolveWidth=e=>void 0===e?"100%":e,radiusForShape=(e,t,s,o,i)=>{if(void 0!==i)return resolveRadius(e,i);switch(t){case"circle":return"number"==typeof s?Math.min(s,o)/2:o/2;case"rounded":return e.radius.md;default:return e.radius.sm}},Skeleton=e=>{const{shape:t="rect",width:s="100%",height:o=16,radius:i,variant:n,colors:r,labels:a,style:l,testID:u}=e;assertValidValue("Skeleton","shape",e.shape,["rect","rounded","circle","text"]),assertValidValue("Skeleton","variant",e.variant,["shimmer","pulse","none"]);const m=useTheme(),d=useSkeletonDefaults(),c=useSkeletonClock(),h=useReducedMotion(),p=n??d.variant??"shimmer",S=h&&"auto"===(d.animation??"auto");let k=p;c.enabled?S&&"shimmer"===p&&(k="pulse"):k="none";const y=r?.background??d.colors?.background??m.colors.skeleton,g=r?.highlight??d.colors?.highlight??m.colors["skeleton-highlight"],{responsive:x}=useScreenDimensions(),b=useMemo(()=>buildStyles(),[]),f=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...a}),[a]),v=resolveWidth(s),j=x.size(o),w=radiusForShape(m,t,v,j,i),[L,M]=useState(0),V=useMemo(()=>L<=0?0:Math.max(48,.7*L),[L]),R=useMemo(()=>L<=0?0:c.shimmer.interpolate({inputRange:[0,1],outputRange:[-V,L]}),[c.shimmer,V,L]),_=useMemo(()=>"none"===k?null:"pulse"===k?_jsx(Animated.View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{backgroundColor:g,opacity:c.pulse.interpolate({inputRange:[0,1],outputRange:[0,.55]})}]}):L<=0?null:_jsx(Animated.View,{pointerEvents:"none",style:[b.shimmerBand,{width:V,transform:[{translateX:R}],experimental_backgroundImage:[toBackgroundImage({colors:["transparent",g,"transparent"],locations:[0,.5,1],start:{x:0,y:.5},end:{x:1,y:.5}})]}]}),[k,g,c.pulse,L,b.shimmerBand,V,R]);return _jsx(View,{onLayout:e=>{const t=e.nativeEvent.layout.width;t!==L&&M(t)},accessible:!0,accessibilityLabel:f.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",testID:u,style:[b.base,{width:v,height:j,borderRadius:w,...smoothCorners,backgroundColor:y},l],children:_})};Skeleton.displayName="Skeleton";const SkeletonCircle=({size:e,style:t,...s})=>{const{responsive:o}=useScreenDimensions(),i=o.size(e);return _jsx(Skeleton,{...s,shape:"circle",width:i,height:e,style:t})};SkeletonCircle.displayName="SkeletonCircle";const SkeletonText=({lines:e=3,lastLineWidth:t="60%",spacing:s,fontSize:o,variant:i,radius:n="sm",width:r="100%",labels:a,style:l,testID:u})=>{const m=useTheme(),d=s??m.space.xs,c=Math.max(1,e),h=useMemo(()=>Array.from({length:c},(e,t)=>({key:`sk-text-line-${t}`,index:t})),[c]);return _jsx(View,{style:l,testID:u,children:h.map(e=>{const s=e.index===c-1;return _jsx(Skeleton,{shape:"text",width:s&&c>1?t:r,height:o??m.text.base.size,radius:n,variant:i,labels:a,style:e.index<c-1?{marginBottom:d}:void 0},e.key)})})};SkeletonText.displayName="SkeletonText";const buildStyles=()=>StyleSheet.create({base:{overflow:"hidden"},shimmerBand:{position:"absolute",top:0,bottom:0,left:0}});export{Skeleton,SkeletonCircle,SkeletonText};export default Skeleton;
@@ -1 +1 @@
1
- "use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{isRecord}from"../../utils/guards.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text as LibraryText}from"../Text/index.js";import{DEFAULT_SKELETON_LABELS,Skeleton}from"./Skeleton.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{SkeletonSkip}from"./SkeletonSkip.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const DEFAULT_REVEAL_FADE_MS=300,flattenStyle=e=>({...StyleSheet.flatten(e)}),isWidthText=e=>"auto"===e||"100%"===e||/^\d+(\.\d+)?%$/.test(e),isComponentType=e=>"function"==typeof e||isRecord(e),resolveWidth=(e,t)=>"number"==typeof e||"string"==typeof e&&isWidthText(e)?e:t,resolveRadius=(e,t)=>"number"==typeof e?e:t,skeletonizeNode=(e,t,i,r,n="r")=>{if(null==t||"boolean"==typeof t)return null;if("string"==typeof t||"number"==typeof t)return _jsx(Skeleton,{shape:"text",width:"60%",height:14,variant:i,colors:r},`${n}-text`);if(Array.isArray(t))return Children.map(t,(t,s)=>skeletonizeNode(e,t,i,r,`${n}-${s}`));if(!isValidElement(t))return null;const s=t,o=s.props??{},l=s.type;if(l===SkeletonSkip)return cloneElement(s,{key:`${n}-skip`});if(("function"==typeof l||"object"==typeof l)&&"Skeleton"in l&&isComponentType(l.Skeleton)){const e=l.Skeleton;return _jsx(e,{...o},`${n}-self`)}if(l===Image){const e=flattenStyle(o.style),t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:120,l=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:l,variant:i,colors:r,style:{margin:"number"==typeof e.margin?e.margin:void 0}},`${n}-img`)}if(l===Text||l===LibraryText){const t=flattenStyle(o.style),s="number"==typeof t.fontSize?t.fontSize:e.text.base.size,l=resolveWidth(t.width,"85%");return _jsx(Skeleton,{shape:"text",width:l,height:Math.round(1.15*s),variant:i,colors:r,style:{marginVertical:e.space.xxs}},`${n}-txt`)}if(null!=o.children)return cloneElement(s,{key:`${n}-w`},skeletonizeNode(e,o.children,i,r,`${n}-c`));if(l===View){const e=flattenStyle(o.style);if(null!=e.width||null!=e.height){const t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:20,o=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:o,variant:i,colors:r},`${n}-vw`)}}return cloneElement(s,{key:`${n}-leaf`})},SkeletonContent=e=>{const{loading:t,children:i,placeholder:r,variant:n,count:s=1,colors:o,labels:l,fadeDuration:a,style:u,testID:c}=e;assertValidValue("SkeletonContent","variant",e.variant,["shimmer","pulse","none"]);const d=useTheme(),m=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...l}),[l]),f=useSkeletonDefaults(),h=usePresenceMotion(),y=a??f.fadeDuration??(h.reduced?h.duration("default"):300),p=useRef(t),S=useRef(createAnimatedValue(t?0:1)).current;if(useEffect(()=>{let e;return p.current&&!t?(S.setValue(0),e=Animated.timing(S,{toValue:1,duration:y,useNativeDriver:nativeDriver}),e.start()):!p.current&&t&&S.setValue(1),p.current=t,()=>e?.stop()},[t,S,y]),!t)return y<=0?_jsx(_Fragment,{children:i}):_jsx(Animated.View,{style:[u,{opacity:S}],testID:c,children:i});if(void 0!==r){const e=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:r},`sk-ph-${t}`)):r;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:e})}const k=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:i},`sk-rep-${t}`)):i;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:skeletonizeNode(d,k,n,o)})};SkeletonContent.displayName="SkeletonContent";export{SkeletonContent};export default SkeletonContent;
1
+ "use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{isRecord}from"../../utils/guards.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text as LibraryText}from"../Text/index.js";import{DEFAULT_SKELETON_LABELS,Skeleton}from"./Skeleton.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{SkeletonSkip}from"./SkeletonSkip.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const DEFAULT_REVEAL_FADE_MS=300,flattenStyle=e=>({...StyleSheet.flatten(e)}),isWidthText=e=>"auto"===e||"100%"===e||/^\d+(\.\d+)?%$/.test(e),isComponentType=e=>"function"==typeof e||isRecord(e),resolveWidth=(e,t)=>"number"==typeof e||"string"==typeof e&&isWidthText(e)?e:t,resolveRadius=(e,t)=>"number"==typeof e?e:t,skeletonizeNode=(e,t,i,r,n="r")=>{if(null==t||"boolean"==typeof t)return null;if("string"==typeof t||"number"==typeof t)return _jsx(Skeleton,{shape:"text",width:"60%",height:14,variant:i,colors:r},`${n}-text`);if(Array.isArray(t))return Children.map(t,(t,s)=>skeletonizeNode(e,t,i,r,`${n}-${s}`));if(!isValidElement(t))return null;const s=t,o=s.props??{},l=s.type;if(l===SkeletonSkip)return cloneElement(s,{key:`${n}-skip`});if(("function"==typeof l||"object"==typeof l)&&"Skeleton"in l&&isComponentType(l.Skeleton)){const e=l.Skeleton;return _jsx(e,{...o},`${n}-self`)}if(l===Image){const e=flattenStyle(o.style),t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:120,l=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:l,variant:i,colors:r,style:{margin:"number"==typeof e.margin?e.margin:void 0}},`${n}-img`)}if(l===Text||l===LibraryText){const t=flattenStyle(o.style),s="number"==typeof t.fontSize?t.fontSize:e.text.base.size,l=resolveWidth(t.width,"85%");return _jsx(Skeleton,{shape:"text",width:l,height:Math.round(1.15*s),variant:i,colors:r,style:{marginVertical:e.space.xxs}},`${n}-txt`)}if(null!=o.children)return cloneElement(s,{key:`${n}-w`},skeletonizeNode(e,o.children,i,r,`${n}-c`));if(l===View){const e=flattenStyle(o.style);if(null!=e.width||null!=e.height){const t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:20,o=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:o,variant:i,colors:r},`${n}-vw`)}}return cloneElement(s,{key:`${n}-leaf`})},SkeletonContent=e=>{const{loading:t,children:i,placeholder:r,variant:n,count:s=1,colors:o,labels:l,fadeDuration:a,style:u,testID:c}=e;assertValidValue("SkeletonContent","variant",e.variant,["shimmer","pulse","none"]);const m=useTheme(),d=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...l}),[l]),f=useMemo(()=>Array.from({length:s},(e,t)=>({key:`sk-slot-${t}`})),[s]),y=useSkeletonDefaults(),h=usePresenceMotion(),p=a??y.fadeDuration??(h.reduced?h.duration("default"):300),S=useRef(t),k=useRef(createAnimatedValue(t?0:1)).current;if(useEffect(()=>{let e;return S.current&&!t?(k.setValue(0),e=Animated.timing(k,{toValue:1,duration:p,useNativeDriver:nativeDriver}),e.start()):!S.current&&t&&k.setValue(1),S.current=t,()=>e?.stop()},[t,k,p]),!t)return p<=0?_jsx(_Fragment,{children:i}):_jsx(Animated.View,{style:[u,{opacity:k}],testID:c,children:i});if(void 0!==r){const e=s>1?f.map(e=>_jsx(React.Fragment,{children:r},e.key)):r;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:d.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:e})}const b=s>1?f.map(e=>_jsx(React.Fragment,{children:i},e.key)):i;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:d.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:skeletonizeNode(m,b,n,o)})};SkeletonContent.displayName="SkeletonContent";export{SkeletonContent};export default SkeletonContent;
@@ -1 +1 @@
1
- "use strict";import React from"react";import{FlatList,View}from"react-native";import{SkeletonContent}from"./SkeletonContent.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{jsx as _jsx}from"react/jsx-runtime";export function SkeletonList(e){const{loading:t,data:o,renderItem:n,renderPlaceholder:r,placeholderCount:l,variant:s,colors:a,labels:i,placeholderContainerStyle:c,horizontal:m,contentContainerStyle:d,style:u,testID:f,...h}=e,x=useSkeletonDefaults(),y=l??x.placeholderCount??3;if(t){const e=Array.from({length:Math.max(0,y)},(e,t)=>_jsx(React.Fragment,{children:r?r(t):null},`sk-list-${t}`));return _jsx(SkeletonContent,{loading:!0,variant:s,colors:a,labels:i,style:u,testID:f,children:_jsx(View,{style:[m?styles.row:styles.column,c],children:e})})}return _jsx(FlatList,{data:o??[],renderItem:n,horizontal:m,contentContainerStyle:d,style:u,testID:f,...h})}const styles={row:{flexDirection:"row"},column:{flexDirection:"column"}};
1
+ "use strict";import React,{useMemo}from"react";import{FlatList,View}from"react-native";import{SkeletonContent}from"./SkeletonContent.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{jsx as _jsx}from"react/jsx-runtime";export function SkeletonList(e){const{loading:t,data:o,renderItem:n,renderPlaceholder:l,placeholderCount:r,variant:s,colors:a,labels:i,placeholderContainerStyle:c,horizontal:m,contentContainerStyle:d,style:u,testID:x,...y}=e,f=useSkeletonDefaults(),h=r??f.placeholderCount??3,k=useMemo(()=>Array.from({length:Math.max(0,h)},(e,t)=>({key:`sk-list-${t}`,index:t})),[h]);return t?_jsx(SkeletonContent,{loading:!0,variant:s,colors:a,labels:i,style:u,testID:x,children:_jsx(View,{style:[m?styles.row:styles.column,c],children:k.map(e=>_jsx(React.Fragment,{children:l?l(e.index):null},e.key))})}):_jsx(FlatList,{data:o??[],renderItem:n,horizontal:m,contentContainerStyle:d,style:u,testID:x,...y})}const styles={row:{flexDirection:"row"},column:{flexDirection:"column"}};
@@ -1 +1 @@
1
- "use strict";import{memo,useEffect,useRef,useState}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const sliderToneInk=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];case"primary":return e.colors["on-primary"]}};export const clampValue=(e,t,n)=>Math.min(Math.max(e,t),n);export const snapValue=(e,t,n,r)=>{if(r<=0)return clampValue(e,t,n);const o=String(r).split(".")[1]?.length??0,s=Math.round((e-t)/r)*r+t;return clampValue(o>0?Number(s.toFixed(o)):s,t,n)};export const parseTyped=e=>{const t=e.replace(/[^\d.-]/g,"");if(""===t||"."===t||"-"===t)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?n:null};const easeOutCubic=e=>1-(1-e)**3,roundTo=(e,t)=>{const n=10**t;return Math.round(e*n)/n};export const CountingText=memo(({value:e,format:t,decimals:n=2,duration:r,jumpKey:o="",style:s,testID:l})=>{const[a,i]=useState(e),u=useRef(e),c=useRef(o);return useEffect(()=>{const t=c.current!==o;c.current=o;const n=u.current;if(t||r<=0||n===e)return u.current=e,void i(e);const s=Date.now();let l=0;const tick=()=>{const t=Math.min(1,(Date.now()-s)/r),o=n+(e-n)*easeOutCubic(t);u.current=o,i(o),t<1&&(l=requestAnimationFrame(tick))};return l=requestAnimationFrame(tick),()=>cancelAnimationFrame(l)},[e,o,r]),_jsx(Text,{variant:"caption",weight:"semibold",style:s,testID:l,children:t(roundTo(a,n))})});CountingText.displayName="CountingText";export const useValueDraft=({value:e,min:t,max:n,step:r,format:o,parse:s=parseTyped,onChange:l})=>{const[a,i]=useState(null);return{text:a??o(e),editing:null!==a,onFocus:()=>i(o(e)),onChangeText:e=>{i(e);const r=s(e);null!==r&&l(clampValue(r,t,n))},onBlur:()=>{if(null===a)return;const o=s(a);i(null);const u=snapValue(o??t,t,n,r);u!==e&&l(u)}}};const ROLL_TRAVEL_RATIO=1.2,RollingSlot=memo(({text:e,direction:t,duration:n,style:r,testID:o})=>{const[s,l]=useState(null),a=useRef(e),i=useRef(new Animated.Value(1)).current,u=1.2*(StyleSheet.flatten(r)?.fontSize??14);useEffect(()=>{if(a.current===e)return;const t=a.current;if(a.current=e,n<=0)return void l(null);l(t),i.setValue(0);const r=Animated.timing(i,{toValue:1,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver});return r.start(({finished:e})=>{e&&l(null)}),()=>r.stop()},[e,n,i]);const c="up"===t?-1:1,m=null===s?null:{opacity:i,transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[-c*u,0]})}]},p={opacity:i.interpolate({inputRange:[0,1],outputRange:[1,0]}),transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[0,c*u]})}]};return _jsxs(View,{style:rollStyles.slot,children:[_jsx(Animated.Text,{style:[r,m],testID:o,children:e}),null!==s?_jsx(Animated.Text,{style:[r,rollStyles.leaving,p],testID:o?`${o}-leaving`:void 0,children:s}):null]})});RollingSlot.displayName="RollingSlot";export const RollingText=memo(({text:e,direction:t="up",duration:n,perCharacter:r=!0,style:o,testID:s})=>{const l=useRef(e),a=r?Math.max(e.length,l.current.length):1;return useEffect(()=>{l.current=e},[e]),_jsx(View,{style:rollStyles.row,testID:s,children:r?Array.from({length:a},(r,l)=>_jsx(RollingSlot,{text:e[l]??"",direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0},l)):_jsx(RollingSlot,{text:e,direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0})})});RollingText.displayName="RollingText";const rollStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"baseline"},slot:{overflow:"hidden"},leaving:{position:"absolute",left:0,top:0}});
1
+ "use strict";import{memo,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,StyleSheet,View}from"react-native";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const sliderToneInk=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];case"primary":return e.colors["on-primary"]}};export const clampValue=(e,t,n)=>Math.min(Math.max(e,t),n);export const snapValue=(e,t,n,r)=>{if(r<=0)return clampValue(e,t,n);const o=String(r).split(".")[1]?.length??0,s=Math.round((e-t)/r)*r+t;return clampValue(o>0?Number(s.toFixed(o)):s,t,n)};export const parseTyped=e=>{const t=e.replace(/[^\d.-]/g,"");if(""===t||"."===t||"-"===t)return null;const n=Number.parseFloat(t);return Number.isFinite(n)?n:null};const easeOutCubic=e=>1-(1-e)**3,roundTo=(e,t)=>{const n=10**t;return Math.round(e*n)/n};export const CountingText=memo(({value:e,format:t,decimals:n=2,duration:r,jumpKey:o="",style:s,testID:l})=>{const[a,i]=useState(e),u=useRef(e),c=useRef(o);return useEffect(()=>{const t=c.current!==o;c.current=o;const n=u.current;if(t||r<=0||n===e)return u.current=e,void i(e);const s=Date.now();let l=0;const tick=()=>{const t=Math.min(1,(Date.now()-s)/r),o=n+(e-n)*easeOutCubic(t);u.current=o,i(o),t<1&&(l=requestAnimationFrame(tick))};return l=requestAnimationFrame(tick),()=>cancelAnimationFrame(l)},[e,o,r]),_jsx(Text,{variant:"caption",weight:"semibold",style:s,testID:l,children:t(roundTo(a,n))})});CountingText.displayName="CountingText";export const useValueDraft=({value:e,min:t,max:n,step:r,format:o,parse:s=parseTyped,onChange:l})=>{const[a,i]=useState(null);return{text:a??o(e),editing:null!==a,onFocus:()=>i(o(e)),onChangeText:e=>{i(e);const r=s(e);null!==r&&l(clampValue(r,t,n))},onBlur:()=>{if(null===a)return;const o=s(a);i(null);const u=snapValue(o??t,t,n,r);u!==e&&l(u)}}};const ROLL_TRAVEL_RATIO=1.2,RollingSlot=memo(({text:e,direction:t,duration:n,style:r,testID:o})=>{const[s,l]=useState(null),a=useRef(e),i=useRef(new Animated.Value(1)).current,u=1.2*(StyleSheet.flatten(r)?.fontSize??14);useEffect(()=>{if(a.current===e)return;const t=a.current;if(a.current=e,n<=0)return void l(null);l(t),i.setValue(0);const r=Animated.timing(i,{toValue:1,duration:n,easing:Easing.out(Easing.cubic),useNativeDriver:nativeDriver});return r.start(({finished:e})=>{e&&l(null)}),()=>r.stop()},[e,n,i]);const c="up"===t?-1:1,m=null===s?null:{opacity:i,transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[-c*u,0]})}]},p={opacity:i.interpolate({inputRange:[0,1],outputRange:[1,0]}),transform:[{translateY:i.interpolate({inputRange:[0,1],outputRange:[0,c*u]})}]};return _jsxs(View,{style:rollStyles.slot,children:[_jsx(Animated.Text,{style:[r,m],testID:o,children:e}),null!==s?_jsx(Animated.Text,{style:[r,rollStyles.leaving,p],testID:o?`${o}-leaving`:void 0,children:s}):null]})});RollingSlot.displayName="RollingSlot";export const RollingText=memo(({text:e,direction:t="up",duration:n,perCharacter:r=!0,style:o,testID:s})=>{const l=useRef(e),a=r?Math.max(e.length,l.current.length):1;useEffect(()=>{l.current=e},[e]);const i=useMemo(()=>Array.from({length:a},(e,t)=>({key:`roll-slot-${t}`,index:t})),[a]);return _jsx(View,{style:rollStyles.row,testID:s,children:r?i.map(({key:r,index:l})=>_jsx(RollingSlot,{text:e[l]??"",direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0},r)):_jsx(RollingSlot,{text:e,direction:t,duration:n,style:o,testID:s?`${s}-char`:void 0})})});RollingText.displayName="RollingText";const rollStyles=StyleSheet.create({row:{flexDirection:"row",alignItems:"baseline"},slot:{overflow:"hidden"},leaving:{position:"absolute",left:0,top:0}});