@webority/mobile-ui 0.96.0 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-kit/kit.js +6773 -6594
- package/dist/canvas-kit/manifest.json +20 -2
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/canvasKit/index.js +1 -1
- package/lib/commonjs/components/AppBar/AppBar.js +1 -1
- package/lib/commonjs/components/Avatar/Avatar.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/Button/Button.js +1 -1
- package/lib/commonjs/components/Calendar/Calendar.js +1 -1
- package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
- package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/KeyboardToolbar/KeyboardToolbar.js +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +1 -1
- package/lib/commonjs/components/Modal/Modal.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/Radio/Radio.js +1 -1
- package/lib/commonjs/components/Rating/Rating.js +1 -1
- package/lib/commonjs/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
- package/lib/commonjs/components/SliderField/SliderField.js +1 -1
- package/lib/commonjs/components/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/Switch/Switch.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/Toast/Toast.js +1 -1
- package/lib/commonjs/form/path.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/theme/index.js +1 -1
- package/lib/commonjs/utils/announce.js +1 -1
- package/lib/module/canvasKit/index.js +1 -1
- package/lib/module/components/AppBar/AppBar.js +1 -1
- package/lib/module/components/Avatar/Avatar.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/Button/Button.js +1 -1
- package/lib/module/components/Calendar/Calendar.js +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +1 -1
- package/lib/module/components/FilePicker/FilePicker.js +1 -1
- package/lib/module/components/IconButton/IconButton.js +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/KeyboardToolbar/KeyboardToolbar.js +1 -1
- package/lib/module/components/MessageList/MessageList.js +1 -1
- package/lib/module/components/Modal/Modal.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/OptionSheet/OptionSheet.js +1 -1
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/Radio/Radio.js +1 -1
- package/lib/module/components/Rating/Rating.js +1 -1
- package/lib/module/components/RichTextEditor/RichTextEditor.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.js +1 -1
- package/lib/module/components/SliderField/SliderField.js +1 -1
- package/lib/module/components/Stepper/Stepper.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/Switch/Switch.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/Toast/Toast.js +1 -1
- package/lib/module/form/path.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/theme/index.js +1 -1
- package/lib/module/utils/announce.js +1 -1
- package/lib/typescript/commonjs/canvasKit/index.d.ts +20 -3
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +1 -0
- package/lib/typescript/commonjs/components/Button/Button.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Card/Card.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Checkbox/Checkbox.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/DecimalInput/DecimalInput.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Input/Input.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Radio/Radio.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Switch/Switch.meta.d.ts +1 -1
- package/lib/typescript/commonjs/components/Text/Text.meta.d.ts +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -3
- package/lib/typescript/commonjs/theme/index.d.ts +0 -20
- package/lib/typescript/module/canvasKit/index.d.ts +20 -3
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +1 -0
- package/lib/typescript/module/components/Button/Button.meta.d.ts +1 -1
- package/lib/typescript/module/components/Card/Card.meta.d.ts +1 -1
- package/lib/typescript/module/components/Checkbox/Checkbox.meta.d.ts +1 -1
- package/lib/typescript/module/components/DecimalInput/DecimalInput.meta.d.ts +1 -1
- package/lib/typescript/module/components/Input/Input.meta.d.ts +1 -1
- package/lib/typescript/module/components/Radio/Radio.meta.d.ts +1 -1
- package/lib/typescript/module/components/SearchBar/SearchBar.meta.d.ts +1 -1
- package/lib/typescript/module/components/Switch/Switch.meta.d.ts +1 -1
- package/lib/typescript/module/components/Text/Text.meta.d.ts +1 -1
- package/lib/typescript/module/index.d.ts +2 -3
- package/lib/typescript/module/theme/index.d.ts +0 -20
- package/package.json +7 -7
- package/lib/commonjs/initUI.js +0 -1
- package/lib/module/initUI.js +0 -1
- package/lib/typescript/commonjs/initUI.d.ts +0 -12
- package/lib/typescript/module/initUI.d.ts +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../PickerTrigger/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,s=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);s.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return s},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:s,disabledDates:n,mode:o="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:g,containerStyle:_,headerLabelStyle:x,navButtonStyle:y,footerButtonStyle:h,haptic:b,testID:v,label:p,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:A,onClear:S,formatValue:T,triggerStyle:V}=e,M=void 0!==e.visible,[k,P]=(0,_react.useState)(!1),I=M?e.visible:k,F=M?v:v?`${v}-calendar`:void 0,Y=(0,_index.useTheme)(),L=(0,_usePresenceMotion.usePresenceMotion)(),[z,B]=(0,_ModalSafeArea.useModalInsets)(),$=(0,_react.useMemo)(()=>buildStyles(Y),[Y]),[H,q]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{I&&q(startOfDay(new Date))},[I]);const E=t?startOfDay(t):H,[O,W]=(0,_react.useState)(E),[G,X]=(0,_react.useState)(t?startOfDay(t):null),[Z,U]=(0,_react.useState)("days"),J=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ee=(0,_react.useRef)(0),te=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ae=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,re=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ie=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,se=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ne=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);X(e),W(e)}else X(null)},[t]);const oe=(0,_react.useMemo)(()=>{const e=new Set;return n?.forEach(t=>e.add(toIso(startOfDay(t)))),e},[n]),le=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),ce=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),de=(0,_react.useCallback)(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!oe.has(toIso(e))),[le,ce,oe]),ue=(0,_react.useMemo)(()=>buildMonthMatrix(O,c),[O,c]),me=(0,_react.useMemo)(()=>buildYearCells(O.getFullYear()),[O]),ge=(0,_react.useMemo)(()=>buildDecadeCells(O.getFullYear()),[O]),xe=(0,_react.useMemo)(()=>weekdayLabels(l,c),[l,c]),ye=(0,_react.useMemo)(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),he=(0,_react.useMemo)(()=>{if("days"===Z)return formatMonthYear(O,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[O,ge,l,Z,me]),be=(0,_react.useCallback)(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),ve=(0,_react.useCallback)(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),pe=(0,_react.useCallback)(e=>{!1!==b&&(0,_index2.triggerHaptic)("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[i]=L.range(32*-t,0),[s]=L.range(32*t,0),n=L.reduced?L.duration("fast"):a,o=L.reduced?L.duration("fast"):r;_reactNative.Animated.sequence([_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:i,duration:a,easing:_reactNative.Easing.out(_reactNative.Easing.quad),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:0,duration:n,useNativeDriver:!0})]),_reactNative.Animated.timing(te,{toValue:s,duration:0,useNativeDriver:!0}),_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:0,duration:r,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:1,duration:o,useNativeDriver:!0})])]).start();const c=addMonths(O,e);W(c),_reactNative.AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[O,b,l,ae,te,L,Y.motion.duration.fast]),fe=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):pe(-1)},[pe,Z,b]),je=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):pe(1)},[pe,Z,b]),Ne=(0,_react.useCallback)(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;(0,_index.setNativeValue)(ie,0),(0,_index.setNativeValue)(se,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ie,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(se,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[ie,se,L,Y.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(b,"selection");if(e&&(0,_index2.triggerHaptic)(e),!L.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ne,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(ne,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),Ne()},[Ne,ne,b,L.reduced]),we=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e,t.getMonth(),1)),U("days"),Ne()},[Ne,b]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e+4,t.getMonth(),1)),U("years"),Ne()},[Ne,b]),Ce=(0,_react.useCallback)(e=>{if(de(e.date))return;const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),X(e.date),e.inMonth||W(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||((0,_index.setNativeValue)(re,.7),_reactNative.Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,b]),Ae=(0,_react.useCallback)(()=>{M||P(!1),r?.()},[M,r]),Se=(0,_react.useCallback)(()=>{"modal"===o?_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),_reactNative.Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Ae()}):Ae()},[J,o,Ae,L,K,Y.motion.ease.accelerate]),{handleGesture:Te,opacity:Ve}=(0,_useDragToDismiss.useDragToDismiss)({drag:Q,travel:()=>ee.current||320,onDismiss:Se}),Me=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(K,Ve),[K,Ve]),ke=(0,_react.useMemo)(()=>J.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);(0,_react.useEffect)(()=>{if("modal"===o&&I){J.setValue(0),(0,_index.setNativeValue)(K,0),(0,_index.setNativeValue)(Q,0),(0,_index.setNativeValue)(Ve,1);const e=L.reduced?_reactNative.Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):_reactNative.Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[I,o,J,L,K,Q,Ve,Y.motion]);const Pe=(0,_react.useCallback)(()=>{!1!==b&&(0,_index2.triggerHaptic)("selection"),Se()},[Se,b]),Ie=(0,_react.useCallback)(()=>{G&&(!1!==b&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(G),Se())},[Se,a,G,b]),Fe=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.titleRow,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.card,g,_],accessibilityRole:"modal"===o?void 0:"none",accessible:!1,testID:F,children:["modal"===o?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Te,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.handle}),Ye]})}):Ye,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:fe,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[$.headerLabelWrap,x],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${he}, switch to year selection`:"years"===Z?`${he}, switch to decade selection`:`${he}, switch to year selection`,hitSlop:8,children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.headerLabelInner,{transform:[{scale:ne}],opacity:"days"===Z?ae:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"›"})})]}),"days"===Z?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayRow,children:xe.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!G&&isSameDay(e.date,G),r=isSameDay(e.date,H),i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],o=t?.3:e.inMonth?1:.4;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:ye.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.dayInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o},a?{transform:[{scale:re}]}:null],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.dayText,{color:n}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):"years"===Z?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!G&&G.getFullYear()===e,r=H.getFullYear()===e,i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],o=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:n}],children:e})})},`year-${e}`)})},`yr-${t}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=ve(e),r=!!G&&decadeStartFor(G.getFullYear())===e,i=decadeStartFor(H.getFullYear())===e,s=r?Y.colors.primary:"transparent",n=i&&!r?Y.colors.primary:"transparent",o=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:l}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:o}],children:`${e}s`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:m,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ie,disabled:!G,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:G?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!G},"aria-disabled":!G,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(T??(e=>e.toLocaleDateString()))(t):void 0,Be=!M;if("inline"===o)return I||Be?Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:p,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:A,onClear:S,onPress:()=>P(!0),triggerStyle:V,testID:v}),I?Le:null]}):Le:null;const $e=(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:I,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Se,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:B,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:ke}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:Se,accessibilityLabel:"Dismiss"}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:Me,transform:[{translateY:_reactNative.Animated.add(Fe,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})});return Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:p,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:A,onClear:S,onPress:()=>P(!0),triggerStyle:V,testID:v}),$e]}):$e};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({backdrop:{..._reactNative.StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,..._corners.smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};var _default=exports.default=DatePicker;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.DatePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_index3=require("../PickerTrigger/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const NAV_BUTTON_SIZE=36,AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),GRID_SIZE=12,DECADE_SPAN=10,startOfDay=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),isSameDay=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),toIso=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,addMonths=(e,t)=>new Date(e.getFullYear(),e.getMonth()+t,1),buildMonthMatrix=(e,t)=>{const a=e.getFullYear(),r=e.getMonth(),i=(new Date(a,r,1).getDay()-t+7)%7,s=[];for(let e=0;e<42;e+=1){const t=new Date(a,r,1-i+e);s.push({date:t,inMonth:t.getMonth()===r,iso:toIso(t)})}return s},weekdayLabels=(e,t)=>{const a=new Intl.DateTimeFormat(e,{weekday:"short"}),r=[];for(let e=0;e<7;e+=1){const i=new Date(1970,0,4+(t+e)%7);r.push(a.format(i))}return r},formatMonthYear=(e,t)=>new Intl.DateTimeFormat(t,{month:"long",year:"numeric"}).format(e),decadeStartFor=e=>10*Math.floor(e/10),buildYearCells=e=>{const t=e-4;return Array.from({length:12},(e,a)=>t+a)},buildDecadeCells=e=>{const t=decadeStartFor(e)-40;return Array.from({length:12},(e,a)=>t+10*a)},DatePicker=e=>{const{value:t,onChange:a,onClose:r,minDate:i,maxDate:s,disabledDates:n,mode:o="modal",locale:l="en-IN",weekStartsOn:c=0,title:d="Select Date",confirmLabel:u="Confirm",cancelLabel:m="Cancel",style:_,containerStyle:g,headerLabelStyle:x,navButtonStyle:y,footerButtonStyle:h,haptic:b,testID:p,label:v,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,formatValue:M,triggerStyle:T}=e,V=void 0!==e.visible,[k,P]=(0,_react.useState)(!1),I=V?e.visible:k,F=V?p:p?`${p}-calendar`:void 0,Y=(0,_index.useTheme)(),L=(0,_usePresenceMotion.usePresenceMotion)(),[z,B]=(0,_ModalSafeArea.useModalInsets)(),$=(0,_react.useMemo)(()=>buildStyles(Y),[Y]),[q,H]=(0,_react.useState)(()=>startOfDay(new Date));(0,_react.useEffect)(()=>{I&&H(startOfDay(new Date))},[I]);const E=t?startOfDay(t):q,[O,W]=(0,_react.useState)(E),[G,X]=(0,_react.useState)(t?startOfDay(t):null),[Z,U]=(0,_react.useState)("days"),J=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,K=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,Q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ee=(0,_react.useRef)(0),te=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,ae=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,re=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ie=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,se=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current,ne=(0,_react.useRef)((0,_index.createAnimatedValue)(1)).current;(0,_react.useEffect)(()=>{if(t){const e=startOfDay(t);X(e),W(e)}else X(null)},[t]);const oe=(0,_react.useMemo)(()=>{const e=new Set;return n?.forEach(t=>{e.add(toIso(startOfDay(t)))}),e},[n]),le=(0,_react.useMemo)(()=>i?startOfDay(i):null,[i]),ce=(0,_react.useMemo)(()=>s?startOfDay(s):null,[s]),de=(0,_react.useCallback)(e=>!!(le&&e.getTime()<le.getTime())||(!!(ce&&e.getTime()>ce.getTime())||!!oe.has(toIso(e))),[le,ce,oe]),ue=(0,_react.useMemo)(()=>buildMonthMatrix(O,c),[O,c]),me=(0,_react.useMemo)(()=>buildYearCells(O.getFullYear()),[O]),ge=(0,_react.useMemo)(()=>buildDecadeCells(O.getFullYear()),[O]),xe=(0,_react.useMemo)(()=>weekdayLabels(l,c),[l,c]),ye=(0,_react.useMemo)(()=>new Intl.DateTimeFormat(l,{weekday:"long",year:"numeric",month:"long",day:"numeric"}),[l]),he=(0,_react.useMemo)(()=>{if("days"===Z)return formatMonthYear(O,l);if("years"===Z){return`${me[0]} - ${me[me.length-1]}`}return`${ge[0]} - ${ge[ge.length-1]+9}`},[O,ge,l,Z,me]),be=(0,_react.useCallback)(e=>!!(le&&e<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),pe=(0,_react.useCallback)(e=>!!(le&&e+10-1<le.getFullYear())||!!(ce&&e>ce.getFullYear()),[le,ce]),ve=(0,_react.useCallback)(e=>{!1!==b&&(0,_index2.triggerHaptic)("impactLight");const t=e>0?1:-1,a=Y.motion.duration.fast,r=Y.motion.duration.fast,[i]=L.range(32*-t,0),[s]=L.range(32*t,0),n=L.reduced?L.duration("fast"):a,o=L.reduced?L.duration("fast"):r;_reactNative.Animated.sequence([_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:i,duration:a,easing:_reactNative.Easing.out(_reactNative.Easing.quad),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:0,duration:n,useNativeDriver:!0})]),_reactNative.Animated.timing(te,{toValue:s,duration:0,useNativeDriver:!0}),_reactNative.Animated.parallel([_reactNative.Animated.timing(te,{toValue:0,duration:r,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(ae,{toValue:1,duration:o,useNativeDriver:!0})])]).start();const c=addMonths(O,e);W(c),_reactNative.AccessibilityInfo.announceForAccessibility(formatMonthYear(c,l))},[O,b,l,ae,te,L,Y.motion.duration.fast]),fe=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()-12,e.getMonth(),1):e=>new Date(e.getFullYear()-120,e.getMonth(),1))):ve(-1)},[ve,Z,b]),je=(0,_react.useCallback)(()=>{"days"!==Z?(!1!==b&&(0,_index2.triggerHaptic)("impactLight"),W("years"===Z?e=>new Date(e.getFullYear()+12,e.getMonth(),1):e=>new Date(e.getFullYear()+120,e.getMonth(),1))):ve(1)},[ve,Z,b]),Ne=(0,_react.useCallback)(()=>{const[e]=L.range(.9,1),t=L.reduced?L.duration("default"):Y.motion.duration.default;(0,_index.setNativeValue)(ie,0),(0,_index.setNativeValue)(se,e),_reactNative.Animated.parallel([_reactNative.Animated.timing(ie,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0}),_reactNative.Animated.timing(se,{toValue:1,duration:t,easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!0})]).start()},[ie,se,L,Y.motion.duration.default]),Re=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(b,"selection");if(e&&(0,_index2.triggerHaptic)(e),!L.reduced){const e=80,t=100;_reactNative.Animated.sequence([_reactNative.Animated.timing(ne,{toValue:.96,duration:e,useNativeDriver:!0}),_reactNative.Animated.timing(ne,{toValue:1,duration:t,useNativeDriver:!0})]).start()}U(e=>"days"===e?"years":"years"===e?"decades":"years"),Ne()},[Ne,ne,b,L.reduced]),we=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e,t.getMonth(),1)),U("days"),Ne()},[Ne,b]),De=(0,_react.useCallback)(e=>{const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),W(t=>new Date(e+4,t.getMonth(),1)),U("years"),Ne()},[Ne,b]),Ce=(0,_react.useCallback)(e=>{if(de(e.date))return;const t=(0,_index2.resolveHaptic)(b,"selection");t&&(0,_index2.triggerHaptic)(t),X(e.date),e.inMonth||W(new Date(e.date.getFullYear(),e.date.getMonth(),1)),L.reduced||((0,_index.setNativeValue)(re,.7),_reactNative.Animated.spring(re,{toValue:1,damping:Y.motion.spring.bouncy.damping,stiffness:Y.motion.spring.bouncy.stiffness,mass:Y.motion.spring.bouncy.mass,useNativeDriver:!0}).start())},[de,L.reduced,re,Y.motion.spring.bouncy,b]),Se=(0,_react.useCallback)(()=>{V||P(!1),r?.()},[V,r]),Ae=(0,_react.useCallback)(()=>{"modal"===o?_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:0,duration:L.duration("default"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!1}),_reactNative.Animated.timing(K,{toValue:0,duration:L.duration("fast"),easing:_reactNative.Easing.bezier(...Y.motion.ease.accelerate),useNativeDriver:!0})]).start(()=>{Se()}):Se()},[J,o,Se,L,K,Y.motion.ease.accelerate]),{handleGesture:Me,opacity:Te}=(0,_useDragToDismiss.useDragToDismiss)({drag:Q,travel:()=>ee.current||320,onDismiss:Ae}),Ve=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(K,Te),[K,Te]),ke=(0,_react.useMemo)(()=>J.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(Y.colors.scrim),Y.colors.scrim]}),[J,Y.colors.scrim]);(0,_react.useEffect)(()=>{if("modal"===o&&I){J.setValue(0),(0,_index.setNativeValue)(K,0),(0,_index.setNativeValue)(Q,0),(0,_index.setNativeValue)(Te,1);const e=L.reduced?_reactNative.Animated.timing(K,{toValue:1,duration:L.duration("default"),useNativeDriver:!0}):_reactNative.Animated.spring(K,{toValue:1,damping:Y.motion.spring.gentle.damping,stiffness:Y.motion.spring.gentle.stiffness,mass:Y.motion.spring.gentle.mass,useNativeDriver:!0}),t=_reactNative.Animated.parallel([_reactNative.Animated.timing(J,{toValue:1,duration:L.duration("default"),easing:_reactNative.Easing.out(_reactNative.Easing.cubic),useNativeDriver:!1}),e]);return t.start(),()=>t.stop()}},[I,o,J,L,K,Q,Te,Y.motion]);const Pe=(0,_react.useCallback)(()=>{!1!==b&&(0,_index2.triggerHaptic)("selection"),Ae()},[Ae,b]),Ie=(0,_react.useCallback)(()=>{G&&(!1!==b&&(0,_index2.triggerHaptic)("notificationSuccess"),a?.(G),Ae())},[Ae,a,G,b]),Fe=K.interpolate({inputRange:[0,1],outputRange:L.range(320,0)}),Ye=(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.titleRow,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.title,accessibilityRole:"header",children:d})}),Le=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.card,_,g],accessibilityRole:"modal"===o?void 0:"none",accessible:!1,testID:F,children:["modal"===o?(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:Me,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.grabArea,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.handle}),Ye]})}):Ye,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.headerRow,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:fe,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Previous month":"years"===Z?"Previous years":"Previous decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"‹"})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Re,style:[$.headerLabelWrap,x],accessibilityRole:"button",accessibilityLabel:"days"===Z?`${he}, switch to year selection`:"years"===Z?`${he}, switch to decade selection`:`${he}, switch to year selection`,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[$.headerLabelInner,{transform:[{scale:ne}],opacity:"days"===Z?ae:1}],children:[(0,_jsxRuntime.jsx)(_reactNative.Animated.Text,{style:[$.headerLabel,{transform:[{translateX:"days"===Z?te:0}]}],accessibilityLiveRegion:"polite",children:he}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.headerCaret,children:(Y.settings.icons.chevronDown??_defaultIcons.defaultIcons.chevronDown)({size:Y.text.sm.size,color:Y.colors["text-muted"]})})]})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:je,style:({pressed:e})=>[$.navBtn,e&&$.navBtnPressed,y],accessibilityRole:"button",accessibilityLabel:"days"===Z?"Next month":"years"===Z?"Next years":"Next decades",hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.navText,children:"›"})})]}),"days"===Z?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayRow,children:xe.map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.weekdayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:$.weekdayText,children:e})},`${e}-${t}`))}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.grid,{opacity:ae,transform:[{translateX:te}]}],children:Array.from({length:6}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ue.slice(7*t,7*t+7).map(e=>{const t=de(e.date),a=!!G&&isSameDay(e.date,G),r=isSameDay(e.date,q),i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:e.inMonth?t?Y.colors["text-disabled"]:Y.colors["text-body"]:Y.colors["text-subtle"],o=t?.3:e.inMonth?1:.4;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>Ce(e),accessibilityRole:"button",accessibilityLabel:ye.format(e.date),accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.dayCell,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.dayInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o},a?{transform:[{scale:re}]}:null],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.dayText,{color:n}],children:e.date.getDate()})})},e.iso)})},`r-${t}`))})]}):"years"===Z?(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:me.slice(4*t,4*t+4).map(e=>{const t=be(e),a=!!G&&G.getFullYear()===e,r=q.getFullYear()===e,i=a?Y.colors.primary:"transparent",s=r&&!a?Y.colors.primary:"transparent",n=a?Y.colors["on-primary"]:t?Y.colors["text-disabled"]:Y.colors["text-body"],o=t?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:t,onPress:()=>we(e),accessibilityRole:"button",accessibilityLabel:`Year ${e}`,accessibilityState:{selected:a,disabled:t},"aria-selected":a,"aria-disabled":t,style:$.yearCell,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[$.yearInner,{backgroundColor:i,borderColor:s,borderWidth:r&&!a?1.5:0,opacity:o}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:n}],children:e})})},`year-${e}`)})},`yr-${t}`))}):(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.yearGrid,{opacity:ie,transform:[{scale:se}]}],children:Array.from({length:3}).map((e,t)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:$.gridRow,children:ge.slice(4*t,4*t+4).map(e=>{const t=e+10-1,a=pe(e),r=!!G&&decadeStartFor(G.getFullYear())===e,i=decadeStartFor(q.getFullYear())===e,s=r?Y.colors.primary:"transparent",n=i&&!r?Y.colors.primary:"transparent",o=r?Y.colors["on-primary"]:a?Y.colors["text-disabled"]:Y.colors["text-body"],l=a?.3:1;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{disabled:a,onPress:()=>De(e),accessibilityRole:"button",accessibilityLabel:`Decade ${e} to ${t}`,accessibilityState:{selected:r,disabled:a},"aria-selected":r,"aria-disabled":a,style:$.yearCell,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[$.yearInner,{backgroundColor:s,borderColor:n,borderWidth:i&&!r?1.5:0,opacity:l}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.yearText,{color:o}],children:`${e}s`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.decadeRangeText,{color:r?Y.colors["on-primary"]:Y.colors["text-subtle"]}],children:`${e}-${t}`})]})},`decade-${e}`)})},`dec-${t}`))}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:$.footer,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Pe,style:({pressed:e})=>[$.footerBtn,$.footerCancel,e&&$.footerBtnPressed,h],accessibilityRole:"button",accessibilityLabel:m,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["text-muted"]}],children:m})}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:Ie,disabled:!G,style:({pressed:e})=>[$.footerBtn,$.footerConfirm,{backgroundColor:Y.colors.primary,opacity:G?1:.5},e&&{backgroundColor:Y.colors["primary-hover"]},h],accessibilityRole:"button",accessibilityLabel:u,accessibilityState:{disabled:!G},"aria-disabled":!G,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[$.footerBtnText,{color:Y.colors["on-primary"]}],children:u})})]})]}),ze=t?(M??(e=>e.toLocaleDateString()))(t):void 0,Be=!V;if("inline"===o)return I||Be?Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),I?Le:null]}):Le:null;const $e=(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:I,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:Ae,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:B,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,style:[$.backdrop,{backgroundColor:ke}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:Ae,accessibilityLabel:"Dismiss"}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[$.sheetWrap,{paddingBottom:Math.max(z.bottom,Y.space.lg),opacity:Ve,transform:[{translateY:_reactNative.Animated.add(Fe,Q)}]}],onLayout:e=>{ee.current=e.nativeEvent.layout.height},accessibilityViewIsModal:!0,accessibilityRole:"none",children:Le}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})});return Be?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_index3.PickerTrigger,{label:v,value:ze,placeholder:f,helperText:j,error:N,required:R,disabled:w,size:D,variant:C,clearable:S,onClear:A,onPress:()=>P(!0),triggerStyle:T,testID:p}),$e]}):$e};exports.DatePicker=DatePicker;const buildStyles=e=>{const t=e.shadow.popover;return _reactNative.StyleSheet.create({backdrop:{..._reactNative.StyleSheet.absoluteFill},sheetWrap:{position:"absolute",left:0,right:0,bottom:0,paddingHorizontal:e.space.md,paddingBottom:e.space.lg},card:{backgroundColor:e.colors.surface,borderRadius:e.radius.xl,..._corners.smoothCorners,padding:e.space.lg,shadowColor:t.shadowColor,shadowOffset:t.shadowOffset,shadowOpacity:t.shadowOpacity,shadowRadius:t.shadowRadius,elevation:t.elevation},grabArea:{marginTop:-e.space.lg,paddingTop:e.space.sm},handle:{alignSelf:"center",width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:e.colors["border-subtle"],marginBottom:e.space.sm},titleRow:{marginBottom:e.space.sm},title:{fontSize:e.text.lg.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:e.space.md},navBtn:{width:36,height:36,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:e.colors["bg-subtle"]},navBtnPressed:{backgroundColor:e.colors["surface-pressed"]},navText:{fontSize:e.text["2xl"].size,lineHeight:26,color:e.colors["text-body"],fontWeight:e.weight.semibold},headerLabelWrap:{flex:1,alignItems:"center"},headerLabelInner:{flexDirection:"row",alignItems:"center",justifyContent:"center"},headerLabel:{fontSize:e.text.base.size,fontWeight:e.weight.semibold,color:e.colors["text-body"]},headerCaret:{marginLeft:e.space.xs,alignItems:"center",justifyContent:"center"},weekdayRow:{flexDirection:"row",marginBottom:e.space.xs},weekdayCell:{flex:1,alignItems:"center",paddingVertical:e.space.xs},weekdayText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,color:e.colors["text-subtle"],letterSpacing:e["letter-spacing"].wide},grid:{},gridRow:{flexDirection:"row"},dayCell:{flex:1,aspectRatio:1,alignItems:"center",justifyContent:"center",padding:e.space.xxs},dayInner:{width:"100%",height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},dayText:{fontSize:e.text.sm.size,fontWeight:e.weight.medium},yearGrid:{},yearCell:{flex:1,aspectRatio:1.6,alignItems:"center",justifyContent:"center",padding:e.space.xs},yearInner:{width:"100%",height:"100%",borderRadius:e.radius.lg,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},yearText:{fontSize:e.text.base.size,fontWeight:e.weight.semibold},decadeRangeText:{fontSize:e.text.xs.size,fontWeight:e.weight.medium,marginTop:e.space.xxs},footer:{flexDirection:"row",justifyContent:"flex-end",alignItems:"center",marginTop:e.space.lg,gap:e.space.sm},footerBtn:{paddingHorizontal:e.space.lg,paddingVertical:e.space.sm,borderRadius:e.radius.md,..._corners.smoothCorners,minHeight:40,alignItems:"center",justifyContent:"center"},footerCancel:{backgroundColor:"transparent"},footerConfirm:{},footerBtnPressed:{opacity:.85},footerBtnText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}})};var _default=exports.default=DatePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchesAccept=exports.formatFileSize=exports.default=exports.FilePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../FieldBase/index.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`},formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i+=1;return`${r>=10||0===i?Math.round(r):Math.round(10*r)/10} ${t[i]}`};exports.formatFileSize=formatFileSize;const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));exports.matchesAccept=matchesAccept;const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=exports.FilePicker=(0,_react.forwardRef)((e,t)=>{const{files:r,defaultFiles:i,onChange:s,sources:o,maxFiles:n,maxSizeMB:l,accept:a,validate:c,process:d,variant:u="card",renderFile:x,renderTrigger:m,disabled:g=!1,helperText:h,error:p,labels:_,haptic:b,onPick:y,onRemove:f,onError:j,onFilePress:v,onRetry:R,style:T,accessibilityLabel:S,testID:C}=e,F=(0,_index2.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(F),[F]),z=(0,_react.useMemo)(()=>({...DEFAULT_LABELS,..._}),[_]),N=F.radius.md,P=F.colors.primary,[k,I]=(0,_index.useControllableState)({value:r,defaultValue:i??[],onChange:s}),O=(0,_react.useRef)(k);O.current=k;const V=(0,_react.useCallback)(e=>{O.current=e,I(e)},[I]),[B,L]=(0,_react.useState)(null),[M,A]=(0,_react.useState)(!1),$=p??B??void 0,H="number"==typeof n&&k.length>=n,q=(0,_react.useCallback)((e,t)=>{0!==e.length&&(L(e[0]),e.forEach(e=>j?.(e,t)),!1!==b&&(0,_index3.triggerHaptic)("notificationError"))},[j,b]),E=(0,_react.useCallback)(async e=>{let t;try{t=await e.pick()}catch(e){return void q([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let i=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof n){const e=Math.max(0,n-O.current.length);i.length>e&&(r.push(z.errorTooMany(n)),i=i.slice(0,e))}const s=[];for(const e of i){if("number"==typeof l&&"number"==typeof e.size&&e.size>1024*l*1024){r.push(z.errorTooLarge(e.name,l));continue}if(!matchesAccept(e.type,a)){r.push(z.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):s.push(e)}if(q(r),0===s.length)return;if(!d){V([...O.current,...s]),L(r.length>0?r[0]:null);const e=(0,_index3.resolveHaptic)(b,"selection");return e&&(0,_index3.triggerHaptic)(e),void y?.(s)}const o=s.map(e=>({...e,status:"processing"}));V([...O.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};V(O.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){V(O.current.filter(t=>t.id!==e.id)),q([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&L(null);const e=(0,_index3.resolveHaptic)(b,"selection");e&&(0,_index3.triggerHaptic)(e),y?.(u)}},[n,l,a,c,d,z,q,V,y,b]),W=(0,_react.useCallback)(e=>{if(g||H)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?E(t):o.length>1&&A(!0)},[g,H,o,E]),D=(0,_react.useCallback)(e=>{if(g)return;V(O.current.filter(t=>t.id!==e.id)),L(null);const t=(0,_index3.resolveHaptic)(b,"selection");t&&(0,_index3.triggerHaptic)(t),f?.(e)},[g,V,f,b]),U=(0,_react.useCallback)(()=>{V([]),L(null)},[V]);(0,_react.useImperativeHandle)(t,()=>({open:W,clear:U}),[W,U]);const G=0===k.length?z.trigger:`${k.length} file${1===k.length?"":"s"} attached`,K=S??`Attachments. ${G}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=F.settings.icons.attachment??_defaultIcons.defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.tileOverlayText,{color:F.colors["on-scrim"]}],children:`${t}%`}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressFill,{width:`${t}%`,backgroundColor:F.colors.primary}]})})]})}return"done"===e.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.doneBadge,{backgroundColor:F.colors.success}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.doneBadgeText,{color:F.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?(0,_jsxRuntime.jsx)(_reactNative.Image,{source:{uri:t},style:w.thumbnailImage}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.extensionTile,{backgroundColor:F.colors["bg-subtle"]}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.extensionText,{color:F.colors["text-muted"],...(0,_index2.fontFor)(F,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(e),disabled:g,hitSlop:8,accessibilityRole:"button",accessibilityLabel:z.removeFile(e.name),style:[w.removeButton,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.removeButtonText,{color:F.colors["on-scrim"]}],children:"×"})}),retryButton=e=>R&&"error"===e.status?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>R(e),disabled:g,hitSlop:8,accessibilityRole:"button",accessibilityLabel:z.retry,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.retryText,{color:F.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:g,remove:()=>D(e),retry:R?()=>R(e):void 0},i=x?x(r):"card"===u?(e=>{const{file:t}=e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listRow,{borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border,backgroundColor:F.colors.bg}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listThumb,{borderRadius:F.radius.sm,..._corners.smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})}):null]}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.listTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,ellipsizeMode:"middle",style:[w.listName,{color:F.colors["text-body"],fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:t.name}),(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:[w.listSubtitle,{color:"error"===t.status?F.colors["danger-text"]:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:F.colors.primary}]})}):null]}),retryButton(t),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(t),disabled:g,hitSlop:8,accessibilityRole:"button",accessibilityLabel:z.removeFile(t.name),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.listRemoveText,{color:F.colors["text-subtle"]}],children:"×"})})]})})(r);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:v?()=>v(e):void 0,disabled:g||!v,accessibilityLabel:fileA11yLabel(e),children:i},e.id)},J={open:W,disabled:g||H,fileCount:k.length,atCapacity:H},dashedTrigger=e=>(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>W(),disabled:g||H,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:g||H},"aria-disabled":g||H,style:({pressed:t})=>[w.trigger,e?w.triggerCompact:null,{borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:t?F.colors["surface-pressed"]:F.colors.bg,opacity:g||H?.55:1}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.triggerRow,children:[Y?Y({size:16,color:F.colors.primary}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.triggerText,{color:F.colors.primary,fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:0===k.length?z.trigger:z.addMore})]}),!e&&h?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.helperText,{color:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:h}):null]}),Q=(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>W(),disabled:g||H,accessibilityRole:"button",accessibilityLabel:z.addMore,style:({pressed:e})=>[w.tile,w.addTile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:e?F.colors["surface-pressed"]:"transparent",opacity:g||H?.55:1}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.addTileText,{color:F.colors.primary}],children:"+"})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.container,T],testID:C,accessibilityLabel:K,children:["card"===u?0===k.length?m?m(J):dashedTrigger(!1):(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[w.strip,{columnGap:F.space.sm}],children:[k.map(renderOneFile),m?m(J):H||g?null:Q]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{rowGap:F.space.sm},children:[m?m(J):H?null:dashedTrigger(k.length>0),k.map(renderOneFile)]}),(0,_index4.hasFieldText)($)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityLiveRegion:"polite",style:[w.errorText,{color:F.colors["danger-text"],fontSize:F.text.xs.size,marginTop:F.space.xxs}],children:$}):null,(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:M,onClose:()=>A(!1),title:z.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{A(!1),E(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});var _default=exports.default=FilePicker;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchesAccept=exports.formatFileSize=exports.default=exports.FilePicker=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index4=require("../FieldBase/index.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");let fileIdSeq=0;const nextFileId=()=>"wfp-"+ ++fileIdSeq,DEFAULT_LABELS={trigger:"Attach file",addMore:"Add more",sheetTitle:"Add from",removeFile:e=>`Remove ${e}`,retry:"Retry upload",errorTooMany:e=>`You can attach up to ${e} files.`,errorTooLarge:(e,t)=>`${e} is larger than ${t} MB.`,errorWrongType:e=>`${e} is not an accepted file type.`},formatFileSize=e=>{if(void 0===e||e<=0)return"";const t=["B","KB","MB","GB"];let r=e,i=0;for(;r>=1024&&i<t.length-1;)r/=1024,i+=1;return`${r>=10||0===i?Math.round(r):Math.round(10*r)/10} ${t[i]}`};exports.formatFileSize=formatFileSize;const matchesAccept=(e,t)=>!t||0===t.length||!!e&&t.some(t=>"*/*"===t||"*"===t||(t.endsWith("/*")?e.startsWith(t.slice(0,t.length-1)):e===t));exports.matchesAccept=matchesAccept;const isImage=e=>!0===e.type?.startsWith("image/")||!e.type&&/\.(png|jpe?g|gif|webp|heic)$/i.test(e.name),imageSourceOf=e=>e.thumbnailUrl??(isImage(e)?e.uri??e.url:void 0),extensionOf=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"FILE":e.slice(t+1).toUpperCase().slice(0,4)},FilePicker=exports.FilePicker=(0,_react.forwardRef)((e,t)=>{const{files:r,defaultFiles:i,onChange:s,sources:o,maxFiles:n,maxSizeMB:l,accept:a,validate:c,process:d,variant:u="card",renderFile:x,renderTrigger:m,disabled:h=!1,helperText:g,error:p,labels:_,haptic:b,onPick:y,onRemove:f,onError:j,onFilePress:v,onRetry:R,style:S,accessibilityLabel:T,testID:C}=e,F=(0,_index2.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(F),[F]),z=(0,_react.useMemo)(()=>({...DEFAULT_LABELS,..._}),[_]),N=F.radius.md,P=F.colors.primary,[k,I]=(0,_index.useControllableState)({value:r,defaultValue:i??[],onChange:s}),O=(0,_react.useRef)(k);O.current=k;const V=(0,_react.useCallback)(e=>{O.current=e,I(e)},[I]),[M,B]=(0,_react.useState)(null),[L,A]=(0,_react.useState)(!1),$=p??M??void 0,q="number"==typeof n&&k.length>=n,H=(0,_react.useCallback)((e,t)=>{0!==e.length&&(B(e[0]),e.forEach(e=>{j?.(e,t)}),!1!==b&&(0,_index3.triggerHaptic)("notificationError"))},[j,b]),E=(0,_react.useCallback)(async e=>{let t;try{t=await e.pick()}catch(e){return void H([e instanceof Error?e.message:String(e)])}if(!t||0===t.length)return;const r=[];let i=t.map(e=>({id:nextFileId(),name:e.name??e.uri.split("/").pop()??"file",uri:e.uri,type:e.type,size:e.size,meta:e.meta,status:"idle"}));if("number"==typeof n){const e=Math.max(0,n-O.current.length);i.length>e&&(r.push(z.errorTooMany(n)),i=i.slice(0,e))}const s=[];for(const e of i){if("number"==typeof l&&"number"==typeof e.size&&e.size>1024*l*1024){r.push(z.errorTooLarge(e.name,l));continue}if(!matchesAccept(e.type,a)){r.push(z.errorWrongType(e.name));continue}const t=c?.(e);t?r.push(t):s.push(e)}if(H(r),0===s.length)return;if(!d){V([...O.current,...s]),B(r.length>0?r[0]:null);const e=(0,_index3.resolveHaptic)(b,"selection");return e&&(0,_index3.triggerHaptic)(e),void y?.(s)}const o=s.map(e=>({...e,status:"processing"}));V([...O.current,...o]);const u=[];for(const e of o)try{const t=await d({...e,status:"idle"}),r={...t,id:e.id,status:t.status??"idle"};V(O.current.map(t=>t.id===e.id?r:t)),u.push(r)}catch(t){V(O.current.filter(t=>t.id!==e.id)),H([t instanceof Error?t.message:String(t)],e)}if(u.length>0){0===r.length&&B(null);const e=(0,_index3.resolveHaptic)(b,"selection");e&&(0,_index3.triggerHaptic)(e),y?.(u)}},[n,l,a,c,d,z,H,V,y,b]),W=(0,_react.useCallback)(e=>{if(h||q)return;const t=e?o.find(t=>t.key===e):1===o.length?o[0]:void 0;t?E(t):o.length>1&&A(!0)},[h,q,o,E]),D=(0,_react.useCallback)(e=>{if(h)return;V(O.current.filter(t=>t.id!==e.id)),B(null);const t=(0,_index3.resolveHaptic)(b,"selection");t&&(0,_index3.triggerHaptic)(t),f?.(e)},[h,V,f,b]),U=(0,_react.useCallback)(()=>{V([]),B(null)},[V]);(0,_react.useImperativeHandle)(t,()=>({open:W,clear:U}),[W,U]);const G=0===k.length?z.trigger:`${k.length} file${1===k.length?"":"s"} attached`,K=T??`Attachments. ${G}`,statusText=e=>{switch(e.status){case"processing":return"Processing…";case"uploading":return`Uploading ${Math.round(100*(e.progress??0))}%`;case"done":return"Uploaded";case"error":return e.error??"Failed";default:return""}},fileA11yLabel=e=>[e.name,formatFileSize(e.size),statusText(e)].filter(Boolean).join(", "),Y=F.settings.icons.attachment??_defaultIcons.defaultIcons.attachment,renderStatusOverlay=e=>{if("processing"===e.status)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})});if("uploading"===e.status){const t=Math.round(100*(e.progress??0));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.tileOverlayText,{color:F.colors["on-scrim"]}],children:`${t}%`}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileProgressFill,{width:`${t}%`,backgroundColor:F.colors.primary}]})})]})}return"done"===e.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.doneBadge,{backgroundColor:F.colors.success}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.doneBadgeText,{color:F.colors["on-success"]}],children:"✓"})}):null},renderThumbnail=e=>{const t=imageSourceOf(e);return t?(0,_jsxRuntime.jsx)(_reactNative.Image,{source:{uri:t},style:w.thumbnailImage}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.extensionTile,{backgroundColor:F.colors["bg-subtle"]}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.extensionText,{color:F.colors["text-muted"],...(0,_index2.fontFor)(F,"semibold")}],children:extensionOf(e.name)})})},removeButton=e=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(e.name),style:[w.removeButton,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.removeButtonText,{color:F.colors["on-scrim"]}],children:"×"})}),retryButton=e=>R&&"error"===e.status?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>R(e),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.retry,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.retryText,{color:F.colors.primary}],children:"↻"})}):null,renderOneFile=(e,t)=>{const r={file:e,index:t,disabled:h,remove:()=>D(e),retry:R?()=>R(e):void 0},i=x?x(r):"card"===u?(e=>{const{file:t}=e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.tile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border}],children:[renderThumbnail(t),renderStatusOverlay(t),"error"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:retryButton(t)}):null,removeButton(t)]})})(r):(e=>{const{file:t}=e,r=statusText(t);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listRow,{borderRadius:N,..._corners.smoothCorners,borderColor:"error"===t.status?F.colors.danger:F.colors.border,backgroundColor:F.colors.bg}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.listThumb,{borderRadius:F.radius.sm,..._corners.smoothCorners}],children:[renderThumbnail(t),"processing"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.tileOverlay,{backgroundColor:F.colors.scrim}],children:(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm"})}):null]}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.listTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,ellipsizeMode:"middle",style:[w.listName,{color:F.colors["text-body"],fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:t.name}),(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:[w.listSubtitle,{color:"error"===t.status?F.colors["danger-text"]:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:[formatFileSize(t.size),r].filter(Boolean).join(" · ")}),"uploading"===t.status?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressTrack,{backgroundColor:F.colors.border}],children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[w.listProgressFill,{width:`${Math.round(100*(t.progress??0))}%`,backgroundColor:F.colors.primary}]})}):null]}),retryButton(t),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>D(t),disabled:h,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:z.removeFile(t.name),children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.listRemoveText,{color:F.colors["text-subtle"]}],children:"×"})})]})})(r);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:v?()=>v(e):void 0,disabled:h||!v,accessibilityLabel:fileA11yLabel(e),children:i},e.id)},J={open:W,disabled:h||q,fileCount:k.length,atCapacity:q},dashedTrigger=e=>(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:K,accessibilityState:{disabled:h||q},"aria-disabled":h||q,style:({pressed:t})=>[w.trigger,e?w.triggerCompact:null,{borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:t?F.colors["surface-pressed"]:F.colors.bg,opacity:h||q?.55:1}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:w.triggerRow,children:[Y?Y({size:16,color:F.colors.primary}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.triggerText,{color:F.colors.primary,fontSize:F.text.sm.size,...(0,_index2.fontFor)(F,"medium")}],children:0===k.length?z.trigger:z.addMore})]}),!e&&g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.helperText,{color:F.colors["text-subtle"],fontSize:F.text.xs.size}],children:g}):null]}),Q=(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>W(),disabled:h||q,accessibilityRole:"button",accessibilityLabel:z.addMore,style:({pressed:e})=>[w.tile,w.addTile,{width:84,height:84,borderRadius:N,..._corners.smoothCorners,borderColor:P,backgroundColor:e?F.colors["surface-pressed"]:"transparent",opacity:h||q?.55:1}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[w.addTileText,{color:F.colors.primary}],children:"+"})});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[w.container,S],testID:C,accessibilityLabel:K,children:["card"===u?0===k.length?m?m(J):dashedTrigger(!1):(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!1,contentContainerStyle:[w.strip,{columnGap:F.space.sm}],children:[k.map(renderOneFile),m?m(J):q||h?null:Q]}):(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{rowGap:F.space.sm},children:[m?m(J):q?null:dashedTrigger(k.length>0),k.map(renderOneFile)]}),(0,_index4.hasFieldText)($)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityLiveRegion:"polite",style:[w.errorText,{color:F.colors["danger-text"],fontSize:F.text.xs.size,marginTop:F.space.xxs}],children:$}):null,(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:L,onClose:()=>A(!1),title:z.sheetTitle,options:o,labelOf:e=>e.label,getValue:e=>e.key,disabledOf:()=>!1,descriptionOf:e=>e.description,iconOf:e=>e.icon,isSelected:()=>!1,onSelect:e=>{A(!1),E(e)}})]})});FilePicker.displayName="FilePicker";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},trigger:{borderWidth:1,borderStyle:"dashed",alignItems:"center",minHeight:48,paddingVertical:e.space.md,paddingHorizontal:e.space.lg},triggerCompact:{minHeight:40,paddingVertical:e.space.sm},triggerRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},triggerText:{includeFontPadding:!1},helperText:{includeFontPadding:!1,marginTop:e.space.xs,textAlign:"center"},strip:{paddingVertical:e.space.xxs},tile:{borderWidth:1,overflow:"hidden"},addTile:{borderStyle:"dashed",alignItems:"center",justifyContent:"center"},addTileText:{fontSize:e.text["3xl"].size,includeFontPadding:!1},thumbnailImage:{width:"100%",height:"100%",resizeMode:"cover"},extensionTile:{width:"100%",height:"100%",alignItems:"center",justifyContent:"center"},extensionText:{fontSize:e.text.sm.size,letterSpacing:1,includeFontPadding:!1},tileOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},tileOverlayText:{fontSize:e.text.sm.size,includeFontPadding:!1,marginBottom:e.space.xs},tileProgressTrack:{position:"absolute",left:8,right:8,bottom:8,height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden"},tileProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},doneBadge:{position:"absolute",right:4,bottom:4,width:18,height:18,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},doneBadgeText:{fontSize:e.text.xs.size,includeFontPadding:!1},removeButton:{position:"absolute",top:4,right:4,width:20,height:20,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center"},removeButtonText:{fontSize:e.text.sm.size,lineHeight:15,includeFontPadding:!1},retryText:{fontSize:e.text.xl.size,includeFontPadding:!1},listRow:{flexDirection:"row",alignItems:"center",borderWidth:1,padding:e.space.sm,columnGap:e.space.sm},listThumb:{width:40,height:40,overflow:"hidden"},listTextWrap:{flex:1},listName:{includeFontPadding:!1},listSubtitle:{includeFontPadding:!1,marginTop:e.space.xxs},listProgressTrack:{height:3,borderRadius:e.radius.pill,..._corners.smoothCorners,overflow:"hidden",marginTop:e.space.xs},listProgressFill:{height:"100%",borderRadius:e.radius.pill,..._corners.smoothCorners},listRemoveText:{fontSize:e.text["2xl"].size,includeFontPadding:!1,paddingHorizontal:e.space.xs},errorText:{includeFontPadding:!1}});var _default=exports.default=FilePicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.IconButton=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePressAnimation=require("../../hooks/usePressAnimation.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,s)=>{switch(s){case"secondary":return{base:e.colors.neutral,on:e.colors["on-neutral"],fg:e.colors.neutral};case"success":return{base:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"neutral":return{base:e.colors["bg-muted"],on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=exports.IconButton=(0,_react.forwardRef)((e,s)=>{const{icon:r,iconVariant:o,onPress:t,accessibilityLabel:n,tone:i="primary",variant:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.IconButton=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePressAnimation=require("../../hooks/usePressAnimation.js"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index3=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const GLASS_RIM_WIDTH=1,HIT_SLOP=6,SOFT_FILL_OPACITY=.14,SIZE_MAP={sm:{diameter:32,icon:16},md:{diameter:40,icon:20},lg:{diameter:48,icon:24}},toneFor=(e,s)=>{switch(s){case"secondary":return{base:e.colors.neutral,outline:e.colors.border,on:e.colors["on-neutral"],fg:e.colors.neutral};case"success":return{base:e.colors.success,outline:e.colors.success,on:e.colors["on-success"],fg:e.colors["success-text"]};case"warning":return{base:e.colors.warning,outline:e.colors.warning,on:e.colors["on-warning"],fg:e.colors["warning-text"]};case"danger":return{base:e.colors.danger,outline:e.colors.danger,on:e.colors["on-danger"],fg:e.colors["danger-text"]};case"neutral":return{base:e.colors["bg-muted"],outline:e.colors.border,on:e.colors["text-body"],fg:e.colors["text-body"]};default:return{base:e.colors.primary,outline:e.colors.primary,on:e.colors["on-primary"],fg:e.colors.primary}}},IconButton=exports.IconButton=(0,_react.forwardRef)((e,s)=>{const{icon:r,iconVariant:o,onPress:t,accessibilityLabel:n,tone:i="primary",variant:c="solid",size:l="md",shape:a="circle",active:d=!1,disabled:u=!1,loading:b=!1,haptic:_,style:m,testID:g}=e,p=(0,_index.useTheme)(),x=SIZE_MAP[l],y=u||b,{style:I,pressIn:f,pressOut:h}=(0,_usePressAnimation.usePressAnimation)({scaleTo:.92,enabled:!y}),{base:j,outline:S,on:P,fg:v}=toneFor(p,i),q=d?"solid":c;let A="transparent",w="transparent",R=0,O=y?p.colors["text-disabled"]:v;"solid"===q?(A=y?p.colors["surface-disabled"]:j,O=y?p.colors["text-disabled"]:P):"soft"===q?A=y?p.colors["surface-disabled"]:(0,_color.tintOf)(j,.14,p.colors["bg-subtle"]):"outline"===q?(w=y?p.colors.border:S,R=p.size.border):"glass"===q&&(A=p.colors["glass-fill"],w=p.colors["glass-border"],R=1,O=y?p.colors["text-disabled"]:p.colors["on-glass"]);const B={color:O,size:x.icon,disabled:y},C="circle"===a?x.diameter/2:p.radius.md;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{ref:s,onPress:e=>{if(y)return;const s=(0,_index2.resolveHaptic)(_,"selection");s&&(0,_index2.triggerHaptic)(s),t?.(e)},onPressIn:f,onPressOut:h,disabled:y,accessibilityRole:"button",accessibilityLabel:n,accessibilityState:{disabled:y,selected:d},"aria-disabled":y,"aria-selected":d,hitSlop:6,...(0,_hitSlop.hitSlopMarker)(6),testID:g,style:({pressed:e})=>[styles.base,{width:x.diameter,height:x.diameter,borderRadius:C,..._corners.smoothCorners,backgroundColor:A,borderColor:w,borderWidth:R,opacity:e&&"solid"!==q?.7:1},m],children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[styles.content,I],children:b?(0,_jsxRuntime.jsx)(_index3.Spinner,{size:"sm",color:O}):(0,_slotIcon.renderSlotIcon)(r,B,o)})})});IconButton.displayName="IconButton";const styles=_reactNative.StyleSheet.create({base:{alignItems:"center",justifyContent:"center"},content:{alignItems:"center",justifyContent:"center"}});var _default=exports.default=IconButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_index4=require("../Skeleton/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,r=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=r&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?r(n,i,a):n[i]=e[i]);return n}const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:i=!0,enableLightbox:r=!0,enablePinchZoom:n=!0,onIndexChange:l,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d})=>{const m=(0,_index.useTheme)(),_=(0,_react.useMemo)(()=>buildStyles(m),[m]),[h,g]=(0,_react.useState)(clamp(t,0,Math.max(0,e.length-1))),[v,x]=(0,_react.useState)(!1),p=(0,_react.useCallback)(e=>{g(e),l?.(e)},[l]),b=(0,_react.useCallback)(()=>{if(!r)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),x(!0)},[r,s]),R=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),x(!1)},[s]),N=(0,_react.useCallback)((t,a)=>{const i=t.alt??`Image ${a+1} of ${e.length}`;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:b,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:r?"Tap to open fullscreen":void 0,style:_.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:t.source,style:_.image,resizeMode:"cover"})})},[r,e.length,b,_]),S=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:_.thumbnailImage,resizeMode:"cover"}),[_]),y=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[_.container,u],testID:d,accessibilityLabel:c??"Image gallery",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.carouselWrap,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:t,onIndexChange:p,renderItem:N,showPagination:!1,showThumbnails:a,renderThumbnail:S,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[_.counterText,{color:m.colors["on-scrim"]}],accessibilityLabel:`Image ${h+1} of ${e.length}`,children:`${h+1} / ${e.length}`})}):null]}),r?(0,_jsxRuntime.jsx)(Lightbox,{visible:v,images:e,initialIndex:h,enablePinchZoom:n,showCounter:i,onClose:R,onIndexChange:p,haptic:s}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:i,containerStyle:u,testID:d}):y};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:i,testID:r})=>{const n=(0,_index.useTheme)(),l=Math.min(e?.length||4,6);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:n.space.md},children:Array.from({length:l}).map((e,t)=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:n.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({visible:e,images:t,initialIndex:a,enablePinchZoom:i,showCounter:r,onClose:n,onIndexChange:l,haptic:s})=>{const o=(0,_index.useTheme)(),c=(0,_react.useMemo)(()=>buildLightboxStyles(o),[o]),u=(0,_react.useRef)(null),[d,m]=(0,_react.useState)(a),_=(0,_react.useCallback)(e=>{if(e!==d){const t=(0,_index2.resolveHaptic)(s,"selection");t&&(0,_index2.triggerHaptic)(t),m(e),l(e)}},[d,l,s]),h=(0,_react.useCallback)((e,a)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s}),[d,i,t.length,s]),g=t[d]?.caption;return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:e,transparent:!0,statusBarTranslucent:!0,presentationStyle:"overFullScreen",animationType:"fade",onRequestClose:n,accessibilityViewIsModal:!0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:c.backdrop,accessibilityViewIsModal:!0,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:u,data:t,defaultIndex:a,onIndexChange:_,renderItem:h,showPagination:!1,haptic:s}),r&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:c.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[c.counterText,{color:o.colors["on-scrim"]}],accessibilityLabel:`Image ${d+1} of ${t.length}`,children:`${d+1} / ${t.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:n,accessibilityRole:"button",accessibilityLabel:"Close gallery",style:c.closeButton,hitSlop:12,children:(o.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:o.colors["on-scrim"]})}),g?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:c.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:c.captionText,numberOfLines:3,children:g})}):null,(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})},ZoomableImage=({image:e,index:t,total:a,active:i,enabled:r,maxScale:n,minScale:l,doubleTapScale:s,haptic:o})=>{const c=_reactNative.Dimensions.get("window"),u=(0,_reactNativeReanimated.useSharedValue)(1),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(0),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_react.useCallback)(()=>{u.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),d.value=1,m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=0,g.value=0},[u,d,m,_,h,g]);_react.default.useEffect(()=>{i||(u.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),m.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),d.value=1,h.value=0,g.value=0)},[i,u,m,_,d,h,g]);const x=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),p=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pinch().enabled(r).onStart(()=>{"worklet";d.value=u.value}).onUpdate(e=>{"worklet";const t=d.value*e.scale;u.value=t<l?l+.3*(t-l):t>n?n+.2*(t-n):t}).onEnd(()=>{"worklet";return u.value<l?(u.value=(0,_reactNativeReanimated.withSpring)(l,SPRING_CONFIG),m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),d.value=l,h.value=0,void(g.value=0)):u.value>n?(u.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(d.value=n)):void(d.value=u.value)}),[r,u,d,m,_,h,g,l,n]),b=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";h.value=m.value,g.value=_.value}).onUpdate(e=>{"worklet";u.value<=1||(m.value=h.value+e.translationX,_.value=g.value+e.translationY)}).onEnd(()=>{"worklet";h.value=m.value,g.value=_.value}),[u,m,_,h,g]),R=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onEnd(()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(x)(),u.value>1?(u.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),d.value=1,h.value=0,g.value=0):(u.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),d.value=s)}),[u,d,m,_,h,g,x,s]),N=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Race(p,b,R),[p,b,R]),S=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:m.value},{translateY:_.value},{scale:u.value}]}));_react.default.useEffect(()=>{i||v()},[i,v]);const y=e.alt??`Image ${t+1} of ${a}`;return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:N,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:c.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,S],accessibilityLabel:y,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,..._corners.smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"},counterText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}}),buildLightboxStyles=e=>_reactNative.StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},counterText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:"#FFFFFF",fontSize:e.text.base.size,lineHeight:21,textAlign:"center"}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ImageGallery=void 0;var cache,_react=_interopRequireWildcard(require("react")),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated")),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_index3=require("../Carousel/index.js"),_index4=require("../Skeleton/index.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,i,r=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(i in e)"default"!==i&&{}.hasOwnProperty.call(e,i)&&((a=r&&Object.getOwnPropertyDescriptor(e,i))&&(a.get||a.set)?r(n,i,a):n[i]=e[i]);return n}const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:i=!0,enableLightbox:r=!0,enablePinchZoom:n=!0,onIndexChange:l,haptic:s,loading:o=!1,accessibilityLabel:c,containerStyle:u,testID:d})=>{const m=(0,_index.useTheme)(),_=(0,_react.useMemo)(()=>buildStyles(m),[m]),[h,g]=(0,_react.useState)(clamp(t,0,Math.max(0,e.length-1))),[v,x]=(0,_react.useState)(!1),p=(0,_react.useCallback)(e=>{g(e),l?.(e)},[l]),b=(0,_react.useCallback)(()=>{if(!r)return;const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),x(!0)},[r,s]),R=(0,_react.useCallback)(()=>{const e=(0,_index2.resolveHaptic)(s,"selection");e&&(0,_index2.triggerHaptic)(e),x(!1)},[s]),S=(0,_react.useCallback)((t,a)=>{const i=t.alt??`Image ${a+1} of ${e.length}`;return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:b,accessibilityRole:"image",accessibilityLabel:i,accessibilityHint:r?"Tap to open fullscreen":void 0,style:_.imageWrap,children:(0,_jsxRuntime.jsx)(_reactNative.Image,{source:t.source,style:_.image,resizeMode:"cover"})})},[r,e.length,b,_]),N=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNative.Image,{source:e.source,style:_.thumbnailImage,resizeMode:"cover"}),[_]),y=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[_.container,u],testID:d,accessibilityLabel:c??"Image gallery",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_.carouselWrap,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{data:e,defaultIndex:t,onIndexChange:p,renderItem:S,showPagination:!1,showThumbnails:a,renderThumbnail:N,haptic:s}),i&&e.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:_.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[_.counterText,{color:m.colors["on-scrim"]}],accessibilityLabel:`Image ${h+1} of ${e.length}`,children:`${h+1} / ${e.length}`})}):null]}),r?(0,_jsxRuntime.jsx)(Lightbox,{visible:v,images:e,initialIndex:h,enablePinchZoom:n,showCounter:i,onClose:R,onIndexChange:p,haptic:s}):null]});return o?(0,_jsxRuntime.jsx)(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:i,containerStyle:u,testID:d}):y};exports.ImageGallery=ImageGallery,ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:i,testID:r})=>{const n=(0,_index.useTheme)(),l=Math.min(e?.length||4,6);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:"100%"},i],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:"100%",height:280,radius:"lg"}),a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:"absolute",top:12,right:12},children:(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",marginTop:n.space.md},children:Array.from({length:l}).map((e,t)=>(0,_jsxRuntime.jsx)(_index4.Skeleton,{width:64,height:64,radius:"md",style:{marginRight:n.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({visible:e,images:t,initialIndex:a,enablePinchZoom:i,showCounter:r,onClose:n,onIndexChange:l,haptic:s})=>{const o=(0,_index.useTheme)(),c=(0,_react.useMemo)(()=>buildLightboxStyles(o),[o]),u=(0,_react.useRef)(null),[d,m]=(0,_react.useState)(a),_=(0,_react.useCallback)(e=>{if(e!==d){const t=(0,_index2.resolveHaptic)(s,"selection");t&&(0,_index2.triggerHaptic)(t),m(e),l(e)}},[d,l,s]),h=(0,_react.useCallback)((e,a)=>(0,_jsxRuntime.jsx)(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:i,maxScale:4,minScale:1,doubleTapScale:2,haptic:s}),[d,i,t.length,s]),g=t[d]?.caption;return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:e,transparent:!0,statusBarTranslucent:!0,presentationStyle:"overFullScreen",animationType:"fade",onRequestClose:n,accessibilityViewIsModal:!0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:c.backdrop,accessibilityViewIsModal:!0,children:[(0,_jsxRuntime.jsx)(_index3.Carousel,{ref:u,data:t,defaultIndex:a,onIndexChange:_,renderItem:h,showPagination:!1,haptic:s}),r&&t.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:c.counterPill,pointerEvents:"none",children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[c.counterText,{color:o.colors["on-scrim"]}],accessibilityLabel:`Image ${d+1} of ${t.length}`,children:`${d+1} / ${t.length}`})}):null,(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:n,accessibilityRole:"button",accessibilityLabel:"Close gallery",style:c.closeButton,hitSlop:12,...(0,_hitSlop.hitSlopMarker)(12),children:(o.settings.icons.close??_defaultIcons.defaultIcons.close)({size:24,color:o.colors["on-scrim"]})}),g?(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:c.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:c.captionText,numberOfLines:3,children:g})}):null,(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})},ZoomableImage=({image:e,index:t,total:a,active:i,enabled:r,maxScale:n,minScale:l,doubleTapScale:s,haptic:o})=>{const c=_reactNative.Dimensions.get("window"),u=(0,_reactNativeReanimated.useSharedValue)(1),d=(0,_reactNativeReanimated.useSharedValue)(1),m=(0,_reactNativeReanimated.useSharedValue)(0),_=(0,_reactNativeReanimated.useSharedValue)(0),h=(0,_reactNativeReanimated.useSharedValue)(0),g=(0,_reactNativeReanimated.useSharedValue)(0),v=(0,_react.useCallback)(()=>{u.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),d.value=1,m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),h.value=0,g.value=0},[u,d,m,_,h,g]);_react.default.useEffect(()=>{i||(u.value=(0,_reactNativeReanimated.withTiming)(1,{duration:150}),m.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),_.value=(0,_reactNativeReanimated.withTiming)(0,{duration:150}),d.value=1,h.value=0,g.value=0)},[i,u,m,_,d,h,g]);const x=(0,_react.useCallback)(()=>{!1!==o&&(0,_index2.triggerHaptic)("impactLight")},[o]),p=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pinch().enabled(r).onStart(()=>{"worklet";d.value=u.value}).onUpdate(e=>{"worklet";const t=d.value*e.scale;u.value=t<l?l+.3*(t-l):t>n?n+.2*(t-n):t}).onEnd(()=>{"worklet";return u.value<l?(u.value=(0,_reactNativeReanimated.withSpring)(l,SPRING_CONFIG),m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),d.value=l,h.value=0,void(g.value=0)):u.value>n?(u.value=(0,_reactNativeReanimated.withSpring)(n,SPRING_CONFIG),void(d.value=n)):void(d.value=u.value)}),[r,u,d,m,_,h,g,l,n]),b=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";h.value=m.value,g.value=_.value}).onUpdate(e=>{"worklet";u.value<=1||(m.value=h.value+e.translationX,_.value=g.value+e.translationY)}).onEnd(()=>{"worklet";h.value=m.value,g.value=_.value}),[u,m,_,h,g]),R=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onEnd(()=>{"worklet";(0,_reactNativeReanimated.runOnJS)(x)(),u.value>1?(u.value=(0,_reactNativeReanimated.withSpring)(1,SPRING_CONFIG),m.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),_.value=(0,_reactNativeReanimated.withSpring)(0,SPRING_CONFIG),d.value=1,h.value=0,g.value=0):(u.value=(0,_reactNativeReanimated.withSpring)(s,SPRING_CONFIG),d.value=s)}),[u,d,m,_,h,g,x,s]),S=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Race(p,b,R),[p,b,R]),N=(0,_reactNativeReanimated.useAnimatedStyle)(()=>({transform:[{translateX:m.value},{translateY:_.value},{scale:u.value}]}));_react.default.useEffect(()=>{i||v()},[i,v]);const y=e.alt??`Image ${t+1} of ${a}`;return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:S,children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.View,{style:[lightboxImageStyles.container,{width:c.width}],children:(0,_jsxRuntime.jsx)(_reactNativeReanimated.default.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,N],accessibilityLabel:y,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,..._corners.smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"},counterText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold}}),buildLightboxStyles=e=>_reactNative.StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,..._corners.smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},counterText:{fontSize:e.text.sm.size,fontWeight:e.weight.semibold},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,..._corners.smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:"#FFFFFF",fontSize:e.text.base.size,lineHeight:21,textAlign:"center"}}),lightboxImageStyles=_reactNative.StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});var _default=exports.default=ImageGallery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.InlineSelect=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_Chevron=require("../FieldBase/Chevron.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_jsxRuntime=require("react/jsx-runtime");const InlineSelect=exports.InlineSelect=(0,_react.forwardRef)((e,t)=>{const{options:i,getOptionLabel:l,getOptionValue:s,getOptionDisabled:a,getOptionDescription:r,getOptionIcon:n,value:c,onChange:o,placeholder:d,label:u,title:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.InlineSelect=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_index2=require("../../utils/index.js"),_hitSlop=require("../../utils/hitSlop.js"),_Chevron=require("../FieldBase/Chevron.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_OptionSheet=require("../OptionSheet/OptionSheet.js"),_jsxRuntime=require("react/jsx-runtime");const InlineSelect=exports.InlineSelect=(0,_react.forwardRef)((e,t)=>{const{options:i,getOptionLabel:l,getOptionValue:s,getOptionDisabled:a,getOptionDescription:r,getOptionIcon:n,value:c,onChange:o,placeholder:d,label:u,title:p,searchable:x=!1,haptic:_,disabled:b=!1,size:S="md",color:h,chevronColor:y,chevronSize:j,textStyle:m,style:g,optionStyle:v,selectedOptionStyle:O,optionTextStyle:f,selectedOptionTextStyle:C,accessibilityLabel:I,testID:R}=e,k=(0,_index.useTheme)(),F=(0,_react.useMemo)(()=>buildStyles(k),[k]),q=(0,_index.resolveFieldSize)(k,S),T=(0,_react.useCallback)(e=>l?l(e):e.label??"",[l]),N=(0,_react.useCallback)(e=>s?s(e):e.value,[s]),z=(0,_react.useCallback)(e=>a?a(e):!0===e.disabled,[a]),L=(0,_react.useCallback)(e=>r?r(e):e.description,[r]),B=(0,_react.useCallback)(e=>n?n(e):e.icon,[n]),[D,H]=(0,_react.useState)(!1),M=(0,_react.useMemo)(()=>{if(null!=c)return i.find(e=>N(e)===c)},[i,c,N]),P=(0,_react.useCallback)(e=>c===e,[c]),w=(0,_react.useCallback)(()=>{if(b)return;const e=(0,_index2.resolveHaptic)(_,"selection");e&&(0,_index2.triggerHaptic)(e),H(!0)},[b,_]),V=(0,_react.useCallback)(()=>{H(!1)},[]),$=(0,_react.useCallback)(e=>{if(z(e))return;const t=(0,_index2.resolveHaptic)(_,"selection");t&&(0,_index2.triggerHaptic)(t),o(N(e)),V()},[z,N,o,V,_]),G=b?k.colors["text-disabled"]:h??k.colors.primary,A=void 0!==M?T(M):d??"Select",E=void 0!==M?`Selected: ${T(M)}`:d??"No selection",J=I??`${u??p??"Select"}. ${E}`,K=(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:t,onPress:w,disabled:b,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:J,accessibilityState:{disabled:b,expanded:D},"aria-disabled":b,"aria-expanded":D,testID:R,style:({pressed:e})=>[F.trigger,{columnGap:k.space.xs,opacity:e&&!b?.6:1},g],children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[F.triggerText,{color:G,fontSize:q.text,...(0,_index.fontFor)(k,"medium")},m],numberOfLines:1,children:A}),(0,_jsxRuntime.jsx)(_Chevron.Chevron,{color:y??G,size:j??q.icon,open:D})]});return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[u?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:F.labelled,children:[(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:S,children:u}),K]}):K,(0,_jsxRuntime.jsx)(_OptionSheet.OptionSheet,{open:D,onClose:V,title:p,accessibilityLabel:u??p??d??"Options",options:i,labelOf:T,getValue:N,disabledOf:z,descriptionOf:L,iconOf:B,isSelected:P,onSelect:$,searchable:x,optionStyle:v,selectedOptionStyle:O,optionTextStyle:f,selectedOptionTextStyle:C})]})});InlineSelect.displayName="InlineSelect";const buildStyles=e=>_reactNative.StyleSheet.create({labelled:{alignItems:"flex-start"},trigger:{flexDirection:"row",alignItems:"center"},triggerText:{includeFontPadding:!1}});var _default=exports.default=InlineSelect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_Notation=require("../Notation/Notation.js"),_jsxRuntime=require("react/jsx-runtime");const Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:o,onChangeText:s,error:r,helperText:l,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:f,rightIcon:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Input=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_slotIcon=require("../AppIcon/slotIcon.js"),_index4=require("../Button/index.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_useFloatingLabel=require("../FieldBase/useFloatingLabel.js"),_Notation=require("../Notation/Notation.js"),_jsxRuntime=require("react/jsx-runtime");const Input=exports.Input=(0,_react.forwardRef)((e,t)=>{const{label:i,help:n,placeholder:a,value:o,onChangeText:s,error:r,helperText:l,type:d="input",secureTextEntry:c=!1,showPasswordToggle:u=!1,disabled:x=!1,multiline:p=!1,leftIcon:f,rightIcon:_,unit:g,unitStyle:m,prefix:h,prefixStyle:v,readOnly:j=!1,action:y,actionStyle:b,size:N="md",variant:R,labelMode:S,required:w=!1,maxLength:F,showCounter:I=!0,textAlign:T,format:V,parse:A,style:B,containerStyle:z,inputStyle:q,labelStyle:k,messageStyle:C,borderRadius:L,onFocus:D,onBlur:P,accessibilityLabel:H,testID:M,editable:O,...E}=e,G=(0,_index2.useTheme)(),W=(0,_react.useMemo)(()=>buildStyles(G),[G]),$=(0,_index2.resolveFieldSize)(G,N),X=G.components.input[N]["multiline-min-height"],J=Math.round($.text*G.leading.body),K=R??G.settings.components.input?.defaultVariant??G.settings.components.field?.defaultVariant??"outlined",Q=S??G.settings.components.input?.defaultLabelMode??"top",[U,Y]=(0,_react.useState)(!1),[Z,ee]=(0,_react.useState)(!1),te="password"===d||u||c,ie="password"===d||u,ne="textarea"===d||p,ae=ne?Math.round(.1*$.text):0,oe="string"==typeof o&&o.length>0,se=(0,_FieldBase.hasFieldText)(r),re=!0===r||se,le=(0,_FieldBase.hasFieldText)(l),de=se||!re&&le,ce=(0,_FieldBase.hasFieldText)(i),ue=(0,_FieldBase.hasFieldText)(h),xe=!x&&!1!==O,pe=U||oe||ue,fe=(0,_react.useRef)(null),ge=(0,_react.useMemo)(()=>(0,_index3.mergeRefs)(fe,t),[t]),me=(0,_react.useCallback)(()=>{xe&&fe.current?.focus()},[xe]),he=ce&&"float"===Q,ve=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,je=(0,_react.useRef)((0,_index2.createAnimatedValue)(de?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.timing(je,{toValue:de?1:0,duration:G.motion.duration.fast,easing:_reactNative.Easing.bezier(...G.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[de,je,G.motion.duration.fast,G.motion.ease["in-out"]]);const ye=(0,_index.useReducedMotion)(),be=G.settings.components.input?.shakeOnError??!1,Ne=(0,_react.useRef)(re);(0,_react.useEffect)(()=>{if(!be)return void(Ne.current=re);let e;return re&&!Ne.current&&(ye||((0,_index2.setNativeValue)(ve,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(ve,{toValue:1,duration:50,useNativeDriver:!0}),_reactNative.Animated.timing(ve,{toValue:-1,duration:50,useNativeDriver:!0}),_reactNative.Animated.timing(ve,{toValue:1,duration:50,useNativeDriver:!0}),_reactNative.Animated.timing(ve,{toValue:-1,duration:50,useNativeDriver:!0}),_reactNative.Animated.timing(ve,{toValue:0,duration:100,useNativeDriver:!0})]),e.start()),(0,_index3.triggerHaptic)("notificationError")),Ne.current=re,()=>e?.stop()},[re,ve,be,ye]);const Re=(0,_react.useCallback)(e=>{Y(!0),D?.(e)},[D]),Se=(0,_react.useCallback)(e=>{Y(!1),P?.(e)},[P]),we=(0,_react.useCallback)(()=>{(0,_index3.triggerHaptic)("selection"),ee(e=>!e)},[]),Fe=G.colors["field-caret"],Ie=L??$.radius,Te=G.settings.components.input?.tintLabelOnFocus??!1,Ve=U&&Te?G.colors["field-border-focus"]:G.colors["field-label"],Ae=ve.interpolate({inputRange:[-1,0,1],outputRange:[-6,0,6]}),Be=Boolean(_)||Boolean(g)||ie,ze="underline"===K,qe=f?$.icon+G.space.md+1+G.space.md:0,ke=(0,_useFloatingLabel.useFloatingLabel)({label:i,enabled:he,floated:pe,required:w,variant:K,sizeTokens:$,leadingOffset:qe,trailingOffset:Be?$.icon+G.space.sm:0,textAlign:T,paddingLeft:ze?G.space.none:$["padding-x"],lineHeight:ne?J:void 0,restNudge:ae,floatTrim:ne?2:0,color:Ve,style:k}),Ce=(0,_FieldBase.resolveFieldTextStyle)(G,{disabled:x}),Le=Ce.color,De=Ce.placeholderColor,Pe=w&&!ce&&!oe&&"string"==typeof a&&a.length>0,He=re?r:l,Me=I&&"number"==typeof F&&"string"==typeof o?`${o.length} / ${F}`:null,Oe=re?G.colors["field-message"]:G.colors["text-muted"],Ee=(0,_Notation.useNotationInk)(C,$["message-text"],Oe),Ge=H??(0,_FieldBase.fieldTextAsString)(i)??a,We=x?G.colors["field-icon-disabled"]:U?G.colors["field-icon-focus"]:G.colors["field-icon"],$e={focused:U,disabled:x,error:re,color:We,size:$.icon},renderSlot=e=>(0,_slotIcon.renderSlotIcon)(e,$e),Xe=(()=>{if(ie){const e=(Z?G.settings.icons.eyeOff:G.settings.icons.eye)??(Z?_defaultIcons.defaultIcons.eyeOff:_defaultIcons.defaultIcons.eye);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:we,disabled:!xe,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:Z?"Hide password":"Show password",children:e({size:$.icon,color:We})})}const e=g?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[W.unit,{fontSize:$.text,color:De},m],children:g}):null,t=_?(0,_jsxRuntime.jsx)(_reactNative.View,{children:renderSlot(_)}):null;return e&&t?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:W.trailingRow,children:[e,t]}):e??t})(),Je=f?(0,_jsxRuntime.jsx)(_reactNative.View,{children:renderSlot(f)}):null,Ke=_reactNative.StyleSheet.flatten(v),Qe=Ke?.fontSize??$.text,Ue=Ke?.color??De,Ye=(0,_react.useMemo)(()=>({fontSize:Qe,color:Ue}),[Qe,Ue]),Ze=ue?"string"==typeof h||"number"==typeof h?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[W.prefix,{fontSize:$.text,color:De,marginRight:G.space.xs,lineHeight:ne?J:void 0,paddingTop:ne?ae:void 0},v],children:h}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[W.prefixNode,{marginRight:G.space.xs,minHeight:ne?J:void 0,justifyContent:"center",paddingTop:ne?ae:void 0}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[W.prefix,{fontSize:$.text,color:De,lineHeight:ne?J:void 0},v],children:(0,_jsxRuntime.jsx)(_Notation.NotationInkContext.Provider,{value:Ye,children:h})})}):null,et=y?(0,_jsxRuntime.jsx)(_index4.Button,{variant:y.variant??"outline",tone:y.tone??"primary",size:N,title:y.label,leftIcon:y.icon,loading:y.loading,disabled:x||y.disabled,onPress:y.onPress,pressAnimation:!1,testID:y.testID,style:[W.action,{minHeight:$["min-height"],alignSelf:ne?"flex-start":"stretch"},b]}):null;return(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[W.container,{transform:[{translateX:Ae}]},B],children:[ce&&!he?(0,_jsxRuntime.jsx)(_FieldBase.FieldLabel,{size:N,required:w,help:n,color:Ve,style:k,children:i}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[W.fieldRow,{columnGap:G.space.sm,alignItems:ne?"flex-start":"stretch"}],children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:W.fieldWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:N,variant:K,focused:U,disabled:x,error:re,filled:oe,minHeight:ne?X:void 0,borderRadius:Ie,leading:Je,leadingDivider:null!=f,paddingLeft:ze?G.space.none:void 0,trailing:Xe,slotAlign:ne?"top":"center",slotLineHeight:ne?J:void 0,topNotch:ke.topNotch,onPress:me,pressFeedback:!1,style:z,children:[Ze,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:W.inputWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:ge,style:[W.input,{color:Le,fontSize:$.text,...Ce.weightStyle,paddingLeft:ze?G.space.none:void 0,minHeight:ne?X-2*$["padding-y"]:void 0,lineHeight:ne?J:void 0,paddingTop:ne?ae:void 0,textAlignVertical:ne?"top":"center"},q],textAlign:T,placeholder:he&&!pe||Pe?void 0:a,placeholderTextColor:De,value:V&&null!=o?V(o):o,onChangeText:e=>{s&&s(A?A(e):e)},onFocus:Re,onBlur:Se,editable:xe,readOnly:j,secureTextEntry:te&&!Z,multiline:ne,autoCapitalize:te?"none":void 0,autoCorrect:!te&&void 0,maxLength:F,selectionColor:Fe,accessibilityLabel:Ge,accessibilityState:{disabled:x},"aria-disabled":x,testID:M,...E}),Pe?(0,_jsxRuntime.jsx)(_FieldBase.RequiredPlaceholder,{text:a,color:De,fontSize:$.text,weightStyle:Ce.weightStyle,align:ne?"top":"center",paddingTop:ne?ae:void 0,textAlign:T}):null]})]}),ke.node]}),et]}),de||Me?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[W.footerRow,{marginTop:$["message-gap"]}],children:[de?(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[W.messageRow,{columnGap:G.space.xs,opacity:je}],accessibilityLiveRegion:re?"polite":"none",children:[re?(0,_jsxRuntime.jsx)(_FieldBase.FieldErrorGlyph,{size:$["message-text"],color:Oe}):null,(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[W.messageText,{color:Oe,fontSize:$["message-text"],...(0,_index2.fontFor)(G,"normal")},C],children:(0,_jsxRuntime.jsx)(_Notation.NotationInkContext.Provider,{value:Ee,children:He})})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:W.footerSpacer}),Me?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[W.counterText,{color:G.colors["text-subtle"],fontSize:$["message-text"],...(0,_index2.fontFor)(G,"normal")}],children:Me}):null]}):null]})});Input.displayName="Input";const buildStyles=e=>_reactNative.StyleSheet.create({container:{width:"100%"},fieldRow:{flexDirection:"row"},fieldWrapper:{position:"relative",overflow:"visible",flex:1},action:{flexShrink:0},input:{padding:e.space.none,margin:e.space.none,includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},inputWrap:{flex:1,alignSelf:"stretch",justifyContent:"center"},unit:{includeFontPadding:!1},trailingRow:{flexDirection:"row",alignItems:"center",columnGap:e.space.sm},footerRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",columnGap:e.space.sm},footerSpacer:{flex:1},messageRow:{flex:1,flexDirection:"row",alignItems:"center"},messageText:{flexShrink:1,includeFontPadding:!1},counterText:{flexShrink:0,includeFontPadding:!1}});var _default=exports.default=Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.KeyboardToolbar=void 0;var _reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_FormContext=require("../../form/FormContext.js"),_index=require("../../theme/index.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NavButton=({label:e,accessibilityLabel:t,onPress:r,theme:o})=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:t,hitSlop:8,style:{paddingHorizontal:o.space.sm},children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",size:"lg",color:"link",children:e})}),KeyboardToolbar=e=>{const{doneLabel:t="Done",showNavigation:r=!0,onDone:o,onNext:i,onPrev:s,leading:a,style:l,testID:n}=e,c=(0,_index.useTheme)(),b=(0,_FormContext.useOptionalFormContext)();if(!(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.isVisible))return null;const d=o??(()=>{_reactNativeKeyboardController.KeyboardController.dismiss()}),x=s??b?.focusPrev??(()=>_reactNativeKeyboardController.KeyboardController.setFocusTo("prev")),u=i??b?.focusNext??(()=>_reactNativeKeyboardController.KeyboardController.setFocusTo("next"));return(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardStickyView,{style:styles.anchor,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:n,accessibilityRole:"toolbar",style:[styles.bar,{backgroundColor:c.colors.surface,borderTopColor:c.colors.border,paddingHorizontal:c.space.md},l],children:[r?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.nav,children:[(0,_jsxRuntime.jsx)(NavButton,{label:"‹",accessibilityLabel:"Previous field",onPress:x,theme:c}),(0,_jsxRuntime.jsx)(NavButton,{label:"›",accessibilityLabel:"Next field",onPress:u,theme:c})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{}),a,(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.spacer}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:d,accessibilityRole:"button",accessibilityLabel:t,hitSlop:8,children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",color:"link",children:t})})]})})};exports.KeyboardToolbar=KeyboardToolbar;const styles=_reactNative.StyleSheet.create({anchor:{position:"absolute",left:0,right:0,bottom:0},bar:{height:44,flexDirection:"row",alignItems:"center",borderTopWidth:_reactNative.StyleSheet.hairlineWidth},nav:{flexDirection:"row",alignItems:"center"},spacer:{flex:1}});var _default=exports.default=KeyboardToolbar;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.KeyboardToolbar=void 0;var _reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_FormContext=require("../../form/FormContext.js"),_index=require("../../theme/index.js"),_hitSlop=require("../../utils/hitSlop.js"),_index2=require("../Text/index.js"),_jsxRuntime=require("react/jsx-runtime");const NavButton=({label:e,accessibilityLabel:t,onPress:r,theme:o})=>(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:r,accessibilityRole:"button",accessibilityLabel:t,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),style:{paddingHorizontal:o.space.sm},children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",size:"lg",color:"link",children:e})}),KeyboardToolbar=e=>{const{doneLabel:t="Done",showNavigation:r=!0,onDone:o,onNext:i,onPrev:s,leading:a,style:l,testID:n}=e,c=(0,_index.useTheme)(),b=(0,_FormContext.useOptionalFormContext)();if(!(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.isVisible))return null;const d=o??(()=>{_reactNativeKeyboardController.KeyboardController.dismiss()}),x=s??b?.focusPrev??(()=>_reactNativeKeyboardController.KeyboardController.setFocusTo("prev")),u=i??b?.focusNext??(()=>_reactNativeKeyboardController.KeyboardController.setFocusTo("next"));return(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardStickyView,{style:styles.anchor,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:n,accessibilityRole:"toolbar",style:[styles.bar,{backgroundColor:c.colors.surface,borderTopColor:c.colors.border,paddingHorizontal:c.space.md},l],children:[r?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.nav,children:[(0,_jsxRuntime.jsx)(NavButton,{label:"‹",accessibilityLabel:"Previous field",onPress:x,theme:c}),(0,_jsxRuntime.jsx)(NavButton,{label:"›",accessibilityLabel:"Next field",onPress:u,theme:c})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{}),a,(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.spacer}),(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:d,accessibilityRole:"button",accessibilityLabel:t,hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),children:(0,_jsxRuntime.jsx)(_index2.Text,{variant:"body",weight:"semibold",color:"link",children:t})})]})})};exports.KeyboardToolbar=KeyboardToolbar;const styles=_reactNative.StyleSheet.create({anchor:{position:"absolute",left:0,right:0,bottom:0},bar:{height:44,flexDirection:"row",alignItems:"center",borderTopWidth:_reactNative.StyleSheet.hairlineWidth},nav:{flexDirection:"row",alignItems:"center"},spacer:{flex:1}});var _default=exports.default=KeyboardToolbar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MESSAGE_LIST_LABELS=void 0,exports.MessageList=MessageList,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_corners=require("../../utils/corners.js"),_index2=require("../Badge/index.js"),_index3=require("../DateSeparator/index.js"),_index4=require("../IconButton/index.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_LIST_LABELS=exports.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"}),JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:JUMP_AT},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";function MessageList({messages:e,keyExtractor:t,renderMessage:n,getAuthorKey:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MESSAGE_LIST_LABELS=void 0,exports.MessageList=MessageList,exports.default=void 0;var _mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_useReducedMotion=require("../../hooks/useReducedMotion.js"),_index=require("../../theme/index.js"),_announce=require("../../utils/announce.js"),_corners=require("../../utils/corners.js"),_index2=require("../Badge/index.js"),_index3=require("../DateSeparator/index.js"),_index4=require("../IconButton/index.js"),_index5=require("../Spinner/index.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_MESSAGE_LIST_LABELS=exports.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"}),JUMP_AT=160,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:JUMP_AT},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";function MessageList({messages:e,keyExtractor:t,renderMessage:n,getAuthorKey:r,getDate:s,firstUnreadKey:a,onLoadOlder:o,loadingOlder:i=!1,hasOlder:l=!0,typing:u,empty:c,getAnnouncement:d,followNew:_,keyboardAware:m=!0,keyboardOffset:x,labels:p,now:j,onScroll:f,contentContainerStyle:y,style:g,testID:b,...S}){const v=(0,_index.useTheme)(),L=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),h=(0,_useReducedMotion.useReducedMotion)(),E=(0,_react.useMemo)(()=>buildStyles(v),[v]),R=(0,_react.useMemo)(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...p}),[p]),w=x??L.bottom,T=(0,_react.useRef)(null),A=(0,_react.useRef)(!1),[C,M]=(0,_react.useState)(!1),[I,N]=(0,_react.useState)(0),O=(0,_react.useMemo)(()=>{const n=s?e.map(e=>(0,_mobileCore.formatDate)(s(e))):null,o=r?e.map(r):null,i=void 0===a?-1:e.findIndex(e=>t(e)===a);return e.map((t,r)=>{const a=r===e.length-1,l=null!==n&&(a||n[r]!==n[r+1]),u=null!==o&&!a&&o[r+1]===o[r]&&!l&&r!==i,c=null!==o&&r>0&&o[r-1]===o[r]&&(null===n||n[r-1]===n[r])&&r-1!==i;return{groupPosition:positionOf(u,c),day:l&&s?(0,_index3.dayLabel)(s(t),{now:j,labels:R}):null,unread:r===i}})},[e,s,r,a,t,j,R]),k=(0,_react.useCallback)(()=>{T.current?.scrollToOffset({offset:0,animated:!h}),N(0)},[h]),q=e.length>0?t(e[0]):null,D=(0,_react.useRef)(q);(0,_react.useEffect)(()=>{const n=D.current;if(D.current=q,null===n||null===q||n===q)return;const r=e.findIndex(e=>t(e)===n);if(-1===r)return void N(0);const s=e.slice(0,r).reverse();for(const e of s){const t=d?.(e);t&&(0,_announce.announce)(t)}_&&s.some(_)?k():A.current&&N(e=>e+s.length)},[q]);const P=(0,_react.useCallback)(e=>{const t=e.nativeEvent.contentOffset.y>JUMP_AT;t!==A.current&&(A.current=t,M(t),t||N(0)),f?.(e)},[f]),V=(0,_react.useCallback)(()=>{l&&!i&&o?.()},[l,i,o]),F=(0,_react.useCallback)(({item:e,index:t})=>{const r=O[t];return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[r?.day?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:r.day}):null,r?.unread?(0,_jsxRuntime.jsx)(_index3.DateSeparator,{label:R.unread,emphasis:!0}):null,n({item:e,index:t,groupPosition:r?.groupPosition??"single"})]})},[O,R.unread,n]),B=(0,_react.useCallback)(e=>t(e),[t]),U=(0,_react.useCallback)(e=>(0,_jsxRuntime.jsx)(_reactNativeKeyboardController.KeyboardChatScrollView,{...e,inverted:!0,offset:w}),[w]),K=I>0?`${R.newMessages(I)}. ${R.jumpToLatest}`:R.jumpToLatest;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[E.root,g],children:[(0,_jsxRuntime.jsx)(_reactNative.FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...S,ref:T,data:e,renderItem:F,keyExtractor:B,inverted:!0,onScroll:P,onEndReached:o?V:void 0,ListHeaderComponent:u?(0,_jsxRuntime.jsx)(_reactNative.View,{children:u}):null,ListFooterComponent:i?(0,_jsxRuntime.jsx)(_index5.Spinner,{size:"sm",accessibilityLabel:R.loadingOlder,style:E.older}):null,ListEmptyComponent:c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.fill,children:c}):null,renderScrollComponent:m?U:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,y],testID:b}),C?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:E.jump,pointerEvents:"box-none",children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.jumpDisc,children:(0,_jsxRuntime.jsx)(_index4.IconButton,{icon:"arrow-down",accessibilityLabel:K,variant:"ghost",tone:"neutral",onPress:k,testID:b?`${b}-jump`:void 0})}),I>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:(0,_jsxRuntime.jsx)(_index2.Badge,{value:I,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>_reactNative.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,..._corners.smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});var _default=exports.default=MessageList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{const{visible:r,onRequestClose:a,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:o,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:f,onDismissed:p,haptic:v,testID:g}=e,b=(0,_index.useTheme)(),S=(0,_usePresenceMotion.usePresenceMotion)(),[h,x]=(0,_ModalSafeArea.useModalInsets)(),A=o??S.duration("default"),M=_reactNative.Dimensions.get("window").height,N=(0,_react.useRef)(!l&&r),R=N.current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:.9)).current,j=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(R?0:M)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,V=(0,_react.useRef)(null),D=(0,_react.useRef)(!1),[T,w]=(0,_react.useState)(r),I=(0,_react.useMemo)(()=>buildStyles(b),[b]),E=(0,_react.useMemo)(()=>{const e=b.colors.scrim;return"number"!=typeof s?e:(0,_color.withAlpha)(e,s)??e},[b.colors.scrim,s]),P=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(E),E]}),[C,E]);(0,_react.useEffect)(()=>{r&&w(!0)},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&T&&N.current)N.current=!1;else if(r&&T){const t=_reactNative.Animated.timing(C,{toValue:1,duration:S.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),S.reduced){j.setValue(0),q.setValue(0),y.setValue(1);const t=_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){j.setValue(1);const t=_reactNative.Animated.spring(q,{toValue:0,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(y,{toValue:1,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0}),_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(T){const t=S.duration("fast"),r=_reactNative.Easing.bezier(...b.motion.ease.accelerate),a=_reactNative.Animated.timing(j,{toValue:0,duration:t,easing:r,useNativeDriver:!0}),s=S.reduced?a:"bottom"===i?_reactNative.Animated.timing(q,{toValue:M,duration:t,easing:r,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.timing(y,{toValue:.9,duration:t,easing:r,useNativeDriver:!0}),a]),n=_reactNative.Animated.parallel([s,_reactNative.Animated.timing(C,{toValue:0,duration:S.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(q.setValue(M),w(!1))}),e.push(n)}return()=>e.forEach(e=>e.stop())},[r,T,i,A,y,j,C,q,M,b.motion.spring.gentle.damping,b.motion.spring.gentle.stiffness,b.motion.spring.gentle.mass,S,b.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{V.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(V.current,"focus")},150),D.current=!0):D.current&&(D.current=!1,f
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Modal=exports.MODAL_DISMISS_GRACE_MS=void 0;var _react=require("react"),_reactNative=require("react-native"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_squircle=require("../../utils/squircle.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_SquircleFill=require("../SquircleFill/SquircleFill.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const MODAL_DISMISS_GRACE_MS=exports.MODAL_DISMISS_GRACE_MS=300,SCALE_START_VALUE=.9,Modal=exports.Modal=(0,_react.forwardRef)((e,t)=>{const{visible:r,onRequestClose:a,presentation:i="centered",backdropOpacity:s,backdropPressClose:n=!0,animationDuration:o,animateMount:l=!0,accessibilityLabel:c,hardwareBackPress:u=!0,children:d,contentStyle:m,backdropStyle:_,restoreFocusRef:f,onDismissed:p,haptic:v,testID:g}=e,b=(0,_index.useTheme)(),S=(0,_usePresenceMotion.usePresenceMotion)(),[h,x]=(0,_ModalSafeArea.useModalInsets)(),A=o??S.duration("default"),M=_reactNative.Dimensions.get("window").height,N=(0,_react.useRef)(!l&&r),R=N.current,y=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:.9)).current,j=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(R?0:M)).current,C=(0,_react.useRef)((0,_index.createAnimatedValue)(R?1:0)).current,V=(0,_react.useRef)(null),D=(0,_react.useRef)(!1),[T,w]=(0,_react.useState)(r),I=(0,_react.useMemo)(()=>buildStyles(b),[b]),E=(0,_react.useMemo)(()=>{const e=b.colors.scrim;return"number"!=typeof s?e:(0,_color.withAlpha)(e,s)??e},[b.colors.scrim,s]),P=(0,_react.useMemo)(()=>C.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(E),E]}),[C,E]);(0,_react.useEffect)(()=>{r&&w(!0)},[r]),(0,_react.useEffect)(()=>{const e=[];if(r&&T&&N.current)N.current=!1;else if(r&&T){const t=_reactNative.Animated.timing(C,{toValue:1,duration:S.duration("default"),useNativeDriver:!1});if(t.start(),e.push(t),S.reduced){j.setValue(0),q.setValue(0),y.setValue(1);const t=_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0});t.start(),e.push(t)}else if("bottom"===i){j.setValue(1);const t=_reactNative.Animated.spring(q,{toValue:0,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0});t.start(),e.push(t)}else{const t=_reactNative.Animated.parallel([_reactNative.Animated.spring(y,{toValue:1,damping:b.motion.spring.gentle.damping,stiffness:b.motion.spring.gentle.stiffness,mass:b.motion.spring.gentle.mass,useNativeDriver:!0}),_reactNative.Animated.timing(j,{toValue:1,duration:A,useNativeDriver:!0})]);t.start(),e.push(t)}}else if(T){const t=S.duration("fast"),r=_reactNative.Easing.bezier(...b.motion.ease.accelerate),a=_reactNative.Animated.timing(j,{toValue:0,duration:t,easing:r,useNativeDriver:!0}),s=S.reduced?a:"bottom"===i?_reactNative.Animated.timing(q,{toValue:M,duration:t,easing:r,useNativeDriver:!0}):_reactNative.Animated.parallel([_reactNative.Animated.timing(y,{toValue:.9,duration:t,easing:r,useNativeDriver:!0}),a]),n=_reactNative.Animated.parallel([s,_reactNative.Animated.timing(C,{toValue:0,duration:S.duration("default"),useNativeDriver:!1})]);n.start(({finished:e})=>{e&&(q.setValue(M),w(!1))}),e.push(n)}return()=>e.forEach(e=>{e.stop()})},[r,T,i,A,y,j,C,q,M,b.motion.spring.gentle.damping,b.motion.spring.gentle.stiffness,b.motion.spring.gentle.mass,S,b.motion.ease.accelerate]),(0,_react.useEffect)(()=>{if("web"===_reactNative.Platform.OS)return;let e,t;return r?(e=setTimeout(()=>{V.current&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(V.current,"focus")},150),D.current=!0):D.current&&(D.current=!1,f?.current&&(t=setTimeout(()=>{const e=f.current;e&&_reactNative.AccessibilityInfo.sendAccessibilityEvent(e,"focus")},A))),()=>{e&&clearTimeout(e),t&&clearTimeout(t)}},[r,A,f]);const L=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{if(r)return void(L.current=!0);if(!L.current)return;if(L.current=!1,!p)return;const e=setTimeout(p,MODAL_DISMISS_GRACE_MS);return()=>clearTimeout(e)},[r,p]);const k=(0,_react.useCallback)(()=>{if(!n)return;const e=(0,_hapticUtils.resolveHaptic)(v,"selection");e&&(0,_hapticUtils.triggerHaptic)(e),a()},[n,a,v]),z=(0,_react.useCallback)(()=>{u&&a()},[u,a]),F=(0,_SquircleFill.useSquircle)("bottom"!==i&&"fullScreen"!==i,b.radius.xl),O=(0,_react.useMemo)(()=>"fullScreen"===i?[I.fullScreenContent,{backgroundColor:b.colors.surface}]:"bottom"===i?[I.bottomContent,{backgroundColor:b.colors.surface,borderTopLeftRadius:b.radius.xl,borderTopRightRadius:b.radius.xl,..._corners.smoothCorners,paddingTop:b.space.lg,paddingHorizontal:b.space.lg,paddingBottom:b.space.lg+h.bottom},b.shadow.modal]:[I.centeredContent,{backgroundColor:b.colors.surface,borderRadius:F.active&&F.size?(0,_squircle.squircleHostRadius)(F.size.width,F.size.height,b.radius.xl):b.radius.xl,..._corners.smoothCorners,padding:b.space.xl},b.shadow.modal],[i,b,I,h.bottom,F.active,F.size]),W=(0,_react.useMemo)(()=>"bottom"===i?I.bottomWrapper:"fullScreen"===i?I.fullScreenWrapper:I.centeredWrapper,[i,I]),H=(0,_react.useMemo)(()=>"bottom"===i?{opacity:j,transform:[{translateY:q}]}:"fullScreen"===i?{opacity:j}:{opacity:j,transform:[{scale:y}]},[i,y,j,q]);return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:T,transparent:!0,statusBarTranslucent:!0,navigationBarTranslucent:!0,animationType:"none",onRequestClose:z,testID:g,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{V.current=e,"function"==typeof t?t(e):t&&(t.current=e)},style:I.root,accessible:!1,accessibilityViewIsModal:!0,accessibilityRole:"alert",accessibilityLabel:c,children:(0,_jsxRuntime.jsxs)(_ModalSafeArea.ModalSafeArea,{onInsets:x,children:[(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{collapsable:!1,style:[_reactNative.StyleSheet.absoluteFill,W,{backgroundColor:P},_],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:k,accessibilityRole:"button",accessibilityLabel:"Close modal",disabled:!n}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{style:[O,H,m],onLayout:F.onLayout,pointerEvents:"auto",children:[F.active&&F.size?(0,_jsxRuntime.jsx)(_SquircleFill.SquircleFill,{width:F.size.width,height:F.size.height,radius:b.radius.xl,fill:b.colors.surface}):null,d]})]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})});Modal.displayName="Modal";const buildStyles=e=>_reactNative.StyleSheet.create({root:{flex:1},centeredWrapper:{flex:1,alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},centeredContent:{maxWidth:"90%",width:"90%"},bottomWrapper:{flex:1,justifyContent:"flex-end"},bottomContent:{width:"100%"},fullScreenWrapper:{flex:1},fullScreenContent:{flex:1}});var _default=exports.default=Modal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:n,onComplete:a,length:s=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:m=!1,haptic:p,onFocus:g,accessibilityLabel:x,style:f,cellStyle:h,textStyle:v,testID:b}=e,[y,j]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:n}),N=(0,_index2.useTheme)(),R=(0,_react.useMemo)(()=>buildStyles(N),[N]),C=(0,_index2.resolveOtpInputSize)(N,_),T=(0,_react.useRef)([]),[F,k]=(0,_react.useState)(-1),V=(0,_react.useRef)(null),w=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,E=(0,_react.useRef)(new Map),A=(0,_react.useMemo)(()=>{const e=E.current,t=[];for(let i=0;i<s;i+=1){let r=e.get(i);r||(r=new _reactNative.Animated.Value(0),e.set(i,r)),t.push(r)}for(const t of Array.from(e.keys()))t>=s&&e.delete(t);return t},[s]),I=(0,_react.useRef)(-1),S=N.settings.components["otp-input"]?.shakeOnError??!1,O=(0,_index.useReducedMotion)(),z=!0===d||(0,_FieldBase.hasFieldText)(d);(0,_react.useEffect)(()=>{let e;return null===V.current||!z||V.current||(p&&(0,_index3.triggerHaptic)("notificationError"),S&&!O&&((0,_index2.setNativeValue)(w,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:-1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:0,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0})]),e.start())),V.current=z,()=>e?.stop()},[z,w,S,p,O,N.motion.duration.instant]),(0,_react.useEffect)(()=>{const e=I.current;if(I.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return A.forEach((i,r)=>{const n=r===F?1:0;if(r!==F&&r!==e)return;const a=_reactNative.Animated.timing(i,{toValue:n,duration:N.motion.duration.fast,easing:_reactNative.Easing.bezier(...N.motion.ease["in-out"]),useNativeDriver:!0});a.start(),t.push(a)}),()=>t.forEach(e=>e.stop())},[F,A,N]);const B=(0,_react.useCallback)(e=>{const t=T.current[e];t&&t.focus()},[]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>B(0),blur:()=>{const e=T.current[F>=0?F:0];e?.blur()},clear:()=>{j(""),B(0)}}),[B,F,j]),(0,_react.useEffect)(()=>{if(l&&!u){const e=setTimeout(()=>B(0),c);return()=>clearTimeout(e)}},[l,c,u,B]);const D=(0,_react.useMemo)(()=>{const e=new Array(s).fill("");for(let t=0;t<Math.min(y.length,s);t+=1)e[t]=y[t]??"";return e},[y,s]),P=(0,_react.useCallback)(e=>{const t=e.slice(0,s);t!==y&&(j(t),t.length===s&&a&&a(t))},[s,j,a,y]),q=(0,_react.useCallback)((e,t)=>{const i=t.replace(/\u200B/g,""),r=sanitizeChar(i,o);if(!r){const t=D.slice(),i=(t[e]??"").length>0;if(t[e]="",P(t.join("").slice(0,s)),!i&&e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}return}const n=D[e]??"",a=n&&r.length>s&&r.startsWith(n)?r.slice(n.length):r;if(a.length>=s){const t=a.slice(0,s),i=y.length;return P(t),t.length!==i&&p&&(0,_index3.triggerHaptic)(p),void T.current[e]?.blur()}const l=D.slice();let c=e;for(let e=0;e<r.length&&c<s;e+=1)l[c]=r[e]??"",c+=1;const u=l.join("").slice(0,s),d=y.length;P(u),u.length!==d&&p&&(0,_index3.triggerHaptic)(p);const _=Math.min(c,s-1);c>=s?T.current[e]?.blur():B(_)},[D,B,o,s,p,P,y]),M=(0,_react.useCallback)((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(D[e]??"").length){if(e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}}else{const t=D.slice();t[e]="",P(t.join(""))}},[D,B,P]),H=(0,_react.useCallback)((e,t)=>{k(e),g?.(t)},[g]),W=(0,_react.useCallback)(()=>{k(-1)},[]),L=(0,_react.useCallback)(()=>{if(u)return;const e=D.indexOf("");B(-1===e?s-1:e)},[D,u,B,s]),$=x??`Enter ${s}-digit code`,G=w.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:f,accessible:!0,accessibilityRole:"none",accessibilityLabel:$,accessibilityValue:{text:i},accessibilityState:{disabled:u},"aria-disabled":u,testID:b,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:L,disabled:u,accessible:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.row,{columnGap:C.gap,transform:[{translateX:G}]}],children:D.map((e,t)=>{const i=F===t,r=e.length>0,n=z?N.colors["danger-border"]:N.colors["focus-ring"],a=A[t];if(!a)return null;const l=m&&r?"●":e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:R.cellWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:_,width:C.cell,height:C.cell,borderRadius:C.radius,borderWidth:1.5,focused:i,error:z,filled:r,disabled:u,paddingHorizontal:N.space.none,paddingVertical:N.space.none,gap:N.space.none,style:h,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:e=>{T.current[t]=e},value:(m&&r?"":e)||"",onChangeText:e=>q(t,e),onKeyPress:e=>M(t,e),onFocus:e=>H(t,e),onBlur:W,keyboardType:o,editable:!u,selectTextOnFocus:!0,caretHidden:r,maxLength:s+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[R.input,{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v]}),m&&r?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:R.maskOverlay,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v],children:l})}):null]}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.underline,{backgroundColor:n,opacity:a}]})]},`otp-cell-${t}`)})})}),(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:_,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,..._corners.smoothCorners}});var _default=exports.default=OTPInput;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OTPInput=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_index3=require("../../utils/index.js"),_corners=require("../../utils/corners.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=exports.OTPInput=(0,_react.forwardRef)((e,t)=>{const{value:i,defaultValue:r,onChange:n,onComplete:a,length:s=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:c=0,disabled:u=!1,error:d,size:_="md",secure:m=!1,haptic:p,onFocus:g,accessibilityLabel:x,style:f,cellStyle:h,textStyle:v,testID:b}=e,[y,j]=(0,_index.useControllableState)({value:i,defaultValue:r??"",onChange:n}),N=(0,_index2.useTheme)(),R=(0,_react.useMemo)(()=>buildStyles(N),[N]),C=(0,_index2.resolveOtpInputSize)(N,_),T=(0,_react.useRef)([]),[F,k]=(0,_react.useState)(-1),V=(0,_react.useRef)(null),w=(0,_react.useRef)((0,_index2.createAnimatedValue)(0)).current,E=(0,_react.useRef)(new Map),A=(0,_react.useMemo)(()=>{const e=E.current,t=[];for(let i=0;i<s;i+=1){let r=e.get(i);r||(r=new _reactNative.Animated.Value(0),e.set(i,r)),t.push(r)}for(const t of Array.from(e.keys()))t>=s&&e.delete(t);return t},[s]),I=(0,_react.useRef)(-1),S=N.settings.components["otp-input"]?.shakeOnError??!1,O=(0,_index.useReducedMotion)(),z=!0===d||(0,_FieldBase.hasFieldText)(d);(0,_react.useEffect)(()=>{let e;return null===V.current||!z||V.current||(p&&(0,_index3.triggerHaptic)("notificationError"),S&&!O&&((0,_index2.setNativeValue)(w,0),e=_reactNative.Animated.sequence([_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:-1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:1,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0}),_reactNative.Animated.timing(w,{toValue:0,duration:N.motion.duration.instant,easing:_reactNative.Easing.linear,useNativeDriver:!0})]),e.start())),V.current=z,()=>e?.stop()},[z,w,S,p,O,N.motion.duration.instant]),(0,_react.useEffect)(()=>{const e=I.current;if(I.current=F,e===F)return;if(-1===e&&-1===F)return;const t=[];return A.forEach((i,r)=>{const n=r===F?1:0;if(r!==F&&r!==e)return;const a=_reactNative.Animated.timing(i,{toValue:n,duration:N.motion.duration.fast,easing:_reactNative.Easing.bezier(...N.motion.ease["in-out"]),useNativeDriver:!0});a.start(),t.push(a)}),()=>t.forEach(e=>{e.stop()})},[F,A,N]);const B=(0,_react.useCallback)(e=>{const t=T.current[e];t&&t.focus()},[]);(0,_react.useImperativeHandle)(t,()=>({focus:()=>B(0),blur:()=>{const e=T.current[F>=0?F:0];e?.blur()},clear:()=>{j(""),B(0)}}),[B,F,j]),(0,_react.useEffect)(()=>{if(l&&!u){const e=setTimeout(()=>B(0),c);return()=>clearTimeout(e)}},[l,c,u,B]);const D=(0,_react.useMemo)(()=>{const e=new Array(s).fill("");for(let t=0;t<Math.min(y.length,s);t+=1)e[t]=y[t]??"";return e},[y,s]),P=(0,_react.useCallback)(e=>{const t=e.slice(0,s);t!==y&&(j(t),t.length===s&&a&&a(t))},[s,j,a,y]),q=(0,_react.useCallback)((e,t)=>{const i=t.replace(/\u200B/g,""),r=sanitizeChar(i,o);if(!r){const t=D.slice(),i=(t[e]??"").length>0;if(t[e]="",P(t.join("").slice(0,s)),!i&&e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}return}const n=D[e]??"",a=n&&r.length>s&&r.startsWith(n)?r.slice(n.length):r;if(a.length>=s){const t=a.slice(0,s),i=y.length;return P(t),t.length!==i&&p&&(0,_index3.triggerHaptic)(p),void T.current[e]?.blur()}const l=D.slice();let c=e;for(let e=0;e<r.length&&c<s;e+=1)l[c]=r[e]??"",c+=1;const u=l.join("").slice(0,s),d=y.length;P(u),u.length!==d&&p&&(0,_index3.triggerHaptic)(p);const _=Math.min(c,s-1);c>=s?T.current[e]?.blur():B(_)},[D,B,o,s,p,P,y]),M=(0,_react.useCallback)((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(D[e]??"").length){if(e>0){const t=D.slice();t[e-1]="",P(t.join("")),B(e-1)}}else{const t=D.slice();t[e]="",P(t.join(""))}},[D,B,P]),H=(0,_react.useCallback)((e,t)=>{k(e),g?.(t)},[g]),W=(0,_react.useCallback)(()=>{k(-1)},[]),L=(0,_react.useCallback)(()=>{if(u)return;const e=D.indexOf("");B(-1===e?s-1:e)},[D,u,B,s]),$=x??`Enter ${s}-digit code`,G=w.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:f,accessible:!0,accessibilityRole:"none",accessibilityLabel:$,accessibilityValue:{text:i},accessibilityState:{disabled:u},"aria-disabled":u,testID:b,children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:L,disabled:u,accessible:!1,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.row,{columnGap:C.gap,transform:[{translateX:G}]}],children:D.map((e,t)=>{const i=F===t,r=e.length>0,n=z?N.colors["danger-border"]:N.colors["focus-ring"],a=A[t];if(!a)return null;const l=m&&r?"●":e;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:R.cellWrapper,children:[(0,_jsxRuntime.jsxs)(_FieldBase.FieldBase,{size:_,width:C.cell,height:C.cell,borderRadius:C.radius,borderWidth:1.5,focused:i,error:z,filled:r,disabled:u,paddingHorizontal:N.space.none,paddingVertical:N.space.none,gap:N.space.none,style:h,children:[(0,_jsxRuntime.jsx)(_reactNative.TextInput,{ref:e=>{T.current[t]=e},value:(m&&r?"":e)||"",onChangeText:e=>q(t,e),onKeyPress:e=>M(t,e),onFocus:e=>H(t,e),onBlur:W,keyboardType:o,editable:!u,selectTextOnFocus:!0,caretHidden:r,maxLength:s+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[R.input,{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v]}),m&&r?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:R.maskOverlay,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[{fontSize:C.text,color:N.colors["text-body"],...(0,_index2.fontFor)(N,"semibold")},v],children:l})}):null]}),(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[R.underline,{backgroundColor:n,opacity:a}]})]},`otp-cell-${t}`)})})}),(0,_jsxRuntime.jsx)(_FieldBase.FieldMessage,{size:_,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{..._reactNative.StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,..._corners.smoothCorners}});var _default=exports.default=OTPInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OptionSheet=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),SEARCH_ICON_SIZE=18,OptionSheet=e=>{const{open:t,onClose:i,onAfterClose:r,onOpenChange:s,title:a,options:o,sections:n,renderSectionHeader:l,renderOption:c,alphabetIndex:d=!1,searchPlaceholder:u="Search…",emptyText:p="No options",labelOf:m,getValue:h,disabledOf:x,destructiveOf:_,descriptionOf:g,iconOf:b,isSelected:f,onSelect:y,multi:v=!1,searchable:j=!1,searchSelectionColor:R,accessibilityLabel:N,optionStyle:S,selectedOptionStyle:T,optionTextStyle:w,selectedOptionTextStyle:C,testID:I}=e,V=(0,_index.useTheme)(),k=(0,_usePresenceMotion.usePresenceMotion)(),[M,z]=(0,_ModalSafeArea.useModalInsets)(),D=(0,_react.useMemo)(()=>buildStyles(V),[V]),[A,P]=(0,_react.useState)(""),L=_reactNative.Dimensions.get("window").height,H=Math.round(.7*L),[O,W]=(0,_react.useState)(t),B=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,E=(0,_react.useRef)((0,_index.createAnimatedValue)(H)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,F=(0,_react.useMemo)(()=>k.reduced?q:_reactNative.Animated.add(E,q),[k.reduced,E,q]),G=(0,_react.useMemo)(()=>k.reduced?E.interpolate({inputRange:[0,H],outputRange:[1,0],extrapolate:"clamp"}):1,[k.reduced,E,H]),{handleGesture:$,opacity:K}=(0,_useDragToDismiss.useDragToDismiss)({drag:q,travel:H,onDismiss:i}),J=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(G,K),[G,K]),U=(0,_react.useMemo)(()=>{const e=V.colors.scrim;return B.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(e),e]})},[B,V.colors.scrim]);(0,_react.useEffect)(()=>{t&&W(!0)},[t]);const Y=(0,_react.useRef)(s);Y.current=s;const Z=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{Z.current!==t&&(Z.current=t,Y.current?.(t))},[t]);const Q=(0,_react.useRef)(r);Q.current=r;const X=(0,_react.useRef)(O);(0,_react.useEffect)(()=>{X.current&&!O&&"ios"!==_reactNative.Platform.OS&&Q.current?.(),X.current=O},[O]),(0,_react.useEffect)(()=>{if(!O)return;t&&((0,_index.setNativeValue)(q,0),(0,_index.setNativeValue)(K,1));const e=t?_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:1,duration:k.duration("default"),easing:_reactNative.Easing.bezier(...V.motion.ease["in-out"]),useNativeDriver:!1}),k.reduced?_reactNative.Animated.timing(E,{toValue:0,duration:k.duration("default"),easing:_reactNative.Easing.bezier(...V.motion.ease["in-out"]),useNativeDriver:!0}):_reactNative.Animated.spring(E,{toValue:0,damping:V.motion.spring.snappy.damping,stiffness:V.motion.spring.snappy.stiffness,mass:V.motion.spring.snappy.mass,useNativeDriver:!0})]):_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:0,duration:k.duration("default"),easing:_reactNative.Easing.bezier(...V.motion.ease["in-out"]),useNativeDriver:!1}),_reactNative.Animated.timing(E,{toValue:H,duration:k.duration("fast"),easing:_reactNative.Easing.bezier(...V.motion.ease.accelerate),useNativeDriver:!0})]);return e.start(({finished:e})=>{e&&!t&&W(!1)}),()=>e.stop()},[t,O,B,E,q,K,H,k,V.motion.ease["in-out"],V.motion.ease.accelerate,V.motion.spring.snappy]);const ee=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Native(),[]),[te,ie]=(0,_react.useState)(0),re=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),se=O?Math.max(0,Math.round(re)):0,ae=Math.max(M.top,_reactNative.StatusBar.currentHeight??0)+V.space.sm,oe=se>0,ne=oe?Math.max(0,Math.min(H,(te>0?te:L)-se-ae)):H;(0,_react.useEffect)(()=>{t||P("")},[t]);const le=(0,_react.useMemo)(()=>{const e=j?A.trim().toLowerCase():"",matches=t=>0===e.length||m(t).toLowerCase().includes(e)||(g(t)??"").toLowerCase().includes(e);if(!n)return o.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return n.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[j,A,o,n,m,g]),ce=(0,_react.useCallback)(()=>{i()},[i]),de=(0,_react.useRef)(null),ue=(0,_react.useMemo)(()=>{const e=new Map;if(!d)return e;let t=0;if(n)for(let e=le.length-1;e>=0;e-=1)if("header"===le[e].kind){t=e+1;break}for(let i=t;i<le.length;i+=1){const t=le[i];if("option"!==t.kind)continue;const r=m(t.option).trim().charAt(0).toUpperCase(),s=/^[A-Z]$/.test(r)?r:"#";e.has(s)||e.set(s,i)}return e},[d,le,n,m]),pe=d&&ue.size>0&&0===A.trim().length,me=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...ue.has("#")?["#"]:[]],[ue]),he=(0,_react.useCallback)(e=>{const t=ue.get(e);void 0!==t&&de.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[ue]),xe=(0,_react.useRef)(null),ge=(0,_react.useCallback)(()=>{null!==xe.current&&(clearTimeout(xe.current),xe.current=null)},[]),be=(0,_react.useCallback)(e=>{de.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),ge(),xe.current=setTimeout(()=>{xe.current=null,de.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[ge]);(0,_react.useEffect)(()=>(O||ge(),ge),[O,ge]);return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:O,transparent:!0,animationType:"none",onRequestClose:ce,onDismiss:()=>Q.current?.(),statusBarTranslucent:!0,navigationBarTranslucent:!0,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:z,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,onLayout:e=>ie(e.nativeEvent.layout.height),style:[_reactNative.StyleSheet.absoluteFill,{backgroundColor:U}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:ce,accessibilityRole:"button",accessibilityLabel:"Close picker"}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:I,accessibilityViewIsModal:!0,accessibilityLabel:N??a??"Options",style:[D.sheet,{maxHeight:ne,bottom:se,paddingBottom:oe?V.space.lg:M.bottom+V.space.lg,backgroundColor:V.colors.surface,borderTopLeftRadius:V.radius.xl,borderTopRightRadius:V.radius.xl,..._corners.smoothCorners,opacity:J,transform:[{translateY:F}],...V.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:$,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetHandle,{backgroundColor:V.colors.border}]})}),a?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.sheetTitle,{color:V.colors["text-body"],fontSize:V.text.lg.size,fontWeight:V.weight.semibold,paddingHorizontal:V.space.lg,marginBottom:V.space.sm}],children:a}):null]})}),j?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.searchWrap,{marginHorizontal:V.space.lg,marginBottom:V.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.searchBox,{backgroundColor:V.colors["bg-subtle"],borderColor:V.colors.border,borderRadius:V.radius.md,..._corners.smoothCorners,paddingHorizontal:V.space.md,gap:V.space.sm}],children:[(V.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:V.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:A,onChangeText:P,placeholder:u,placeholderTextColor:V.colors["text-subtle"],selectionColor:R??V.colors["focus-ring"],accessibilityLabel:"Search options",style:[D.searchInput,{color:V.colors["text-body"],fontSize:V.text.base.size,paddingVertical:V.space.sm}]}),A.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>P(""),hitSlop:8,accessibilityRole:"button",accessibilityLabel:"Clear search",children:(V.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:V.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.listWrap,pe?D.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ee,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:de,data:le,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(h(e.option))}`,renderItem:({item:e})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[D.sectionHeader,{paddingHorizontal:V.space.lg,paddingTop:V.space.md}],children:l?l(e.title):(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.sectionTitle,{color:V.colors["text-subtle"],fontSize:V.text.xs.size,fontWeight:V.weight.semibold}],children:e.title.toUpperCase()})});const t=e.option,i=m(t),r=h(t),s=g(t),a=b(t),o=f(r),n=x(t),d=_?.(t)??!1;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>y(t),disabled:n,android_ripple:{color:V.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:o,disabled:n},"aria-selected":o,"aria-disabled":n,style:({pressed:e})=>[D.optionRow,{backgroundColor:o?V.colors["surface-selected"]:e?V.colors["surface-pressed"]:"transparent",opacity:n?.5:1,paddingHorizontal:V.space.lg,paddingVertical:V.space.md},S,o?T:null],children:[c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionTextWrap,children:c(t,{selected:o,disabled:n})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionIcon,children:a}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.optionLabel,{color:d?V.colors["danger-text"]:o?V.colors.primary:V.colors["text-body"],fontSize:V.text.base.size,fontWeight:o?V.weight.semibold:V.weight.medium},w,o?C:null],children:i}),s?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.optionDescription,{color:V.colors["text-subtle"],fontSize:V.text.sm.size}],numberOfLines:2,children:s}):null]})]}),v?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.checkbox,{borderColor:o?V.colors.primary:V.colors.border,backgroundColor:o?V.colors.primary:"transparent"}],children:o?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.checkboxTick}):null}):o?"icon"===V.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.singleSelectedIcon,children:(V.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:V.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.singleSelectedDot,{backgroundColor:V.colors.primary}]}):null]})},onScrollToIndexFailed:be,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!pe,style:pe?D.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.empty,{color:V.colors["text-subtle"],fontSize:V.text.sm.size,paddingVertical:V.space.xl}],children:p})})}),pe?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.rail,{paddingRight:V.space.xs}],accessibilityRole:"list",accessibilityLabel:"Jump to letter",testID:"option-sheet-alphabet",children:me.map(e=>{const t=ue.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>he(e),disabled:!t,hitSlop:{left:8,right:8},accessibilityRole:"button",accessibilityLabel:`Jump to ${e}`,accessibilityState:{disabled:!t},"aria-disabled":!t,style:D.railLetter,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.railLetterText,{color:t?V.colors.primary:V.colors["text-subtle"],fontSize:V.text.xs.size,fontWeight:V.weight.semibold,opacity:t?1:.45}],children:e})},e)})}):null]}),v?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetFooter,{borderTopColor:V.colors["border-subtle"],paddingHorizontal:V.space.lg,paddingVertical:V.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ce,accessibilityRole:"button",accessibilityLabel:"Done",style:({pressed:e})=>[D.doneButton,{backgroundColor:e?V.colors["primary-pressed"]:V.colors.primary,borderRadius:V.radius.md,..._corners.smoothCorners,paddingVertical:V.space.sm,paddingHorizontal:V.space.lg}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:V.colors["on-primary"],fontSize:V.text.base.size,fontWeight:V.weight.semibold},children:"Done"})})}):null]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})};exports.OptionSheet=OptionSheet,OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({sheet:{position:"absolute",left:0,right:0,bottom:0,paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight: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,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},empty:{textAlign:"center"},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.OptionSheet=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeGestureHandler=require("react-native-gesture-handler"),_reactNativeKeyboardController=require("react-native-keyboard-controller"),_useDragToDismiss=require("../../hooks/useDragToDismiss.js"),_usePresenceMotion=require("../../hooks/usePresenceMotion.js"),_index=require("../../theme/index.js"),_color=require("../../utils/color.js"),_corners=require("../../utils/corners.js"),_hitSlop=require("../../utils/hitSlop.js"),_defaultIcons=require("../AppIcon/defaultIcons.js"),_ModalSafeArea=require("../ModalSafeArea/ModalSafeArea.js"),_ToastProvider=require("../Toast/ToastProvider.js"),_jsxRuntime=require("react/jsx-runtime");const AnimatedGestureRoot=_reactNative.Animated.createAnimatedComponent(_reactNativeGestureHandler.GestureHandlerRootView),SEARCH_ICON_SIZE=18,OptionSheet=e=>{const{open:t,onClose:i,onAfterClose:r,onOpenChange:s,title:a,options:o,sections:n,renderSectionHeader:l,renderOption:c,alphabetIndex:d=!1,searchPlaceholder:u="Search…",emptyText:p="No options",labelOf:m,getValue:h,disabledOf:_,destructiveOf:x,descriptionOf:g,iconOf:b,isSelected:f,onSelect:y,multi:v=!1,searchable:j=!1,searchSelectionColor:R,accessibilityLabel:N,optionStyle:S,selectedOptionStyle:T,optionTextStyle:w,selectedOptionTextStyle:C,testID:k}=e,I=(0,_index.useTheme)(),V=(0,_usePresenceMotion.usePresenceMotion)(),[M,z]=(0,_ModalSafeArea.useModalInsets)(),D=(0,_react.useMemo)(()=>buildStyles(I),[I]),[A,P]=(0,_react.useState)(""),L=_reactNative.Dimensions.get("window").height,H=Math.round(.7*L),[O,W]=(0,_react.useState)(t),B=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,E=(0,_react.useRef)((0,_index.createAnimatedValue)(H)).current,q=(0,_react.useRef)((0,_index.createAnimatedValue)(0)).current,F=(0,_react.useMemo)(()=>V.reduced?q:_reactNative.Animated.add(E,q),[V.reduced,E,q]),G=(0,_react.useMemo)(()=>V.reduced?E.interpolate({inputRange:[0,H],outputRange:[1,0],extrapolate:"clamp"}):1,[V.reduced,E,H]),{handleGesture:$,opacity:K}=(0,_useDragToDismiss.useDragToDismiss)({drag:q,travel:H,onDismiss:i}),J=(0,_react.useMemo)(()=>_reactNative.Animated.multiply(G,K),[G,K]),U=(0,_react.useMemo)(()=>{const e=I.colors.scrim;return B.interpolate({inputRange:[0,1],outputRange:[(0,_color.transparentOf)(e),e]})},[B,I.colors.scrim]);(0,_react.useEffect)(()=>{t&&W(!0)},[t]);const Y=(0,_react.useRef)(s);Y.current=s;const Z=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>{Z.current!==t&&(Z.current=t,Y.current?.(t))},[t]);const Q=(0,_react.useRef)(r);Q.current=r;const X=(0,_react.useRef)(O);(0,_react.useEffect)(()=>{X.current&&!O&&"ios"!==_reactNative.Platform.OS&&Q.current?.(),X.current=O},[O]),(0,_react.useEffect)(()=>{if(!O)return;t&&((0,_index.setNativeValue)(q,0),(0,_index.setNativeValue)(K,1));const e=t?_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:1,duration:V.duration("default"),easing:_reactNative.Easing.bezier(...I.motion.ease["in-out"]),useNativeDriver:!1}),V.reduced?_reactNative.Animated.timing(E,{toValue:0,duration:V.duration("default"),easing:_reactNative.Easing.bezier(...I.motion.ease["in-out"]),useNativeDriver:!0}):_reactNative.Animated.spring(E,{toValue:0,damping:I.motion.spring.snappy.damping,stiffness:I.motion.spring.snappy.stiffness,mass:I.motion.spring.snappy.mass,useNativeDriver:!0})]):_reactNative.Animated.parallel([_reactNative.Animated.timing(B,{toValue:0,duration:V.duration("default"),easing:_reactNative.Easing.bezier(...I.motion.ease["in-out"]),useNativeDriver:!1}),_reactNative.Animated.timing(E,{toValue:H,duration:V.duration("fast"),easing:_reactNative.Easing.bezier(...I.motion.ease.accelerate),useNativeDriver:!0})]);return e.start(({finished:e})=>{e&&!t&&W(!1)}),()=>e.stop()},[t,O,B,E,q,K,H,V,I.motion.ease["in-out"],I.motion.ease.accelerate,I.motion.spring.snappy]);const ee=(0,_react.useMemo)(()=>_reactNativeGestureHandler.Gesture.Native(),[]),[te,ie]=(0,_react.useState)(0),re=(0,_reactNativeKeyboardController.useKeyboardState)(e=>e.height),se=O?Math.max(0,Math.round(re)):0,ae=Math.max(M.top,_reactNative.StatusBar.currentHeight??0)+I.space.sm,oe=se>0,ne=oe?Math.max(0,Math.min(H,(te>0?te:L)-se-ae)):H;(0,_react.useEffect)(()=>{t||P("")},[t]);const le=(0,_react.useMemo)(()=>{const e=j?A.trim().toLowerCase():"",matches=t=>0===e.length||m(t).toLowerCase().includes(e)||(g(t)??"").toLowerCase().includes(e);if(!n)return o.filter(matches).map(e=>({kind:"option",option:e}));const t=[];return n.forEach((e,i)=>{const r=e.options.filter(matches);if(0!==r.length){t.push({kind:"header",title:e.title});for(const e of r)t.push({kind:"option",option:e,section:i})}}),t},[j,A,o,n,m,g]),ce=(0,_react.useCallback)(()=>{i()},[i]),de=(0,_react.useRef)(null),ue=(0,_react.useMemo)(()=>{const e=new Map;if(!d)return e;let t=0;if(n)for(let e=le.length-1;e>=0;e-=1)if("header"===le[e].kind){t=e+1;break}for(let i=t;i<le.length;i+=1){const t=le[i];if("option"!==t.kind)continue;const r=m(t.option).trim().charAt(0).toUpperCase(),s=/^[A-Z]$/.test(r)?r:"#";e.has(s)||e.set(s,i)}return e},[d,le,n,m]),pe=d&&ue.size>0&&0===A.trim().length,me=(0,_react.useMemo)(()=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ",...ue.has("#")?["#"]:[]],[ue]),he=(0,_react.useCallback)(e=>{const t=ue.get(e);void 0!==t&&de.current?.scrollToIndex({index:t,animated:!0,viewPosition:0})},[ue]),xe=(0,_react.useRef)(null),ge=(0,_react.useCallback)(()=>{null!==xe.current&&(clearTimeout(xe.current),xe.current=null)},[]),be=(0,_react.useCallback)(e=>{de.current?.scrollToOffset({offset:e.averageItemLength*e.index,animated:!1}),ge(),xe.current=setTimeout(()=>{xe.current=null,de.current?.scrollToIndex({index:e.index,animated:!0,viewPosition:0})},50)},[ge]);(0,_react.useEffect)(()=>(O||ge(),ge),[O,ge]);return(0,_jsxRuntime.jsx)(_reactNative.Modal,{visible:O,transparent:!0,animationType:"none",onRequestClose:ce,onDismiss:()=>Q.current?.(),statusBarTranslucent:!0,navigationBarTranslucent:!0,children:(0,_jsxRuntime.jsx)(_ModalSafeArea.ModalSafeArea,{onInsets:z,children:(0,_jsxRuntime.jsxs)(AnimatedGestureRoot,{collapsable:!1,onLayout:e=>ie(e.nativeEvent.layout.height),style:[_reactNative.StyleSheet.absoluteFill,{backgroundColor:U}],children:[(0,_jsxRuntime.jsx)(_reactNative.Pressable,{style:_reactNative.StyleSheet.absoluteFill,onPress:ce,accessibilityRole:"button",accessibilityLabel:"Close picker"}),(0,_jsxRuntime.jsxs)(_reactNative.Animated.View,{testID:k,accessibilityViewIsModal:!0,accessibilityLabel:N??a??"Options",style:[D.sheet,{maxHeight:ne,bottom:se,paddingBottom:oe?I.space.lg:M.bottom+I.space.lg,backgroundColor:I.colors.surface,borderTopLeftRadius:I.radius.xl,borderTopRightRadius:I.radius.xl,..._corners.smoothCorners,opacity:J,transform:[{translateY:F}],...I.shadow.modal}],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:$,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.sheetHandleRow,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetHandle,{backgroundColor:I.colors.border}]})}),a?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.sheetTitle,{color:I.colors["text-body"],fontSize:I.text.lg.size,fontWeight:I.weight.semibold,paddingHorizontal:I.space.lg,marginBottom:I.space.sm}],children:a}):null]})}),j?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.searchWrap,{marginHorizontal:I.space.lg,marginBottom:I.space.sm}],children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.searchBox,{backgroundColor:I.colors["bg-subtle"],borderColor:I.colors.border,borderRadius:I.radius.md,..._corners.smoothCorners,paddingHorizontal:I.space.md,gap:I.space.sm}],children:[(I.settings.icons.search??_defaultIcons.defaultIcons.search)({size:18,color:I.colors["text-subtle"]}),(0,_jsxRuntime.jsx)(_reactNative.TextInput,{value:A,onChangeText:P,placeholder:u,placeholderTextColor:I.colors["text-subtle"],selectionColor:R??I.colors["focus-ring"],accessibilityLabel:"Search options",style:[D.searchInput,{color:I.colors["text-body"],fontSize:I.text.base.size,paddingVertical:I.space.sm}]}),A.length>0?(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>P(""),hitSlop:8,...(0,_hitSlop.hitSlopMarker)(8),accessibilityRole:"button",accessibilityLabel:"Clear search",children:(I.settings.icons.close??_defaultIcons.defaultIcons.close)({size:18,color:I.colors["text-muted"]})}):null]})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[D.listWrap,pe?D.listRow:null],children:[(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector,{gesture:ee,children:(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:de,data:le,keyExtractor:e=>"header"===e.kind?`h:${e.title}`:`o:${e.section??""}:${String(h(e.option))}`,renderItem:({item:e})=>{if("header"===e.kind)return(0,_jsxRuntime.jsx)(_reactNative.View,{accessible:!0,accessibilityRole:"header",style:[D.sectionHeader,{paddingHorizontal:I.space.lg,paddingTop:I.space.md}],children:l?l(e.title):(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.sectionTitle,{color:I.colors["text-subtle"],fontSize:I.text.xs.size,fontWeight:I.weight.semibold}],children:e.title.toUpperCase()})});const t=e.option,i=m(t),r=h(t),s=g(t),a=b(t),o=f(r),n=_(t),d=x?.(t)??!1;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{onPress:()=>y(t),disabled:n,android_ripple:{color:I.colors["surface-pressed"],borderless:!1},accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:o,disabled:n},"aria-selected":o,"aria-disabled":n,style:({pressed:e})=>[D.optionRow,{backgroundColor:o?I.colors["surface-selected"]:e?I.colors["surface-pressed"]:"transparent",opacity:n?.5:1,paddingHorizontal:I.space.lg,paddingVertical:I.space.md},S,o?T:null],children:[c?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionTextWrap,children:c(t,{selected:o,disabled:n})}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[a?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.optionIcon,children:a}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:D.optionTextWrap,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.optionLabel,{color:d?I.colors["danger-text"]:o?I.colors.primary:I.colors["text-body"],fontSize:I.text.base.size,fontWeight:o?I.weight.semibold:I.weight.medium},w,o?C:null],children:i}),s?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.optionDescription,{color:I.colors["text-subtle"],fontSize:I.text.sm.size}],numberOfLines:2,children:s}):null]})]}),v?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.checkbox,{borderColor:o?I.colors.primary:I.colors.border,backgroundColor:o?I.colors.primary:"transparent"}],children:o?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.checkboxTick}):null}):o?"icon"===I.settings.components["option-sheet"]?.selectedMarker?(0,_jsxRuntime.jsx)(_reactNative.View,{style:D.singleSelectedIcon,children:(I.settings.icons.selectedTick??_defaultIcons.defaultIcons.selectedTick)({size:20,color:I.colors.primary})}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.singleSelectedDot,{backgroundColor:I.colors.primary}]}):null]})},onScrollToIndexFailed:be,overScrollMode:"never",bounces:!1,keyboardShouldPersistTaps:"handled",showsVerticalScrollIndicator:!pe,style:pe?D.listBesideRail:null,ListEmptyComponent:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.empty,{color:I.colors["text-subtle"],fontSize:I.text.sm.size,paddingVertical:I.space.xl}],children:p})})}),pe?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.rail,{paddingRight:I.space.xs}],accessibilityRole:"list",accessibilityLabel:"Jump to letter",testID:"option-sheet-alphabet",children:me.map(e=>{const t=ue.has(e);return(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:()=>he(e),disabled:!t,hitSlop:{left:8,right:8},...(0,_hitSlop.hitSlopMarker)({left:8,right:8}),accessibilityRole:"button",accessibilityLabel:`Jump to ${e}`,accessibilityState:{disabled:!t},"aria-disabled":!t,style:D.railLetter,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[D.railLetterText,{color:t?I.colors.primary:I.colors["text-subtle"],fontSize:I.text.xs.size,fontWeight:I.weight.semibold,opacity:t?1:.45}],children:e})},e)})}):null]}),v?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[D.sheetFooter,{borderTopColor:I.colors["border-subtle"],paddingHorizontal:I.space.lg,paddingVertical:I.space.md}],children:(0,_jsxRuntime.jsx)(_reactNative.Pressable,{onPress:ce,accessibilityRole:"button",accessibilityLabel:"Done",style:({pressed:e})=>[D.doneButton,{backgroundColor:e?I.colors["primary-pressed"]:I.colors.primary,borderRadius:I.radius.md,..._corners.smoothCorners,paddingVertical:I.space.sm,paddingHorizontal:I.space.lg}],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:I.colors["on-primary"],fontSize:I.text.base.size,fontWeight:I.weight.semibold},children:"Done"})})}):null]}),(0,_jsxRuntime.jsx)(_ToastProvider.ToastHost,{})]})})})};exports.OptionSheet=OptionSheet,OptionSheet.displayName="OptionSheet";const buildStyles=e=>_reactNative.StyleSheet.create({sheet:{position:"absolute",left:0,right:0,bottom:0,paddingBottom:e.space.lg,overflow:"hidden"},sheetHandleRow:{alignItems:"center",paddingTop:e.space.sm,paddingBottom:e.space.sm},sheetHandle:{width:36,height:4,borderRadius:e.radius.pill,..._corners.smoothCorners},sheetTitle:{includeFontPadding:!1},searchWrap:{width:"auto"},searchBox:{flexDirection:"row",alignItems:"center",borderWidth:1},searchInput:{flex:1,includeFontPadding:!1},optionRow:{flexDirection:"row",alignItems:"center"},sectionHeader:{paddingBottom:e.space.xs},listWrap:{flexShrink:1},listRow:{flexDirection:"row"},listBesideRail:{flex:1},rail:{justifyContent:"space-between",alignItems:"center",alignSelf:"stretch",paddingVertical:e.space.xs},railLetter:{paddingHorizontal:e.space.xs,minHeight:14,justifyContent:"center"},railLetterText:{includeFontPadding:!1,lineHeight: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,..._corners.smoothCorners,borderWidth:2,alignItems:"center",justifyContent:"center",marginLeft:e.space.md},checkboxTick:{width:10,height:6,borderLeftWidth:2,borderBottomWidth:2,borderColor:e.colors["on-primary"],transform:[{rotate:"-45deg"},{translateY:-1}]},singleSelectedDot:{width:8,height:8,borderRadius:e.radius.pill,..._corners.smoothCorners,marginLeft:e.space.md},singleSelectedIcon:{marginLeft:e.space.md},empty:{textAlign:"center"},sheetFooter:{borderTopWidth:_reactNative.StyleSheet.hairlineWidth,alignItems:"flex-end"},doneButton:{alignSelf:"flex-end"}});var _default=exports.default=OptionSheet;
|