@webority/mobile-ui 0.146.1 → 0.147.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 (126) hide show
  1. package/dist/canvas-kit/kit.js +4344 -4214
  2. package/dist/canvas-kit/manifest.json +1 -1
  3. package/dist/canvas-kit/release.json +5 -5
  4. package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
  5. package/lib/commonjs/components/Avatar/Avatar.js +1 -1
  6. package/lib/commonjs/components/Badge/Badge.js +1 -1
  7. package/lib/commonjs/components/Banner/Banner.js +1 -1
  8. package/lib/commonjs/components/BarChart/BarChart.js +1 -1
  9. package/lib/commonjs/components/BottomNavigation/BottomNavigation.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/Calendar/Calendar.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/Confetti/Confetti.js +1 -1
  16. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  17. package/lib/commonjs/components/Drawer/Drawer.js +1 -1
  18. package/lib/commonjs/components/FieldBase/Chevron.js +1 -1
  19. package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
  20. package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
  21. package/lib/commonjs/components/FormField/FormField.js +1 -1
  22. package/lib/commonjs/components/Input/Input.js +1 -1
  23. package/lib/commonjs/components/LoaderOverlay/LoaderOverlay.js +1 -1
  24. package/lib/commonjs/components/Menu/MenuSurface.js +1 -1
  25. package/lib/commonjs/components/MessageList/MessageList.js +1 -1
  26. package/lib/commonjs/components/Modal/Modal.js +1 -1
  27. package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
  28. package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
  29. package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
  30. package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
  31. package/lib/commonjs/components/Radio/RadioDot.js +1 -1
  32. package/lib/commonjs/components/Rating/Rating.js +1 -1
  33. package/lib/commonjs/components/RichTextEditor/markdownActions.js +1 -1
  34. package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
  35. package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
  36. package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
  37. package/lib/commonjs/components/SignaturePad/signatureGeometry.js +1 -1
  38. package/lib/commonjs/components/Skeleton/SkeletonClock.js +1 -1
  39. package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
  40. package/lib/commonjs/components/Slider/valueText.js +1 -1
  41. package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
  42. package/lib/commonjs/components/Sparkline/geometry.js +1 -1
  43. package/lib/commonjs/components/Spinner/Spinner.js +1 -1
  44. package/lib/commonjs/components/Stepper/Stepper.js +1 -1
  45. package/lib/commonjs/components/Switch/Switch.js +1 -1
  46. package/lib/commonjs/components/Tabs/Tabs.js +1 -1
  47. package/lib/commonjs/components/TagInput/TagInput.js +1 -1
  48. package/lib/commonjs/components/Text/Text.js +1 -1
  49. package/lib/commonjs/components/Toast/Toast.js +1 -1
  50. package/lib/commonjs/components/Toast/ToastProvider.js +1 -1
  51. package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
  52. package/lib/commonjs/components/Tour/Tour.js +1 -1
  53. package/lib/commonjs/form/path.js +1 -1
  54. package/lib/commonjs/hooks/useDragToDismiss.js +1 -1
  55. package/lib/commonjs/hooks/usePressAnimation.js +1 -1
  56. package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
  57. package/lib/commonjs/theme/animatedValue.js +1 -1
  58. package/lib/commonjs/theme/componentSizes.js +1 -1
  59. package/lib/commonjs/theme/merge.js +1 -1
  60. package/lib/commonjs/theme/toneInk.js +1 -1
  61. package/lib/commonjs/utils/color.js +1 -1
  62. package/lib/commonjs/utils/nativeDriver.js +1 -0
  63. package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
  64. package/lib/module/components/Avatar/Avatar.js +1 -1
  65. package/lib/module/components/Badge/Badge.js +1 -1
  66. package/lib/module/components/Banner/Banner.js +1 -1
  67. package/lib/module/components/BarChart/BarChart.js +1 -1
  68. package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
  69. package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
  70. package/lib/module/components/Button/Button.js +1 -1
  71. package/lib/module/components/Calendar/Calendar.js +1 -1
  72. package/lib/module/components/Carousel/Carousel.js +1 -1
  73. package/lib/module/components/Checkbox/Checkbox.js +1 -1
  74. package/lib/module/components/Confetti/Confetti.js +1 -1
  75. package/lib/module/components/DatePicker/DatePicker.js +1 -1
  76. package/lib/module/components/Drawer/Drawer.js +1 -1
  77. package/lib/module/components/FieldBase/Chevron.js +1 -1
  78. package/lib/module/components/FilePicker/FilePicker.js +1 -1
  79. package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
  80. package/lib/module/components/FormField/FormField.js +1 -1
  81. package/lib/module/components/Input/Input.js +1 -1
  82. package/lib/module/components/LoaderOverlay/LoaderOverlay.js +1 -1
  83. package/lib/module/components/Menu/MenuSurface.js +1 -1
  84. package/lib/module/components/MessageList/MessageList.js +1 -1
  85. package/lib/module/components/Modal/Modal.js +1 -1
  86. package/lib/module/components/OTPInput/OTPInput.js +1 -1
  87. package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
  88. package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
  89. package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
  90. package/lib/module/components/Radio/RadioDot.js +1 -1
  91. package/lib/module/components/Rating/Rating.js +1 -1
  92. package/lib/module/components/RichTextEditor/markdownActions.js +1 -1
  93. package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
  94. package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
  95. package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
  96. package/lib/module/components/SignaturePad/signatureGeometry.js +1 -1
  97. package/lib/module/components/Skeleton/SkeletonClock.js +1 -1
  98. package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
  99. package/lib/module/components/Slider/valueText.js +1 -1
  100. package/lib/module/components/Sparkline/Sparkline.js +1 -1
  101. package/lib/module/components/Sparkline/geometry.js +1 -1
  102. package/lib/module/components/Spinner/Spinner.js +1 -1
  103. package/lib/module/components/Stepper/Stepper.js +1 -1
  104. package/lib/module/components/Switch/Switch.js +1 -1
  105. package/lib/module/components/Tabs/Tabs.js +1 -1
  106. package/lib/module/components/TagInput/TagInput.js +1 -1
  107. package/lib/module/components/Text/Text.js +1 -1
  108. package/lib/module/components/Toast/Toast.js +1 -1
  109. package/lib/module/components/Toast/ToastProvider.js +1 -1
  110. package/lib/module/components/Tooltip/Tooltip.js +1 -1
  111. package/lib/module/components/Tour/Tour.js +1 -1
  112. package/lib/module/form/path.js +1 -1
  113. package/lib/module/hooks/useDragToDismiss.js +1 -1
  114. package/lib/module/hooks/usePressAnimation.js +1 -1
  115. package/lib/module/network/NetworkStatusBanner.js +1 -1
  116. package/lib/module/theme/animatedValue.js +1 -1
  117. package/lib/module/theme/componentSizes.js +1 -1
  118. package/lib/module/theme/merge.js +1 -1
  119. package/lib/module/theme/toneInk.js +1 -1
  120. package/lib/module/utils/color.js +1 -1
  121. package/lib/module/utils/nativeDriver.js +1 -0
  122. package/lib/typescript/commonjs/theme/animatedValue.d.ts +1 -1
  123. package/lib/typescript/commonjs/utils/nativeDriver.d.ts +2 -0
  124. package/lib/typescript/module/theme/animatedValue.d.ts +1 -1
  125. package/lib/typescript/module/utils/nativeDriver.d.ts +2 -0
  126. package/package.json +7 -7
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:o,placeholder:n,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:y,prefixStyle:b,readOnly:S=!1,action:v,actionStyle:w,size:T="md",variant:j,labelMode:I,required:V=!1,maxLength:F,showCounter:_=!0,textAlign:A,format:R,parse:z,style:L,containerStyle:k,inputStyle:P,labelStyle:C,messageStyle:D,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;assertValidValue("Input","variant",j,["outline","filled","underline"]),assertValidValue("Input","size",e.size,["sm","md","lg"]),assertValidValue("Input","labelMode",I,["float","top"]),assertValidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,T),J=W.components.input[T]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=j??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=I??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),oe="password"===d||u||c,ne="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(y),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ye=useCallback(()=>{me&&ge.current?.focus()},[me]),be=pe&&"float"===Y,Se=useRef(createAnimatedValue(0)).current,ve=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(ve,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[ue,ve,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Te=W.settings.components.input?.shakeOnError??!1,je=useRef(de);useEffect(()=>{if(!Te)return void(je.current=de);let e;return de&&!je.current&&(we||(setNativeValue(Se,0),e=Animated.sequence([Animated.timing(Se,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(Se,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(Se,{toValue:1,duration:50,useNativeDriver:!0}),Animated.timing(Se,{toValue:-1,duration:50,useNativeDriver:!0}),Animated.timing(Se,{toValue:0,duration:100,useNativeDriver:!0})]),e.start()),triggerHaptic("notificationError")),je.current=de,()=>e?.stop()},[de,Se,Te,we]);const Ie=useCallback(e=>{ee(!0),E?.(e)},[E]),Ve=useCallback(e=>{ee(!1),B?.(e)},[B]),Fe=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,ze=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],Le=Se.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),ke=Boolean(x)||Boolean(g)||ne,Pe="underline"===Q,Ce=m?X.icon+W.space.md+1+W.space.md:0,De=useFloatingLabel({label:i,enabled:be,floated:xe,required:V,variant:Q,sizeTokens:X,leadingOffset:Ce,trailingOffset:ke?X.icon+W.space.sm:0,textAlign:A,paddingLeft:Pe?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:ze,style:C}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=V&&!pe&&!re&&"string"==typeof n&&n.length>0,He=de?r:a,Oe=_&&"number"==typeof F&&"string"==typeof l?`${l.length} / ${F}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(D,X["message-text"],qe),Ue=M??fieldTextAsString(i)??n,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(ne){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Fe,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(b),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof y||"number"==typeof y?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},b],children:y}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},b],children:_jsx(TextInkContext.Provider,{value:Ze,children:y})})}):null,tt=v?_jsx(Button,{variant:v.variant??"outline",tone:v.tone??"primary",size:T,label:v.label,leftIcon:v.icon,loading:v.loading,disabled:p||v.disabled,onPress:v.onPress,pressAnimation:!1,testID:v.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:Le}]},L],children:[pe&&!be?_jsx(FieldLabel,{size:T,required:V,help:o,color:ze,style:C,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:T,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:Pe?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:De.topNotch,onPress:ye,pressFeedback:!1,style:k,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:Pe?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},P],textAlign:A,placeholder:be&&!xe||Me?void 0:n,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(z?z(e):e)},onFocus:Ie,onBlur:Ve,editable:me,readOnly:S,secureTextEntry:oe&&!te,multiline:le,autoCapitalize:oe?"none":void 0,autoCorrect:!oe&&void 0,maxLength:F,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me?_jsx(RequiredPlaceholder,{text:n,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),De.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:ve}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},D],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,Text,TextInput,View}from"react-native";import{useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveFieldSize,setNativeValue,useTheme}from"../../theme/index.js";import{mergeRefs,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Button}from"../Button/index.js";import{FieldBase,FieldErrorGlyph,FieldLabel,fieldTextAsString,hasFieldText,RequiredPlaceholder,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{TextInkContext,useTextInk}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_INPUT_LABELS={showPassword:"Show password",hidePassword:"Hide password"};const Input=forwardRef((e,t)=>{const{label:i,help:n,placeholder:o,value:l,onChangeText:s,error:r,helperText:a,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:p=!1,multiline:f=!1,leftIcon:m,rightIcon:x,unit:g,unitStyle:h,prefix:v,prefixStyle:y,readOnly:b=!1,action:S,actionStyle:w,size:T="md",variant:j,labelMode:I,required:V=!1,maxLength:F,showCounter:_=!0,textAlign:A,format:R,parse:D,style:z,containerStyle:L,inputStyle:k,labelStyle:P,messageStyle:C,radius:N,onFocus:E,onBlur:B,accessibilityLabel:M,labels:H,testID:O,editable:q,...G}=e;assertValidValue("Input","variant",j,["outline","filled","underline"]),assertValidValue("Input","size",e.size,["sm","md","lg"]),assertValidValue("Input","labelMode",I,["float","top"]),assertValidValue("Input","type",e.type,["input","password","textarea"]);const U=useMemo(()=>({...DEFAULT_INPUT_LABELS,...H}),[H]),W=useTheme(),$=useMemo(()=>buildStyles(W),[W]),X=resolveFieldSize(W,T),J=W.components.input[T]["multiline-min-height"],K=Math.round(X.text*W.leading.body),Q=j??W.settings.components.input?.defaultVariant??W.settings.components.field?.defaultVariant??"outline",Y=I??W.settings.components.input?.defaultLabelMode??"top",[Z,ee]=useState(!1),[te,ie]=useState(!1),ne="password"===d||u||c,oe="password"===d||u,le="textarea"===d||f,se=le?Math.round(.1*X.text):0,re="string"==typeof l&&l.length>0,ae=hasFieldText(r),de=!0===r||ae,ce=hasFieldText(a),ue=ae||!de&&ce,pe=hasFieldText(i),fe=hasFieldText(v),me=!p&&!1!==q,xe=Z||re||fe,ge=useRef(null),he=useMemo(()=>mergeRefs(ge,t),[t]),ve=useCallback(()=>{me&&ge.current?.focus()},[me]),ye=pe&&"float"===Y,be=useRef(createAnimatedValue(0)).current,Se=useRef(createAnimatedValue(ue?1:0)).current;useEffect(()=>{const e=Animated.timing(Se,{toValue:ue?1:0,duration:W.motion.duration.fast,easing:Easing.bezier(...W.motion.ease["in-out"]),useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[ue,Se,W.motion.duration.fast,W.motion.ease["in-out"]]);const we=useReducedMotion(),Te=W.settings.components.input?.shakeOnError??!1,je=useRef(de);useEffect(()=>{if(!Te)return void(je.current=de);let e;return de&&!je.current&&(we||(setNativeValue(be,0),e=Animated.sequence([Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:-1,duration:50,useNativeDriver:nativeDriver}),Animated.timing(be,{toValue:0,duration:100,useNativeDriver:nativeDriver})]),e.start()),triggerHaptic("notificationError")),je.current=de,()=>e?.stop()},[de,be,Te,we]);const Ie=useCallback(e=>{ee(!0),E?.(e)},[E]),Ve=useCallback(e=>{ee(!1),B?.(e)},[B]),Fe=useCallback(()=>{triggerHaptic("selection"),ie(e=>!e)},[]),Ae=W.colors["field-caret"],Re=W.settings.components.input?.tintLabelOnFocus??!1,De=Z&&Re?W.colors["field-border-focus"]:W.colors["field-label"],ze=be.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Le=Boolean(x)||Boolean(g)||oe,ke="underline"===Q,Pe=m?X.icon+W.space.md+1+W.space.md:0,Ce=useFloatingLabel({label:i,enabled:ye,floated:xe,required:V,variant:Q,sizeTokens:X,leadingOffset:Pe,trailingOffset:Le?X.icon+W.space.sm:0,textAlign:A,paddingLeft:ke?W.space.none:X["padding-x"],lineHeight:le?K:void 0,restNudge:se,floatTrim:le?2:0,color:De,style:P}),Ne=resolveFieldTextStyle(W,{disabled:p}),Ee=Ne.color,Be=Ne.placeholderColor,Me=V&&!pe&&!re&&"string"==typeof o&&o.length>0,He=de?r:a,Oe=_&&"number"==typeof F&&"string"==typeof l?`${l.length} / ${F}`:null,qe=de?W.colors["field-message"]:W.colors["text-muted"],Ge=useTextInk(C,X["message-text"],qe),Ue=M??fieldTextAsString(i)??o,We=p?W.colors["field-icon-disabled"]:Z?W.colors["field-icon-focus"]:W.colors["field-icon"],$e={focused:Z,disabled:p,error:de,color:We,size:X.icon},renderSlot=e=>renderSlotIcon(e,$e),Xe=(()=>{if(oe){const e=(te?W.settings.icons.eyeOff:W.settings.icons.eye)??(te?defaultIcons.eyeOff:defaultIcons.eye);return _jsx(Pressable,{onPress:Fe,disabled:!me,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:te?U.hidePassword:U.showPassword,children:e({size:X.icon,color:We})})}const e=g?_jsx(Text,{style:[$.unit,{fontSize:X.text,color:Be},h],children:g}):null,t=x?slotIconView(x,renderSlot(x)):null;return e&&t?_jsxs(View,{style:$.trailingRow,children:[e,t]}):e??t})(),Je=m?slotIconView(m,renderSlot(m)):null,Ke=StyleSheet.flatten(y),Qe=Ke?.fontSize??X.text,Ye=Ke?.color??Be,Ze=useMemo(()=>({fontSize:Qe,color:Ye}),[Qe,Ye]),et=fe?"string"==typeof v||"number"==typeof v?_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,marginRight:W.space.xs,lineHeight:le?K:void 0,paddingTop:le?se:void 0},y],children:v}):_jsx(View,{style:[$.prefixNode,{marginRight:W.space.xs,minHeight:le?K:void 0,justifyContent:"center",paddingTop:le?se:void 0}],children:_jsx(Text,{style:[$.prefix,{fontSize:X.text,color:Be,lineHeight:le?K:void 0},y],children:_jsx(TextInkContext.Provider,{value:Ze,children:v})})}):null,tt=S?_jsx(Button,{variant:S.variant??"outline",tone:S.tone??"primary",size:T,label:S.label,leftIcon:S.icon,loading:S.loading,disabled:p||S.disabled,onPress:S.onPress,pressAnimation:!1,testID:S.testID,style:[$.action,{minHeight:X["min-height"],alignSelf:le?"flex-start":"stretch"},w]}):null;return _jsxs(Animated.View,{style:[$.container,{transform:[{translateX:ze}]},z],children:[pe&&!ye?_jsx(FieldLabel,{size:T,required:V,help:n,color:De,style:P,children:i}):null,_jsxs(View,{style:[$.fieldRow,{columnGap:W.space.sm,alignItems:le?"flex-start":"stretch"}],children:[_jsxs(View,{style:$.fieldWrapper,children:[_jsxs(FieldBase,{size:T,variant:Q,focused:Z,disabled:p,error:de,filled:re,minHeight:le?J:void 0,radius:N,leading:Je,leadingDivider:null!=m,paddingLeft:ke?W.space.none:void 0,trailing:Xe,slotAlign:le?"top":"center",slotLineHeight:le?K:void 0,topNotch:Ce.topNotch,onPress:ve,pressFeedback:!1,style:L,children:[et,_jsxs(View,{style:$.inputWrap,children:[_jsx(TextInput,{ref:he,style:[$.input,{color:Ee,fontSize:X.text,...Ne.weightStyle,paddingLeft:ke?W.space.none:void 0,minHeight:le?J-2*X["padding-y"]:void 0,lineHeight:le?K:void 0,paddingTop:le?se:void 0,textAlignVertical:le?"top":"center"},k],textAlign:A,placeholder:ye&&!xe||Me?void 0:o,placeholderTextColor:Be,value:R&&null!=l?R(l):l,onChangeText:e=>{s&&s(D?D(e):e)},onFocus:Ie,onBlur:Ve,editable:me,readOnly:b,secureTextEntry:ne&&!te,multiline:le,autoCapitalize:ne?"none":void 0,autoCorrect:!ne&&void 0,maxLength:F,selectionColor:Ae,accessibilityLabel:Ue,accessibilityState:{disabled:p},"aria-disabled":p,testID:O,...G}),Me?_jsx(RequiredPlaceholder,{text:o,color:Be,fontSize:X.text,weightStyle:Ne.weightStyle,align:le?"top":"center",paddingTop:le?se:void 0,textAlign:A}):null]})]}),Ce.node]}),tt]}),ue||Oe?_jsxs(View,{style:[$.footerRow,{marginTop:X["message-gap"]}],children:[ue?_jsxs(Animated.View,{style:[$.messageRow,{columnGap:W.space.xs,opacity:Se}],accessibilityLiveRegion:de?"polite":"none",children:[de?_jsx(FieldErrorGlyph,{size:X["message-text"],color:qe}):null,_jsx(Text,{style:[$.messageText,{color:qe,fontSize:X["message-text"],...fontFor(W,"normal")},C],children:_jsx(TextInkContext.Provider,{value:Ge,children:He})})]}):_jsx(View,{style:$.footerSpacer}),Oe?_jsx(Text,{style:[$.counterText,{color:W.colors["text-subtle"],fontSize:X["message-text"],...fontFor(W,"normal")}],children:Oe}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});export{Input};export default Input;
@@ -1 +1 @@
1
- "use strict";import{useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,StyleSheet}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const DEFAULT_SHOW_DELAY_MS=150,DEFAULT_MIN_VISIBLE_MS=400;let state={refCount:0,message:void 0};const listeners=new Set,notify=()=>{for(const e of listeners)e()},subscribe=e=>(listeners.add(e),()=>{listeners.delete(e)}),getState=()=>state,show=e=>{state={refCount:state.refCount+1,message:e??state.message},notify()},hide=()=>{if(state.refCount<=0)return;const e=state.refCount-1;state={refCount:e,message:0===e?void 0:state.message},notify()},reset=()=>{0===state.refCount&&void 0===state.message||(state={refCount:0,message:void 0},notify())},isVisible=()=>state.refCount>0,wrap=async(e,t)=>{show(t);try{return await("function"==typeof e?e():e)}finally{hide()}};export const loader={show:show,hide:hide,wrap:wrap,isVisible:isVisible,reset:reset};export const useLoader=()=>loader;export const DEFAULT_LOADER_OVERLAY_LABELS={loading:"Loading"};export const LoaderOverlay=({renderIndicator:e,backdropColor:t,showDelayMs:s=150,minVisibleMs:r=400,labels:n,testID:i})=>{const o=useTheme(),a=usePresenceMotion().duration("default"),u=useSyncExternalStore(subscribe,getState),[l,c]=useState(!1),f=useRef(null),m=useRef(null),d=useRef(null),y=useRef(createAnimatedValue(0)).current,b=u.refCount>0;useEffect(()=>{if(b)return null!==m.current&&(clearTimeout(m.current),m.current=null),void(l||null!==f.current||(f.current=setTimeout(()=>{f.current=null,0!==getState().refCount&&(d.current=Date.now(),c(!0))},s)));if(null!==f.current&&(clearTimeout(f.current),f.current=null),l&&null===m.current){const e=null!==d.current?Date.now()-d.current:r,t=Math.max(0,r-e);m.current=setTimeout(()=>{m.current=null,d.current=null,c(!1)},t)}},[b,l,s,r]),useEffect(()=>()=>{null!==f.current&&clearTimeout(f.current),null!==m.current&&clearTimeout(m.current)},[]),useEffect(()=>{l?Animated.timing(y,{toValue:1,duration:a,easing:Easing.bezier(...o.motion.ease["in-out"]),useNativeDriver:!0}).start():y.setValue(0)},[l,a,y,o]),useEffect(()=>{if(!l)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>!0);return()=>{e.remove()}},[l]);const S=u.message;useEffect(()=>{l&&S&&AccessibilityInfo.announceForAccessibility(S)},[l,S]);const g=useMemo(()=>buildStyles(),[]),E=useMemo(()=>({...DEFAULT_LOADER_OVERLAY_LABELS,...n}),[n]);return l?_jsx(Animated.View,{pointerEvents:"auto",testID:i,accessible:!0,accessibilityViewIsModal:!0,accessibilityLiveRegion:"polite",accessibilityLabel:S??E.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,style:[g.overlay,{backgroundColor:t??o.colors.scrim,opacity:y}],children:e?e(S):_jsx(Spinner,{size:"lg",message:S})}):null};const buildStyles=()=>StyleSheet.create({overlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center",zIndex:1e3}});
1
+ "use strict";import{useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,StyleSheet}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx}from"react/jsx-runtime";const DEFAULT_SHOW_DELAY_MS=150,DEFAULT_MIN_VISIBLE_MS=400;let state={refCount:0,message:void 0};const listeners=new Set,notify=()=>{for(const e of listeners)e()},subscribe=e=>(listeners.add(e),()=>{listeners.delete(e)}),getState=()=>state,show=e=>{state={refCount:state.refCount+1,message:e??state.message},notify()},hide=()=>{if(state.refCount<=0)return;const e=state.refCount-1;state={refCount:e,message:0===e?void 0:state.message},notify()},reset=()=>{0===state.refCount&&void 0===state.message||(state={refCount:0,message:void 0},notify())},isVisible=()=>state.refCount>0,wrap=async(e,t)=>{show(t);try{return await("function"==typeof e?e():e)}finally{hide()}};export const loader={show:show,hide:hide,wrap:wrap,isVisible:isVisible,reset:reset};export const useLoader=()=>loader;export const DEFAULT_LOADER_OVERLAY_LABELS={loading:"Loading"};export const LoaderOverlay=({renderIndicator:e,backdropColor:t,showDelayMs:s=150,minVisibleMs:r=400,labels:n,testID:i})=>{const o=useTheme(),a=usePresenceMotion().duration("default"),u=useSyncExternalStore(subscribe,getState),[l,c]=useState(!1),f=useRef(null),m=useRef(null),d=useRef(null),y=useRef(createAnimatedValue(0)).current,b=u.refCount>0;useEffect(()=>{if(b)return null!==m.current&&(clearTimeout(m.current),m.current=null),void(l||null!==f.current||(f.current=setTimeout(()=>{f.current=null,0!==getState().refCount&&(d.current=Date.now(),c(!0))},s)));if(null!==f.current&&(clearTimeout(f.current),f.current=null),l&&null===m.current){const e=null!==d.current?Date.now()-d.current:r,t=Math.max(0,r-e);m.current=setTimeout(()=>{m.current=null,d.current=null,c(!1)},t)}},[b,l,s,r]),useEffect(()=>()=>{null!==f.current&&clearTimeout(f.current),null!==m.current&&clearTimeout(m.current)},[]),useEffect(()=>{l?Animated.timing(y,{toValue:1,duration:a,easing:Easing.bezier(...o.motion.ease["in-out"]),useNativeDriver:nativeDriver}).start():y.setValue(0)},[l,a,y,o]),useEffect(()=>{if(!l)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>!0);return()=>{e.remove()}},[l]);const S=u.message;useEffect(()=>{l&&S&&AccessibilityInfo.announceForAccessibility(S)},[l,S]);const g=useMemo(()=>buildStyles(),[]),E=useMemo(()=>({...DEFAULT_LOADER_OVERLAY_LABELS,...n}),[n]);return l?_jsx(Animated.View,{pointerEvents:"auto",testID:i,accessible:!0,accessibilityViewIsModal:!0,accessibilityLiveRegion:"polite",accessibilityLabel:S??E.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,style:[g.overlay,{backgroundColor:t??o.colors.scrim,opacity:y}],children:e?e(S):_jsx(Spinner,{size:"lg",message:S})}):null};const buildStyles=()=>StyleSheet.create({overlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center",zIndex:1e3}});
@@ -1 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:i,title:o,topActions:n,placement:r,presentation:l,unavailable:a,context:c=!1,preview:d,onClose:u,restoreFocusTo:m,haptic:p,accessibilityLabel:b,labels:h,testID:f}=e,x=useTheme(),y=useMemo(()=>buildStyles(x),[x]),g=useSafeAreaInsets(),[v,_]=useModalInsets(),w=useMemo(()=>({...g,top:v.top,bottom:v.bottom}),[g,v]),j=useWindowDimensions(),A=usePresenceMotion(),I=A.duration("fast"),k=useMemo(()=>visibleGroups(i,a),[i,a]),S=useMemo(()=>visibleTopActions(n,a),[n,a]),E="sheet"===l||"auto"===l&&j.width<Breakpoints.lg&&wantsSheet(k,S),[M,C]=useState(null),[D,R]=useState(null),T=useRef(u);T.current=u;const L=useRef(m);L.current=m;const O=useRef(null),P=useRef(!1),V=useRef(!1),H=useRef(new Map),F=useRef(null),N=useCallback(()=>{if(!P.current)return;P.current=!1;const e=O.current;O.current=null,e?e():focusHost(L.current?.())},[]);useEffect(()=>{if(t)return V.current=!0,P.current=!1,O.current=null,claimAnchoredSurface(()=>T.current());V.current&&(V.current=!1,P.current=!0,C(null),R(null))},[t]);const B=useCallback(e=>{if(e.disabled)return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),e.key!==BACK_KEY?e.submenu?C(e):(O.current=e.onPress??null,T.current()):C(null)},[p]),K=useMemo(()=>({width:j.width,height:j.height,insets:w}),[j.width,j.height,w]),$=useMemo(()=>{if(!s||!D)return null;const e=s.x+s.width/2>K.width/2?"end":"start";return computePlacement(s,D,K,r,{align:e})},[s,D,K,r]);let z=K.height-w.top-w.bottom-2*PLACEMENT_MARGIN;if(s&&$){const e=placementRoom(s,K);z="top"===$.placement?e.above:e.below}const G=Math.min(280,K.width-w.left-w.right-2*PLACEMENT_MARGIN),W=t&&null!==$,Y=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!W)return setNativeValue(Y,0),void setNativeValue(U,1);const e=[Animated.timing(Y,{toValue:1,duration:I,easing:Easing.bezier(...x.motion.ease.decelerate),useNativeDriver:!0})];c&&!A.reduced&&e.push(Animated.spring(U,{toValue:1.02,damping:x.motion.spring.snappy.damping,stiffness:x.motion.spring.snappy.stiffness,mass:x.motion.spring.snappy.mass,useNativeDriver:!0}));const t=Animated.parallel(e);return t.start(),()=>t.stop()},[W,c,A.reduced,Y,U,x.motion,I]);const X=useCallback(e=>{const{width:t,height:s}=e.nativeEvent.layout;R(e=>e&&e.width===t&&e.height===s?e:{width:t,height:s})},[]),Z=c&&"top"===$?.placement,q=M?.submenu?[M.submenu]:k,J=Z?[...q].reverse().map(e=>[...e].reverse()):q,Q=[];if(M)Q.push({key:BACK_KEY,label:M.label});else for(const e of S)Q.push({key:`${TOP_PREFIX}${e.key}`,label:e.label,item:e});for(const e of J)for(const t of e)Q.push({key:t.key,label:t.label,item:t});const ee=Q[0]?.key;useEffect(()=>{if(!W||E||!ee)return;const e=setTimeout(()=>focusHost(H.current.get(ee)),FOCUS_DELAY_MS);return()=>clearTimeout(e)},[W,E,ee]);const setItemRef=e=>t=>{t?H.current.set(e,t):H.current.delete(e)},te=webOnly({onKeyDown:e=>{const t=e.key??e.nativeEvent?.key??"",s=Q.length,i=Q.findIndex(e=>e.key===F.current);let o=-1;if("ArrowDown"===t)o=(i+1)%s;else if("ArrowUp"===t)o=i<=0?s-1:i-1;else if("Home"===t)o=0;else if("End"===t)o=s-1;else{if("ArrowLeft"===t&&M)return e.preventDefault?.(),void C(null);if("ArrowRight"===t&&Q[i]?.item?.submenu)return e.preventDefault?.(),void B(Q[i].item);if(1===t.length&&""!==t.trim()){const e=t.toLowerCase();for(let t=1;t<=s;t+=1){const n=(i+t)%s;if(Q[n].label.toLowerCase().startsWith(e)){o=n;break}}}}o>=0&&(e.preventDefault?.(),(e=>{const t=Q[e];t&&focusHost(H.current.get(t.key))})(o))}});if(E){const e=M?.submenu?[{key:BACK_KEY,label:h.back,icon:"chevron-left"},...M.submenu]:[...S,...k.flat()],s=[...new Set(e.filter(e=>e.checked).map(e=>e.key))];return _jsx(OptionSheet,{open:t,onClose:u,onAfterClose:N,title:M?.label??o,options:e,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,isOptionDisabled:e=>Boolean(e.disabled),destructiveOf:e=>Boolean(e.destructive),getOptionDescription:e=>e.description,getOptionIcon:e=>{const t=e;return renderSlotIcon(t.icon,{color:t.destructive?x.colors["danger-text"]:x.colors["text-muted"],size:20,disabled:Boolean(t.disabled)})},value:s,onChange:(e,t)=>B(t),accessibilityLabel:b??o,testID:f?`${f}-sheet`:void 0})}const inkFor=e=>e.disabled?x.colors["text-disabled"]:e.destructive?x.colors["danger-text"]:x.colors["text-body"],inkRoleFor=e=>e.disabled?"disabled":e.destructive?"danger":"primary",se=_jsxs(_Fragment,M?{children:[_jsx(ListItem,{ref:setItemRef(BACK_KEY),variant:"menu",onPress:()=>C(null),onFocus:()=>{F.current=BACK_KEY},accessibilityLabel:`${h.back}, ${M.label}`,leading:_jsx(View,{style:y.icon,children:_jsx(AppIcon,{name:"chevron-left",size:20,color:x.colors["text-muted"]})}),title:_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:1,children:M.label})}),_jsx(Divider,{spacing:"none"})]}:{children:[o?_jsx(Text,{variant:"caption",color:"secondary",accessibilityRole:"header",numberOfLines:2,style:y.title,children:o}):null,S.length>0?_jsxs(_Fragment,{children:[_jsx(View,{style:y.topRow,children:S.map(e=>{const t=`${TOP_PREFIX}${e.key}`,s=Boolean(e.disabled),i=inkFor(e);return _jsxs(Pressable,{ref:setItemRef(t),onPress:()=>B(e),onFocus:()=>{F.current=t},disabled:s,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityState:{disabled:s},"aria-disabled":s,testID:e.testID,style:({pressed:e})=>[y.topAction,e?y.pressed:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}),_jsx(Text,{variant:"caption",color:inkRoleFor(e),numberOfLines:1,children:e.label})]},t)})}),_jsx(Divider,{spacing:"none"})]}):null]});return _jsxs(Modal,{open:t,onClose:u,presentation:"fullScreen",bare:!0,backdropOpacity:c?void 0:0,haptic:!1,labels:{close:h.close},onInsetsChange:_,onDismissed:N,testID:f?`${f}-modal`:void 0,children:[c&&d&&s?_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[y.preview,{left:s.x,top:s.y,width:s.width,height:s.height,transform:[{scale:U}]}],children:d}):null,_jsx(Animated.View,{accessibilityRole:"menu",accessibilityLabel:M?.label??b??o,onLayout:X,testID:f?`${f}-menu`:void 0,...te,style:[y.anchored,{left:$?.x??0,top:$?.y??0,maxWidth:G,opacity:W?Y:0}],children:_jsx(View,{style:y.surface,children:_jsxs(View,{style:[y.clip,{maxHeight:z}],children:[se,_jsx(ScrollView,{style:y.scroll,bounces:!1,keyboardShouldPersistTaps:"handled",children:J.map((e,t)=>{const s=e.some(e=>null!=e.icon);return _jsxs(View,{children:[t>0?_jsx(Divider,{spacing:"none"}):null,e.map(e=>((e,t)=>{const s=Boolean(e.disabled),i=inkFor(e),o=e.detail||e.checked||e.submenu?_jsxs(Row,{gap:"md",children:[e.detail?_jsx(Text,{variant:"caption",color:"tertiary",children:e.detail}):null,e.checked?_jsx(AppIcon,{name:"check",size:20,color:x.colors.primary}):null,e.submenu?_jsx(AppIcon,{name:"chevron-right",size:20,color:x.colors["text-subtle"]}):null]}):void 0;return _jsx(ListItem,{ref:setItemRef(e.key),variant:"menu",onPress:()=>B(e),onFocus:()=>{F.current=e.key},disabled:s,checked:e.checked,accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,rightPlacement:"side",leading:t?_jsx(View,{style:y.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}):void 0,title:_jsx(Text,{variant:"body",color:inkRoleFor(e),numberOfLines:2,children:e.label}),subtitle:e.description?_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:2,children:e.description}):void 0,trailing:o},e.key)})(e,s))]},e[0].key)})})]})})})]})};const buildStyles=e=>StyleSheet.create({preview:{position:"absolute"},anchored:{position:"absolute",minWidth:180},surface:{backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,...e.shadow.popover},clip:{borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},scroll:{flexGrow:0,flexShrink:1},title:{paddingHorizontal:e.space.md,paddingTop:e.space.sm,paddingBottom:e.space.xs},pressed:{backgroundColor:e.colors["surface-pressed"]},icon:{width:20,alignItems:"center"},topRow:{flexDirection:"row",padding:e.space.xs,gap:e.space.xs},topAction:{flexGrow:1,flexBasis:0,alignItems:"center",justifyContent:"center",gap:e.space.xs,minHeight:64,borderRadius:e.radius.sm,...smoothCorners}});
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{claimAnchoredSurface,computePlacement,PLACEMENT_MARGIN,placementRoom}from"../../utils/placement.js";import{Breakpoints}from"../../utils/responsive.js";import{AppIcon}from"../AppIcon/AppIcon.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Row}from"../Box/index.js";import{Divider}from"../Divider/index.js";import{ListItem}from"../ListItem/index.js";import{Modal}from"../Modal/index.js";import{useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{OptionSheet}from"../OptionSheet/index.js";import{Text}from"../Text/index.js";import{FOCUS_DELAY_MS,focusHost}from"./focusHost.js";import{visibleGroups,visibleTopActions,wantsSheet}from"./menuModel.js";import{webOnly}from"./webOnly.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MENU_MIN_WIDTH=180,MENU_MAX_WIDTH=280,TOP_ACTION_MIN_HEIGHT=64,ICON_SIZE=20,PREVIEW_LIFT=1.02,BACK_KEY="__menu-back",TOP_PREFIX="__menu-top:";export const MenuSurface=e=>{const{open:t,anchor:s,items:i,title:o,topActions:n,placement:r,presentation:l,unavailable:a,context:c=!1,preview:d,onClose:u,restoreFocusTo:m,haptic:p,accessibilityLabel:f,labels:h,testID:b}=e,v=useTheme(),x=useMemo(()=>buildStyles(v),[v]),y=useSafeAreaInsets(),[g,_]=useModalInsets(),w=useMemo(()=>({...y,top:g.top,bottom:g.bottom}),[y,g]),j=useWindowDimensions(),A=usePresenceMotion(),I=A.duration("fast"),k=useMemo(()=>visibleGroups(i,a),[i,a]),S=useMemo(()=>visibleTopActions(n,a),[n,a]),E="sheet"===l||"auto"===l&&j.width<Breakpoints.lg&&wantsSheet(k,S),[M,D]=useState(null),[C,R]=useState(null),T=useRef(u);T.current=u;const L=useRef(m);L.current=m;const O=useRef(null),P=useRef(!1),V=useRef(!1),H=useRef(new Map),F=useRef(null),N=useCallback(()=>{if(!P.current)return;P.current=!1;const e=O.current;O.current=null,e?e():focusHost(L.current?.())},[]);useEffect(()=>{if(t)return V.current=!0,P.current=!1,O.current=null,claimAnchoredSurface(()=>T.current());V.current&&(V.current=!1,P.current=!0,D(null),R(null))},[t]);const B=useCallback(e=>{if(e.disabled)return;const t=resolveHaptic(p,"selection");t&&triggerHaptic(t),e.key!==BACK_KEY?e.submenu?D(e):(O.current=e.onPress??null,T.current()):D(null)},[p]),K=useMemo(()=>({width:j.width,height:j.height,insets:w}),[j.width,j.height,w]),$=useMemo(()=>{if(!s||!C)return null;const e=s.x+s.width/2>K.width/2?"end":"start";return computePlacement(s,C,K,r,{align:e})},[s,C,K,r]);let z=K.height-w.top-w.bottom-2*PLACEMENT_MARGIN;if(s&&$){const e=placementRoom(s,K);z="top"===$.placement?e.above:e.below}const G=Math.min(280,K.width-w.left-w.right-2*PLACEMENT_MARGIN),W=t&&null!==$,Y=useRef(createAnimatedValue(0)).current,U=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!W)return setNativeValue(Y,0),void setNativeValue(U,1);const e=[Animated.timing(Y,{toValue:1,duration:I,easing:Easing.bezier(...v.motion.ease.decelerate),useNativeDriver:nativeDriver})];c&&!A.reduced&&e.push(Animated.spring(U,{toValue:1.02,damping:v.motion.spring.snappy.damping,stiffness:v.motion.spring.snappy.stiffness,mass:v.motion.spring.snappy.mass,useNativeDriver:nativeDriver}));const t=Animated.parallel(e);return t.start(),()=>t.stop()},[W,c,A.reduced,Y,U,v.motion,I]);const X=useCallback(e=>{const{width:t,height:s}=e.nativeEvent.layout;R(e=>e&&e.width===t&&e.height===s?e:{width:t,height:s})},[]),Z=c&&"top"===$?.placement,q=M?.submenu?[M.submenu]:k,J=Z?[...q].reverse().map(e=>[...e].reverse()):q,Q=[];if(M)Q.push({key:BACK_KEY,label:M.label});else for(const e of S)Q.push({key:`${TOP_PREFIX}${e.key}`,label:e.label,item:e});for(const e of J)for(const t of e)Q.push({key:t.key,label:t.label,item:t});const ee=Q[0]?.key;useEffect(()=>{if(!W||E||!ee)return;const e=setTimeout(()=>focusHost(H.current.get(ee)),FOCUS_DELAY_MS);return()=>clearTimeout(e)},[W,E,ee]);const setItemRef=e=>t=>{t?H.current.set(e,t):H.current.delete(e)},te=webOnly({onKeyDown:e=>{const t=e.key??e.nativeEvent?.key??"",s=Q.length,i=Q.findIndex(e=>e.key===F.current),o=Q[i];let n=-1;if("ArrowDown"===t)n=(i+1)%s;else if("ArrowUp"===t)n=i<=0?s-1:i-1;else if("Home"===t)n=0;else if("End"===t)n=s-1;else{if("ArrowLeft"===t&&M)return e.preventDefault?.(),void D(null);if("ArrowRight"===t&&o?.item?.submenu)return e.preventDefault?.(),void B(o.item);if(1===t.length&&""!==t.trim()){const e=t.toLowerCase();for(let t=1;t<=s;t+=1){const o=(i+t)%s,r=Q[o];if(void 0===r)throw new Error("MenuSurface key navigation stepped outside its items.");if(r.label.toLowerCase().startsWith(e)){n=o;break}}}}n>=0&&(e.preventDefault?.(),(e=>{const t=Q[e];t&&focusHost(H.current.get(t.key))})(n))}});if(E){const e=M?.submenu?[{key:BACK_KEY,label:h.back,icon:"chevron-left"},...M.submenu]:[...S,...k.flat()],s=[...new Set(e.filter(e=>e.checked).map(e=>e.key))];return _jsx(OptionSheet,{open:t,onClose:u,onAfterClose:N,title:M?.label??o,options:e,getOptionLabel:e=>e.label,getOptionValue:e=>e.key,isOptionDisabled:e=>Boolean(e.disabled),destructiveOf:e=>Boolean(e.destructive),getOptionDescription:e=>e.description,getOptionIcon:e=>{const t=e;return renderSlotIcon(t.icon,{color:t.destructive?v.colors["danger-text"]:v.colors["text-muted"],size:20,disabled:Boolean(t.disabled)})},value:s,onChange:(e,t)=>B(t),accessibilityLabel:f??o,testID:b?`${b}-sheet`:void 0})}const inkFor=e=>e.disabled?v.colors["text-disabled"]:e.destructive?v.colors["danger-text"]:v.colors["text-body"],inkRoleFor=e=>e.disabled?"disabled":e.destructive?"danger":"primary",se=_jsxs(_Fragment,M?{children:[_jsx(ListItem,{ref:setItemRef(BACK_KEY),variant:"menu",onPress:()=>D(null),onFocus:()=>{F.current=BACK_KEY},accessibilityLabel:`${h.back}, ${M.label}`,leading:_jsx(View,{style:x.icon,children:_jsx(AppIcon,{name:"chevron-left",size:20,color:v.colors["text-muted"]})}),title:_jsx(Text,{variant:"body",weight:"semibold",numberOfLines:1,children:M.label})}),_jsx(Divider,{spacing:"none"})]}:{children:[o?_jsx(Text,{variant:"caption",color:"secondary",accessibilityRole:"header",numberOfLines:2,style:x.title,children:o}):null,S.length>0?_jsxs(_Fragment,{children:[_jsx(View,{style:x.topRow,children:S.map(e=>{const t=`${TOP_PREFIX}${e.key}`,s=Boolean(e.disabled),i=inkFor(e);return _jsxs(Pressable,{ref:setItemRef(t),onPress:()=>B(e),onFocus:()=>{F.current=t},disabled:s,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel??e.label,accessibilityState:{disabled:s},"aria-disabled":s,testID:e.testID,style:({pressed:e})=>[x.topAction,e?x.pressed:null],children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}),_jsx(Text,{variant:"caption",color:inkRoleFor(e),numberOfLines:1,children:e.label})]},t)})}),_jsx(Divider,{spacing:"none"})]}):null]});return _jsxs(Modal,{open:t,onClose:u,presentation:"fullScreen",bare:!0,backdropOpacity:c?void 0:0,haptic:!1,labels:{close:h.close},onInsetsChange:_,onDismissed:N,testID:b?`${b}-modal`:void 0,children:[c&&d&&s?_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:[x.preview,{left:s.x,top:s.y,width:s.width,height:s.height,transform:[{scale:U}]}],children:d}):null,_jsx(Animated.View,{accessibilityRole:"menu",accessibilityLabel:M?.label??f??o,onLayout:X,testID:b?`${b}-menu`:void 0,...te,style:[x.anchored,{left:$?.x??0,top:$?.y??0,maxWidth:G,opacity:W?Y:0}],children:_jsx(View,{style:x.surface,children:_jsxs(View,{style:[x.clip,{maxHeight:z}],children:[se,_jsx(ScrollView,{style:x.scroll,bounces:!1,keyboardShouldPersistTaps:"handled",children:J.map((e,t)=>{const s=e.some(e=>null!=e.icon),[i]=e;if(void 0===i)throw new Error("MenuSurface has a group with no items to draw.");return _jsxs(View,{children:[t>0?_jsx(Divider,{spacing:"none"}):null,e.map(e=>((e,t)=>{const s=Boolean(e.disabled),i=inkFor(e),o=e.detail||e.checked||e.submenu?_jsxs(Row,{gap:"md",children:[e.detail?_jsx(Text,{variant:"caption",color:"tertiary",children:e.detail}):null,e.checked?_jsx(AppIcon,{name:"check",size:20,color:v.colors.primary}):null,e.submenu?_jsx(AppIcon,{name:"chevron-right",size:20,color:v.colors["text-subtle"]}):null]}):void 0;return _jsx(ListItem,{ref:setItemRef(e.key),variant:"menu",onPress:()=>B(e),onFocus:()=>{F.current=e.key},disabled:s,checked:e.checked,accessibilityLabel:e.accessibilityLabel??e.label,testID:e.testID,rightPlacement:"side",leading:t?_jsx(View,{style:x.icon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:renderSlotIcon(e.icon,{color:i,size:20,disabled:s})}):void 0,title:_jsx(Text,{variant:"body",color:inkRoleFor(e),numberOfLines:2,children:e.label}),subtitle:e.description?_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:2,children:e.description}):void 0,trailing:o},e.key)})(e,s))]},i.key)})})]})})})]})};const buildStyles=e=>StyleSheet.create({preview:{position:"absolute"},anchored:{position:"absolute",minWidth:180},surface:{backgroundColor:e.colors.surface,borderRadius:e.radius.md,...smoothCorners,...e.shadow.popover},clip:{borderRadius:e.radius.md,...smoothCorners,overflow:"hidden"},scroll:{flexGrow:0,flexShrink:1},title:{paddingHorizontal:e.space.md,paddingTop:e.space.sm,paddingBottom:e.space.xs},pressed:{backgroundColor:e.colors["surface-pressed"]},icon:{width:20,alignItems:"center"},topRow:{flexDirection:"row",padding:e.space.xs,gap:e.space.xs},topAction:{flexGrow:1,flexBasis:0,alignItems:"center",justifyContent:"center",gap:e.space.xs,minHeight:64,borderRadius:e.radius.sm,...smoothCorners}});
@@ -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:n,getDate:s,firstUnreadKey:r,onLoadOlder:a,loadingOlder:l=!1,hasOlder:i=!0,typing:u,empty:c,getAnnouncement:d,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:y,now:g,onScroll:x,onContentSizeChange:b,contentContainerStyle:S,style:h,testID:j,...w}){const L=useTheme(),_=useSafeAreaInsets(),C=useReducedMotion(),E=useMemo(()=>buildStyles(L),[L]),v=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=s?e.map(e=>formatDate(s(e))):null,a=n?e.map(n):null,l=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,n)=>{const r=n===e.length-1,i=null!==o&&(r||o[n]!==o[n+1]),u=null!==a&&!r&&a[n+1]===a[n]&&!i&&n!==l,c=null!==a&&n>0&&a[n-1]===a[n]&&(null===o||o[n-1]===o[n])&&n-1!==l;return{groupPosition:positionOf(u,c),day:i&&s?dayLabel(s(t),{now:g,labels:v}):null,unread:n===l}})},[e,s,n,r,t,g,v]),B=useCallback(()=>{k.current=!0,O.current?.scrollToOffset({offset:0,animated:!C}),P(0)},[C]),F=e.length>0?t(e[0]):null,z=useRef(F);useEffect(()=>{const o=z.current;if(z.current=F,null===o||null===F||o===F)return;const n=e.findIndex(e=>t(e)===o);if(-1===n)return void P(0);const s=e.slice(0,n).reverse();for(const e of s){const t=d?.(e);t&&announce(t)}m&&s.some(m)?B():I.current&&P(e=>e+s.length)},[F]);const K=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)),x?.(e)},[x]),N=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]),U=useCallback(()=>{i&&!l&&a?.()},[i,l,a]),$=useCallback(({item:e,index:t})=>{const n=R[t];return _jsxs(View,{children:[n?.day?_jsx(DateSeparator,{label:n.day}):null,n?.unread?_jsx(DateSeparator,{label:v.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:n?.groupPosition??"single"})]})},[R,v.unread,o]),G=useCallback(e=>t(e),[t]),H=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:T}),[T]),J=V>0?`${v.newMessages(V)}. ${v.jumpToLatest}`:v.jumpToLatest;return _jsxs(View,{style:[E.root,h],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...w,ref:O,data:e,renderItem:$,keyExtractor:G,inverted:!0,onScroll:K,onContentSizeChange:N,onEndReached:a?U:void 0,ListHeaderComponent:u?_jsx(View,{children:u}):null,ListFooterComponent:l?_jsx(Spinner,{size:"sm",accessibilityLabel:v.loadingOlder,style:E.older}):null,ListEmptyComponent:c?_jsx(View,{style:E.fill,children:c}):null,renderScrollComponent:p?H:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,S],testID:j}),A?_jsxs(View,{style:E.jump,pointerEvents:"box-none",children:[_jsx(View,{style:E.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:J,variant:"ghost",tone:"neutral",onPress:B,testID:j?`${j}-jump`:void 0})}),V>0?_jsx(View,{style:E.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:n,getDate:s,firstUnreadKey:r,onLoadOlder:a,loadingOlder:l=!1,hasOlder:i=!0,typing:u,empty:c,getAnnouncement:d,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(),C=useReducedMotion(),E=useMemo(()=>buildStyles(L),[L]),v=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=s?e.map(e=>formatDate(s(e))):null,a=n?e.map(n):null,l=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,n)=>{const r=n===e.length-1,i=null!==o&&(r||o[n]!==o[n+1]),u=null!==a&&!r&&a[n+1]===a[n]&&!i&&n!==l,c=null!==a&&n>0&&a[n-1]===a[n]&&(null===o||o[n-1]===o[n])&&n-1!==l;return{groupPosition:positionOf(u,c),day:i&&s?dayLabel(s(t),{now:x,labels:v}):null,unread:n===l}})},[e,s,n,r,t,x,v]),B=useCallback(()=>{k.current=!0,O.current?.scrollToOffset({offset:0,animated:!C}),P(0)},[C]),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 n=e.findIndex(e=>t(e)===o);if(-1===n)return void P(0);const s=e.slice(0,n).reverse();for(const e of s){const t=d?.(e);t&&announce(t)}m&&s.some(m)?B():I.current&&P(e=>e+s.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(()=>{i&&!l&&a?.()},[i,l,a]),G=useCallback(({item:e,index:t})=>{const n=R[t];return _jsxs(View,{children:[n?.day?_jsx(DateSeparator,{label:n.day}):null,n?.unread?_jsx(DateSeparator,{label:v.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:n?.groupPosition??"single"})]})},[R,v.unread,o]),H=useCallback(e=>t(e),[t]),J=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:T}),[T]),W=V>0?`${v.newMessages(V)}. ${v.jumpToLatest}`:v.jumpToLatest;return _jsxs(View,{style:[E.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:u?_jsx(View,{children:u}):null,ListFooterComponent:l?_jsx(Spinner,{size:"sm",accessibilityLabel:v.loadingOlder,style:E.older}):null,ListEmptyComponent:c?_jsx(View,{style:E.fill,children:c}):null,renderScrollComponent:p?J:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,S],testID:j}),A?_jsxs(View,{style:E.jump,pointerEvents:"box-none",children:[_jsx(View,{style:E.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:E.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{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{assertValidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:s="centered",backdropOpacity:n,backdropPressClose:i=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:S,placement:A="auto",align:y="center",testID:x,bare:M=!1,onInsetsChange:v}=e,C=useTheme(),w=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),R=usePresenceMotion(),[V,j]=useModalInsets();useEffect(()=>{v?.(V)},[V,v]);const{width:E,height:T}=useWindowDimensions(),[D,_]=useState({width:0,height:0}),L=a??R.duration("default"),N=Dimensions.get("window").height,H=useRef(!l&&o),I=H.current,P=useRef(createAnimatedValue(I?1:.9)).current,k=useRef(createAnimatedValue(I?1:0)).current,O=useRef(createAnimatedValue(I?0:N)).current,z=useRef(createAnimatedValue(I?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(C),[C]),K=useMemo(()=>{if("anchored"!==s||void 0===S)return null;const e={width:E,height:T,insets:{top:V.top,bottom:V.bottom,left:0,right:0}},t=computePlacement(S,D,e,A,{align:y});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(S,e))}},[s,S,D,A,y,E,T,V.top,V.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof n?"anchored"===s?transparentOf(e):e:withAlpha(e,n)??e},[C.colors.scrim,n,s]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&H.current)H.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:R.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),R.reduced||"anchored"===s){k.setValue(0),O.setValue(0),P.setValue(1);const t=Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===s){k.setValue(1);const t=Animated.spring(O,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(P,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:!0}),Animated.timing(k,{toValue:1,duration:L,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(F){const t=R.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(k,{toValue:0,duration:t,easing:o,useNativeDriver:!0}),n=R.reduced||"anchored"===s?r:"bottom"===s?Animated.timing(O,{toValue:N,duration:t,easing:o,useNativeDriver:!0}):Animated.parallel([Animated.timing(P,{toValue:.9,duration:t,easing:o,useNativeDriver:!0}),r]),i=Animated.parallel([n,Animated.timing(z,{toValue:0,duration:R.duration("default"),useNativeDriver:!1})]);i.start(({finished:e})=>{e&&(O.setValue(N),B(!1))}),e.push(i)}return()=>e.forEach(e=>{e.stop()})},[o,F,s,L,P,k,z,O,N,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,R,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const J=useRef(h);J.current=h;const Q=useRef(!1);useEffect(()=>{if(o)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),300);return()=>clearTimeout(e)},[o]);const X=useCallback(()=>{if(!i)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[i,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),$=useSquircle(!M&&"bottom"!==s&&"fullScreen"!==s&&"anchored"!==s,C.radius.xl),ee=useCallback(e=>{$.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[$.onLayout]),te=useMemo(()=>M?"bottom"===s?U.bottomContent:"fullScreen"===s?U.fullScreenContent:U.bareCentredContent:"anchored"===s?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===s?[U.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===s?[U.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+V.bottom},C.shadow.modal]:[U.centeredContent,{backgroundColor:C.colors.surface,borderRadius:$.active&&$.size?squircleHostRadius($.size.width,$.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[s,C,U,V.bottom,$.active,$.size,K,M]),oe=useMemo(()=>"anchored"===s?U.anchoredWrapper:"bottom"===s?U.bottomWrapper:"fullScreen"===s?U.fullScreenWrapper:U.centeredWrapper,[s,U]),re=useMemo(()=>"bottom"===s?{opacity:k,transform:[{translateY:O}]}:"fullScreen"===s||"anchored"===s?{opacity:k}:{opacity:k,transform:[{scale:P}]},[s,P,k,O]);if("anchored"===s&&void 0===S)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(M&&"anchored"===s)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:x,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:j,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:X,accessibilityRole:i?"button":void 0,accessibilityLabel:i?w.close:void 0,accessible:!!i&&void 0,importantForAccessibility:i?void 0:"no",disabled:!i}),_jsxs(Animated.View,{style:[te,re,D.height>0||"anchored"!==s?null:U.unmeasured,m],onLayout:ee,pointerEvents:M&&"fullScreen"===s?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?_jsx(SquircleFill,{width:$.size.width,height:$.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,Dimensions,Easing,Keyboard,Platform,Pressable,Modal as RNModal,StyleSheet,useWindowDimensions,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{transparentOf,withAlpha}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{computePlacement,placementMaxHeight,placementRoom}from"../../utils/placement.js";import{squircleHostRadius}from"../../utils/squircle.js";import{ModalSafeArea,useModalInsets}from"../ModalSafeArea/ModalSafeArea.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{ToastHost}from"../Toast/ToastProvider.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MODAL_LABELS=Object.freeze({close:"Close modal"});const MODAL_PRESENTATIONS=["centered","bottom","fullScreen","anchored"];export const MODAL_DISMISS_GRACE_MS=300;const SCALE_START_VALUE=.9,Modal=forwardRef((e,t)=>{assertValidValue("Modal","presentation",e.presentation,MODAL_PRESENTATIONS);const{open:o,onClose:r,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:a,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:p,restoreFocusRef:f,onDismissed:h,haptic:g,labels:b,anchor:v,placement:S="auto",align:A="center",testID:y,bare:x=!1,onInsetsChange:M}=e,C=useTheme(),w=useMemo(()=>({...DEFAULT_MODAL_LABELS,...b}),[b]),D=usePresenceMotion(),[R,V]=useModalInsets();useEffect(()=>{M?.(R)},[R,M]);const{width:j,height:E}=useWindowDimensions(),[T,_]=useState({width:0,height:0}),L=a??D.duration("default"),N=Dimensions.get("window").height,H=useRef(!l&&o),I=H.current,P=useRef(createAnimatedValue(I?1:.9)).current,k=useRef(createAnimatedValue(I?1:0)).current,O=useRef(createAnimatedValue(I?0:N)).current,z=useRef(createAnimatedValue(I?1:0)).current,W=useRef(null),q=useRef(!1),[F,B]=useState(o),U=useMemo(()=>buildStyles(C),[C]),K=useMemo(()=>{if("anchored"!==i||void 0===v)return null;const e={width:j,height:E,insets:{top:R.top,bottom:R.bottom,left:0,right:0}},t=computePlacement(v,T,e,S,{align:A});return{...t,maxHeight:placementMaxHeight(t.placement,placementRoom(v,e))}},[i,v,T,S,A,j,E,R.top,R.bottom]),G=useMemo(()=>{const e=C.colors.scrim;return"number"!=typeof s?"anchored"===i?transparentOf(e):e:withAlpha(e,s)??e},[C.colors.scrim,s,i]),Y=useMemo(()=>z.interpolate({inputRange:[0,1],outputRange:[transparentOf(G),G]}),[z,G]);useEffect(()=>{o&&(Keyboard.dismiss(),B(!0))},[o]),useEffect(()=>{const e=[];if(o&&F&&H.current)H.current=!1;else if(o&&F){const t=Animated.timing(z,{toValue:1,duration:D.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),D.reduced||"anchored"===i){k.setValue(0),O.setValue(0),P.setValue(1);const t=Animated.timing(k,{toValue:1,duration:L,useNativeDriver:nativeDriver});t.start(),e.push(t)}else if("bottom"===i){k.setValue(1);const t=Animated.spring(O,{toValue:0,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver});t.start(),e.push(t)}else{const t=Animated.parallel([Animated.spring(P,{toValue:1,damping:C.motion.spring.gentle.damping,stiffness:C.motion.spring.gentle.stiffness,mass:C.motion.spring.gentle.mass,useNativeDriver:nativeDriver}),Animated.timing(k,{toValue:1,duration:L,useNativeDriver:nativeDriver})]);t.start(),e.push(t)}}else if(F){const t=D.duration("fast"),o=Easing.bezier(...C.motion.ease.accelerate),r=Animated.timing(k,{toValue:0,duration:t,easing:o,useNativeDriver:nativeDriver}),s=D.reduced||"anchored"===i?r:"bottom"===i?Animated.timing(O,{toValue:N,duration:t,easing:o,useNativeDriver:nativeDriver}):Animated.parallel([Animated.timing(P,{toValue:.9,duration:t,easing:o,useNativeDriver:nativeDriver}),r]),n=Animated.parallel([s,Animated.timing(z,{toValue:0,duration:D.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(O.setValue(N),B(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[o,F,i,L,P,k,z,O,N,C.motion.spring.gentle.damping,C.motion.spring.gentle.stiffness,C.motion.spring.gentle.mass,D,C.motion.ease.accelerate]),useEffect(()=>{if("web"===Platform.OS)return;let e,t;return o?(e=setTimeout(()=>{W.current&&AccessibilityInfo.sendAccessibilityEvent(W.current,"focus")},150),q.current=!0):q.current&&(q.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&AccessibilityInfo.sendAccessibilityEvent(e,"focus")},L))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[o,L,f]);const J=useRef(h);J.current=h;const Q=useRef(!1);useEffect(()=>{if(o)return void(Q.current=!0);if(!Q.current)return;Q.current=!1;const e=setTimeout(()=>J.current?.(),300);return()=>clearTimeout(e)},[o]);const X=useCallback(()=>{if(!n)return;const e=resolveHaptic(g,"selection");e&&triggerHaptic(e),r()},[n,r,g]),Z=useCallback(()=>{u&&r()},[u,r]),$=useSquircle(!x&&"bottom"!==i&&"fullScreen"!==i&&"anchored"!==i,C.radius.xl),ee=useCallback(e=>{$.onLayout(e);const{width:t,height:o}=e.nativeEvent.layout;_(e=>e.width===t&&e.height===o?e:{width:t,height:o})},[$.onLayout]),te=useMemo(()=>x?"bottom"===i?U.bottomContent:"fullScreen"===i?U.fullScreenContent:U.bareCentredContent:"anchored"===i?[U.anchoredContent,{left:K?.x,top:K?.y,maxHeight:K?.maxHeight,backgroundColor:C.colors.surface,borderRadius:C.radius.lg,...smoothCorners},C.shadow.modal]:"fullScreen"===i?[U.fullScreenContent,{backgroundColor:C.colors.surface}]:"bottom"===i?[U.bottomContent,{backgroundColor:C.colors.surface,borderTopLeftRadius:C.radius.xl,borderTopRightRadius:C.radius.xl,...smoothCorners,paddingTop:C.space.lg,paddingHorizontal:C.space.lg,paddingBottom:C.space.lg+R.bottom},C.shadow.modal]:[U.centeredContent,{backgroundColor:C.colors.surface,borderRadius:$.active&&$.size?squircleHostRadius($.size.width,$.size.height,C.radius.xl):C.radius.xl,...smoothCorners,padding:C.space.xl},C.shadow.modal],[i,C,U,R.bottom,$.active,$.size,K,x]),oe=useMemo(()=>"anchored"===i?U.anchoredWrapper:"bottom"===i?U.bottomWrapper:"fullScreen"===i?U.fullScreenWrapper:U.centeredWrapper,[i,U]),re=useMemo(()=>"bottom"===i?{opacity:k,transform:[{translateY:O}]}:"fullScreen"===i||"anchored"===i?{opacity:k}:{opacity:k,transform:[{scale:P}]},[i,P,k,O]);if("anchored"===i&&void 0===v)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" needs an anchor.');if(x&&"anchored"===i)throw new Error('[@webority/mobile-ui] Modal: presentation "anchored" bare does not combine with presentation anchored.');return _jsx(RNModal,{visible:F,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Z,testID:y,children:_jsx(View,{ref:e=>{W.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:U.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:_jsxs(ModalSafeArea,{onInsets:V,children:[_jsxs(Animated.View,{collapsable:!1,style:[StyleSheet.absoluteFill,oe,{backgroundColor:Y},p],children:[_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:X,accessibilityRole:n?"button":void 0,accessibilityLabel:n?w.close:void 0,accessible:!!n&&void 0,importantForAccessibility:n?void 0:"no",disabled:!n}),_jsxs(Animated.View,{style:[te,re,T.height>0||"anchored"!==i?null:U.unmeasured,m],onLayout:ee,pointerEvents:x&&"fullScreen"===i?"box-none":"auto",needsOffscreenAlphaCompositing:!0,children:[$.active&&$.size?_jsx(SquircleFill,{width:$.size.width,height:$.size.height,radius:C.radius.xl,fill:C.colors.surface}):null,d]})]}),_jsx(ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1},anchoredWrapper:{flex:1},anchoredContent:{position:"absolute"},unmeasured:{opacity:0},bareCentredContent:{alignSelf:"center"}});export{Modal};export default Modal;
@@ -1 +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{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 sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:s,onChange:i,onComplete:r,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:T,testID:j}=e;assertValidValue("OTPInput","size",e.size,["sm","md","lg"]),assertValidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const v=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[V,C]=useControllableState({value:n,defaultValue:s??"",onChange:i}),E=useTheme(),S=useMemo(()=>buildStyles(E),[E]),A=resolveOtpInputSize(E,m),k=E.components["otp-input"][m].radius,I=useRef([]),[_,F]=useState(-1),[w,O]=useState(0),P=useRef(null),z=useRef(createAnimatedValue(0)).current,M=useRef(new Map),R=useMemo(()=>{const e=M.current,t=[];for(let n=0;n<a;n+=1){let s=e.get(n);s||(s=new Animated.Value(0),e.set(n,s)),t.push(s)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),D=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===P.current||!B||P.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(z,0),e=Animated.sequence([Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),P.current=B,()=>e?.stop()},[B,z,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=D.current;if(D.current=_,e===_)return;if(-1===e&&-1===_)return;const t=[];return R.forEach((n,s)=>{const i=s===_?1:0;if(s!==_&&s!==e)return;const r=Animated.timing(n,{toValue:i,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>{e.stop()})},[_,R,E]);const H=useCallback(e=>{const t=I.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=I.current[_>=0?_:0];e?.blur()},clear:()=>{C(""),H(0)}}),[H,_,C]),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(V.length,a);t+=1)e[t]=V[t]??"";return e},[V,a]),W=useCallback(e=>{const t=e.slice(0,a);t!==V&&(C(t),t.length===a&&r&&r(t))},[a,C,r,V]),$=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),s=sanitizeChar(n,o);if(!s){const t=U.slice(),n=(t[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 i=U[e]??"",r=i&&s.length>a&&s.startsWith(i)?s.slice(i.length):s;if(r.length>=a){const t=r.slice(0,a),n=V.length;return W(t),t.length!==n&&f&&triggerHaptic(f),void I.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<s.length&&u<a;e+=1)l[u]=s[e]??"",u+=1;const c=l.join("").slice(0,a),d=V.length;W(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?I.current[e]?.blur():H(m)},[U,H,o,a,f,W,V]),q=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(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)=>{F(e),h?.(t)},[h]),K=useCallback(()=>{F(-1)},[]),X=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),J=useCallback(e=>{O(e.nativeEvent.layout.width)},[]),Q=b??v.field(a),Y=w>0?Math.max(24,Math.min(A.cell,Math.floor((w-A.gap*(a-1))/a))):A.cell,Z=z.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:j,children:[_jsx(Pressable,{onPress:X,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[S.row,{columnGap:A.gap,transform:[{translateX:Z}]}],children:U.map((e,t)=>{const n=_===t,s=e.length>0,i=B?E.colors["danger-border"]:E.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&s?"●":e;return _jsxs(View,{style:S.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Y,height:Y,radius:k,borderWidth:1.5,focused:n,error:B,filled:s,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{I.current[t]=e},value:(p&&s?"":e)||"​",onChangeText:e=>$(t,e),onKeyPress:e=>q(t,e),onFocus:e=>G(t,e),onBlur:K,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:s,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[S.input,{fontSize:A.text,color:E.colors["text-body"],...fontFor(E,"semibold")},T]}),p&&s?_jsx(View,{pointerEvents:"none",style:S.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:A.text},T],children:l})}):null]}),_jsx(Animated.View,{style:[S.underline,{backgroundColor:i,opacity:r}]})]},`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: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 +1 @@
1
- "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,value:b,onChange:g,multi:x=!1,searchable:y=!1,searchSelectionColor:f,accessibilityLabel:S,optionStyle:T,selectedOptionStyle:j,optionTextStyle:w,selectedOptionTextStyle:C,testID:_}=e,k=c??selectOptionLabel,L=d??selectOptionValue,I=p??selectOptionDescription,O=u??selectOptionDisabled,R=h??selectOptionIcon,V=useTheme(),D=useSafeAreaInsets(),v=useMemo(()=>buildStyles(V),[V]),[P,H]=useState(""),M=Dimensions.get("window").height,B=Math.round(.7*M),A=useRef(createAnimatedValue(0)).current,{handleGesture:E,opacity:F}=useDragToDismiss({drag:A,travel:B,onDismiss:t}),z=useMemo(()=>Gesture.Native(),[]),W=useKeyboardState(e=>e.height),N=Math.max(0,Math.round(W)),G=Math.max(D.top,StatusBar.currentHeight??0)+V.space.sm,U=N>0,$=U?Math.max(0,Math.min(B,M-N-G)):B,J=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,I]),K=useCallback(()=>{t()},[t]),Y=useRef(null),Z=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(let e=J.length-1;e>=0;e-=1)if("header"===J[e].kind){t=e+1;break}for(let o=t;o<J.length;o+=1){const t=J[o];if("option"!==t.kind)continue;const s=k(t.option).trim().charAt(0).toUpperCase(),i=/^[A-Z]$/.test(s)?s:"#";e.has(i)||e.set(i,o)}return e},[n,J,i,k]),Q=n&&Z.size>0&&0===P.trim().length,X=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Z.has("#")?["#"]:[]],[Z]),q=useCallback(e=>{const t=Z.get(e);void 0!==t&&Y.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Z]),ee=useRef(null),te=useCallback(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),oe=useCallback(e=>{Y.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,Y.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);useEffect(()=>te,[te]);return _jsx(GestureHandlerRootView,{style:v.gestureRoot,children:_jsxs(Animated.View,{testID:_,accessibilityViewIsModal:!0,accessibilityLabel:S??o??a.fallbackName,style:[v.sheet,{maxHeight:$,marginBottom:N,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,...smoothCorners,opacity:F,transform:[{translateY:A}],...V.shadow.modal}],children:[_jsx(GestureDetector,{gesture:E,children:_jsxs(View,{children:[_jsx(View,{style:v.sheetHandleRow,children:_jsx(View,{style:[v.sheetHandle,{backgroundColor:V.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[v.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[v.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:_jsxs(View,{style:[v.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:H,placeholder:a.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:f??V.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[v.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>H(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(V.settings.icons.close??defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[v.listWrap,Q?v.listRow:null],children:[_jsx(GestureDetector,{gesture:z,children:_jsx(FlatList,{ref:Y,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[v.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:v.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=L(o),n=I(o),a=R(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=O(o),u=m?.(o)??!1;return _jsxs(Pressable,{onPress:()=>g(i,o),disabled:p,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[v.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},T,c?j:null],children:[l?_jsx(View,{style:v.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:v.optionIcon,children:a}):null,_jsxs(View,{style:v.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[v.optionLabel,w,c?C:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:v.optionDescription,children:n}):null]})]}),x?_jsx(View,{style:[v.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?_jsx(View,{style:v.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:v.singleSelectedIcon,children:(V.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):_jsx(View,{style:[v.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?v.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:a.empty})})}),Q?_jsx(View,{style:[v.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:X.map(e=>{const t=Z.has(e);return _jsx(Pressable,{onPress:()=>q(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:v.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[v.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),x?_jsx(View,{style:[v.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:_jsx(Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[v.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,...smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Dimensions,FlatList,Pressable,StatusBar,StyleSheet,TextInput,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import{useKeyboardState}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useDragToDismiss}from"../../hooks/useDragToDismiss.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Modal}from"../Modal/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const SEARCH_ICON_SIZE=18;export const DEFAULT_OPTION_SHEET_LABELS=Object.freeze({searchPlaceholder:"Search…",empty:"No options",done:"Done",closePicker:"Close picker",fallbackName:"Options",searchOptions:"Search options",clearSearch:"Clear search",jumpToLetter:"Jump to letter",jumpTo:e=>`Jump to ${e}`});const selectOptionLabel=e=>e.label,selectOptionValue=e=>e.value,selectOptionDescription=e=>e.description,selectOptionDisabled=e=>!0===e.disabled,selectOptionIcon=e=>e.icon,hostStyle=StyleSheet.create({host:{padding:0,paddingTop:0,paddingHorizontal:0,paddingBottom:0,backgroundColor:"transparent",borderTopLeftRadius:0,borderTopRightRadius:0,shadowOpacity:0,elevation:0}}).host;function OptionSheetPanel(e){const{onClose:t,title:o,options:s,sections:i,renderSectionHeader:r,renderOption:l,alphabetIndex:n=!1,labels:a,getOptionLabel:c,getOptionValue:d,getOptionDescription:p,isOptionDisabled:u,getOptionIcon:h,destructiveOf:m,value:b,onChange:g,multi:x=!1,searchable:y=!1,searchSelectionColor:f,accessibilityLabel:S,optionStyle:T,selectedOptionStyle:j,optionTextStyle:w,selectedOptionTextStyle:C,testID:_}=e,k=c??selectOptionLabel,L=d??selectOptionValue,I=p??selectOptionDescription,O=u??selectOptionDisabled,R=h??selectOptionIcon,V=useTheme(),D=useSafeAreaInsets(),v=useMemo(()=>buildStyles(V),[V]),[P,H]=useState(""),M=Dimensions.get("window").height,B=Math.round(.7*M),A=useRef(createAnimatedValue(0)).current,{handleGesture:E,opacity:F}=useDragToDismiss({drag:A,travel:B,onDismiss:t}),z=useMemo(()=>Gesture.Native(),[]),W=useKeyboardState(e=>e.height),N=Math.max(0,Math.round(W)),G=Math.max(D.top,StatusBar.currentHeight??0)+V.space.sm,U=N>0,$=U?Math.max(0,Math.min(B,M-N-G)):B,J=useMemo(()=>{const e=y?P.trim().toLowerCase():"",matches=t=>0===e.length||k(t).toLowerCase().includes(e)||(I(t)??"").toLowerCase().includes(e);if(!i)return s.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return i.forEach((e,o)=>{const s=e.options.filter(matches);if(0!==s.length){t.push({kind:"header",title:e.title});for(const e of s)t.push({kind:"option",option:e,section:o})}}),t},[y,P,s,i,k,I]),K=useCallback(()=>{t()},[t]),Y=useRef(null),Z=useMemo(()=>{const e=new Map;if(!n)return e;let t=0;if(i)for(const[e,o]of J.entries())"header"===o.kind&&(t=e+1);for(const[o,s]of J.entries()){if(o<t||"option"!==s.kind)continue;const i=k(s.option).trim().charAt(0).toUpperCase(),r=/^[A-Z]$/.test(i)?i:"#";e.has(r)||e.set(r,o)}return e},[n,J,i,k]),Q=n&&Z.size>0&&0===P.trim().length,X=useMemo(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...Z.has("#")?["#"]:[]],[Z]),q=useCallback(e=>{const t=Z.get(e);void 0!==t&&Y.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[Z]),ee=useRef(null),te=useCallback(()=>{null!==ee.current&&(clearTimeout(ee.current),ee.current=null)},[]),oe=useCallback(e=>{Y.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),te(),ee.current=setTimeout(()=>{ee.current=null,Y.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[te]);useEffect(()=>te,[te]);return _jsx(GestureHandlerRootView,{style:v.gestureRoot,children:_jsxs(Animated.View,{testID:_,accessibilityViewIsModal:!0,accessibilityLabel:S??o??a.fallbackName,style:[v.sheet,{maxHeight:$,marginBottom:N,paddingBottom:U?V.space.lg:D.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,...smoothCorners,opacity:F,transform:[{translateY:A}],...V.shadow.modal}],children:[_jsx(GestureDetector,{gesture:E,children:_jsxs(View,{children:[_jsx(View,{style:v.sheetHandleRow,children:_jsx(View,{style:[v.sheetHandle,{backgroundColor:V.colors.border}]})}),o?_jsx(Text,{variant:"title",style:[v.sheetTitle,{paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:o}):null]})}),y?_jsx(View,{style:[v.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:_jsxs(View,{style:[v.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,...smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),_jsx(TextInput,{value:P,onChangeText:H,placeholder:a.searchPlaceholder,placeholderTextColor:V.colors["text-subtle"],selectionColor:f??V.colors["focus-ring"],accessibilityLabel:a.searchOptions,style:[v.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),P.length>0?_jsx(Pressable,{onPress:()=>H(""),hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:a.clearSearch,children:(V.settings.icons.close??defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,_jsxs(View,{style:[v.listWrap,Q?v.listRow:null],children:[_jsx(GestureDetector,{gesture:z,children:_jsx(FlatList,{ref:Y,data:J,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(L(e.option))}`,renderItem:({item:e,index:t})=>{if("header"===e.kind)return _jsx(View,{accessible:!0,accessibilityRole:"header",style:[v.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:r?r(e.title):_jsx(Text,{variant:"caption",weight:"semibold",color:"tertiary",style:v.sectionTitle,children:e.title.toUpperCase()})});const o=e.option,s=k(o),i=L(o),n=I(o),a=R(o),c=(d=i,Array.isArray(b)?b.some(e=>String(e)===String(d)):null!=b&&String(b)===String(d));var d;const p=O(o),u=m?.(o)??!1;return _jsxs(Pressable,{onPress:()=>g(i,o),disabled:p,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:s,accessibilityState:{selected:c,disabled:p},"aria-selected":c,"aria-disabled":p,style:({pressed:e})=>[v.optionRow,{backgroundColor:c?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:p?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},T,c?j:null],children:[l?_jsx(View,{style:v.optionTextWrap,children:l({option:o,selected:c,disabled:p,index:t})}):_jsxs(_Fragment,{children:[a?_jsx(View,{style:v.optionIcon,children:a}):null,_jsxs(View,{style:v.optionTextWrap,children:[_jsx(Text,{variant:"body",weight:c?"semibold":"medium",color:u?"danger":c?"brand":void 0,style:[v.optionLabel,w,c?C:null],children:s}),n?_jsx(Text,{variant:"bodySmall",color:"tertiary",numberOfLines:2,style:v.optionDescription,children:n}):null]})]}),x?_jsx(View,{style:[v.checkbox,{borderColor:c?V.colors.primary:V.colors.border,backgroundColor:c?V.colors.primary:"transparent"}],children:c?_jsx(View,{style:v.checkboxTick}):null}):c?"icon"===V.settings.components["option-sheet"]?.selectedMarker?_jsx(View,{style:v.singleSelectedIcon,children:(V.settings.icons.selectedTick??defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):_jsx(View,{style:[v.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:oe,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!Q,style:Q?v.listBesideRail:null,ListEmptyComponent:_jsx(Text,{variant:"bodySmall",color:"tertiary",align:"center",style:{paddingVertical:V.space.xl},children:a.empty})})}),Q?_jsx(View,{style:[v.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:a.jumpToLetter,testID:"option-sheet-alphabet",children:X.map(e=>{const t=Z.has(e);return _jsx(Pressable,{onPress:()=>q(e),disabled:!t,hitSlop:{left:8,right:8},...hitSlopMarker({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:a.jumpTo(e),accessibilityState:{disabled:!t},"aria-disabled":!t,style:v.railLetter,children:_jsx(Text,{variant:"caption",weight:"semibold",color:t?"brand":"tertiary",style:[v.railLetterText,{opacity:t?1:.45}],children:e})},e)})}):null]}),x?_jsx(View,{style:[v.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:_jsx(Pressable,{onPress:K,accessibilityRole:"button",accessibilityLabel:a.done,style:({pressed:e})=>[v.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,...smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:_jsx(Text,{variant:"body",weight:"semibold",style:{color:V.colors["on-primary"]},children:a.done})})}):null]})})}export function OptionSheet(e){const{open:t,onOpenChange:o,onAfterClose:s,labels:i,onClose:r,haptic:l,...n}=e,a=useMemo(()=>({...DEFAULT_OPTION_SHEET_LABELS,...i}),[i]),c=useRef(o);c.current=o;const d=useRef(!1);return useEffect(()=>{d.current!==t&&(d.current=t,c.current?.(t))},[t]),_jsx(Modal,{open:t,onClose:r,presentation:"bottom",onDismissed:s,haptic:l,contentStyle:hostStyle,labels:{close:a.closePicker},accessibilityLabel:n.accessibilityLabel??n.title??a.fallbackName,children:_jsx(OptionSheetPanel,{...n,onClose:r,labels:a})})}OptionSheet.displayName="OptionSheet";const buildStyles=e=>StyleSheet.create({gestureRoot:{width:"100%"},sheet:{paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,...smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight:14},sectionTitle:{includeFontPadding:!1,letterSpacing:.6},optionIcon:{marginRight:e.space.md},optionTextWrap:{flex:1},optionLabel:{includeFontPadding:!1},optionDescription:{includeFontPadding:!1,marginTop:e.space.xxs},checkbox:{width:22,height:22,borderRadius:e.radius.sm,...smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,...smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},sheetFooter:{borderTopWidth:StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});export default OptionSheet;
@@ -1 +1 @@
1
- "use strict";import{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,l="neutral"===r;let n;switch(t){case"soft":n={fill:l?e.colors["bg-muted"]:blendOf(s,.14,i,e.colors["bg-subtle"]),ring:i,icon:s};break;case"outline":n={fill:i,ring:l?e.colors.border:s,icon:s};break;default:n={fill:s,ring:i,icon:o.on}}return n},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:l,loading:n=!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=n||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(l)),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),le=useCallback(e=>{$(e),E?.(e),!1!==I&&triggerHaptic("notificationError")},[E,I]),ne=useCallback(async e=>{let r;try{r=await e.pick()}catch(e){return void le(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 le(H.errorTooLarge(d));if(t.type&&!matchesAccept(t.type,c))return void le(H.errorWrongType);$(null),B(t.uri);const o=resolveHaptic(I,"selection");o&&triggerHaptic(o),i?.(t)},[d,c,H,I,i,le]),ae=useCallback(()=>{K||(ue.current=null,1!==s.length||Y?(s.length>0||Y)&&W(!0):ne(s[0]))},[K,s,Y,ne]),ce=useCallback(()=>{B(null),$(null);const e=resolveHaptic(I,"selection");e&&triggerHaptic(e),l?.()},[I,l]),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(ne);pe.current=ne;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:n}:{busy:n},"aria-disabled":J?K:void 0,"aria-busy":n,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"})}),n?_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{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 +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{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;default: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:a,label:o,showPercent:i=!1,valueLabel:n,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:g,gradient:p,segments:f,animated:y=!0,style:h,containerStyle:b,barStyle:x,accessibilityLabel:w,labels:R,testID:A}=e;assertValidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),j=l??"number"!=typeof a,V=clampProgress(a),E=useRef(createAnimatedValue(V)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(createAnimatedValue(0)).current,N=useRef(0),O=useMemo(()=>buildStyles(r),[r]),v=c??r.radius.pill,L=m??r.colors["surface-disabled"],B=g??toneColor(r,d),I=useMemo(()=>p?"string"==typeof p?r.settings.gradients[p]??null:p:null,[p,r.settings.gradients]),C=useMemo(()=>glowOf(B),[B]),D=Array.isArray(f)&&f.length>0;useEffect(()=>{j||(y?Animated.timing(E,{toValue:V,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():E.setValue(V))},[y,V,E,j,r]),useEffect(()=>{if(!j)return;setNativeValue(S,0);const e=Animated.loop(Animated.timing(S,{toValue:1,duration:1500,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}));return e.start(),()=>{e.stop()}},[j,S]);const M=E.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),P=S.interpolate({inputRange:[0,1],outputRange:[-1,1]}),k=S.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),G=i&&!j&&!D,F=null!=o||G||null!=n,U=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:w??("string"==typeof o?o:void 0),accessibilityValue:j?{text:_.loading}:{min:0,max:100,now:Math.round(100*V)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;N.current=t,setNativeValue(T,t)},style:[O.track,{height:u,borderRadius:v,...smoothCorners,backgroundColor:L},b,h],children:D?_jsx(View,{style:[O.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,j?{style:[O.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?k:1,transform:s?[]:[{translateX:Animated.multiply(P,T)}]},x],children:_jsx(Gradient,{gradient:C,style:StyleSheet.absoluteFill})}:{style:[O.determinateBar,{height:u,borderRadius:v,...smoothCorners,backgroundColor:I?"transparent":B,width:M,overflow:I?"hidden":void 0},x],children:I?_jsx(Gradient,{gradient:I,style:StyleSheet.absoluteFill}):null})});return F?_jsxs(View,{style:O.wrapper,children:[_jsxs(View,{style:[O.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof o||"number"==typeof o?_jsx(Text,{variant:"label",color:"primary",style:O.label,children:o}):_jsx(View,{style:O.label,children:o}),null!=n?"string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:n}):n:G?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*V)}%`}):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
+ "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:a,label:i,showPercent:o=!1,valueLabel:n,indeterminate:l,height:u=6,radius:c,tone:d="primary",trackColor:m,barColor:p,gradient:g,segments:f,animated:y=!0,style:h,containerStyle:b,barStyle:x,accessibilityLabel:w,labels:R,testID:A}=e;assertValidValue("ProgressBar","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const _=useMemo(()=>({...DEFAULT_PROGRESS_BAR_LABELS,...R}),[R]),j=l??"number"!=typeof a,v=clampProgress(a),V=useRef(createAnimatedValue(v)).current,E=useRef(createAnimatedValue(0)).current,S=useRef(createAnimatedValue(0)).current,T=useRef(0),N=useMemo(()=>buildStyles(r),[r]),O=c??r.radius.pill,D=m??r.colors["surface-disabled"],L=p??toneColor(r,d),B=useMemo(()=>g?"string"==typeof g?r.settings.gradients[g]??null:g:null,[g,r.settings.gradients]),I=useMemo(()=>glowOf(L),[L]),C=Array.isArray(f)&&f.length>0;useEffect(()=>{j||(y?Animated.timing(V,{toValue:v,duration:400,easing:Easing.bezier(...r.motion.ease["in-out"]),useNativeDriver:!1}).start():V.setValue(v))},[y,v,V,j,r]),useEffect(()=>{if(!j)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()}},[j,E]);const M=V.interpolate({inputRange:[0,1],outputRange:["0%","100%"]}),P=E.interpolate({inputRange:[0,1],outputRange:[-1,1]}),k=E.interpolate({inputRange:[0,.5,1],outputRange:[.4,1,.4]}),G=o&&!j&&!C,F=null!=i||G||null!=n,U=_jsx(View,{ref:t,accessibilityRole:"progressbar",accessibilityLabel:w??("string"==typeof i?i:void 0),accessibilityValue:j?{text:_.loading}:{min:0,max:100,now:Math.round(100*v)},testID:A,onLayout:e=>{const t=e.nativeEvent.layout.width;T.current=t,setNativeValue(S,t)},style:[N.track,{height:u,borderRadius:O,...smoothCorners,backgroundColor:D},b,h],children:C?_jsx(View,{style:[N.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,j?{style:[N.indeterminateBar,{height:u,width:s?"100%":"30%",opacity:s?k:1,transform:s?[]:[{translateX:Animated.multiply(P,S)}]},x],children:_jsx(Gradient,{gradient:I,style:StyleSheet.absoluteFill})}:{style:[N.determinateBar,{height:u,borderRadius:O,...smoothCorners,backgroundColor:B?"transparent":L,width:M,overflow:B?"hidden":void 0},x],children:B?_jsx(Gradient,{gradient:B,style:StyleSheet.absoluteFill}):null})});return F?_jsxs(View,{style:N.wrapper,children:[_jsxs(View,{style:[N.labelRow,{marginBottom:r.space.xs}],children:["string"==typeof i||"number"==typeof i?_jsx(Text,{variant:"label",color:"primary",style:N.label,children:i}):_jsx(View,{style:N.label,children:i}),null!=n?"string"==typeof n||"number"==typeof n?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:n}):n:G?_jsx(Text,{variant:"label",color:"secondary",accessible:!1,importantForAccessibility:"no",children:`${Math.round(100*v)}%`}):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{useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveRadioSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{jsx as _jsx}from"react/jsx-runtime";export const RadioDot=e=>{const{selected:t,color:o,disabled:r=!1,size:s="md",style:i,dotStyle:n}=e,a=useTheme(),d=useMemo(()=>buildStyles(),[]),l=o??a.colors.primary;let m,u;if("number"==typeof s)m=s,u=Math.round(s/2);else{const e=resolveRadioSize(a,s);m=e.outer,u=e.inner}const p=useRef(createAnimatedValue(t?1:0)).current;useEffect(()=>{const e=Animated.spring(p,{toValue:t?1:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[t,p,a.motion.spring.snappy]);const c=p.interpolate({inputRange:[0,1],outputRange:[0,1]}),f=r?a.colors.border:t?l:a.colors.border;return _jsx(View,{style:[d.outer,{width:m,height:m,borderWidth:a.size.border,borderRadius:a.radius.pill,...smoothCorners,borderColor:f},i],children:_jsx(Animated.View,{style:[{width:u,height:u,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:r?a.colors["text-disabled"]:l,opacity:p,transform:[{scale:c}]},n]})})};RadioDot.displayName="RadioDot";const buildStyles=()=>StyleSheet.create({outer:{alignItems:"center",justifyContent:"center"}});export default RadioDot;
1
+ "use strict";import{useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,View}from"react-native";import{createAnimatedValue,resolveRadioSize,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{jsx as _jsx}from"react/jsx-runtime";export const RadioDot=e=>{const{selected:t,color:r,disabled:o=!1,size:s="md",style:i,dotStyle:n}=e,a=useTheme(),d=useMemo(()=>buildStyles(),[]),m=r??a.colors.primary;let l,u;if("number"==typeof s)l=s,u=Math.round(s/2);else{const e=resolveRadioSize(a,s);l=e.outer,u=e.inner}const p=useRef(createAnimatedValue(t?1:0)).current;useEffect(()=>{const e=Animated.spring(p,{toValue:t?1:0,damping:a.motion.spring.snappy.damping,stiffness:a.motion.spring.snappy.stiffness,mass:a.motion.spring.snappy.mass,useNativeDriver:nativeDriver});return e.start(),()=>e.stop()},[t,p,a.motion.spring.snappy]);const c=p.interpolate({inputRange:[0,1],outputRange:[0,1]}),f=o?a.colors.border:t?m:a.colors.border;return _jsx(View,{style:[d.outer,{width:l,height:l,borderWidth:a.size.border,borderRadius:a.radius.pill,...smoothCorners,borderColor:f},i],children:_jsx(Animated.View,{style:[{width:u,height:u,borderRadius:a.radius.pill,...smoothCorners,backgroundColor:o?a.colors["text-disabled"]:m,opacity:p,transform:[{scale:c}]},n]})})};RadioDot.displayName="RadioDot";const buildStyles=()=>StyleSheet.create({outer:{alignItems:"center",justifyContent:"center"}});export default RadioDot;
@@ -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{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;default:return e.colors.primary}},clampToStep=(e,t,s)=>{const i=Math.max(0,Math.min(t,e)),a=Math.round(i/s)*s;return Number(a.toFixed(2))},Star=({index:e,filled:t,size:s,filledColor:i,emptyColor:a,scale:n})=>{const r=Math.max(0,Math.min(1,t-e));return _jsxs(Animated.View,{style:[starStyles.starWrap,{width:s,height:s,transform:[{scale:n}]}],children:[_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:a,fontSize:s,lineHeight:s}],accessible:!1,children:"☆"}),r>0?_jsx(View,{pointerEvents:"none",style:[starStyles.fillClip,{width:s*r,height:s}],children:_jsx(Text,{variant:"body",style:[starStyles.glyph,{color:i,fontSize:s,lineHeight:s}],accessible:!1,children:"★"})}):null]})},Rating=forwardRef((e,t)=>{const{value:s,onChange:i,max:a=5,allowHalf:n=!0,readonly:r=!1,size:l="md",tone:o="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=!r&&"function"==typeof i,w=n?.5:1,j=resolveSize(l),R=toneColorFor(S,o),_=S.colors.border,A=useRef(j),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<a;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>=a&&e.delete(t);return t},[a]),C=S.settings.components.rating?.pulseOnPress??!1,E=useCallback(e=>{const t=V[e];t&&Animated.sequence([Animated.timing(t,{toValue:1.2,duration:S.motion.duration.fast,easing:Easing.bezier(...S.motion.ease["in-out"]),useNativeDriver:!0}),Animated.spring(t,{toValue:1,damping:S.motion.spring.bouncy.damping,stiffness:S.motion.spring.bouncy.stiffness,mass:S.motion.spring.bouncy.mass,useNativeDriver:!0})]).start()},[S.motion,V]),M=useCallback((e,t)=>{if(!v||!i)return;const s=clampToStep(e,a,w),n=resolveHaptic(u,"selection");n&&triggerHaptic(n),C&&"number"==typeof t&&E(t),i(s)},[v,i,a,w,E,u,C]),z=useCallback(e=>t=>{if(!v)return;const s=A.current||j,i=t.nativeEvent.locationX??s;let a;a=n&&i<s/2?e+.5:e+1,M(a,e)},[v,j,n,M]),N=useCallback(e=>{v&&("increment"===e.nativeEvent.actionName?M(s+w):"decrement"===e.nativeEvent.actionName&&M(s-w))},[v,s,w,M]),I=x.value(s,a),L=p??c??I,P=[];for(let e=0;e<a;e+=1){const t=V[e];if(!t)continue;const i=_jsx(Star,{index:e,filled:s,size:j,filledColor:R,emptyColor:_,scale:t},e);P.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 D=_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:L,accessibilityValue:v?{min:0,max:a,now:s,text:I}:void 0,accessibilityActions:v?[{name:"increment"},{name:"decrement"}]:void 0,onAccessibilityAction:v?N:void 0,children:P})]});return m?_jsx(RatingSkeleton,{...e}):D});Rating.displayName="Rating";const RatingSkeleton=({max:e=5,size:t="md",label:s,containerStyle:i,starContainerStyle:a,style:n})=>{const r=useTheme(),l=resolveSize(t),o=Math.max(1,e);return _jsxs(View,{style:[{alignItems:"flex-start"},i,n],accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[void 0!==s?_jsx(Skeleton,{shape:"text",width:80,height:14,style:{marginBottom:r.space.xs}}):null,_jsx(View,{style:[{flexDirection:"row"},a],children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:l,height:l,radius:Math.round(.25*l),style:t<o-1?{marginRight:r.space.xs}:void 0},`sk-star-${t}`))})]})};RatingSkeleton.displayName="RatingSkeleton",Rating.Skeleton=RatingSkeleton;const 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]})},Rating=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,j=resolveSize(o),R=toneColorFor(S,l),_=S.colors.border,A=useRef(j),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||j,i=t.nativeEvent.locationX??s;let r;r=a&&i<s/2?e+.5:e+1,M(r,e)},[v,j,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:j,filledColor:R,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});Rating.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",Rating.Skeleton=RatingSkeleton;const 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";const INLINE_MARKERS={bold:"**",italic:"*",strikethrough:"~~",code:"`"},WHOLE_LINK=/^\[([^\]]*)\]\(([^)\s]*)\)$/,LINK_URL_PLACEHOLDER="url",BLOCK_RULES={heading1:{has:t=>/^#\s/.test(t),prefix:()=>"# "},heading2:{has:t=>/^##\s/.test(t),prefix:()=>"## "},bulletList:{has:t=>/^[-*+]\s/.test(t),prefix:()=>"- "},numberedList:{has:t=>/^\d+[.)]\s/.test(t),prefix:t=>`${t+1}. `},quote:{has:t=>/^>\s?/.test(t),prefix:()=>"> "}},ANY_BLOCK_PREFIX=/^(?:#{1,6}\s+|[-*+]\s+|\d+[.)]\s+|>\s?)/,isBlockAction=t=>t in BLOCK_RULES,clamp=(t,e)=>!Number.isFinite(t)||t<0?0:Math.min(Math.trunc(t),e);export const normalizeSelection=(t,e)=>{const s=clamp(t.start,e),n=clamp(t.end,e);return{start:Math.min(s,n),end:Math.max(s,n)}};const caret=t=>({start:t,end:t}),applyInlineMarker=(t,e,s)=>{const{start:n,end:l}=e,i=t.slice(n,l),r=s.length,c="*"===s;if(i.length>=2*r&&i.startsWith(s)&&i.endsWith(s)&&!(c&&i.startsWith("**")&&i.endsWith("**"))){const e=i.slice(r,i.length-r);return{text:t.slice(0,n)+e+t.slice(l),selection:{start:n,end:n+e.length}}}const a=t.slice(Math.max(0,n-r),n),o=t.slice(l,l+r);if(n>=r&&a===s&&o===s&&!(c&&"**"===t.slice(Math.max(0,n-2),n)))return{text:t.slice(0,n-r)+i+t.slice(l+r),selection:{start:n-r,end:l-r}};return{text:t.slice(0,n)+s+i+s+t.slice(l),selection:n===l?caret(n+r):{start:n+r,end:l+r}}},applyLink=(t,e)=>{const{start:s,end:n}=e,l=t.slice(s,n),i=WHOLE_LINK.exec(l);if(i){const e=i[1];return{text:t.slice(0,s)+e+t.slice(n),selection:{start:s,end:s+e.length}}}const r=`[${l}](url)`,c=t.slice(0,s)+r+t.slice(n);if(s===n)return{text:c,selection:caret(s+1)};const a=s+l.length+3;return{text:c,selection:{start:a,end:a+3}}},applyBlockPrefix=(t,e,s)=>{const n=BLOCK_RULES[s],l=t.split("\n"),i=[];let r=0;for(const t of l)i.push(r),r+=t.length+1;const lineIndexAt=t=>{let e=0;for(let s=0;s<l.length;s+=1)i[s]<=t&&(e=s);return e},c=lineIndexAt(e.start),a=lineIndexAt(e.end),o=l.slice(c,a+1),h=o.every(t=>n.has(t)),p=o.map((t,e)=>h?t.replace(ANY_BLOCK_PREFIX,""):n.prefix(e)+t.replace(ANY_BLOCK_PREFIX,"")),d=p[0].length-o[0].length,x=p.reduce((t,e,s)=>t+(e.length-o[s].length),0),L=[...l.slice(0,c),...p,...l.slice(a+1)].join("\n");return{text:L,selection:normalizeSelection({start:Math.max(i[c],e.start+d),end:e.end+x},L.length)}};export const applyMarkdownAction=(t,e)=>{const s=t.text??"",n=normalizeSelection(t.selection,s.length);return isBlockAction(e)?applyBlockPrefix(s,n,e):"link"===e?applyLink(s,n):applyInlineMarker(s,n,INLINE_MARKERS[e])};
1
+ "use strict";const INLINE_MARKERS={bold:"**",italic:"*",strikethrough:"~~",code:"`"},WHOLE_LINK=/^\[([^\]]*)\]\(([^)\s]*)\)$/,LINK_URL_PLACEHOLDER="url",BLOCK_RULES={heading1:{has:e=>/^#\s/.test(e),prefix:()=>"# "},heading2:{has:e=>/^##\s/.test(e),prefix:()=>"## "},bulletList:{has:e=>/^[-*+]\s/.test(e),prefix:()=>"- "},numberedList:{has:e=>/^\d+[.)]\s/.test(e),prefix:e=>`${e+1}. `},quote:{has:e=>/^>\s?/.test(e),prefix:()=>"> "}},ANY_BLOCK_PREFIX=/^(?:#{1,6}\s+|[-*+]\s+|\d+[.)]\s+|>\s?)/,isBlockAction=e=>e in BLOCK_RULES,clamp=(e,t)=>!Number.isFinite(e)||e<0?0:Math.min(Math.trunc(e),t);export const normalizeSelection=(e,t)=>{const s=clamp(e.start,t),n=clamp(e.end,t);return{start:Math.min(s,n),end:Math.max(s,n)}};const caret=e=>({start:e,end:e}),applyInlineMarker=(e,t,s)=>{const{start:n,end:r}=t,i=e.slice(n,r),l=s.length,a="*"===s;if(i.length>=2*l&&i.startsWith(s)&&i.endsWith(s)&&!(a&&i.startsWith("**")&&i.endsWith("**"))){const t=i.slice(l,i.length-l);return{text:e.slice(0,n)+t+e.slice(r),selection:{start:n,end:n+t.length}}}const c=e.slice(Math.max(0,n-l),n),o=e.slice(r,r+l);if(n>=l&&c===s&&o===s&&!(a&&"**"===e.slice(Math.max(0,n-2),n)))return{text:e.slice(0,n-l)+i+e.slice(r+l),selection:{start:n-l,end:r-l}};return{text:e.slice(0,n)+s+i+s+e.slice(r),selection:n===r?caret(n+l):{start:n+l,end:r+l}}},applyLink=(e,t)=>{const{start:s,end:n}=t,r=e.slice(s,n),i=WHOLE_LINK.exec(r);if(i){const t=i[1];if(void 0===t)throw new Error("WHOLE_LINK always captures the label in group 1 when it matches");return{text:e.slice(0,s)+t+e.slice(n),selection:{start:s,end:s+t.length}}}const l=`[${r}](url)`,a=e.slice(0,s)+l+e.slice(n);if(s===n)return{text:a,selection:caret(s+1)};const c=s+r.length+3;return{text:a,selection:{start:c,end:c+3}}},applyBlockPrefix=(e,t,s)=>{const n=BLOCK_RULES[s],r=e.split("\n"),i=[];let l=0;for(const e of r)i.push(l),l+=e.length+1;const lineIndexAt=e=>{let t=0;for(const[s,n]of i.entries())n<=e&&(t=s);return t},a=lineIndexAt(t.start),c=lineIndexAt(t.end),o=r.slice(a,c+1),h=o.every(e=>n.has(e)),p=o.map((e,t)=>({before:e,after:h?e.replace(ANY_BLOCK_PREFIX,""):n.prefix(t)+e.replace(ANY_BLOCK_PREFIX,"")})),f=p.map(e=>e.after),[d]=p;if(void 0===d)throw new Error("applyBlockPrefix: the selection always covers at least one line");const x=i[a];if(void 0===x)throw new Error("applyBlockPrefix: the first selected line always has an offset");const L=d.after.length-d.before.length,u=p.reduce((e,t)=>e+(t.after.length-t.before.length),0),E=[...r.slice(0,a),...f,...r.slice(c+1)].join("\n");return{text:E,selection:normalizeSelection({start:Math.max(x,t.start+L),end:t.end+u},E.length)}};export const applyMarkdownAction=(e,t)=>{const s=e.text??"",n=normalizeSelection(e.selection,s.length);return isBlockAction(t)?applyBlockPrefix(s,n,t):"link"===t?applyLink(s,n):applyInlineMarker(s,n,INLINE_MARKERS[t])};
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{assertValidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n="scanning",helperText:i,labels:s,torch:a=!1,onTorchChange:r,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=useTheme(),g=useSafeAreaInsets(),y=useReducedMotion(),x=useMemo(()=>buildStyles(p),[p]),b=useMemo(()=>({...DEFAULT_SCANNER_OVERLAY_LABELS,...s}),[s]),j=i??b.hint,[S,v]=useState({width:0,height:0}),[A,E]=useState(0),_="scanning"===n||"found"===n||"invalid"===n,w=useRef(createAnimatedValue(1)).current,V=p.motion.duration.slower,C=p.motion.duration.default;useEffect(()=>{if(w.setValue(1),y)return;let e;return"scanning"===n&&V>0?e=Animated.loop(Animated.sequence([Animated.timing(w,{toValue:1.03,duration:2*V,useNativeDriver:!0}),Animated.timing(w,{toValue:1,duration:2*V,useNativeDriver:!0})])):"found"===n&&C>0&&(w.setValue(1.08),e=Animated.timing(w,{toValue:1,duration:C,useNativeDriver:!0})),e?.start(),()=>e?.stop()},[n,y,V,C,w]);const R=useRef(n);useEffect(()=>{R.current!==n&&(R.current=n,!1!==u&&("found"===n?triggerHaptic("notificationSuccess"):"invalid"===n&&triggerHaptic("notificationError")))},[n,u]);const{found:M,invalid:L}=b,{noPermissionTitle:I,noPermissionMessage:P}=b,{noCameraTitle:k,noCameraMessage:N}=b;useEffect(()=>{switch(n){case"scanning":announce(j);break;case"found":announce(M);break;case"invalid":announce(L,{polite:!1});break;case"noPermission":announce(`${I}. ${P}`);break;case"noCamera":announce(`${k}. ${N}`)}},[n,j,M,L,I,P,k,N]);const O=Math.max(240,Math.min(m,S.width-2*p.space.xl)),F=(S.width-O)/2,B=Math.max(p.space.md,(S.height-A-O)/2),D=S.width>0&&S.height>0,H={borderColor:"found"===n?p.colors.success:"invalid"===n?p.colors.danger:p.colors["on-scrim"],width:32,height:32},z="found"===n||"invalid"===n?_jsx(View,{style:[x.pill,{backgroundColor:"found"===n?p.colors.success:p.colors.danger}],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:"found"===n?p.colors["on-success"]:p.colors["on-danger"]},children:"found"===n?M:L})}):_jsx(Text,{variant:"bodySmall",align:"center",style:{color:p.colors["on-scrim"]},children:j}),W=_&&null!=r,U=_?"glass":"outline";return _jsxs(View,{ref:t,testID:f,onLayout:e=>{const{width:t,height:o}=e.nativeEvent.layout;v(e=>e.width===t&&e.height===o?e:{width:t,height:o})},style:[x.root,!_&&{backgroundColor:p.colors.bg},h],children:[_?_jsx(View,{style:StyleSheet.absoluteFill,children:o}):null,_&&D?_jsx(_Fragment,{children:_jsxs(View,{pointerEvents:"none",style:StyleSheet.absoluteFill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:[_jsx(View,{style:[x.scrim,{left:0,right:0,top:0,height:B}]}),_jsx(View,{style:[x.scrim,{left:0,right:0,top:B+O,bottom:0}]}),_jsx(View,{style:[x.scrim,{left:0,width:F,top:B,height:O}]}),_jsx(View,{style:[x.scrim,{left:F+O,right:0,top:B,height:O}]}),_jsx(Animated.View,{style:{position:"absolute",left:F,top:B,width:O,height:O,transform:[{scale:w}]},children:CORNERS.map(e=>_jsx(View,{style:[x.mark,H,e.style]},e.key))})]})}):null,_?null:_jsx(View,{style:x.panel,children:_jsx(EmptyState,{fill:!0,icon:_jsx(AppIcon,{name:"noPermission"===n?"camera":"camera-slash",size:48,color:p.colors["text-subtle"]}),title:"noPermission"===n?I:k,description:"noPermission"===n?P:N,action:"noPermission"===n&&d?{label:b.permissionAction,onPress:d}:void 0})}),_jsxs(View,{pointerEvents:"box-none",onLayout:e=>{const{height:t}=e.nativeEvent.layout;E(e=>e===t?e:t)},style:[x.bar,{paddingBottom:Math.max(g.bottom,p.space.md)}],children:[_&&D?_jsx(View,{pointerEvents:"none",style:x.message,children:z}):null,_jsxs(View,{style:x.actions,children:[W?_jsx(IconButton,{icon:a?"flash":"flash-slash",variant:"glass",size:"lg",active:a,haptic:u,accessibilityLabel:a?b.torchOff:b.torchOn,onPress:()=>r?.(!a)}):null,c?_jsx(Button,{label:b.gallery,leftIcon:"gallery",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:c}):null,l?_jsx(Button,{label:b.manualEntry,leftIcon:"keyboard",variant:U,tone:"neutral",size:"lg",haptic:u,onPress:l}):null]})]})]})});ScannerOverlay.displayName="ScannerOverlay";const buildStyles=e=>StyleSheet.create({root:{flex:1,overflow:"hidden"},scrim:{position:"absolute",backgroundColor:e.colors.scrim},mark:{position:"absolute"},message:{alignItems:"center",paddingHorizontal:e.space.xl},pill:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},panel:{...StyleSheet.absoluteFill,justifyContent:"center"},bar:{position:"absolute",left:0,right:0,bottom:0,flexDirection:"column",alignItems:"center",justifyContent:"center",gap:e.space.sm,paddingHorizontal:e.space.md},actions:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"center",gap:e.space.sm}});export{ScannerOverlay};export default ScannerOverlay;
1
+ "use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{assertValidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n,helperText:i,labels:s,torch:r=!1,onTorchChange:a,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=n??"scanning",g=useTheme(),y=useSafeAreaInsets(),x=useReducedMotion(),b=useMemo(()=>buildStyles(g),[g]),v=useMemo(()=>({...DEFAULT_SCANNER_OVERLAY_LABELS,...s}),[s]),j=i??v.hint,[S,A]=useState({width:0,height:0}),[E,_]=useState(0),w="scanning"===p||"found"===p||"invalid"===p,V=useRef(createAnimatedValue(1)).current,C=g.motion.duration.slower,R=g.motion.duration.default;useEffect(()=>{if(V.setValue(1),x)return;let e;return"scanning"===p&&C>0?e=Animated.loop(Animated.sequence([Animated.timing(V,{toValue:1.03,duration:2*C,useNativeDriver:nativeDriver}),Animated.timing(V,{toValue:1,duration:2*C,useNativeDriver:nativeDriver})])):"found"===p&&R>0&&(V.setValue(1.08),e=Animated.timing(V,{toValue:1,duration:R,useNativeDriver:nativeDriver})),e?.start(),()=>e?.stop()},[p,x,C,R,V]);const M=useRef(p);useEffect(()=>{M.current!==p&&(M.current=p,!1!==u&&("found"===p?triggerHaptic("notificationSuccess"):"invalid"===p&&triggerHaptic("notificationError")))},[p,u]);const{found:L,invalid:I}=v,{noPermissionTitle:P,noPermissionMessage:k}=v,{noCameraTitle:D,noCameraMessage:N}=v;useEffect(()=>{switch(p){case"scanning":announce(j);break;case"found":announce(L);break;case"invalid":announce(I,{polite:!1});break;case"noPermission":announce(`${P}. ${k}`);break;case"noCamera":announce(`${D}. ${N}`)}},[p,j,L,I,P,k,D,N]);const O=Math.max(240,Math.min(m,S.width-2*g.space.xl)),F=(S.width-O)/2,B=Math.max(g.space.md,(S.height-E-O)/2),H=S.width>0&&S.height>0,z={borderColor:"found"===p?g.colors.success:"invalid"===p?g.colors.danger:g.colors["on-scrim"],width:32,height:32},W="found"===p||"invalid"===p?_jsx(View,{style:[b.pill,{backgroundColor:"found"===p?g.colors.success:g.colors.danger}],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:"found"===p?g.colors["on-success"]:g.colors["on-danger"]},children:"found"===p?L:I})}):_jsx(Text,{variant:"bodySmall",align:"center",style:{color:g.colors["on-scrim"]},children:j}),U=w&&null!=a,$=w?"glass":"outline";return _jsxs(View,{ref:t,testID:f,onLayout:e=>{const{width:t,height:o}=e.nativeEvent.layout;A(e=>e.width===t&&e.height===o?e:{width:t,height:o})},style:[b.root,!w&&{backgroundColor:g.colors.bg},h],children:[w?_jsx(View,{style:StyleSheet.absoluteFill,children:o}):null,w&&H?_jsx(_Fragment,{children:_jsxs(View,{pointerEvents:"none",style:StyleSheet.absoluteFill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:[_jsx(View,{style:[b.scrim,{left:0,right:0,top:0,height:B}]}),_jsx(View,{style:[b.scrim,{left:0,right:0,top:B+O,bottom:0}]}),_jsx(View,{style:[b.scrim,{left:0,width:F,top:B,height:O}]}),_jsx(View,{style:[b.scrim,{left:F+O,right:0,top:B,height:O}]}),_jsx(Animated.View,{style:{position:"absolute",left:F,top:B,width:O,height:O,transform:[{scale:V}]},children:CORNERS.map(e=>_jsx(View,{style:[b.mark,z,e.style]},e.key))})]})}):null,w?null:_jsx(View,{style:b.panel,children:_jsx(EmptyState,{fill:!0,icon:_jsx(AppIcon,{name:"noPermission"===p?"camera":"camera-slash",size:48,color:g.colors["text-subtle"]}),title:"noPermission"===p?P:D,description:"noPermission"===p?k:N,action:"noPermission"===p&&d?{label:v.permissionAction,onPress:d}:void 0})}),_jsxs(View,{pointerEvents:"box-none",onLayout:e=>{const{height:t}=e.nativeEvent.layout;_(e=>e===t?e:t)},style:[b.bar,{paddingBottom:Math.max(y.bottom,g.space.md)}],children:[w&&H?_jsx(View,{pointerEvents:"none",style:b.message,children:W}):null,_jsxs(View,{style:b.actions,children:[U?_jsx(IconButton,{icon:r?"flash":"flash-slash",variant:"glass",size:"lg",active:r,haptic:u,accessibilityLabel:r?v.torchOff:v.torchOn,onPress:()=>a?.(!r)}):null,c?_jsx(Button,{label:v.gallery,leftIcon:"gallery",variant:$,tone:"neutral",size:"lg",haptic:u,onPress:c}):null,l?_jsx(Button,{label:v.manualEntry,leftIcon:"keyboard",variant:$,tone:"neutral",size:"lg",haptic:u,onPress:l}):null]})]})]})});ScannerOverlay.displayName="ScannerOverlay";const buildStyles=e=>StyleSheet.create({root:{flex:1,overflow:"hidden"},scrim:{position:"absolute",backgroundColor:e.colors.scrim},mark:{position:"absolute"},message:{alignItems:"center",paddingHorizontal:e.space.xl},pill:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},panel:{...StyleSheet.absoluteFill,justifyContent:"center"},bar:{position:"absolute",left:0,right:0,bottom:0,flexDirection:"column",alignItems:"center",justifyContent:"center",gap:e.space.sm,paddingHorizontal:e.space.md},actions:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"center",gap:e.space.sm}});export{ScannerOverlay};export default ScannerOverlay;
@@ -1 +1 @@
1
- "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,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{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:s,label:r,helperText:i,error:l,value:o,defaultValue:n,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:b,style:x,containerStyle:y,segmentStyle:S,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;assertValidValue("SegmentedControl","size",e.size,["sm","md","lg"]),assertValidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[V,k]=useControllableState({value:o,defaultValue:n??s[0]?.value,onChange:a}),F=useTheme(),I=F.components["segmented-control"],L=useMemo(()=>buildStyles(F),[F]),_=useMemo(()=>resolveSegmentedControlSize(F,d),[F,d]),z=p>=2?2:1,M=z>1,R="segmented"===h,T="underline"===h,A="pills"===h,E=R?F.space[I["track-padding"]]:0,H=Math.ceil(1.25*_.text)*(z-1),q=I["underline-height"],D=F.space[I["pill-inset"]],B="number"==typeof g?g:g?F.radius[g]:void 0,W=B??F.radius.md,P=void 0===B?F.radius.sm:Math.max(B-E,0),N=B??F.radius.pill,G=B??F.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,s.findIndex(e=>e.value===V)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=F.motion.spring.snappy,s=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!0});return s.start(),s},[F.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===s.length||0===e.length?e:[])},[s.length]);const Z=useRef(null);useEffect(()=>{if(void 0===U)return;const e=null!==Z.current&&Z.current!==K;if(Z.current=K,!e)return void J.setValue(U);const t=Y(U);return()=>t.stop()},[K,U,Y,J]);const $=useCallback((e,t)=>{const{x:s,width:r}=t.nativeEvent.layout;X(t=>{const i=t[e];if(i&&i.x===s&&i.width===r)return t;const l=t.slice();return l[e]={x:s,width:r},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===V)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),k(e.value)},[u,k,V,f]),te=R?F.colors.thumb:A?F.colors["primary-soft"]:F.colors.primary,se=R?P:A?N:G,re=activeInkFor(F,m),ie=F.colors["bg-muted"],le=useSquircle(R,W),oe=!0===l||hasFieldText(l),ne=oe&&!u,ae=F.colors["field-border-error"],de=F.size.border,ce=hasFieldText(r),ue=oe?l:i,me=hasFieldText(ue),he=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof r?r:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+H}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},R?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":ie,padding:E}:T?{borderBottomColor:ne?ae:F.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,y,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:ie,stroke:ne?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,R?M?{top:0,bottom:0}:{top:0,height:_.height-2*E}:A?{top:D,bottom:D,left:D}:{bottom:0,height:q},{width:A?Math.max(Q.width-2*D,0):Q.width,borderRadius:se,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},v]}):null,s.map((e,t)=>{const s=e.value===V,r=s?re:F.colors["text-subtle"],i=renderSlotIcon(e.icon,{color:r,size:_.icon,selected:s,disabled:u});return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:s,selected:s,disabled:u},"aria-checked":s,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!s?.7:1},S],children:[i?_jsx(View,{style:L.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:i}):null,_jsx(Text,{variant:"label",weight:s?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:r,fontSize:_.text},w,C],numberOfLines:z,children:e.label})]},String(e.value))})]}),!ne||T||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:R?W:N,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:r}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:oe}):null]}):he});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;
1
+ "use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,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{nativeDriver}from"../../utils/nativeDriver.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];case"info":return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:r,label:i,helperText:s,error:l,value:o,defaultValue:n,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:b,style:x,containerStyle:y,segmentStyle:S,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;assertValidValue("SegmentedControl","size",e.size,["sm","md","lg"]),assertValidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[V]=r;if(void 0===V)throw new Error("SegmentedControl needs at least one segment");const[k,F]=useControllableState({value:o,defaultValue:n??V.value,onChange:a}),I=useTheme(),L=I.components["segmented-control"],_=useMemo(()=>buildStyles(I),[I]),z=useMemo(()=>resolveSegmentedControlSize(I,d),[I,d]),M=p>=2?2:1,R=M>1,T="segmented"===h,E="underline"===h,A="pills"===h,D=T?I.space[L["track-padding"]]:0,H=Math.ceil(1.25*z.text)*(M-1),q=L["underline-height"],B=I.space[L["pill-inset"]],W="number"==typeof g?g:g?I.radius[g]:void 0,P=W??I.radius.md,N=void 0===W?I.radius.sm:Math.max(W-D,0),G=W??I.radius.pill,O=W??I.radius.none,[X,J]=useState([]),K=useRef(createAnimatedValue(0)).current,Q=Math.max(0,r.findIndex(e=>e.value===k)),U=X[Q],Y=U?.x,Z=useCallback(e=>{const t=I.motion.spring.snappy,r=Animated.spring(K,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:nativeDriver});return r.start(),r},[I.motion.spring.snappy,K]);useEffect(()=>{J(e=>e.length===r.length||0===e.length?e:[])},[r.length]);const $=useRef(null);useEffect(()=>{if(void 0===Y)return;const e=null!==$.current&&$.current!==Q;if($.current=Q,!e)return void K.setValue(Y);const t=Z(Y);return()=>t.stop()},[Q,Y,Z,K]);const ee=useCallback((e,t)=>{const{x:r,width:i}=t.nativeEvent.layout;J(t=>{const s=t[e];if(s&&s.x===r&&s.width===i)return t;const l=t.slice();return l[e]={x:r,width:i},l})},[]),te=useCallback(e=>{if(u)return;if(e.value===k)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),F(e.value)},[u,F,k,f]),re=T?I.colors.thumb:A?I.colors["primary-soft"]:I.colors.primary,ie=T?N:A?G:O,se=activeInkFor(I,m),le=I.colors["bg-muted"],oe=useSquircle(T,P),ne=!0===l||hasFieldText(l),ae=ne&&!u,de=I.colors["field-border-error"],ce=I.size.border,ue=hasFieldText(i),me=ne?l:s,he=hasFieldText(me),ge=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof i?i:void 0),testID:j,style:[_.track,{...R?{minHeight:z.height+H}:{height:z.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},T?{borderRadius:P,...smoothCorners,backgroundColor:oe.active?"transparent":le,padding:D}:E?{borderBottomColor:ae?de:I.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,y,x],onLayout:oe.onLayout,children:[oe.active&&oe.size?_jsx(SquircleFill,{width:oe.size.width,height:oe.size.height,radius:P,fill:le,stroke:ae?de:void 0,strokeWidth:ce}):null,_jsxs(View,{style:_.row,children:[U?_jsx(Animated.View,{pointerEvents:"none",style:[_.thumb,T?R?{top:0,bottom:0}:{top:0,height:z.height-2*D}:A?{top:B,bottom:B,left:B}:{bottom:0,height:q},{width:A?Math.max(U.width-2*B,0):U.width,borderRadius:ie,...smoothCorners,backgroundColor:re,transform:[{translateX:K}]},v]}):null,r.map((e,t)=>{const r=e.value===k,i=r?se:I.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:i,size:z.icon,selected:r,disabled:u});return _jsxs(Pressable,{onPress:()=>te(e),onLayout:e=>ee(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:r,selected:r,disabled:u},"aria-checked":r,"aria-disabled":u,style:({pressed:e})=>[_.segment,R?_.segmentMultiline:null,{paddingHorizontal:z["padding-x"],opacity:e&&!r?.7:1},S],children:[s?_jsx(View,{style:_.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:s}):null,_jsx(Text,{variant:"label",weight:r?"semibold":"medium",style:[_.segmentLabel,R?_.segmentLabelMultiline:null,{color:i,fontSize:z.text},w,C],numberOfLines:M,children:e.label})]},String(e.value))})]}),!ae||E||oe.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:ce,borderColor:de,borderRadius:T?P:G,...smoothCorners}]})]});return ue||he?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ue?_jsx(FieldLabel,{size:d,children:i}):null,ge,he?_jsx(FieldMessage,{size:d,text:me,error:ne}):null]}):ge});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;