@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/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-D7tB4pMK.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};
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};
@@ -1,4 +1,4 @@
1
- import{jsx as c}from"react/jsx-runtime";import{useRef as W,useState as y,useEffect as H,useCallback as C}from"react";import{ThemeProvider as N,useTheme as O}from"./theme";import{WidgetStateManager as A}from"./state";import{WidgetErrorBoundary as P}from"./WidgetErrorBoundary";import{renderWidget as F}from"./runtime";import{mergeConfig as j}from"./config";import{UserLocationProvider as _}from"./components/Map";import{TEXT_DIRECTIONS as $}from"./schema";const w=390,z=24;function G(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("#"),l=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(l*(1-n)+80*n),f=Math.round(d*(1-n)+120*n),m=Math.round(g*(1-n)+200*n);return`rgb(${u}, ${f}, ${m})`}const q=`
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 R=!1;function U(){if(R||typeof document>"u")return;if(document.getElementById("widget-renderer-style")){R=!0;return}const e=document.createElement("style");e.id="widget-renderer-style",e.textContent=q,document.head.appendChild(e),R=!0}function ae({widget:e,branding:t,brandingStyles:a,theme:l="light",messageId:d,onConsumerAction:g,config:n,errorFallback:u,userLocation:f,direction:m=$.ltr}){const h=W(null),p=W(null),[b,k]=y(1),[E,I]=y(!1),[M,L]=y(void 0),v=C(()=>{const o=h.current;if(!o)return;const r=o.clientWidth;I(s=>s?r<w+z:r<w);const i=Math.min(r<w?r/w:1,1);k(s=>Math.abs(s-i)<.005?s:i)},[]),x=C(()=>{const o=p.current;if(!o)return;const r=o.scrollHeight;L(i=>i!==void 0&&Math.abs(i-r)<1?i:r)},[]);if(H(()=>{U();const o=h.current,r=p.current;if(!o||!r)return;let i=0;const s=()=>{cancelAnimationFrame(i),i=requestAnimationFrame(()=>{v(),x()})},S=new ResizeObserver(s);S.observe(o);const T=new ResizeObserver(s);return T.observe(r),()=>{cancelAnimationFrame(i),S.disconnect(),T.disconnect()}},[v,x]),!e)return null;const B=t??a,D=j(n);return c(N,{branding:B,mode:l,config:D,children:c(A,{messageId:d,onConsumerAction:g,children:c(_,{location:f??null,children:c(Y,{outerRef:h,innerRef:p,theme:l,direction:m,needsScaling:E,innerHeight:M,scale:b,errorFallback:u,widget:e})})})})}function Y({outerRef:e,innerRef:t,theme:a,direction:l,needsScaling:d,innerHeight:g,scale:n,errorFallback:u,widget:f}){const{tokens:m,variants:h}=O(),p=h.input.soft.bg,b=G(p);return c("div",{ref:e,style:{direction:"ltr",width:"100%",overflow:"hidden",height:d&&g?g*n:void 0},children:c("div",{ref:t,"data-widget-renderer":"","data-widget-dir":l,"data-theme":a,style:{width:d?`${w}px`:"100%",transformOrigin:"top left",transform:d?`scale(${n})`:void 0,WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale","--widget-input-fg":m.color.text,"--widget-input-bg":b},children:c(P,{fallback:u,children:F(f)})})})}export{q as WIDGET_CSS,ae as WidgetRenderer};
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 c}from"react-native";import{ThemeProvider as f}from"./theme";import{WidgetStateManager as C}from"./state";import{WidgetErrorBoundary as W}from"./WidgetErrorBoundary";import{renderWidget as u}from"./runtime";import{mergeConfig as y}from"./config";import{UserLocationProvider as R}from"./components/Map";import{TEXT_DIRECTIONS as T}from"./schema";import{rootAlignItems as h}from"./runtime/rootAnchor";function E({widget:o,branding:r,brandingStyles:t,theme:i="light",messageId:n,onConsumerAction:d,config:a,errorFallback:m,userLocation:g,direction:s=T.ltr}){if(!o)return null;const l=r??t,p=y(a);return e(f,{branding:l,mode:i,config:p,children:e(C,{messageId:n,onConsumerAction:d,children:e(R,{location:g??null,children:e(c,{style:{width:"100%",direction:"ltr",alignItems:h(s)},children:e(W,{fallback:m,children:u(o)})})})})})}export{E as WidgetRenderer};
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 r,useSelectedCategory as o,useFileUploadState as i}from"../state";const p=e;export{e as WidgetStateManager,p as WidgetStateProvider,i as useFileUploadState,r as useMessageId,o as useSelectedCategory,a as useWidgetDispatch,t as useWidgetState};
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 U}from"react/jsx-runtime";import{Text as b,View as x,Pressable as z}from"react-native";import{ACTION_TYPES as r}from"../schema";import{PRIMITIVE_KINDS as T,resolveStyle as q,useTheme as M}from"../theme";import{useActionHandler as O,useFileUploadState as F,useMessageId as E}from"../state";import{Icon as w}from"./Icon";let m=null,c=null;try{m=require("expo-document-picker")}catch{m=null}try{c=require("expo-image-picker")}catch{c=null}function v(t){const{tokens:e,config:y}=M(),n=O(),i=E(),f=F(t.fileRequestId),s=f?.uploaded??t.uploaded,g=f?.fileName??t.fileName,u=f?.error??t.error,R=t.maxFileSize??y.fileUpload.maxSizeBytes,I=t.allowedFileExtensions??y.fileUpload.allowedExtensions;function S(l){if(l.size&&l.size>R)return`File too large (max ${Math.round(R/1024/1024)} MB)`;if(I.length>0&&l.name){const a=l.name.toLowerCase().split(".").pop()??"";if(!I.map(o=>o.replace(/^\./,"").toLowerCase()).includes(a))return`Unsupported extension .${a}`}return null}async function h(){try{let l=null;if(m?.getDocumentAsync){const o=await m.getDocumentAsync({type:"*/*"});!o.canceled&&o.assets&&o.assets[0]&&(l=o.assets[0])}else if(c?.launchImageLibraryAsync){const o=await c.launchImageLibraryAsync({mediaTypes:c.MediaTypeOptions?.Images,allowsMultipleSelection:!1});if(!o.canceled&&o.assets&&o.assets[0]){const d=o.assets[0];l={uri:d.uri,name:d.fileName??"photo.jpg",size:d.fileSize,mimeType:d.mimeType}}}else{n({type:r.UPLOAD_ERROR,payload:{fileRequestId:t.fileRequestId,error:"File picker unavailable \u2014 install expo-document-picker or expo-image-picker",...i?{messageId:i}:{}}});return}if(!l)return;const a=S(l);if(a){n({type:r.UPLOAD_ERROR,payload:{fileRequestId:t.fileRequestId,error:a,...i?{messageId:i}:{}}});return}n({type:r.UPLOAD_SELECT,payload:{fileRequestId:t.fileRequestId,file:l,...i?{messageId:i}:{}}})}catch(l){const a=l instanceof Error?l.message:"File selection failed";n({type:r.UPLOAD_ERROR,payload:{fileRequestId:t.fileRequestId,error:a,...i?{messageId:i}:{}}})}}function k(){n({type:r.UPLOAD_REMOVE,payload:{fileRequestId:t.fileRequestId,...i?{messageId:i}:{}}})}const P={...e.layout.fileUpload.row,backgroundColor:e.color.surfaceAlt,borderRadius:e.radius.lg,gap:e.fileUpload.rowGap,paddingVertical:e.fileUpload.padV,paddingHorizontal:e.fileUpload.padH},A=q(P,T.BOX,{hasBackground:!0});return U(z,{onPress:s?k:h,style:({pressed:l})=>[A,{opacity:l?e.ui.pressedOpacity:1}],accessibilityRole:"button",accessibilityLabel:s?`Remove ${g??"file"}`:t.label,children:[p(w,{name:u?"alert-triangle":s?"check":t.icon??"upload",size:"md",color:u?"danger":s?"success":"primary"}),U(x,{style:[e.layout.fileUpload.col,{gap:e.fileUpload.colGap}],children:[p(b,{style:{color:e.color.text,fontFamily:e.font.family,fontSize:e.fileUpload.label.fontSize,fontWeight:e.fileUpload.label.weight},numberOfLines:1,children:u??g??t.label}),!s&&!u?p(b,{style:{color:e.color.textFaint,fontFamily:e.font.family,fontSize:e.fileUpload.hint.fontSize},children:"Tap to select"}):null]}),s?p(w,{name:"x",size:"sm",color:"secondary"}):null]})}export{v as FileUploadRequest};
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 H,useState as I}from"react";import{Platform as O,Pressable as R,TextInput as W,View as g,Text as p}from"react-native";import{PRIMITIVE_KINDS as N,resolveStyle as M,useTheme as v}from"../theme";import{controlRadius as S}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 B,useFieldError as K}from"./Form";function $(e){switch(e){case"email":return"email-address";case"number":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 ne(e){const{tokens:t,variants:h}=v(),b=w(),y=V(),m=z(),s=E(),i=t.control.size[e.size],r=h.input[e.variant],T=e.gutterSize?t.control.size[e.gutterSize].padH:i.padH;B(e.name,e.required,e.inputType??"text",e.pattern);const c=K(e.name);if(e.inputType==="counter")return o(X,{...e});const f=s.formFields[e.name],[a,x]=I(f??e.defaultValue??""),[n,u]=I(!1),C=!!c;H(()=>{a!==(s.formFields[e.name]??"")&&y({type:F.SET_FORM_FIELD,payload:{name:e.name,value:a}})},[a]);const _={...t.layout.input.wrap,borderRadius:S(e.size,t,e.pill),backgroundColor:r.bg,borderColor:r.border,borderWidth:r.borderWidth},P=M(_,N.BOX,{controlHeightPx:i.h,hasBackground:r.bg!==void 0});function k(l){let d=l;switch(e.inputType){case"card_number":d=q(l);break;case"month_year":d=G(l);break;case"cvc":d=U(l);break}x(d),e.onChangeAction&&b({...e.onChangeAction,payload:{...e.onChangeAction.payload??{},[e.name]:d,...m?{messageId:m}:{}}})}function D(){if(e.pattern)try{const l=new RegExp(e.pattern);u(!l.test(a))}catch{}}return A(g,{children:[o(g,{style:[P,C?{borderColor:t.color.danger.solid}:null],children:o(W,{value:a,onChangeText:k,onBlur:D,placeholder:e.placeholder,placeholderTextColor:t.color.placeholder,editable:!e.disabled,autoFocus:e.autoFocus,selectTextOnFocus:!!e.autoSelect,secureTextEntry:e.inputType==="password",keyboardType:$(e.inputType),autoComplete:e.allowAutofillExtensions===!1?"off":L(e.inputType),style:[t.layout.input.field,{fontSize:i.font,color:r.fg,caretColor:r.fg,fontFamily:t.font.family,outlineStyle:"none",paddingHorizontal:T,...O.OS==="web"?{height:"100%"}:{flex:1,paddingVertical:Math.max(6,(i.h-i.font-4)/2)},borderRadius:S(e.size,t,e.pill)},n?{color:t.color.danger.solid}:null]})}),C?o(p,{style:{color:t.color.danger.solid,fontSize:12,marginTop:4,fontFamily:t.font.family},children:c}):null]})}function X(e){const{tokens:t}=v(),h=w(),b=V(),y=z(),m=E(),s=t.control.size[e.size],i=m.formFields[e.name]??e.defaultValue??"0",[r,T]=I(()=>parseInt(i,10)||0);function c(n){if(e.disabled)return;const u=Math.max(0,r+n);T(u),b({type:F.SET_FORM_FIELD,payload:{name:e.name,value:String(u)}}),e.onChangeAction&&h({...e.onChangeAction,payload:{...e.onChangeAction.payload??{},name:e.name,delta:n,value:u,...y?{messageId:y}:{}}})}const f=n=>({...t.layout.counter.btn,width:t.counter.btn,height:t.counter.btn,borderRadius:t.counter.btnRadius,opacity:n?t.ui.pressedOpacity:1}),a={color:t.color.text,fontSize:t.counter.glyph.fontSize,fontWeight:t.counter.glyph.weight,lineHeight:t.counter.glyph.lineHeight},x={height:s.h,minWidth:t.counter.valueMinWidth,paddingHorizontal:t.space[12],borderRadius:S(e.size,t,e.pill),borderColor:t.color.borderInput,borderWidth:t.ui.hairlineBorder,alignItems:"center",justifyContent:"center"};return A(g,{style:[t.layout.counter.row,{gap:t.counter.rowGap,height:s.h}],children:[o(R,{accessibilityLabel:`Decrease ${e.name}`,onPress:()=>c(-1),disabled:e.disabled,style:({pressed:n})=>f(n),children:o(p,{style:a,children:"\u2212"})}),o(g,{style:x,children:o(p,{style:[t.layout.counter.valueText,{color:t.color.text,fontSize:s.font,fontWeight:t.font.weight.normal}],children:r})}),o(R,{accessibilityLabel:`Increase ${e.name}`,onPress:()=>c(1),disabled:e.disabled,style:({pressed:n})=>f(n),children:o(p,{style:a,children:"+"})})]})}export{ne as Input};
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 t}from"./components/Badge";import{BasicRoot as a}from"./components/BasicRoot";import{Box as i,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 l}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 A}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 D}from"./components/Text";import{ListView as v,ListViewItem as w}from"./components/ListView";import{RadioGroup as L}from"./components/RadioGroup";import{Select as U}from"./components/Select";import{Spacer as H}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 te}from"./compat/WidgetThemeContext";import{WidgetRenderer as ae}from"./WidgetRenderer";import{WidgetErrorBoundary as ie}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 le,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 he,resolveTemplate as Ae,ActionHandlerContext as Fe,defaultActionHandler as Ie}from"./utils/widgetUtils";import{useWidgetState as Ee,useWidgetDispatch as Me,useActionHandler as Oe}from"./state";import{REDUCER_ACTIONS as De}from"./state";import{validateFields as ve}from"./utils/formValidationCore";import{validateForm as Be,markRequiredLabels as Le}from"./utils/formValidation";import{useFormContext as Ue,FormContext as _e}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{le as ACTION_TYPES,Fe as ActionHandlerContext,t as Badge,a as BasicRoot,i as Box,f as Button,ue as CONSUMER_ACTIONS,Y as Caption,s as Card,X as Chart,l as Checkbox,d as Col,ze as DEFAULT_CONFIG,u as DatePicker,W as Divider,T as FileUploadRequest,R as Form,_e as FormContext,A as Icon,I as Image,O as Input,D as Label,v as ListView,w as ListViewItem,$ as Markdown,De as REDUCER_ACTIONS,L as RadioGroup,m as Row,Ce as SELF_CONTAINED_ACTIONS,U as Select,H as Spacer,q as Text,z as Textarea,G as Title,K as Transition,E as Video,ie as WidgetErrorBoundary,ae as WidgetRenderer,de as WidgetStateManager,se as WidgetStateProvider,oe as WidgetThemeProvider,Ke as configureMap,Ie as defaultActionHandler,he as formatOrderItems,Le as markRequiredLabels,je as mergeConfig,We as renderWidget,Ae 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,te as useWidgetTheme,ve as validateFields,Be as validateForm};
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"},g={"2xs":"2xs",xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl","2xl":"2xl","3xl":"3xl","4xl":"4xl",full:"full","100%":"100%",none:"none"},y={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",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,y 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,g 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};
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};
@@ -1 +1 @@
1
- import{jsx as O}from"react/jsx-runtime";import{createContext as y,useCallback as _,useContext as g,useMemo as h,useReducer as k,useRef as C}from"react";import{Linking as L}from"react-native";import{ACTION_TYPES as o,CONSUMER_ACTIONS as W,SELF_CONTAINED_ACTIONS as b}from"../schema";import{createInitialWidgetState as T,REDUCER_ACTIONS as f,widgetStateReducer as N}from"./reducer";import{useRendererConfig as P}from"../theme/ThemeContext";import{DEFAULT_CONFIG as D}from"../config";const v=n=>{console.warn("[widget-renderer] action dispatched outside WidgetStateManager:",n)},I=y(v);function V(){return g(I)}const m=y({state:T(),dispatch:()=>{}});function B({messageId:n,children:a,onConsumerAction:l}){const[r,e]=k(N,void 0,T),u=P(),s=C(r);s.current=r;const p=C(l);p.current=l;const S=C(u);S.current=u;const R=C(n);R.current=n;const E=h(()=>({messageId:n,state:r,dispatch:e}),[n,r]),A=_(x=>{if(!x?.type)return;const c=x.type,t=x.payload||{};if(c===o.URL){const i=t.text;typeof i=="string"&&i&&L.openURL(i).catch(()=>{});return}if(b.has(c)){switch(c){case o.TABS:e({type:f.SET_SELECTED_CATEGORY,payload:{id:String(t.id??"")}});break;case o.DATA_CHECKBOX:case o.DATA_SELECT:e({type:f.TOGGLE_CHECKBOX,payload:{data:String(t.data??"")}});break;case o.QUANTITY_CHANGE:{const i=String(t.name??""),d=Number(t.delta??0);e({type:f.TOGGLE_QUANTITY,payload:{id:i,delta:Number.isFinite(d)?d:0}});break}case o.UPLOAD_SELECT:e({type:f.UPLOAD_FILE,payload:{requestId:String(t.fileRequestId??""),file:t.file}});break;case o.UPLOAD_REMOVE:e({type:f.REMOVE_FILE,payload:{requestId:String(t.fileRequestId??"")}});break;case o.UPLOAD_ERROR:e({type:f.SET_UPLOAD_ERROR,payload:{requestId:String(t.fileRequestId??""),error:typeof t.error=="string"?t.error:null}});break}return}if(W.has(c)){const i=s.current,d={...t};R.current&&!d.messageId&&(d.messageId=R.current),c===o.REPLY_TEMPLATE&&(d.resolvedText=w(String(t.text??""),i,t,S.current)),c===o.ORDER_SUBMIT&&(d.resolvedText=U(i.formFields)),p.current?.({type:c,payload:d,state:i});return}console.warn("[widget-renderer] unhandled action",c,t)},[]);return O(m.Provider,{value:E,children:O(I.Provider,{value:A,children:a})})}function Y(){return g(m).state}function K(){return g(m).dispatch}function Q(){return g(m).messageId}function X(){return g(m).state.selectedCategory}function $(n){return g(m).state.fileUpload.files[n]}function w(n,a,l={},r=D){let e=n;const u=a.checkboxes?.selected?.join(", ")||"";e=e.split(r.template.dataSelectToken).join(u),e=e.split(r.template.dataCheckboxToken).join(u);const{text:s,messageId:p,...S}=l,R=Object.values(S).filter(Boolean).join(", ");return e=e.split(r.template.dataInputToken).join(R),a.formFields&&(e=e.replace(new RegExp(r.template.dataFieldPattern.source,"g"),(E,A)=>a.formFields?.[A]||"")),e=e.replace(new RegExp(r.template.formPlaceholderPattern.source,"g"),(E,A)=>String(S[A.trim()]??"")),e}function U(n){const a=Object.entries(n),l=a.filter(([e])=>e.startsWith("items."));return(l.length>0?l:a).map(([e,u])=>{const s=Number(u);if(!Number.isFinite(s)||s<=0)return null;const p=e.replace(/^items\./,"");return`${s}x ${p}`}).filter(Boolean).join(", ")}export{I as ActionHandlerContext,B as WidgetStateManager,U as formatOrderItems,w as resolveTemplate,V as useActionHandler,$ as useFileUploadState,Q as useMessageId,X as useSelectedCategory,K as useWidgetDispatch,Y as useWidgetState};
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};
@@ -1 +1 @@
1
- function a(){return{fileUpload:{files:{},loading:!1,error:null},checkboxes:{selected:[],disabled:[],maxSelection:20},quantities:{},selectedCategory:void 0,formFields:{}}}const r={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_ERROR:"SET_UPLOAD_ERROR",RESET_UPLOADS:"RESET_UPLOADS",SET_FORM_FIELD:"SET_FORM_FIELD"};function c(e,E){switch(E.type){case r.TOGGLE_CHECKBOX:{const{data:n}=E.payload,{selected:l,maxSelection:o}=e.checkboxes;return l.includes(n)?{...e,checkboxes:{...e.checkboxes,selected:l.filter(i=>i!==n)}}:l.length>=o?e:{...e,checkboxes:{...e.checkboxes,selected:[...l,n]}}}case r.SET_CHECKBOX_DATA:{const{data:n,checked:l}=E.payload,{selected:o,maxSelection:i}=e.checkboxes,d=o.includes(n);return l===d?e:l?o.length>=i?e:{...e,checkboxes:{...e.checkboxes,selected:[...o,n]}}:{...e,checkboxes:{...e.checkboxes,selected:o.filter(t=>t!==n)}}}case r.CLEAR_SELECTIONS:return{...e,checkboxes:{...e.checkboxes,disabled:e.checkboxes.selected,selected:[]}};case r.SET_SELECTED_CATEGORY:return{...e,selectedCategory:E.payload.id};case r.TOGGLE_QUANTITY:{const{id:n,delta:l}=E.payload;if(!n||l===0)return e;const o=e.quantities[n]??0,i=Math.max(0,o+l),d={...e.quantities};return i===0?delete d[n]:d[n]=i,{...e,quantities:d}}case r.UPLOAD_FILE:{const{requestId:n,file:l}=E.payload,o=(l&&typeof l=="object"&&"name"in l?String(l.name??""):null)||null;return{...e,fileUpload:{...e.fileUpload,loading:!1,files:{...e.fileUpload.files,[n]:{file:l,fileName:o,uploaded:!0,loading:!1,error:null}}}}}case r.REMOVE_FILE:{const{requestId:n}=E.payload,{[n]:l,...o}=e.fileUpload.files;return{...e,fileUpload:{...e.fileUpload,files:o}}}case r.SET_UPLOAD_ERROR:{const{requestId:n,error:l}=E.payload;return{...e,fileUpload:{...e.fileUpload,files:{...e.fileUpload.files,[n]:{...e.fileUpload.files[n],error:l,uploaded:!1,fileName:null,loading:!1}}}}}case r.RESET_UPLOADS:return{...e,fileUpload:a().fileUpload};case r.SET_FORM_FIELD:{const{name:n,value:l}=E.payload;return{...e,formFields:{...e.formFields,[n]:l}}}default:return e}}export{r as REDUCER_ACTIONS,a as createInitialWidgetState,c as widgetStateReducer};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1interface/widgets",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,