ynotsoft-dynamic-form 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var nt=(e,r)=>{for(var c in r)J(e,c,{get:r[c],enumerable:!0})},
|
|
1
|
+
var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var nt=(e,r)=>{for(var c in r)J(e,c,{get:r[c],enumerable:!0})},me=(e,r,c,h)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of rt(r))!st.call(e,d)&&d!==c&&J(e,d,{get:()=>r[d],enumerable:!(h=ot(r,d))||h.enumerable});return e};var I=(e,r,c)=>(c=e!=null?tt(at(e)):{},me(r||!e||!e.__esModule?J(c,"default",{value:e,enumerable:!0}):c,e)),lt=e=>me(J({},"__esModule",{value:!0}),e);var Rt={};nt(Rt,{DynamicForm:()=>ae,DynamicFormComponent:()=>ae,MyButton:()=>Q,MyButtonComponent:()=>Q,default:()=>Ft});module.exports=lt(Rt);var ue=require("react/jsx-runtime");function Q({children:e,onClick:r}){return(0,ue.jsx)("button",{onClick:r,children:e})}var M=require("react"),Ze=require("react-hot-toast"),de=I(require("dayjs"),1);var be=I(require("axios"),1),Z=I(require("react-hot-toast"),1);var pe={REACT_API_URL:"http://localhost:5000/"};var ge=be.default.create({baseURL:pe.REACT_API_URL,headers:{"Content-Type":"application/json"}});ge.interceptors.response.use(e=>e.data,e=>{var r;if(e.response&&e.response.status===403)return Z.default.error("You are not authorized to access this resource."),Promise.reject("You are not authorized to access this resource.");if(e.response)return Z.default.error("An error occurred"),Promise.reject(((r=e.response.data)==null?void 0:r.message)||"An error occurred");Z.default.error(e.message)});var he=ge;var fe=require("react/jsx-runtime");function it(e){return(0,fe.jsx)("input",{type:"hidden",name:e.name,value:e.value},e.name)}var xe=it;var ye=I(require("react-select"),1),ve=I(require("react-select/animated"),1),Ne=require("react/jsx-runtime");function ct({field:e,formValues:r,handleChange:c,touched:h,errors:d,handleBlur:a}){let l=e.disabled&&e.disabled(r),p=e.options||[],s=(0,ve.default)(),b=r[e.name]||[];return(0,Ne.jsx)(ye.default,{components:s,isMulti:!0,isDisabled:l,name:e.label,value:b,onChange:v=>c(e.name,v),options:p,placeholder:e.placeholder,closeMenuOnSelect:!1})}var we=ct;var g=I(require("@radix-ui/react-select"),1),At=require("react"),ke=require("@heroicons/react/20/solid"),w=require("react/jsx-runtime");function dt({field:e,formValues:r,handleChange:c,handleBlur:h}){var p;let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[];return(0,w.jsxs)(g.Root,{value:d,onValueChange:s=>c(e.name,s),disabled:a,children:[(0,w.jsxs)(g.Trigger,{id:e.name,onBlur:()=>h(e.name),className:`inline-flex items-center justify-between w-full px-3 py-2 border rounded-md text-sm transition-all
|
|
2
2
|
${a?"bg-gray-100 text-gray-500 cursor-not-allowed":"border-gray-300 hover:border-gray-400 focus:ring-2 focus:ring-blue-500"}
|
|
3
|
-
`,children:[(0,w.jsx)(g.Value,{placeholder:e.placeholder||`Select ${((p=e.label)==null?void 0:p.toLowerCase())||""}`}),(0,w.jsx)(g.Icon,{className:"ml-2 text-gray-500",children:(0,w.jsx)(
|
|
3
|
+
`,children:[(0,w.jsx)(g.Value,{placeholder:e.placeholder||`Select ${((p=e.label)==null?void 0:p.toLowerCase())||""}`}),(0,w.jsx)(g.Icon,{className:"ml-2 text-gray-500",children:(0,w.jsx)(ke.ChevronDownIcon,{className:"w-4 h-4"})})]}),(0,w.jsx)(g.Portal,{children:(0,w.jsxs)(g.Content,{className:"bg-white border border-gray-200 rounded-md shadow-lg z-50 min-w-[var(--radix-select-trigger-width)]",position:"popper",sideOffset:5,children:[(0,w.jsx)(g.ScrollUpButton,{className:"flex items-center justify-center h-6 text-gray-500 bg-gray-50",children:(0,w.jsx)(g.Arrow,{className:"fill-white stroke-gray-200"})}),(0,w.jsxs)(g.Viewport,{className:"p-1",children:[e.groupLabel&&(0,w.jsx)(g.Group,{children:(0,w.jsx)(g.Label,{className:"px-2 py-1 text-xs text-gray-500 uppercase tracking-wide",children:e.groupLabel})}),l.map(s=>(0,w.jsx)(g.Item,{value:s.value,className:`relative flex items-center px-3 py-2 text-sm rounded cursor-pointer select-none
|
|
4
4
|
data-[state=checked]:bg-blue-50
|
|
5
5
|
data-[state=checked]:text-blue-600
|
|
6
|
-
`,children:(0,w.jsx)(g.ItemText,{children:s.label})},s.value)),e.separator&&(0,w.jsx)(g.Separator,{className:"my-1 h-px bg-gray-200"})]}),(0,w.jsx)(g.Arrow,{className:"fill-white stroke-gray-200"})]})})]})}var
|
|
6
|
+
`,children:(0,w.jsx)(g.ItemText,{children:s.label})},s.value)),e.separator&&(0,w.jsx)(g.Separator,{className:"my-1 h-px bg-gray-200"})]}),(0,w.jsx)(g.Arrow,{className:"fill-white stroke-gray-200"})]})})]})}var Ce=dt;var zt=require("react"),Fe=require("react/jsx-runtime");function mt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){let l=e.readOnly&&e.disabled;return(0,Fe.jsx)("input",{...e.props,type:"email",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>h(e.name),disabled:l,name:e.name,placeholder:e.placeholder,className:`w-full px-3 py-2 border rounded-md ${!1?"border-red-500":"border-gray-300"} ${l?"bg-gray-100 text-gray-500 cursor-not-allowed":""}`})}var Se=mt;var _t=require("react"),Re=require("react/jsx-runtime");function ut({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){console.log("Rendering InputField for",e);let l=e.readOnly||e.disabled;return(0,Re.jsx)("input",{...e.props,id:e.name,type:e.type||"text",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>h(e.name),disabled:l,name:e.name,placeholder:e.placeholder,min:e.minLength,max:e.maxLength,className:`flex h-10 w-full rounded-md border px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 ${!1?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${l?"bg-gray-50 text-gray-500":"bg-background"}`})}var ne=ut;var Gt=require("react"),le=require("react/jsx-runtime");function pt({field:e,formValues:r}){let c=r[e.name]||e.content||"";return(0,le.jsx)("div",{className:`mb-4 ${e.fieldClass?e.fieldClass:"col-span-full"}`,id:e.name.toLowerCase()+"_id",children:(0,le.jsx)("div",{className:"w-full px-3 py-2 border rounded-md overflow-y-auto max-h-40 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:c}})},e.name)}var Pe=pt;var D=require("react/jsx-runtime");function bt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){let l=e.disabled&&e.disabled(r),p=!1;return(0,D.jsxs)("div",{className:"mt-1 space-x-2",children:[(0,D.jsx)("input",{...e.props,id:"id_"+e.name,type:"checkbox",checked:r[e.name]||!1,onChange:s=>c(e.name,s.target.checked),onBlur:()=>h(e.name),disabled:l,className:`rounded border-gray-300 ${l?"opacity-50 cursor-not-allowed":""}`}),(0,D.jsxs)("label",{className:"",htmlFor:"id_"+e.name,children:[e.label,e.required&&(0,D.jsx)("span",{className:"text-red-500",children:"*"})]}),p&&(0,D.jsx)("p",{className:"mt-1 text-sm text-red-500",children:p})]})}var Le=bt;var _=I(require("@radix-ui/react-popover"),1),$e=require("react"),Ie=require("react-day-picker"),qt=require("react-day-picker/dist/style.css"),S=require("react/jsx-runtime");function gt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,$e.useState)(!1),l=r[e.name]??{from:null,to:null},p=b=>c(e.name,b),s=()=>c(e.name,{from:null,to:null});return(0,S.jsx)("div",{children:(0,S.jsxs)(_.Root,{open:d,onOpenChange:a,children:[(0,S.jsx)(_.Trigger,{asChild:!0,children:(0,S.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
|
|
7
7
|
inline-flex items-center justify-between gap-2
|
|
8
8
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
9
9
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
10
10
|
hover:bg-gray-50 hover:text-gray-900
|
|
11
11
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
12
12
|
disabled:cursor-not-allowed disabled:opacity-50
|
|
13
|
-
`,children:[l.from?l.to?(0,S.jsxs)("span",{children:[l.from.toLocaleDateString()," \u2013 ",l.to.toLocaleDateString()]}):(0,S.jsx)("span",{children:l.from.toLocaleDateString()}):(0,S.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date range"}),(0,S.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,S.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,S.jsxs)(_.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,S.jsx)(
|
|
13
|
+
`,children:[l.from?l.to?(0,S.jsxs)("span",{children:[l.from.toLocaleDateString()," \u2013 ",l.to.toLocaleDateString()]}):(0,S.jsx)("span",{children:l.from.toLocaleDateString()}):(0,S.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date range"}),(0,S.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,S.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,S.jsxs)(_.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,S.jsx)(Ie.DayPicker,{mode:"range",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,S.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,S.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var Ee=gt;var Jt=require("react"),ie=require("react-hot-toast");var Me={apiBaseUrl:process.env.API_BASE_URL||""};var x=require("react/jsx-runtime");function ht({field:e,formValues:r,touched:c,errors:h,fileUploads:d,setFileUploads:a,fileInputRefs:l,handleChange:p,onFieldsChange:s}){let b=c[e.name]&&h[e.name],v=e.type==="multifile",P=d[e.name]||{},C=r[e.name],B=v?C||[]:[C].filter(Boolean),L=e.disabled&&e.disabled(r),O=`px-4 py-2 bg-gray-100 border rounded hover:bg-gray-200 ${L?"cursor-not-allowed":""}`,V=`${Me.REACT_API_URL}uploads`,A=i=>{if(i===0)return"0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(i)/Math.log(t));return parseFloat((i/Math.pow(t,n)).toFixed(2))+" "+o[n]},U=async(i,t)=>{let o=new FormData;o.append("file",i);let n=await fetch(`${V}`,{method:"POST",body:o});if(!n.ok)throw ie.toast.error("Upload failed"),new Error("Upload failed");return await n.json()},f=async(i,t)=>{if(!t)return;if(i.maxSize&&t.size>i.maxSize)throw new Error(`File size must not exceed ${A(i.maxSize)}`);let o=await U(t,i.name),n={...r,[i.name]:o};p(i.name,o),s(n)},$=async(i,t)=>{let o=r[i.name]||[];if(o.length+t.length>i.maxFiles)throw new Error(`Maximum ${i.maxFiles} files allowed`);t.forEach(k=>{if(i.maxSize&&k.size>i.maxSize)throw new Error(`Each file must not exceed ${A(i.maxSize)}`)});let n=await Promise.all(t.map(k=>U(k,i.name))),m=[...o,...n];p(i.name,m),s({...r,[i.name]:m})},X=async(i,t)=>{let o=Array.from(t);try{e.type==="file"?await f(e,o[0]):e.type==="multifile"&&await $(e,o),l.current[i]&&(l.current[i].value="")}catch(n){ie.toast.error(`Upload failed: ${n.message}`)}},se=async(i,t)=>{let o;e.type==="file"?o="":o=(r[i]||[]).filter(m=>m!==t),p(i,o),s({...r,[i]:o}),l.current[i]&&(l.current[i].value="")};return(0,x.jsxs)("div",{className:`mb-4 ${e.fieldClass||"col-span-full"}`,children:[(0,x.jsxs)("label",{className:"block font-medium mb-1",children:[e.label,e.required&&(0,x.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,x.jsxs)("div",{className:"space-y-2",children:[(0,x.jsxs)("div",{className:"items-center space-x-2",children:[(0,x.jsxs)("button",{type:"button",disabled:L,onClick:()=>l.current[e.name].click(),className:O,children:["Choose ",v?"Files":"File"]}),v&&B.length>0&&(0,x.jsxs)("span",{className:"text-sm text-gray-600",children:[B.length," of ",e.maxFiles," files uploaded"]})]}),(0,x.jsx)("input",{ref:i=>l.current[e.name]=i,type:"file",accept:e.accept,multiple:v,className:"hidden",onChange:i=>X(e.name,i.target.files)}),(0,x.jsx)("div",{className:"space-y-2",children:B.map((i,t)=>{let o=Object.values(P).find(n=>n.file===i);return(0,x.jsxs)("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded",children:[(0,x.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("span",{className:"text-sm",children:o.fileName}),(0,x.jsxs)("span",{className:"text-xs text-gray-500",children:["(",A(o.fileSize),")"]})]}),!o&&(0,x.jsx)("span",{className:"text-sm",children:i.original_name})]}),(0,x.jsx)("button",{type:"button",onClick:()=>se(e.name,i),className:"text-red-500 hover:text-red-700 ml-3",children:"Remove"})]},i)})}),Object.entries(P).map(([i,t])=>t.status==="uploading"?(0,x.jsxs)("div",{className:"relative pt-1",children:[(0,x.jsxs)("div",{className:"flex items-center justify-between",children:[(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:["Uploading ",i]}),(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:[t.progress,"%"]})]}),(0,x.jsx)("div",{className:"overflow-hidden h-2 mt-1 text-xs flex rounded bg-blue-200",children:(0,x.jsx)("div",{className:"shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500",style:{width:`${t.progress}%`}})})]},i):null)]}),b&&(0,x.jsx)("p",{className:"mt-1 text-sm text-red-500",children:b})]},e.name)}var ce=ht;var ee=require("react"),j=require("react/jsx-runtime");function xt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a,charCount:l,setCharCounts:p}){let s=(0,ee.useRef)(null),b=r[e.name]||"",v=typeof e.disabled=="function"?e.disabled(r):e.disabled||e.readOnly,P=d!=null&&d[e.name]&&(a!=null&&a[e.name])?a[e.name]:null,C=()=>{let L=s.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight+2}px`)};(0,ee.useEffect)(()=>{C()},[b]);let B=L=>{c(e.name,L.target.value),C(),p&&p(O=>({...O,[e.name]:L.target.value.length}))};return(0,j.jsxs)("div",{className:"space-y-2",children:[(0,j.jsx)("textarea",{...e.props,ref:s,id:e.name,name:e.name,placeholder:e.placeholder||"",value:b,onChange:B,onBlur:()=>h(e.name),disabled:v,maxLength:e.maxLength,rows:e.rows||3,className:`flex w-full rounded-md border px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none overflow-y-auto ${P?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${v?"bg-gray-50 text-gray-500":"bg-background"}`,style:{minHeight:"80px",maxHeight:"400px"}}),(0,j.jsx)("div",{className:"flex justify-between items-center",children:e.maxLength&&!e.readOnly&&(0,j.jsxs)("span",{className:"text-xs text-gray-500",children:[l||0,"/",e.maxLength," characters"]})})]})}var Be=xt;var Ae=require("@mui/x-date-pickers"),ro=require("react"),De=require("@mui/x-date-pickers/AdapterDayjs"),Te=require("@mui/x-date-pickers/DateTimeField"),te=require("react/jsx-runtime");function ft({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){return(0,te.jsx)("div",{children:(0,te.jsx)(Ae.LocalizationProvider,{dateAdapter:De.AdapterDayjs,adapterLocale:"aus",children:(0,te.jsx)(Te.DateTimeField,{value:e.value,onChange:l=>c(e.name,l)})})})}var ze=ft;var oe=require("@radix-ui/react-separator"),T=require("react/jsx-runtime");function yt({field:e}){return e!=null&&e.label?(0,T.jsxs)("div",{className:"relative flex items-center py-4",children:[(0,T.jsx)(oe.Separator,{className:"flex-1 h-px bg-gray-300"}),(0,T.jsx)("span",{className:"px-3 font-medium text-gray-600 bg-white",children:e.label}),(0,T.jsx)(oe.Separator,{className:"flex-1 h-px bg-gray-300"})]}):(0,T.jsx)(oe.Separator,{className:"my-4 h-px bg-gray-300"})}var Oe=yt;var lo=require("react"),H=I(require("@radix-ui/react-radio-group"),1),E=require("react/jsx-runtime");function vt({field:e,formValues:r,handleChange:c,handleBlur:h}){let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[],p=e.inline||!1;return(0,E.jsx)(H.Root,{value:d,onValueChange:s=>c(e.name,s),onBlur:()=>h(e.name),disabled:a,className:p?"flex flex-wrap gap-4":"space-y-3","aria-label":e.label||e.name,children:l.map(s=>{let b=typeof s=="object"?s.value:s,v=typeof s=="object"?s.label:s,P=typeof s=="object"?s.description:null,C=`${e.name}-${b}`;return(0,E.jsxs)("div",{className:"relative flex items-start",children:[(0,E.jsx)("div",{className:"flex h-6 items-center",children:(0,E.jsx)(H.Item,{value:b,id:C,disabled:a,className:`
|
|
14
14
|
relative size-4 rounded-full border transition-all
|
|
15
15
|
${a?"border-gray-300 bg-gray-100 cursor-not-allowed":"border-gray-300 bg-white hover:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"}
|
|
16
16
|
data-[state=checked]:border-blue-600 data-[state=checked]:bg-blue-600
|
|
17
|
-
`,children:(0,E.jsx)(H.Indicator,{className:"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-1.5 after:h-1.5 after:rounded-full after:bg-white"})})}),(0,E.jsxs)("div",{className:"ml-3 text-sm",children:[(0,E.jsx)("label",{htmlFor:C,className:`font-medium ${a?"text-gray-500":"text-gray-900 cursor-pointer"}`,children:v}),P&&!p&&(0,E.jsx)("p",{className:`text-sm ${a?"text-gray-400":"text-gray-500"}`,children:P})]})]},b)})})}var
|
|
17
|
+
`,children:(0,E.jsx)(H.Indicator,{className:"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-1.5 after:h-1.5 after:rounded-full after:bg-white"})})}),(0,E.jsxs)("div",{className:"ml-3 text-sm",children:[(0,E.jsx)("label",{htmlFor:C,className:`font-medium ${a?"text-gray-500":"text-gray-900 cursor-pointer"}`,children:v}),P&&!p&&(0,E.jsx)("p",{className:`text-sm ${a?"text-gray-400":"text-gray-500"}`,children:P})]})]},b)})})}var Ue=vt;var mo=require("react"),q=require("react/jsx-runtime");function wt({field:e}){let r=e.text||e.label||"",c=e.description||"",h=e.size||"lg",d=e.underline||!1,a=e.align||"left",l=e.className||"",p={sm:"text-base font-semibold",md:"text-lg font-semibold",lg:"text-xl font-bold",xl:"text-2xl font-bold","2xl":"text-3xl font-bold","3xl":"text-4xl font-bold","4xl":"text-5xl font-bold"},s={left:"text-left",center:"text-center",right:"text-right"},b=`
|
|
18
18
|
${p[h]||p.lg}
|
|
19
19
|
${s[a]||s.left}
|
|
20
20
|
${d?"border-b-2 border-gray-300 pb-2":""}
|
|
@@ -23,14 +23,14 @@ var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDes
|
|
|
23
23
|
`.trim(),v=`
|
|
24
24
|
mt-1 text-sm text-gray-600
|
|
25
25
|
${s[a]||s.left}
|
|
26
|
-
`.trim();return(0,q.jsxs)("div",{className:"my-4",children:[(0,q.jsx)("h2",{className:b,children:r}),c&&(0,q.jsx)("p",{className:v,children:c})]})}var
|
|
26
|
+
`.trim();return(0,q.jsxs)("div",{className:"my-4",children:[(0,q.jsx)("h2",{className:b,children:r}),c&&(0,q.jsx)("p",{className:v,children:c})]})}var _e=wt;var G=I(require("@radix-ui/react-popover"),1),je=require("react"),He=require("react-day-picker"),bo=require("react-day-picker/dist/style.css"),F=require("react/jsx-runtime");function Nt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,je.useState)(!1),l=r[e.name]??null,p=b=>c(e.name,b),s=()=>c(e.name,null);return(0,F.jsx)("div",{children:(0,F.jsxs)(G.Root,{open:d,onOpenChange:a,children:[(0,F.jsx)(G.Trigger,{asChild:!0,children:(0,F.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
|
|
27
27
|
inline-flex items-center justify-between gap-2
|
|
28
28
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
29
29
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
30
30
|
hover:bg-gray-50 hover:text-gray-900
|
|
31
31
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
|
|
32
32
|
disabled:cursor-not-allowed disabled:opacity-50
|
|
33
|
-
`,children:[l?(0,F.jsx)("span",{children:l.toLocaleDateString()}):(0,F.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date"}),(0,F.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,F.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,F.jsxs)(G.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,F.jsx)(
|
|
33
|
+
`,children:[l?(0,F.jsx)("span",{children:l.toLocaleDateString()}):(0,F.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date"}),(0,F.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,F.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,F.jsxs)(G.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,F.jsx)(He.DayPicker,{mode:"single",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,F.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,F.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,F.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var Ge=Nt;var z=I(require("react"),1),W=I(require("@radix-ui/react-popover"),1),u=require("react/jsx-runtime");function kt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,z.useState)(!1),[l,p]=(0,z.useState)("12"),[s,b]=(0,z.useState)("00"),[v,P]=(0,z.useState)("PM"),C=r[e.name]||"";z.default.useEffect(()=>{if(C){let f=C.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);f&&(p(f[1].padStart(2,"0")),b(f[2]),P(f[3].toUpperCase()))}},[C]);let B=()=>{let f=`${l}:${s} ${v}`;c(e.name,f),a(!1)},L=()=>{c(e.name,""),p("12"),b("00"),P("PM")},O=()=>{let f=parseInt(l);p((f%12+1).toString().padStart(2,"0"))},V=()=>{let f=parseInt(l);p((f===1?12:f-1).toString().padStart(2,"0"))},A=()=>{let f=parseInt(s);b(((f+5)%60).toString().padStart(2,"0"))},U=()=>{let f=parseInt(s);b((f===0?55:f-5).toString().padStart(2,"0"))};return(0,u.jsx)("div",{children:(0,u.jsxs)(W.Root,{open:d,onOpenChange:a,children:[(0,u.jsx)(W.Trigger,{asChild:!0,children:(0,u.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),className:`
|
|
34
34
|
inline-flex items-center justify-between gap-2
|
|
35
35
|
w-full h-9 rounded-md border border-gray-300 bg-white
|
|
36
36
|
px-3 py-2 text-sm font-normal shadow-sm
|
|
@@ -43,5 +43,5 @@ var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDes
|
|
|
43
43
|
`,children:"AM"}),(0,u.jsx)("button",{type:"button",onClick:()=>P("PM"),className:`
|
|
44
44
|
px-3 py-1 text-sm font-medium rounded
|
|
45
45
|
${v==="PM"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}
|
|
46
|
-
`,children:"PM"})]})]}),(0,u.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 pt-3",children:[(0,u.jsx)("button",{type:"button",onClick:L,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,u.jsx)("button",{type:"button",onClick:B,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})})]})})}var
|
|
46
|
+
`,children:"PM"})]})]}),(0,u.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 pt-3",children:[(0,u.jsx)("button",{type:"button",onClick:L,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,u.jsx)("button",{type:"button",onClick:B,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})})]})})}var We=kt;var fo=require("react");var re=require("@heroicons/react/20/solid"),Ve=require("@heroicons/react/20/solid"),Ye=require("@heroicons/react/24/outline");var N=require("react/jsx-runtime");function qe({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-red-50 border border-red-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(re.XCircleIcon,{"aria-hidden":"true",className:"size-5 text-red-500 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-red-900",children:e})]})})}function Ke({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-amber-50 border border-amber-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(Ye.ExclamationCircleIcon,{"aria-hidden":"true",className:"size-5 text-amber-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-amber-900",children:e})]})})}function Xe({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-green-50 border border-green-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(Ve.CheckCircleIcon,{"aria-hidden":"true",className:"size-5 text-green-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-green-900",children:e})]})})}function Je({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-blue-50 border border-blue-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(re.InformationCircleIcon,{"aria-hidden":"true",className:"size-5 text-blue-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-blue-900",children:e})]})})}var K=require("react/jsx-runtime");function Ct({field:e}){let{variant:r="info",message:c,content:h}=e,d=c||h||"";switch(r.toLowerCase()){case"error":case"danger":return(0,K.jsx)(qe,{message:d});case"success":return(0,K.jsx)(Xe,{message:d});case"warning":case"warn":return(0,K.jsx)(Ke,{message:d});case"info":case"information":default:return(0,K.jsx)(Je,{message:d})}}var Qe=Ct;var et=require("@radix-ui/react-label"),R=require("react/jsx-runtime"),St=({formDefinition:e,sendFormValues:r,children:c,defaultValues:h={},onFieldsChange:d=()=>{}})=>{let[a,l]=(0,M.useState)({...h}),[p,s]=(0,M.useState)({}),[b,v]=(0,M.useState)({}),[P,C]=(0,M.useState)({}),B=["hidden","html","linebreak","header","alert"],L=(0,M.useMemo)(()=>({file:ce,multifile:ce,dateRange:Ee,date:Ge,dayTimePicker:ze,time:We,hidden:xe,multiselect:we,select:Ce,email:Se,litertext:Pe,checkbox:Le,radiogroup:Ue,input:ne,textarea:Be,header:_e,alert:Qe,linebreak:Oe}),[]),O={},V=async(t,o=null)=>{try{let n=await he(`/${t.optionsUrl}`);console.log(n);let m=[];t.type==="select"?m=[{value:"",label:`Select ${t.label.toLowerCase()}`},...n.data]:m=[...n.data.map(k=>({value:k.value,label:k.label}))],e.fields.forEach(k=>{k.name===t.name&&(k.options=m)})}catch(n){console.error(`Failed to load options for ${t.name}:`,n)}finally{}};(0,M.useEffect)(()=>{if(e!=null&&e.fields&&e.fields.length>0){if(!e.fields.some(n=>n.value))return;e.fields.forEach(n=>{n.optionsUrl&&V(n)});let o={};e.fields.forEach(n=>{o[n.name]=h[n.name]??n.value??(n.type==="multiselect"?[]:"")}),l(o)}},[e]);let A=(t,o,n)=>{if(t.disabled&&t.disabled(n))return null;if(t.required){if(!o)return`${t.label} is required`;if(Array.isArray(o)&&o.length===0)return`Please select at least one ${t.label.toLowerCase()}`}if(t.validate){let m=t.validate(o,n);if(m)return m}if(t.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o))return"Please enter a valid email address";if(t.type==="number"){if(t.min!==void 0&&o<t.min)return`${t.label} must be at least ${t.min}`;if(t.max!==void 0&&o>t.max)return`${t.label} must be no more than ${t.max}`}return t.type==="date"&&!(0,de.default)(o).isValid()?`${t.label} must be a valid date`:t.maxLength&&o&&o.length>t.maxLength?`${t.label} must not exceed ${t.maxLength} characters`:null},U=(t,o)=>{let n=e.fields.find(y=>y.name===t);if(!n)return;let m={...a};console.log(o),n.type==="multiselect"?m[t]=Array.isArray(o)?o:Array.from(o.target.selectedOptions).map(y=>y.value):n.type==="dateRange"?(console.log(o),m[t]=[{startDate:o[0].from,endDate:o[0].to,key:"selection"}]):n.type==="dayTimePicker"?m[t]=o?(0,de.default)(o).format("YYYY-MM-DD HH:mm:ss"):"":m[t]=o,n.type==="select"&&e.fields.forEach(y=>{y.showIf&&!y.showIf(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),e.fields.forEach(y=>{y.disabled&&y.disabled(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),l(m);let k={};e.fields.forEach(y=>{if(!y.showIf||y.showIf(m)){let Y=A(y,m[y.name],m);Y&&(k[y.name]=Y)}}),s(k)},f=t=>{v({...b,[t]:!0})},$=t=>{t.preventDefault();let o={};e.fields.forEach(m=>{o[m.name]=!0}),v(o);let n={};e.fields.forEach(m=>{if((!m.showIf||m.showIf(a))&&(!m.disabled||!m.disabled(a))){let k=A(m,a[m.name],a);k&&(n[m.name]=k)}}),s(n),Object.keys(n).length===0?r(a):Ze.toast.error("Please correct the errors in the form")};(0,M.useEffect)(()=>{d(a)},[a,d]);let X={green:"border-green-500 bg-green-50",blue:"border-blue-500 bg-blue-50",red:"border-red-500 bg-red-50",yellow:"border-yellow-500 bg-yellow-50",purple:"border-purple-500 bg-purple-50",indigo:"border-indigo-500 bg-indigo-50",gray:"border-gray-500 bg-gray-50",pink:"border-pink-500 bg-pink-50",orange:"border-orange-500 bg-orange-50"};function se(t,o,n){if(B.includes(o.type))return(0,R.jsx)("div",{className:o.fieldClass||"col-span-8",children:t});let m=o.containerStyle,k=o.color||"blue",y=m==="card"?`rounded-lg border text-card-foreground shadow-sm p-4 ${o.containerClassName||X[k]||X.blue}`:"",Y=(0,R.jsxs)(R.Fragment,{children:[o.label&&(0,R.jsxs)(et.Label,{htmlFor:o.name,className:"block text-sm font-medium mb-1",children:[o.label,o.required&&(0,R.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,R.jsx)("div",{children:t}),n&&(0,R.jsx)("p",{className:"mt-1 text-sm text-red-500",children:n})]});return(0,R.jsx)("div",{className:`mb-4 ${o.fieldClass||"col-span-8"}`,children:m==="card"?(0,R.jsx)("div",{className:y,children:Y}):Y})}let i=t=>{if(t.showIf&&!t.showIf(a))return null;let o=L[t.type]||ne;a[t.name]===void 0&&(a[t.name]=t.value!==void 0?t.value:t.type==="multiselect"?[]:"");let n=b[t.name]&&p[t.name]?p[t.name]:null;return se((0,R.jsx)(o,{field:t,formValues:a,handleChange:U,handleBlur:()=>f(t.name),setCharCounts:C,charCount:P[t.name]||0}),t)};return(0,R.jsxs)("form",{onSubmit:$,className:"grid grid-cols-12 gap-x-4 mx-auto",children:[e?e.fields.map(i):(0,R.jsx)("div",{children:"Loading..."}),c]})},ae=St;var Ft=ae;0&&(module.exports={DynamicForm,DynamicFormComponent,MyButton,MyButtonComponent});
|
|
47
47
|
//# sourceMappingURL=index.cjs.map
|