@formatica/react 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/BaseField.d.ts +17 -0
- package/dist/components/BaseField.d.ts.map +1 -0
- package/dist/components/FormBuilder.d.ts +22 -0
- package/dist/components/FormBuilder.d.ts.map +1 -0
- package/dist/components/FormaticaProvider.d.ts +15 -0
- package/dist/components/FormaticaProvider.d.ts.map +1 -0
- package/dist/components/fields/CheckboxField.d.ts +10 -0
- package/dist/components/fields/CheckboxField.d.ts.map +1 -0
- package/dist/components/fields/NumberField.d.ts +17 -0
- package/dist/components/fields/NumberField.d.ts.map +1 -0
- package/dist/components/fields/RadioField.d.ts +17 -0
- package/dist/components/fields/RadioField.d.ts.map +1 -0
- package/dist/components/fields/SelectField.d.ts +19 -0
- package/dist/components/fields/SelectField.d.ts.map +1 -0
- package/dist/components/fields/SliderField.d.ts +13 -0
- package/dist/components/fields/SliderField.d.ts.map +1 -0
- package/dist/components/fields/SwitchField.d.ts +11 -0
- package/dist/components/fields/SwitchField.d.ts.map +1 -0
- package/dist/components/fields/TextField.d.ts +15 -0
- package/dist/components/fields/TextField.d.ts.map +1 -0
- package/dist/components/fields/TextareaField.d.ts +14 -0
- package/dist/components/fields/TextareaField.d.ts.map +1 -0
- package/dist/formatica-react.es.js +498 -486
- package/dist/formatica-react.es.js.map +1 -1
- package/dist/formatica-react.umd.cjs +1 -1
- package/dist/formatica-react.umd.cjs.map +1 -1
- package/dist/hooks/useForm.d.ts +26 -0
- package/dist/hooks/useForm.d.ts.map +1 -0
- package/dist/hooks/useFormContext.d.ts +4 -0
- package/dist/hooks/useFormContext.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +3 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(F,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@formatica/core"),require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","@formatica/core","react","react/jsx-runtime"],k):(F=typeof globalThis<"u"?globalThis:F||self,k(F.FormaticaReact={},F.FormaticaCore,F.React,F.jsxRuntime))})(this,function(F,k,g,r){"use strict";function ee(e){switch(e.type){case"tags":case"checkbox-group":return[];case"checkbox":case"switch":return!1;case"number":case"slider":case"file":return null;default:return""}}function re(e){const s={};for(const a of e)s[a.name]=a.defaultValue??ee(a);return s}function te(e){return e?typeof e=="string"?e.split("|").map(G):Array.isArray(e)?e.map(G):Object.entries(e).filter(([,s])=>s!==!1&&s!==void 0).map(([s,a])=>({name:s,params:typeof a=="object"&&a!==null?a:{[s]:a}})):[]}function G(e){const[s="",...a]=e.split(":"),t=a.join(":"),n={};if(t){const o=t.split(",");if(s==="between"&&o.length===2)n.min=Number(o[0]),n.max=Number(o[1]);else if(s==="pattern")n.pattern=t;else if(n[s]=o.length===1?o[0]:o,o.length===1){const i=Number(o[0]);Number.isNaN(i)||(n[s]=i,s==="minLength"&&(n.min=i),s==="maxLength"&&(n.max=i))}}return{name:s,params:n}}function W(e,s){const a=k.extractFields(e.fields),t=g.useRef(re(a)),n=g.useRef(a),[o,i]=g.useState(()=>({...t.current})),[d,l]=g.useState({}),[b,u]=g.useState({}),[m,f]=g.useState({}),[C,v]=g.useState(!1),[p,y]=g.useState(0),S=g.useRef(o);S.current=o;const x=g.useRef(d);x.current=d;const j=Object.values(d).every(h=>h.length===0),O=Object.values(m).some(Boolean),D=g.useCallback((h,$)=>{i(N=>({...N,[h]:$})),f(N=>({...N,[h]:!0}))},[]),H=g.useCallback(h=>S.current[h],[]),I=g.useCallback(async(h,$)=>{const N=n.current.find(E=>E.name===h);if(!N)return[];if(N.condition&&!k.evaluateCondition(N.condition,$))return[];const T=te(N.rules);N.required&&!T.some(E=>E.name==="required")&&T.unshift({name:"required",params:{}});const P=[],$e={values:$,getFieldValue:E=>$[E]};for(const E of T){const B=k.getRule(E.name);if(!B)continue;const R=await B($[h],E.params,$e);typeof R=="string"&&P.push(R)}return P},[]),A=g.useCallback(async h=>{const $=await I(h,S.current);return l(N=>({...N,[h]:$})),u(N=>({...N,[h]:!0})),$.length===0},[I]),V=g.useCallback(async()=>{const h=S.current,$={};let N=!0;for(const T of n.current){const P=await I(T.name,h);$[T.name]=P,P.length>0&&(N=!1)}return l($),N},[I]),z=g.useCallback(async h=>{v(!0),y(N=>N+1);const $={};for(const N of n.current)$[N.name]=!0;u($);try{if(!await V())return;await h({...S.current})}finally{v(!1)}},[V]),_=g.useCallback(()=>{i({...t.current}),l({}),u({}),f({})},[]),U=g.useCallback(()=>{const h={};for(const $ of n.current)h[$.name]=null;i(h),l({})},[]),K=g.useCallback((h,$)=>{const N=Array.isArray($)?$:[$];l(T=>({...T,[h]:N}))},[]),c=g.useCallback(h=>{l($=>{const N={...$};return delete N[h],N})},[]),w=g.useCallback(()=>{l({})},[]);return{values:o,errors:d,touched:b,dirty:m,isValid:j,isDirty:O,isSubmitting:C,submitCount:p,setFieldValue:D,validate:V,validateField:A,submit:z,reset:_,clear:U,setError:K,clearError:c,clearErrors:w,getFieldValue:H}}const q=g.createContext(null);function se(){const e=g.useContext(q);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e}function ae({label:e,required:s,errors:a,touched:t=!0,helpText:n,tooltip:o,disabled:i,readOnly:d,fieldName:l,children:b,className:u,style:m}){const[f,C]=g.useState(!1),v=t&&a!==void 0&&a.length>0,p=l?`fc-field-${l}`:void 0,y=l?`fc-error-${l}`:void 0;return r.jsxs("div",{className:`relative mb-4 ${i?"opacity-50 cursor-not-allowed":""} ${d?"fc-readonly":""} ${u??""}`,style:m,children:[e&&r.jsxs("div",{className:"mb-1.5 flex items-center gap-1",children:[r.jsxs("label",{htmlFor:p,className:"block text-sm font-medium text-gray-700",children:[e,s&&r.jsx("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"})]}),o&&r.jsxs("span",{className:"relative inline-flex",onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),onFocus:()=>C(!0),onBlur:()=>C(!1),children:[r.jsx("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-500 text-xs hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40","aria-label":`Info: ${o}`,tabIndex:0,children:"i"}),f&&r.jsxs("div",{role:"tooltip",className:"absolute bottom-full left-1/2 z-10 mb-2 -translate-x-1/2 rounded-md bg-gray-900 px-3 py-1.5 text-xs text-white shadow-lg whitespace-nowrap",children:[o,r.jsx("div",{className:"absolute left-1/2 top-full -translate-x-1/2 border-4 border-transparent border-t-gray-900"})]})]})]}),r.jsx("div",{id:p,children:b}),v&&r.jsx("div",{children:a.map((S,x)=>r.jsx("p",{id:x===0?y:void 0,className:"mt-1 text-xs text-red-500",role:"alert",children:S},`${S}-${x}`))}),n&&!v&&r.jsx("p",{className:"mt-1 text-xs text-gray-400",children:n})]})}const ne="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-text-input";function Z({value:e,onChange:s,onBlur:a,disabled:t,placeholder:n,inputType:o="text",readOnly:i,prefix:d,suffix:l,maxLength:b,className:u}){const v=`${ne} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${d?"rounded-l-none":""} ${l?"rounded-r-none":""} ${u??""}`.trim(),p=r.jsx("input",{type:o,className:v,style:{borderColor:void 0},value:e??"",onChange:y=>s(y.target.value),onFocus:y=>{y.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:y=>{y.target.style.borderColor="",a==null||a()},disabled:t,placeholder:n,readOnly:i,maxLength:b,"aria-disabled":t||void 0,"aria-readonly":i||void 0});return d||l?r.jsxs("div",{className:"flex items-stretch",children:[d&&r.jsx("span",{className:"inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:d}),p,l&&r.jsx("span",{className:"inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:l})]}):p}const oe="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-number-input";function le({value:e,onChange:s,onBlur:a,disabled:t,placeholder:n,min:o,max:i,step:d=1,precision:l,readOnly:b,prefix:u,suffix:m,className:f}){const y=`${oe} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${u?"rounded-l-none":""} ${m?"rounded-r-none":""} ${f??""}`.trim();function S(j){const O=j.target.value;if(O===""){s(null);return}let D=Number.parseFloat(O);Number.isNaN(D)||(l!==void 0&&(D=Number.parseFloat(D.toFixed(l))),s(D))}const x=r.jsx("input",{type:"number",className:y,value:e??"",onChange:S,onFocus:j=>{j.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:j=>{j.target.style.borderColor="",a==null||a()},disabled:t,placeholder:n,min:o,max:i,step:d,readOnly:b,"aria-disabled":t||void 0,"aria-readonly":b||void 0});return u||m?r.jsxs("div",{className:"flex items-stretch",children:[u&&r.jsx("span",{className:"inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:u}),x,m&&r.jsx("span",{className:"inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:m})]}):x}const ie="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 resize-y focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-textarea-input";function ce({value:e,onChange:s,onBlur:a,disabled:t,placeholder:n,rows:o=3,readOnly:i,autoResize:d,maxLength:l,className:b}){const u=g.useRef(null),m=g.useCallback(()=>{if(!d||!u.current)return;const p=u.current;p.style.height="auto",p.style.height=`${p.scrollHeight}px`},[d]);g.useEffect(()=>{m()},[e,m]);const v=`${ie} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${d?"resize-none overflow-hidden":""} ${b??""}`.trim();return r.jsx("textarea",{ref:u,className:v,value:e??"",onChange:p=>{s(p.target.value)},onFocus:p=>{p.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:p=>{p.target.style.borderColor="",a==null||a()},disabled:t,placeholder:n,rows:o,readOnly:i,maxLength:l,"aria-disabled":t||void 0,"aria-readonly":i||void 0})}function de({value:e,onChange:s,onBlur:a,disabled:t,placeholder:n="Select...",options:o,multiple:i=!1,searchable:d=!1,clearable:l=!1,className:b}){const[u,m]=g.useState(!1),[f,C]=g.useState(""),[v,p]=g.useState(-1),y=g.useRef(null),S=g.useRef(null),x=e==null?[]:Array.isArray(e)?e:[e],j=(()=>{if(x.length===0||i)return"";const c=o.find(w=>w.value===x[0]);return(c==null?void 0:c.label)??String(x[0])})(),O=f?o.filter(c=>c.label.toLowerCase().includes(f.toLowerCase())):o;function D(c){return x.includes(c)}function H(c){const w=o.find(h=>h.value===c);return(w==null?void 0:w.label)??String(c)}const I=g.useCallback(()=>{m(!0),p(-1),C(""),setTimeout(()=>{var c;return(c=S.current)==null?void 0:c.focus()},0)},[]),A=g.useCallback(()=>{m(!1),C(""),a==null||a()},[a]);function V(){t||(u?A():I())}function z(c){if(!c.disabled)if(i){const w=[...x],h=w.indexOf(c.value);h>=0?w.splice(h,1):w.push(c.value),s(w)}else s(c.value),A()}function _(c){if(t)return;const w=x.filter(h=>h!==c);s(w.length?w:i?[]:null)}function U(c){c.stopPropagation(),s(i?[]:null)}function K(c){if(!u){(c.key==="Enter"||c.key===" "||c.key==="ArrowDown")&&(c.preventDefault(),I());return}switch(c.key){case"ArrowDown":c.preventDefault(),p(w=>Math.min(w+1,O.length-1));break;case"ArrowUp":c.preventDefault(),p(w=>Math.max(w-1,0));break;case"Enter":c.preventDefault(),v>=0&&O[v]&&z(O[v]);break;case"Escape":c.preventDefault(),A();break}}return g.useEffect(()=>{function c(w){y.current&&!y.current.contains(w.target)&&A()}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[A]),r.jsxs("div",{ref:y,className:`relative w-full ${t?"opacity-50 cursor-not-allowed":""} ${b??""}`,children:[r.jsxs("div",{role:"combobox","aria-expanded":u,"aria-haspopup":"listbox",tabIndex:0,className:`flex min-h-[38px] w-full cursor-pointer items-center rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm transition-colors duration-200 ${u?"ring-2 ring-blue-500/20":""} ${t?"pointer-events-none bg-gray-100":""}`,style:u?{borderColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:V,onKeyDown:K,children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-1",children:[i&&x.map(c=>r.jsxs("span",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs",style:{backgroundColor:"color-mix(in srgb, var(--fc-color-primary, #3b82f6) 15%, white)",color:"var(--fc-color-primary, #3b82f6)"},children:[H(c),r.jsx("button",{type:"button",className:"ml-0.5",style:{color:"var(--fc-color-primary, #3b82f6)"},"aria-label":"Remove",onClick:w=>{w.stopPropagation(),_(c)},children:"×"})]},String(c))),!i&&j&&r.jsx("span",{className:"truncate",children:j}),x.length===0&&!i&&r.jsx("span",{className:"text-gray-400",children:n}),i&&x.length===0&&r.jsx("span",{className:"text-gray-400",children:n})]}),l&&x.length>0&&!t&&r.jsx("button",{type:"button",className:"ml-1 shrink-0 text-gray-400 hover:text-gray-600 transition-colors duration-200","aria-label":"Clear selection",onClick:U,children:"×"}),r.jsx("svg",{className:`ml-1 h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${u?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]}),u&&r.jsxs("div",{className:"absolute z-50 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg",children:[d&&r.jsx("div",{className:"border-b border-gray-200 p-2",children:r.jsx("input",{ref:S,type:"text",className:"w-full rounded border border-gray-300 px-2 py-1 text-sm focus:outline-none fc-select-search",placeholder:"Search...",value:f,onChange:c=>C(c.target.value),onKeyDown:K,onFocus:c=>{c.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:c=>{c.target.style.borderColor=""}})}),r.jsxs("ul",{role:"listbox",className:"max-h-60 overflow-auto py-1",children:[O.map((c,w)=>r.jsx("li",{role:"option","aria-selected":D(c.value),className:`cursor-pointer px-3 py-2 text-sm transition-colors duration-200 ${D(c.value)?"":"text-gray-900"} ${v===w?"bg-gray-100":""} ${c.disabled?"opacity-50 cursor-not-allowed":"hover:bg-gray-50"}`,style:D(c.value)?{backgroundColor:"color-mix(in srgb, var(--fc-color-primary, #3b82f6) 8%, white)",color:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>z(c),onMouseEnter:()=>p(w),children:c.label},String(c.value))),O.length===0&&r.jsx("li",{className:"px-3 py-2 text-sm text-gray-400",children:"No options found"})]})]})]})}function ue({value:e,onChange:s,onBlur:a,disabled:t,label:n,className:o}){function i(){t||s(!e)}function d(l){(l.key===" "||l.key==="Enter")&&(l.preventDefault(),i())}return r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"} ${o??""}`,children:[r.jsx("input",{type:"checkbox",checked:e??!1,onChange:()=>{},onBlur:a,disabled:t,className:"sr-only"}),r.jsx("div",{role:"checkbox","aria-checked":e,"aria-disabled":t||void 0,tabIndex:0,className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors duration-200 ${e?"text-white":"border-gray-300 bg-white"}`,style:e?{borderColor:"var(--fc-color-primary, #3b82f6)",backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:l=>{l.preventDefault(),i()},onKeyDown:d,children:e&&r.jsx("svg",{className:"h-3 w-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:r.jsx("path",{d:"M2 6l3 3 5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n&&r.jsx("span",{className:"text-sm text-gray-700",children:n})]})}function fe({name:e,value:s,onChange:a,onBlur:t,disabled:n,options:o,inline:i=!1,className:d}){function l(f){return s===f}function b(f){return n===!0||!!f.disabled}function u(f){b(f)||a(f.value)}function m(f,C){(f.key===" "||f.key==="Enter")&&(f.preventDefault(),u(C))}return r.jsx("div",{role:"radiogroup",className:`${i?"flex flex-wrap gap-4":"flex flex-col gap-2"} ${d??""}`,children:o.map(f=>r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${b(f)?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("input",{type:"radio",checked:l(f.value),disabled:b(f),className:"sr-only",name:e,onChange:()=>u(f),onBlur:t}),r.jsx("div",{role:"radio","aria-checked":l(f.value),"aria-disabled":b(f)||void 0,tabIndex:0,className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors duration-200 ${l(f.value)?"":"border-gray-300"}`,style:l(f.value)?{borderColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>u(f),onKeyDown:C=>m(C,f),children:l(f.value)&&r.jsx("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"}})}),r.jsx("span",{className:"text-sm text-gray-700",children:f.label})]},String(f.value)))})}function be({value:e,onChange:s,onBlur:a,disabled:t,activeLabel:n,inactiveLabel:o,className:i}){function d(){t||s(!e)}function l(b){(b.key===" "||b.key==="Enter")&&(b.preventDefault(),d())}return r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"} ${i??""}`,children:[o&&r.jsx("span",{className:"text-sm text-gray-600",children:o}),r.jsx("input",{type:"checkbox",checked:e??!1,onChange:d,onBlur:a,disabled:t,className:"sr-only"}),r.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-disabled":t||void 0,tabIndex:0,className:`relative inline-flex h-6 w-11 shrink-0 rounded-full border-2 border-transparent transition-colors duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e?"":"bg-gray-300"} ${t?"pointer-events-none":"focus:outline-none focus:ring-2 focus:ring-blue-500/20"}`,style:e?{backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:d,onKeyDown:l,children:r.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow-sm transition-transform duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e?"translate-x-5":"translate-x-0"}`,"aria-hidden":"true"})}),n&&r.jsx("span",{className:"text-sm text-gray-600",children:n})]})}function pe({value:e,onChange:s,onBlur:a,disabled:t,min:n=0,max:o=100,step:i=1,showTooltip:d=!0,className:l}){const[b,u]=g.useState(!1),m=e??n,f=o-n,C=f===0?0:(m-n)/f*100;return r.jsxs("div",{className:`relative w-full py-2 ${t?"opacity-50 cursor-not-allowed":""} ${l??""}`,children:[d&&b&&r.jsx("div",{className:"absolute -top-8 rounded bg-gray-800 px-2 py-1 text-xs text-white shadow-sm transition-opacity duration-200",style:{left:`calc(${C}% - 16px)`},children:m}),r.jsx("input",{type:"range",value:m,onChange:v=>s(Number.parseFloat(v.target.value)),onMouseDown:()=>u(!0),onMouseUp:()=>u(!1),onTouchStart:()=>u(!0),onTouchEnd:()=>u(!1),onFocus:()=>u(!0),onBlur:v=>{u(!1),a==null||a()},disabled:t,min:n,max:o,step:i,"aria-valuenow":m,"aria-valuemin":n,"aria-valuemax":o,"aria-disabled":t||void 0,className:"h-2 w-full cursor-pointer appearance-none rounded-full bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500/20 disabled:pointer-events-none",style:{accentColor:"var(--fc-color-primary, #3b82f6)"}}),r.jsxs("div",{className:"mt-1 flex justify-between text-xs text-gray-400",children:[r.jsx("span",{children:n}),r.jsx("span",{children:o})]})]})}function L(e){return e.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`)}function ge(e){if(!e)return{};const s={};if(e.colors)for(const[a,t]of Object.entries(e.colors))t&&(s[`--fc-color-${L(a)}`]=t);if(e.typography)for(const[a,t]of Object.entries(e.typography))t&&(s[`--fc-${L(a)}`]=t);if(e.spacing)for(const[a,t]of Object.entries(e.spacing))t&&(s[`--fc-${L(a)}`]=t);if(e.borders)for(const[a,t]of Object.entries(e.borders))t&&(s[`--fc-border-${L(a)}`]=t);if(e.shadows)for(const[a,t]of Object.entries(e.shadows))t&&(s[`--fc-shadow-${L(a)}`]=t);if(e.transitions)for(const[a,t]of Object.entries(e.transitions))t&&(s[`--fc-transition-${L(a)}`]=t);return e.cssVars&&Object.assign(s,e.cssVars),s}function J(e,s,a,t,n){var l,b;const o=e.translations;if(!o)return n;const i=o[a];if((l=i==null?void 0:i.messages)!=null&&l[s])return i.messages[s];const d=o[t];return((b=d==null?void 0:d.messages)==null?void 0:b[s])??n}function Q(e,s,a,t,n){const o=e.translations;if(!o)return n;const i=o[a];if(i!=null&&i[s])return i[s];const d=o[t];return(d==null?void 0:d[s])??n}function X(e){return Array.isArray(e)?e:[]}function ye({field:e,value:s,onChange:a,onBlur:t,disabled:n}){switch(e.type){case"text":return r.jsx(Z,{value:String(s??""),onChange:a,onBlur:t,disabled:n,placeholder:e.placeholder,inputType:e.inputType,readOnly:e.readOnly});case"number":return r.jsx(le,{value:s,onChange:a,onBlur:t,disabled:n,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,readOnly:e.readOnly});case"textarea":return r.jsx(ce,{value:String(s??""),onChange:a,onBlur:t,disabled:n,placeholder:e.placeholder,rows:e.rows,readOnly:e.readOnly});case"select":return r.jsx(de,{value:s,onChange:a,onBlur:t,disabled:n,placeholder:e.placeholder,options:X(e.options)});case"checkbox":return r.jsx(ue,{value:!!s,onChange:a,onBlur:t,disabled:n});case"radio":return r.jsx(fe,{name:e.name,value:s,onChange:a,onBlur:t,disabled:n,options:X(e.options)});case"switch":return r.jsx(be,{value:!!s,onChange:a,onBlur:t,disabled:n});case"slider":return r.jsx(pe,{value:s,onChange:a,onBlur:t,disabled:n,min:e.min,max:e.max,step:e.step});default:return r.jsx(Z,{value:String(s??""),onChange:a,onBlur:t,disabled:n,placeholder:e.placeholder})}}function Y(e){return e==="full"?{gridColumn:"1 / -1"}:e==="auto"?{gridColumn:"auto"}:typeof e=="number"?{gridColumn:`span ${e} / span ${e}`}:{gridColumn:"span 12 / span 12"}}function he(e,s,a){const t=s.errors[e.name]??[],n=e.disabled===!0||!1,o={field:e,value:s.values[e.name],onChange:l=>s.setFieldValue(e.name,l),onBlur:()=>s.validateField(e.name),errors:t,disabled:n},d=(a==null?void 0:a[e.type])??ye;return r.jsx(ae,{label:e.label,required:e.required,errors:t,touched:s.touched[e.name],helpText:e.helpText,tooltip:e.tooltip,disabled:e.disabled,readOnly:e.readOnly,fieldName:e.name,className:e.className,style:e.style,children:r.jsx(d,{...o})},e.name)}function me(e,s,a){const n={start:"items-start",center:"items-center",end:"items-end",stretch:"items-stretch"}[e.align??"stretch"]??"items-stretch",o=e.gap!==void 0?typeof e.gap=="number"?`${e.gap}px`:e.gap:"1rem";return r.jsx("div",{className:`grid grid-cols-12 ${n} ${e.className??""}`,style:{gap:o},role:"group",children:e.children.map((i,d)=>r.jsx("div",{style:Y(k.isFieldNode(i)?i.span:void 0),children:M(i,s,a)},k.isFieldNode(i)?i.name:`row-child-${d}`))})}function xe({node:e,form:s,components:a}){const[t,n]=g.useState(e.collapsed??!1),o=e.title?`fc-group-${e.title.toLowerCase().replace(/\s+/g,"-")}`:void 0;function i(){e.collapsible&&n(!t)}const d=e.collapsible?"button":"div";return r.jsxs("fieldset",{className:`rounded-lg border border-gray-200 bg-white ${e.className??""}`,"aria-labelledby":o,children:[(e.title||e.description)&&r.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:r.jsxs(d,{type:e.collapsible?"button":void 0,className:`flex w-full items-center justify-between text-left ${e.collapsible?"cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-500/40 rounded":""}`,"aria-expanded":e.collapsible?!t:void 0,"aria-controls":e.collapsible?`fc-group-body-${o}`:void 0,onClick:i,children:[r.jsxs("div",{children:[e.title&&r.jsx("legend",{id:o,className:"text-sm font-semibold text-gray-800",children:e.title}),e.description&&r.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:e.description})]}),e.collapsible&&r.jsx("svg",{className:`h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${t?"":"rotate-180"}`,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})}),!t&&r.jsx("div",{id:e.collapsible?`fc-group-body-${o}`:void 0,className:"p-4",children:e.children.map((l,b)=>r.jsx("div",{children:M(l,s,a)},k.isFieldNode(l)?l.name:`group-child-${b}`))})]})}function ve({node:e,form:s,components:a}){const[t,n]=g.useState(0),[o,i]=g.useState(new Set),d=e.steps,l=d.length,b=t===0,u=t===l-1;function m(){u||(i(p=>{const y=new Set(p);return y.add(t),y}),n(p=>p+1))}function f(){b||n(p=>p-1)}function C(p){e.linear&&p>t||n(p)}const v=d[t];return r.jsxs("div",{className:`space-y-6 ${e.className??""}`,children:[r.jsx("nav",{"aria-label":"Form steps",className:"flex items-center justify-center",children:r.jsx("ol",{className:"flex items-center gap-0",children:d.map((p,y)=>r.jsxs("li",{className:"flex items-center",children:[r.jsx("button",{type:"button",disabled:e.linear===!0&&y>t,"aria-current":y===t?"step":void 0,"aria-label":`Step ${y+1}: ${p.title}`,className:`relative flex h-8 w-8 shrink-0 items-center justify-center rounded-full border-2 text-xs font-semibold transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40 ${o.has(y)&&y!==t?"border-green-500 bg-green-500 text-white":y!==t?"border-gray-300 bg-white text-gray-500":"text-white"} ${e.linear===!0&&y>t?"cursor-not-allowed":"cursor-pointer hover:shadow-md"}`,style:y===t?{borderColor:"var(--fc-color-primary, #3b82f6)",backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>C(y),children:o.has(y)&&y!==t?r.jsx("svg",{className:"h-4 w-4 transition-transform duration-200",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})}):r.jsx("span",{children:y+1})}),y<d.length-1&&r.jsx("div",{className:`mx-1 h-0.5 w-8 transition-colors duration-300 sm:w-12 ${o.has(y)?"bg-green-500":"bg-gray-200"}`})]},p.title))})}),v&&r.jsxs("div",{className:"text-center",children:[r.jsx("h3",{className:"text-base font-semibold text-gray-800",children:v.title}),v.description&&r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:v.description})]}),v&&r.jsx("div",{children:v.children.map((p,y)=>r.jsx("div",{children:M(p,s,a)},k.isFieldNode(p)?p.name:`step-child-${y}`))}),r.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 pt-4",children:[r.jsx("button",{type:"button",disabled:b,className:"rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",onClick:f,children:"Previous"}),r.jsxs("span",{className:"text-xs text-gray-400",children:[t+1," / ",l]}),u?r.jsx("div",{className:"w-[72px]"}):r.jsx("button",{type:"button",className:"rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"},onClick:m,children:"Next"})]})]})}function we({node:e,form:s,components:a}){const[t,n]=g.useState(0),o=e.tabs,i=o[t],d=`fc-tabpanel-${t}`;function l(b){n(b)}return r.jsxs("div",{className:e.className??"",children:[r.jsx("div",{className:"relative flex border-b border-gray-200",role:"tablist","aria-orientation":"horizontal",children:o.map((b,u)=>r.jsxs("button",{id:`fc-tab-${u}`,type:"button",role:"tab","aria-selected":u===t,"aria-controls":d,tabIndex:u===t?0:-1,className:`relative px-4 py-2.5 text-sm font-medium transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-blue-500/40 ${u!==t?"text-gray-500 hover:text-gray-700":""}`,style:u===t?{color:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>l(u),children:[b.title,u===t&&r.jsx("span",{className:"absolute inset-x-0 -bottom-px h-0.5 transition-all duration-200",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"}})]},b.title))}),i&&r.jsx("div",{id:d,role:"tabpanel","aria-labelledby":`fc-tab-${t}`,tabIndex:0,className:"pt-4",children:i.children.map((b,u)=>r.jsx("div",{children:M(b,s,a)},k.isFieldNode(b)?b.name:`tab-child-${u}`))})]})}function Ne(e){return e.label?r.jsxs("div",{className:`relative my-4 ${e.className??""}`,children:[r.jsx("div",{className:"absolute inset-0 flex items-center","aria-hidden":"true",children:r.jsx("div",{className:"w-full border-t border-gray-200"})}),r.jsx("div",{className:"relative flex justify-center",children:r.jsx("span",{className:"bg-white px-3 text-sm text-gray-500",children:e.label})})]}):r.jsx("hr",{className:`my-4 border-gray-200 ${e.className??""}`})}function M(e,s,a){if(k.isFieldNode(e))return he(e,s,a);switch(e.type){case"row":return me(e,s,a);case"group":return r.jsx(xe,{node:e,form:s,components:a});case"steps":return r.jsx(ve,{node:e,form:s,components:a});case"tabs":return r.jsx(we,{node:e,form:s,components:a});case"divider":return Ne(e);case"html":return r.jsx("div",{className:e.className??"",dangerouslySetInnerHTML:{__html:e.content}});default:return null}}function Ce({schema:e,onSubmit:s,onError:a,locale:t="en",fallbackLocale:n="en",theme:o,components:i,className:d}){var y,S;const l=W(e),b=ge(o),u=J(e,"title",t,n,""),m=J(e,"description",t,n,""),f=Q(e,"submit",t,n,"Submit"),C=Q(e,"reset",t,n,"Reset"),v=async x=>{x.preventDefault(),s?await l.submit(async j=>{await s(j)}):await l.validate(),!l.isValid&&a&&a(l.errors)},p=x=>{x.preventDefault(),l.reset()};return r.jsx(q.Provider,{value:l,children:r.jsxs("form",{className:`fc-form-builder ${((y=o==null?void 0:o.components)==null?void 0:y.form)??""} ${d??""}`.trim(),style:b,onSubmit:v,onReset:p,noValidate:!0,children:[(u||m)&&r.jsxs("div",{className:"mb-6",children:[u&&r.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:u}),m&&r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:m})]}),e.fields.map((x,j)=>r.jsx("div",{style:k.isFieldNode(x)?Y(x.span):void 0,children:M(x,l,i)},k.isFieldNode(x)?x.name:`node-${j}`)),r.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[r.jsxs("button",{type:"submit",disabled:l.isSubmitting,className:`fc-submit-btn rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 ${((S=o==null?void 0:o.components)==null?void 0:S.button)??""}`,style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"},children:[l.isSubmitting&&r.jsx("span",{className:"mr-2 inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent","aria-hidden":"true"}),f]}),r.jsx("button",{type:"reset",disabled:l.isSubmitting,className:"rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",children:C})]})]})})}F.FormBuilder=Ce,F.FormContext=q,F.useForm=W,F.useFormContext=se,Object.keys(k).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(F,e)&&Object.defineProperty(F,e,{enumerable:!0,get:()=>k[e]})}),Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(F,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@formatica/core"),require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","@formatica/core","react","react/jsx-runtime"],k):(F=typeof globalThis<"u"?globalThis:F||self,k(F.FormaticaReact={},F.FormaticaCore,F.React,F.jsxRuntime))})(this,function(F,k,g,r){"use strict";function te(e){switch(e.type){case"tags":case"checkbox-group":return[];case"checkbox":case"switch":return!1;case"number":case"slider":case"file":return null;default:return""}}function se(e){const s={};for(const a of e)s[a.name]=a.defaultValue??te(a);return s}function ae(e){return e?typeof e=="string"?e.split("|").map(G):Array.isArray(e)?e.map(G):Object.entries(e).filter(([,s])=>s!==!1&&s!==void 0).map(([s,a])=>({name:s,params:typeof a=="object"&&a!==null?a:{[s]:a}})):[]}function G(e){const[s="",...a]=e.split(":"),t=a.join(":"),o={};if(t){const n=t.split(",");if(s==="between"&&n.length===2)o.min=Number(n[0]),o.max=Number(n[1]);else if(s==="pattern")o.pattern=t;else if(o[s]=n.length===1?n[0]:n,n.length===1){const l=Number(n[0]);Number.isNaN(l)||(o[s]=l,s==="minLength"&&(o.min=l),s==="maxLength"&&(o.max=l))}}return{name:s,params:o}}function W(e,s){const a=k.extractFields(e.fields),t=g.useRef(se(a)),o=g.useRef(a),[n,l]=g.useState(()=>({...t.current})),[d,c]=g.useState({}),[f,u]=g.useState({}),[h,b]=g.useState({}),[m,v]=g.useState(!1),[p,y]=g.useState(0),j=g.useRef(n);j.current=n;const $=g.useRef(d);$.current=d;const D=Object.values(d).every(x=>x.length===0),E=Object.values(h).some(Boolean),O=g.useCallback((x,C)=>{l(N=>({...N,[x]:C})),b(N=>({...N,[x]:!0}))},[]),M=g.useCallback(x=>j.current[x],[]),S=g.useCallback(async(x,C)=>{const N=o.current.find(I=>I.name===x);if(!N)return[];if(N.condition&&!k.evaluateCondition(N.condition,C))return[];const L=ae(N.rules);N.required&&!L.some(I=>I.name==="required")&&L.unshift({name:"required",params:{}});const z=[],Fe={values:C,getFieldValue:I=>C[I]};for(const I of L){const ee=k.getRule(I.name);if(!ee)continue;const re=await ee(C[x],I.params,Fe);typeof re=="string"&&z.push(re)}return z},[]),T=g.useCallback(async x=>{const C=await S(x,j.current);return c(N=>({...N,[x]:C})),u(N=>({...N,[x]:!0})),C.length===0},[S]),V=g.useCallback(async()=>{const x=j.current,C={};let N=!0;for(const L of o.current){const z=await S(L.name,x);C[L.name]=z,z.length>0&&(N=!1)}return c(C),N},[S]),K=g.useCallback(async x=>{v(!0),y(N=>N+1);const C={};for(const N of o.current)C[N.name]=!0;u(C);try{if(!await V())return;await x({...j.current})}finally{v(!1)}},[V]),_=g.useCallback(()=>{l({...t.current}),c({}),u({}),b({})},[]),U=g.useCallback(()=>{const x={};for(const C of o.current)x[C.name]=null;l(x),c({})},[]),q=g.useCallback((x,C)=>{const N=Array.isArray(C)?C:[C];c(L=>({...L,[x]:N}))},[]),i=g.useCallback(x=>{c(C=>{const N={...C};return delete N[x],N})},[]),w=g.useCallback(()=>{c({})},[]);return{values:n,errors:d,touched:f,dirty:h,isValid:D,isDirty:E,isSubmitting:m,submitCount:p,setFieldValue:O,validate:V,validateField:T,submit:K,reset:_,clear:U,setError:q,clearError:i,clearErrors:w,getFieldValue:M}}const H=g.createContext(null);function oe(){const e=g.useContext(H);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e}const Z=g.createContext({});function ne({config:e,children:s}){return r.jsx(Z.Provider,{value:e,children:s})}function J(){return g.useContext(Z)}function le({label:e,required:s,errors:a,touched:t=!0,helpText:o,tooltip:n,disabled:l,readOnly:d,fieldName:c,children:f,className:u,style:h}){const[b,m]=g.useState(!1),v=t&&a!==void 0&&a.length>0,p=c?`fc-field-${c}`:void 0,y=c?`fc-error-${c}`:void 0;return r.jsxs("div",{className:`relative mb-4 ${l?"opacity-50 cursor-not-allowed":""} ${d?"fc-readonly":""} ${u??""}`,style:h,children:[e&&r.jsxs("div",{className:"mb-1.5 flex items-center gap-1",children:[r.jsxs("label",{htmlFor:p,className:"block text-sm font-medium text-gray-700",children:[e,s&&r.jsx("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"})]}),n&&r.jsxs("span",{className:"relative inline-flex",onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),onFocus:()=>m(!0),onBlur:()=>m(!1),children:[r.jsx("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-500 text-xs hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40","aria-label":`Info: ${n}`,tabIndex:0,children:"i"}),b&&r.jsxs("div",{role:"tooltip",className:"absolute bottom-full left-1/2 z-10 mb-2 -translate-x-1/2 rounded-md bg-gray-900 px-3 py-1.5 text-xs text-white shadow-lg whitespace-nowrap",children:[n,r.jsx("div",{className:"absolute left-1/2 top-full -translate-x-1/2 border-4 border-transparent border-t-gray-900"})]})]})]}),r.jsx("div",{id:p,children:f}),v&&r.jsx("div",{children:a.map((j,$)=>r.jsx("p",{id:$===0?y:void 0,className:"mt-1 text-xs text-red-500",role:"alert",children:j},`${j}-${$}`))}),o&&!v&&r.jsx("p",{className:"mt-1 text-xs text-gray-400",children:o})]})}const ce="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-text-input";function Q({value:e,onChange:s,onBlur:a,disabled:t,placeholder:o,inputType:n="text",readOnly:l,prefix:d,suffix:c,maxLength:f,className:u}){const v=`${ce} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${d?"rounded-l-none":""} ${c?"rounded-r-none":""} ${u??""}`.trim(),p=r.jsx("input",{type:n,className:v,style:{borderColor:void 0},value:e??"",onChange:y=>s(y.target.value),onFocus:y=>{y.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:y=>{y.target.style.borderColor="",a==null||a()},disabled:t,placeholder:o,readOnly:l,maxLength:f,"aria-disabled":t||void 0,"aria-readonly":l||void 0});return d||c?r.jsxs("div",{className:"flex items-stretch",children:[d&&r.jsx("span",{className:"inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:d}),p,c&&r.jsx("span",{className:"inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:c})]}):p}const ie="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-number-input";function de({value:e,onChange:s,onBlur:a,disabled:t,placeholder:o,min:n,max:l,step:d=1,precision:c,readOnly:f,prefix:u,suffix:h,className:b}){const y=`${ie} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${u?"rounded-l-none":""} ${h?"rounded-r-none":""} ${b??""}`.trim();function j(D){const E=D.target.value;if(E===""){s(null);return}let O=Number.parseFloat(E);Number.isNaN(O)||(c!==void 0&&(O=Number.parseFloat(O.toFixed(c))),s(O))}const $=r.jsx("input",{type:"number",className:y,value:e??"",onChange:j,onFocus:D=>{D.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:D=>{D.target.style.borderColor="",a==null||a()},disabled:t,placeholder:o,min:n,max:l,step:d,readOnly:f,"aria-disabled":t||void 0,"aria-readonly":f||void 0});return u||h?r.jsxs("div",{className:"flex items-stretch",children:[u&&r.jsx("span",{className:"inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:u}),$,h&&r.jsx("span",{className:"inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500",children:h})]}):$}const ue="w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 resize-y focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-textarea-input";function fe({value:e,onChange:s,onBlur:a,disabled:t,placeholder:o,rows:n=3,readOnly:l,autoResize:d,maxLength:c,className:f}){const u=g.useRef(null),h=g.useCallback(()=>{if(!d||!u.current)return;const p=u.current;p.style.height="auto",p.style.height=`${p.scrollHeight}px`},[d]);g.useEffect(()=>{h()},[e,h]);const v=`${ue} ${t?"opacity-50 cursor-not-allowed bg-gray-100":""} ${d?"resize-none overflow-hidden":""} ${f??""}`.trim();return r.jsx("textarea",{ref:u,className:v,value:e??"",onChange:p=>{s(p.target.value)},onFocus:p=>{p.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:p=>{p.target.style.borderColor="",a==null||a()},disabled:t,placeholder:o,rows:n,readOnly:l,maxLength:c,"aria-disabled":t||void 0,"aria-readonly":l||void 0})}function be({value:e,onChange:s,onBlur:a,disabled:t,placeholder:o="Select...",options:n,multiple:l=!1,searchable:d=!1,clearable:c=!1,className:f}){const[u,h]=g.useState(!1),[b,m]=g.useState(""),[v,p]=g.useState(-1),y=g.useRef(null),j=g.useRef(null),$=e==null?[]:Array.isArray(e)?e:[e],D=(()=>{if($.length===0||l)return"";const i=n.find(w=>w.value===$[0]);return(i==null?void 0:i.label)??String($[0])})(),E=b?n.filter(i=>i.label.toLowerCase().includes(b.toLowerCase())):n;function O(i){return $.includes(i)}function M(i){const w=n.find(x=>x.value===i);return(w==null?void 0:w.label)??String(i)}const S=g.useCallback(()=>{h(!0),p(-1),m(""),setTimeout(()=>{var i;return(i=j.current)==null?void 0:i.focus()},0)},[]),T=g.useCallback(()=>{h(!1),m(""),a==null||a()},[a]);function V(){t||(u?T():S())}function K(i){if(!i.disabled)if(l){const w=[...$],x=w.indexOf(i.value);x>=0?w.splice(x,1):w.push(i.value),s(w)}else s(i.value),T()}function _(i){if(t)return;const w=$.filter(x=>x!==i);s(w.length?w:l?[]:null)}function U(i){i.stopPropagation(),s(l?[]:null)}function q(i){if(!u){(i.key==="Enter"||i.key===" "||i.key==="ArrowDown")&&(i.preventDefault(),S());return}switch(i.key){case"ArrowDown":i.preventDefault(),p(w=>Math.min(w+1,E.length-1));break;case"ArrowUp":i.preventDefault(),p(w=>Math.max(w-1,0));break;case"Enter":i.preventDefault(),v>=0&&E[v]&&K(E[v]);break;case"Escape":i.preventDefault(),T();break}}return g.useEffect(()=>{function i(w){y.current&&!y.current.contains(w.target)&&T()}return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[T]),r.jsxs("div",{ref:y,className:`relative w-full ${t?"opacity-50 cursor-not-allowed":""} ${f??""}`,children:[r.jsxs("div",{role:"combobox","aria-expanded":u,"aria-haspopup":"listbox",tabIndex:0,className:`flex min-h-[38px] w-full cursor-pointer items-center rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm transition-colors duration-200 ${u?"ring-2 ring-blue-500/20":""} ${t?"pointer-events-none bg-gray-100":""}`,style:u?{borderColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:V,onKeyDown:q,children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-center gap-1",children:[l&&$.map(i=>r.jsxs("span",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs",style:{backgroundColor:"color-mix(in srgb, var(--fc-color-primary, #3b82f6) 15%, white)",color:"var(--fc-color-primary, #3b82f6)"},children:[M(i),r.jsx("button",{type:"button",className:"ml-0.5",style:{color:"var(--fc-color-primary, #3b82f6)"},"aria-label":"Remove",onClick:w=>{w.stopPropagation(),_(i)},children:"×"})]},String(i))),!l&&D&&r.jsx("span",{className:"truncate",children:D}),$.length===0&&!l&&r.jsx("span",{className:"text-gray-400",children:o}),l&&$.length===0&&r.jsx("span",{className:"text-gray-400",children:o})]}),c&&$.length>0&&!t&&r.jsx("button",{type:"button",className:"ml-1 shrink-0 text-gray-400 hover:text-gray-600 transition-colors duration-200","aria-label":"Clear selection",onClick:U,children:"×"}),r.jsx("svg",{className:`ml-1 h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${u?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]}),u&&r.jsxs("div",{className:"absolute z-50 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg",children:[d&&r.jsx("div",{className:"border-b border-gray-200 p-2",children:r.jsx("input",{ref:j,type:"text",className:"w-full rounded border border-gray-300 px-2 py-1 text-sm focus:outline-none fc-select-search",placeholder:"Search...",value:b,onChange:i=>m(i.target.value),onKeyDown:q,onFocus:i=>{i.target.style.borderColor="var(--fc-color-primary, #3b82f6)"},onBlur:i=>{i.target.style.borderColor=""}})}),r.jsxs("ul",{role:"listbox",className:"max-h-60 overflow-auto py-1",children:[E.map((i,w)=>r.jsx("li",{role:"option","aria-selected":O(i.value),className:`cursor-pointer px-3 py-2 text-sm transition-colors duration-200 ${O(i.value)?"":"text-gray-900"} ${v===w?"bg-gray-100":""} ${i.disabled?"opacity-50 cursor-not-allowed":"hover:bg-gray-50"}`,style:O(i.value)?{backgroundColor:"color-mix(in srgb, var(--fc-color-primary, #3b82f6) 8%, white)",color:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>K(i),onMouseEnter:()=>p(w),children:i.label},String(i.value))),E.length===0&&r.jsx("li",{className:"px-3 py-2 text-sm text-gray-400",children:"No options found"})]})]})]})}function pe({value:e,onChange:s,onBlur:a,disabled:t,label:o,className:n}){function l(){t||s(!e)}function d(c){(c.key===" "||c.key==="Enter")&&(c.preventDefault(),l())}return r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"} ${n??""}`,children:[r.jsx("input",{type:"checkbox",checked:e??!1,onChange:()=>{},onBlur:a,disabled:t,className:"sr-only"}),r.jsx("div",{role:"checkbox","aria-checked":e,"aria-disabled":t||void 0,tabIndex:0,className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors duration-200 ${e?"text-white":"border-gray-300 bg-white"}`,style:e?{borderColor:"var(--fc-color-primary, #3b82f6)",backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:c=>{c.preventDefault(),l()},onKeyDown:d,children:e&&r.jsx("svg",{className:"h-3 w-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:r.jsx("path",{d:"M2 6l3 3 5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&r.jsx("span",{className:"text-sm text-gray-700",children:o})]})}function ge({name:e,value:s,onChange:a,onBlur:t,disabled:o,options:n,inline:l=!1,className:d}){function c(b){return s===b}function f(b){return o===!0||!!b.disabled}function u(b){f(b)||a(b.value)}function h(b,m){(b.key===" "||b.key==="Enter")&&(b.preventDefault(),u(m))}return r.jsx("div",{role:"radiogroup",className:`${l?"flex flex-wrap gap-4":"flex flex-col gap-2"} ${d??""}`,children:n.map(b=>r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${f(b)?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("input",{type:"radio",checked:c(b.value),disabled:f(b),className:"sr-only",name:e,onChange:()=>u(b),onBlur:t}),r.jsx("div",{role:"radio","aria-checked":c(b.value),"aria-disabled":f(b)||void 0,tabIndex:0,className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors duration-200 ${c(b.value)?"":"border-gray-300"}`,style:c(b.value)?{borderColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>u(b),onKeyDown:m=>h(m,b),children:c(b.value)&&r.jsx("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"}})}),r.jsx("span",{className:"text-sm text-gray-700",children:b.label})]},String(b.value)))})}function ye({value:e,onChange:s,onBlur:a,disabled:t,activeLabel:o,inactiveLabel:n,className:l}){function d(){t||s(!e)}function c(f){(f.key===" "||f.key==="Enter")&&(f.preventDefault(),d())}return r.jsxs("label",{className:`inline-flex items-center gap-2 select-none ${t?"opacity-50 cursor-not-allowed":"cursor-pointer"} ${l??""}`,children:[n&&r.jsx("span",{className:"text-sm text-gray-600",children:n}),r.jsx("input",{type:"checkbox",checked:e??!1,onChange:d,onBlur:a,disabled:t,className:"sr-only"}),r.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-disabled":t||void 0,tabIndex:0,className:`relative inline-flex h-6 w-11 shrink-0 rounded-full border-2 border-transparent transition-colors duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e?"":"bg-gray-300"} ${t?"pointer-events-none":"focus:outline-none focus:ring-2 focus:ring-blue-500/20"}`,style:e?{backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:d,onKeyDown:c,children:r.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow-sm transition-transform duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e?"translate-x-5":"translate-x-0"}`,"aria-hidden":"true"})}),o&&r.jsx("span",{className:"text-sm text-gray-600",children:o})]})}function he({value:e,onChange:s,onBlur:a,disabled:t,min:o=0,max:n=100,step:l=1,showTooltip:d=!0,className:c}){const[f,u]=g.useState(!1),h=e??o,b=n-o,m=b===0?0:(h-o)/b*100;return r.jsxs("div",{className:`relative w-full py-2 ${t?"opacity-50 cursor-not-allowed":""} ${c??""}`,children:[d&&f&&r.jsx("div",{className:"absolute -top-8 rounded bg-gray-800 px-2 py-1 text-xs text-white shadow-sm transition-opacity duration-200",style:{left:`calc(${m}% - 16px)`},children:h}),r.jsx("input",{type:"range",value:h,onChange:v=>s(Number.parseFloat(v.target.value)),onMouseDown:()=>u(!0),onMouseUp:()=>u(!1),onTouchStart:()=>u(!0),onTouchEnd:()=>u(!1),onFocus:()=>u(!0),onBlur:v=>{u(!1),a==null||a()},disabled:t,min:o,max:n,step:l,"aria-valuenow":h,"aria-valuemin":o,"aria-valuemax":n,"aria-disabled":t||void 0,className:"h-2 w-full cursor-pointer appearance-none rounded-full bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500/20 disabled:pointer-events-none",style:{accentColor:"var(--fc-color-primary, #3b82f6)"}}),r.jsxs("div",{className:"mt-1 flex justify-between text-xs text-gray-400",children:[r.jsx("span",{children:o}),r.jsx("span",{children:n})]})]})}function A(e){return e.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`)}function me(e){if(!e)return{};const s={};if(e.colors)for(const[a,t]of Object.entries(e.colors))t&&(s[`--fc-color-${A(a)}`]=t);if(e.typography)for(const[a,t]of Object.entries(e.typography))t&&(s[`--fc-${A(a)}`]=t);if(e.spacing)for(const[a,t]of Object.entries(e.spacing))t&&(s[`--fc-${A(a)}`]=t);if(e.borders)for(const[a,t]of Object.entries(e.borders))t&&(s[`--fc-border-${A(a)}`]=t);if(e.shadows)for(const[a,t]of Object.entries(e.shadows))t&&(s[`--fc-shadow-${A(a)}`]=t);if(e.transitions)for(const[a,t]of Object.entries(e.transitions))t&&(s[`--fc-transition-${A(a)}`]=t);return e.cssVars&&Object.assign(s,e.cssVars),s}function X(e,s,a,t,o){var c,f;const n=e.translations;if(!n)return o;const l=n[a];if((c=l==null?void 0:l.messages)!=null&&c[s])return l.messages[s];const d=n[t];return((f=d==null?void 0:d.messages)==null?void 0:f[s])??o}function Y(e,s,a,t,o){const n=e.translations;if(!n)return o;const l=n[a];if(l!=null&&l[s])return l[s];const d=n[t];return(d==null?void 0:d[s])??o}function B(e){return Array.isArray(e)?e:[]}function xe({field:e,value:s,onChange:a,onBlur:t,disabled:o}){switch(e.type){case"text":return r.jsx(Q,{value:String(s??""),onChange:a,onBlur:t,disabled:o,placeholder:e.placeholder,inputType:e.inputType,readOnly:e.readOnly});case"number":return r.jsx(de,{value:s,onChange:a,onBlur:t,disabled:o,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step,readOnly:e.readOnly});case"textarea":return r.jsx(fe,{value:String(s??""),onChange:a,onBlur:t,disabled:o,placeholder:e.placeholder,rows:e.rows,readOnly:e.readOnly});case"select":return r.jsx(be,{value:s,onChange:a,onBlur:t,disabled:o,placeholder:e.placeholder,options:B(e.options)});case"checkbox":return r.jsx(pe,{value:!!s,onChange:a,onBlur:t,disabled:o});case"radio":return r.jsx(ge,{name:e.name,value:s,onChange:a,onBlur:t,disabled:o,options:B(e.options)});case"switch":return r.jsx(ye,{value:!!s,onChange:a,onBlur:t,disabled:o});case"slider":return r.jsx(he,{value:s,onChange:a,onBlur:t,disabled:o,min:e.min,max:e.max,step:e.step});default:return r.jsx(Q,{value:String(s??""),onChange:a,onBlur:t,disabled:o,placeholder:e.placeholder})}}function R(e){return e==="full"?{gridColumn:"1 / -1"}:e==="auto"?{gridColumn:"auto"}:typeof e=="number"?{gridColumn:`span ${e} / span ${e}`}:{gridColumn:"span 12 / span 12"}}function ve(e,s,a){const t=s.errors[e.name]??[],o=e.disabled===!0||!1,n={field:e,value:s.values[e.name],onChange:c=>s.setFieldValue(e.name,c),onBlur:()=>s.validateField(e.name),errors:t,disabled:o},d=(a==null?void 0:a[e.type])??xe;return r.jsx(le,{label:e.label,required:e.required,errors:t,touched:s.touched[e.name],helpText:e.helpText,tooltip:e.tooltip,disabled:e.disabled,readOnly:e.readOnly,fieldName:e.name,className:e.className,style:e.style,children:r.jsx(d,{...n})},e.name)}function we(e,s,a){const o={start:"items-start",center:"items-center",end:"items-end",stretch:"items-stretch"}[e.align??"stretch"]??"items-stretch",n=e.gap!==void 0?typeof e.gap=="number"?`${e.gap}px`:e.gap:"1rem";return r.jsx("div",{className:`grid grid-cols-12 ${o} ${e.className??""}`,style:{gap:n},role:"group",children:e.children.map((l,d)=>r.jsx("div",{style:R(k.isFieldNode(l)?l.span:void 0),children:P(l,s,a)},k.isFieldNode(l)?l.name:`row-child-${d}`))})}function Ne({node:e,form:s,components:a}){const[t,o]=g.useState(e.collapsed??!1),n=e.title?`fc-group-${e.title.toLowerCase().replace(/\s+/g,"-")}`:void 0;function l(){e.collapsible&&o(!t)}const d=e.collapsible?"button":"div";return r.jsxs("fieldset",{className:`rounded-lg border border-gray-200 bg-white ${e.className??""}`,"aria-labelledby":n,children:[(e.title||e.description)&&r.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:r.jsxs(d,{type:e.collapsible?"button":void 0,className:`flex w-full items-center justify-between text-left ${e.collapsible?"cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-500/40 rounded":""}`,"aria-expanded":e.collapsible?!t:void 0,"aria-controls":e.collapsible?`fc-group-body-${n}`:void 0,onClick:l,children:[r.jsxs("div",{children:[e.title&&r.jsx("legend",{id:n,className:"text-sm font-semibold text-gray-800",children:e.title}),e.description&&r.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:e.description})]}),e.collapsible&&r.jsx("svg",{className:`h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${t?"":"rotate-180"}`,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})}),!t&&r.jsx("div",{id:e.collapsible?`fc-group-body-${n}`:void 0,className:"p-4",children:e.children.map((c,f)=>r.jsx("div",{children:P(c,s,a)},k.isFieldNode(c)?c.name:`group-child-${f}`))})]})}function Ce({node:e,form:s,components:a}){const[t,o]=g.useState(0),[n,l]=g.useState(new Set),d=e.steps,c=d.length,f=t===0,u=t===c-1;function h(){u||(l(p=>{const y=new Set(p);return y.add(t),y}),o(p=>p+1))}function b(){f||o(p=>p-1)}function m(p){e.linear&&p>t||o(p)}const v=d[t];return r.jsxs("div",{className:`space-y-6 ${e.className??""}`,children:[r.jsx("nav",{"aria-label":"Form steps",className:"flex items-center justify-center",children:r.jsx("ol",{className:"flex items-center gap-0",children:d.map((p,y)=>r.jsxs("li",{className:"flex items-center",children:[r.jsx("button",{type:"button",disabled:e.linear===!0&&y>t,"aria-current":y===t?"step":void 0,"aria-label":`Step ${y+1}: ${p.title}`,className:`relative flex h-8 w-8 shrink-0 items-center justify-center rounded-full border-2 text-xs font-semibold transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40 ${n.has(y)&&y!==t?"border-green-500 bg-green-500 text-white":y!==t?"border-gray-300 bg-white text-gray-500":"text-white"} ${e.linear===!0&&y>t?"cursor-not-allowed":"cursor-pointer hover:shadow-md"}`,style:y===t?{borderColor:"var(--fc-color-primary, #3b82f6)",backgroundColor:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>m(y),children:n.has(y)&&y!==t?r.jsx("svg",{className:"h-4 w-4 transition-transform duration-200",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",clipRule:"evenodd"})}):r.jsx("span",{children:y+1})}),y<d.length-1&&r.jsx("div",{className:`mx-1 h-0.5 w-8 transition-colors duration-300 sm:w-12 ${n.has(y)?"bg-green-500":"bg-gray-200"}`})]},p.title))})}),v&&r.jsxs("div",{className:"text-center",children:[r.jsx("h3",{className:"text-base font-semibold text-gray-800",children:v.title}),v.description&&r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:v.description})]}),v&&r.jsx("div",{children:v.children.map((p,y)=>r.jsx("div",{children:P(p,s,a)},k.isFieldNode(p)?p.name:`step-child-${y}`))}),r.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 pt-4",children:[r.jsx("button",{type:"button",disabled:f,className:"rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",onClick:b,children:"Previous"}),r.jsxs("span",{className:"text-xs text-gray-400",children:[t+1," / ",c]}),u?r.jsx("div",{className:"w-[72px]"}):r.jsx("button",{type:"button",className:"rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"},onClick:h,children:"Next"})]})]})}function $e({node:e,form:s,components:a}){const[t,o]=g.useState(0),n=e.tabs,l=n[t],d=`fc-tabpanel-${t}`;function c(f){o(f)}return r.jsxs("div",{className:e.className??"",children:[r.jsx("div",{className:"relative flex border-b border-gray-200",role:"tablist","aria-orientation":"horizontal",children:n.map((f,u)=>r.jsxs("button",{id:`fc-tab-${u}`,type:"button",role:"tab","aria-selected":u===t,"aria-controls":d,tabIndex:u===t?0:-1,className:`relative px-4 py-2.5 text-sm font-medium transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-blue-500/40 ${u!==t?"text-gray-500 hover:text-gray-700":""}`,style:u===t?{color:"var(--fc-color-primary, #3b82f6)"}:{},onClick:()=>c(u),children:[f.title,u===t&&r.jsx("span",{className:"absolute inset-x-0 -bottom-px h-0.5 transition-all duration-200",style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"}})]},f.title))}),l&&r.jsx("div",{id:d,role:"tabpanel","aria-labelledby":`fc-tab-${t}`,tabIndex:0,className:"pt-4",children:l.children.map((f,u)=>r.jsx("div",{children:P(f,s,a)},k.isFieldNode(f)?f.name:`tab-child-${u}`))})]})}function ke(e){return e.label?r.jsxs("div",{className:`relative my-4 ${e.className??""}`,children:[r.jsx("div",{className:"absolute inset-0 flex items-center","aria-hidden":"true",children:r.jsx("div",{className:"w-full border-t border-gray-200"})}),r.jsx("div",{className:"relative flex justify-center",children:r.jsx("span",{className:"bg-white px-3 text-sm text-gray-500",children:e.label})})]}):r.jsx("hr",{className:`my-4 border-gray-200 ${e.className??""}`})}function P(e,s,a){if(k.isFieldNode(e))return ve(e,s,a);switch(e.type){case"row":return we(e,s,a);case"group":return r.jsx(Ne,{node:e,form:s,components:a});case"steps":return r.jsx(Ce,{node:e,form:s,components:a});case"tabs":return r.jsx($e,{node:e,form:s,components:a});case"divider":return ke(e);case"html":return r.jsx("div",{className:e.className??"",dangerouslySetInnerHTML:{__html:e.content}});default:return null}}function Se({schema:e,onSubmit:s,onError:a,locale:t,fallbackLocale:o,theme:n,components:l,className:d}){var O,M;const c=J(),f=t??c.locale??"en",u=o??c.fallbackLocale??"en",h=n??c.theme,b=l??c.components,m=W(e),v=me(h),p=X(e,"title",f,u,""),y=X(e,"description",f,u,""),j=Y(e,"submit",f,u,"Submit"),$=Y(e,"reset",f,u,"Reset"),D=async S=>{S.preventDefault(),s?await m.submit(async T=>{await s(T)}):await m.validate(),!m.isValid&&a&&a(m.errors)},E=S=>{S.preventDefault(),m.reset()};return r.jsx(H.Provider,{value:m,children:r.jsxs("form",{className:`fc-form-builder ${((O=h==null?void 0:h.components)==null?void 0:O.form)??""} ${d??""}`.trim(),style:v,onSubmit:D,onReset:E,noValidate:!0,children:[(p||y)&&r.jsxs("div",{className:"mb-6",children:[p&&r.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:p}),y&&r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:y})]}),e.fields.map((S,T)=>r.jsx("div",{style:k.isFieldNode(S)?R(S.span):void 0,children:P(S,m,b)},k.isFieldNode(S)?S.name:`node-${T}`)),r.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[r.jsxs("button",{type:"submit",disabled:m.isSubmitting,className:`fc-submit-btn rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 ${((M=h==null?void 0:h.components)==null?void 0:M.button)??""}`,style:{backgroundColor:"var(--fc-color-primary, #3b82f6)"},children:[m.isSubmitting&&r.jsx("span",{className:"mr-2 inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent","aria-hidden":"true"}),j]}),r.jsx("button",{type:"reset",disabled:m.isSubmitting,className:"rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",children:$})]})]})})}F.FormBuilder=Se,F.FormContext=H,F.FormaticaProvider=ne,F.useForm=W,F.useFormContext=oe,F.useFormaticaConfig=J,Object.keys(k).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(F,e)&&Object.defineProperty(F,e,{enumerable:!0,get:()=>k[e]})}),Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=formatica-react.umd.cjs.map
|