react-luna-form 0.0.83 → 0.0.84
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/README.md +140 -0
- package/dist/client/cjs/index.js +1 -1
- package/dist/client/esm/index.js +1 -1
- package/dist/server/cjs/index.js +1 -1
- package/dist/server/esm/index.js +1 -1
- package/dist/types/luna-core/util/build.d.ts +1 -1
- package/dist/types/luna-core/util/schema.d.ts +4 -4
- package/dist/types/luna-core/util/style.d.ts +1 -5
- package/docs/events/change.md +45 -2
- package/docs/fields/data-source.md +113 -0
- package/docs/fields/input.md +1 -1
- package/docs/fields/list.md +5 -2
- package/docs/fields/select.md +49 -1
- package/docs/forms/submit.md +129 -0
- package/docs/index.md +9 -3
- package/docs/interpolation/format-filters.md +4 -0
- package/docs/interpolation/overview.md +179 -0
- package/docs/setup.md +65 -14
- package/docs/structure/definition.md +99 -0
- package/docs/structure/layout.md +189 -0
- package/docs/structure/sections.md +187 -0
- package/docs/validation/overview.md +1 -1
- package/package.json +4 -4
package/dist/server/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as Rr}from"react/jsx-runtime";function ke(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return Rr("div",{"data-slot":"field-control",className:"w-full",children:t})}import{jsx as Le}from"react/jsx-runtime";function C(e){return Le("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:`size-4 transition-transform duration-200 ${e.expanded?"rotate-90":""}`,children:Le("path",{fillRule:"evenodd",d:"M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})})}import{Activity as Tr}from"react";import{createContext as hr}from"react";var Ee=hr(!1);import{jsx as Oe}from"react/jsx-runtime";function I({children:e,visible:t}){return Oe(Tr,{mode:t?"visible":"hidden",children:Oe(Ee,{value:!0,children:e})})}var H="input",De="input/date",Pe="input/email",Me="input/number",_e="input/time";var ze="textarea",Ve="radio",Be="checkbox",ae="list",He="select",Ge="select/active",Ue="select/day",$e="select/month",Ye="select/timezone",Xe="select/year";var Ke="chips",We="chips/day",Ze="chips/month",k="column",qe="description",se="fields",Je="label",ce="value",G="options",de="email",Qe="number",je="password",et="tel",L="text",tt="aria-errormessage",nt="aria-invalid",rt="data-invalid",ot="data-readonly",it="aria",lt="data",at="max",st="maxLength",ct="min",dt="minLength",S="$ref";var ut="type",ft={Africa:"Africa",America:"Americas",Asia:"Asia / Pacific",Atlantic:"Atlantic",Australia:"Asia / Pacific",Europe:"Europe",Indian:"Asia / Pacific",Pacific:"Asia / Pacific"};import{format as Fr,formatDistanceToNow as gt,formatDuration as Cr,intervalToDuration as Sr,isValid as U,parseISO as Nr}from"date-fns";import{enUS as pt,es as ue}from"date-fns/locale";function u(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function p(e){return c(e)||typeof e=="number"||Ar(e)}function mt(e){return Array.isArray(e)&&e.every(p)}function c(e){return typeof e=="string"}function Ar(e){return typeof e=="boolean"}var xt={en:pt,"en-US":pt,es:ue,"es-ES":ue,"es-MX":ue},vr={short:"M/d/yy",medium:"MMM d, yyyy",long:"MMMM d, yyyy",full:"EEEE, MMMM d, yyyy"},wr={ms:1,s:1e3,min:6e4,h:36e5,d:864e5};function yt(e){if(e)return xt[e]??xt[e.split("-")[0]]}function $(e){if(typeof e=="number"&&!Number.isNaN(e))return e;if(c(e)&&e.trim()!==""){let t=Number(e);return Number.isNaN(t)?null:t}return null}function bt(e,t,n){let r=wr[t];if(r===void 0)return String(e);let o=e*r,i=Sr({start:0,end:o});return Cr(i,{locale:n})}function Rt(e){if(e instanceof Date)return U(e)?e:null;if(c(e)){let t=Nr(e);if(U(t))return t;let n=new Date(e);return U(n)?n:null}if(typeof e=="number"){let t=new Date(e);return U(t)?t:null}return null}var Ir={currency:(e,t,n)=>{let r=$(e);if(r===null)return String(e);let o=t[0]??"USD";return new Intl.NumberFormat(n.locale,{style:"currency",currency:o}).format(r)},percent:(e,t,n)=>{let r=$(e);return r===null?String(e):new Intl.NumberFormat(n.locale,{style:"percent"}).format(r)},number:(e,t,n)=>{let r=$(e);return r===null?String(e):new Intl.NumberFormat(n.locale).format(r)},date:(e,t,n)=>{let r=Rt(e);if(!r)return String(e);let o=t[0]??"short",i=yt(n.locale);if(o==="relative")return gt(r,{addSuffix:!0,locale:i});let l=vr[o]??o;return Fr(r,l,{locale:i})},duration:(e,t,n)=>{let r=yt(n.locale);if(typeof e=="number")return bt(e,t[0]??"ms",r);if(c(e)){let i=$(e);if(i!==null)return bt(i,t[0]??"ms",r)}let o=Rt(e);return o?gt(o,{addSuffix:!0,locale:r}):String(e)}};function ht(e,t,n){let r=t.split(":").map(a=>a.trim()).filter(a=>a.length>0);if(r.length===0)return;let[o,...i]=r,l=Ir[o];if(l)return l(e,i,n)}function Tt(e,t=ce){if(e!=null){if(mt(e)||p(e))return e;if(u(e)){let n=kr(e,t);if(p(n))return n}}}function kr(e,t){let n=x(e,t);if(p(n))return n}function x(e,t){if(!t||!u(e))return null;let n=t.split(".").filter(o=>o!=="");if(n.length===0)return null;let r=e;for(let o of n)if(u(r)&&o in r)r=r[o];else if(Array.isArray(r)){let i=Number(o);if(!Number.isInteger(i)||i<0||i>=r.length)return null;r=r[i]}else return null;return r}function At(e,t={description:qe,label:Je,value:ce}){return e.map(n=>{if(u(n)){let r=x(n,t.label),o=x(n,t.value);if(p(r)&&p(o)){let i=x(n,t.description);return{label:`${r}`,value:`${o}`,...p(i)&&{description:`${i}`}}}}return n})}function Ft(e=L){let t=e.lastIndexOf("/"),n=t===-1?e:e.slice(t+1);return n&&n!==H?n.trim().toLowerCase():L}var Lr=/\[([^\]]{1,500})\]\(([^)]{1,2000})\)/g,Er=/{([^}]{1,200})}/,Or=/{([^}]{1,200})}/g;function E(e,t={},n={}){if(c(e))return Pr(e,t,n);if(Array.isArray(e))return e.map(r=>E(r,t,n));if(u(e)){let r={};for(let o in e)r[o]=E(e[o],t,n);return r}return e}function O(e,t={},n={}){return fe(e)?E(e,t,n):e}function fe(e){return c(e)?Er.test(e):Array.isArray(e)?e.some(t=>fe(t)):u(e)?Object.values(e).some(t=>fe(t)):!1}function Dr(e,t){return t.includes(".")?x(e,t):e[t]}function Pr(e,t={},n={}){return e.replace(Or,(r,o)=>{let i=String(o).split("|").map(m=>m.trim()),[l,...a]=i;if(!l)return r;let s=Dr(t,l);if(a.length===0)return p(s)?String(s):r;if(s==null)return r;let d=s;for(let m of a){let B=ht(d,m,{locale:n.locale});if(B===void 0)return r;d=B}return String(d)})}function Ct(e,t){if(!c(e)||!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=Lr.exec(e))!==null;){let[l,a,s]=n,d=n.index;o=!0,d>r&&i.push(e.substring(r,d));let m=t?t(d,s,a):l;i.push(m),r=d+l.length}return o?(r<e.length&&i.push(e.substring(r)),i):e}var St=e=>f(Ge)(e),Nt=e=>f(Ue)(e),vt=e=>f($e)(e),wt=e=>f(Xe)(e),It=e=>f(Ye)(e),kt=e=>f(We)(e),Lt=e=>f(Ze)(e),Et=f(De),me=f(_e),y=f(Be),N=f(Ke),F=f(Ve),Ot=f(H),h=f(He),Dt=f(ze),Pt=f(L,de,je,et),Ii=f(Pe,de),Mt=f(Me,Qe);function _t(e){return F(e)||y(e)}function Y(e){return e.type===ae}function v(e){return e.type===k}function X(e){return e.type!==k&&e.type!==ae}function ge(e){return h(e)||F(e)||N(e)}function D(e){return e!=null&&e!==""}function f(...e){return t=>{let n=c(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function zt(e,t={}){if(h(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&u(n))return[n]}}function Vt(e){return F(e)||y(e)?!0:e.advanced?.horizontal??!1}function Bt(e){return y(e)?e.advanced?.reverse!==!1:!1}function Ht(e,t){let n=e.readonly??!1;return t||n}function pe(e){if(Mr(e)){let t=e.source;if(Array.isArray(t)||u(t)&&!(S in t))return t}}function Gt(e){return Array.isArray(pe(e))}function Mr(e){return F(e)||N(e)||h(e)&&!e.disabled}import{isValid as Yt,parse as Xt,format as Kt}from"date-fns";var _r=/^\d+$/,Wt=new Date(2e3,0,1),zr=()=>"supportedValuesOf"in Intl?Intl.supportedValuesOf("timeZone"):[],xe="default";function Zt(e){if(!e)return xe;try{return Intl.getCanonicalLocales(e)[0]??xe}catch{return xe}}function ye(e){let t=Zt(e);return Array.from({length:12},(n,r)=>({value:(r+1).toString(),label:new Date(0,r).toLocaleString(t,{month:"long"})}))}function be(e){let t=Zt(e);return Array.from({length:7},(n,r)=>({value:r.toString(),label:new Date(2e3,0,2+r).toLocaleString(t,{weekday:"long"})}))}function qt(e,t){return t>=e?Array.from({length:t-e+1},(n,r)=>{let o=e+r;return{value:o.toString(),label:o.toString()}}):[]}function Re(){return new Date().getFullYear()}function Vr(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Br(e){let t=e.indexOf("/"),n=t===-1?e:e.slice(0,t);return ft[n]??"Other"}function Hr(e,t){return(e.find(r=>r.type==="timeZoneName")?.value??t).replace(/\s+(?:Standard|Daylight(?: Saving)?|Summer|Winter)\s+Time$/,"")}function Ut(e,t){let n=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"longOffset"}).formatToParts(t),r=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"long"}).formatToParts(t),i=(n.find(a=>a.type==="timeZoneName")?.value??"GMT+00:00").replace("GMT","UTC"),l=Hr(r,e);return{offset:i,longName:l}}function $t(e){return e.slice(e.lastIndexOf("/")+1).replace(/_/g," ")}function Jt(){let e=new Date,t=Vr(),n=new Map,r=$t(t),{offset:o,longName:i}=Ut(t,e),l={value:t,label:`${r} - ${i} (${o})`};for(let s of zr()){if(s===t)continue;let d=$t(s),{offset:m,longName:B}=Ut(s,e),we={value:s,label:`${d} - ${B} (${m})`},le=Br(s);if(le==="Other")continue;let Ie=n.get(le);Ie?Ie.push(we):n.set(le,[we])}for(let s of n.values())s.sort((d,m)=>d.label.localeCompare(m.label));let a=Array.from(n.entries()).sort(([s],[d])=>s.localeCompare(d)).map(([s,d])=>({label:s,items:d}));return[{label:"Suggested",items:[l]},...a]}function he(e,t){if(typeof e=="number")return e;let n=t??Re(),r=e.trim().toLowerCase();if(r.startsWith("current")){let o=r.match(/^current([+-])(\d+)$/);if(o){let[,i,l]=o,a=parseInt(l,10);if(!isNaN(a))return i==="+"?n+a:n-a}return n}return _r.test(r)?parseInt(r,10):n}function Qt(e,t){if(!e)return"";try{let n=Xt(e,t,Wt);return Yt(n)?Kt(n,"yyyy-MM-dd"):""}catch{return""}}function jt(e,t){if(!e)return"";try{let n=Xt(e,t,Wt);return Yt(n)?Kt(n,"HH:mm:ss"):""}catch{return""}}function Te(e){return e.advanced?.format??"HH:mm"}function en(e){return e.advanced?.format??"MMMM d, yyyy"}var Gr={es:{"(Optional)":"(Opcional)","Add item":"A\xF1adir elemento","An unexpected error occurred submitting the form.":"Ocurri\xF3 un error inesperado al enviar el formulario.","Collapse {label} {index}":"Contraer {label} {index}","Expand {label} {index}":"Expandir {label} {index}","Please correct the errors and try again.":"Corrige los errores e int\xE9ntalo de nuevo.","Remove {label} item {index}":"Eliminar {label} {index}","There were validation errors submitting the form.":"Se encontraron errores de validaci\xF3n al enviar el formulario.","Unknown error":"Error desconocido",No:"No",Yes:"S\xED"}};function K(e,t){return b(e,t)}function nn(e,t){let n=t?.[e??""],r=e?Gr[Ur(e)]:void 0;return r?n?{...r,...n}:r:n}function Ur(e){return e.toLowerCase().split(/[-_]/)[0]}function b(e,t){return e?t?t[e]??e:e:""}function w(e,t){return e?b(e,t):void 0}function W(e,t){if(!t)return e;let n=!1,r=e.map(o=>{let i=$r(o,t);return i!==o&&(n=!0),i});return n?r:e}function $r(e,t){if(!u(e))return e;let n=tn(e.label,t),r=e.items;if(Array.isArray(r)){let i=W(r,t);return i===r&&n===e.label?e:{...e,...n!==void 0&&{label:n},items:i}}let o=tn(e.description,t);return n===e.label&&o===e.description?e:{...e,...n!==void 0&&{label:n},...o!==void 0&&{description:o}}}function tn(e,t){return c(e)?b(e,t):e}var Z=Re();function Yr(e,t){if(N(e))return Xr(e,t?.lang)}function Xr(e,t){if(kt(e))return be(t);if(Lt(e))return ye(t)}function Kr(e,t){if(h(e))return Wr(e,t)}function Wr(e,t){let{lang:n,translations:r}=t??{};if(Nt(e))return be(n);if(vt(e))return ye(n);if(wt(e)){let o=e.advanced?.length?.min??Z,i=e.advanced?.length?.max??Z+5;return qt(he(o,Z),he(i,Z))}if(It(e))return Jt();if(St(e))return W([{value:"true",label:"Yes"},{value:"false",label:"No"}],r)}function rn(e,t=!1,n){let r={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return Ot(e)?{...r,...Zr(e)}:h(e)?{...r,...on(Kr(e,n))}:Dt(e)?{...r,...Jr(e)}:N(e)?{...r,...qr(e,n)}:r}function Zr(e){let t=Ft(e.type),n={...e,type:t};return{...jr(e),...ln(e),...Qr(n),...Pt(n)?an(n):{},type:t}}function on(e){return e?{options:e}:{}}function qr(e,t){let n=on(Yr(e,t)),r=e.advanced?.multiple??!0;return{...n,multiple:r}}function Jr(e){return{...ln(e),...an(e)}}function ln(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Qr(e){return Mt(e)?eo(e):{}}function jr(e){if(me(e)){let t=Te(e);return{step:t==="HH:mm:ss"||t==="hh:mm:ss a"?"1":"60"}}return{}}function an(e){return sn(e,{min:dt,max:st})}function eo(e){return sn(e,{min:ct,max:at})}function sn(e,t){let n={},r=e.advanced?.length;return r&&(r.min!==void 0&&(n[t.min]=r.min),r.max!==void 0&&(n[t.max]=r.max)),n}function cn(e,t){let n=pe(e);return n||zt(e,t)}function to(e,t){let n=u(t)&&e.name in t?t[e.name]:t,r=Tt(n,e.advanced?.entity),o=D(r)?r:e.defaultValue;return me(e)&&D(o)?no(e,o):Et(e)&&D(o)?lo(e,o):o}function no(e,t){let n=Te(e);return c(t)?jt(t,n):t}function ro(e,t,n){return ge(e)&&Array.isArray(n)?{...t,[G]:n}:t}function oo(e,t,n){if(e.required&&!D(n)&&h(e)&&e.advanced?.preselected!==!1&&G in t){let r=t[G];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function io(e,t,n){if(ge(e)&&Array.isArray(t)){let r=At(t,e.advanced?.options);return Gt(e)?W(r,n):r}return t}function dn(e,t,n,r,o){let i=to(e,r),l=Array.isArray(n)?io(e,n,o):n,a=ro(e,t,l),s=oo(e,a,i);return{commonPropsWithOptions:a,defaultValue:s}}function un(e,t){return y(e)?{defaultChecked:!!t}:{defaultValue:t}}function lo(e,t){let n=en(e);return c(t)?Qt(t,n):t}var ao=/^#\/definition\//;function J(e=[],t){let n=q(e,t);return Array.isArray(n)?n.filter(co).sort((r,o)=>fn(r)-fn(o)):[]}function q(e,t,n=new Map,r=new WeakSet){if(!so(t)||!e||typeof e!="object")return e;if(n.has(e))return n.get(e);if(r.has(e))return e;if(r.add(e),Array.isArray(e))return e.map(i=>q(i,t,n,r));if(S in e&&c(e[S])){let i=e[S].replace(ao,""),l=x(t,i);return l!==null?q(l,t,n,r):e}let o={};for(let[i,l]of Object.entries(e))o[i]=q(l,t,n,r);return r.delete(e),n.set(e,o),o}function mn(e){return Object.entries(e??{})}function fn(e){return e.order??Number.MAX_VALUE}function so(e){return e!==void 0&&u(e)&&Object.keys(e).length>0}function co(e){return ut in e?!0:Array.isArray(e[se])?e[se].length>0:!0}function gn(e,t){let n={};for(let[r,o]of mn(t))n[`${e}-${r}`]=o;return n}function uo(e){return gn(it,e)}function fo(e){return gn(lt,e)}function pn(e,t){let n=uo(e.advanced?.aria);return t&&t.length>0&&(n[nt]="true",n[tt]=`${e.name}-error`),n}function xn(e){return fo(e.advanced?.data)}var yn={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},bn={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function Rn(e,t=2){return yn[e&&e in yn?e:t]}function hn(e){if(e&&e in bn)return bn[e]}function mo(e){return{min:e.advanced?.length?.min??1,max:e.advanced?.length?.max??1/0}}function go(e,t){let n=t?x(t,e.name):null;return po(e,Array.isArray(n)?n.length:0)}function Tn(e){return!Array.isArray(e.fields)||e.fields.length===0?!1:e.fields.length>1||e.fields[0].type===k}function An(e,t){let n=go(e,t);return Array.from({length:n},(r,o)=>o)}function Fn(e){return e.advanced?.title??e.label??e.name}function po(e,t){let{min:n,max:r}=mo(e);return Math.min(Math.max(t,n),r)}function Q(e,t){return{...e,...t}}import{jsx as xo}from"react/jsx-runtime";function R(e){return Ct(e,(t,n,r)=>xo("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}import{useCallback as yo,useState as bo}from"react";import{jsx as P,jsxs as Ae}from"react/jsx-runtime";function Cn(e){let{fields:t=[]}=e.section,[n,r]=bo(!1),o=yo(()=>r(i=>!i),[]);return Ae("fieldset",{"data-slot":"field-set","data-advanced":"true","data-expanded":n,"data-empty":t.length===0,className:"flex flex-col",id:e.section.id?.toString(),children:[P("legend",{children:Ae("button",{className:"flex cursor-pointer items-center gap-2 text-base font-medium text-zinc-600 dark:text-zinc-400",onClick:o,type:"button",children:[P(C,{expanded:n}),P("span",{children:R(e.title)})]})}),P(I,{visible:n,children:Ae("div",{className:"mt-3 ml-1.5 flex flex-col gap-4 border-l-2 border-zinc-300 pl-4 dark:border-zinc-600","data-slot":"field-set-content",children:[e.description&&P("p",{className:"text-sm leading-normal font-normal text-zinc-600 dark:text-zinc-400",children:R(e.description)}),e.group]})})]})}import{jsx as j,jsxs as Sn}from"react/jsx-runtime";function Nn(e){let t=Sn("div",{className:"flex flex-col",children:[e.title&&j("legend",{className:"mb-3 font-medium text-zinc-800 dark:text-zinc-200",children:R(e.title)}),e.description&&j("p",{className:"-mt-2 text-sm leading-normal font-normal text-zinc-600 dark:text-zinc-400",children:R(e.description)})]});return e.step?Sn("div",{className:"flex flex-row items-start gap-4",children:[j("div",{className:"bg-primary text-primary-foreground flex size-6 shrink-0 items-center justify-center rounded-full",children:j("span",{className:"text-sm font-bold",children:e.step})}),t]}):t}import{jsx as vn,jsxs as Ro}from"react/jsx-runtime";function ee(e){return Ro("fieldset",{className:"flex w-full min-w-0 flex-col data-[empty=false]:gap-6","data-empty":e.empty,"data-slot":"field-set",id:e.id,children:[vn(Nn,{description:e.description,step:e.step,title:e.title}),vn("div",{className:"w-full min-w-0",children:e.children})]})}import{jsx as ho}from"react/jsx-runtime";function T(e){return ho("div",{"data-slot":"field-group","data-compact":e.compact,className:"flex w-full flex-col gap-8 data-[compact=true]:gap-3",children:e.children})}import{jsx as Fe}from"react/jsx-runtime";function wn(e){let{fields:t=[]}=e.section,n=e.advanced?.step?e.step:void 0,{compact:r}=Q(e.style,{compact:e.section.advanced?.compact}),o=Fe(T,{compact:r,children:e.children});if(!e.section.title&&!e.section.description)return o;let i=w(e.section.title,e.translations),l=w(e.section.description,e.translations);return e.section.advanced?.collapsible?Fe(Cn,{description:l,group:o,section:e.section,title:i}):Fe(ee,{description:l,empty:t.length===0,id:e.section.id?.toString(),step:n,title:i,children:o})}import{jsx as In}from"react/jsx-runtime";function kn(){return In("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:In("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-zinc-200 dark:bg-zinc-800"})})}import{useAtomValue as vo}from"jotai";import{atom as M}from"jotai";import{atomFamily as To}from"jotai-family";import{deepEqual as Ln}from"fast-equals";function Ao(e,t){let{[t]:n,...r}=e;return r}function Fo(e){return To(t=>M(n=>n(e)[t]??void 0,(n,r,o)=>{let i=n(e);if(o!=null){let l=i[t];Ln(l,o)||r(e,{...i,[t]:o})}else t in i&&r(e,Ao(i,t))}))}function Co(e){return M(null,(t,n)=>{let r=t(e);r&&Object.keys(r).length>0&&n(e,{})})}function So(e){return M(null,(t,n,r)=>{let i={...t(e)},l=!1;for(let a of r)a in i&&(delete i[a],l=!0);l&&n(e,i)})}function No(e){return M(null,(t,n,r)=>{let o=t(e);Ln(o,r)||n(e,r)})}function te(e={}){let t=M(e);return{atom:t,clearAll:Co(t),clear:So(t),bulkReport:No(t),report:Fo(t)}}var En=te(),On=En.atom,Dn=En.report;function wo(e,t){return e.fields.every(n=>Pn(n,t))}function Pn(e,t){return t[e.name]?.hidden??e.hidden??!1}function Io(e,t){return v(e)?wo(e,t):Pn(e,t)}function Mn(e){let t=vo(On);return e.container&&(t[e.container.name]?.hidden??e.container.hidden??!1)||e.fields.length===0||e.fields.every(r=>Io(r,t))?null:e.children}import{jsx as _,jsxs as _n}from"react/jsx-runtime";function zn(e){let t=J(e.sections,e.definition);return _("div",{className:"h-full w-full",children:_("form",{noValidate:e.noValidate,action:e.action,children:_n(T,{children:[t.map((n,r)=>_n(Mn,{fields:n.fields??[],children:[_(wn,{advanced:e.advanced,section:n,step:r+1,style:e.config.style,translations:e.translations,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.advanced?.separator&&_(kn,{})]},`key-${n.id}-${r}`)),e.control&&_(ke,{isPending:e.isPending,children:e.control})]})})})}import{jsx as ko}from"react/jsx-runtime";function Vn(e){return ko("p",{className:"-mt-2 text-xs leading-normal font-normal text-zinc-600 dark:text-zinc-400 [[data-slot=column]_&]:md:line-clamp-2",title:e.title,children:e.children})}import{useState as Lo}from"react";import{jsx as Bn,jsxs as Hn}from"react/jsx-runtime";function ne(e){let t={context:e.context,env:e.config?.env,value:e.value},r={locale:e.config?.env?.locale},[o,i]=Lo(()=>u(e.text)&&"collapsed"in e.text?!e.text.collapsed:!0),l=()=>i(m=>!m),a=u(e.text)&&c(e.text.title)?R(b(O(e.text.title,t,r),e.translations)):void 0,s=b(O(c(e.text)?e.text:e.text?.message,t,r),e.translations),d=R(s);return d?Hn("div",{className:"flex flex-col gap-2",children:[a&&Hn("button",{className:"flex items-center gap-1 text-left text-xs font-medium text-zinc-700 hover:text-zinc-900 dark:text-zinc-300 dark:hover:text-zinc-100",onClick:l,type:"button",children:[a,Bn(C,{expanded:o})]}),o&&Bn(Vn,{title:s,children:d})]}):null}import{atom as Gn}from"jotai";var re=te(),aa=re.atom,sa=re.clearAll,ca=re.clear,Un=re.report,da=Gn({}),ua=Gn(null);import{useAtomValue as $n}from"jotai";import{jsx as Eo}from"react/jsx-runtime";function oe(e){let t=$n(Un(e.field.name)),r=$n(Dn(e.field.name))?.description??e.field.description;return Eo(ne,{config:e.config,context:e.context,text:r,translations:e.translations,value:t})}import{twMerge as Oo}from"tailwind-merge";import{jsx as Yn,jsxs as Do}from"react/jsx-runtime";function Xn(e){let t=e.style?.showOptionalLabel??!0,n=F(e.field)||y(e.field);return Do("label",{"data-slot":"field-label","data-normal":n,className:Oo("flex w-fit items-center text-sm leading-snug font-medium select-none","data-[normal=true]:font-normal [[data-slot=column]_&]:md:w-full","group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"),htmlFor:e.field.name,title:c(e.children)?e.children:void 0,children:[Yn("span",{className:"[[data-slot=column]_&]:md:truncate",children:e.children}),t&&!e.field.required&&Yn("span",{className:"ml-2 flex-shrink-0 text-sm text-zinc-600 dark:text-zinc-400",children:K("(Optional)",e.translations)})]})}import{jsx as Kn,jsxs as Po}from"react/jsx-runtime";function Wn(e){let t={context:e.context,env:e.config?.env},n=O(e.field.label,t);return Po("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[Kn(Xn,{field:e.field,style:e.config?.style,translations:e.translations,children:b(n,e.translations)}),e.horizontal===!0&&Kn(oe,{config:e.config,context:e.context,field:e.field,translations:e.translations})]})}import{Fragment as Mo,jsx as Zn,jsxs as _o}from"react/jsx-runtime";function qn(e){return _o(Mo,{children:[e.field.name&&e.field.label&&Zn(Wn,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations}),e.children,e.horizontal===!1&&Zn(oe,{config:e.config,context:e.context,field:e.field,translations:e.translations})]})}function Jn(e,t){return e?t(e):null}import{jsx as Qn}from"react/jsx-runtime";function jn(e){let t=cn(e.field,e.value),{commonPropsWithOptions:n,defaultValue:r}=dn(e.field,e.commonProps,t,e.value,e.translations),o=un(e.field,r);return Jn(e.config.inputs[e.field.type],i=>Qn(qn,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations,children:Qn(i,{...e.ariaAttributes,...n,...e.dataAttributes,...o})}))}import{jsx as er}from"react/jsx-runtime";function tr(e){return!e.errors||e.errors.length===0?null:er("ul",{className:"text-sm text-red-600 dark:text-red-500",id:e.name?`${e.name}-error`:void 0,children:e.errors?.map((t,n)=>er("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}import{twMerge as zo}from"tailwind-merge";import{jsx as Vo}from"react/jsx-runtime";function ie(e){let t=e.errors&&e.errors.length>0;return Vo("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[rt]:"true"},...e.disabled&&{[ot]:"true"},"data-orientation":e.orientation,className:zo("group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500","data-[clickable=true]:items-start",e.isCheckbox&&(e.isReversed?"flex-row-reverse!":"flex-row!"),"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",e.className),children:e.children})}import{twMerge as Bo}from"tailwind-merge";import{jsx as Ho}from"react/jsx-runtime";function nr(e){return Ho(ie,{...e,orientation:"vertical",className:Bo("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}import{twMerge as Go}from"tailwind-merge";import{jsx as Uo}from"react/jsx-runtime";function rr(e){return Uo(ie,{...e,orientation:"horizontal",className:Go("gap-2 md:flex-row md:gap-4","[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start","[&_[role=checkbox]]:mt-[1.5px]",e.isClickable&&"md:flex-col",!e.isClickable&&["md:justify-between","[&>*:not([data-slot=field-content])]:w-full","[&>*:not([data-slot=field-content])]:md:w-1/2","[&>*:not([data-slot=field-content])]:xl:w-2/5"]),children:e.children})}import{jsx as or}from"react/jsx-runtime";function ir(e){let t=_t(e.field),n=y(e.field),r=Bt(e.field);return e.horizontal?or(rr,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):or(nr,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function lr(e){if(!e.field.type)return null;let t=rn(e.field,e.disabled,{lang:e.lang,translations:e.translations}),n=xn(e.field),r=pn(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,horizontal:e.horizontal})}import{twMerge as $o}from"tailwind-merge";import{jsx as Ce,jsxs as Yo}from"react/jsx-runtime";function ar(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{horizontal:r}=Q(e.style,{horizontal:Vt(e.field)}),o=Ht(e.field,e.disabled);return Yo("div",{className:$o("flex flex-col gap-3",hn(t)),children:[Ce(ir,{disabled:o,errors:n,field:e.field,horizontal:r,children:Ce(lr,{disabled:o,errors:n,field:e.field,horizontal:r,lang:e.lang,translations:e.translations,children:e.children})}),Ce(tr,{errors:n,name:e.field.name})]})}import{twMerge as Se}from"tailwind-merge";import{useState as Xo}from"react";import{Fragment as Ko,jsx as g,jsxs as A}from"react/jsx-runtime";function sr(e){let t=e.isMultiField||e.collapsed!=null,[n,r]=Xo(t?!e.collapsed:!0);function o(){e.canRemove&&e.onRemove&&e.onRemove(e.index)}function i(){r(m=>!m)}let l=m=>E(K(m,e.translations),{index:e.index+1,label:e.label}),a=e.canRemove&&e.onRemove!=null&&g("button",{"aria-label":l("Remove {label} item {index}"),className:Se("flex size-6 items-center justify-center rounded text-xl leading-none text-zinc-400","transition-colors duration-150","hover:text-red-500","focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:outline-none","dark:text-zinc-500 dark:hover:text-red-400"),onClick:o,type:"button",children:g("span",{"aria-hidden":"true",className:"leading-none",children:"\xD7"})}),s=A("div",{className:"flex min-w-0 flex-col font-medium text-zinc-700 dark:text-zinc-400",children:[g("span",{className:"text-base",children:e.previewLabel??A(Ko,{children:[e.label," ",e.index+1]})}),!n&&e.previewTags&&g("div",{className:"flex items-center gap-2 overflow-hidden text-xs font-normal text-ellipsis whitespace-nowrap text-zinc-500 dark:text-zinc-500",children:e.previewTags})]}),d=A("div",{className:Se("flex items-center justify-between gap-2",e.isMultiField&&n&&"mb-3"),children:[t?A("div",{className:"flex min-w-0 grow items-center gap-2",children:[A("button",{"aria-expanded":n,"aria-label":l(n?"Collapse {label} {index}":"Expand {label} {index}"),className:Se("group flex grow items-center gap-2 rounded p-1 text-left text-zinc-400","focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:outline-none","dark:text-zinc-500"),onClick:i,type:"button",children:[g(C,{expanded:n}),s]}),!n&&e.previewBadge&&g("div",{className:"ml-auto shrink-0",children:e.previewBadge})]}):s,a]});return e.isMultiField?A("div",{"data-slot":"list-item-card",className:"box-border w-full min-w-0 rounded-lg border border-zinc-100 p-4 dark:border-zinc-900",children:[d,g(I,{visible:n,children:g(T,{children:e.children})})]}):t?A("div",{className:"box-border flex w-full min-w-0 flex-col gap-2",children:[d,g(I,{visible:n,children:g(T,{children:e.children})})]}):A("div",{className:"box-border flex w-full min-w-0 items-start gap-2",children:[g("div",{className:"flex min-w-0 grow flex-col",children:g(T,{children:e.children})}),a&&g("div",{className:"shrink-0",children:a})]})}import{jsx as Wo}from"react/jsx-runtime";function cr(e){let t=b(Fn(e.field),e.translations),n=Tn(e.field);return An(e.field,e.value).map(r=>Wo(sr,{collapsed:e.field.advanced?.collapsed,index:r,isMultiField:n,label:t,translations:e.translations,children:e.children(r)},r))}import{jsx as Zo}from"react/jsx-runtime";function dr(e){let t=Array.isArray(e.field.fields)&&e.field.fields.length===0,n=w(e.field.label,e.translations),r=w(e.field.description,e.translations);return Zo(ee,{description:r,empty:t,id:e.field.name,title:n,children:e.children})}import{jsx as ur}from"react/jsx-runtime";function fr({children:e,field:t,lang:n,translations:r,value:o}){return ur(dr,{field:t,translations:r,children:ur(cr,{field:t,lang:n,translations:r,value:o,children:e})})}import{twMerge as qo}from"tailwind-merge";import{jsx as mr,jsxs as Jo}from"react/jsx-runtime";function gr(e){let t=Rn(e.column?.advanced?.cols);return Jo("div",{className:"flex w-full flex-col gap-4",children:[mr("div",{"data-slot":"column",className:qo("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children}),e.column?.description&&mr(ne,{config:e.config,context:e.context,text:e.column.description,translations:e.translations})]})}import{Fragment as jo}from"react";import{jsx as Qo}from"react/jsx-runtime";function pr(e){let t=Array.isArray(e.field.fields)?e.field.fields.map(n=>X(n)||Y(n)?{...n,name:`${e.field.name}.${e.index}.${n.name}`}:v(n)?{...n,fields:n.fields.map(r=>({...r,name:`${e.field.name}.${e.index}.${r.name}`}))}:n):[];return Qo(z,{components:e.components,config:e.config,context:e.context,disabled:e.disabled,fields:t,lang:e.lang,onValueChange:e.onValueChange,style:e.style,translations:e.translations,value:e.value,children:e.children})}import{jsx as V,jsxs as ei}from"react/jsx-runtime";function z(e){let{field:t,list:n}=e.components;return J(e.fields).map((r,o)=>ei(jo,{children:[v(r)&&V(gr,{column:r,config:e.config,context:e.context,translations:e.translations,children:V(z,{...e,fields:r.fields})}),X(r)&&V(t,{disabled:e.disabled,field:r,lang:e.lang,style:e.style,translations:e.translations,children:e.children}),Y(r)&&V(n,{field:r,lang:e.lang,onValueChange:e.onValueChange,translations:e.translations,value:e.value,children:i=>V(pr,{components:e.components,config:e.config,context:e.context,disabled:e.disabled,field:r,index:i,lang:e.lang,onValueChange:e.onValueChange,style:e.style,translations:e.translations,value:e.value,children:e.children})})]},o))}import{jsx as ti}from"react/jsx-runtime";function xr(e){return n=>ti(z,{...n,components:e})}var yr=xr({field:ar,list:fr});import{jsx as Ne}from"react/jsx-runtime";function ve(e){let t=nn(e.lang,e.translations);return Ne(zn,{advanced:e.advanced,config:e.config,control:e.children,definition:e.definition,readOnly:e.readOnly,sections:e.sections,translations:t,children:({disabled:n,fields:r})=>Ne(yr,{config:e.config,context:e.context,disabled:n,fields:r,lang:e.lang,style:e.config.style,translations:t,value:e.value,children:o=>Ne(jn,{...o,config:e.config,context:e.context,translations:t,value:e.value})})})}import{Suspense as ni}from"react";import{jsx as br}from"react/jsx-runtime";function ri(e){return br(ni,{fallback:br(ve,{config:e.config,sections:e.sections,readOnly:!0}),children:e.children})}export{ri as Fallback,ve as Form};
|
|
1
|
+
import{jsx as Rr}from"react/jsx-runtime";function ke(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return Rr("div",{"data-slot":"field-control",className:"w-full",children:t})}import{jsx as Le}from"react/jsx-runtime";function C(e){return Le("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:`size-4 transition-transform duration-200 ${e.expanded?"rotate-90":""}`,children:Le("path",{fillRule:"evenodd",d:"M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})})}import{Activity as Tr}from"react";import{createContext as hr}from"react";var Ee=hr(!1);import{jsx as Oe}from"react/jsx-runtime";function I({children:e,visible:t}){return Oe(Tr,{mode:t?"visible":"hidden",children:Oe(Ee,{value:!0,children:e})})}var H="input",De="input/date",Pe="input/email",Me="input/number",_e="input/time";var ze="textarea",Ve="radio",Be="checkbox",ae="list",He="select",Ge="select/active",Ue="select/day",$e="select/month",Ye="select/timezone",Xe="select/year";var Ke="chips",We="chips/day",Ze="chips/month",k="column",qe="description",se="fields",Je="label",ce="value",G="options",de="email",Qe="number",je="password",et="tel",L="text",tt="aria-errormessage",nt="aria-invalid",rt="data-invalid",ot="data-readonly",it="aria",lt="data",at="max",st="maxLength",ct="min",dt="minLength",S="$ref";var ut="type",ft={Africa:"Africa",America:"Americas",Asia:"Asia / Pacific",Atlantic:"Atlantic",Australia:"Asia / Pacific",Europe:"Europe",Indian:"Asia / Pacific",Pacific:"Asia / Pacific"};import{format as Fr,formatDistanceToNow as gt,formatDuration as Cr,intervalToDuration as Sr,isValid as U,parseISO as Nr}from"date-fns";import{enUS as pt,es as ue}from"date-fns/locale";function u(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function p(e){return c(e)||typeof e=="number"||Ar(e)}function mt(e){return Array.isArray(e)&&e.every(p)}function c(e){return typeof e=="string"}function Ar(e){return typeof e=="boolean"}var yt={en:pt,"en-US":pt,es:ue,"es-ES":ue,"es-MX":ue},vr={short:"M/d/yy",medium:"MMM d, yyyy",long:"MMMM d, yyyy",full:"EEEE, MMMM d, yyyy"},wr={ms:1,s:1e3,min:6e4,h:36e5,d:864e5};function xt(e){if(e)return yt[e]??yt[e.split("-")[0]]}function $(e){if(typeof e=="number"&&!Number.isNaN(e))return e;if(c(e)&&e.trim()!==""){let t=Number(e);return Number.isNaN(t)?null:t}return null}function bt(e,t,n){let r=wr[t];if(r===void 0)return String(e);let o=e*r,i=Sr({start:0,end:o});return Cr(i,{locale:n})}function Rt(e){if(e instanceof Date)return U(e)?e:null;if(c(e)){let t=Nr(e);if(U(t))return t;let n=new Date(e);return U(n)?n:null}if(typeof e=="number"){let t=new Date(e);return U(t)?t:null}return null}var Ir={currency:(e,t,n)=>{let r=$(e);if(r===null)return String(e);let o=t[0]??"USD";return new Intl.NumberFormat(n.locale,{style:"currency",currency:o}).format(r)},percent:(e,t,n)=>{let r=$(e);return r===null?String(e):new Intl.NumberFormat(n.locale,{style:"percent"}).format(r)},number:(e,t,n)=>{let r=$(e);return r===null?String(e):new Intl.NumberFormat(n.locale).format(r)},date:(e,t,n)=>{let r=Rt(e);if(!r)return String(e);let o=t[0]??"short",i=xt(n.locale);if(o==="relative")return gt(r,{addSuffix:!0,locale:i});let l=vr[o]??o;return Fr(r,l,{locale:i})},duration:(e,t,n)=>{let r=xt(n.locale);if(typeof e=="number")return bt(e,t[0]??"ms",r);if(c(e)){let i=$(e);if(i!==null)return bt(i,t[0]??"ms",r)}let o=Rt(e);return o?gt(o,{addSuffix:!0,locale:r}):String(e)}};function ht(e,t,n){let r=t.split(":").map(a=>a.trim()).filter(a=>a.length>0);if(r.length===0)return;let[o,...i]=r,l=Ir[o];if(l)return l(e,i,n)}function Tt(e,t=ce){if(e!=null){if(mt(e)||p(e))return e;if(u(e)){let n=kr(e,t);if(p(n))return n}}}function kr(e,t){let n=y(e,t);if(p(n))return n}function y(e,t){if(!t||!u(e))return null;let n=t.split(".").filter(o=>o!=="");if(n.length===0)return null;let r=e;for(let o of n)if(u(r)&&o in r)r=r[o];else if(Array.isArray(r)){let i=Number(o);if(!Number.isInteger(i)||i<0||i>=r.length)return null;r=r[i]}else return null;return r}function At(e,t={description:qe,label:Je,value:ce}){return e.map(n=>{if(u(n)){let r=y(n,t.label),o=y(n,t.value);if(p(r)&&p(o)){let i=y(n,t.description);return{label:`${r}`,value:`${o}`,...p(i)&&{description:`${i}`}}}}return n})}function Ft(e=L){let t=e.lastIndexOf("/"),n=t===-1?e:e.slice(t+1);return n&&n!==H?n.trim().toLowerCase():L}var Lr=/\[([^\]]{1,500})\]\(([^)]{1,2000})\)/g,Er=/{([^}]{1,200})}/,Or=/{([^}]{1,200})}/g;function E(e,t={},n={}){if(c(e))return Pr(e,t,n);if(Array.isArray(e))return e.map(r=>E(r,t,n));if(u(e)){let r={};for(let o in e)r[o]=E(e[o],t,n);return r}return e}function O(e,t={},n={}){return fe(e)?E(e,t,n):e}function fe(e){return c(e)?Er.test(e):Array.isArray(e)?e.some(t=>fe(t)):u(e)?Object.values(e).some(t=>fe(t)):!1}function Dr(e,t){return t.includes(".")?y(e,t):e[t]}function Pr(e,t={},n={}){return e.replace(Or,(r,o)=>{let i=String(o).split("|").map(m=>m.trim()),[l,...a]=i;if(!l)return r;let s=Dr(t,l);if(a.length===0)return p(s)?String(s):r;if(s==null)return r;let d=s;for(let m of a){let B=ht(d,m,{locale:n.locale});if(B===void 0)return r;d=B}return String(d)})}function Ct(e,t){if(!c(e)||!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=Lr.exec(e))!==null;){let[l,a,s]=n,d=n.index;o=!0,d>r&&i.push(e.substring(r,d));let m=t?t(d,s,a):l;i.push(m),r=d+l.length}return o?(r<e.length&&i.push(e.substring(r)),i):e}var St=e=>f(Ge)(e),Nt=e=>f(Ue)(e),vt=e=>f($e)(e),wt=e=>f(Xe)(e),It=e=>f(Ye)(e),kt=e=>f(We)(e),Lt=e=>f(Ze)(e),Et=f(De),me=f(_e),x=f(Be),N=f(Ke),F=f(Ve),Ot=f(H),h=f(He),Dt=f(ze),Pt=f(L,de,je,et),Ii=f(Pe,de),Mt=f(Me,Qe);function _t(e){return F(e)||x(e)}function Y(e){return e.type===ae}function v(e){return e.type===k}function X(e){return e.type!==k&&e.type!==ae}function ge(e){return h(e)||F(e)||N(e)}function D(e){return e!=null&&e!==""}function f(...e){return t=>{let n=c(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function zt(e,t={}){if(h(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&u(n))return[n]}}function Vt(e){return F(e)||x(e)?!0:e.advanced?.horizontal}function Bt(e){return x(e)?e.advanced?.reverse!==!1:!1}function Ht(e,t){let n=e.readonly??!1;return t||n}function pe(e){if(Mr(e)){let t=e.source;if(Array.isArray(t)||u(t)&&!(S in t))return t}}function Gt(e){return Array.isArray(pe(e))}function Mr(e){return F(e)||N(e)||h(e)&&!e.disabled}import{isValid as Yt,parse as Xt,format as Kt}from"date-fns";var _r=/^\d+$/,Wt=new Date(2e3,0,1),zr=()=>"supportedValuesOf"in Intl?Intl.supportedValuesOf("timeZone"):[],ye="default";function Zt(e){if(!e)return ye;try{return Intl.getCanonicalLocales(e)[0]??ye}catch{return ye}}function xe(e){let t=Zt(e);return Array.from({length:12},(n,r)=>({value:(r+1).toString(),label:new Date(0,r).toLocaleString(t,{month:"long"})}))}function be(e){let t=Zt(e);return Array.from({length:7},(n,r)=>({value:r.toString(),label:new Date(2e3,0,2+r).toLocaleString(t,{weekday:"long"})}))}function qt(e,t){return t>=e?Array.from({length:t-e+1},(n,r)=>{let o=e+r;return{value:o.toString(),label:o.toString()}}):[]}function Re(){return new Date().getFullYear()}function Vr(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Br(e){let t=e.indexOf("/"),n=t===-1?e:e.slice(0,t);return ft[n]??"Other"}function Hr(e,t){return(e.find(r=>r.type==="timeZoneName")?.value??t).replace(/\s+(?:Standard|Daylight(?: Saving)?|Summer|Winter)\s+Time$/,"")}function Ut(e,t){let n=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"longOffset"}).formatToParts(t),r=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"long"}).formatToParts(t),i=(n.find(a=>a.type==="timeZoneName")?.value??"GMT+00:00").replace("GMT","UTC"),l=Hr(r,e);return{offset:i,longName:l}}function $t(e){return e.slice(e.lastIndexOf("/")+1).replace(/_/g," ")}function Jt(){let e=new Date,t=Vr(),n=new Map,r=$t(t),{offset:o,longName:i}=Ut(t,e),l={value:t,label:`${r} - ${i} (${o})`};for(let s of zr()){if(s===t)continue;let d=$t(s),{offset:m,longName:B}=Ut(s,e),we={value:s,label:`${d} - ${B} (${m})`},le=Br(s);if(le==="Other")continue;let Ie=n.get(le);Ie?Ie.push(we):n.set(le,[we])}for(let s of n.values())s.sort((d,m)=>d.label.localeCompare(m.label));let a=Array.from(n.entries()).sort(([s],[d])=>s.localeCompare(d)).map(([s,d])=>({label:s,items:d}));return[{label:"Suggested",items:[l]},...a]}function he(e,t){if(typeof e=="number")return e;let n=t??Re(),r=e.trim().toLowerCase();if(r.startsWith("current")){let o=r.match(/^current([+-])(\d+)$/);if(o){let[,i,l]=o,a=parseInt(l,10);if(!isNaN(a))return i==="+"?n+a:n-a}return n}return _r.test(r)?parseInt(r,10):n}function Qt(e,t){if(!e)return"";try{let n=Xt(e,t,Wt);return Yt(n)?Kt(n,"yyyy-MM-dd"):""}catch{return""}}function jt(e,t){if(!e)return"";try{let n=Xt(e,t,Wt);return Yt(n)?Kt(n,"HH:mm:ss"):""}catch{return""}}function Te(e){return e.advanced?.format??"HH:mm"}function en(e){return e.advanced?.format??"MMMM d, yyyy"}var Gr={es:{"(Optional)":"(Opcional)","Add item":"A\xF1adir elemento","An unexpected error occurred submitting the form.":"Ocurri\xF3 un error inesperado al enviar el formulario.","Collapse {label} {index}":"Contraer {label} {index}","Expand {label} {index}":"Expandir {label} {index}","Please correct the errors and try again.":"Corrige los errores e int\xE9ntalo de nuevo.","Remove {label} item {index}":"Eliminar {label} {index}","There were validation errors submitting the form.":"Se encontraron errores de validaci\xF3n al enviar el formulario.","Unknown error":"Error desconocido",No:"No",Yes:"S\xED"}};function K(e,t){return b(e,t)}function nn(e,t){let n=t?.[e??""],r=e?Gr[Ur(e)]:void 0;return r?n?{...r,...n}:r:n}function Ur(e){return e.toLowerCase().split(/[-_]/)[0]}function b(e,t){return e?t?t[e]??e:e:""}function w(e,t){return e?b(e,t):void 0}function W(e,t){if(!t)return e;let n=!1,r=e.map(o=>{let i=$r(o,t);return i!==o&&(n=!0),i});return n?r:e}function $r(e,t){if(!u(e))return e;let n=tn(e.label,t),r=e.items;if(Array.isArray(r)){let i=W(r,t);return i===r&&n===e.label?e:{...e,...n!==void 0&&{label:n},items:i}}let o=tn(e.description,t);return n===e.label&&o===e.description?e:{...e,...n!==void 0&&{label:n},...o!==void 0&&{description:o}}}function tn(e,t){return c(e)?b(e,t):e}var Z=Re();function Yr(e,t){if(N(e))return Xr(e,t?.lang)}function Xr(e,t){if(kt(e))return be(t);if(Lt(e))return xe(t)}function Kr(e,t){if(h(e))return Wr(e,t)}function Wr(e,t){let{lang:n,translations:r}=t??{};if(Nt(e))return be(n);if(vt(e))return xe(n);if(wt(e)){let o=e.advanced?.length?.min??Z,i=e.advanced?.length?.max??Z+5;return qt(he(o,Z),he(i,Z))}if(It(e))return Jt();if(St(e))return W([{value:"true",label:"Yes"},{value:"false",label:"No"}],r)}function rn(e,t=!1,n){let r={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return Ot(e)?{...r,...Zr(e)}:h(e)?{...r,...on(Kr(e,n))}:Dt(e)?{...r,...Jr(e)}:N(e)?{...r,...qr(e,n)}:r}function Zr(e){let t=Ft(e.type),n={...e,type:t};return{...jr(e),...ln(e),...Qr(n),...Pt(n)?an(n):{},type:t}}function on(e){return e?{options:e}:{}}function qr(e,t){let n=on(Yr(e,t)),r=e.advanced?.multiple??!0;return{...n,multiple:r}}function Jr(e){return{...ln(e),...an(e)}}function ln(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Qr(e){return Mt(e)?eo(e):{}}function jr(e){if(me(e)){let t=Te(e);return{step:t==="HH:mm:ss"||t==="hh:mm:ss a"?"1":"60"}}return{}}function an(e){return sn(e,{min:dt,max:st})}function eo(e){return sn(e,{min:ct,max:at})}function sn(e,t){let n={},r=e.advanced?.length;return r&&(r.min!==void 0&&(n[t.min]=r.min),r.max!==void 0&&(n[t.max]=r.max)),n}function cn(e,t){let n=pe(e);return n||zt(e,t)}function to(e,t){let n=u(t)&&e.name in t?t[e.name]:t,r=Tt(n,e.advanced?.entity),o=D(r)?r:e.defaultValue;return me(e)&&D(o)?no(e,o):Et(e)&&D(o)?lo(e,o):o}function no(e,t){let n=Te(e);return c(t)?jt(t,n):t}function ro(e,t,n){return ge(e)&&Array.isArray(n)?{...t,[G]:n}:t}function oo(e,t,n){if(e.required&&!D(n)&&h(e)&&e.advanced?.preselected!==!1&&G in t){let r=t[G];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function io(e,t,n){if(ge(e)&&Array.isArray(t)){let r=At(t,e.advanced?.options);return Gt(e)?W(r,n):r}return t}function dn(e,t,n,r,o){let i=to(e,r),l=Array.isArray(n)?io(e,n,o):n,a=ro(e,t,l),s=oo(e,a,i);return{commonPropsWithOptions:a,defaultValue:s}}function un(e,t){return x(e)?{defaultChecked:!!t}:{defaultValue:t}}function lo(e,t){let n=en(e);return c(t)?Qt(t,n):t}var ao=/^#\/definition\//;function J(e=[],t){let n=q(e,t);return Array.isArray(n)?n.filter(co).sort((r,o)=>fn(r)-fn(o)):[]}function q(e,t,n=new Map,r=new WeakSet){if(!so(t)||!e||typeof e!="object")return e;if(n.has(e))return n.get(e);if(r.has(e))return e;if(r.add(e),Array.isArray(e))return e.map(i=>q(i,t,n,r));if(S in e&&c(e[S])){let i=e[S].replace(ao,""),l=y(t,i);return l!==null?q(l,t,n,r):e}let o={};for(let[i,l]of Object.entries(e))o[i]=q(l,t,n,r);return r.delete(e),n.set(e,o),o}function mn(e){return Object.entries(e??{})}function fn(e){return e.order??Number.MAX_VALUE}function so(e){return e!==void 0&&u(e)&&Object.keys(e).length>0}function co(e){return ut in e?!0:Array.isArray(e[se])?e[se].length>0:!0}function gn(e,t){let n={};for(let[r,o]of mn(t))n[`${e}-${r}`]=o;return n}function uo(e){return gn(it,e)}function fo(e){return gn(lt,e)}function pn(e,t){let n=uo(e.advanced?.aria);return t&&t.length>0&&(n[nt]="true",n[tt]=`${e.name}-error`),n}function yn(e){return fo(e.advanced?.data)}var xn={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},bn={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function Rn(e,t=2){return xn[e&&e in xn?e:t]}function hn(e){if(e&&e in bn)return bn[e]}function mo(e){return{min:e.advanced?.length?.min??1,max:e.advanced?.length?.max??1/0}}function go(e,t){let n=t?y(t,e.name):null;return po(e,Array.isArray(n)?n.length:0)}function Tn(e){return!Array.isArray(e.fields)||e.fields.length===0?!1:e.fields.length>1||e.fields[0].type===k}function An(e,t){let n=go(e,t);return Array.from({length:n},(r,o)=>o)}function Fn(e){return e.advanced?.title??e.label??e.name}function po(e,t){let{min:n,max:r}=mo(e);return Math.min(Math.max(t,n),r)}function Q(e,t){let n={...e};for(let r of Object.keys(t??{})){let o=t?.[r];o!==void 0&&(n[r]=o)}return n}import{jsx as yo}from"react/jsx-runtime";function R(e){return Ct(e,(t,n,r)=>yo("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}import{useCallback as xo,useState as bo}from"react";import{jsx as P,jsxs as Ae}from"react/jsx-runtime";function Cn(e){let{fields:t=[]}=e.section,[n,r]=bo(!1),o=xo(()=>r(i=>!i),[]);return Ae("fieldset",{"data-slot":"field-set","data-advanced":"true","data-expanded":n,"data-empty":t.length===0,className:"flex flex-col",id:e.section.id?.toString(),children:[P("legend",{children:Ae("button",{className:"flex cursor-pointer items-center gap-2 text-base font-medium text-zinc-600 dark:text-zinc-400",onClick:o,type:"button",children:[P(C,{expanded:n}),P("span",{children:R(e.title)})]})}),P(I,{visible:n,children:Ae("div",{className:"mt-3 ml-1.5 flex flex-col gap-4 border-l-2 border-zinc-300 pl-4 dark:border-zinc-600","data-slot":"field-set-content",children:[e.description&&P("p",{className:"text-sm leading-normal font-normal text-zinc-600 dark:text-zinc-400",children:R(e.description)}),e.group]})})]})}import{jsx as j,jsxs as Sn}from"react/jsx-runtime";function Nn(e){let t=Sn("div",{className:"flex flex-col",children:[e.title&&j("legend",{className:"mb-3 font-medium text-zinc-800 dark:text-zinc-200",children:R(e.title)}),e.description&&j("p",{className:"-mt-2 text-sm leading-normal font-normal text-zinc-600 dark:text-zinc-400",children:R(e.description)})]});return e.step?Sn("div",{className:"flex flex-row items-start gap-4",children:[j("div",{className:"bg-primary text-primary-foreground flex size-6 shrink-0 items-center justify-center rounded-full",children:j("span",{className:"text-sm font-bold",children:e.step})}),t]}):t}import{jsx as vn,jsxs as Ro}from"react/jsx-runtime";function ee(e){return Ro("fieldset",{className:"flex w-full min-w-0 flex-col data-[empty=false]:gap-6","data-empty":e.empty,"data-slot":"field-set",id:e.id,children:[vn(Nn,{description:e.description,step:e.step,title:e.title}),vn("div",{className:"w-full min-w-0",children:e.children})]})}import{jsx as ho}from"react/jsx-runtime";function T(e){return ho("div",{"data-slot":"field-group","data-compact":e.compact,className:"flex w-full flex-col gap-8 data-[compact=true]:gap-3",children:e.children})}import{jsx as Fe}from"react/jsx-runtime";function wn(e){let{fields:t=[]}=e.section,n=e.advanced?.step?e.step:void 0,{compact:r}=Q(e.style,{compact:e.section.advanced?.compact}),o=Fe(T,{compact:r,children:e.children});if(!e.section.title&&!e.section.description)return o;let i=w(e.section.title,e.translations),l=w(e.section.description,e.translations);return e.section.advanced?.collapsible?Fe(Cn,{description:l,group:o,section:e.section,title:i}):Fe(ee,{description:l,empty:t.length===0,id:e.section.id?.toString(),step:n,title:i,children:o})}import{jsx as In}from"react/jsx-runtime";function kn(){return In("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:In("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-zinc-200 dark:bg-zinc-800"})})}import{useAtomValue as vo}from"jotai";import{atom as M}from"jotai";import{atomFamily as To}from"jotai-family";import{deepEqual as Ln}from"fast-equals";function Ao(e,t){let{[t]:n,...r}=e;return r}function Fo(e){return To(t=>M(n=>n(e)[t]??void 0,(n,r,o)=>{let i=n(e);if(o!=null){let l=i[t];Ln(l,o)||r(e,{...i,[t]:o})}else t in i&&r(e,Ao(i,t))}))}function Co(e){return M(null,(t,n)=>{let r=t(e);r&&Object.keys(r).length>0&&n(e,{})})}function So(e){return M(null,(t,n,r)=>{let i={...t(e)},l=!1;for(let a of r)a in i&&(delete i[a],l=!0);l&&n(e,i)})}function No(e){return M(null,(t,n,r)=>{let o=t(e);Ln(o,r)||n(e,r)})}function te(e={}){let t=M(e);return{atom:t,clearAll:Co(t),clear:So(t),bulkReport:No(t),report:Fo(t)}}var En=te(),On=En.atom,Dn=En.report;function wo(e,t){return e.fields.every(n=>Pn(n,t))}function Pn(e,t){return t[e.name]?.hidden??e.hidden??!1}function Io(e,t){return v(e)?wo(e,t):Pn(e,t)}function Mn(e){let t=vo(On);return e.container&&(t[e.container.name]?.hidden??e.container.hidden??!1)||e.fields.length===0||e.fields.every(r=>Io(r,t))?null:e.children}import{jsx as _,jsxs as _n}from"react/jsx-runtime";function zn(e){let t=J(e.sections,e.definition);return _("div",{className:"h-full w-full",children:_("form",{noValidate:e.noValidate,action:e.action,children:_n(T,{children:[t.map((n,r)=>_n(Mn,{fields:n.fields??[],children:[_(wn,{advanced:e.advanced,section:n,step:r+1,style:e.config.style,translations:e.translations,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.advanced?.separator&&_(kn,{})]},`key-${n.id}-${r}`)),e.control&&_(ke,{isPending:e.isPending,children:e.control})]})})})}import{jsx as ko}from"react/jsx-runtime";function Vn(e){return ko("p",{className:"-mt-2 text-xs leading-normal font-normal text-zinc-600 dark:text-zinc-400 [[data-slot=column]_&]:md:line-clamp-2",title:e.title,children:e.children})}import{useState as Lo}from"react";import{jsx as Bn,jsxs as Hn}from"react/jsx-runtime";function ne(e){let t={context:e.context,env:e.config?.env,value:e.value},r={locale:e.config?.env?.locale},[o,i]=Lo(()=>u(e.text)&&"collapsed"in e.text?!e.text.collapsed:!0),l=()=>i(m=>!m),a=u(e.text)&&c(e.text.title)?R(b(O(e.text.title,t,r),e.translations)):void 0,s=b(O(c(e.text)?e.text:e.text?.message,t,r),e.translations),d=R(s);return d?Hn("div",{className:"flex flex-col gap-2",children:[a&&Hn("button",{className:"flex items-center gap-1 text-left text-xs font-medium text-zinc-700 hover:text-zinc-900 dark:text-zinc-300 dark:hover:text-zinc-100",onClick:l,type:"button",children:[a,Bn(C,{expanded:o})]}),o&&Bn(Vn,{title:s,children:d})]}):null}import{atom as Gn}from"jotai";var re=te(),aa=re.atom,sa=re.clearAll,ca=re.clear,Un=re.report,da=Gn({}),ua=Gn(null);import{useAtomValue as $n}from"jotai";import{jsx as Eo}from"react/jsx-runtime";function oe(e){let t=$n(Un(e.field.name)),r=$n(Dn(e.field.name))?.description??e.field.description;return Eo(ne,{config:e.config,context:e.context,text:r,translations:e.translations,value:t})}import{twMerge as Oo}from"tailwind-merge";import{jsx as Yn,jsxs as Do}from"react/jsx-runtime";function Xn(e){let t=e.style?.showOptionalLabel??!0,n=F(e.field)||x(e.field);return Do("label",{"data-slot":"field-label","data-normal":n,className:Oo("flex w-fit items-center text-sm leading-snug font-medium select-none","data-[normal=true]:font-normal [[data-slot=column]_&]:md:w-full","group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"),htmlFor:e.field.name,title:c(e.children)?e.children:void 0,children:[Yn("span",{className:"[[data-slot=column]_&]:md:truncate",children:e.children}),t&&!e.field.required&&Yn("span",{className:"ml-2 flex-shrink-0 text-sm text-zinc-600 dark:text-zinc-400",children:K("(Optional)",e.translations)})]})}import{jsx as Kn,jsxs as Po}from"react/jsx-runtime";function Wn(e){let t={context:e.context,env:e.config?.env},n=e.config?.env?.locale,r=O(e.field.label,t,{locale:n});return Po("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[Kn(Xn,{field:e.field,style:e.config?.style,translations:e.translations,children:b(r,e.translations)}),e.horizontal===!0&&Kn(oe,{config:e.config,context:e.context,field:e.field,translations:e.translations})]})}import{Fragment as Mo,jsx as Zn,jsxs as _o}from"react/jsx-runtime";function qn(e){return _o(Mo,{children:[e.field.name&&e.field.label&&Zn(Wn,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations}),e.children,e.horizontal===!1&&Zn(oe,{config:e.config,context:e.context,field:e.field,translations:e.translations})]})}function Jn(e,t){return e?t(e):null}import{jsx as Qn}from"react/jsx-runtime";function jn(e){let t=cn(e.field,e.value),{commonPropsWithOptions:n,defaultValue:r}=dn(e.field,e.commonProps,t,e.value,e.translations),o=un(e.field,r);return Jn(e.config.inputs[e.field.type],i=>Qn(qn,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations,children:Qn(i,{...e.ariaAttributes,...n,...e.dataAttributes,...o})}))}import{jsx as er}from"react/jsx-runtime";function tr(e){return!e.errors||e.errors.length===0?null:er("ul",{className:"text-sm text-red-600 dark:text-red-500",id:e.name?`${e.name}-error`:void 0,children:e.errors?.map((t,n)=>er("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}import{twMerge as zo}from"tailwind-merge";import{jsx as Vo}from"react/jsx-runtime";function ie(e){let t=e.errors&&e.errors.length>0;return Vo("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[rt]:"true"},...e.disabled&&{[ot]:"true"},"data-orientation":e.orientation,className:zo("group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500","data-[clickable=true]:items-start",e.isCheckbox&&(e.isReversed?"flex-row-reverse!":"flex-row!"),"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",e.className),children:e.children})}import{twMerge as Bo}from"tailwind-merge";import{jsx as Ho}from"react/jsx-runtime";function nr(e){return Ho(ie,{...e,orientation:"vertical",className:Bo("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}import{twMerge as Go}from"tailwind-merge";import{jsx as Uo}from"react/jsx-runtime";function rr(e){return Uo(ie,{...e,orientation:"horizontal",className:Go("gap-2 md:flex-row md:gap-4","[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start","[&_[role=checkbox]]:mt-[1.5px]",e.isClickable&&"md:flex-col",!e.isClickable&&["md:justify-between","[&>*:not([data-slot=field-content])]:w-full","[&>*:not([data-slot=field-content])]:md:w-1/2","[&>*:not([data-slot=field-content])]:xl:w-2/5"]),children:e.children})}import{jsx as or}from"react/jsx-runtime";function ir(e){let t=_t(e.field),n=x(e.field),r=Bt(e.field);return e.horizontal?or(rr,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):or(nr,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function lr(e){if(!e.field.type)return null;let t=rn(e.field,e.disabled,{lang:e.lang,translations:e.translations}),n=yn(e.field),r=pn(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,horizontal:e.horizontal})}import{twMerge as $o}from"tailwind-merge";import{jsx as Ce,jsxs as Yo}from"react/jsx-runtime";function ar(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{horizontal:r=!1}=Q(e.style,{horizontal:Vt(e.field)}),o=Ht(e.field,e.disabled);return Yo("div",{className:$o("flex flex-col gap-3",hn(t)),children:[Ce(ir,{disabled:o,errors:n,field:e.field,horizontal:r,children:Ce(lr,{disabled:o,errors:n,field:e.field,horizontal:r,lang:e.lang,translations:e.translations,children:e.children})}),Ce(tr,{errors:n,name:e.field.name})]})}import{twMerge as Se}from"tailwind-merge";import{useState as Xo}from"react";import{Fragment as Ko,jsx as g,jsxs as A}from"react/jsx-runtime";function sr(e){let t=e.isMultiField||e.collapsed!=null,[n,r]=Xo(t?!e.collapsed:!0);function o(){e.canRemove&&e.onRemove&&e.onRemove(e.index)}function i(){r(m=>!m)}let l=m=>E(K(m,e.translations),{index:e.index+1,label:e.label}),a=e.canRemove&&e.onRemove!=null&&g("button",{"aria-label":l("Remove {label} item {index}"),className:Se("flex size-6 items-center justify-center rounded text-xl leading-none text-zinc-400","transition-colors duration-150","hover:text-red-500","focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:outline-none","dark:text-zinc-500 dark:hover:text-red-400"),onClick:o,type:"button",children:g("span",{"aria-hidden":"true",className:"leading-none",children:"\xD7"})}),s=A("div",{className:"flex min-w-0 flex-col font-medium text-zinc-700 dark:text-zinc-400",children:[g("span",{className:"text-base",children:e.previewLabel??A(Ko,{children:[e.label," ",e.index+1]})}),!n&&e.previewTags&&g("div",{className:"flex items-center gap-2 overflow-hidden text-xs font-normal text-ellipsis whitespace-nowrap text-zinc-500 dark:text-zinc-500",children:e.previewTags})]}),d=A("div",{className:Se("flex items-center justify-between gap-2",e.isMultiField&&n&&"mb-3"),children:[t?A("div",{className:"flex min-w-0 grow items-center gap-2",children:[A("button",{"aria-expanded":n,"aria-label":l(n?"Collapse {label} {index}":"Expand {label} {index}"),className:Se("group flex grow items-center gap-2 rounded p-1 text-left text-zinc-400","focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:outline-none","dark:text-zinc-500"),onClick:i,type:"button",children:[g(C,{expanded:n}),s]}),!n&&e.previewBadge&&g("div",{className:"ml-auto shrink-0",children:e.previewBadge})]}):s,a]});return e.isMultiField?A("div",{"data-slot":"list-item-card",className:"box-border w-full min-w-0 rounded-lg border border-zinc-100 p-4 dark:border-zinc-900",children:[d,g(I,{visible:n,children:g(T,{children:e.children})})]}):t?A("div",{className:"box-border flex w-full min-w-0 flex-col gap-2",children:[d,g(I,{visible:n,children:g(T,{children:e.children})})]}):A("div",{className:"box-border flex w-full min-w-0 items-start gap-2",children:[g("div",{className:"flex min-w-0 grow flex-col",children:g(T,{children:e.children})}),a&&g("div",{className:"shrink-0",children:a})]})}import{jsx as Wo}from"react/jsx-runtime";function cr(e){let t=b(Fn(e.field),e.translations),n=Tn(e.field);return An(e.field,e.value).map(r=>Wo(sr,{collapsed:e.field.advanced?.collapsed,index:r,isMultiField:n,label:t,translations:e.translations,children:e.children(r)},r))}import{jsx as Zo}from"react/jsx-runtime";function dr(e){let t=Array.isArray(e.field.fields)&&e.field.fields.length===0,n=w(e.field.label,e.translations),r=w(e.field.description,e.translations);return Zo(ee,{description:r,empty:t,id:e.field.name,title:n,children:e.children})}import{jsx as ur}from"react/jsx-runtime";function fr({children:e,field:t,lang:n,translations:r,value:o}){return ur(dr,{field:t,translations:r,children:ur(cr,{field:t,lang:n,translations:r,value:o,children:e})})}import{twMerge as qo}from"tailwind-merge";import{jsx as mr,jsxs as Jo}from"react/jsx-runtime";function gr(e){let t=Rn(e.column?.advanced?.cols);return Jo("div",{className:"flex w-full flex-col gap-4",children:[mr("div",{"data-slot":"column",className:qo("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children}),e.column?.description&&mr(ne,{config:e.config,context:e.context,text:e.column.description,translations:e.translations})]})}import{Fragment as jo}from"react";import{jsx as Qo}from"react/jsx-runtime";function pr(e){let t=Array.isArray(e.field.fields)?e.field.fields.map(n=>X(n)||Y(n)?{...n,name:`${e.field.name}.${e.index}.${n.name}`}:v(n)?{...n,fields:n.fields.map(r=>({...r,name:`${e.field.name}.${e.index}.${r.name}`}))}:n):[];return Qo(z,{components:e.components,config:e.config,context:e.context,disabled:e.disabled,fields:t,lang:e.lang,onValueChange:e.onValueChange,style:e.style,translations:e.translations,value:e.value,children:e.children})}import{jsx as V,jsxs as ei}from"react/jsx-runtime";function z(e){let{field:t,list:n}=e.components;return J(e.fields).map((r,o)=>ei(jo,{children:[v(r)&&V(gr,{column:r,config:e.config,context:e.context,translations:e.translations,children:V(z,{...e,fields:r.fields})}),X(r)&&V(t,{disabled:e.disabled,field:r,lang:e.lang,style:e.style,translations:e.translations,children:e.children}),Y(r)&&V(n,{field:r,lang:e.lang,onValueChange:e.onValueChange,translations:e.translations,value:e.value,children:i=>V(pr,{components:e.components,config:e.config,context:e.context,disabled:e.disabled,field:r,index:i,lang:e.lang,onValueChange:e.onValueChange,style:e.style,translations:e.translations,value:e.value,children:e.children})})]},o))}import{jsx as ti}from"react/jsx-runtime";function yr(e){return n=>ti(z,{...n,components:e})}var xr=yr({field:ar,list:fr});import{jsx as Ne}from"react/jsx-runtime";function ve(e){let t=nn(e.lang,e.translations);return Ne(zn,{advanced:e.advanced,config:e.config,control:e.children,definition:e.definition,readOnly:e.readOnly,sections:e.sections,translations:t,children:({disabled:n,fields:r})=>Ne(xr,{config:e.config,context:e.context,disabled:n,fields:r,lang:e.lang,style:e.config.style,translations:t,value:e.value,children:o=>Ne(jn,{...o,config:e.config,context:e.context,translations:t,value:e.value})})})}import{Suspense as ni}from"react";import{jsx as br}from"react/jsx-runtime";function ri(e){return br(ni,{fallback:br(ve,{config:e.config,sections:e.sections,readOnly:!0}),children:e.children})}export{ri as Fallback,ve as Form};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Field, Nullable } from '../type';
|
|
2
2
|
export declare function buildOptions(field: Field, values?: Nullable<Record<string, unknown>>): Record<string, unknown>[] | undefined;
|
|
3
|
-
export declare function buildOrientation(field: Field): boolean;
|
|
3
|
+
export declare function buildOrientation(field: Field): boolean | undefined;
|
|
4
4
|
export declare function buildReverse(field: Field): boolean;
|
|
5
5
|
export declare function buildDisabled(field: Field, disabled?: boolean): boolean;
|
|
6
6
|
export declare function buildSource(field: Field): import("..").DataSource | unknown[] | undefined;
|
|
@@ -3,10 +3,10 @@ import type { CustomValidation, Definition, Field, Input, Schemas, Sections, Zod
|
|
|
3
3
|
export declare function buildSchema(schemas: Schemas, fields?: Field[], translations?: Record<string, string>): ZodSchema;
|
|
4
4
|
export declare function flatten(error: z.ZodError<Record<string, unknown>>): Record<string, string[]>;
|
|
5
5
|
export declare function getSchema(input: Input, translations?: Record<string, string>): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
6
|
-
export declare function getEmail(input: Input, translations?: Record<string, string>): z.ZodPreprocess<z.ZodPipe<z.ZodString, z.ZodEmail
|
|
7
|
-
export declare function getText(input: Input, translations?: Record<string, string>): z.ZodPreprocess<z.ZodCoercedString<unknown
|
|
8
|
-
export declare function getNumber(input: Input, translations?: Record<string, string>): z.ZodNullable<z.ZodCoercedNumber<unknown>> | z.ZodPreprocess<z.ZodCoercedNumber<unknown
|
|
9
|
-
export declare function getYearSchema(input: Input, translations?: Record<string, string>): z.ZodNullable<z.ZodCoercedNumber<unknown>> | z.ZodPreprocess<z.ZodCoercedNumber<unknown
|
|
6
|
+
export declare function getEmail(input: Input, translations?: Record<string, string>): z.ZodPreprocess<z.ZodPipe<z.ZodString, z.ZodEmail>, unknown> | z.ZodNullable<z.ZodUnion<[z.ZodPipe<z.ZodString, z.ZodEmail>, z.ZodLiteral<"">]>>;
|
|
7
|
+
export declare function getText(input: Input, translations?: Record<string, string>): z.ZodPreprocess<z.ZodCoercedString<unknown>, unknown> | z.ZodNullable<z.ZodCoercedString<unknown>>;
|
|
8
|
+
export declare function getNumber(input: Input, translations?: Record<string, string>): z.ZodNullable<z.ZodCoercedNumber<unknown>> | z.ZodPreprocess<z.ZodCoercedNumber<unknown>, unknown>;
|
|
9
|
+
export declare function getYearSchema(input: Input, translations?: Record<string, string>): z.ZodNullable<z.ZodCoercedNumber<unknown>> | z.ZodPreprocess<z.ZodCoercedNumber<unknown>, unknown>;
|
|
10
10
|
export declare function getMonthSchema(input: Input, translations?: Record<string, string>): z.ZodCoercedNumber<unknown> | z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
11
11
|
export declare function applyCustomValidation(schema: ZodSchema, fields?: Field[], translations?: Record<string, string>): ZodSchema;
|
|
12
12
|
export declare function validateCustom(value: unknown, rules: CustomValidation | Array<CustomValidation>, getValue: (name: string) => unknown, translations?: Record<string, string>): string[];
|
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
import type { Style } from '../type';
|
|
2
|
-
export declare function mergeStyle(globalStyle?: Style, localStyle?: Style):
|
|
3
|
-
compact?: boolean;
|
|
4
|
-
horizontal?: boolean;
|
|
5
|
-
showOptionalLabel?: boolean;
|
|
6
|
-
};
|
|
2
|
+
export declare function mergeStyle(globalStyle?: Style, localStyle?: Style): Style;
|
package/docs/events/change.md
CHANGED
|
@@ -10,6 +10,8 @@ In many actions (like `value`, `source`, and `state`), you may want to use the v
|
|
|
10
10
|
|
|
11
11
|
Placeholders also support format filters with pipe syntax (`{value | filter:arg}`) for locale-aware formatting of currency, dates, percentages, and durations. See [Format Filters](../interpolation/format-filters.md) for the full reference.
|
|
12
12
|
|
|
13
|
+
What a placeholder can reach in an event payload is the selected option and only that; the rules, and the different set a label or a description resolves against, are in [Interpolation](../interpolation/overview.md).
|
|
14
|
+
|
|
13
15
|
### Passing a structure rather than text
|
|
14
16
|
|
|
15
17
|
A placeholder is normally replaced _inside_ a string, so what comes out is text. When the template is **nothing but one placeholder** and the value behind it is an object or an array, the `value` action hands that value over untouched instead:
|
|
@@ -188,13 +190,48 @@ The `state` action modifies the interactive state or visibility of other fields
|
|
|
188
190
|
- `target` (string | array of strings): The field name, or an array of field names, that the state modifications should be applied to.
|
|
189
191
|
- `state` (object): An object containing the new state to apply. Properties are independent of field names — the form may safely contain a field whose `name` is `"description"`, `"disabled"` or `"hidden"`; `target` identifies the field, the keys inside `state` configure it.
|
|
190
192
|
- `disabled` (boolean, optional): Whether the field should be disabled.
|
|
191
|
-
- `hidden` (boolean, optional): Whether the field should be hidden from view. **Note:** When a field becomes hidden (`hidden: true`), its current value is automatically cleared from the form state to ensure no non-applicable data is submitted.
|
|
193
|
+
- `hidden` (boolean, optional): Whether the field should be hidden from view. **Note:** When a field becomes hidden (`hidden: true`), its current value is automatically cleared from the form state to ensure no non-applicable data is submitted. See [What clearing a hidden target means](#what-clearing-a-hidden-target-means).
|
|
192
194
|
- `description` (string | object, optional): A new description to render for the target field. Supports interpolation, format filters, and **Markdown** (specifically links). e.g. `"Check our [terms](https://example.com) for details."`.
|
|
193
195
|
- `when` (string | array of strings | [Condition object](#the-condition-object), optional): A condition that specifies when this state should be applied.
|
|
194
196
|
- If a **string** is provided, it matches exactly against the field's new value.
|
|
195
197
|
- If an **array of strings** is provided, it performs an **OR match** (the state is applied if the field's new value matches _any_ string in the array).
|
|
196
198
|
- If a **Condition object** is provided, it evaluates complex logic.
|
|
197
199
|
|
|
200
|
+
#### What clearing a hidden target means
|
|
201
|
+
|
|
202
|
+
The clear is reported, not only applied. Every field the clear empties is
|
|
203
|
+
announced through `onValueChange` with `value: undefined`, the same way a
|
|
204
|
+
`value` action announces what it writes.
|
|
205
|
+
|
|
206
|
+
That is what makes the clear stick on a **controlled** form — one that holds
|
|
207
|
+
the values in its own state and feeds them back through the `value` prop.
|
|
208
|
+
Hiding a field unmounts it, so the form's own copy goes away with it; if the
|
|
209
|
+
host were not told, its copy would remain, and the next time the target was
|
|
210
|
+
shown the field would read the host's `value` and put the old data straight
|
|
211
|
+
back. The value would be gone from the form and still be in the consumer,
|
|
212
|
+
which is the one place it could return from.
|
|
213
|
+
|
|
214
|
+
So the rule reads the same from both sides: once a `state` action hides a
|
|
215
|
+
field, the value is gone. Showing the field again gives an empty field, never
|
|
216
|
+
the old data, and a host that mirrors `onValueChange` into its own state stays
|
|
217
|
+
in step without doing anything special.
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"action": "state",
|
|
222
|
+
"target": ["advanced_body"],
|
|
223
|
+
"state": { "hidden": true },
|
|
224
|
+
"when": "none"
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Selecting `none` hides `advanced_body`, drops its value, and reports
|
|
229
|
+
`advanced_body` as `undefined`. Selecting anything else shows the field empty.
|
|
230
|
+
|
|
231
|
+
A target that holds nothing is not announced — there is nothing to clear —
|
|
232
|
+
and a target that keeps its own values under compound names (a `group`, a
|
|
233
|
+
`list`) has each of those cleared and reported in its own right.
|
|
234
|
+
|
|
198
235
|
#### What `when` compares against for a `chips` field
|
|
199
236
|
|
|
200
237
|
A `chips` field [holds an array](../fields/select.md#a-chips-value-is-always-an-array),
|
|
@@ -316,6 +353,12 @@ below run before the user has touched anything.
|
|
|
316
353
|
Two details:
|
|
317
354
|
|
|
318
355
|
- **It happens once.** Re-rendering does not fire it again.
|
|
356
|
+
- **It waits for the whole form.** What a `value` or a `source` action writes is
|
|
357
|
+
addressed to another field, and a field declared after the one carrying the
|
|
358
|
+
event has not mounted when that field does. So the run is held until the form
|
|
359
|
+
is complete, and only then are the targets filled and the sources fetched.
|
|
360
|
+
This is still before anything is painted: nothing flashes in between, and
|
|
361
|
+
target order in the definition does not change what happens.
|
|
319
362
|
- **A select waits for its options.** For a field whose options come from a
|
|
320
363
|
`source`, the initial run is held until the data has loaded, so an action
|
|
321
364
|
keyed on the selected entity sees the entity rather than a bare value. Text
|
|
@@ -378,7 +421,7 @@ In the `state` action (and potentially other areas), the `when` property can be
|
|
|
378
421
|
- `"lt"`: Less than
|
|
379
422
|
- `"lte"`: Less than or equal
|
|
380
423
|
- `value` (string | number | array): The target value to compare against the field's current value.
|
|
381
|
-
- `field` (string, optional):
|
|
424
|
+
- `field` (string, optional): Reads a different key of the **selected option** instead of its value. It is not a reference to another field in the form: a change event carries the option behind the selection and nothing else, so `field` reaches `{ "value": "cl", "dial": "+56" }`'s `dial`, not a sibling input. On a text or date field, whose event carries only `{ value }`, any other key resolves to nothing and the condition fails. See [Event payloads](../interpolation/overview.md#event-payloads).
|
|
382
425
|
|
|
383
426
|
### Examples of Conditions
|
|
384
427
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Data Sources
|
|
2
|
+
|
|
3
|
+
The options of a `select`, `radio` or `chips` can be written in the schema or
|
|
4
|
+
fetched. This page is the fetched half: the shape of a `DataSource`, when a
|
|
5
|
+
request is actually made, and what happens when one is not.
|
|
6
|
+
|
|
7
|
+
Declaring options inline is covered in [select.md](select.md#1-static-options),
|
|
8
|
+
and mapping a fetched row onto `{ label, value }` in
|
|
9
|
+
[Property Mapping Reference](select.md#property-mapping-reference).
|
|
10
|
+
|
|
11
|
+
## The shape
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"name": "country",
|
|
16
|
+
"type": "select",
|
|
17
|
+
"label": "Country",
|
|
18
|
+
"source": {
|
|
19
|
+
"url": "/api/countries",
|
|
20
|
+
"method": "GET",
|
|
21
|
+
"namespace": "data.results",
|
|
22
|
+
"headers": { "X-Tenant": "acme" },
|
|
23
|
+
"cache": "no-store"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| Key | Type | Does |
|
|
29
|
+
| ----------- | -------------------- | -------------------------------------------------- |
|
|
30
|
+
| `url` | `string`, required | relative or absolute |
|
|
31
|
+
| `method` | `string` | defaults to `GET` |
|
|
32
|
+
| `namespace` | `string` | dot path to the array inside the response |
|
|
33
|
+
| `headers` | `HeadersInit` | merged over `Accept: application/json` |
|
|
34
|
+
| `body` | `object \| BodyInit` | query parameters on a `GET`, a JSON body otherwise |
|
|
35
|
+
| `cache` | `RequestCache` | passed through to `fetch` |
|
|
36
|
+
|
|
37
|
+
## `body` changes meaning with the method
|
|
38
|
+
|
|
39
|
+
On a `GET`, each key of `body` is appended to the URL as a query parameter, and
|
|
40
|
+
keys holding `undefined` are dropped rather than sent as the string
|
|
41
|
+
`"undefined"`. On anything else the body is serialized as JSON and
|
|
42
|
+
`Content-Type: application/json` is added for you.
|
|
43
|
+
|
|
44
|
+
## `namespace` reaches into the response
|
|
45
|
+
|
|
46
|
+
An API that answers with the array itself needs nothing. One that wraps it needs
|
|
47
|
+
the dot path to it:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "url": "/api/countries", "namespace": "data.results" }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If the response is already an array, `namespace` is ignored. If the path does
|
|
54
|
+
not lead to an array, the field renders with no options — the same outcome as an
|
|
55
|
+
empty response.
|
|
56
|
+
|
|
57
|
+
## When a request is made, and when it is not
|
|
58
|
+
|
|
59
|
+
Four ways to end up with an empty field and no request:
|
|
60
|
+
|
|
61
|
+
- **The source is an array.** Inline options are used as they are.
|
|
62
|
+
- **The URL still holds a placeholder.** A cascading source keyed on another
|
|
63
|
+
field is not fetched until that placeholder resolves. This is deliberate and
|
|
64
|
+
it is also what a typo produces — see
|
|
65
|
+
[Interpolation](../interpolation/overview.md#an-unresolved-placeholder-cancels-a-request).
|
|
66
|
+
- **The URL is blocked** by [`fetcher.remotePatterns`](../setup.md#fetcherremotepatterns).
|
|
67
|
+
This one is logged; the others are silent. Relative URLs are internal and
|
|
68
|
+
always allowed.
|
|
69
|
+
- **The field is disabled.** Nothing is fetched, and a disabled `select` whose
|
|
70
|
+
value is an object renders that object as its only option — so a saved
|
|
71
|
+
selection is still readable on a form that cannot be edited.
|
|
72
|
+
|
|
73
|
+
Requests are keyed by the source itself, so two fields declaring the same one
|
|
74
|
+
share a single request and its cache entry.
|
|
75
|
+
|
|
76
|
+
## Failures
|
|
77
|
+
|
|
78
|
+
A non-2xx response throws with the parsed body, and the error is logged rather
|
|
79
|
+
than rendered: the field shows an empty list. A response that is not JSON fails
|
|
80
|
+
the same way, since the body is always parsed as JSON.
|
|
81
|
+
|
|
82
|
+
A URL containing the literal `null` or `undefined` in a path or query segment is
|
|
83
|
+
rejected before the request goes out — the usual sign that a placeholder
|
|
84
|
+
resolved to nothing.
|
|
85
|
+
|
|
86
|
+
## Changing a source at run time
|
|
87
|
+
|
|
88
|
+
A [`source` change event](../events/change.md#3-source-action-sourceevent)
|
|
89
|
+
installs a new `DataSource` on another field, with `{value}` and the rest of the
|
|
90
|
+
selected option interpolated into its `url` and `body`.
|
|
91
|
+
|
|
92
|
+
Several events aimed at the same target **merge** rather than replace: query
|
|
93
|
+
parameters from each URL are combined, `body` and `headers` are merged key by
|
|
94
|
+
key, and for anything else the most recent event wins. Two fields can each
|
|
95
|
+
contribute a parameter to one dependent source that way.
|
|
96
|
+
|
|
97
|
+
Options that arrive from a source are data, not authored copy, so they are not
|
|
98
|
+
resolved against the dictionary — see
|
|
99
|
+
[Translating Options](select.md#translating-options).
|
|
100
|
+
|
|
101
|
+
## Sharing one source between fields
|
|
102
|
+
|
|
103
|
+
A source used in more than one place belongs in a
|
|
104
|
+
[definition](../structure/definition.md), named once and referenced:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"source": { "$ref": "#/definition/sources.countries" }
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A reference that does not resolve is left as written, and a `source` that is
|
|
113
|
+
still a `$ref` is never fetched.
|
package/docs/fields/input.md
CHANGED
|
@@ -44,7 +44,7 @@ The `advanced` property dictates finer HTML details, interactive structures, and
|
|
|
44
44
|
- **`autocomplete`** _(string)_: Standard HTML autocomplete attribute (e.g., `"username"`, `"off"`).
|
|
45
45
|
- **`cols`** _(number)_: Layout column span for CSS grid alignment.
|
|
46
46
|
- **`horizontal`** _(boolean)_: Overrides configuration layout to render label and input horizontally.
|
|
47
|
-
- **`reverse`** _(boolean)_:
|
|
47
|
+
- **`reverse`** _(boolean)_: `checkbox` only, and it exists to turn a default **off**. A checkbox renders its box first and its label after it; `reverse: false` swaps them, `true` changes nothing, and on any other field type the key is not read. See [Layout](../structure/layout.md#advancedreverse-checkbox-only).
|
|
48
48
|
- **`aria`** _(object)_: Map of specific ARIA attributes for screen readers (e.g., `{ "aria-label": "Custom label" }`).
|
|
49
49
|
- **`data`** _(object)_: Map of specific HTML data attributes (e.g., `{ "data-test-id": "my-field" }`).
|
|
50
50
|
- **`transient`** _(boolean)_: If `true`, the field fires its change events and keeps nothing of its own — it is neither stored nor reported to the consumer. For a control whose whole job is to write to _another_ field. See [Transient controls](../events/change.md#transient-controls).
|
package/docs/fields/list.md
CHANGED
|
@@ -18,6 +18,9 @@ The `list` field type in Luna Form acts as an iterative array structure, enablin
|
|
|
18
18
|
|
|
19
19
|
The `advanced` property customizes structural interaction rules and layout rendering for the collection container.
|
|
20
20
|
|
|
21
|
+
- **`title`** _(string)_: Names one item of the collection. The header of the second row then reads `Contact 2` and its controls announce `Collapse Contact 2` and `Remove Contact 2`.
|
|
22
|
+
It falls back to the list's `label`, and then to its `name`, so a list called `contacts` with neither captions its rows `contacts 1`. A [`preview.label`](#collapsed-previews-preview-object) replaces the caption where it resolves; this stays the fallback for the rows where it does not.
|
|
23
|
+
Like `action`, it is copy the form declares, so it is translated through the dictionary — see [Localization](#localization).
|
|
21
24
|
- **`action`** _(string)_: A custom label applied strictly to the generic "Add item" button rendering at the end of the collection (e.g. `"Add email address"`).
|
|
22
25
|
A custom label has to be translated by the form; the built-in `Add item` default is already translated by the library — see [Localization](#localization).
|
|
23
26
|
- **`length`** _({ min?: number, max?: number })_: Configures restrictions on how many items can be generated. Enforces boundary conditions where minimum instances ensure permanent default items and maximum instances automatically disable insertion toggles. The matching error messages are declared under the list's `validation.length` — see the [Validation reference](../validation/overview.md#list-length).
|
|
@@ -65,7 +68,7 @@ For example, if you want a field inside the list to update another field **in th
|
|
|
65
68
|
{
|
|
66
69
|
"name": "role",
|
|
67
70
|
"type": "select",
|
|
68
|
-
"
|
|
71
|
+
"source": [
|
|
69
72
|
{ "value": "admin", "label": "Admin" },
|
|
70
73
|
{ "value": "user", "label": "User" }
|
|
71
74
|
],
|
|
@@ -215,7 +218,7 @@ Left untranslated, the template fills in to the same English text it replaced.
|
|
|
215
218
|
{
|
|
216
219
|
"name": "status",
|
|
217
220
|
"type": "select",
|
|
218
|
-
"
|
|
221
|
+
"source": [
|
|
219
222
|
{ "value": "active", "label": "Currently Employed" },
|
|
220
223
|
{ "value": "past", "label": "Past Job" }
|
|
221
224
|
]
|
package/docs/fields/select.md
CHANGED
|
@@ -36,7 +36,7 @@ Each option consists of:
|
|
|
36
36
|
|
|
37
37
|
### 2. Remote Data Source
|
|
38
38
|
|
|
39
|
-
You can fetch options from a remote API by providing a `DataSource` configuration.
|
|
39
|
+
You can fetch options from a remote API by providing a `DataSource` configuration. Its full shape, and when a request is and is not made, are in [data-source.md](data-source.md).
|
|
40
40
|
|
|
41
41
|
```json
|
|
42
42
|
"source": {
|
|
@@ -79,6 +79,52 @@ Inside `advanced.options`, you can map:
|
|
|
79
79
|
|
|
80
80
|
---
|
|
81
81
|
|
|
82
|
+
### `advanced.entity`
|
|
83
|
+
|
|
84
|
+
`advanced.options` decides what the user sees and what the field submits.
|
|
85
|
+
`advanced.entity` decides how a value is matched **back** to the row it came
|
|
86
|
+
from, and it defaults to `value`.
|
|
87
|
+
|
|
88
|
+
That default is right for options shaped `{ label, value }` and wrong for
|
|
89
|
+
everything else, which is why it belongs next to `options`: whenever
|
|
90
|
+
`options.value` names a key other than `value`, `entity` has to name the same
|
|
91
|
+
key.
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"name": "user_selection",
|
|
96
|
+
"type": "select",
|
|
97
|
+
"source": { "url": "/api/users" },
|
|
98
|
+
"advanced": {
|
|
99
|
+
"entity": "id",
|
|
100
|
+
"options": { "value": "id", "label": "name" }
|
|
101
|
+
},
|
|
102
|
+
"event": {
|
|
103
|
+
"change": [{ "action": "value", "value": { "contact_email": "{email}" } }]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
It does two things, both of them a lookup by that key:
|
|
109
|
+
|
|
110
|
+
- **A change event gets the whole row.** The library finds the source row whose
|
|
111
|
+
`entity` key equals the current selection and hands that object to the
|
|
112
|
+
event, which is what makes `{email}` — a key that is neither the label nor
|
|
113
|
+
the value — resolvable. Without `entity` the lookup matches nothing, the
|
|
114
|
+
event falls back to `{ value }`, and every other placeholder is left literal.
|
|
115
|
+
See [Event payloads](../interpolation/overview.md#event-payloads).
|
|
116
|
+
- **An object value is read through it.** A form whose value for this field is
|
|
117
|
+
the whole record rather than the id — `{ "id": 101, "name": "John" }` — shows
|
|
118
|
+
the right option, because `entity` says which key of that object is the
|
|
119
|
+
value. Without it the field looks for a `value` key, finds none, and mounts
|
|
120
|
+
empty.
|
|
121
|
+
|
|
122
|
+
The comparison is made on the text of both sides, so a numeric `id` in the
|
|
123
|
+
source matches the string the select reports.
|
|
124
|
+
|
|
125
|
+
`entity` is not read for `chips`: an array selection answers to no single row,
|
|
126
|
+
so a `chips` change carries the array itself.
|
|
127
|
+
|
|
82
128
|
## Translating Options
|
|
83
129
|
|
|
84
130
|
When the options are declared inline as an array, `label` and `description` are resolved against the form dictionary, exactly like a field's own `label`. Missing keys fall back to the key itself.
|
|
@@ -139,6 +185,8 @@ Specialized selectors carry their own built-in labels and are not resolved again
|
|
|
139
185
|
- **`multiple`** _(boolean, optional)_: (Available for `chips`) Allows selecting more than one option. Defaults to `true`.
|
|
140
186
|
- **`preselected`** _(boolean, optional)_: For specialized selectors like `select/month`, determines if the current value (e.g., current month) should be selected by default.
|
|
141
187
|
- **`horizontal`** _(boolean, optional)_: Renders the options or selector horizontally.
|
|
188
|
+
- **`entity`** _(string, optional)_: The key that identifies an option row, defaulting to `value`. Set it whenever `options.value` names a different key — see [`advanced.entity`](#advancedentity).
|
|
189
|
+
- **`options`** _({ label, value, description }, optional)_: Maps the keys of a remote row onto the option shape — see [Property Mapping Reference](#property-mapping-reference).
|
|
142
190
|
|
|
143
191
|
### A chips value is always an array
|
|
144
192
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Submitting
|
|
2
|
+
|
|
3
|
+
What happens between the user pressing the button and your code receiving an
|
|
4
|
+
object. This page is about the client `Form` — the server one renders fields and
|
|
5
|
+
has no submit path of its own.
|
|
6
|
+
|
|
7
|
+
## Nothing submits without a control
|
|
8
|
+
|
|
9
|
+
The library renders no button. Whatever you pass as `children` becomes the
|
|
10
|
+
form's control area:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
<Form sections={sections} config={config} action={save}>
|
|
14
|
+
{({ isPending }) => (
|
|
15
|
+
<button type="submit" disabled={isPending}>
|
|
16
|
+
{isPending ? 'Saving…' : 'Save'}
|
|
17
|
+
</button>
|
|
18
|
+
)}
|
|
19
|
+
</Form>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
A plain node works as well; the function form is what gets `isPending`, which is
|
|
23
|
+
true from the moment the action starts until it settles.
|
|
24
|
+
|
|
25
|
+
## The pipeline
|
|
26
|
+
|
|
27
|
+
On submit, in this order:
|
|
28
|
+
|
|
29
|
+
1. **The form data becomes an object.** A name that appears more than once
|
|
30
|
+
arrives as an array; everything else as a single value.
|
|
31
|
+
2. **Date fields are normalized.** A date input holds its value in the display
|
|
32
|
+
format the field declares, and it is converted back to a native date before
|
|
33
|
+
validation, so the schema and your action see one shape whatever
|
|
34
|
+
`advanced.format` says.
|
|
35
|
+
3. **It is validated** against the schema built from the fields that are
|
|
36
|
+
currently mounted.
|
|
37
|
+
4. **Dotted names are un-flattened.** `basicAuth.username` becomes
|
|
38
|
+
`{ basicAuth: { username } }`, and a numeric segment becomes an array index,
|
|
39
|
+
so `rules.0.value` rebuilds the list — with the gaps of removed rows closed
|
|
40
|
+
up.
|
|
41
|
+
5. **Your `action` is awaited** with that object and the schema.
|
|
42
|
+
6. **`onSuccess` is called** with what the action returned, and the form clears
|
|
43
|
+
itself.
|
|
44
|
+
|
|
45
|
+
## Only mounted fields are validated
|
|
46
|
+
|
|
47
|
+
The client schema is assembled from the fields on screen. A field hidden by a
|
|
48
|
+
[`state` action](../events/change.md#2-state-action-stateevent) is unmounted, so
|
|
49
|
+
it is absent from the schema and from the submitted object — which is the point:
|
|
50
|
+
a rule that does not apply cannot block a submit.
|
|
51
|
+
|
|
52
|
+
The consequence is that the browser check is narrower than the
|
|
53
|
+
[headless one](../validation/overview.md#headless-validation).
|
|
54
|
+
`buildFormSchema` walks the whole tree, item-scoped rules and list lengths
|
|
55
|
+
included. A server that re-validates with it is not repeating the client's work;
|
|
56
|
+
it is doing the part the client structurally cannot.
|
|
57
|
+
|
|
58
|
+
## What `action` receives and returns
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
type FormState<T> = {
|
|
62
|
+
data: T | null
|
|
63
|
+
error: {
|
|
64
|
+
title: string
|
|
65
|
+
description?: string
|
|
66
|
+
details?: string[] | Record<string, string[]>
|
|
67
|
+
} | null
|
|
68
|
+
success: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function save(
|
|
72
|
+
data: Payload,
|
|
73
|
+
schema?: ZodSchema
|
|
74
|
+
): Promise<FormState<Saved>> {
|
|
75
|
+
const stored = await api.save(data)
|
|
76
|
+
return { data: stored, error: null, success: true }
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The schema is handed over with the data so a server action can re-parse the same
|
|
81
|
+
rules rather than reconstructing them.
|
|
82
|
+
|
|
83
|
+
Three ways it can end:
|
|
84
|
+
|
|
85
|
+
- **`success: true`** — `onSuccess` receives `data`, and the form clears.
|
|
86
|
+
- **`success: false`** — the `error` you return is rendered by the form's
|
|
87
|
+
[alert](../setup.md#style-alert-env), untouched. This is where a server-side
|
|
88
|
+
failure ("that email is already registered") belongs.
|
|
89
|
+
- **It throws** — the error is caught and logged, and the alert shows a generic
|
|
90
|
+
title with the thrown message as its detail. A rejection is a bug report, not
|
|
91
|
+
a message for the user; return `success: false` for anything you want them to
|
|
92
|
+
read.
|
|
93
|
+
|
|
94
|
+
## The form empties on a successful submit
|
|
95
|
+
|
|
96
|
+
Once the action succeeds the values are cleared and the inputs come back blank.
|
|
97
|
+
For the usual "submit and move on" this is what you want, and for a form that
|
|
98
|
+
should keep what was submitted it is a surprise.
|
|
99
|
+
|
|
100
|
+
If the values have to survive, hold them outside the form: mirror
|
|
101
|
+
`onValueChange` into your own state and feed it back through `value` — see
|
|
102
|
+
[`withDeclaredFields`](../setup.md#withdeclaredfields) for the part that trips
|
|
103
|
+
people, which is that a key you stop sending is not the same as a key you send
|
|
104
|
+
empty.
|
|
105
|
+
|
|
106
|
+
A **failed** validation is the opposite: the submitted values are handed back to
|
|
107
|
+
the form, so the user's typing is still on screen next to the errors.
|
|
108
|
+
|
|
109
|
+
## Turning submit validation off
|
|
110
|
+
|
|
111
|
+
`defineConfig({ validation: { submit: false, ... } })` skips the parse
|
|
112
|
+
entirely. The action is called with the raw `FormData` and the schema, and
|
|
113
|
+
nothing is checked, reported or cleared on the way — for a form whose action
|
|
114
|
+
does its own parsing. With no action at all, submitting does nothing.
|
|
115
|
+
|
|
116
|
+
Remember that this object [replaces the defaults rather than merging](../setup.md#validation),
|
|
117
|
+
so pass the keys you still want.
|
|
118
|
+
|
|
119
|
+
## The error summary
|
|
120
|
+
|
|
121
|
+
When a validation fails, two things happen at once: each field is told about its
|
|
122
|
+
own errors, and the form reports a summary. The summary renders only when
|
|
123
|
+
`validation.showError` is on and a component is registered as `alert`; without
|
|
124
|
+
one, the per-field messages are all the user sees.
|
|
125
|
+
|
|
126
|
+
Its three strings — the title, the "correct the errors" description, and the
|
|
127
|
+
title used when an action throws — are
|
|
128
|
+
[shipped translations](../fields/list.md#built-in-translations), so `lang` alone
|
|
129
|
+
localizes them.
|