@1interface/widgets 0.2.0 → 0.4.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/{Chart.web-BWW6NfWY.js → Chart.web-hrwFpYNo.js} +1 -1
- package/dist/{GoogleMapsComponent-6Gx4YaUI.js → GoogleMapsComponent-BzTpTirq.js} +1 -1
- package/dist/{Markdown.web-DSdGESF9.js → Markdown.web-Cb6DGzuq.js} +1 -1
- package/dist/{OpenStreetMapComponent-BWdwxya-.js → OpenStreetMapComponent-DwUAjMIU.js} +1 -1
- package/dist/{constants-DgIER4D0.js → constants-CoEHFWGs.js} +1 -1
- package/dist/index-CuqDLhq-.js +1 -0
- package/dist/index.d.ts +33 -2
- package/dist/index.mjs +1 -1
- package/native/WidgetRenderer.js +2 -2
- package/native/WidgetRenderer.native.js +1 -1
- package/native/compat/WidgetStateContext.js +1 -1
- package/native/components/FileUploadRequest.js +1 -1
- package/native/components/Input.js +1 -1
- package/native/index.js +1 -1
- package/native/schema/widget-types.js +1 -1
- package/native/state/context.js +1 -1
- package/native/state/reducer.js +1 -1
- package/package.json +1 -1
- package/dist/index-D7tB4pMK.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1149,9 +1149,12 @@ export declare interface FieldDescriptor {
|
|
|
1149
1149
|
declare interface FileUploadEntry {
|
|
1150
1150
|
file?: unknown;
|
|
1151
1151
|
fileName?: string | null;
|
|
1152
|
+
fileSize?: number | null;
|
|
1153
|
+
label?: string | null;
|
|
1152
1154
|
uploaded?: boolean;
|
|
1153
1155
|
loading?: boolean;
|
|
1154
1156
|
error?: string | null;
|
|
1157
|
+
documentId?: string | null;
|
|
1155
1158
|
}
|
|
1156
1159
|
|
|
1157
1160
|
export declare function FileUploadRequest(p: FileUploadRequest_2): JSX.Element;
|
|
@@ -1163,6 +1166,8 @@ export declare type FileUploadRequestProps = {
|
|
|
1163
1166
|
key?: string;
|
|
1164
1167
|
label: string;
|
|
1165
1168
|
fileRequestId: string;
|
|
1169
|
+
documentType?: string;
|
|
1170
|
+
required?: boolean;
|
|
1166
1171
|
icon: string;
|
|
1167
1172
|
messageId?: string;
|
|
1168
1173
|
maxFileSize?: number;
|
|
@@ -1311,6 +1316,7 @@ declare type Input_2 = InputProps;
|
|
|
1311
1316
|
|
|
1312
1317
|
export declare const INPUT_TYPES: {
|
|
1313
1318
|
readonly number: "number";
|
|
1319
|
+
readonly currency: "currency";
|
|
1314
1320
|
readonly email: "email";
|
|
1315
1321
|
readonly text: "text";
|
|
1316
1322
|
readonly password: "password";
|
|
@@ -1645,11 +1651,14 @@ export declare const REDUCER_ACTIONS: {
|
|
|
1645
1651
|
readonly TOGGLE_QUANTITY: "TOGGLE_QUANTITY";
|
|
1646
1652
|
readonly UPLOAD_FILE: "UPLOAD_FILE";
|
|
1647
1653
|
readonly REMOVE_FILE: "REMOVE_FILE";
|
|
1654
|
+
readonly SET_UPLOAD_RESULT: "SET_UPLOAD_RESULT";
|
|
1648
1655
|
readonly SET_UPLOAD_ERROR: "SET_UPLOAD_ERROR";
|
|
1649
1656
|
readonly RESET_UPLOADS: "RESET_UPLOADS";
|
|
1650
1657
|
readonly SET_FORM_FIELD: "SET_FORM_FIELD";
|
|
1651
1658
|
};
|
|
1652
1659
|
|
|
1660
|
+
export declare type RemoveFileHandler = (documentId: string) => Promise<void> | void;
|
|
1661
|
+
|
|
1653
1662
|
export declare interface RendererConfig {
|
|
1654
1663
|
scroll: {
|
|
1655
1664
|
allowOrthogonalAxis: boolean;
|
|
@@ -2281,6 +2290,14 @@ export declare type TransitionProps = {
|
|
|
2281
2290
|
children: WidgetComponent;
|
|
2282
2291
|
};
|
|
2283
2292
|
|
|
2293
|
+
export declare type UploadFileHandler = (file: unknown, meta: {
|
|
2294
|
+
fileRequestId: string;
|
|
2295
|
+
documentType?: string;
|
|
2296
|
+
fileName?: string | null;
|
|
2297
|
+
}) => Promise<{
|
|
2298
|
+
documentId: string;
|
|
2299
|
+
}>;
|
|
2300
|
+
|
|
2284
2301
|
declare function useActionHandler(): ActionHandler_2;
|
|
2285
2302
|
export { useActionHandler as defaultActionHandler }
|
|
2286
2303
|
export { useActionHandler as useAction }
|
|
@@ -2446,7 +2463,7 @@ export declare interface WidgetInternalState {
|
|
|
2446
2463
|
formFields: Record<string, string>;
|
|
2447
2464
|
}
|
|
2448
2465
|
|
|
2449
|
-
export declare function WidgetRenderer({ widget, branding, brandingStyles, theme, messageId, onConsumerAction, config, errorFallback, userLocation, direction, }: WidgetRendererProps): default_2.JSX.Element | null;
|
|
2466
|
+
export declare function WidgetRenderer({ widget, branding, brandingStyles, theme, messageId, onConsumerAction, onUploadFile, onRemoveFile, config, errorFallback, userLocation, direction, }: WidgetRendererProps): default_2.JSX.Element | null;
|
|
2450
2467
|
|
|
2451
2468
|
export declare interface WidgetRendererProps {
|
|
2452
2469
|
widget: WidgetRoot | WidgetComponent | null;
|
|
@@ -2455,6 +2472,8 @@ export declare interface WidgetRendererProps {
|
|
|
2455
2472
|
theme?: ThemeMode;
|
|
2456
2473
|
messageId?: string;
|
|
2457
2474
|
onConsumerAction?: (action: ConsumerAction) => void;
|
|
2475
|
+
onUploadFile?: UploadFileHandler;
|
|
2476
|
+
onRemoveFile?: RemoveFileHandler;
|
|
2458
2477
|
config?: DeepPartial<RendererConfig>;
|
|
2459
2478
|
errorFallback?: ReactNode;
|
|
2460
2479
|
userLocation?: LocationCoordinates | null;
|
|
@@ -2494,12 +2513,20 @@ declare type WidgetStateAction = {
|
|
|
2494
2513
|
payload: {
|
|
2495
2514
|
requestId: string;
|
|
2496
2515
|
file: unknown;
|
|
2516
|
+
label?: string;
|
|
2517
|
+
pending?: boolean;
|
|
2497
2518
|
};
|
|
2498
2519
|
} | {
|
|
2499
2520
|
type: typeof REDUCER_ACTIONS.REMOVE_FILE;
|
|
2500
2521
|
payload: {
|
|
2501
2522
|
requestId: string;
|
|
2502
2523
|
};
|
|
2524
|
+
} | {
|
|
2525
|
+
type: typeof REDUCER_ACTIONS.SET_UPLOAD_RESULT;
|
|
2526
|
+
payload: {
|
|
2527
|
+
requestId: string;
|
|
2528
|
+
documentId: string;
|
|
2529
|
+
};
|
|
2503
2530
|
} | {
|
|
2504
2531
|
type: typeof REDUCER_ACTIONS.SET_UPLOAD_ERROR;
|
|
2505
2532
|
payload: {
|
|
@@ -2516,11 +2543,13 @@ declare type WidgetStateAction = {
|
|
|
2516
2543
|
};
|
|
2517
2544
|
};
|
|
2518
2545
|
|
|
2519
|
-
export declare function WidgetStateManager({ messageId, children, onConsumerAction, }: WidgetStateManagerProps_2): JSX.Element;
|
|
2546
|
+
export declare function WidgetStateManager({ messageId, children, onConsumerAction, onUploadFile, onRemoveFile, }: WidgetStateManagerProps_2): JSX.Element;
|
|
2520
2547
|
|
|
2521
2548
|
export declare type WidgetStateManagerProps = {
|
|
2522
2549
|
messageId?: string;
|
|
2523
2550
|
onConsumerAction?: (action: any) => void;
|
|
2551
|
+
onUploadFile?: UploadFileHandler;
|
|
2552
|
+
onRemoveFile?: RemoveFileHandler;
|
|
2524
2553
|
children?: ReactNode;
|
|
2525
2554
|
};
|
|
2526
2555
|
|
|
@@ -2528,6 +2557,8 @@ declare interface WidgetStateManagerProps_2 {
|
|
|
2528
2557
|
messageId?: string;
|
|
2529
2558
|
children: ReactNode;
|
|
2530
2559
|
onConsumerAction?: OnConsumerAction;
|
|
2560
|
+
onUploadFile?: UploadFileHandler;
|
|
2561
|
+
onRemoveFile?: RemoveFileHandler;
|
|
2531
2562
|
}
|
|
2532
2563
|
|
|
2533
2564
|
export declare const WidgetStateProvider: typeof WidgetStateManager;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as a,m as e,B as s,n as t,o as r,p as i,C as o,q as d,t as n,v as u,w as l,x as m,D as g,y as C,z as T,F as c,E as p,G as S,I,H as x,J as A,L as F,K as R,N as W,O as E,R as N,P as O,Q as f,S as h,T as v,U as D,V as L,W as _,X as k,Y as B,Z as M,_ as U,$ as w,a0 as P,a1 as V,a2 as b,a3 as H,e as j,a4 as q,a5 as y,a6 as G,a7 as Y,a8 as z,a9 as J,e as K,e as Q,aa as X,ab as Z,f as $,ac as aa,a as ea,u as sa,ad as ta,ae as ra,af as ia,ag as oa,ah as da,ai as na}from"./index-
|
|
1
|
+
import{A as a,m as e,B as s,n as t,o as r,p as i,C as o,q as d,t as n,v as u,w as l,x as m,D as g,y as C,z as T,F as c,E as p,G as S,I,H as x,J as A,L as F,K as R,N as W,O as E,R as N,P as O,Q as f,S as h,T as v,U as D,V as L,W as _,X as k,Y as B,Z as M,_ as U,$ as w,a0 as P,a1 as V,a2 as b,a3 as H,e as j,a4 as q,a5 as y,a6 as G,a7 as Y,a8 as z,a9 as J,e as K,e as Q,aa as X,ab as Z,f as $,ac as aa,a as ea,u as sa,ad as ta,ae as ra,af as ia,ag as oa,ah as da,ai as na}from"./index-CuqDLhq-.js";import"react/jsx-runtime";import"react";export{a as ACTION_TYPES,e as ActionHandlerContext,s as Badge,t as BasicRoot,r as Box,i as Button,o as CONSUMER_ACTIONS,d as Caption,n as Card,u as Chart,l as Checkbox,m as Col,g as DEFAULT_CONFIG,C as DatePicker,T as Divider,c as FileUploadRequest,p as Form,S as FormContext,I as Icon,x as Image,A as Input,F as Label,R as ListView,W as ListViewItem,E as Markdown,N as REDUCER_ACTIONS,O as RadioGroup,f as Row,h as SELF_CONTAINED_ACTIONS,v as Select,D as Spacer,L as Text,_ as Textarea,k as Title,B as Transition,M as Video,U as WidgetErrorBoundary,w as WidgetRenderer,P as WidgetStateManager,V as WidgetStateProvider,b as WidgetThemeProvider,H as configureMap,j as defaultActionHandler,q as formatOrderItems,y as markRequiredLabels,G as mergeConfig,Y as renderWidget,z as resolveTemplate,J as safeRenderWidget,K as useAction,Q as useActionHandler,X as useFileUploadState,Z as useFormContext,$ as useMessageId,aa as useSelectedCategory,ea as useTheme,sa as useTokens,ta as useVariants,ra as useWidgetDispatch,ia as useWidgetState,oa as useWidgetTheme,da as validateFields,na as validateForm};
|
package/native/WidgetRenderer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as l}from"react/jsx-runtime";import{useRef as C,useState as v,useEffect as N,useCallback as k}from"react";import{ThemeProvider as O,useTheme as A}from"./theme";import{WidgetStateManager as P}from"./state";import{WidgetErrorBoundary as j}from"./WidgetErrorBoundary";import{renderWidget as U}from"./runtime";import{mergeConfig as _}from"./config";import{UserLocationProvider as $}from"./components/Map";import{TEXT_DIRECTIONS as z}from"./schema";const p=390,G=24;function q(e){const t=e.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i)??e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);if(!t)return e;const a=e.startsWith("#"),c=a?parseInt(t[1],16):Number(t[1]),d=a?parseInt(t[2],16):Number(t[2]),g=a?parseInt(t[3],16):Number(t[3]),n=.08,u=Math.round(c*(1-n)+80*n),m=Math.round(d*(1-n)+120*n),f=Math.round(g*(1-n)+200*n);return`rgb(${u}, ${m}, ${f})`}const Y=`
|
|
2
2
|
[data-widget-renderer][data-widget-renderer] *,
|
|
3
3
|
[data-widget-renderer][data-widget-renderer] *::before,
|
|
4
4
|
[data-widget-renderer][data-widget-renderer] *::after {
|
|
@@ -47,4 +47,4 @@ import{jsx as c}from"react/jsx-runtime";import{useRef as W,useState as y,useEffe
|
|
|
47
47
|
[data-widget-renderer][data-widget-dir="rtl"] > * > * {
|
|
48
48
|
direction: ltr;
|
|
49
49
|
}
|
|
50
|
-
`;let
|
|
50
|
+
`;let y=!1;function V(){if(y||typeof document>"u")return;if(document.getElementById("widget-renderer-style")){y=!0;return}const e=document.createElement("style");e.id="widget-renderer-style",e.textContent=Y,document.head.appendChild(e),y=!0}function se({widget:e,branding:t,brandingStyles:a,theme:c="light",messageId:d,onConsumerAction:g,onUploadFile:n,onRemoveFile:u,config:m,errorFallback:f,userLocation:w,direction:b=z.ltr}){const h=C(null),R=C(null),[E,I]=v(1),[M,F]=v(!1),[H,L]=v(void 0),x=k(()=>{const o=h.current;if(!o)return;const r=o.clientWidth;F(s=>s?r<p+G:r<p);const i=Math.min(r<p?r/p:1,1);I(s=>Math.abs(s-i)<.005?s:i)},[]),S=k(()=>{const o=R.current;if(!o)return;const r=o.scrollHeight;L(i=>i!==void 0&&Math.abs(i-r)<1?i:r)},[]);if(N(()=>{V();const o=h.current,r=R.current;if(!o||!r)return;let i=0;const s=()=>{cancelAnimationFrame(i),i=requestAnimationFrame(()=>{x(),S()})},T=new ResizeObserver(s);T.observe(o);const W=new ResizeObserver(s);return W.observe(r),()=>{cancelAnimationFrame(i),T.disconnect(),W.disconnect()}},[x,S]),!e)return null;const B=t??a,D=_(m);return l(O,{branding:B,mode:c,config:D,children:l(P,{messageId:d,onConsumerAction:g,onUploadFile:n,onRemoveFile:u,children:l($,{location:w??null,children:l(X,{outerRef:h,innerRef:R,theme:c,direction:b,needsScaling:M,innerHeight:H,scale:E,errorFallback:f,widget:e})})})})}function X({outerRef:e,innerRef:t,theme:a,direction:c,needsScaling:d,innerHeight:g,scale:n,errorFallback:u,widget:m}){const{tokens:f,variants:w}=A(),b=w.input.soft.bg,h=q(b);return l("div",{ref:e,style:{direction:"ltr",width:"100%",overflow:"hidden",height:d&&g?g*n:void 0},children:l("div",{ref:t,"data-widget-renderer":"","data-widget-dir":c,"data-theme":a,style:{width:d?`${p}px`:"100%",transformOrigin:"top left",transform:d?`scale(${n})`:void 0,WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale","--widget-input-fg":f.color.text,"--widget-input-bg":h},children:l(j,{fallback:u,children:U(m)})})})}export{Y as WIDGET_CSS,se as WidgetRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{View as
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{View as C}from"react-native";import{ThemeProvider as W}from"./theme";import{WidgetStateManager as R}from"./state";import{WidgetErrorBoundary as u}from"./WidgetErrorBoundary";import{renderWidget as y}from"./runtime";import{mergeConfig as v}from"./config";import{UserLocationProvider as F}from"./components/Map";import{TEXT_DIRECTIONS as T}from"./schema";import{rootAlignItems as h}from"./runtime/rootAnchor";function E({widget:o,branding:r,brandingStyles:i,theme:n="light",messageId:t,onConsumerAction:d,onUploadFile:a,onRemoveFile:m,config:l,errorFallback:g,userLocation:p,direction:s=T.ltr}){if(!o)return null;const c=r??i,f=v(l);return e(W,{branding:c,mode:n,config:f,children:e(R,{messageId:t,onConsumerAction:d,onUploadFile:a,onRemoveFile:m,children:e(F,{location:p??null,children:e(C,{style:{width:"100%",direction:"ltr",alignItems:h(s)},children:e(u,{fallback:g,children:y(o)})})})})})}export{E as WidgetRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WidgetStateManager as e,useWidgetState as t,useWidgetDispatch as a,useMessageId as
|
|
1
|
+
import{WidgetStateManager as e,useWidgetState as t,useWidgetDispatch as a,useMessageId as o,useSelectedCategory as r,useFileUploadState as i}from"../state";const p=e;export{e as WidgetStateManager,p as WidgetStateProvider,i as useFileUploadState,o as useMessageId,r as useSelectedCategory,a as useWidgetDispatch,t as useWidgetState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as p,jsxs as
|
|
1
|
+
import{jsx as p,jsxs as E}from"react/jsx-runtime";import{Text as O,View as P,Pressable as x,Platform as z}from"react-native";import{ACTION_TYPES as f}from"../schema";import{PRIMITIVE_KINDS as F,resolveStyle as q,useTheme as M}from"../theme";import{useActionHandler as _,useFileUploadState as v,useMessageId as V}from"../state";import{Icon as T}from"./Icon";import{useRegisterRequired as B,useFieldError as $}from"./Form";let y=null,m=null;try{y=require("expo-document-picker")}catch{y=null}try{m=require("expo-image-picker")}catch{m=null}function G(e){return new Promise(l=>{const n=document.createElement("input");n.type="file",e&&(n.accept=e),n.style.display="none",document.body.appendChild(n);const r=c=>{window.removeEventListener("focus",a),n.remove(),l(c)},a=()=>setTimeout(()=>r(n.files?.[0]??null),300);n.addEventListener("change",()=>r(n.files?.[0]??null)),n.addEventListener("cancel",()=>r(null)),window.addEventListener("focus",a),n.click()})}const t={IDLE:"idle",UPLOADING:"uploading",ERROR:"error",DONE:"done"};function C(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Q(e){const{tokens:l,config:n}=M(),r=_(),a=V(),c=v(e.fileRequestId);B(e.fileRequestId,e.required,"file");const U=$(e.fileRequestId),g=c?.uploaded??e.uploaded,R=c?.fileName??e.fileName,I=c?.fileSize??null,L=c?.error??e.error,i=c?.loading??!1?t.UPLOADING:L?t.ERROR:g?t.DONE:t.IDLE,b=e.maxFileSize??n.fileUpload.maxSizeBytes,S=e.allowedFileExtensions??n.fileUpload.allowedExtensions;function w(o){if(o.size&&o.size>b)return`File too large (max ${Math.round(b/1024/1024)} MB)`;if(S.length>0&&o.name){const d=o.name.toLowerCase().split(".").pop()??"";if(!S.map(s=>s.replace(/^\./,"").toLowerCase()).includes(d))return`Unsupported extension .${d}`}return null}async function A(){try{let o=null;if(z.OS==="web"&&typeof document<"u"){const s=S.map(u=>u.startsWith(".")?u:`.${u}`).join(",");o=await G(s)}else if(y?.getDocumentAsync){const s=await y.getDocumentAsync({type:"*/*"});!s.canceled&&s.assets&&s.assets[0]&&(o=s.assets[0])}else if(m?.launchImageLibraryAsync){const s=await m.launchImageLibraryAsync({mediaTypes:m.MediaTypeOptions?.Images,allowsMultipleSelection:!1});if(!s.canceled&&s.assets&&s.assets[0]){const u=s.assets[0];o={uri:u.uri,name:u.fileName??"photo.jpg",size:u.fileSize,mimeType:u.mimeType}}}else{r({type:f.UPLOAD_ERROR,payload:{fileRequestId:e.fileRequestId,error:"File picker unavailable \u2014 install expo-document-picker or expo-image-picker",...a?{messageId:a}:{}}});return}if(!o)return;const d=w(o);if(d){r({type:f.UPLOAD_ERROR,payload:{fileRequestId:e.fileRequestId,error:d,...a?{messageId:a}:{}}});return}r({type:f.UPLOAD_SELECT,payload:{fileRequestId:e.fileRequestId,file:o,label:e.label,...e.documentType?{documentType:e.documentType}:{},...a?{messageId:a}:{}}})}catch(o){const d=o instanceof Error?o.message:"File selection failed";r({type:f.UPLOAD_ERROR,payload:{fileRequestId:e.fileRequestId,error:d,...a?{messageId:a}:{}}})}}function D(){r({type:f.UPLOAD_REMOVE,payload:{fileRequestId:e.fileRequestId,...a?{messageId:a}:{}}})}const h={...l.layout.fileUpload.row,backgroundColor:l.color.surfaceAlt,borderRadius:l.radius.lg,gap:l.fileUpload.rowGap,paddingVertical:l.fileUpload.padV,paddingHorizontal:l.fileUpload.padH},k=q(h,F.BOX,{hasBackground:!0}),N=i===t.ERROR||i===t.IDLE&&!!U;return E(x,{onPress:i===t.UPLOADING?void 0:g?D:A,disabled:i===t.UPLOADING,style:({pressed:o})=>[k,{opacity:o?l.ui.pressedOpacity:1}],accessibilityRole:"button",accessibilityLabel:i===t.UPLOADING?`Uploading ${R??"file"}`:g?`Remove ${R??"file"}`:e.label,children:[p(T,{name:i===t.ERROR?"alert-triangle":i===t.DONE?"check-circle-filled":e.icon??"upload-01",size:"md",color:i===t.ERROR?"danger":i===t.DONE?"success":"primary"}),E(P,{style:[l.layout.fileUpload.col,{gap:l.fileUpload.colGap}],children:[E(P,{style:l.layout.label.row,children:[p(O,{style:{color:l.color.text,fontFamily:l.font.family,fontSize:l.fileUpload.label.fontSize,fontWeight:l.fileUpload.label.weight,flexShrink:1},numberOfLines:1,children:e.label}),e.required?p(O,{style:{color:l.color.danger.solid,fontFamily:l.font.family,fontSize:l.fileUpload.label.fontSize,marginLeft:l.text.requiredMarker.marginLeft},children:"*"}):null]}),p(O,{style:{color:N?l.color.danger.solid:l.color.textFaint,fontFamily:l.font.family,fontSize:l.fileUpload.hint.fontSize},numberOfLines:i===t.ERROR?2:1,children:i===t.UPLOADING?"Uploading\u2026":i===t.DONE?[R,I!=null?C(I):null].filter(Boolean).join(" \xB7 "):i===t.ERROR?`${L} \u2014 tap to retry`:U??"Tap to select"})]}),i===t.DONE?p(T,{name:"x",size:"sm",color:"secondary"}):null]})}export{Q as FileUploadRequest};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o,jsxs as A}from"react/jsx-runtime";import{useEffect as
|
|
1
|
+
import{jsx as o,jsxs as A}from"react/jsx-runtime";import{useEffect as D,useState as I}from"react";import{Platform as H,Pressable as R,TextInput as W,View as h,Text as b}from"react-native";import{PRIMITIVE_KINDS as N,resolveStyle as M,useTheme as v}from"../theme";import{controlRadius as C}from"../theme/style";import{useActionHandler as w,useMessageId as z,useWidgetDispatch as V,useWidgetState as E}from"../state";import{REDUCER_ACTIONS as F}from"../state";import{useRegisterRequired as $,useFieldError as B}from"./Form";function K(e){switch(e){case"email":return"email-address";case"number":case"currency":case"card_number":case"cvc":return"number-pad";case"tel":return"phone-pad";case"url":return"url";default:return"default"}}function L(e){switch(e){case"email":return"email";case"password":return"password";case"tel":return"tel";case"card_number":return"cc-number";case"cvc":return"cc-csc";case"month_year":return"cc-exp";default:return}}function q(e){return e.replace(/\D/g,"").slice(0,19).replace(/(.{4})/g,"$1 ").trim()}function G(e){const t=e.replace(/\D/g,"").slice(0,4);return t.length<3?t:`${t.slice(0,2)}/${t.slice(2)}`}function U(e){return e.replace(/\D/g,"").slice(0,4)}function X(e){const t=e.replace(/[^\d.]/g,""),a=t.indexOf("."),c=(a===-1?t:t.slice(0,a)).replace(/\B(?=(\d{3})+(?!\d))/g,",");if(a===-1)return c;const u=t.slice(a+1).replace(/\./g,"").slice(0,2);return`${c}.${u}`}function oe(e){const{tokens:t,variants:a}=v(),c=w(),u=V(),g=z(),d=E(),s=t.control.size[e.size],r=a.input[e.variant],T=e.gutterSize?t.control.size[e.gutterSize].padH:s.padH;$(e.name,e.required,e.inputType??"text",e.pattern);const f=B(e.name);if(e.inputType==="counter")return o(j,{...e});const p=d.formFields[e.name],[i,x]=I(p??e.defaultValue??""),[n,m]=I(!1),S=!!f;D(()=>{i!==(d.formFields[e.name]??"")&&u({type:F.SET_FORM_FIELD,payload:{name:e.name,value:i}})},[i]);const _={...t.layout.input.wrap,borderRadius:C(e.size,t,e.pill),backgroundColor:r.bg,borderColor:r.border,borderWidth:r.borderWidth},k=M(_,N.BOX,{controlHeightPx:s.h,hasBackground:r.bg!==void 0});function O(l){let y=l;switch(e.inputType){case"card_number":y=q(l);break;case"month_year":y=G(l);break;case"cvc":y=U(l);break;case"currency":y=X(l);break}x(y),e.onChangeAction&&c({...e.onChangeAction,payload:{...e.onChangeAction.payload??{},[e.name]:y,...g?{messageId:g}:{}}})}function P(){if(e.pattern)try{const l=new RegExp(e.pattern);m(!l.test(i))}catch{}}return A(h,{children:[o(h,{style:[k,S?{borderColor:t.color.danger.solid}:null],children:o(W,{value:i,onChangeText:O,onBlur:P,placeholder:e.placeholder,placeholderTextColor:t.color.placeholder,editable:!e.disabled,autoFocus:e.autoFocus,selectTextOnFocus:!!e.autoSelect,secureTextEntry:e.inputType==="password",keyboardType:K(e.inputType),autoComplete:e.allowAutofillExtensions===!1?"off":L(e.inputType),style:[t.layout.input.field,{fontSize:s.font,color:r.fg,caretColor:r.fg,fontFamily:t.font.family,outlineStyle:"none",paddingHorizontal:T,...H.OS==="web"?{height:"100%"}:{flex:1,paddingVertical:Math.max(6,(s.h-s.font-4)/2)},borderRadius:C(e.size,t,e.pill)},n?{color:t.color.danger.solid}:null]})}),S?o(b,{style:{color:t.color.danger.solid,fontSize:12,marginTop:4,fontFamily:t.font.family},children:f}):null]})}function j(e){const{tokens:t}=v(),a=w(),c=V(),u=z(),g=E(),d=t.control.size[e.size],s=g.formFields[e.name]??e.defaultValue??"0",[r,T]=I(()=>parseInt(s,10)||0);function f(n){if(e.disabled)return;const m=Math.max(0,r+n);T(m),c({type:F.SET_FORM_FIELD,payload:{name:e.name,value:String(m)}}),e.onChangeAction&&a({...e.onChangeAction,payload:{...e.onChangeAction.payload??{},name:e.name,delta:n,value:m,...u?{messageId:u}:{}}})}const p=n=>({...t.layout.counter.btn,width:t.counter.btn,height:t.counter.btn,borderRadius:t.counter.btnRadius,opacity:n?t.ui.pressedOpacity:1}),i={color:t.color.text,fontSize:t.counter.glyph.fontSize,fontWeight:t.counter.glyph.weight,lineHeight:t.counter.glyph.lineHeight},x={height:d.h,minWidth:t.counter.valueMinWidth,paddingHorizontal:t.space[12],borderRadius:C(e.size,t,e.pill),borderColor:t.color.borderInput,borderWidth:t.ui.hairlineBorder,alignItems:"center",justifyContent:"center"};return A(h,{style:[t.layout.counter.row,{gap:t.counter.rowGap,height:d.h}],children:[o(R,{accessibilityLabel:`Decrease ${e.name}`,onPress:()=>f(-1),disabled:e.disabled,style:({pressed:n})=>p(n),children:o(b,{style:i,children:"\u2212"})}),o(h,{style:x,children:o(b,{style:[t.layout.counter.valueText,{color:t.color.text,fontSize:d.font,fontWeight:t.font.weight.normal}],children:r})}),o(R,{accessibilityLabel:`Increase ${e.name}`,onPress:()=>f(1),disabled:e.disabled,style:({pressed:n})=>p(n),children:o(b,{style:i,children:"+"})})]})}export{oe as Input};
|
package/native/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Badge as
|
|
1
|
+
import{Badge as r}from"./components/Badge";import{BasicRoot as a}from"./components/BasicRoot";import{Box as p,Row as m,Col as d}from"./components/Box";import{Button as f}from"./components/Button";import{Card as s}from"./components/Card";import{Checkbox as g}from"./components/Checkbox";import{DatePicker as u}from"./components/DatePicker";import{Divider as W}from"./components/Divider";import{FileUploadRequest as T}from"./components/FileUploadRequest";import{Form as R}from"./components/Form";import{Icon as h}from"./components/Icon";import{Image as I}from"./components/Image";import{Video as E}from"./components/Video";import{Input as O}from"./components/Input";import{Label as v}from"./components/Text";import{ListView as N,ListViewItem as w}from"./components/ListView";import{RadioGroup as H}from"./components/RadioGroup";import{Select as U}from"./components/Select";import{Spacer as _}from"./components/Spacer";import{Text as q,Title as G,Caption as Y}from"./components/Text";import{Textarea as z}from"./components/Textarea";import{Transition as K}from"./components/Transition";import{ChartWidget as X}from"./components/ChartWidget";import{MarkdownWidget as $}from"./components/MarkdownWidget";import{WidgetThemeProvider as oe,useWidgetTheme as re}from"./compat/WidgetThemeContext";import{WidgetRenderer as ae}from"./WidgetRenderer";import{WidgetErrorBoundary as pe}from"./WidgetErrorBoundary";import{WidgetStateManager as de,useMessageId as ne,useSelectedCategory as fe,useFileUploadState as xe,WidgetStateProvider as se}from"./compat/WidgetStateContext";import{ACTION_TYPES as ge,SELF_CONTAINED_ACTIONS as Ce,CONSUMER_ACTIONS as ue}from"./schema";import{renderWidget as We}from"./runtime";import{safeRenderWidget as Te}from"./utils/safeRender";import{useActionHandler as Re,formatOrderItems as Fe,resolveTemplate as he,ActionHandlerContext as Ae,defaultActionHandler as Ie}from"./utils/widgetUtils";import{useWidgetState as Ee,useWidgetDispatch as Me,useActionHandler as Oe}from"./state";import{REDUCER_ACTIONS as ve}from"./state";import{validateFields as Ne}from"./utils/formValidationCore";import{validateForm as Be,markRequiredLabels as He}from"./utils/formValidation";import{useFormContext as Ue,FormContext as ke}from"./compat/FormContext";import{useTheme as be,useTokens as qe,useVariants as Ge}from"./theme";import{mergeConfig as je,DEFAULT_CONFIG as ze}from"./config";import{configureMap as Ke}from"./components/Map";export{ge as ACTION_TYPES,Ae as ActionHandlerContext,r as Badge,a as BasicRoot,p as Box,f as Button,ue as CONSUMER_ACTIONS,Y as Caption,s as Card,X as Chart,g as Checkbox,d as Col,ze as DEFAULT_CONFIG,u as DatePicker,W as Divider,T as FileUploadRequest,R as Form,ke as FormContext,h as Icon,I as Image,O as Input,v as Label,N as ListView,w as ListViewItem,$ as Markdown,ve as REDUCER_ACTIONS,H as RadioGroup,m as Row,Ce as SELF_CONTAINED_ACTIONS,U as Select,_ as Spacer,q as Text,z as Textarea,G as Title,K as Transition,E as Video,pe as WidgetErrorBoundary,ae as WidgetRenderer,de as WidgetStateManager,se as WidgetStateProvider,oe as WidgetThemeProvider,Ke as configureMap,Ie as defaultActionHandler,Fe as formatOrderItems,He as markRequiredLabels,je as mergeConfig,We as renderWidget,he as resolveTemplate,Te as safeRenderWidget,Oe as useAction,Re as useActionHandler,xe as useFileUploadState,Ue as useFormContext,ne as useMessageId,fe as useSelectedCategory,be as useTheme,qe as useTokens,Ge as useVariants,Me as useWidgetDispatch,Ee as useWidgetState,re as useWidgetTheme,Ne as validateFields,Be as validateForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={Basic:"Basic",Card:"Card",ListView:"ListView",ListViewItem:"ListViewItem",Box:"Box",Row:"Row",Col:"Col",Form:"Form",Spacer:"Spacer",Divider:"Divider",Transition:"Transition",Title:"Title",Caption:"Caption",Text:"Text",Markdown:"Markdown",Badge:"Badge",Icon:"Icon",Image:"Image",Video:"Video",Button:"Button",Input:"Input",Textarea:"Textarea",Select:"Select",DatePicker:"DatePicker",Checkbox:"Checkbox",RadioGroup:"RadioGroup",Label:"Label",Chart:"Chart",FileUploadRequest:"FileUploadRequest",Map:"Map",MapMarker:"MapMarker",MapPolyline:"MapPolyline",MapCircle:"MapCircle",MapPolygon:"MapPolygon"},t={row:"row",col:"col"},o={ltr:"ltr",rtl:"rtl"},r={start:"start",center:"center",end:"end",baseline:"baseline",stretch:"stretch"},n={start:"start",center:"center",end:"end",between:"between",around:"around",evenly:"evenly",stretch:"stretch"},i={nowrap:"nowrap",wrap:"wrap","wrap-reverse":"wrap-reverse"},p={start:"start",center:"center",end:"end"},s={normal:"normal",medium:"medium",semibold:"semibold",bold:"bold"},a={light:"light",dark:"dark"},l={clear:"clear"},
|
|
1
|
+
const e={Basic:"Basic",Card:"Card",ListView:"ListView",ListViewItem:"ListViewItem",Box:"Box",Row:"Row",Col:"Col",Form:"Form",Spacer:"Spacer",Divider:"Divider",Transition:"Transition",Title:"Title",Caption:"Caption",Text:"Text",Markdown:"Markdown",Badge:"Badge",Icon:"Icon",Image:"Image",Video:"Video",Button:"Button",Input:"Input",Textarea:"Textarea",Select:"Select",DatePicker:"DatePicker",Checkbox:"Checkbox",RadioGroup:"RadioGroup",Label:"Label",Chart:"Chart",FileUploadRequest:"FileUploadRequest",Map:"Map",MapMarker:"MapMarker",MapPolyline:"MapPolyline",MapCircle:"MapCircle",MapPolygon:"MapPolygon"},t={row:"row",col:"col"},o={ltr:"ltr",rtl:"rtl"},r={start:"start",center:"center",end:"end",baseline:"baseline",stretch:"stretch"},n={start:"start",center:"center",end:"end",between:"between",around:"around",evenly:"evenly",stretch:"stretch"},i={nowrap:"nowrap",wrap:"wrap","wrap-reverse":"wrap-reverse"},p={start:"start",center:"center",end:"end"},s={normal:"normal",medium:"medium",semibold:"semibold",bold:"bold"},a={light:"light",dark:"dark"},l={clear:"clear"},y={"2xs":"2xs",xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl","4xl":"4xl",full:"full","100%":"100%",none:"none"},g={solid:"solid",dashed:"dashed",dotted:"dotted",double:"double",groove:"groove",ridge:"ridge",inset:"inset",outset:"outset"},d={cover:"cover",contain:"contain",fill:"fill","scale-down":"scale-down",none:"none"},c={"top left":"top left",top:"top","top right":"top right",left:"left",center:"center",right:"right","bottom left":"bottom left",bottom:"bottom","bottom right":"bottom right"},x={solid:"solid",soft:"soft",outline:"outline",ghost:"ghost",tabs:"tabs"},u={soft:"soft",outline:"outline"},S={"3xs":"3xs","2xs":"2xs",xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl"},b={"2xs":"2xs",xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"},m={"2xs":"2xs",xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl"},T={sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl","4xl":"4xl","5xl":"5xl"},f={sm:"sm",md:"md",lg:"lg"},I={xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl",button:"button"},C={sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl"},P={sm:"sm",md:"md",lg:"lg",full:"full"},E={primary:"primary",secondary:"secondary",info:"info",discovery:"discovery",success:"success",caution:"caution",warning:"warning",danger:"danger"},k={primary:"primary",secondary:"secondary"},A={primary:"primary",secondary:"secondary",success:"success",danger:"danger",warning:"warning",info:"info",discovery:"discovery"},h={solid:"solid",soft:"soft",outline:"outline"},_={sm:"sm",md:"md",lg:"lg"},O={number:"number",currency:"currency",email:"email",text:"text",password:"password",tel:"tel",url:"url",card_number:"card_number",month_year:"month_year",cvc:"cvc",counter:"counter"},M={top:"top",bottom:"bottom",left:"left",right:"right"},R={start:"start",center:"center",end:"end"},B={auto:"auto",metadata:"metadata",none:"none"},V="auto",w={display:"display",input:"input"},N={bar:"bar",area:"area",line:"line"},D={basis:"basis",basisClosed:"basisClosed",basisOpen:"basisOpen",bumpX:"bumpX",bumpY:"bumpY",bump:"bump",linear:"linear",linearClosed:"linearClosed",natural:"natural",monotoneX:"monotoneX",monotoneY:"monotoneY",monotone:"monotone",step:"step",stepBefore:"stepBefore",stepAfter:"stepAfter"};export{r as ALIGNMENTS,A as BADGE_COLORS,_ as BADGE_SIZES,h as BADGE_VARIANTS,g as BORDER_STYLES,E as BUTTON_COLORS,C as BUTTON_ICON_SIZES,k as BUTTON_STYLE_SHORTHANDS,f as CAPTION_SIZES,P as CARD_SIZES,S as CONTROL_SIZES,x as CONTROL_VARIANTS,D as CURVE_TYPES,t as DIRECTIONS,d as FIT_MODES,s as FONT_WEIGHTS,b as GUTTER_SIZES,I as ICON_SIZES,c as IMAGE_POSITIONS,O as INPUT_TYPES,u as INPUT_VARIANTS,n as JUSTIFICATIONS,V as LIMIT_AUTO,w as MAP_MODES,R as POPOVER_ALIGNS,M as POPOVER_SIDES,B as PRELOAD_MODES,y as RADIUS_VALUES,N as SERIES_TYPES,p as TEXT_ALIGNS,o as TEXT_DIRECTIONS,m as TEXT_SIZES,a as THEME_MODES,l as TINTS,T as TITLE_SIZES,e as WIDGET_TYPES,i as WRAP_MODES};
|
package/native/state/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as b}from"react/jsx-runtime";import{createContext as L,useCallback as W,useContext as S,useMemo as N,useReducer as H,useRef as y}from"react";import{Linking as M}from"react-native";import{ACTION_TYPES as a,CONSUMER_ACTIONS as j,SELF_CONTAINED_ACTIONS as q}from"../schema";import{createInitialWidgetState as U,REDUCER_ACTIONS as c,widgetStateReducer as G}from"./reducer";import{useRendererConfig as V}from"../theme/ThemeContext";import{DEFAULT_CONFIG as B}from"../config";const Y=i=>{console.warn("[widget-renderer] action dispatched outside WidgetStateManager:",i)},k=L(Y);function te(){return S(k)}const A=L({state:U(),dispatch:()=>{}});function ne({messageId:i,children:l,onConsumerAction:p,onUploadFile:s,onRemoveFile:r}){const[d,o]=H(G,void 0,U),m=V(),f=y(d);f.current=d;const C=y(p);C.current=p;const I=y(s);I.current=s;const g=y(r);g.current=r;const _=y(m);_.current=m;const x=y(i);x.current=i;const F=N(()=>({messageId:i,state:d,dispatch:o}),[i,d]),P=W(O=>{if(!O?.type)return;const u=O.type,e=O.payload||{};if(u===a.URL){const t=e.text;typeof t=="string"&&t&&M.openURL(t).catch(()=>{});return}if(q.has(u)){switch(u){case a.TABS:o({type:c.SET_SELECTED_CATEGORY,payload:{id:String(e.id??"")}});break;case a.DATA_CHECKBOX:case a.DATA_SELECT:o({type:c.TOGGLE_CHECKBOX,payload:{data:String(e.data??"")}});break;case a.QUANTITY_CHANGE:{const t=String(e.name??""),n=Number(e.delta??0);o({type:c.TOGGLE_QUANTITY,payload:{id:t,delta:Number.isFinite(n)?n:0}});break}case a.UPLOAD_SELECT:{const t=String(e.fileRequestId??""),n=e.file,E=typeof e.label=="string"?e.label:void 0,T=I.current;if(!T){o({type:c.UPLOAD_FILE,payload:{requestId:t,file:n,label:E}});break}const w=typeof e.documentType=="string"?e.documentType:void 0,D=n&&typeof n=="object"&&"name"in n&&String(n.name??"")||null,h=f.current.fileUpload.files[t]?.documentId,v=g.current;h&&v&&Promise.resolve(v(h)).catch(R=>{console.warn("[widget-renderer] document delete failed",R)}),o({type:c.UPLOAD_FILE,payload:{requestId:t,file:n,label:E,pending:!0}}),T(n,{fileRequestId:t,documentType:w,fileName:D}).then(R=>{o({type:c.SET_UPLOAD_RESULT,payload:{requestId:t,documentId:R.documentId}})}).catch(R=>{o({type:c.SET_UPLOAD_ERROR,payload:{requestId:t,error:R instanceof Error?R.message:"Upload failed"}})});break}case a.UPLOAD_REMOVE:{const t=String(e.fileRequestId??""),n=f.current.fileUpload.files[t]?.documentId,E=g.current;n&&E&&Promise.resolve(E(n)).catch(T=>{console.warn("[widget-renderer] document delete failed",T)}),o({type:c.REMOVE_FILE,payload:{requestId:t}});break}case a.UPLOAD_ERROR:o({type:c.SET_UPLOAD_ERROR,payload:{requestId:String(e.fileRequestId??""),error:typeof e.error=="string"?e.error:null}});break}return}if(j.has(u)){const t=f.current,n={...e};x.current&&!n.messageId&&(n.messageId=x.current),u===a.REPLY_TEMPLATE&&(n.resolvedText=K(String(e.text??""),t,e,_.current)),u===a.ORDER_SUBMIT&&(n.resolvedText=Q(t.formFields)),C.current?.({type:u,payload:n,state:t});return}console.warn("[widget-renderer] unhandled action",u,e)},[]);return b(A.Provider,{value:F,children:b(k.Provider,{value:P,children:l})})}function re(){return S(A).state}function oe(){return S(A).dispatch}function ie(){return S(A).messageId}function ae(){return S(A).state.selectedCategory}function se(i){return S(A).state.fileUpload.files[i]}function K(i,l,p={},s=B){let r=i;const d=l.checkboxes?.selected?.join(", ")||"";r=r.split(s.template.dataSelectToken).join(d),r=r.split(s.template.dataCheckboxToken).join(d);const{text:o,messageId:m,...f}=p,C=Object.values(f).filter(Boolean).join(", ");return r=r.split(s.template.dataInputToken).join(C),l.formFields&&(r=r.replace(new RegExp(s.template.dataFieldPattern.source,"g"),(I,g)=>l.formFields?.[g]||"")),r=r.replace(new RegExp(s.template.formPlaceholderPattern.source,"g"),(I,g)=>String(f[g.trim()]??"")),r}function Q(i){const l=Object.entries(i),p=l.filter(([r])=>r.startsWith("items."));return(p.length>0?p:l).map(([r,d])=>{const o=Number(d);if(!Number.isFinite(o)||o<=0)return null;const m=r.replace(/^items\./,"");return`${o}x ${m}`}).filter(Boolean).join(", ")}export{k as ActionHandlerContext,ne as WidgetStateManager,Q as formatOrderItems,K as resolveTemplate,te as useActionHandler,se as useFileUploadState,ie as useMessageId,ae as useSelectedCategory,oe as useWidgetDispatch,re as useWidgetState};
|
package/native/state/reducer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(){return{fileUpload:{files:{},loading:!1,error:null},checkboxes:{selected:[],disabled:[],maxSelection:20},quantities:{},selectedCategory:void 0,formFields:{}}}const d={TOGGLE_CHECKBOX:"TOGGLE_CHECKBOX",SET_CHECKBOX_DATA:"SET_CHECKBOX_DATA",CLEAR_SELECTIONS:"CLEAR_SELECTIONS",SET_SELECTED_CATEGORY:"SET_SELECTED_CATEGORY",TOGGLE_QUANTITY:"TOGGLE_QUANTITY",UPLOAD_FILE:"UPLOAD_FILE",REMOVE_FILE:"REMOVE_FILE",SET_UPLOAD_RESULT:"SET_UPLOAD_RESULT",SET_UPLOAD_ERROR:"SET_UPLOAD_ERROR",RESET_UPLOADS:"RESET_UPLOADS",SET_FORM_FIELD:"SET_FORM_FIELD"};function u(e,r){switch(r.type){case d.TOGGLE_CHECKBOX:{const{data:l}=r.payload,{selected:n,maxSelection:i}=e.checkboxes;return n.includes(l)?{...e,checkboxes:{...e.checkboxes,selected:n.filter(o=>o!==l)}}:n.length>=i?e:{...e,checkboxes:{...e.checkboxes,selected:[...n,l]}}}case d.SET_CHECKBOX_DATA:{const{data:l,checked:n}=r.payload,{selected:i,maxSelection:o}=e.checkboxes,E=i.includes(l);return n===E?e:n?i.length>=o?e:{...e,checkboxes:{...e.checkboxes,selected:[...i,l]}}:{...e,checkboxes:{...e.checkboxes,selected:i.filter(a=>a!==l)}}}case d.CLEAR_SELECTIONS:return{...e,checkboxes:{...e.checkboxes,disabled:e.checkboxes.selected,selected:[]}};case d.SET_SELECTED_CATEGORY:return{...e,selectedCategory:r.payload.id};case d.TOGGLE_QUANTITY:{const{id:l,delta:n}=r.payload;if(!l||n===0)return e;const i=e.quantities[l]??0,o=Math.max(0,i+n),E={...e.quantities};return o===0?delete E[l]:E[l]=o,{...e,quantities:E}}case d.UPLOAD_FILE:{const{requestId:l,file:n,label:i,pending:o}=r.payload,E=(n&&typeof n=="object"&&"name"in n?String(n.name??""):null)||null,a=n&&typeof n=="object"&&"size"in n?n.size:null,t=typeof a=="number"?a:null,{[l]:c,...s}=e.formFields;return{...e,formFields:o?s:{...s,[l]:E??"uploaded"},fileUpload:{...e.fileUpload,loading:!1,files:{...e.fileUpload.files,[l]:{file:n,fileName:E,fileSize:t,label:i??null,uploaded:!o,loading:!!o,error:null,documentId:null}}}}}case d.SET_UPLOAD_RESULT:{const{requestId:l,documentId:n}=r.payload;return e.fileUpload.files[l]?{...e,formFields:{...e.formFields,[l]:e.fileUpload.files[l]?.fileName??"uploaded"},fileUpload:{...e.fileUpload,files:{...e.fileUpload.files,[l]:{...e.fileUpload.files[l],uploaded:!0,loading:!1,error:null,documentId:n}}}}:e}case d.REMOVE_FILE:{const{requestId:l}=r.payload,{[l]:n,...i}=e.fileUpload.files,{[l]:o,...E}=e.formFields;return{...e,formFields:E,fileUpload:{...e.fileUpload,files:i}}}case d.SET_UPLOAD_ERROR:{const{requestId:l,error:n}=r.payload;if(!e.fileUpload.files[l])return e;const{[l]:i,...o}=e.formFields;return{...e,formFields:o,fileUpload:{...e.fileUpload,files:{...e.fileUpload.files,[l]:{...e.fileUpload.files[l],error:n,uploaded:!1,fileName:null,fileSize:null,loading:!1,documentId:null}}}}}case d.RESET_UPLOADS:return{...e,fileUpload:f().fileUpload};case d.SET_FORM_FIELD:{const{name:l,value:n}=r.payload;return{...e,formFields:{...e.formFields,[l]:n}}}default:return e}}export{d as REDUCER_ACTIONS,f as createInitialWidgetState,u as widgetStateReducer};
|