@opennsw/jsonforms-renderers 0.9.0 → 0.10.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/renderers.cjs.js +3 -3
- package/dist/renderers.es.js +1190 -1061
- package/package.json +1 -1
package/dist/renderers.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).map(t=>t.trim()==="is a required property"?`${
|
|
3
|
-
`):"",He=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,uischema:i,schema:d,enabled:a,visible:u=!0})=>{var m;if(pe(u,t,r),u===!1)return null;const f=l.length===0;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.TextField.Root,{value:e||"",onChange:p=>r(t,p.target.value),disabled:!a,placeholder:(m=i.options)==null?void 0:m.placeholder,color:f?void 0:"red",id:t}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),d.description&&n.jsx(o.Text,{size:"1",color:"gray",children:d.description})]})})},Xe=b.rankWith(1,b.isStringControl),$t=J.withJsonFormsControlProps(He),Je=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,uischema:i,schema:d,enabled:a,visible:u=!0})=>{var p;if(pe(u,t,r),u===!1)return null;const f=l.length===0,m=x=>{if(x===""){r(t,void 0);return}const g=Number(x);isNaN(g)||r(t,g)};return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.TextField.Root,{type:"number",value:e??"",onChange:x=>m(x.target.value),disabled:!a,placeholder:(p=i.options)==null?void 0:p.placeholder,color:f?void 0:"red",id:t}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),d.description&&n.jsx(o.Text,{size:"1",color:"gray",children:d.description})]})})},Ke=b.rankWith(2,b.or(b.isNumberControl,b.isIntegerControl)),_t=J.withJsonFormsControlProps(Je),Ge=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(pe(a,t,r),a===!1)return null;const u=l.length===0;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(o.Checkbox,{checked:!!e,onCheckedChange:f=>r(t,f===!0),disabled:!d,id:t}),n.jsxs(o.Text,{as:"label",size:"2",htmlFor:t,children:[s," ",c&&"*"]})]}),!u&&n.jsx(o.Text,{color:"red",size:"1",className:"block mt-1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",className:"block mt-1",children:i.description})]})},Ye=b.rankWith(2,b.isBooleanControl),Wt=J.withJsonFormsControlProps(Ge),qe=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(pe(a,t,r),a===!1)return null;const u=l.length===0;let f=[];i.enum?f=i.enum.map(p=>({value:p,label:String(p)})):i.oneOf&&(f=i.oneOf.map(p=>({value:p.const,label:p.title||String(p.const)})));const m=e;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"div",size:"2",weight:"bold",children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsx(o.RadioGroup.Root,{value:m!==void 0?String(m):"",onValueChange:p=>{const x=f.find(g=>String(g.value)===p);x&&r(t,x.value)},disabled:!d,children:n.jsx(o.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:f.map(p=>n.jsxs(o.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[n.jsx(o.RadioGroup.Item,{value:String(p.value)}),n.jsx(o.Text,{size:"2",color:d?void 0:"gray",children:p.label})]},String(p.value)))})}),!u&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},Ze=(e,r,t)=>{var c;return b.or(b.isEnumControl,b.isOneOfControl)(e,r,t)&&((c=e==null?void 0:e.options)==null?void 0:c.format)==="radio"?3:-1},Vt=J.withJsonFormsControlProps(qe),Qe=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,uischema:d,enabled:a,visible:u=!0})=>{var x;if(pe(u,t,r),u===!1)return null;const f=l.length===0;let m=[];i.enum?m=i.enum.map(g=>({value:String(g),label:String(g)})):i.oneOf&&(m=i.oneOf.map(g=>({value:String(g.const),label:g.title||String(g.const)})));const p=e!==void 0?String(e):"";return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsxs(o.Select.Root,{value:p,onValueChange:g=>r(t,g),disabled:!a,children:[n.jsx(o.Select.Trigger,{placeholder:((x=d.options)==null?void 0:x.placeholder)||"Select an option",color:f?void 0:"red",id:t}),n.jsx(o.Select.Content,{children:m.map(g=>n.jsx(o.Select.Item,{value:g.value,children:g.label},g.value))})]}),!f&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),i.description&&n.jsx(o.Text,{size:"1",color:"gray",children:i.description})]})})},et=b.rankWith(2,b.or(b.isEnumControl,b.isOneOfControl)),Ht=J.withJsonFormsControlProps(Qe),Xt={"small-list":{fetchOnOpen:!0,searchable:!1,paginated:!1},"large-searchable-list":{fetchOnOpen:!0,searchable:!0,paginated:!1},"large-paginated-list":{fetchOnOpen:!1,searchable:!0,paginated:!0}},Jt=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,enabled:i,visible:d=!0,schema:a,uischema:u})=>{var me;const f=(a==null?void 0:a["x-search"])??{service:""},m=f.service??"",p=f.mode??"large-paginated-list",x=Xt[p],g=(x==null?void 0:x.fetchOnOpen)??!1,F=f.params,E=Ve(m),T=a.type==="object",O=T?typeof e=="string"?{value:e}:e??void 0:void 0,L=T?O==null?void 0:O.value:e,N=O==null?void 0:O.label,v=m?E?x?null:`Invalid x-search.mode "${p}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${m}" is not registered.`:"Search not configured.",U=i!==!1,P=!l||l.length===0,[S,R]=y.useState(!1),[B,W]=y.useState(""),[$,V]=y.useState([]),[Q,ee]=y.useState(!1),[se,ne]=y.useState(!1),[le,ue]=y.useState(!1),[H,h]=y.useState(null),[C,X]=y.useState(void 0),A=y.useRef(void 0),M=y.useRef(null),q=y.useRef(null),oe=y.useRef(null),G=y.useRef(void 0);y.useEffect(()=>{var ie,Z;if(!L){X(void 0),G.current=void 0;return}if(((ie=G.current)==null?void 0:ie.value)===L&&((Z=G.current)==null?void 0:Z.label)===N)return;if(G.current={value:L,label:N},T&&N){X({id:L,name:N});return}if(X({id:L,name:N??L}),!(E!=null&&E.resolve))return;let w=!1;return E.resolve(L,F).then(ae=>{!w&&ae&&X(ae)}).catch(()=>{}),()=>{w=!0}},[L,N,T,E,F]);const k=y.useCallback(async(w,ie=!1)=>{var ae;if(!E){h("Search service not configured.");return}(ae=q.current)==null||ae.abort();const Z=new AbortController;q.current=Z,ie?ue(!0):(ne(!0),ue(!1),h(null));try{const ye=await E.search({query:w,cursor:ie?A.current:void 0,signal:Z.signal,params:F}),ve=ye.options??[];V(ie?je=>[...je,...ve]:ve),A.current=ye.nextCursor,ee(((x==null?void 0:x.paginated)??!1)&&ye.nextCursor!=null)}catch{if(Z.signal.aborted)return;h("Failed to load results. Please try again.")}finally{Z.signal.aborted||(ie?ue(!1):ne(!1))}},[E,x==null?void 0:x.paginated,F]);if(y.useEffect(()=>{if(!S)return;const w=ie=>{oe.current&&!oe.current.contains(ie.target)&&R(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[S]),y.useEffect(()=>{var w;S||((w=q.current)==null||w.abort(),W(""),V([]),ee(!1),h(null),ne(!1),ue(!1),A.current=void 0)},[S]),y.useEffect(()=>{if(!S)return;if(!B&&!g){V([]),ee(!1),h(null),A.current=void 0;return}M.current&&clearTimeout(M.current);const w=B?300:0;return M.current=setTimeout(()=>{V([]),ee(!1),A.current=void 0,k(B)},w),()=>{M.current&&clearTimeout(M.current)}},[B,S,g,k]),pe(d,t,r,T?void 0:null),d===!1)return null;const j=()=>{W(""),V([]),ee(!1),h(null),A.current=void 0,R(!0)},D=w=>{r(t,T?{value:w.id,label:w.name}:w.id),X(w),G.current={value:w.id,label:T?w.name:void 0},R(!1)},ce=w=>{w.stopPropagation(),r(t,T?void 0:null),X(void 0)},_=w=>{(w.key==="Enter"||w.key===" ")&&ce(w)},z=((me=u==null?void 0:u.options)==null?void 0:me.placeholder)??"Select an option";return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&n.jsx(o.Text,{color:"red",children:"*"})]}),n.jsxs("div",{ref:oe,style:{position:"relative"},children:[n.jsx(o.TextField.Root,{id:t,value:S?B:(C==null?void 0:C.name)??"",placeholder:S&&(x!=null&&x.searchable)?"Search...":z,disabled:!U,readOnly:S&&!(x!=null&&x.searchable),style:P?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:w=>{x!=null&&x.searchable&&(W(w.target.value),S||j())},onFocus:()=>{U&&!S&&j()},onKeyDown:w=>{w.key==="Escape"&&R(!1)},children:n.jsx(o.TextField.Slot,{side:"right",children:n.jsxs(o.Flex,{align:"center",gap:"1",children:[L&&U&&n.jsx("span",{role:"button",tabIndex:0,onMouseDown:w=>w.preventDefault(),onClick:ce,onKeyDown:_,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),n.jsx(Y.ChevronDownIcon,{style:{transform:S?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),S&&n.jsx(o.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:v?n.jsx(o.Box,{p:"3",children:n.jsx(o.Text,{size:"2",color:"gray",children:v})}):n.jsx(o.ScrollArea,{style:{maxHeight:240},children:n.jsxs(o.Box,{p:"1",children:[se&&n.jsx(o.Flex,{justify:"center",p:"4",children:n.jsx(o.Spinner,{})}),!se&&H&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Text,{size:"2",color:"red",children:H})}),!se&&!H&&$.length===0&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Text,{size:"2",color:"gray",children:B||g?"No results found.":"Type to search…"})}),$.map(w=>n.jsx(o.Box,{px:"3",py:"2",onMouseDown:ie=>ie.preventDefault(),onClick:()=>D(w),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:w.id===L?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:n.jsx(o.Text,{size:"2",children:w.name})},w.id)),(x==null?void 0:x.paginated)&&Q&&!le&&n.jsx(o.Box,{px:"3",py:"2",children:n.jsx(o.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:w=>w.preventDefault(),onClick:()=>void k(B,!0),children:"Load more"})}),le&&n.jsx(o.Flex,{justify:"center",p:"2",children:n.jsx(o.Spinner,{})})]})})})]}),!P&&n.jsx(o.Text,{color:"red",size:"1",children:xe(l,s)}),a.description&&n.jsx(o.Text,{size:"1",color:"gray",children:a.description})]})})},tt=J.withJsonFormsControlProps(Jt),rt=b.rankWith(3,b.schemaMatches(e=>{const r=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(r==null?void 0:r.service)=="string"&&r.service!==""})),Kt=(e,r)=>Ut(`${e}T${r}`).format(),Gt=({path:e,label:r,required:t,errors:s,description:c,children:l})=>{const i=s.length===0;return n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[r," ",t&&n.jsx(o.Text,{color:"red",children:"*"})]}),l,!i&&n.jsx(o.Text,{color:"red",size:"1",children:xe(s,r)}),c&&n.jsx(o.Text,{size:"1",color:"gray",children:c})]})})},nt=({data:e,handleChange:r,path:t,label:s,required:c,errors:l,schema:i,enabled:d,visible:a=!0})=>{if(y.useEffect(()=>{a===!1&&r(t,void 0)},[a,t,r]),a===!1)return null;const u=l.length===0,f=typeof e=="string"?e:"",m=T=>n.jsx(Gt,{path:t,label:s,required:c,errors:l,description:i.description,children:T});if(i.format==="time")return m(n.jsx(o.TextField.Root,{type:"time",value:f,onChange:T=>r(t,T.target.value),disabled:!d,color:u?void 0:"red",id:t}));const p=i.format==="date-time",[x="",g=""]=f.split("T"),F=g.slice(0,5),E=(T,O)=>{if(!T){r(t,void 0);return}r(t,p?Kt(T,O||"00:00"):T)};return m(n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(o.TextField.Root,{type:"date",value:x,disabled:!d,color:u?void 0:"red",onChange:T=>E(T.target.value,F),id:t,style:{flex:1}}),p&&n.jsx(o.TextField.Root,{type:"time",value:F,disabled:!d||!x,color:u?void 0:"red",onChange:T=>E(x,T.target.value),style:{flex:1}})]}))},ot=b.rankWith(2,b.or(b.isDateControl,b.isDateTimeControl,b.isTimeControl)),Yt=J.withJsonFormsControlProps(nt),st=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const a=e.elements;return i===!1?null:n.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((u,f)=>n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${f}`))})},lt=b.rankWith(1,b.uiTypeIs("VerticalLayout")),it=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const a=e.elements;return i===!1?null:n.jsx(o.Flex,{direction:"row",gap:"4",children:a.map((u,f)=>n.jsx(o.Box,{style:{flex:1},children:n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l})},`${t}-${f}`))})},at=b.rankWith(1,b.uiTypeIs("HorizontalLayout")),ct=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{const d=e,a=d.elements;return i===!1?null:n.jsxs(o.Box,{mb:"6",children:[d.label&&n.jsx(o.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:d.label}),n.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((u,f)=>n.jsx(J.JsonFormsDispatch,{uischema:u,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${f}`))})]})},ut=b.rankWith(1,b.uiTypeIs("Group")),dt=({uischema:e,schema:r,path:t,renderers:s,cells:c,enabled:l,visible:i=!0})=>{var p;const a=e.elements.filter(x=>x.type==="Category"),[u,f]=y.useState(((p=a[0])==null?void 0:p.label)||"");if(i===!1||!a.length)return null;const m=a.find(x=>x.label===u)?u:a[0].label;return n.jsxs(o.Tabs.Root,{value:m,onValueChange:f,children:[n.jsx(o.Tabs.List,{children:a.map((x,g)=>n.jsx(o.Tabs.Trigger,{value:x.label,children:x.label},`${t}-${g}`))}),n.jsx(o.Box,{pt:"3",children:a.map((x,g)=>n.jsx(o.Tabs.Content,{value:x.label,children:n.jsx(o.Flex,{direction:"column",gap:"4",children:x.elements.map((F,E)=>n.jsx(J.JsonFormsDispatch,{uischema:F,schema:r,path:t,renderers:s,cells:c,enabled:l},`${t}-${g}-${E}`))})},`${t}-${g}`))})]})},ft=b.rankWith(1,b.uiTypeIs("Categorization"));function fe(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function he(e){return e.split(",").map(r=>{if(r=r.trim(),r.endsWith("/*"))return r.split("/")[0].toUpperCase()+"S";if(r.startsWith("."))return r.slice(1).toUpperCase();const t=r.split("/")[1];return t?t.toUpperCase():r}).join(", ")}function qt(e){return e?Array.isArray(e)?e:[e]:[]}const Zt=({data:e,handleChange:r,path:t,label:s,required:c,uischema:l,schema:i,enabled:d,errors:a,visible:u=!0})=>{const f=_e();pe(u,t,r,null);const m=!a||a.length===0,p=(i==null?void 0:i["x-file"])??{},x=(l==null?void 0:l.options)??{},g=p.maxFiles??x.maxFiles??1,F=p.maxSize??x.maxSize??5*1024*1024,E=p.accept??x.accept??"image/*,application/pdf",T=g>1,O=d!==!1,[L,N]=y.useState(!1),[v,U]=y.useState(null),[P,S]=y.useState({}),R=y.useRef(new Set),B=y.useRef(null),W=qt(e),$=W.length>=g;y.useEffect(()=>()=>{R.current.forEach(h=>URL.revokeObjectURL(h)),R.current.clear()},[]);const V=y.useCallback(async h=>{if(U(null),W.length>=g){U(`Maximum ${g} file${g>1?"s":""} allowed.`);return}if(h.size>F){U(`File exceeds the ${fe(F)} limit.`);return}if(!E.split(",").map(A=>A.trim()).some(A=>A==="*"||A==="*/*"?!0:A.endsWith("/*")?h.type.startsWith(A.slice(0,-1)):A.startsWith(".")?h.name.toLowerCase().endsWith(A.toLowerCase()):h.type===A)){U(`Invalid type. Accepted: ${he(E)}`);return}if(!(f!=null&&f.onUpload)){U("Upload service not configured.");return}try{const A=await f.onUpload(h),M=URL.createObjectURL(h);R.current.add(M);const q={key:A.key,name:A.name??h.name,blobUrl:M};S(G=>({...G,[A.key]:q}));const oe=[...W,A.key];r(t,T?oe:oe[0])}catch{U("Upload failed. Please try again."),B.current&&(B.current.value="")}},[W,g,F,E,f,t,r,T]);if(u===!1)return null;const Q=h=>{h.preventDefault(),h.stopPropagation(),!(!O||$)&&N(h.type==="dragenter"||h.type==="dragover")},ee=h=>{var C;h.preventDefault(),h.stopPropagation(),N(!1),!(!O||$)&&(C=h.dataTransfer.files)!=null&&C[0]&&V(h.dataTransfer.files[0])},se=h=>{var C;(C=h.target.files)!=null&&C[0]&&(V(h.target.files[0]),h.target.value="")},ne=h=>{if(!O)return;S(X=>{var q;const A={...X},M=(q=A[h])==null?void 0:q.blobUrl;return M&&(URL.revokeObjectURL(M),R.current.delete(M)),delete A[h],A});const C=W.filter(X=>X!==h);r(t,T?C.length>0?C:null:C[0]??null)},le=async(h,C)=>{var M,q,oe;h.preventDefault();const X=(M=P[C])==null?void 0:M.blobUrl;if(X){(q=window.open(X,"_blank","noopener,noreferrer"))==null||q.focus();return}const A=window.open("","_blank");if(A)try{const G=await((oe=f==null?void 0:f.getDownloadUrl)==null?void 0:oe.call(f,C));G!=null&&G.url?A.location.href=G.url:A.close()}catch{A.close()}};if(!O&&W.length===0)return null;const ue=g-W.length,H=O&&!$;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),n.jsx(o.Text,{size:"1",color:"gray",children:T?`Up to ${g} files · ${fe(F)} each · ${he(E)}`:`${fe(F)} · ${he(E)}`})]}),W.map(h=>{var C;return n.jsx(o.Card,{size:"2",variant:"surface",mb:"2",children:n.jsxs(o.Flex,{align:"center",gap:"3",children:[n.jsx(o.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:n.jsx(Y.FileTextIcon,{width:"20",height:"20"})}),n.jsx(o.Box,{style:{flex:1,overflow:"hidden"},children:n.jsx(o.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((C=P[h])==null?void 0:C.name)??"Uploaded File"})}),n.jsxs(o.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[n.jsx(o.Button,{variant:"soft",color:"blue",size:"1",onClick:X=>le(X,h),children:"View"}),n.jsx(Y.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),O&&n.jsx(o.IconButton,{variant:"ghost",color:"gray",onClick:()=>ne(h),children:n.jsx(Y.Cross2Icon,{})})]})]})},h)}),H&&n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var h;return(h=B.current)==null?void 0:h.click()},onKeyDown:h=>{var C;(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),(C=B.current)==null||C.click())},onDragEnter:Q,onDragLeave:Q,onDragOver:Q,onDrop:ee,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",L?"border-blue-500 bg-blue-50":v?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[n.jsx("input",{ref:B,type:"file",style:{display:"none"},accept:E,onChange:se}),n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:v?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:v}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:W.length>0?`Add another file (${ue} remaining)`:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(E)]})]})})]}),O&&$&&T&&n.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block",textAlign:"center"},children:["Maximum ",g," files uploaded. Remove one to replace it."]}),!m&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},ht=J.withJsonFormsControlProps(Zt),pt=b.rankWith(10,b.and(b.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const r=e.items;return(r==null?void 0:r.type)==="string"&&(r==null?void 0:r.format)==="file"}return!1})));function xt(e,r){return e!==!1&&r!==!0}class Ae extends Error{}function Qt(e,r){const t=Ne.read(e,{type:"array",cellDates:!0});if(t.SheetNames.length===0)throw new Ae("This file has no sheets.");const s=r??t.SheetNames[0],c=t.Sheets[s];if(!c)throw new Ae(`This file doesn't have a sheet named "${s}".`);const l=Ne.utils.sheet_to_json(c,{header:1,raw:!0,defval:null});return{sheetName:s,matrix:l,rowCount:l.length,colCount:Math.max(0,...l.map(i=>i.length))}}function er(e){let r=e+1,t="";for(;r>0;){const s=(r-1)%26;t=String.fromCharCode(65+s)+t,r=Math.floor((r-1)/26)}return t}class re extends Error{constructor(t,s){super(s??t);Ie(this,"code");this.code=t,this.name="FormulaError"}}const tr=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],rr=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],nr=["YEAR","MONTH","DAY","WEEKDAY"],or=["IF"],sr=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],lr=new Set([...tr,...rr,...nr,...sr,...or]),ir=/"(?:[^"]|"")*"/g,De=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function ar(e){const r=e.replace(ir,s=>" ".repeat(s.length));De.lastIndex=0;let t;for(;(t=De.exec(r))!==null;){const s=t[1].toUpperCase();if(!lr.has(s))throw new re("NAME",`Function ${s} is not allowed.`)}}function cr(e,r,t){let s=e;if(s==null)throw t.NA;if(typeof s=="object"&&!(s instanceof t)&&(s=r.retrieveRef(s)),s instanceof t)throw s;if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;throw t.VALUE}function mt(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function Te(e){const r=mt(e);return Array.isArray(r)?r.flat(1/0):[r]}function I(e){const r=mt(e);return Array.isArray(r)?r.flat(1/0)[0]:r}function Ce(e){return e===void 0?void 0:I(e)}function te(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function ur(e,r){return e instanceof r?e:new r(e.message||"#ERROR!")}function K(e){return e.find(r=>r instanceof Error)}function dr(e,r){const t=l=>{throw ur(l,r)},s=(l,{checkArgsForErrors:i=!0}={})=>(...d)=>{const a=d.flatMap(Te);if(i){const f=K(a);f&&t(f)}const u=l(...a);return u instanceof Error?t(u):u},c=(l,{toText:i=!1}={})=>d=>{const a=I(d),u=K([a]);u&&t(u);const f=l(i?te(a):a);return f instanceof Error?t(f):f};return{IF:(l,i,d,a)=>{const u=cr(i,l,r);if(d==null)throw r.NA;return u?d:a??!1},MAX:s(e.MAX),MIN:s(e.MIN),MAXA:s(e.MAXA),MINA:s(e.MINA),MEDIAN:s(e.MEDIAN),COUNTA:s(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(l,i)=>{const d=Te(l),a=I(i),u=K([...d,a]);u&&t(u);const f=e.LARGE(d,a);return f instanceof Error?t(f):f},SMALL:(l,i)=>{const d=Te(l),a=I(i),u=K([...d,a]);u&&t(u);const f=e.SMALL(d,a);return f instanceof Error?t(f):f},PERMUT:(l,i)=>{const d=[I(l),I(i)],a=K(d);a&&t(a);const u=e.PERMUT(d[0],d[1]);return u instanceof Error?t(u):u},PERMUTATIONA:(l,i)=>{const d=[I(l),I(i)],a=K(d);a&&t(a);const u=e.PERMUTATIONA(d[0],d[1]);return u instanceof Error?t(u):u},MATCH:(l,i)=>{const d=I(l),a=Te(i),u=K([d,...a]);u&&t(u);const f=e.MATCH(d,a,0);return f instanceof Error?t(f):f},SWITCH:(...l)=>{const i=l.map(I),d=K(i);d&&t(d);const a=e.SWITCH(...i);return a instanceof Error?t(a):a},SUBSTITUTE:(l,i,d,a)=>{const u=[te(I(l)),te(I(i)),te(I(d))];a!==void 0&&u.push(I(a));const f=K(u);f&&t(f);const m=e.SUBSTITUTE(...u);return m instanceof Error?t(m):m},TEXTJOIN:(l,i,...d)=>{const a=te(I(l)),u=I(i),f=d.flatMap(Te).map(te),m=K([a,u]);m&&t(m);const p=e.TEXTJOIN(a,u,f);return p instanceof Error?t(p):p},UPPER:c(e.UPPER),YEAR:c(e.YEAR),MONTH:c(e.MONTH),DAY:c(e.DAY),WEEKDAY:(l,i)=>{const d=I(l),a=I(i),u=K([d]);u&&t(u);const f=e.WEEKDAY(d,a);return f instanceof Error?t(f):f},CONCATENATE:(...l)=>{const i=l.flatMap(Te),d=K(i);d&&t(d);const a=e.CONCATENATE(...i.map(te));return a instanceof Error?t(a):a},CONCAT:(...l)=>{const i=l.flatMap(Te),d=K(i);d&&t(d);const a=e.CONCAT(...i.map(te));return a instanceof Error?t(a):a},LEN:c(e.LEN,{toText:!0}),TRIM:c(e.TRIM,{toText:!0}),LOWER:c(e.LOWER,{toText:!0}),LEFT:(l,i)=>{const d=I(l),a=Ce(i),u=K([d]);u&&t(u);const f=e.LEFT(te(d),a);return f instanceof Error?t(f):f},RIGHT:(l,i)=>{const d=I(l),a=Ce(i),u=K([d]);u&&t(u);const f=e.RIGHT(te(d),a);return f instanceof Error?t(f):f},MID:(l,i,d)=>{const a=I(l),u=I(i),f=I(d),m=K([a,u,f]);m&&t(m);const p=e.MID(te(a),u,f);return p instanceof Error?t(p):p},FIND:(l,i,d)=>{const a=I(l),u=I(i),f=Ce(d),m=K([a,u]);m&&t(m);const p=e.FIND(te(a),te(u),f);return p instanceof Error?t(p):p},SEARCH:(l,i,d)=>{const a=I(l),u=I(i),f=Ce(d),m=K([a,u]);m&&t(m);const p=e.SEARCH(te(a),te(u),f);return p instanceof Error?t(p):p}}}const fr={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Le(e){return fr[e.error]??"ERROR"}function Me(e,r){if(e instanceof re)return e;if(e instanceof r){const t=e.details;return t instanceof re?t:t instanceof r?new re(Le(t),t.message):new re(Le(e),e.message)}return new re("ERROR",e instanceof Error?e.message:void 0)}function hr(e){return Math.max(0,...e.map(r=>(r==null?void 0:r.length)??0))}function pr(e){return r=>{const t=e[r.row-1];if(r.row<1||r.col<1||t==null||r.col-1>=t.length)throw new re("REF");const s=t[r.col-1];return s==null||s===""?null:s}}function xr(e){return r=>{const t=Math.min(r.from.row,r.to.row),s=Math.min(r.from.col,r.to.col),c=Math.max(r.from.row,r.to.row),l=Math.max(r.from.col,r.to.col),i=hr(e);if(t>e.length||s>i)throw new re("REF");const d=Math.min(c,e.length),a=[];for(let u=t;u<=d;u++){const f=e[u-1],m=[];if(f!=null){const p=Math.min(l,f.length);for(let x=s;x<=p;x++){const g=f[x-1];m.push(g==null||g===""?null:g)}}a.push(m)}return a}}function mr(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new re("VALUE")}async function gt(e,r){if(typeof e!="string")throw new re("ERROR");const t=e.trim();if(t==="")throw new re("ERROR");const s=t.startsWith("=")?t.slice(1):t;ar(s);const[c,l]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),i=c.default??c,d=i.FormulaError,a=new i({...r,functions:dr(l,d)});let u;try{u=a.parse(s,{row:1,col:1,sheet:"Sheet1"})}catch(f){throw Me(f,d)}if(u instanceof d)throw Me(u,d);return mr(u)}async function gr(e,r){return gt(r,{onCell:pr(e),onRange:xr(e)})}const ze=-1;async function yt(e,r){const t=Object.keys(e);return gt(r,{onVariable:s=>{const c=t.indexOf(s);return c===-1?null:{row:ze,col:c+1}},onCell:s=>{if(s.row===ze)return e[t[s.col-1]]??null;throw new re("REF")},onRange:()=>{throw new re("REF")}})}const Tt={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function ke(e){const r=e instanceof re?e.code:"ERROR";return Tt[r]}async function yr(e,r){return e.length===0?r.map(t=>({id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:Tt.ERROR})):Promise.all(r.map(async t=>{try{if(!t||typeof t.label!="string"||typeof t.expression!="string"||typeof t.id!="string")throw new re("ERROR");return{id:t.id,label:t.label,value:await gr(e,t.expression)}}catch(s){return{id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:ke(s)}}}))}function Tr(e,r={}){if(r.columnHeader&&r.rowHeader)throw new Error("x-spreadsheet: columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.");return r.columnHeader?br(e):r.rowHeader?vr(e):e}function bt(e){return e==null||e===""?null:e instanceof Date?e.toISOString():String(e)}function vt(e,r){const t=new Set;for(const s of e)if(s!=null){if(t.has(s))throw new Error(`x-spreadsheet: duplicate ${r} value "${s}" — every ${r==="columnHeader"?"column header":"column-A value"} must be unique to shape as records.`);t.add(s)}}function br(e){const[r,...t]=e;if(!r)return[];const s=r.map(bt);return vt(s,"columnHeader"),t.map(c=>{const l=Object.create(null);return s.forEach((i,d)=>{i!=null&&(l[i]=c[d]??null)}),l})}function vr(e){const r=e.map(c=>bt(c[0]));vt(r,"rowHeader");const t=Math.max(0,...e.map(c=>c.length)),s=Math.max(0,t-1);return Array.from({length:s},(c,l)=>{const i=l+1,d=Object.create(null);return r.forEach((a,u)=>{a!=null&&(d[a]=e[u][i]??null)}),d})}function jr(e){return!Array.isArray(e[0])}function wr(e){const r=Object.create(null);for(const{id:t,label:s,value:c,error:l}of e)r[t]=l===void 0?{label:s,value:c}:{label:s,value:c,error:l};return r}function Fe(e,r){const t=s=>s instanceof Date?s.toISOString():s??null;return t(e)===t(r)}function Cr(e,r){const t=e??{},s=r??{},c=Object.keys(t);return c.length!==Object.keys(s).length?!1:c.every(l=>{if(!Object.prototype.hasOwnProperty.call(s,l))return!1;const i=t[l],d=s[l];return i.label===d.label&&i.error===d.error&&Fe(i.value,d.value)})}function Er(e,r){if(e==null||r==null)return e===r;const t=Array.isArray(e);if(t!==Array.isArray(r))return!1;if(t){const i=e,d=r;return i.length===d.length&&i.every((a,u)=>Fe(a,d[u]))}const s=e,c=r,l=Object.keys(s);return l.length!==Object.keys(c).length?!1:l.every(i=>Object.prototype.hasOwnProperty.call(c,i)&&Fe(s[i],c[i]))}function Rr(e,r){if(e===r)return!0;if(e==null||r==null)return!1;const t=e,s=r;return t.length!==s.length?!1:t.every((c,l)=>Er(c,s[l]))}function Sr(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e instanceof Date}function Ar(e){if(e.length===0)return[];const r=[],t=new Set;for(const c of e)for(const l of Object.keys(c))t.has(l)||(t.add(l),r.push(l));if(r.length===0)return[];const s=e.map(c=>r.map(l=>{if(!Object.prototype.hasOwnProperty.call(c,l))return null;const i=c[l];return Sr(i)?i:null}));return[r,...s]}function Fr(e){const r=Math.max(0,...e.map(t=>t.length));return Array.from({length:r},(t,s)=>e.map(c=>c[s]??null))}const Or=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",kr=10*1024*1024,Se=200,Ir=50,Nr=[];function Ee(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const Dr=({data:e,handleChange:r,path:t,label:s,required:c,schema:l,enabled:i,readonly:d,errors:a,visible:u=!0})=>{pe(u,t,r,null);const f=!a||a.length===0,m=xt(i,d),p=(l==null?void 0:l["x-spreadsheet"])??{},x=(l==null?void 0:l["x-evaluate"])??Nr,g=p.accept??Or,F=p.maxSize??kr,E=p.columnHeader===!0,T=p.rowHeader===!0,O=p.showSheet!==!1,L=p.sheetName,N=p.persistSheet!==!1,v=e??null,[U,P]=y.useState(()=>v!=null&&v.sheet||Object.keys((v==null?void 0:v.derivations)??{}).length>0?"ready":"empty"),[S,R]=y.useState(null),[B,W]=y.useState(!1),[$,V]=y.useState(null),[Q,ee]=y.useState(null),se=y.useRef(null),ne=y.useRef(null),le=(v==null?void 0:v.sheet)??null,ue=y.useCallback(j=>{if(!jr(j))return j;const D=Ar(j);return T?Fr(D):D},[T]),H=y.useMemo(()=>$??(le?ue(le):null),[$,le,ue]),h=((Q==null?void 0:Q.matrix)===H?Q.derivations:null)??(v==null?void 0:v.derivations)??{},C=H!=null||v!=null,X=y.useMemo(()=>{const j=E?1:0,D=T?1:0,ce=H?H.slice(j):[],_=ce.slice(0,Se),z=Math.min(Ir,Math.max(0,..._.map(Z=>Math.max(0,Z.length-D)))),me=Array.from({length:z},(Z,ae)=>ae+D),w="",ie=T&&!E;return n.jsx(n.Fragment,{children:H&&O&&n.jsxs(o.Box,{mt:"3",children:[n.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:n.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[!ie&&n.jsx(o.Table.Header,{children:n.jsxs(o.Table.Row,{children:[n.jsx(o.Table.ColumnHeaderCell,{children:w}),me.map(Z=>{var ae;return n.jsx(o.Table.ColumnHeaderCell,{children:E?Ee((ae=H[0])==null?void 0:ae[Z]):er(Z)},Z)})]})}),n.jsx(o.Table.Body,{children:_.map((Z,ae)=>{var ve;const ye=j+ae;return n.jsxs(o.Table.Row,{children:[n.jsx(o.Table.RowHeaderCell,{style:T?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:T?Ee((ve=H[ye])==null?void 0:ve[0]):E?"":ye+1}),me.map(je=>n.jsx(o.Table.Cell,{children:Ee(Z[je])},je))]},ae)})})]})}),ce.length>Se&&n.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",Se," of ",ce.length," rows"]})]})})},[H,O,E,T]),A=y.useCallback(async j=>{if(R(null),j.size>F){R(`File exceeds the ${fe(F)} limit.`);return}if(!g.split(",").map(z=>z.trim()).some(z=>z==="*"||z==="*/*"?!0:z.endsWith("/*")?j.type.startsWith(z.slice(0,-1)):z.startsWith(".")?j.name.toLowerCase().endsWith(z.toLowerCase()):j.type===z)){R(`Invalid type. Accepted: ${he(g)}`);return}P("parsing");let _;try{const z=await j.arrayBuffer();_=Qt(z,L).matrix}catch(z){P("error"),R(z instanceof Ae?z.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}ne.current=(e==null?void 0:e.sheet)??null,V(_),P("ready")},[g,F,L,e]);if(y.useEffect(()=>{$!=null&&le!=null&&le!==ne.current&&V(null)},[$,le]),y.useEffect(()=>{if(x.length===0&&!N)return;let j=!1;const D=_=>{m&&(Cr(v==null?void 0:v.derivations,_==null?void 0:_.derivations)&&Rr(v==null?void 0:v.sheet,_==null?void 0:_.sheet)||(ne.current=(_==null?void 0:_.sheet)??null,r(t,_)))},ce=H??[];if(ce.length===0){v!=null&&D(void 0);return}return yr(ce,x).then(_=>{if(j)return;let z;if($!=null){if(N)try{z=Tr(ce,{columnHeader:E,rowHeader:T})}catch(w){R(w instanceof Error?w.message:"Failed to process this sheet.");return}}else z=v==null?void 0:v.sheet;R(null);const me=wr(_);ee({matrix:ce,derivations:me}),D(z===void 0?{derivations:me}:{sheet:z,derivations:me})}),()=>{j=!0}},[H,$,x,m,N,E,T]),u===!1)return null;if(E&&T)return n.jsxs(o.Box,{mb:"4",children:[n.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),n.jsx(o.Text,{size:"2",color:"red",style:{display:"block"},children:"Invalid x-spreadsheet config: columnHeader and rowHeader cannot both be true — pick one orientation."})]});if(!m&&!C)return null;const M=j=>{j.preventDefault(),j.stopPropagation(),m&&W(j.type==="dragenter"||j.type==="dragover")},q=j=>{var D;j.preventDefault(),j.stopPropagation(),W(!1),m&&(D=j.dataTransfer.files)!=null&&D[0]&&A(j.dataTransfer.files[0])},oe=j=>{var D;(D=j.target.files)!=null&&D[0]&&(A(j.target.files[0]),j.target.value="")},G=()=>{m&&(V(null),ee(null),ne.current=null,R(null),P("empty"),r(t,null))},k=O&&H==null&&v!=null;return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Flex,{align:"center",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),C&&m&&n.jsxs(n.Fragment,{children:[n.jsx(o.Tooltip,{content:"Replace spreadsheet",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var j;return(j=se.current)==null?void 0:j.click()},"aria-label":"Replace spreadsheet",children:n.jsx(Y.UploadIcon,{})})}),n.jsx(o.Tooltip,{content:"Remove spreadsheet",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:G,"aria-label":"Remove spreadsheet",children:n.jsx(Y.Cross2Icon,{})})})]})]}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(g)]})]}),C&&S&&n.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:S}),n.jsx("input",{ref:se,type:"file",style:{display:"none"},accept:g,onChange:oe}),m&&!C&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var j;return(j=se.current)==null?void 0:j.click()},onKeyDown:j=>{var D;(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),(D=se.current)==null||D.click())},onDragEnter:M,onDragLeave:M,onDragOver:M,onDrop:q,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",B?"border-blue-500 bg-blue-50":S?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:U==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(o.Spinner,{size:"3"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):S?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:S}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(F)," max · ",he(g)]})]})})}),X,k&&n.jsx(o.Text,{size:"2",color:"gray",mt:"3",style:{display:"block"},children:"Sheet preview not stored for this field — re-upload to view contents."}),Object.keys(h).length>0&&n.jsxs(o.Box,{mt:"3",children:[n.jsx(o.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),n.jsx(o.Flex,{direction:"column",gap:"1",children:Object.entries(h).map(([j,D])=>n.jsxs(o.Flex,{justify:"between",children:[n.jsx(o.Text,{size:"2",children:D.label}),D.error?n.jsx(o.Text,{size:"2",color:"red",children:D.error}):n.jsx(o.Text,{size:"2",children:Ee(D.value)})]},j))})]}),!f&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},jt=J.withJsonFormsControlProps(Dr),wt=b.rankWith(10,b.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object"));class ge extends Error{}const Ue=5e6,Lr=1024,Mr=/^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i,zr={ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseTagValue:!0,parseAttributeValue:!0,numberParseOptions:{hex:!1,leadingZeros:!1,eNotation:!0},trimValues:!0,cdataPropName:!1,commentPropName:!1,processEntities:!0,htmlEntities:!0,ignoreDeclaration:!0,ignorePiTags:!0,alwaysCreateTextNode:!1,preserveOrder:!1,removeNSPrefix:!1,maxNestedTags:100,strictReservedNames:!0};function Ur(e){const r=new Set(e);return r.size===0?()=>!1:(t,s)=>r.has(typeof s=="string"?s:s.toString())||r.has(t)}function Pr(e){const r=e instanceof Error?e.message:"";return r.startsWith("[SECURITY] Invalid name:")?"This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely.":r==="External entities are not supported"||r==="Parameter entities are not supported"?`${r}. Please remove the DOCTYPE entity declarations and try again.`:r.startsWith("Maximum nested tags exceeded")?"This document is nested too deeply to parse.":r.startsWith("Entity count")||r.includes("exceeds maximum allowed")?"This document declares too many or too large entity definitions to expand safely.":"This doesn't look like a valid XML document. Please check the file and try again."}async function Br(e,r={}){var u;if(typeof e!="string")throw new ge("This file could not be read as text.");const t=e.charCodeAt(0)===65279?e.slice(1):e;if(t.trim()==="")throw new ge("This file is empty.");if(t.length>Ue)throw new ge(`This document is too large to parse (over ${Ue/1e6} million characters).`);const s=(u=Mr.exec(t.slice(0,Lr)))==null?void 0:u[1];if(s&&!/^utf-?8$/i.test(s))throw new ge(`This document declares the unsupported encoding "${s}". Only UTF-8 is supported.`);const{XMLParser:c,XMLValidator:l}=await import("fast-xml-parser"),i=l.validate(t,{allowBooleanAttributes:!1});if(i!==!0){const{msg:f,line:m,col:p}=i.err;throw new ge(`Invalid XML at line ${m}, column ${p}: ${f}`)}const d=new c({...zr,removeNSPrefix:r.removeNamespaces===!0,isArray:Ur(r.arrayPaths??[])});let a;try{a=d.parse(t)}catch(f){throw new ge(Pr(f))}if(a==null||typeof a!="object"||Array.isArray(a))throw new ge("This document has no root element.");return a}const be={found:!1},de=e=>({found:!0,value:e});function Pe(e){return e==null||e===""?be:Array.isArray(e)||e instanceof Date?de(e):typeof e=="object"?be:typeof e=="string"||typeof e=="number"||typeof e=="boolean"?de(e):be}const $r=new Set(["true","1","yes","y"]),_r=new Set(["false","0","no","n"]);async function Wr(e,r){switch(r.as){case void 0:return de(e);case"string":return de(e instanceof Date?e.toISOString():String(e));case"number":{const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?de(t):be}case"boolean":{const t=String(e).trim().toLowerCase();return $r.has(t)?de(!0):_r.has(t)?de(!1):be}case"date":{const{default:t}=await import("dayjs"),{default:s}=await Promise.resolve().then(()=>require("./customParseFormat-CLvZwox5.cjs")).then(i=>i.customParseFormat);t.extend(s);const c=e instanceof Date?e.toISOString():String(e),l=r.format?t(c,r.format,!0):t(c);return l.isValid()?de(l.format("YYYY-MM-DD")):be}}}async function Vr(e,r){if(r.formula!==void 0){const t={};for(const[s,c]of Object.entries(r.inputs??{})){const l=Pe(b.Resolve.data(e,c));if(!l.found||Array.isArray(l.value))return be;t[s]=l.value}try{return de(await yt(t,r.formula))}catch(s){throw new Error(`x-xml.writeTo "${r.to}": ${ke(s)}`)}}if(r.from===void 0)throw new Error(`x-xml.writeTo "${r.to}" needs either "from" or "formula".`);return Pe(b.Resolve.data(e,r.from))}async function Hr(e,r){const t=[];for(const s of r){let c=await Vr(e,s);const l=c.found&&Array.isArray(c.value);if(c.found&&!l&&s.map){const i=c.value instanceof Date?c.value.toISOString():String(c.value);Object.prototype.hasOwnProperty.call(s.map,i)&&(c=de(s.map[i]))}if(c.found&&!l&&(c=await Wr(c.value,s)),!c.found){if(s.default===void 0)continue;t.push({to:s.to,value:s.default});continue}t.push({to:s.to,value:c.value})}return t}const Xr=".xml,text/xml,application/xml",Jr=5*1024*1024,Kr=({data:e,handleChange:r,path:t,label:s,required:c,schema:l,enabled:i,readonly:d,errors:a,visible:u=!0})=>{pe(u,t,r);const f=!a||a.length===0,m=xt(i,d),p=(l==null?void 0:l["x-xml"])??{},x=p.accept??Xr,g=p.maxSize??Jr,F=p.arrayPaths,E=p.removeNamespaces===!0,T=p.writeTo,O=p.writeBase??"root",L=p.persistDocument!==!1,N=J.useJsonForms(),v=e??null,[U,P]=y.useState(()=>v?"ready":"empty"),[S,R]=y.useState(null),[B,W]=y.useState(!1),$=y.useRef(null),V=y.useRef(0),Q=v!=null,ee=T!==void 0&&T.length>0,se=y.useCallback(async h=>{var G;const C=++V.current;if(R(null),h.size>g){R(`File exceeds the ${fe(g)} limit.`);return}if(!x.split(",").map(k=>k.trim()).some(k=>k==="*"||k==="*/*"?!0:k.endsWith("/*")?h.type.startsWith(k.slice(0,-1)):k.startsWith(".")?h.name.toLowerCase().endsWith(k.toLowerCase()):h.type===k)){R(`Invalid type. Accepted: ${he(x)}`);return}P("parsing");let M;try{const k=await h.text();M=await Br(k,{arrayPaths:F,removeNamespaces:E})}catch(k){if(C!==V.current)return;P("error"),R(k instanceof ge?k.message:"This doesn't look like a valid XML document. Please check the file and try again.");return}let q=[];if(T&&T.length>0)try{q=await Hr(M,T)}catch(k){if(C!==V.current)return;P("error"),R(k instanceof Error?k.message:"This document could not be mapped onto the form.");return}if(C!==V.current)return;L&&r(t,M);const oe=O==="parent"?t.split(".").slice(0,-1).join("."):"";for(const k of q)(G=N.dispatch)==null||G.call(N,b.update(oe?`${oe}.${k.to}`:k.to,()=>k.value));P("ready")},[x,g,F,E,T,O,L,t,r,N]);if(u===!1||!m&&!Q)return null;const ne=h=>{h.preventDefault(),h.stopPropagation(),m&&W(h.type==="dragenter"||h.type==="dragover")},le=h=>{var C;h.preventDefault(),h.stopPropagation(),W(!1),m&&(C=h.dataTransfer.files)!=null&&C[0]&&se(h.dataTransfer.files[0])},ue=h=>{var C;(C=h.target.files)!=null&&C[0]&&(se(h.target.files[0]),h.target.value="")},H=()=>{m&&(++V.current,R(null),P("empty"),r(t,void 0))};return n.jsxs(o.Box,{mb:"4",children:[n.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[n.jsxs(o.Flex,{align:"center",gap:"1",children:[n.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&n.jsx(o.Text,{color:"red",children:" *"})]}),!ee&&Q&&m&&n.jsxs(n.Fragment,{children:[n.jsx(o.Tooltip,{content:"Replace document",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},"aria-label":"Replace document",children:n.jsx(Y.UploadIcon,{})})}),n.jsx(o.Tooltip,{content:"Remove document",children:n.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:H,"aria-label":"Remove document",children:n.jsx(Y.Cross2Icon,{})})})]})]}),n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(g)," max · ",he(x)]}),ee&&m&&n.jsxs(o.Button,{size:"1",variant:"soft",onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},disabled:U==="parsing",children:[U==="parsing"?n.jsx(o.Spinner,{size:"1"}):n.jsx(Y.UploadIcon,{}),"Upload"]})]})]}),(ee||Q)&&S&&n.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:S}),n.jsx("input",{ref:$,type:"file",style:{display:"none"},accept:x,onChange:ue}),!ee&&m&&!Q&&n.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var h;return(h=$.current)==null?void 0:h.click()},onKeyDown:h=>{var C;(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),(C=$.current)==null||C.click())},onDragEnter:ne,onDragLeave:ne,onDragOver:ne,onDrop:le,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",B?"border-blue-500 bg-blue-50":S?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:n.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:U==="parsing"?n.jsxs(n.Fragment,{children:[n.jsx(o.Spinner,{size:"3"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Parsing document…"})]}):S?n.jsxs(n.Fragment,{children:[n.jsx(Y.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),n.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:S}),n.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Y.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),n.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),n.jsxs(o.Text,{size:"1",color:"gray",children:[fe(g)," max · ",he(x)]})]})})}),!f&&n.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:xe(a,s)})]})},Ct=J.withJsonFormsControlProps(Kr),Et=b.rankWith(10,b.schemaMatches(e=>{const r=e["x-xml"];return e.type==="object"&&typeof r=="object"&&r!==null}));function Gr(e,r,t){const s={};for(const[c,l]of Object.entries(t)){const{path:i,default:d}=typeof l=="string"?{path:l,default:void 0}:l,a=r?`${r}.${i}`:i,u=b.Resolve.data(e,a);if(u==null){if(d===void 0)return;s[c]=d}else s[c]=u}return s}async function Yr(e,r){try{return{status:"ok",value:await yt(e,r)}}catch(t){return{status:"error",error:ke(t)}}}function qr(e,r){return e==null?"":typeof e=="number"?e.toFixed(Zr(r)):e instanceof Date?e.toLocaleDateString():String(e)}function Zr(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const Be="{value}",Qr=2,en={},tn=({data:e,handleChange:r,path:t,label:s,schema:c,visible:l=!0})=>{var U;pe(l,t,r,null);const i=c==null?void 0:c["x-computed"],d=(i==null?void 0:i.inputs)??en,a=(i==null?void 0:i.formula)??"",u=(i==null?void 0:i.format)??Be,f=(i==null?void 0:i.decimals)??Qr,m=J.useJsonForms(),p=t.split(".").slice(0,-1).join("."),x=Gr((U=m.core)==null?void 0:U.data,p,d),g=x?JSON.stringify(x):null,F=m.readonly===!0,[E,T]=y.useState(()=>typeof e=="number"?"ok":"unavailable"),[O,L]=y.useState(()=>typeof e=="number"?e:null),[N,v]=y.useState(null);return y.useEffect(()=>{if(!l)return;let P=!1;const S=R=>{F||R!==(e??null)&&r(t,R)};if(x===void 0){T("unavailable"),v(null),L(null),S(null);return}return T(R=>R==="ok"?R:"loading"),Yr(x,a).then(R=>{if(P)return;const B=R.status==="ok"&&typeof R.value=="number"&&Number.isFinite(R.value)?R.value:null;if(B===null){T("error"),v(R.status==="error"?R.error??"Unable to compute value.":"Computed value must be a number."),L(null),S(null);return}T("ok"),v(null),L(B),S(B)}),()=>{P=!0}},[g,a,l,F]),l===!1?null:n.jsx(o.Box,{mb:"4",children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),E==="unavailable"?n.jsx(o.Text,{size:"2",color:"gray",children:"Not yet available."}):E==="loading"?n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsx(o.Spinner,{size:"1"}),n.jsx(o.Text,{size:"2",color:"gray",children:"Computing…"})]}):E==="error"?n.jsx(o.Text,{size:"2",color:"red",children:N}):n.jsx(o.Text,{size:"2",children:u.split(Be).join(qr(O,f))}),c.description&&n.jsx(o.Text,{size:"1",color:"gray",children:c.description})]})})},Rt=J.withJsonFormsControlProps(tn),St=b.rankWith(5,b.schemaMatches(e=>{const r=e["x-computed"];return e.type==="number"&&typeof r=="object"&&r!==null})),rn=({data:e,path:r,schema:t,uischema:s,enabled:c,visible:l,addItem:i,removeItems:d,rootSchema:a,arraySchema:u})=>{const f=u?t:t.items,m=u||t;if(l===!1||!f||typeof f!="object"||Array.isArray(f))return null;const p=f,x=Array.isArray(e)?e:[],g=m.title||"Array Items",F=s.options??{},E=c&&F.addable!==!1,T=c&&F.removable!==!1,O=()=>{const N=b.createDefaultValue(p,a);i&&i(r,N)()},L=N=>{if(d){const v=d(r,[N]);v&&v()}};return n.jsx(o.Box,{mb:"6",children:n.jsxs(o.Flex,{direction:"column",gap:"4",children:[n.jsx(o.Text,{as:"div",size:"4",weight:"bold",children:g}),x.length===0&&n.jsx(o.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:n.jsx(o.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),x.map((N,v)=>{var P;const U=`${r}.${v}`;return n.jsx(o.Card,{size:"3",variant:"surface",children:n.jsxs(o.Flex,{direction:"column",gap:"4",children:[n.jsxs(o.Flex,{justify:"between",align:"center",children:[n.jsxs(o.Text,{size:"3",weight:"bold",children:["Item ",v+1]}),T&&n.jsxs(o.Button,{type:"button",color:"red",variant:"soft",onClick:()=>L(v),title:"Remove item",children:[n.jsx(Y.TrashIcon,{}),"Remove"]})]}),n.jsx(o.Box,{children:n.jsx(J.JsonFormsDispatch,{schema:p,uischema:((P=s.options)==null?void 0:P.detail)||(p.type==="object"||p.properties?{type:"VerticalLayout",elements:Object.keys(p.properties||{}).map(S=>({type:"Control",scope:`#/properties/${S}`}))}:{type:"Control",scope:"#"}),path:U,enabled:c,renderers:void 0,cells:void 0})})]})},U)}),E&&n.jsx(o.Box,{mt:"2",children:n.jsxs(o.Button,{type:"button",variant:"surface",onClick:O,children:[n.jsx(Y.PlusIcon,{}),"Add Item"]})})]})})},Oe=J.withJsonFormsArrayControlProps(rn),At=b.rankWith(3,b.isObjectArrayControl),Ft=({uischema:e,visible:r})=>{const t=e;return r===!1?null:n.jsx(o.Box,{mb:"4",children:n.jsx(o.Heading,{size:"4",children:t.text})})},Ot=b.rankWith(1,b.uiTypeIs("Label")),nn=b.rankWith(3,b.isPrimitiveArrayControl),on=[{tester:Xe,renderer:$t},{tester:Ke,renderer:_t},{tester:Ye,renderer:Wt},{tester:Ze,renderer:Vt},{tester:rt,renderer:tt},{tester:et,renderer:Ht},{tester:ot,renderer:Yt},{tester:lt,renderer:st},{tester:at,renderer:it},{tester:ut,renderer:ct},{tester:ft,renderer:dt},{tester:pt,renderer:ht},{tester:wt,renderer:jt},{tester:Et,renderer:Ct},{tester:St,renderer:Rt},{tester:At,renderer:Oe},{tester:nn,renderer:Oe},{tester:Ot,renderer:Ft}];exports.ArrayControl=Oe;exports.ArrayControlTester=At;exports.BooleanControl=Ge;exports.BooleanControlTester=Ye;exports.CategorizationLayoutRenderer=dt;exports.CategorizationLayoutTester=ft;exports.ComputedControl=Rt;exports.ComputedControlTester=St;exports.DateControl=nt;exports.DateControlTester=ot;exports.FileControl=ht;exports.FileControlTester=pt;exports.GroupLayoutRenderer=ct;exports.GroupLayoutTester=ut;exports.HorizontalLayoutRenderer=it;exports.HorizontalLayoutTester=at;exports.LabelRenderer=Ft;exports.LabelTester=Ot;exports.NumberControl=Je;exports.NumberControlTester=Ke;exports.RadioControl=qe;exports.RadioControlTester=Ze;exports.SearchSelectControl=tt;exports.SearchSelectControlTester=rt;exports.SearchServiceProvider=Bt;exports.SelectControl=Qe;exports.SelectControlTester=et;exports.SpreadsheetControl=jt;exports.SpreadsheetControlTester=wt;exports.TextControl=He;exports.TextControlTester=Xe;exports.UploadProvider=Pt;exports.VerticalLayoutRenderer=st;exports.VerticalLayoutTester=lt;exports.XmlControl=Ct;exports.XmlControlTester=Et;exports.radixRenderers=on;exports.useSearchService=Ve;exports.useUpload=_e;
|
|
1
|
+
"use strict";var Mt=Object.create;var Se=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var Pt=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var $t=(e,n,t)=>n in e?Se(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var _t=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of Ut(n))!Bt.call(e,c)&&c!==t&&Se(e,c,{get:()=>n[c],enumerable:!(s=zt(n,c))||s.enumerable});return e};var ve=(e,n,t)=>(t=e!=null?Mt(Pt(e)):{},_t(n||!e||!e.__esModule?Se(t,"default",{value:e,enumerable:!0}):t,e));var Me=(e,n,t)=>$t(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),y=require("react"),w=require("@jsonforms/core"),G=require("@jsonforms/react"),o=require("@radix-ui/themes"),Z=require("@radix-ui/react-icons"),Wt=require("dayjs"),Je=y.createContext(null);function Vt({children:e,onUpload:n,getDownloadUrl:t}){const s={onUpload:n,getDownloadUrl:t};return r.jsx(Je.Provider,{value:s,children:e})}function Ke(){return y.useContext(Je)}const Ge=y.createContext(null);function Ht({children:e,services:n}){const t=y.useMemo(()=>n,[n]);return r.jsx(Ge.Provider,{value:t,children:e})}function Ye(e){const n=y.useContext(Ge);return!n||!e?null:n[e]??null}const fe=(e,n,t,s=void 0)=>{y.useEffect(()=>{e===!1&&t(n,s)},[e,n,t,s])},le=(e,n)=>e?e.split(`
|
|
2
|
+
`).map(t=>t.trim()==="is a required property"?`${n||"This field"} is required`:t).join(`
|
|
3
|
+
`):"",qe=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,uischema:l,schema:u,enabled:a,visible:f=!0})=>{var x;if(fe(f,t,n),f===!1)return null;const d=i.length===0;return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsx(o.TextField.Root,{value:e||"",onChange:h=>n(t,h.target.value),disabled:!a,placeholder:(x=l.options)==null?void 0:x.placeholder,color:d?void 0:"red",id:t}),!d&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),u.description&&r.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},Ze=w.rankWith(1,w.isStringControl),Xt=G.withJsonFormsControlProps(qe),Qe=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,uischema:l,schema:u,enabled:a,visible:f=!0})=>{var h;if(fe(f,t,n),f===!1)return null;const d=i.length===0,x=m=>{if(m===""){n(t,void 0);return}const v=Number(m);isNaN(v)||n(t,v)};return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsx(o.TextField.Root,{type:"number",value:e??"",onChange:m=>x(m.target.value),disabled:!a,placeholder:(h=l.options)==null?void 0:h.placeholder,color:d?void 0:"red",id:t}),!d&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),u.description&&r.jsx(o.Text,{size:"1",color:"gray",children:u.description})]})})},et=w.rankWith(2,w.or(w.isNumberControl,w.isIntegerControl)),Jt=G.withJsonFormsControlProps(Qe),tt=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,schema:l,enabled:u,visible:a=!0})=>{if(fe(a,t,n),a===!1)return null;const f=i.length===0;return r.jsxs(o.Box,{mb:"4",children:[r.jsxs(o.Flex,{gap:"2",align:"center",children:[r.jsx(o.Checkbox,{checked:!!e,onCheckedChange:d=>n(t,d===!0),disabled:!u,id:t}),r.jsxs(o.Text,{as:"label",size:"2",htmlFor:t,children:[s," ",c&&"*"]})]}),!f&&r.jsx(o.Text,{color:"red",size:"1",className:"block mt-1",children:le(i,s)}),l.description&&r.jsx(o.Text,{size:"1",color:"gray",className:"block mt-1",children:l.description})]})},rt=w.rankWith(2,w.isBooleanControl),Kt=G.withJsonFormsControlProps(tt),nt=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,schema:l,enabled:u,visible:a=!0})=>{if(fe(a,t,n),a===!1)return null;const f=i.length===0;let d=[];l.enum?d=l.enum.map(h=>({value:h,label:String(h)})):l.oneOf&&(d=l.oneOf.map(h=>({value:h.const,label:h.title||String(h.const)})));const x=e;return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"div",size:"2",weight:"bold",children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsx(o.RadioGroup.Root,{value:x!==void 0?String(x):"",onValueChange:h=>{const m=d.find(v=>String(v.value)===h);m&&n(t,m.value)},disabled:!u,children:r.jsx(o.Flex,{direction:"row",style:{flexWrap:"wrap",columnGap:"clamp(14px, 3vw, 36px)",rowGap:"clamp(8px, 1.6vw, 14px)"},children:d.map(h=>r.jsxs(o.Flex,{align:"center",gap:"2",style:{minWidth:"max-content"},children:[r.jsx(o.RadioGroup.Item,{value:String(h.value)}),r.jsx(o.Text,{size:"2",color:u?void 0:"gray",children:h.label})]},String(h.value)))})}),!f&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),l.description&&r.jsx(o.Text,{size:"1",color:"gray",children:l.description})]})})},ot=(e,n,t)=>{var c;return w.or(w.isEnumControl,w.isOneOfControl)(e,n,t)&&((c=e==null?void 0:e.options)==null?void 0:c.format)==="radio"?3:-1},Gt=G.withJsonFormsControlProps(nt),st=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,schema:l,uischema:u,enabled:a,visible:f=!0})=>{var U,$,N;fe(f,t,n);const d=((U=u.options)==null?void 0:U.autocomplete)===!0,[x,h]=y.useState(!1),[m,v]=y.useState(""),[D,A]=y.useState(0),j=y.useRef(null);if(y.useEffect(()=>{if(!d||!x)return;const T=b=>{j.current&&!j.current.contains(b.target)&&h(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[d,x]),f===!1)return null;const R=i.length===0;let S=[];l.enum?S=l.enum.map(T=>({value:String(T),label:String(T)})):l.oneOf&&(S=l.oneOf.map(T=>({value:String(T.const),label:T.title||String(T.const)})));const O=e!==void 0?String(e):"",I=(($=u.options)==null?void 0:$.placeholder)||"Select an option";if(d){const T=((N=S.find(E=>E.value===O))==null?void 0:N.label)??"",b=x?S.filter(E=>E.label.toLowerCase().includes(m.toLowerCase())):S,H=Math.min(D,b.length-1),X=E=>{n(t,E.value),h(!1)},_=E=>{E.stopPropagation(),n(t,void 0),v("")},J=E=>{(E.key==="Enter"||E.key===" ")&&_(E)};return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsxs("div",{ref:j,style:{position:"relative"},children:[r.jsx(o.TextField.Root,{id:t,value:x?m:T,placeholder:I,disabled:!a,style:R?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:E=>{v(E.target.value),A(0),x||h(!0)},onFocus:()=>{a&&!x&&(v(""),A(0),h(!0))},onKeyDown:E=>{E.key==="Escape"?h(!1):E.key==="ArrowDown"?(E.preventDefault(),x?A(Y=>Math.min(Y+1,b.length-1)):(v(""),h(!0))):E.key==="ArrowUp"?(E.preventDefault(),x&&A(Y=>Math.max(Y-1,0))):E.key==="Enter"&&x&&b[H]&&(E.preventDefault(),X(b[H]))},children:r.jsx(o.TextField.Slot,{side:"right",children:r.jsxs(o.Flex,{align:"center",gap:"1",children:[O&&a&&r.jsx("span",{role:"button",tabIndex:0,onMouseDown:E=>E.preventDefault(),onClick:_,onKeyDown:J,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),r.jsx(Z.ChevronDownIcon,{style:{transform:x?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),x&&r.jsx(o.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:r.jsx(o.ScrollArea,{style:{maxHeight:240},children:r.jsxs(o.Box,{p:"1",children:[b.length===0&&r.jsx(o.Box,{px:"3",py:"2",children:r.jsx(o.Text,{size:"2",color:"gray",children:"No results found."})}),b.map((E,Y)=>r.jsx(o.Box,{px:"3",py:"2",onMouseDown:K=>K.preventDefault(),onClick:()=>X(E),onMouseEnter:()=>A(Y),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:Y===H?"var(--accent-4)":E.value===O?"var(--accent-3)":void 0},children:r.jsx(o.Text,{size:"2",children:E.label})},E.value))]})})})]}),!R&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),l.description&&r.jsx(o.Text,{size:"1",color:"gray",children:l.description})]})})}return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsxs(o.Select.Root,{value:O,onValueChange:T=>n(t,T),disabled:!a,children:[r.jsx(o.Select.Trigger,{placeholder:I,color:R?void 0:"red",id:t}),r.jsx(o.Select.Content,{children:S.map(T=>r.jsx(o.Select.Item,{value:T.value,children:T.label},T.value))})]}),!R&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),l.description&&r.jsx(o.Text,{size:"1",color:"gray",children:l.description})]})})},it=w.rankWith(2,w.or(w.isEnumControl,w.isOneOfControl)),Yt=G.withJsonFormsControlProps(st),qt={"small-list":{fetchOnOpen:!0,searchable:!1,paginated:!1},"large-searchable-list":{fetchOnOpen:!0,searchable:!0,paginated:!1},"large-paginated-list":{fetchOnOpen:!1,searchable:!0,paginated:!0}},Zt=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,enabled:l,visible:u=!0,schema:a,uischema:f})=>{var C;const d=(a==null?void 0:a["x-search"])??{service:""},x=d.service??"",h=d.mode??"large-paginated-list",m=qt[h],v=(m==null?void 0:m.fetchOnOpen)??!1,D=d.params,A=Ye(x),j=a.type==="object",R=j?typeof e=="string"?{value:e}:e??void 0:void 0,S=j?R==null?void 0:R.value:e,O=R==null?void 0:R.label,I=x?A?m?null:`Invalid x-search.mode "${h}". Expected "small-list", "large-searchable-list", or "large-paginated-list".`:`Search service "${x}" is not registered.`:"Search not configured.",U=l!==!1,$=!i||i.length===0,[N,T]=y.useState(!1),[b,H]=y.useState(""),[X,_]=y.useState([]),[J,E]=y.useState(!1),[Y,K]=y.useState(!1),[ae,oe]=y.useState(!1),[ce,p]=y.useState(null),[F,W]=y.useState(void 0),k=y.useRef(void 0),z=y.useRef(null),Q=y.useRef(null),ee=y.useRef(null),te=y.useRef(void 0);y.useEffect(()=>{var V,L;if(!S){W(void 0),te.current=void 0;return}if(((V=te.current)==null?void 0:V.value)===S&&((L=te.current)==null?void 0:L.label)===O)return;if(te.current={value:S,label:O},j&&O){W({id:S,name:O});return}if(W({id:S,name:O??S}),!(A!=null&&A.resolve))return;let g=!1;return A.resolve(S,D).then(M=>{!g&&M&&W(M)}).catch(()=>{}),()=>{g=!0}},[S,O,j,A,D]);const P=y.useCallback(async(g,V=!1)=>{var M;if(!A){p("Search service not configured.");return}(M=Q.current)==null||M.abort();const L=new AbortController;Q.current=L,V?oe(!0):(K(!0),oe(!1),p(null));try{const se=await A.search({query:g,cursor:V?k.current:void 0,signal:L.signal,params:D}),xe=se.options??[];_(V?Re=>[...Re,...xe]:xe),k.current=se.nextCursor,E(((m==null?void 0:m.paginated)??!1)&&se.nextCursor!=null)}catch{if(L.signal.aborted)return;p("Failed to load results. Please try again.")}finally{L.signal.aborted||(V?oe(!1):K(!1))}},[A,m==null?void 0:m.paginated,D]);if(y.useEffect(()=>{if(!N)return;const g=V=>{ee.current&&!ee.current.contains(V.target)&&T(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[N]),y.useEffect(()=>{var g;N||((g=Q.current)==null||g.abort(),H(""),_([]),E(!1),p(null),K(!1),oe(!1),k.current=void 0)},[N]),y.useEffect(()=>{if(!N)return;if(!b&&!v){_([]),E(!1),p(null),k.current=void 0;return}z.current&&clearTimeout(z.current);const g=b?300:0;return z.current=setTimeout(()=>{_([]),E(!1),k.current=void 0,P(b)},g),()=>{z.current&&clearTimeout(z.current)}},[b,N,v,P]),fe(u,t,n),u===!1)return null;const be=()=>{H(""),_([]),E(!1),p(null),k.current=void 0,T(!0)},je=g=>{n(t,j?{value:g.id,label:g.name}:g.id),W(g),te.current={value:g.id,label:j?g.name:void 0},T(!1)},Te=g=>{g.stopPropagation(),n(t,void 0),W(void 0)},Ce=g=>{(g.key==="Enter"||g.key===" ")&&Te(g)},Ee=((C=f==null?void 0:f.options)==null?void 0:C.placeholder)??"Select an option";return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:t,children:[s," ",c&&r.jsx(o.Text,{color:"red",children:"*"})]}),r.jsxs("div",{ref:ee,style:{position:"relative"},children:[r.jsx(o.TextField.Root,{id:t,value:N?b:(F==null?void 0:F.name)??"",placeholder:N&&(m!=null&&m.searchable)?"Search...":Ee,disabled:!U,readOnly:N&&!(m!=null&&m.searchable),style:$?void 0:{outline:"2px solid var(--red-7)",outlineOffset:"-1px"},onChange:g=>{m!=null&&m.searchable&&(H(g.target.value),N||be())},onFocus:()=>{U&&!N&&be()},onKeyDown:g=>{g.key==="Escape"&&T(!1)},children:r.jsx(o.TextField.Slot,{side:"right",children:r.jsxs(o.Flex,{align:"center",gap:"1",children:[S&&U&&r.jsx("span",{role:"button",tabIndex:0,onMouseDown:g=>g.preventDefault(),onClick:Te,onKeyDown:Ce,style:{lineHeight:1,color:"var(--gray-9)",padding:"0 2px",cursor:"pointer"},"aria-label":"Clear selection",children:"×"}),r.jsx(Z.ChevronDownIcon,{style:{transform:N?"rotate(180deg)":void 0,transition:"transform 150ms"}})]})})}),N&&r.jsx(o.Box,{style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:50,background:"var(--color-panel-solid)",borderRadius:"var(--radius-3)",boxShadow:"var(--shadow-5)",border:"1px solid var(--gray-a6)",overflow:"hidden"},children:I?r.jsx(o.Box,{p:"3",children:r.jsx(o.Text,{size:"2",color:"gray",children:I})}):r.jsx(o.ScrollArea,{style:{maxHeight:240},children:r.jsxs(o.Box,{p:"1",children:[Y&&r.jsx(o.Flex,{justify:"center",p:"4",children:r.jsx(o.Spinner,{})}),!Y&&ce&&r.jsx(o.Box,{px:"3",py:"2",children:r.jsx(o.Text,{size:"2",color:"red",children:ce})}),!Y&&!ce&&X.length===0&&r.jsx(o.Box,{px:"3",py:"2",children:r.jsx(o.Text,{size:"2",color:"gray",children:b||v?"No results found.":"Type to search…"})}),X.map(g=>r.jsx(o.Box,{px:"3",py:"2",onMouseDown:V=>V.preventDefault(),onClick:()=>je(g),style:{cursor:"pointer",borderRadius:"var(--radius-2)",backgroundColor:g.id===S?"var(--accent-3)":void 0},className:"hover:bg-(--gray-3)",children:r.jsx(o.Text,{size:"2",children:g.name})},g.id)),(m==null?void 0:m.paginated)&&J&&!ae&&r.jsx(o.Box,{px:"3",py:"2",children:r.jsx(o.Button,{variant:"ghost",size:"1",style:{width:"100%"},onMouseDown:g=>g.preventDefault(),onClick:()=>void P(b,!0),children:"Load more"})}),ae&&r.jsx(o.Flex,{justify:"center",p:"2",children:r.jsx(o.Spinner,{})})]})})})]}),!$&&r.jsx(o.Text,{color:"red",size:"1",children:le(i,s)}),a.description&&r.jsx(o.Text,{size:"1",color:"gray",children:a.description})]})})},lt=G.withJsonFormsControlProps(Zt),at=w.rankWith(3,w.schemaMatches(e=>{const n=e["x-search"];return(e.type==="string"||e.type==="object")&&typeof(n==null?void 0:n.service)=="string"&&n.service!==""})),Qt=(e,n)=>Wt(`${e}T${n}`).format(),er=({path:e,label:n,required:t,errors:s,description:c,children:i})=>{const l=s.length===0;return r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",htmlFor:e,children:[n," ",t&&r.jsx(o.Text,{color:"red",children:"*"})]}),i,!l&&r.jsx(o.Text,{color:"red",size:"1",children:le(s,n)}),c&&r.jsx(o.Text,{size:"1",color:"gray",children:c})]})})},ct=({data:e,handleChange:n,path:t,label:s,required:c,errors:i,schema:l,enabled:u,visible:a=!0})=>{if(y.useEffect(()=>{a===!1&&n(t,void 0)},[a,t,n]),a===!1)return null;const f=i.length===0,d=typeof e=="string"?e:"",x=j=>r.jsx(er,{path:t,label:s,required:c,errors:i,description:l.description,children:j});if(l.format==="time")return x(r.jsx(o.TextField.Root,{type:"time",value:d,onChange:j=>n(t,j.target.value),disabled:!u,color:f?void 0:"red",id:t}));const h=l.format==="date-time",[m="",v=""]=d.split("T"),D=v.slice(0,5),A=(j,R)=>{if(!j){n(t,void 0);return}n(t,h?Qt(j,R||"00:00"):j)};return x(r.jsxs(o.Flex,{gap:"2",align:"center",children:[r.jsx(o.TextField.Root,{type:"date",value:m,disabled:!u,color:f?void 0:"red",onChange:j=>A(j.target.value,D),id:t,style:{flex:1}}),h&&r.jsx(o.TextField.Root,{type:"time",value:D,disabled:!u||!m,color:f?void 0:"red",onChange:j=>A(m,j.target.value),style:{flex:1}})]}))},ut=w.rankWith(2,w.or(w.isDateControl,w.isDateTimeControl,w.isTimeControl)),tr=G.withJsonFormsControlProps(ct),dt=({uischema:e,schema:n,path:t,renderers:s,cells:c,enabled:i,visible:l=!0})=>{const a=e.elements;return l===!1?null:r.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((f,d)=>r.jsx(G.JsonFormsDispatch,{uischema:f,schema:n,path:t,renderers:s,cells:c,enabled:i},`${t}-${d}`))})},ft=w.rankWith(1,w.uiTypeIs("VerticalLayout")),ht=({uischema:e,schema:n,path:t,renderers:s,cells:c,enabled:i,visible:l=!0})=>{const a=e.elements;return l===!1?null:r.jsx(o.Flex,{direction:"row",gap:"4",children:a.map((f,d)=>r.jsx(o.Box,{style:{flex:1},children:r.jsx(G.JsonFormsDispatch,{uischema:f,schema:n,path:t,renderers:s,cells:c,enabled:i})},`${t}-${d}`))})},pt=w.rankWith(1,w.uiTypeIs("HorizontalLayout")),xt=({uischema:e,schema:n,path:t,renderers:s,cells:c,enabled:i,visible:l=!0})=>{const u=e,a=u.elements;return l===!1?null:r.jsxs(o.Box,{mb:"6",children:[u.label&&r.jsx(o.Heading,{size:"3",mb:"3",className:"text-gray-500 uppercase tracking-wide font-semibold",children:u.label}),r.jsx(o.Flex,{direction:"column",gap:"4",children:a.map((f,d)=>r.jsx(G.JsonFormsDispatch,{uischema:f,schema:n,path:t,renderers:s,cells:c,enabled:i},`${t}-${d}`))})]})},mt=w.rankWith(1,w.uiTypeIs("Group")),gt=({uischema:e,schema:n,path:t,renderers:s,cells:c,enabled:i,visible:l=!0})=>{var h;const a=e.elements.filter(m=>m.type==="Category"),[f,d]=y.useState(((h=a[0])==null?void 0:h.label)||"");if(l===!1||!a.length)return null;const x=a.find(m=>m.label===f)?f:a[0].label;return r.jsxs(o.Tabs.Root,{value:x,onValueChange:d,children:[r.jsx(o.Tabs.List,{children:a.map((m,v)=>r.jsx(o.Tabs.Trigger,{value:m.label,children:m.label},`${t}-${v}`))}),r.jsx(o.Box,{pt:"3",children:a.map((m,v)=>r.jsx(o.Tabs.Content,{value:m.label,children:r.jsx(o.Flex,{direction:"column",gap:"4",children:m.elements.map((D,A)=>r.jsx(G.JsonFormsDispatch,{uischema:D,schema:n,path:t,renderers:s,cells:c,enabled:i},`${t}-${v}-${A}`))})},`${t}-${v}`))})]})},yt=w.rankWith(1,w.uiTypeIs("Categorization"));function ue(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}function de(e){const n=e.split(",").map(i=>i.trim()).filter(Boolean),t=n.filter(i=>i.startsWith(".")),c=(t.length>0?t:n).map(i=>{if(i.endsWith("/*"))return i.split("/")[0].toUpperCase()+"S";if(i.startsWith("."))return i.slice(1).toUpperCase();const l=i.split("/")[1];return l?l.toUpperCase():i});return[...new Set(c)].join(", ")}function rr(e){return e?Array.isArray(e)?e:[e]:[]}const nr=({data:e,handleChange:n,path:t,label:s,required:c,uischema:i,schema:l,enabled:u,errors:a,visible:f=!0})=>{const d=Ke();fe(f,t,n);const x=!a||a.length===0,h=(l==null?void 0:l["x-file"])??{},m=(i==null?void 0:i.options)??{},v=h.maxFiles??m.maxFiles??1,D=h.maxSize??m.maxSize??5*1024*1024,A=h.accept??m.accept??"image/*,application/pdf",j=v>1,R=u!==!1,[S,O]=y.useState(!1),[I,U]=y.useState(null),[$,N]=y.useState({}),T=y.useRef(new Set),b=y.useRef(null),H=rr(e),X=H.length>=v;y.useEffect(()=>()=>{T.current.forEach(p=>URL.revokeObjectURL(p)),T.current.clear()},[]);const _=y.useCallback(async p=>{if(U(null),H.length>=v){U(`Maximum ${v} file${v>1?"s":""} allowed.`);return}if(p.size>D){U(`File exceeds the ${ue(D)} limit.`);return}if(!A.split(",").map(k=>k.trim()).some(k=>k==="*"||k==="*/*"?!0:k.endsWith("/*")?p.type.startsWith(k.slice(0,-1)):k.startsWith(".")?p.name.toLowerCase().endsWith(k.toLowerCase()):p.type===k)){U(`Invalid type. Accepted: ${de(A)}`);return}if(!(d!=null&&d.onUpload)){U("Upload service not configured.");return}try{const k=await d.onUpload(p),z=URL.createObjectURL(p);T.current.add(z);const Q={key:k.key,name:k.name??p.name,blobUrl:z};N(te=>({...te,[k.key]:Q}));const ee=[...H,k.key];n(t,j?ee:ee[0])}catch{U("Upload failed. Please try again."),b.current&&(b.current.value="")}},[H,v,D,A,d,t,n,j]);if(f===!1)return null;const J=p=>{p.preventDefault(),p.stopPropagation(),!(!R||X)&&O(p.type==="dragenter"||p.type==="dragover")},E=p=>{var F;p.preventDefault(),p.stopPropagation(),O(!1),!(!R||X)&&(F=p.dataTransfer.files)!=null&&F[0]&&_(p.dataTransfer.files[0])},Y=p=>{var F;(F=p.target.files)!=null&&F[0]&&(_(p.target.files[0]),p.target.value="")},K=p=>{if(!R)return;N(W=>{var Q;const k={...W},z=(Q=k[p])==null?void 0:Q.blobUrl;return z&&(URL.revokeObjectURL(z),T.current.delete(z)),delete k[p],k});const F=H.filter(W=>W!==p);n(t,j?F.length>0?F:void 0:F[0])},ae=async(p,F)=>{var z,Q,ee;p.preventDefault();const W=(z=$[F])==null?void 0:z.blobUrl;if(W){(Q=window.open(W,"_blank","noopener,noreferrer"))==null||Q.focus();return}const k=window.open("","_blank");if(k)try{const te=await((ee=d==null?void 0:d.getDownloadUrl)==null?void 0:ee.call(d,F));te!=null&&te.url?k.location.href=te.url:k.close()}catch{k.close()}};if(!R&&H.length===0)return null;const oe=v-H.length,ce=R&&!X;return r.jsxs(o.Box,{mb:"4",children:[r.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&r.jsx(o.Text,{color:"red",children:" *"})]}),r.jsx(o.Text,{size:"1",color:"gray",children:j?`Up to ${v} files · ${ue(D)} each · ${de(A)}`:`${ue(D)} · ${de(A)}`})]}),H.map(p=>{var F;return r.jsx(o.Card,{size:"2",variant:"surface",mb:"2",children:r.jsxs(o.Flex,{align:"center",gap:"3",children:[r.jsx(o.Box,{style:{background:"var(--blue-3)",padding:8,borderRadius:6,color:"var(--blue-9)",flexShrink:0},children:r.jsx(Z.FileTextIcon,{width:"20",height:"20"})}),r.jsx(o.Box,{style:{flex:1,overflow:"hidden"},children:r.jsx(o.Text,{size:"2",weight:"bold",style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:((F=$[p])==null?void 0:F.name)??"Uploaded File"})}),r.jsxs(o.Flex,{align:"center",gap:"2",style:{flexShrink:0},children:[r.jsx(o.Button,{variant:"soft",color:"blue",size:"1",onClick:W=>ae(W,p),children:"View"}),r.jsx(Z.CheckCircledIcon,{style:{color:"var(--green-9)",width:18,height:18}}),R&&r.jsx(o.IconButton,{variant:"ghost",color:"gray",onClick:()=>K(p),children:r.jsx(Z.Cross2Icon,{})})]})]})},p)}),ce&&r.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{var p;return(p=b.current)==null?void 0:p.click()},onKeyDown:p=>{var F;(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),(F=b.current)==null||F.click())},onDragEnter:J,onDragLeave:J,onDragOver:J,onDrop:E,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",S?"border-blue-500 bg-blue-50":I?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:[r.jsx("input",{ref:b,type:"file",style:{display:"none"},accept:A,onChange:Y}),r.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:I?r.jsxs(r.Fragment,{children:[r.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),r.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:I}),r.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):r.jsxs(r.Fragment,{children:[r.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),r.jsx(o.Text,{size:"2",weight:"medium",children:H.length>0?`Add another file (${oe} remaining)`:"Click to upload or drag and drop"}),r.jsxs(o.Text,{size:"1",color:"gray",children:[ue(D)," max · ",de(A)]})]})})]}),R&&X&&j&&r.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block",textAlign:"center"},children:["Maximum ",v," files uploaded. Remove one to replace it."]}),!x&&r.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(a,s)})]})},bt=G.withJsonFormsControlProps(nr),vt=w.rankWith(10,w.and(w.schemaMatches(e=>{if(e.type==="string"&&e.format==="file")return!0;if(e.type==="array"){const n=e.items;return(n==null?void 0:n.type)==="string"&&(n==null?void 0:n.format)==="file"}return!1})));function Tt(e,n){return e!==!1&&n!==!0}class Fe extends Error{}async function or(e,n){const{read:t,utils:s}=await import("@e965/xlsx"),c=t(e,{type:"array",cellDates:!0});if(c.SheetNames.length===0)throw new Fe("This file has no sheets.");const i=n??c.SheetNames[0],l=c.Sheets[i];if(!l)throw new Fe(`This file doesn't have a sheet named "${i}".`);const u=s.sheet_to_json(l,{header:1,raw:!0,defval:null});return{sheetName:i,matrix:u,rowCount:u.length,colCount:Math.max(0,...u.map(a=>a.length))}}function sr(e){let n=e+1,t="";for(;n>0;){const s=(n-1)%26;t=String.fromCharCode(65+s)+t,n=Math.floor((n-1)/26)}return t}class ne extends Error{constructor(t,s){super(s??t);Me(this,"code");this.code=t,this.name="FormulaError"}}const ir=["IFS","IFERROR","AND","OR","NOT","ROUND","ROUNDUP","ROUNDDOWN","INDEX","VLOOKUP","HLOOKUP","SUM","AVERAGE","COUNT","DATE","TODAY"],lr=["MAX","MIN","MAXA","MINA","MEDIAN","LARGE","SMALL","PERMUT","PERMUTATIONA","MATCH","SWITCH","SUBSTITUTE","TEXTJOIN","COUNTA","UPPER"],ar=["YEAR","MONTH","DAY","WEEKDAY"],cr=["IF"],ur=["CONCATENATE","CONCAT","LEN","TRIM","LOWER","LEFT","RIGHT","MID","FIND","SEARCH"],dr=new Set([...ir,...lr,...ar,...ur,...cr]),fr=/"(?:[^"]|"")*"/g,ze=new RegExp("(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_.]*)\\s*\\(","g");function hr(e){const n=e.replace(fr,s=>" ".repeat(s.length));ze.lastIndex=0;let t;for(;(t=ze.exec(n))!==null;){const s=t[1].toUpperCase();if(!dr.has(s))throw new ne("NAME",`Function ${s} is not allowed.`)}}function pr(e,n,t){let s=e;if(s==null)throw t.NA;if(typeof s=="object"&&!(s instanceof t)&&(s=n.retrieveRef(s)),s instanceof t)throw s;if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;throw t.VALUE}function wt(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function ge(e){const n=wt(e);return Array.isArray(n)?n.flat(1/0):[n]}function B(e){const n=wt(e);return Array.isArray(n)?n.flat(1/0)[0]:n}function we(e){return e===void 0?void 0:B(e)}function re(e){return e==null||e===""?"":typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof Date?e.toLocaleDateString():String(e)}function xr(e,n){return e instanceof n?e:new n(e.message||"#ERROR!")}function q(e){return e.find(n=>n instanceof Error)}function mr(e,n){const t=i=>{throw xr(i,n)},s=(i,{checkArgsForErrors:l=!0}={})=>(...u)=>{const a=u.flatMap(ge);if(l){const d=q(a);d&&t(d)}const f=i(...a);return f instanceof Error?t(f):f},c=(i,{toText:l=!1}={})=>u=>{const a=B(u),f=q([a]);f&&t(f);const d=i(l?re(a):a);return d instanceof Error?t(d):d};return{IF:(i,l,u,a)=>{const f=pr(l,i,n);if(u==null)throw n.NA;return f?u:a??!1},MAX:s(e.MAX),MIN:s(e.MIN),MAXA:s(e.MAXA),MINA:s(e.MINA),MEDIAN:s(e.MEDIAN),COUNTA:s(e.COUNTA,{checkArgsForErrors:!1}),LARGE:(i,l)=>{const u=ge(i),a=B(l),f=q([...u,a]);f&&t(f);const d=e.LARGE(u,a);return d instanceof Error?t(d):d},SMALL:(i,l)=>{const u=ge(i),a=B(l),f=q([...u,a]);f&&t(f);const d=e.SMALL(u,a);return d instanceof Error?t(d):d},PERMUT:(i,l)=>{const u=[B(i),B(l)],a=q(u);a&&t(a);const f=e.PERMUT(u[0],u[1]);return f instanceof Error?t(f):f},PERMUTATIONA:(i,l)=>{const u=[B(i),B(l)],a=q(u);a&&t(a);const f=e.PERMUTATIONA(u[0],u[1]);return f instanceof Error?t(f):f},MATCH:(i,l)=>{const u=B(i),a=ge(l),f=q([u,...a]);f&&t(f);const d=e.MATCH(u,a,0);return d instanceof Error?t(d):d},SWITCH:(...i)=>{const l=i.map(B),u=q(l);u&&t(u);const a=e.SWITCH(...l);return a instanceof Error?t(a):a},SUBSTITUTE:(i,l,u,a)=>{const f=[re(B(i)),re(B(l)),re(B(u))];a!==void 0&&f.push(B(a));const d=q(f);d&&t(d);const x=e.SUBSTITUTE(...f);return x instanceof Error?t(x):x},TEXTJOIN:(i,l,...u)=>{const a=re(B(i)),f=B(l),d=u.flatMap(ge).map(re),x=q([a,f]);x&&t(x);const h=e.TEXTJOIN(a,f,d);return h instanceof Error?t(h):h},UPPER:c(e.UPPER),YEAR:c(e.YEAR),MONTH:c(e.MONTH),DAY:c(e.DAY),WEEKDAY:(i,l)=>{const u=B(i),a=B(l),f=q([u]);f&&t(f);const d=e.WEEKDAY(u,a);return d instanceof Error?t(d):d},CONCATENATE:(...i)=>{const l=i.flatMap(ge),u=q(l);u&&t(u);const a=e.CONCATENATE(...l.map(re));return a instanceof Error?t(a):a},CONCAT:(...i)=>{const l=i.flatMap(ge),u=q(l);u&&t(u);const a=e.CONCAT(...l.map(re));return a instanceof Error?t(a):a},LEN:c(e.LEN,{toText:!0}),TRIM:c(e.TRIM,{toText:!0}),LOWER:c(e.LOWER,{toText:!0}),LEFT:(i,l)=>{const u=B(i),a=we(l),f=q([u]);f&&t(f);const d=e.LEFT(re(u),a);return d instanceof Error?t(d):d},RIGHT:(i,l)=>{const u=B(i),a=we(l),f=q([u]);f&&t(f);const d=e.RIGHT(re(u),a);return d instanceof Error?t(d):d},MID:(i,l,u)=>{const a=B(i),f=B(l),d=B(u),x=q([a,f,d]);x&&t(x);const h=e.MID(re(a),f,d);return h instanceof Error?t(h):h},FIND:(i,l,u)=>{const a=B(i),f=B(l),d=we(u),x=q([a,f]);x&&t(x);const h=e.FIND(re(a),re(f),d);return h instanceof Error?t(h):h},SEARCH:(i,l,u)=>{const a=B(i),f=B(l),d=we(u),x=q([a,f]);x&&t(x);const h=e.SEARCH(re(a),re(f),d);return h instanceof Error?t(h):h}}}const gr={"#REF!":"REF","#VALUE!":"VALUE","#DIV/0!":"DIV0","#NAME?":"NAME","#N/A":"NA","#NUM!":"NUM","#NULL!":"NULL"};function Ue(e){return gr[e.error]??"ERROR"}function Pe(e,n){if(e instanceof ne)return e;if(e instanceof n){const t=e.details;return t instanceof ne?t:t instanceof n?new ne(Ue(t),t.message):new ne(Ue(e),e.message)}return new ne("ERROR",e instanceof Error?e.message:void 0)}function yr(e){return Math.max(0,...e.map(n=>(n==null?void 0:n.length)??0))}function br(e){return n=>{const t=e[n.row-1];if(n.row<1||n.col<1||t==null||n.col-1>=t.length)throw new ne("REF");const s=t[n.col-1];return s==null||s===""?null:s}}function vr(e){return n=>{const t=Math.min(n.from.row,n.to.row),s=Math.min(n.from.col,n.to.col),c=Math.max(n.from.row,n.to.row),i=Math.max(n.from.col,n.to.col),l=yr(e);if(t>e.length||s>l)throw new ne("REF");const u=Math.min(c,e.length),a=[];for(let f=t;f<=u;f++){const d=e[f-1],x=[];if(d!=null){const h=Math.min(i,d.length);for(let m=s;m<=h;m++){const v=d[m-1];x.push(v==null||v===""?null:v)}}a.push(x)}return a}}function Tr(e){if(e==null||e==="")return null;if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e instanceof Date)return e;throw new ne("VALUE")}async function jt(e,n){if(typeof e!="string")throw new ne("ERROR");const t=e.trim();if(t==="")throw new ne("ERROR");const s=t.startsWith("=")?t.slice(1):t;hr(s);const[c,i]=await Promise.all([import("fast-formula-parser"),import("@formulajs/formulajs")]),l=c.default??c,u=l.FormulaError,a=new l({...n,functions:mr(i,u)});let f;try{f=a.parse(s,{row:1,col:1,sheet:"Sheet1"})}catch(d){throw Pe(d,u)}if(f instanceof u)throw Pe(f,u);return Tr(f)}async function wr(e,n){return jt(n,{onCell:br(e),onRange:vr(e)})}const Be=-1;async function Ct(e,n){const t=Object.keys(e);return jt(n,{onVariable:s=>{const c=t.indexOf(s);return c===-1?null:{row:Be,col:c+1}},onCell:s=>{if(s.row===Be)return e[t[s.col-1]]??null;throw new ne("REF")},onRange:()=>{throw new ne("REF")}})}const Et={REF:"#REF!",VALUE:"#VALUE!",DIV0:"#DIV/0!",NAME:"#NAME?",ERROR:"#ERROR!",NA:"#N/A",NUM:"#NUM!",NULL:"#NULL!"};function ke(e){const n=e instanceof ne?e.code:"ERROR";return Et[n]}async function jr(e,n){return e.length===0?n.map(t=>({id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:Et.ERROR})):Promise.all(n.map(async t=>{try{if(!t||typeof t.label!="string"||typeof t.expression!="string"||typeof t.id!="string")throw new ne("ERROR");return{id:t.id,label:t.label,value:await wr(e,t.expression)}}catch(s){return{id:typeof(t==null?void 0:t.id)=="string"?t.id:"(unknown)",label:(t==null?void 0:t.label)??"(unknown)",value:null,error:ke(s)}}}))}function $e(e){const n=new Set;for(const{id:t}of e){if(n.has(t))return t;n.add(t)}return null}function Rt(e){const{columnHeader:n,rowHeader:t,columns:s,rows:c}=e;if(s!==void 0&&!Array.isArray(s))return"columns must be an array of { id, label } objects.";if(c!==void 0&&!Array.isArray(c))return"rows must be an array of { id, label } objects.";if(s!==void 0&&s.length===0)return"columns is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";if(c!==void 0&&c.length===0)return"rows is declared but empty — declare at least one field, or omit it entirely for raw matrix mode.";const i=d=>!!d&&typeof d.id=="string"&&d.id!==""&&typeof d.label=="string"&&d.label!=="",l=s==null?void 0:s.findIndex(d=>!i(d));if(l!=null&&l!==-1)return`columns[${l}] must be a { id, label } object with non-empty string fields.`;const u=c==null?void 0:c.findIndex(d=>!i(d));if(u!=null&&u!==-1)return`rows[${u}] must be a { id, label } object with non-empty string fields.`;const a=!!s&&s.length>0,f=!!c&&c.length>0;if(a){const d=$e(s);if(d)return`duplicate column id "${d}" — every declared column id must be unique.`}if(f){const d=$e(c);if(d)return`duplicate row id "${d}" — every declared row id must be unique.`}return n&&t?"columnHeader and rowHeader cannot both be true — pick one orientation for the persisted sheet shape.":a&&f?"columns and rows cannot both be declared — pick one orientation for the persisted sheet shape.":n&&!a?"columnHeader is true but columns is missing or empty — declare the column list columnHeader positions map to.":t&&!f?"rowHeader is true but rows is missing or empty — declare the row list rowHeader positions map to.":null}function _e(e,n={}){const t=Rt(n);if(t)throw new Error(`x-spreadsheet: ${t}`);const{columnHeader:s,rowHeader:c,columns:i,rows:l}=n;return i&&i.length>0?Cr(e,i,s===!0):l&&l.length>0?Er(e,l,c===!0):e}function Cr(e,n,t){return(t?e.slice(1):e).map(c=>{const i=Object.create(null);return n.forEach((l,u)=>{i[l.id]=c[u]??null}),i})}function Er(e,n,t){const s=t?1:0,c=Math.max(0,...e.map(l=>l.length)),i=Math.max(0,c-s);return Array.from({length:i},(l,u)=>{const a=s+u,f=Object.create(null);return n.forEach((d,x)=>{var h;f[d.id]=((h=e[x])==null?void 0:h[a])??null}),f})}function Rr(e){return!Array.isArray(e[0])}function Sr(e){const n=Object.create(null);for(const{id:t,label:s,value:c,error:i}of e)n[t]=i===void 0?{label:s,value:c}:{label:s,value:c,error:i};return n}function Oe(e,n){const t=s=>s instanceof Date?s.toISOString():s??null;return t(e)===t(n)}function Ar(e,n){const t=e??{},s=n??{},c=Object.keys(t);return c.length!==Object.keys(s).length?!1:c.every(i=>{if(!Object.prototype.hasOwnProperty.call(s,i))return!1;const l=t[i],u=s[i];return l.label===u.label&&l.error===u.error&&Oe(l.value,u.value)})}function Fr(e,n){if(e==null||n==null)return e===n;const t=Array.isArray(e);if(t!==Array.isArray(n))return!1;if(t){const l=e,u=n;return l.length===u.length&&l.every((a,f)=>Oe(a,u[f]))}const s=e,c=n,i=Object.keys(s);return i.length!==Object.keys(c).length?!1:i.every(l=>Object.prototype.hasOwnProperty.call(c,l)&&Oe(s[l],c[l]))}function Or(e,n){if(e===n)return!0;if(e==null||n==null)return!1;const t=e,s=n;return t.length!==s.length?!1:t.every((c,i)=>Fr(c,s[i]))}function Ir(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e instanceof Date}function kr(e,n){if(e.length===0)return[];const t=[],s=new Set;for(const i of n??[])s.has(i)||(s.add(i),t.push(i));for(const i of e)for(const l of Object.keys(i))s.has(l)||(s.add(l),t.push(l));if(t.length===0)return[];const c=e.map(i=>t.map(l=>{if(!Object.prototype.hasOwnProperty.call(i,l))return null;const u=i[l];return Ir(u)?u:null}));return[t,...c]}function Nr(e){const n=Math.max(0,...e.map(t=>t.length));return Array.from({length:n},(t,s)=>e.map(c=>c[s]??null))}const Dr=".xlsx,.xls,.csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,text/csv",Lr=10*1024*1024,Ae=200,Mr=50,zr=[];function We(e){return e==null||e===""?"":e instanceof Date?e.toLocaleDateString():String(e)}const Ur=({data:e,handleChange:n,path:t,label:s,required:c,schema:i,enabled:l,readonly:u,errors:a,visible:f=!0})=>{fe(f,t,n);const d=!a||a.length===0,x=Tt(l,u),h=(i==null?void 0:i["x-spreadsheet"])??{},m=(i==null?void 0:i["x-evaluate"])??zr,v=h.accept??Dr,D=h.maxSize??Lr,A=h.columnHeader===!0,j=h.rowHeader===!0,R=h.columns,S=h.rows,O=Array.isArray(R)&&R.length>0,I=Array.isArray(S)&&S.length>0,U=Rt({columnHeader:A,rowHeader:j,columns:R,rows:S}),$=h.showSheet!==!1,N=h.sheetName,T=h.persistSheet!==!1,b=e??null,[H,X]=y.useState(()=>b!=null&&b.sheet||Object.keys((b==null?void 0:b.derivations)??{}).length>0?"ready":"empty"),[_,J]=y.useState(null),[E,Y]=y.useState(!1),[K,ae]=y.useState(null),[oe,ce]=y.useState(null),p=y.useRef(null),F=y.useRef(null),W=(b==null?void 0:b.sheet)??null,k=y.useCallback(C=>{if(!Rr(C))return C;const g=I?S:O?R:void 0,V=kr(C,g==null?void 0:g.map(L=>L.id));return I?Nr(V):V},[O,I,R,S]),z=y.useMemo(()=>K??(W?k(W):null),[K,W,k]),Q=((oe==null?void 0:oe.matrix)===z?oe.derivations:null)??(b==null?void 0:b.derivations)??{},ee=z!=null||b!=null,te=y.useMemo(()=>{const C=O?1:0,g=I?1:0,V=z?z.slice(C):[],L=V.slice(0,Ae),M=Math.min(Mr,Math.max(0,...L.map(he=>Math.max(0,he.length-g)))),se=Array.from({length:M},(he,me)=>me+g),xe="",Re=I&&!O;return r.jsx(r.Fragment,{children:z&&$&&r.jsxs(o.Box,{mt:"3",children:[r.jsx(o.Box,{style:{overflow:"auto",maxHeight:420},children:r.jsxs(o.Table.Root,{variant:"surface",size:"1",children:[!Re&&r.jsx(o.Table.Header,{children:r.jsxs(o.Table.Row,{children:[r.jsx(o.Table.ColumnHeaderCell,{children:xe}),se.map(he=>{var me;return r.jsx(o.Table.ColumnHeaderCell,{children:O?((me=R==null?void 0:R[he])==null?void 0:me.label)??"":sr(he)},he)})]})}),r.jsx(o.Table.Body,{children:L.map((he,me)=>{var De;const Ne=C+me;return r.jsxs(o.Table.Row,{children:[r.jsx(o.Table.RowHeaderCell,{style:I?{fontWeight:700,background:"var(--gray-a3)"}:void 0,children:I?((De=S==null?void 0:S[Ne])==null?void 0:De.label)??"":O?"":Ne+1}),se.map(Le=>r.jsx(o.Table.Cell,{children:We(he[Le])},Le))]},me)})})]})}),V.length>Ae&&r.jsxs(o.Text,{size:"1",color:"gray",mt:"1",style:{display:"block"},children:["Showing first ",Ae," of ",V.length," rows"]})]})})},[z,$,O,I,R,S]),P=y.useCallback(async C=>{if(J(null),C.size>D){J(`File exceeds the ${ue(D)} limit.`);return}if(!v.split(",").map(M=>M.trim()).some(M=>M==="*"||M==="*/*"?!0:M.endsWith("/*")?C.type.startsWith(M.slice(0,-1)):M.startsWith(".")?C.name.toLowerCase().endsWith(M.toLowerCase()):C.type===M)){J(`Invalid type. Accepted: ${de(v)}`);return}X("parsing");let L;try{const M=await C.arrayBuffer();L=(await or(M,N)).matrix}catch(M){X("error"),J(M instanceof Fe?M.message:"This doesn't look like a valid spreadsheet. Please check the file and try again.");return}if(O||I)try{L=k(_e(L,{columnHeader:A,rowHeader:j,columns:R,rows:S}))}catch(M){X("error"),J(M instanceof Error?M.message:"Failed to process this sheet.");return}F.current=(e==null?void 0:e.sheet)??null,ae(L),X("ready")},[v,D,N,e,A,j,R,S,O,I,k]);if(y.useEffect(()=>{K!=null&&W!=null&&W!==F.current&&ae(null)},[K,W]),y.useEffect(()=>{if(U||m.length===0&&!T)return;let C=!1;const g=L=>{x&&(Ar(b==null?void 0:b.derivations,L==null?void 0:L.derivations)&&Or(b==null?void 0:b.sheet,L==null?void 0:L.sheet)||(F.current=(L==null?void 0:L.sheet)??null,n(t,L)))},V=z??[];if(V.length===0){b!=null&&g(void 0);return}return jr(V,m).then(L=>{if(C)return;let M;if(K!=null){if(T)try{M=_e(V,{columnHeader:O,rowHeader:I,columns:R,rows:S})}catch(xe){J(xe instanceof Error?xe.message:"Failed to process this sheet.");return}}else M=b==null?void 0:b.sheet;J(null);const se=Sr(L);ce({matrix:V,derivations:se}),g(M===void 0?{derivations:se}:{sheet:M,derivations:se})}),()=>{C=!0}},[z,K,m,x,T,O,I,R,S,U]),f===!1)return null;if(U)return r.jsxs(o.Box,{mb:"4",children:[r.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),r.jsxs(o.Text,{size:"2",color:"red",style:{display:"block"},children:["Invalid x-spreadsheet config: ",U]})]});if(!x&&!ee)return null;const be=C=>{C.preventDefault(),C.stopPropagation(),x&&Y(C.type==="dragenter"||C.type==="dragover")},je=C=>{var g;C.preventDefault(),C.stopPropagation(),Y(!1),x&&(g=C.dataTransfer.files)!=null&&g[0]&&P(C.dataTransfer.files[0])},Te=C=>{var g;(g=C.target.files)!=null&&g[0]&&(P(C.target.files[0]),C.target.value="")},Ce=()=>{x&&(ae(null),ce(null),F.current=null,J(null),X("empty"),n(t,void 0))},Ee=$&&z==null&&b!=null;return r.jsxs(o.Box,{mb:"4",children:[r.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[r.jsxs(o.Flex,{align:"center",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&r.jsx(o.Text,{color:"red",children:" *"})]}),ee&&x&&r.jsxs(r.Fragment,{children:[r.jsx(o.Tooltip,{content:"Replace spreadsheet",children:r.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var C;return(C=p.current)==null?void 0:C.click()},"aria-label":"Replace spreadsheet",children:r.jsx(Z.UploadIcon,{})})}),r.jsx(o.Tooltip,{content:"Remove spreadsheet",children:r.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:Ce,"aria-label":"Remove spreadsheet",children:r.jsx(Z.Cross2Icon,{})})})]})]}),r.jsxs(o.Text,{size:"1",color:"gray",children:[ue(D)," max · ",de(v)]})]}),ee&&_&&r.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:_}),r.jsx("input",{ref:p,type:"file",style:{display:"none"},accept:v,onChange:Te}),x&&!ee&&r.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var C;return(C=p.current)==null?void 0:C.click()},onKeyDown:C=>{var g;(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),(g=p.current)==null||g.click())},onDragEnter:be,onDragLeave:be,onDragOver:be,onDrop:je,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",E?"border-blue-500 bg-blue-50":_?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:r.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:H==="parsing"?r.jsxs(r.Fragment,{children:[r.jsx(o.Spinner,{size:"3"}),r.jsx(o.Text,{size:"2",color:"gray",children:"Parsing spreadsheet…"})]}):_?r.jsxs(r.Fragment,{children:[r.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),r.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:_}),r.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):r.jsxs(r.Fragment,{children:[r.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),r.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),r.jsxs(o.Text,{size:"1",color:"gray",children:[ue(D)," max · ",de(v)]})]})})}),te,Ee&&r.jsx(o.Text,{size:"2",color:"gray",mt:"3",style:{display:"block"},children:"Sheet preview not stored for this field — re-upload to view contents."}),Object.keys(Q).length>0&&r.jsxs(o.Box,{mt:"3",children:[r.jsx(o.Text,{size:"2",weight:"bold",as:"div",mb:"1",children:"Computed values"}),r.jsx(o.Flex,{direction:"column",gap:"1",children:Object.entries(Q).map(([C,g])=>r.jsxs(o.Flex,{justify:"between",children:[r.jsx(o.Text,{size:"2",children:g.label}),g.error?r.jsx(o.Text,{size:"2",color:"red",children:g.error}):r.jsx(o.Text,{size:"2",children:We(g.value)})]},C))})]}),!d&&r.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(a,s)})]})},St=G.withJsonFormsControlProps(Ur),At=w.rankWith(10,w.schemaMatches(e=>e.type==="object"&&typeof e["x-spreadsheet"]=="object"));class pe extends Error{}const Ve=5e6,Pr=1024,Br=/^<\?xml\s+[^>]*\bencoding\s*=\s*["']([^"']+)["']/i,$r={ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseTagValue:!0,parseAttributeValue:!0,numberParseOptions:{hex:!1,leadingZeros:!1,eNotation:!0},trimValues:!0,cdataPropName:!1,commentPropName:!1,processEntities:!0,htmlEntities:!0,ignoreDeclaration:!0,ignorePiTags:!0,alwaysCreateTextNode:!1,preserveOrder:!1,removeNSPrefix:!1,maxNestedTags:100,strictReservedNames:!0};function _r(e){const n=new Set(e);return n.size===0?()=>!1:(t,s)=>n.has(typeof s=="string"?s:s.toString())||n.has(t)}function Wr(e){const n=e instanceof Error?e.message:"";return n.startsWith("[SECURITY] Invalid name:")?"This document uses a reserved JavaScript name (__proto__, constructor or prototype) as an element or attribute name, which cannot be represented safely.":n==="External entities are not supported"||n==="Parameter entities are not supported"?`${n}. Please remove the DOCTYPE entity declarations and try again.`:n.startsWith("Maximum nested tags exceeded")?"This document is nested too deeply to parse.":n.startsWith("Entity count")||n.includes("exceeds maximum allowed")?"This document declares too many or too large entity definitions to expand safely.":"This doesn't look like a valid XML document. Please check the file and try again."}async function Vr(e,n={}){var f;if(typeof e!="string")throw new pe("This file could not be read as text.");const t=e.charCodeAt(0)===65279?e.slice(1):e;if(t.trim()==="")throw new pe("This file is empty.");if(t.length>Ve)throw new pe(`This document is too large to parse (over ${Ve/1e6} million characters).`);const s=(f=Br.exec(t.slice(0,Pr)))==null?void 0:f[1];if(s&&!/^utf-?8$/i.test(s))throw new pe(`This document declares the unsupported encoding "${s}". Only UTF-8 is supported.`);const{XMLParser:c,XMLValidator:i}=await import("fast-xml-parser"),l=i.validate(t,{allowBooleanAttributes:!1});if(l!==!0){const{msg:d,line:x,col:h}=l.err;throw new pe(`Invalid XML at line ${x}, column ${h}: ${d}`)}const u=new c({...$r,removeNSPrefix:n.removeNamespaces===!0,isArray:_r(n.arrayPaths??[])});let a;try{a=u.parse(t)}catch(d){throw new pe(Wr(d))}if(a==null||typeof a!="object"||Array.isArray(a))throw new pe("This document has no root element.");return a}const ye={found:!1},ie=e=>({found:!0,value:e});function He(e){return e==null||e===""?ye:Array.isArray(e)||e instanceof Date?ie(e):typeof e=="object"?ye:typeof e=="string"||typeof e=="number"||typeof e=="boolean"?ie(e):ye}const Hr=new Set(["true","1","yes","y"]),Xr=new Set(["false","0","no","n"]);async function Jr(e,n){switch(n.as){case void 0:return ie(e);case"string":return ie(e instanceof Date?e.toISOString():String(e));case"number":{const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?ie(t):ye}case"boolean":{const t=String(e).trim().toLowerCase();return Hr.has(t)?ie(!0):Xr.has(t)?ie(!1):ye}case"date":{const{default:t}=await import("dayjs"),{default:s}=await Promise.resolve().then(()=>require("./customParseFormat-CLvZwox5.cjs")).then(l=>l.customParseFormat);t.extend(s);const c=e instanceof Date?e.toISOString():String(e),i=n.format?t(c,n.format,!0):t(c);return i.isValid()?ie(i.format("YYYY-MM-DD")):ye}}}async function Kr(e,n){if(n.formula!==void 0){const t={};for(const[s,c]of Object.entries(n.inputs??{})){const i=He(w.Resolve.data(e,c));if(!i.found||Array.isArray(i.value))return ye;t[s]=i.value}try{return ie(await Ct(t,n.formula))}catch(s){throw new Error(`x-xml.writeTo "${n.to}": ${ke(s)}`)}}if(n.from===void 0)throw new Error(`x-xml.writeTo "${n.to}" needs either "from" or "formula".`);return He(w.Resolve.data(e,n.from))}async function Gr(e,n){const t=[];for(const s of n){let c=await Kr(e,s);const i=c.found&&Array.isArray(c.value);if(c.found&&!i&&s.map){const l=c.value instanceof Date?c.value.toISOString():String(c.value);Object.prototype.hasOwnProperty.call(s.map,l)&&(c=ie(s.map[l]))}if(c.found&&!i&&(c=await Jr(c.value,s)),!c.found){if(s.default===void 0)continue;t.push({to:s.to,value:s.default});continue}t.push({to:s.to,value:c.value})}return t}const Yr=".xml,text/xml,application/xml",qr=5*1024*1024,Zr=({data:e,handleChange:n,path:t,label:s,required:c,schema:i,enabled:l,readonly:u,errors:a,visible:f=!0})=>{fe(f,t,n);const d=!a||a.length===0,x=Tt(l,u),h=(i==null?void 0:i["x-xml"])??{},m=h.accept??Yr,v=h.maxSize??qr,D=h.arrayPaths,A=h.removeNamespaces===!0,j=h.writeTo,R=h.writeBase??"root",S=h.persistDocument!==!1,O=G.useJsonForms(),I=e??null,[U,$]=y.useState(()=>I?"ready":"empty"),[N,T]=y.useState(null),[b,H]=y.useState(!1),X=y.useRef(null),_=y.useRef(0),J=I!=null,E=j!==void 0&&j.length>0,Y=y.useCallback(async p=>{var te;const F=++_.current;if(T(null),p.size>v){T(`File exceeds the ${ue(v)} limit.`);return}if(!m.split(",").map(P=>P.trim()).some(P=>P==="*"||P==="*/*"?!0:P.endsWith("/*")?p.type.startsWith(P.slice(0,-1)):P.startsWith(".")?p.name.toLowerCase().endsWith(P.toLowerCase()):p.type===P)){T(`Invalid type. Accepted: ${de(m)}`);return}$("parsing");let z;try{const P=await p.text();z=await Vr(P,{arrayPaths:D,removeNamespaces:A})}catch(P){if(F!==_.current)return;$("error"),T(P instanceof pe?P.message:"This doesn't look like a valid XML document. Please check the file and try again.");return}let Q=[];if(j&&j.length>0)try{Q=await Gr(z,j)}catch(P){if(F!==_.current)return;$("error"),T(P instanceof Error?P.message:"This document could not be mapped onto the form.");return}if(F!==_.current)return;S&&n(t,z);const ee=R==="parent"?t.split(".").slice(0,-1).join("."):"";for(const P of Q)(te=O.dispatch)==null||te.call(O,w.update(ee?`${ee}.${P.to}`:P.to,()=>P.value));$("ready")},[m,v,D,A,j,R,S,t,n,O]);if(f===!1||!x&&!J)return null;const K=p=>{p.preventDefault(),p.stopPropagation(),x&&H(p.type==="dragenter"||p.type==="dragover")},ae=p=>{var F;p.preventDefault(),p.stopPropagation(),H(!1),x&&(F=p.dataTransfer.files)!=null&&F[0]&&Y(p.dataTransfer.files[0])},oe=p=>{var F;(F=p.target.files)!=null&&F[0]&&(Y(p.target.files[0]),p.target.value="")},ce=()=>{x&&(++_.current,T(null),$("empty"),n(t,void 0))};return r.jsxs(o.Box,{mb:"4",children:[r.jsxs(o.Flex,{align:"center",justify:"between",mb:"2",children:[r.jsxs(o.Flex,{align:"center",gap:"1",children:[r.jsxs(o.Text,{as:"label",size:"2",weight:"bold",children:[s,c&&r.jsx(o.Text,{color:"red",children:" *"})]}),!E&&J&&x&&r.jsxs(r.Fragment,{children:[r.jsx(o.Tooltip,{content:"Replace document",children:r.jsx(o.IconButton,{variant:"ghost",size:"1",onClick:()=>{var p;return(p=X.current)==null?void 0:p.click()},"aria-label":"Replace document",children:r.jsx(Z.UploadIcon,{})})}),r.jsx(o.Tooltip,{content:"Remove document",children:r.jsx(o.IconButton,{variant:"ghost",size:"1",color:"gray",onClick:ce,"aria-label":"Remove document",children:r.jsx(Z.Cross2Icon,{})})})]})]}),r.jsxs(o.Flex,{align:"center",gap:"2",children:[r.jsxs(o.Text,{size:"1",color:"gray",children:[ue(v)," max · ",de(m)]}),E&&x&&r.jsxs(o.Button,{size:"1",variant:"soft",onClick:()=>{var p;return(p=X.current)==null?void 0:p.click()},disabled:U==="parsing",children:[U==="parsing"?r.jsx(o.Spinner,{size:"1"}):r.jsx(Z.UploadIcon,{}),"Upload"]})]})]}),(E||J)&&N&&r.jsx(o.Text,{size:"2",color:"red",mb:"2",style:{display:"block"},children:N}),r.jsx("input",{ref:X,type:"file",style:{display:"none"},accept:m,onChange:oe}),!E&&x&&!J&&r.jsx("div",{role:"button",tabIndex:0,onClick:()=>{var p;return(p=X.current)==null?void 0:p.click()},onKeyDown:p=>{var F;(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),(F=X.current)==null||F.click())},onDragEnter:K,onDragLeave:K,onDragOver:K,onDrop:ae,style:{cursor:"pointer"},className:["border-2 border-dashed rounded-lg p-6 text-center","transition-all duration-200 ease-in-out",b?"border-blue-500 bg-blue-50":N?"border-red-300 bg-red-50":"border-gray-300 hover:border-blue-400 hover:bg-gray-50"].join(" "),children:r.jsx(o.Flex,{direction:"column",align:"center",gap:"2",children:U==="parsing"?r.jsxs(r.Fragment,{children:[r.jsx(o.Spinner,{size:"3"}),r.jsx(o.Text,{size:"2",color:"gray",children:"Parsing document…"})]}):N?r.jsxs(r.Fragment,{children:[r.jsx(Z.ExclamationTriangleIcon,{style:{width:32,height:32,color:"var(--red-9)"}}),r.jsx(o.Text,{size:"2",color:"red",weight:"medium",children:N}),r.jsx(o.Text,{size:"1",color:"gray",children:"Click to try again"})]}):r.jsxs(r.Fragment,{children:[r.jsx(Z.UploadIcon,{style:{width:32,height:32,color:"var(--gray-8)"}}),r.jsx(o.Text,{size:"2",weight:"medium",children:"Click to upload or drag and drop"}),r.jsxs(o.Text,{size:"1",color:"gray",children:[ue(v)," max · ",de(m)]})]})})}),!d&&r.jsx(o.Text,{color:"red",size:"1",mt:"2",style:{display:"block"},children:le(a,s)})]})},Ft=G.withJsonFormsControlProps(Zr),Ot=w.rankWith(10,w.schemaMatches(e=>{const n=e["x-xml"];return e.type==="object"&&typeof n=="object"&&n!==null}));function Qr(e,n,t){const s={};for(const[c,i]of Object.entries(t)){const{path:l,default:u}=typeof i=="string"?{path:i,default:void 0}:i,a=n?`${n}.${l}`:l,f=w.Resolve.data(e,a);if(f==null){if(u===void 0)return;s[c]=u}else s[c]=f}return s}async function en(e,n){try{return{status:"ok",value:await Ct(e,n)}}catch(t){return{status:"error",error:ke(t)}}}function tn(e,n){return e==null?"":typeof e=="number"?e.toFixed(rn(n)):e instanceof Date?e.toLocaleDateString():String(e)}function rn(e){return Number.isFinite(e)?Math.min(100,Math.max(0,Math.trunc(e))):0}const Xe="{value}",nn=2,on={},sn=({data:e,handleChange:n,path:t,label:s,schema:c,visible:i=!0})=>{var U;fe(i,t,n);const l=c==null?void 0:c["x-computed"],u=(l==null?void 0:l.inputs)??on,a=(l==null?void 0:l.formula)??"",f=(l==null?void 0:l.format)??Xe,d=(l==null?void 0:l.decimals)??nn,x=G.useJsonForms(),h=t.split(".").slice(0,-1).join("."),m=Qr((U=x.core)==null?void 0:U.data,h,u),v=m?JSON.stringify(m):null,D=x.readonly===!0,[A,j]=y.useState(()=>typeof e=="number"?"ok":"unavailable"),[R,S]=y.useState(()=>typeof e=="number"?e:null),[O,I]=y.useState(null);return y.useEffect(()=>{if(!i)return;let $=!1;const N=T=>{D||T!==e&&n(t,T)};if(m===void 0){j("unavailable"),I(null),S(null),N(void 0);return}return j(T=>T==="ok"?T:"loading"),en(m,a).then(T=>{if($)return;const b=T.status==="ok"&&typeof T.value=="number"&&Number.isFinite(T.value)?T.value:null;if(b===null){j("error"),I(T.status==="error"?T.error??"Unable to compute value.":"Computed value must be a number."),S(null),N(void 0);return}j("ok"),I(null),S(b),N(b)}),()=>{$=!0}},[v,a,i,D]),i===!1?null:r.jsx(o.Box,{mb:"4",children:r.jsxs(o.Flex,{direction:"column",gap:"1",children:[r.jsx(o.Text,{as:"label",size:"2",weight:"bold",children:s}),A==="unavailable"?r.jsx(o.Text,{size:"2",color:"gray",children:"Not yet available."}):A==="loading"?r.jsxs(o.Flex,{align:"center",gap:"2",children:[r.jsx(o.Spinner,{size:"1"}),r.jsx(o.Text,{size:"2",color:"gray",children:"Computing…"})]}):A==="error"?r.jsx(o.Text,{size:"2",color:"red",children:O}):r.jsx(o.Text,{size:"2",children:f.split(Xe).join(tn(R,d))}),c.description&&r.jsx(o.Text,{size:"1",color:"gray",children:c.description})]})})},It=G.withJsonFormsControlProps(sn),kt=w.rankWith(5,w.schemaMatches(e=>{const n=e["x-computed"];return e.type==="number"&&typeof n=="object"&&n!==null})),ln=({data:e,path:n,schema:t,uischema:s,enabled:c,visible:i,addItem:l,removeItems:u,rootSchema:a,arraySchema:f})=>{const d=f?t:t.items,x=f||t;if(i===!1||!d||typeof d!="object"||Array.isArray(d))return null;const h=d,m=Array.isArray(e)?e:[],v=x.title||"Array Items",D=s.options??{},A=c&&D.addable!==!1,j=c&&D.removable!==!1,R=()=>{const O=w.createDefaultValue(h,a);l&&l(n,O)()},S=O=>{if(u){const I=u(n,[O]);I&&I()}};return r.jsx(o.Box,{mb:"6",children:r.jsxs(o.Flex,{direction:"column",gap:"4",children:[r.jsx(o.Text,{as:"div",size:"4",weight:"bold",children:v}),m.length===0&&r.jsx(o.Box,{py:"4",px:"4",style:{backgroundColor:"var(--gray-3)",borderRadius:"var(--radius-3)"},children:r.jsx(o.Text,{size:"2",color:"gray",children:"No items have been added yet."})}),m.map((O,I)=>{var $;const U=`${n}.${I}`;return r.jsx(o.Card,{size:"3",variant:"surface",children:r.jsxs(o.Flex,{direction:"column",gap:"4",children:[r.jsxs(o.Flex,{justify:"between",align:"center",children:[r.jsxs(o.Text,{size:"3",weight:"bold",children:["Item ",I+1]}),j&&r.jsxs(o.Button,{type:"button",color:"red",variant:"soft",onClick:()=>S(I),title:"Remove item",children:[r.jsx(Z.TrashIcon,{}),"Remove"]})]}),r.jsx(o.Box,{children:r.jsx(G.JsonFormsDispatch,{schema:h,uischema:(($=s.options)==null?void 0:$.detail)||(h.type==="object"||h.properties?{type:"VerticalLayout",elements:Object.keys(h.properties||{}).map(N=>({type:"Control",scope:`#/properties/${N}`}))}:{type:"Control",scope:"#"}),path:U,enabled:c,renderers:void 0,cells:void 0})})]})},U)}),A&&r.jsx(o.Box,{mt:"2",children:r.jsxs(o.Button,{type:"button",variant:"surface",onClick:R,children:[r.jsx(Z.PlusIcon,{}),"Add Item"]})})]})})},Ie=G.withJsonFormsArrayControlProps(ln),Nt=w.rankWith(3,w.isObjectArrayControl),Dt=({uischema:e,visible:n})=>{const t=e;return n===!1?null:r.jsx(o.Box,{mb:"4",children:r.jsx(o.Heading,{size:"4",children:t.text})})},Lt=w.rankWith(1,w.uiTypeIs("Label")),an=w.rankWith(3,w.isPrimitiveArrayControl),cn=[{tester:Ze,renderer:Xt},{tester:et,renderer:Jt},{tester:rt,renderer:Kt},{tester:ot,renderer:Gt},{tester:at,renderer:lt},{tester:it,renderer:Yt},{tester:ut,renderer:tr},{tester:ft,renderer:dt},{tester:pt,renderer:ht},{tester:mt,renderer:xt},{tester:yt,renderer:gt},{tester:vt,renderer:bt},{tester:At,renderer:St},{tester:Ot,renderer:Ft},{tester:kt,renderer:It},{tester:Nt,renderer:Ie},{tester:an,renderer:Ie},{tester:Lt,renderer:Dt}];exports.ArrayControl=Ie;exports.ArrayControlTester=Nt;exports.BooleanControl=tt;exports.BooleanControlTester=rt;exports.CategorizationLayoutRenderer=gt;exports.CategorizationLayoutTester=yt;exports.ComputedControl=It;exports.ComputedControlTester=kt;exports.DateControl=ct;exports.DateControlTester=ut;exports.FileControl=bt;exports.FileControlTester=vt;exports.GroupLayoutRenderer=xt;exports.GroupLayoutTester=mt;exports.HorizontalLayoutRenderer=ht;exports.HorizontalLayoutTester=pt;exports.LabelRenderer=Dt;exports.LabelTester=Lt;exports.NumberControl=Qe;exports.NumberControlTester=et;exports.RadioControl=nt;exports.RadioControlTester=ot;exports.SearchSelectControl=lt;exports.SearchSelectControlTester=at;exports.SearchServiceProvider=Ht;exports.SelectControl=st;exports.SelectControlTester=it;exports.SpreadsheetControl=St;exports.SpreadsheetControlTester=At;exports.TextControl=qe;exports.TextControlTester=Ze;exports.UploadProvider=Vt;exports.VerticalLayoutRenderer=dt;exports.VerticalLayoutTester=ft;exports.XmlControl=Ft;exports.XmlControlTester=Ot;exports.radixRenderers=cn;exports.useSearchService=Ye;exports.useUpload=Ke;
|