@webority/mobile-chat 0.147.0 → 0.147.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatComposer=ChatComposer;var _chatCore=require("@webority/chat-core"),_permissions=require("@webority/mobile-core/permissions"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatDictationButton=require("./ChatDictationButton.js"),_ChatFooter=require("./ChatFooter.js"),_chatShared=require("./chatShared.js"),_iconName=require("./iconName.js"),_speechText=require("./speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:i,safeArea:n,testID:o="chat-composer",focusRef:r,look:l=_chatCore.defaultChatLook,sendIcon:c}){const u=(0,_mobileUi.useTheme)(),m=(0,_react.useMemo)(()=>buildStyles(u),[u]),[h,d]=(0,_react.useState)(""),[p,_]=(0,_react.useState)(null),x=e.editing,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatComposer=ChatComposer;var _chatCore=require("@webority/chat-core"),_permissions=require("@webority/mobile-core/permissions"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatDictationButton=require("./ChatDictationButton.js"),_ChatFooter=require("./ChatFooter.js"),_chatShared=require("./chatShared.js"),_iconName=require("./iconName.js"),_speechText=require("./speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:i,safeArea:n,testID:o="chat-composer",focusRef:r,look:l=_chatCore.defaultChatLook,sendIcon:c}){const u=(0,_mobileUi.useTheme)(),m=(0,_react.useMemo)(()=>buildStyles(u),[u]),[h,d]=(0,_react.useState)(""),[p,_]=(0,_react.useState)(null),x=e.editing,f=(0,_react.useRef)(null),g=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(r)return r.current=()=>g.current?.focus(),()=>{r.current=null}},[r]),(0,_react.useEffect)(()=>{x&&f.current?.(),d(x?x.text:"")},[x]);const b=e.attachments,j=b.some(e=>"Uploading"===e.status),v=b.some(e=>"Ready"===e.status),y=e.messagesLeftToday,R=e.profile?.limits.maxMessageLength??DEFAULT_MAX_LENGTH,C=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,A=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),T=C&&!e.handoffPause?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${o}-attach`}):void 0,S=x?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${o}-editing`}):null,N=b.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.tray,testID:`${o}-attachments`,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.row,children:b.map(s=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.item,children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{removeText:t.removeAttachment(s.fileName)},removeTestID:`${o}-remove-${s.key}`,testID:`${o}-chip-${s.key}`}),"Uploading"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{...null===s.progress||void 0===s.progress?{}:{progress:s.progress},label:t.attachmentUploading,height:4,style:m.progress}):null,"Failed"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.error??t.attachmentFailed}):null]},s.key))})}):null,w=null!==y&&y<=ALLOWANCE_SHOWN_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:0===y?"danger":"secondary",accessibilityLiveRegion:"polite",...(0,_chatShared.webProps)({role:"status"}),testID:`${o}-allowance`,children:t.allowance(y)}):null,D=p?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:p.message,tone:p.tone,dismissible:!0,onClose:()=>_(null),...p.openSettings?{actions:[{label:t.dictateOpenSettings,onPress:()=>{_permissions.Permissions.openSettings()}}]}:{},testID:`${o}-voice-notice`}):null,U=h.length>0,L=h.length>R*COUNTER_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",testID:`${o}-counter`,children:t.counter(h.length,R)}):null,I=S||N||w||L||D?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[S,N,w,L,D]}):void 0,k=!j&&(!!v||void 0),q=(0,_iconName.iconNameOf)(c);return(0,_jsxRuntime.jsx)(_mobileUi.Composer,{ref:g,onSend:t=>{f.current?.(),e.submit(t)},value:h,onChangeText:t=>{f.current?.(),d(t),A&&t.length>0&&e.notifyTyping()},loading:e.streaming&&e.features.Stop,ring:l.input.ring&&(U||e.streaming),sendReveal:"Always"===l.input.sendReveal?"always":"onText",...q?{sendIcon:q}:{},...e.features.Stop?{onStop:()=>e.stop()}:{},stopLabel:t.stop,disabled:0===y||e.handoffPause,maxLength:R,...void 0===k?{}:{canSend:k},placeholder:e.handoffPause?t.handoffMoment:openQuestion(e.messages)??t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:T,trailing:(0,_jsxRuntime.jsx)(_ChatDictationButton.ChatDictationButton,{chat:e,labels:t,disabled:0===y||e.handoffPause,onText:e=>d(t=>(0,_speechText.joinDictation)(t,e,R)),onNotice:_,stopRef:f}),above:I,below:(0,_jsxRuntime.jsx)(_ChatFooter.ChatFooter,{chat:e,labels:t}),...void 0===i?{}:{keyboardAware:i},...void 0===a?{}:{keyboardOffset:a},...void 0===n?{}:{safeArea:n},testID:o})}const buildStyles=e=>_reactNative.StyleSheet.create({tray:{gap:e.space.xs},row:{flexDirection:"row",flexWrap:"wrap",gap:e.space.xs},item:{gap:e.space.xxs,maxWidth:"100%"},progress:{minWidth:120}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const fileNameOf=(e,t)=>{const i="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:a,features:s}=t,[n,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[b,_]=(0,_react.useState)({}),[f,h]=(0,_react.useState)({}),j=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=j.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,w=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(a.errorGeneric),m(!1)}},U=s.LeadShortcuts,T=e.fields[0];if(U&&1===e.fields.length&&void 0===T)throw new Error("A one-field form has no field.");const C=U&&1===e.fields.length&&void 0!==T&&!T.required,q=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...(0,_chatShared.webProps)({role:"form","aria-label":e.title||e.submitLabel}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",...(0,_chatShared.webProps)({"aria-level":3}),children:e.title}):null,e.fields.map(s=>{const l=n[s.key]??"",c=o[s.key];if("File"===s.type){const e=y[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:e?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=s.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:a.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:a.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:a.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i(e.accept??void 0)}catch{return void d(a.errorGeneric)}const s=r[0];if(!s)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(s,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(s,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(s)}})})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},s.key)}if("MultiChoice"===s.type){const e=(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(s.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Choice"===s.type||"TimeSlot"===s.type){const e="TimeSlot"===s.type?(s.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(s.key,String(e)),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Consent"===s.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(s.key,e?"true":"false"),label:s.consentText??s.label,...void 0===c?{}:{error:c},disabled:p},s.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{j.current[s.key]=e},label:s.label,..."string"==typeof s.placeholder?{placeholder:s.placeholder}:{},value:l,onChangeText:e=>setValue(s.key,e),..."number"==typeof s.maxLength?{maxLength:s.maxLength}:{},showCounter:!1,required:s.required,...void 0===c?{}:{error:c},...s.required?{}:{help:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.inputOptional})},labelMode:"top",disabled:p,type:s.secret?"password":"LongText"===s.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[s.type]??"default",..."Email"===s.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[s.type]?{}:{autoComplete:AUTO_COMPLETE[s.type]}},s.key);if(!("Otp"===s.verify&&("Email"===s.type||"Phone"===s.type)))return u;const m=f[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[u,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async i=>{if("Otp"===i.verify)try{await t.sendOtp(e.requestId,{fieldKey:i.key,value:(n[i.key]??"").trim()}),h(e=>({...e,[i.key]:"sent"}))}catch{h(e=>({...e,[i.key]:"failed"}))}})(s)},testID:`otp-send-${s.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:a.inputEnterCode,value:b[s.key]??"",onChangeText:e=>_(t=>({...t,[s.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"failed"===m?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===m?a.inputCodeFailed:a.inputCodeSent}):null]})]},s.key)}),""!==u?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?a.inputSubmitting:e.submitLabel,loading:p,disabled:p||w,onPress:()=>{(async()=>{if(w)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const s="true"===e;t.required&&!s&&(i[t.key]=a.inputConsentRequired),r[t.key]=s?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const s=selectedIds(e);t.required&&0===s.length&&(i[t.key]=a.inputRequired),r[t.key]=JSON.stringify(s)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else{const s=t.secret?e:e.trim();t.required&&""===s&&(i[t.key]=a.inputRequired),r[t.key]=s}}const s={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(b[t.key]??"").trim();""===e&&(i[t.key]=a.inputRequired),s[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&S(t))}m(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(s).length>0?s:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(a.errorGeneric)}m(!1)})()}}),w?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.attachmentUploading}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,q?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]}),e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:a.typeAnswer}):null]})})}function InputRequestPart({part:e,turn:t,pickAttachments:i}){return"Answered"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:e,turn:t,pickAttachments:i},e.requestId)}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const fileNameOf=(e,t)=>{const i="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:a,features:s}=t,[n,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[b,_]=(0,_react.useState)({}),[f,h]=(0,_react.useState)({}),j=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=j.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,w=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(a.errorGeneric),m(!1)}},U=s.LeadShortcuts,T=e.fields[0];if(U&&1===e.fields.length&&void 0===T)throw new Error("A one-field form has no field.");const C=U&&1===e.fields.length&&void 0!==T&&!T.required,q=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...(0,_chatShared.webProps)({role:"form","aria-label":e.title||e.submitLabel}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",...(0,_chatShared.webProps)({"aria-level":3}),children:e.title}):null,e.fields.map(s=>{const l=n[s.key]??"",c=o[s.key];if("File"===s.type){const e=y[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:e?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=s.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{removeText:a.inputRemoveFile(e.fileName)}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:a.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:a.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i(e.accept??void 0)}catch{return void d(a.errorGeneric)}const s=r[0];if(!s)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(s,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(s,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(s)}})})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},s.key)}if("MultiChoice"===s.type){const e=(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(s.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Choice"===s.type||"TimeSlot"===s.type){const e="TimeSlot"===s.type?(s.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(s.key,String(e)),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Consent"===s.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(s.key,e?"true":"false"),label:s.consentText??s.label,...void 0===c?{}:{error:c},disabled:p},s.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{j.current[s.key]=e},label:s.label,..."string"==typeof s.placeholder?{placeholder:s.placeholder}:{},value:l,onChangeText:e=>setValue(s.key,e),..."number"==typeof s.maxLength?{maxLength:s.maxLength}:{},showCounter:!1,required:s.required,...void 0===c?{}:{error:c},...s.required?{}:{help:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.inputOptional})},labelMode:"top",disabled:p,type:s.secret?"password":"LongText"===s.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[s.type]??"default",..."Email"===s.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[s.type]?{}:{autoComplete:AUTO_COMPLETE[s.type]}},s.key);if(!("Otp"===s.verify&&("Email"===s.type||"Phone"===s.type)))return u;const m=f[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[u,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async i=>{if("Otp"===i.verify)try{await t.sendOtp(e.requestId,{fieldKey:i.key,value:(n[i.key]??"").trim()}),h(e=>({...e,[i.key]:"sent"}))}catch{h(e=>({...e,[i.key]:"failed"}))}})(s)},testID:`otp-send-${s.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:a.inputEnterCode,value:b[s.key]??"",onChangeText:e=>_(t=>({...t,[s.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"failed"===m?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===m?a.inputCodeFailed:a.inputCodeSent}):null]})]},s.key)}),""!==u?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?a.inputSubmitting:e.submitLabel,loading:p,disabled:p||w,onPress:()=>{(async()=>{if(w)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const s="true"===e;t.required&&!s&&(i[t.key]=a.inputConsentRequired),r[t.key]=s?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const s=selectedIds(e);t.required&&0===s.length&&(i[t.key]=a.inputRequired),r[t.key]=JSON.stringify(s)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else{const s=t.secret?e:e.trim();t.required&&""===s&&(i[t.key]=a.inputRequired),r[t.key]=s}}const s={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(b[t.key]??"").trim();""===e&&(i[t.key]=a.inputRequired),s[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&S(t))}m(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(s).length>0?s:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(a.errorGeneric)}m(!1)})()}}),w?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.attachmentUploading}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,q?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]}),e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:a.typeAnswer}):null]})})}function InputRequestPart({part:e,turn:t,pickAttachments:i}){return"Answered"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:e,turn:t,pickAttachments:i},e.requestId)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{defaultChatLook}from"@webority/chat-core";import{Permissions}from"@webority/mobile-core/permissions";import{Banner,Chip,Composer,IconButton,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatDictationButton}from"./ChatDictationButton.js";import{ChatFooter}from"./ChatFooter.js";import{webProps}from"./chatShared.js";import{iconNameOf}from"./iconName.js";import{joinDictation}from"./speech/speechText.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};export function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:o,keyboardAware:a,safeArea:n,testID:
|
|
1
|
+
"use strict";import{defaultChatLook}from"@webority/chat-core";import{Permissions}from"@webority/mobile-core/permissions";import{Banner,Chip,Composer,IconButton,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatDictationButton}from"./ChatDictationButton.js";import{ChatFooter}from"./ChatFooter.js";import{webProps}from"./chatShared.js";import{iconNameOf}from"./iconName.js";import{joinDictation}from"./speech/speechText.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};export function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:o,keyboardAware:a,safeArea:n,testID:i="chat-composer",focusRef:r,look:l=defaultChatLook,sendIcon:c}){const m=useTheme(),u=useMemo(()=>buildStyles(m),[m]),[p,d]=useState(""),[f,h]=useState(null),g=e.editing,x=useRef(null),b=useRef(null);useEffect(()=>{if(r)return r.current=()=>b.current?.focus(),()=>{r.current=null}},[r]),useEffect(()=>{g&&x.current?.(),d(g?g.text:"")},[g]);const y=e.attachments,v=y.some(e=>"Uploading"===e.status),j=y.some(e=>"Ready"===e.status),_=e.messagesLeftToday,S=e.profile?.limits.maxMessageLength??4e3,w=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,T=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),A=w&&!e.handoffPause?_jsx(IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${i}-attach`}):void 0,C=g?_jsx(Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${i}-editing`}):null,D=y.length>0?_jsx(View,{style:u.tray,testID:`${i}-attachments`,children:_jsx(View,{style:u.row,children:y.map(s=>_jsxs(View,{style:u.item,children:[_jsx(Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{removeText:t.removeAttachment(s.fileName)},removeTestID:`${i}-remove-${s.key}`,testID:`${i}-chip-${s.key}`}),"Uploading"===s.status?_jsx(ProgressBar,{...null===s.progress||void 0===s.progress?{}:{progress:s.progress},label:t.attachmentUploading,height:4,style:u.progress}):null,"Failed"===s.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.error??t.attachmentFailed}):null]},s.key))})}):null,I=null!==_&&_<=10?_jsx(Text,{variant:"caption",color:0===_?"danger":"secondary",accessibilityLiveRegion:"polite",...webProps({role:"status"}),testID:`${i}-allowance`,children:t.allowance(_)}):null,L=f?_jsx(Banner,{message:f.message,tone:f.tone,dismissible:!0,onClose:()=>h(null),...f.openSettings?{actions:[{label:t.dictateOpenSettings,onPress:()=>{Permissions.openSettings()}}]}:{},testID:`${i}-voice-notice`}):null,R=p.length>0,k=p.length>.9*S?_jsx(Text,{variant:"caption",color:"secondary",testID:`${i}-counter`,children:t.counter(p.length,S)}):null,P=C||D||I||k||L?_jsxs(_Fragment,{children:[C,D,I,k,L]}):void 0,B=!v&&(!!j||void 0),F=iconNameOf(c);return _jsx(Composer,{ref:b,onSend:t=>{x.current?.(),e.submit(t)},value:p,onChangeText:t=>{x.current?.(),d(t),T&&t.length>0&&e.notifyTyping()},loading:e.streaming&&e.features.Stop,ring:l.input.ring&&(R||e.streaming),sendReveal:"Always"===l.input.sendReveal?"always":"onText",...F?{sendIcon:F}:{},...e.features.Stop?{onStop:()=>e.stop()}:{},stopLabel:t.stop,disabled:0===_||e.handoffPause,maxLength:S,...void 0===B?{}:{canSend:B},placeholder:e.handoffPause?t.handoffMoment:openQuestion(e.messages)??t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:A,trailing:_jsx(ChatDictationButton,{chat:e,labels:t,disabled:0===_||e.handoffPause,onText:e=>d(t=>joinDictation(t,e,S)),onNotice:h,stopRef:x}),above:P,below:_jsx(ChatFooter,{chat:e,labels:t}),...void 0===a?{}:{keyboardAware:a},...void 0===o?{}:{keyboardOffset:o},...void 0===n?{}:{safeArea:n},testID:i})}const buildStyles=e=>StyleSheet.create({tray:{gap:e.space.xs},row:{flexDirection:"row",flexWrap:"wrap",gap:e.space.xs},item:{gap:e.space.xxs,maxWidth:"100%"},progress:{minWidth:120}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Button,Card,Checkbox,Chip,ChoiceGroup,Input,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useRef,useState}from"react";import{View}from"react-native";import{focusForAccessibility,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const fileNameOf=(e,t)=>{const r="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof r&&""!==r?r:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:r}){const i=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,b]=useState({}),[h,m]=useState({}),[x,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),w=useRef(!1),T=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const r=g.current[e];r&&focusForAccessibility(r)},[]);useEffect(()=>{if(p||!w.current)return;w.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&T(t)},[p,o,e.fields,T]);const setValue=(e,t)=>l(r=>({...r,[e]:t})),commitUploads=e=>{j.current=e,b(e)},patchUpload=(e,t)=>{const r=j.current[e];r&&commitUploads({...j.current,[e]:{...r,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,C=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},S=a.LeadShortcuts,O=e.fields[0];if(S&&1===e.fields.length&&void 0===O)throw new Error("A one-field form has no field.");const R=S&&1===e.fields.length&&void 0!==O&&!O.required,E=S&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...webProps({role:"form","aria-label":e.title||e.submitLabel}),children:_jsxs(View,{style:{gap:i.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",...webProps({"aria-level":3}),children:e.title}):null,e.fields.map(a=>{const l=n[a.key]??"",c=o[a.key];if("File"===a.type){const e=f[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{...webProps({role:"group","aria-label":a.label}),children:e?_jsxs(View,{style:{gap:i.space.xxs},children:[_jsx(Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=a.key,commitUploads(Object.fromEntries(Object.entries(j.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{
|
|
1
|
+
"use strict";import{Button,Card,Checkbox,Chip,ChoiceGroup,Input,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useRef,useState}from"react";import{View}from"react-native";import{focusForAccessibility,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const fileNameOf=(e,t)=>{const r="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof r&&""!==r?r:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:r}){const i=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,b]=useState({}),[h,m]=useState({}),[x,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),w=useRef(!1),T=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const r=g.current[e];r&&focusForAccessibility(r)},[]);useEffect(()=>{if(p||!w.current)return;w.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&T(t)},[p,o,e.fields,T]);const setValue=(e,t)=>l(r=>({...r,[e]:t})),commitUploads=e=>{j.current=e,b(e)},patchUpload=(e,t)=>{const r=j.current[e];r&&commitUploads({...j.current,[e]:{...r,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,C=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},S=a.LeadShortcuts,O=e.fields[0];if(S&&1===e.fields.length&&void 0===O)throw new Error("A one-field form has no field.");const R=S&&1===e.fields.length&&void 0!==O&&!O.required,E=S&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...webProps({role:"form","aria-label":e.title||e.submitLabel}),children:_jsxs(View,{style:{gap:i.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",...webProps({"aria-level":3}),children:e.title}):null,e.fields.map(a=>{const l=n[a.key]??"",c=o[a.key];if("File"===a.type){const e=f[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{...webProps({role:"group","aria-label":a.label}),children:e?_jsxs(View,{style:{gap:i.space.xxs},children:[_jsx(Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=a.key,commitUploads(Object.fromEntries(Object.entries(j.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{removeText:s.inputRemoveFile(e.fileName)}}),"Uploading"===e.status?_jsx(ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:s.attachmentUploading,height:4}):null,"Failed"===e.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:s.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===r,onPress:()=>{(async e=>{if(!r)return;let i;try{i=await r(e.accept??void 0)}catch{return void d(s.errorGeneric)}const a=i[0];if(!a)return;_.current+=1;const n=_.current;commitUploads({...j.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const r=await t.uploadInputFile(a,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,r),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(a)}})})}),c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},a.key)}if("MultiChoice"===a.type){const e=(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},...webProps({role:"group","aria-label":a.label}),children:_jsx(ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(a.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Choice"===a.type||"TimeSlot"===a.type){const e="TimeSlot"===a.type?(a.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},children:_jsx(ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Consent"===a.type)return _jsx(Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,...void 0===c?{}:{error:c},disabled:p},a.key);const u=_jsx(Input,{ref:e=>{v.current[a.key]=e},label:a.label,..."string"==typeof a.placeholder?{placeholder:a.placeholder}:{},value:l,onChangeText:e=>setValue(a.key,e),..."number"==typeof a.maxLength?{maxLength:a.maxLength}:{},showCounter:!1,required:a.required,...void 0===c?{}:{error:c},...a.required?{}:{help:_jsx(Text,{variant:"caption",color:"secondary",children:s.inputOptional})},labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",..."Email"===a.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[a.type]?{}:{autoComplete:AUTO_COMPLETE[a.type]}},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const y=x[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[u,_jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Button,{label:s.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async r=>{if("Otp"===r.verify)try{await t.sendOtp(e.requestId,{fieldKey:r.key,value:(n[r.key]??"").trim()}),k(e=>({...e,[r.key]:"sent"}))}catch{k(e=>({...e,[r.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),_jsx(Input,{label:s.inputEnterCode,value:h[a.key]??"",onChangeText:e=>m(t=>({...t,[a.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),y?_jsx(Text,{variant:"caption",color:"failed"===y?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===y?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.key)}),""!==u?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[_jsx(Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||C,onPress:()=>{(async()=>{if(C)return;const r={},i={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(r[t.key]=s.inputConsentRequired),i[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(r[t.key]=s.inputRequired),i[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(r[t.key]=s.inputRequired),i[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(h[t.key]??"").trim();""===e&&(r[t.key]=s.inputRequired),a[t.key]=e}if(c(r),Object.keys(r).length>0){const t=firstErrorKey(e.fields,r);return void(void 0!==t&&T(t))}y(!0),d("");try{const r=await t.answerInput(e.requestId,i,Object.keys(a).length>0?a:null);if(r.ok)return;c(r.errors),w.current=!0,d(r.message??"")}catch{d(s.errorGeneric)}y(!1)})()}}),C?_jsx(Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,R?_jsx(Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,E?_jsx(Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]}),e.allowTyped?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:s.typeAnswer}):null]})})}export function InputRequestPart({part:e,turn:t,pickAttachments:r}){return"Answered"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):_jsx(OpenRequest,{part:e,turn:t,pickAttachments:r},e.requestId)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-chat",
|
|
3
|
-
"version": "0.147.
|
|
3
|
+
"version": "0.147.1",
|
|
4
4
|
"description": "Webority Chat for React Native apps: the chat screen, sheet and embedded shells, thread, composer, one renderer per message part kind and the useChat hook, built on @webority/chat-core and @webority/mobile-ui.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"!**/*.map"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@webority/chat-core": "0.147.
|
|
46
|
-
"@webority/markdown-core": "^0.
|
|
47
|
-
"@webority/mobile-core": "^0.
|
|
48
|
-
"@webority/mobile-ui": "^0.
|
|
45
|
+
"@webority/chat-core": "0.147.1",
|
|
46
|
+
"@webority/markdown-core": "^0.167.0",
|
|
47
|
+
"@webority/mobile-core": "^0.167.0",
|
|
48
|
+
"@webority/mobile-ui": "^0.167.0",
|
|
49
49
|
"expo-audio": ">=58.0.0",
|
|
50
50
|
"expo-file-system": ">=58.0.0",
|
|
51
51
|
"react": "^19.3.0",
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
"@testing-library/react-native": "14.1.0",
|
|
99
99
|
"@types/jest": "29.5.14",
|
|
100
100
|
"@types/react": "19.3.0",
|
|
101
|
-
"@webority/canvas-kit": "0.
|
|
102
|
-
"@webority/chat-core": "0.147.
|
|
103
|
-
"@webority/markdown-core": "0.
|
|
104
|
-
"@webority/mobile-core": "0.
|
|
105
|
-
"@webority/mobile-ui": "0.
|
|
101
|
+
"@webority/canvas-kit": "0.167.0",
|
|
102
|
+
"@webority/chat-core": "0.147.1",
|
|
103
|
+
"@webority/markdown-core": "0.167.0",
|
|
104
|
+
"@webority/mobile-core": "0.167.0",
|
|
105
|
+
"@webority/mobile-ui": "0.167.0",
|
|
106
106
|
"babel-jest": "29.7.0",
|
|
107
107
|
"expo": "58.0.23",
|
|
108
108
|
"expo-application": "58.1.2",
|
|
@@ -136,6 +136,6 @@
|
|
|
136
136
|
"lint": "biome lint ./src",
|
|
137
137
|
"lint:fix": "biome lint --write ./src",
|
|
138
138
|
"test": "tsc -p tsconfig.test.json && jest",
|
|
139
|
-
"typecheck": "tsc --noEmit"
|
|
139
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json && tsc --noEmit -p tsconfig.build.json"
|
|
140
140
|
}
|
|
141
141
|
}
|