react-luna-form 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/cjs/index.js +2261 -1
- package/dist/client/esm/index.js +2228 -1
- package/dist/config/cjs/index.js +229 -1
- package/dist/config/esm/index.js +206 -1
- package/dist/server/cjs/index.js +1085 -1
- package/dist/server/esm/index.js +1062 -1
- package/package.json +2 -2
package/dist/client/esm/index.js
CHANGED
|
@@ -1 +1,2228 @@
|
|
|
1
|
-
import{jsx as Ke}from"react/jsx-runtime";function ze(e){return!e.errors||e.errors.length===0?null:Ke("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)=>Ke("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}var re="input",je="input/email",Je="input/number";var Qe="textarea",et="radio",tt="checkbox",nt="select",rt="select/month",ot="select/year";var Fe="column";var it="label",_="value",oe="options",Ne="email",at="number",lt="password",st="tel",Z="text",ct="aria-errormessage",ut="aria-invalid",dt="data-invalid",ft="data-readonly",mt="aria",gt="data",ie="min",ae="max",pt="minLength",yt="maxLength",U="$ref";var bt="source",xt="state",le="http://luna.internal",k="vertical",G="horizontal";function d(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function se(e){return e==null||e===""}function I(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function C(e){return typeof e=="string"}function ht(e){return d(e)&&"url"in e}var kr=/[^/]+$/;function Tt(e,t=[],n=_){if(Array.isArray(t))return t.find(r=>{let o=ke(r,n);if(o!==void 0&&`${o}`===e)return r})??{value:e}}function ke(e,t=_){if(e!=null){if(I(e))return e;if(d(e)){let n=Ir(e,t);if(I(n))return n}}}function Ir(e,t){let n=T(e,t);if(I(n))return n}function Rt(e,t){if(Array.isArray(e))return e;let n=T(e,t);return Array.isArray(n)?n:null}function T(e,t){if(!t||!d(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(d(r)&&o in r)r=r[o];else return null;return r}function St(e,t={label:it,value:_}){return e.map(n=>{if(d(n)){let r=T(n,t.label),o=T(n,t.value);if(I(r)&&I(o))return{label:`${r}`,value:`${o}`}}return n})}function At(e=Z){if(e){let t=e.match(kr);if(t){let[n]=t;if(n!==re)return n.trim().toLowerCase()}}return Z}function Ct(e){let t={};for(let n of e.keys()){let r=e.getAll(n);t[n]=r.length>1?r:r[0]}return t}var vr=/\[([^\]]+)\]\(([^)]+)\)/g;function R(e,t={}){if(C(e))return wr(e,t);if(Array.isArray(e))return e.map(n=>R(n,t));if(d(e)){let n={};for(let r in e)n[r]=R(e[r],t);return n}return e}function w(e){return C(e)?/{([^}]+)}/.test(e):Array.isArray(e)?e.some(t=>w(t)):d(e)?Object.values(e).some(t=>w(t)):!1}function wr(e,t={}){return e.replace(/{([^}]+)}/g,(n,r)=>{let o=r.includes(".")?T(t,r):t[r];return I(o)?String(o):n})}function Et(e,t){if(!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=vr.exec(e))!==null;){let[a,l,s]=n,u=n.index;o=!0,u>r&&i.push(e.substring(r,u));let c=t?t(u,s,l):a;i.push(c),r=u+a.length}return o?(r<e.length&&i.push(e.substring(r)),i):e}var b={error:(...e)=>{Ie()&&!ve()&&ce().error("[Luna Form]",...e)},warn:(...e)=>{Ie()&&!ve()&&ce().warn("[Luna Form]",...e)},info:(...e)=>{Ie()&&!ve()&&ce().info("[Luna Form]",...e)}},Ie=()=>typeof ce()<"u",ve=()=>!0,ce=()=>globalThis.console;function Ft(e=[],t){let n=[],r=[],o=[];e.forEach(i=>{i.action===_&&n.push(i),i.action===bt&&r.push(i),i.action===xt&&o.push(i)}),t({sources:r,states:o,values:n})}function Nt(e=null,t=[],n){t.forEach(r=>{let{target:o,source:i}=r;if(!e){n(o,void 0);return}if(ht(i)){let a=R(i.url,e),l=i.body?R(i.body,e):i.body;n(o,{...i,url:a,body:l})}})}var W={eq:Lr,gt:Gr,gte:Br,in:_r,lt:Yr,lte:Xr,neq:Mr,nin:Ur},Pr=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,kt=/^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;function Or(e){return typeof e=="string"&&Pr.test(e)}function Vr(e){return typeof e=="string"&&kt.test(e)}function Dr(e){let t=e.match(kt);if(t){let[,n,r,o,i,a,l]=t;return new Date(Number(o),Number(r)-1,Number(n),Number(i??0),Number(a??0),Number(l??0)).getTime()}return NaN}function v(e){return Or(e)?new Date(e).getTime():Vr(e)?Dr(e):Number(e)}function Lr(e,t){return e===t}function Mr(e,t){return e!==t}function _r(e,t){return Array.isArray(t)&&t.includes(String(e))}function Ur(e,t){return Array.isArray(t)&&!t.includes(String(e))}function Gr(e,t){return v(e)>v(t)}function Br(e,t){return v(e)>=v(t)}function Yr(e,t){return v(e)<v(t)}function Xr(e,t){return v(e)<=v(t)}function It(e=null,t=[],n){t.forEach(r=>{let{target:o,state:i,when:a}=r;if(!e){n(o);return}let l=Hr(e,a);n(o,l?i:void 0)})}function Hr(e,t){if(t===void 0)return!0;if(C(t))return we(e,"value")===t;if(Array.isArray(t)){let n=we(e,"value");return t.includes(String(n))}return qr(e,t)}function qr(e=null,t){let n=we(e,t.field??"value"),{operator:r="eq",value:o}=t,i=W[r];return i?i(n,o):!1}function we(e,t){return d(e)?t.includes(".")?T(e,t):e[t]:e}function vt(e=null,t=[],n){t.forEach(r=>{Object.entries(r.value).forEach(([o,i])=>{n(o,e?R(i,e):void 0)})})}var ue=e=>S(rt)(e),de=e=>S(ot)(e),x=S(tt),Pe=S(re),E=S(et),F=S(nt),Oe=S(Qe),wt=S(Z,Ne,lt,st),Pt=S(je,Ne),fe=S(Je,at);function me(e){return E(e)||x(e)}function Ot(e){return e.type===Fe}function Vt(e){return e.type!==Fe}function Dt(e){return F(e)||E(e)}function Lt(e){return Pe(e)||Oe(e)}function K(e){return e!=null&&e!==""}function S(...e){return t=>{let n=C(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function Mt(e,t={}){if(F(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&d(n))return[n]}}function _t(e){return E(e)||x(e)?G:e.advanced?.orientation??k}function Ut(e){return x(e)?e.advanced?.reverse!==!1:!1}function Gt(e,t){let n=e.readonly??!1;return t||n}function Bt(e){if(E(e)||F(e)&&!e.disabled){let t=e.source;if(Array.isArray(t)||d(t)&&!(U in t))return t}}var $r=/^\d+$/;function Yt(){return Array.from({length:12},(e,t)=>({value:(t+1).toString(),label:new Date(0,t).toLocaleString("default",{month:"long"})}))}function Xt(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 Ve(){return new Date().getFullYear()}function De(e,t){if(typeof e=="number")return e;let n=t??Ve(),r=e.trim().toLowerCase();if(r.startsWith("current")){let o=r.match(/^current([+-])(\d+)$/);if(o){let[,i,a]=o,l=parseInt(a,10);if(!isNaN(l))return i==="+"?n+l:n-l}return n}return $r.test(r)?parseInt(r,10):n}var ge=Ve();function Zr(e){if(F(e))return Wr(e)}function Wr(e){if(ue(e))return Yt();if(de(e)){let t=e.advanced?.length?.min??ge,n=e.advanced?.length?.max??ge+5;return Xt(De(t,ge),De(n,ge))}}function Ht(e,t=!1){let n={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return Pe(e)?{...n,...Kr(e)}:F(e)?{...n,...zr(e)}:Oe(e)?{...n,...jr(e)}:n}function Kr(e){let t=At(e.type),n={...e,type:t};return{...qt(e),...Jr(n),...wt(n)?$t(n):{},type:t}}function zr(e){let t=Zr(e);return t?{options:t}:{}}function jr(e){return{...qt(e),...$t(e)}}function qt(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Jr(e){return fe(e)?Qr(e):{}}function $t(e){return Zt(e,{min:pt,max:yt})}function Qr(e){return Zt(e,{min:ie,max:ae})}function Zt(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 Wt(e,t){let n=Bt(e);return n||Mt(e,t)}function eo(e,t){let n=d(t)&&e.name in t?t[e.name]:t;return ke(n,e.advanced?.entity)}function to(e,t,n){return Dt(e)&&Array.isArray(n)?{...t,[oe]:n}:t}function no(e,t,n){if(e.required&&!K(n)&&F(e)&&e.advanced?.preselected!==!1&&oe in t){let r=t[oe];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function ro(e,t){return F(e)&&Array.isArray(t)?St(t,e.advanced?.options):t}function Kt(e,t,n,r){let o=eo(e,r),i=Array.isArray(n)?ro(e,n):n,a=to(e,t,i),l=no(e,a,o);return{commonPropsWithOptions:a,defaultValue:l}}function zt(e,t){return x(e)?{checked:K(t)?t:!1}:{value:t??""}}var oo=/^#\/definition\//;function ye(e=[],t){let n=pe(e,t);return Array.isArray(n)?n.sort((r,o)=>jt(r)-jt(o)):[]}function pe(e,t,n=new Map,r=new WeakSet){if(!io(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=>pe(i,t,n,r));if(U in e&&C(e[U])){let i=e[U].replace(oo,""),a=T(t,i);return a!==null?pe(a,t,n,r):e}let o={};for(let[i,a]of Object.entries(e))o[i]=pe(a,t,n,r);return r.delete(e),n.set(e,o),o}function Jt(e){return Object.entries(e??{})}function jt(e){return e.order??Number.MAX_VALUE}function io(e){return e!==void 0&&d(e)&&Object.keys(e).length>0}function Qt(e,t){let n={};for(let[r,o]of Jt(t))n[`${e}-${r}`]=o;return n}function ao(e){return Qt(mt,e)}function lo(e){return Qt(gt,e)}function en(e,t){let n=ao(e.advanced?.aria);return t&&t.length>0&&(n[ut]="true",n[ct]=`${e.name}-error`),n}function tn(e){return lo(e.advanced?.data)}var nn={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},rn={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function on(e,t=2){return nn[e&&e in nn?e:t]}function an(e){if(e&&e in rn)return rn[e]}import{z as f}from"zod";function m(e,t){return e?t?t[e]??e:e:""}var so=[[fe,go],[Pt,co],[de,po],[ue,yo],[x,uo],[E,fo]];function sn(e,t=[],n){let r=f.object(e);return t.length===0?r:To(r,t,n)}function cn(e){let t={},n=f.flattenError(e).fieldErrors;for(let[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t}function un(e,t){for(let[n,r]of so)if(n(e))return r(e,t);return mo(e,t)}function co(e,t){let n=f.string().trim();if(e.required){let r=B(e,t),o=n.min(1,r).pipe(ln(e,t));return f.preprocess(i=>se(i)?"":i,o)}return n.pipe(ln(e,t)).or(f.literal("")).nullable()}function uo(e,t){let n=f.coerce.boolean();return e.required?(n=n.refine(r=>r===!0,{message:B(e,t)}),f.preprocess(r=>r===null?!1:r,n)):n.nullable()}function fo(e,t){let n=f.coerce.string();return e.required?(n=n.min(1,B(e,t)),f.preprocess(r=>se(r)?"":r,n)):n.or(f.literal("")).nullable()}function mo(e,t){let n=f.coerce.string().trim();return n=dn(n,e,t),e.required?(n=fn(n,e,t),f.preprocess(r=>se(r)?"":r,n)):n.nullable()}function go(e,t){let n=f.coerce.number().int();return n=dn(n,e,t),e.required?(n=fn(n,e,t),f.preprocess(r=>r===null?void 0:r,n)):n.nullable()}function po(e,t){return e.required?f.preprocess(bo,f.coerce.number({message:B(e,t)}).int()):f.coerce.number().int().nullable()}function yo(e,t){let n=B(e,t),r=f.coerce.number().int().min(1,n).max(12,n);return e.required?r:r.nullable()}function bo(e){return e===null||e===""?void 0:e}function ln(e,t){let n=e.validation?.email?m(e.validation?.email,t):void 0;return f.email(n)}function dn(e,t,n){return e=xo(e,t,n),e=ho(e,t,n),e}function fn(e,t,n){let r=t.advanced?.length?.min;return r===void 0||r<1?e.min(1,B(t,n)):e}var xo=(e,t,n)=>mn(e,t,ie,n),ho=(e,t,n)=>mn(e,t,ae,n);function mn(e,t,n,r){let o=t.advanced?.length?.[n];if(o!==void 0){let i=t.validation?.length?.[n]?m(t.validation?.length?.[n],r):void 0;return e[n](o,i)}return e}function To(e,t=[],n){let r=So(t);return r.length===0?e:e.superRefine((o,i)=>{for(let{name:a,rule:l}of r)if(!Ro(o,a,l)){let s=m(l.message,n);i.addIssue({code:"custom",message:s,path:[a]})}})}function Ro(e,t,n){let r=n.operator??"eq",o=W[r];return o?o(e[t],e[n.field]):!1}function So(e){let t=[];for(let n of e){let r=n.validation?.custom;if(!r)continue;let o=Array.isArray(r)?r:[r];for(let i of o)t.push({name:n.name,rule:i})}return t}function gn(e,t,n,r){let o=[],i=Array.isArray(t)?t:[t];for(let a of i){let l=a.operator??"eq",s=W[l];if(s&&!s(e,n(a.field))&&a.message){let u=m(a.message,r);o.push(u)}}return o}function B(e,t){return e.validation?.required?m(e.validation?.required,t):void 0}function pn(e,t){if(!t||!Co(e))return!0;if(t.length===0)return!1;try{let n=new URL(e),r=n.protocol.replace(":",""),o=n.hostname,i=n.port||Ao(r);return t.some(a=>!(a.protocol&&a.protocol!==r||a.hostname&&a.hostname!==o||a.port!==void 0&&String(a.port)!==i))}catch{return!1}}function Ao(e){return e==="https"?"443":"80"}function Co(e){return/^(https?:)?\/\//.test(e)}function yn(e,t){try{if(!e)return t;if(!t)return e;let n=new URL(e,le);new URL(t,le).searchParams.forEach((i,a)=>{n.searchParams.set(a,i)});let o=n.toString();return e.startsWith("/")||!e.includes("://")?o.replace(le,""):o}catch{return t||e}}function bn(e){return!Array.isArray(e)||e.length===0?null:e.reduce((t,n)=>{let r=yn(t.url,n.url),o=Eo(t,n),i=Fo(t,n);return{...t,...n,url:r,body:o,headers:i}})}function Eo(e,t){return d(t.body)&&d(e?.body)?{...e.body,...t.body}:t.body??e?.body}function Fo(e,t){return d(t.headers)&&d(e?.headers)?{...e.headers,...t.headers}:t.headers??e?.headers}function be(e,t){return{...e,...t}}import{twMerge as No}from"tailwind-merge";import{jsx as ko}from"react/jsx-runtime";function xe(e){let t=e.errors&&e.errors.length>0;return ko("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[dt]:"true"},...e.disabled&&{[ft]:"true"},"data-orientation":e.orientation,className:No("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 Io}from"tailwind-merge";import{jsx as vo}from"react/jsx-runtime";function xn(e){return vo(xe,{...e,orientation:k,className:Io("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}import{twMerge as wo}from"tailwind-merge";import{jsx as Po}from"react/jsx-runtime";function hn(e){return Po(xe,{...e,orientation:G,className:wo("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 Tn}from"react/jsx-runtime";function Rn(e){let t=me(e.field),n=x(e.field),r=Ut(e.field);return e.orientation===k?Tn(xn,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):Tn(hn,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function Sn(e){if(!e.field.type)return null;let t=Ht(e.field,e.disabled),n=tn(e.field),r=en(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,orientation:e.orientation})}import{twMerge as Oo}from"tailwind-merge";import{jsx as Le,jsxs as Vo}from"react/jsx-runtime";function An(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{orientation:r}=be(e.style,{orientation:_t(e.field)}),o=Gt(e.field,e.disabled);return Vo("div",{className:Oo("flex flex-col gap-3",an(t)),children:[Le(Rn,{disabled:o,errors:n,field:e.field,orientation:r,children:Le(Sn,{disabled:o,errors:n,field:e.field,orientation:r,children:e.children})}),Le(ze,{errors:n,name:e.field.name})]})}import{atom as P}from"jotai";import{atomFamily as Cn}from"jotai-family";import{deepEqual as Me}from"fast-equals";function Do(e){return Cn(t=>P(n=>n(e)[t]??void 0,(n,r,o)=>{let i=n(e);if(o!=null){let a=i[t];(!a||!Me(a,o))&&r(e,{...i,[t]:o})}else if(i[t]){let{[t]:a,...l}=i;r(e,l)}}))}function Lo(e){return P(null,(t,n)=>{let r=t(e);r&&Object.keys(r).length>0&&n(e,{})})}function Mo(e){return P(null,(t,n,r)=>{let i={...t(e)},a=!1;for(let l of r)i[l]&&(delete i[l],a=!0);a&&n(e,i)})}function _o(e){return P(null,(t,n,r)=>{let o=t(e);Me(o,r)||n(e,r)})}function En(e,t={}){let{merge:n,validateTarget:r}=t;return Cn(o=>P(i=>{let a=i(e)[o];if(a&&n)return n(Object.values(a))},(i,a,l,s)=>{if(r&&!r(l))return;let u=i(e),c={...u[l]??{}};if(s!=null){let y=c[o];(!y||!Me(y,s))&&(c[o]=s,a(e,{...u,[l]:c}))}else if(c[o])if(delete c[o],Object.keys(c).length===0){let{[l]:y,...N}=u;a(e,N)}else a(e,{...u,[l]:c})}))}function Fn(e){return P(null,(t,n,r)=>{let i={...t(e)},a=!1;for(let l of r)i[l]&&(delete i[l],a=!0);for(let l in i){let s={...i[l]},u=!1;for(let c of r)s[c]&&(delete s[c],u=!0,a=!0);u&&(Object.keys(s).length===0?delete i[l]:i[l]=s)}a&&n(e,i)})}function Y(e={}){let t=P(e);return{atom:t,clearAll:Lo(t),clear:Mo(t),bulkReport:_o(t),report:Do(t)}}var _e=Y(),Nn=_e.clear,kn=_e.bulkReport,he=_e.report;import{useAtomValue as Uo}from"jotai";import{jsx as Go}from"react/jsx-runtime";function In(e){return n=>{let r=Uo(he(n.field.name));return Go(e,{...n,errors:r?{[n.field.name]:r}:void 0})}}var vn=Y(),wn=vn.atom,Pn=vn.report;import{useAtomValue as Bo}from"jotai";import{jsx as Yo}from"react/jsx-runtime";function On(e){return n=>{let r=Bo(Pn(n.field.name));if(r?.hidden??n.field.hidden??!1)return null;let i=r?.disabled??n.disabled;return Yo(e,{...n,disabled:i})}}var Vn=On(In(An));import{jsx as Xo}from"react/jsx-runtime";function Dn(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return Xo("div",{"data-slot":"field-control",className:"w-full",children:t})}import{jsx as Ho}from"react/jsx-runtime";function z(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 qo}from"react/jsx-runtime";function j(e){return Et(e,(t,n,r)=>qo("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}import{Fragment as $o,jsx as Ln,jsxs as Zo}from"react/jsx-runtime";function Mn(e){return Zo($o,{children:[e.title&&Ln("legend",{className:"mb-3 font-medium text-slate-800 dark:text-slate-200",children:j(e.title)}),e.description&&Ln("p",{className:"-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:j(e.description)})]})}import{jsx as Ue,jsxs as Wo}from"react/jsx-runtime";function _n(e){let t=e.section.fields||[],{compact:n}=be(e.style,{compact:e.section.compact});return!e.section.title&&!e.section.description?Ue(z,{compact:n,children:e.children}):Wo("fieldset",{"data-slot":"field-set","data-empty":t.length===0,className:"flex flex-col data-[empty=false]:gap-6",id:e.section.id?.toString(),children:[Ue(Mn,{description:e.section.description,title:e.section.title}),Ue(z,{compact:n,children:e.children})]})}import{Fragment as Ko}from"react";import{jsx as Un}from"react/jsx-runtime";function Gn(){return Un("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:Un("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800"})})}import{jsx as J,jsxs as Bn}from"react/jsx-runtime";function Yn(e){let t=ye(e.sections,e.definition);return J("div",{className:"h-full w-full",children:J("form",{noValidate:e.noValidate,action:e.action,children:Bn(z,{children:[t.map((n,r)=>Bn(Ko,{children:[J(_n,{section:n,style:e.config.style,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.separator&&J(Gn,{})]},r)),e.control&&J(Dn,{isPending:e.isPending,children:e.control})]})})})}import{jsx as zo}from"react/jsx-runtime";function Xn(e){return zo("p",{className:"-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400",children:e.children})}import{jsx as jo}from"react/jsx-runtime";function Te(e){let t=j(e.text);return t?jo(Xn,{children:t}):null}import{twMerge as Jo}from"tailwind-merge";import{jsx as Qo,jsxs as ei}from"react/jsx-runtime";function Hn(e){let t=e.style?.showOptionalLabel??!0,n=E(e.field)||x(e.field);return ei("label",{"data-slot":"field-label","data-normal":n,className:Jo("flex w-fit items-center gap-2 text-sm leading-snug font-medium select-none","data-[normal=true]:font-normal","group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"),htmlFor:e.field.name,children:[e.children,t&&!e.field.required&&Qo("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:m("(Optional)",e.translations)})]})}import{jsx as qn,jsxs as ti}from"react/jsx-runtime";function $n(e){let t=w(e.field.label)?R(e.field.label,{context:e.context,env:e.config?.env}):e.field.label,n=w(e.field.description)?R(e.field.description,{context:e.context,env:e.config?.env}):e.field.description;return ti("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[qn(Hn,{field:e.field,style:e.config?.style,translations:e.translations,children:m(t,e.translations)}),e.orientation===G&&qn(Te,{text:m(n,e.translations)})]})}import{Fragment as ni,jsx as Zn,jsxs as ri}from"react/jsx-runtime";function Wn(e){return ri(ni,{children:[e.field.name&&e.field.label&&Zn($n,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations}),e.children,e.orientation===k&&e.field.description&&Zn(Te,{text:m(e.field.description,e.translations)})]})}function Re(e,t){return e?t(e):null}import{useCallback as Ce,useRef as Ge,useTransition as hi}from"react";import{atom as oi}from"jotai";var ii=e=>{let t=bn(e);if(t)return t},ai=e=>e.trim()!=="",Kn=oi({}),zn=En(Kn,{merge:ii,validateTarget:ai}),jn=Fn(Kn);import{useAtom as ci}from"jotai";import li from"swr";function Jn(e=null,t,n=!1){let{data:r,error:o}=li(si(e,t,n),t.fetcher.provider);if(o&&b.error("Error fetching data source:",o),e){if(Array.isArray(e))return e;if(r)return Rt(r,e.namespace)}return null}function si(e=null,t,n=!1){if(e&&!Array.isArray(e)&&!n&&e.url&&!w(e.url)){if(pn(e.url,t.fetcher.remotePatterns))return e;b.warn(`URL blocked by remotePatterns: ${e.url}. Check your luna.config.ts`)}return null}function Qn(e,t,n){let r=Wt(e,n),[o,i]=ci(zn(e.name));return[Jn(o??r,t,e.disabled),i]}import{useEffect as ui,useEffectEvent as er,useMemo as di}from"react";function tr(e,t,n,r){let{name:o}=e,i=di(()=>un(e,r),[e,r]),a=er(s=>{s&&t(s,i,e)}),l=er(s=>{s&&n(s)});return ui(()=>(a(o),()=>{l(o)}),[o]),i}import{useSetAtom as Be,useStore as Ti}from"jotai";import{useCallback as fi,useEffect as mi,useRef as gi}from"react";function nr(){let e=gi(null);mi(()=>()=>{e.current&&clearTimeout(e.current)},[]);function t(){e.current&&(clearTimeout(e.current),e.current=null)}return fi((r,o)=>{t(),e.current=setTimeout(r,o)},[])}var Se=Y(),rr=Se.atom,or=Se.clearAll,ir=Se.clear,Ae=Se.report;import{useAtom as pi}from"jotai";import{useCallback as yi,useEffect as bi,useRef as xi}from"react";function ar(e,t){let{name:n}=e,r=xi(!1),[o,i]=pi(Ae(n));bi(()=>{if(!t||!(n in t))return;let l=t[n];K(l)&&(b.info("useValue: setting skipNextOnChange to true",{fieldName:n,newValue:l}),r.current=!0,i(l))},[n,t,i]);let a=yi(()=>r.current?(r.current=!1,!0):!1,[]);return{setValue:i,shouldSkipOnChange:a,value:o}}import{jsx as lr}from"react/jsx-runtime";function sr(e){let t=e.field.advanced?.entity,n=Ti(),r=nr(),[,o]=hi(),{setValue:i,shouldSkipOnChange:a,value:l}=ar(e.field,e.value),s=Ge(l);s.current=l;let u=Ge(e.translations);u.current=e.translations;let c=Lt(e.field),y=me(e.field),N=Be(rr),X=Be(wn),ee=Be(he(e.field.name)),[H,O]=Qn(e.field,e.config,l),A=tr(e.field,e.onMount,e.onUnmount,e.translations),q=m(e.commonProps.placeholder,e.translations),h={...e.commonProps,placeholder:q},{commonPropsWithOptions:Rr,defaultValue:Sr}=Kt(e.field,h,H,l),Ze=Ge(null);Ze.current=g=>{i(g),e.onValueChange&&e.onValueChange({name:e.field.name,value:g})};let Ar=zt(e.field,Sr),te=Ce(g=>{let V=A.safeParse(g).error?.issues.map($=>$.message)??[],D=e.field.validation?.custom,Ee=D?gn(g,D,$=>n.get(Ae($)),u.current):[];ee([...V,...Ee])},[e.field.validation?.custom,A,ee,n]),We=Ce((g,p)=>{if(c){r(()=>{p({value:g})},500);return}let V=Tt(g,H,t);p(V)},[H,t,c,r]),Cr=Ce(g=>{let p=g.target.value;if(b.info("onChange fired",{fieldName:e.field.name,fieldType:e.field.type,inputValue:p,currentValue:s.current,hasTextable:c,hasClickable:y}),a()&&(b.info("shouldSkipOnChange returned true",{fieldName:e.field.name,willSkip:!c||p===s.current,reason:c?"value unchanged":"not textable (checkbox/radio/select)"}),!c||p===s.current)){b.info("SKIPPING onChange",{fieldName:e.field.name});return}b.info("onChange processing",{fieldName:e.field.name,inputValue:p}),Ze.current?.(p),e.config.validation.change&&te(p);let V=e.field.event?.change;V&&We(p,D=>{Ft(V,({sources:Ee,states:$,values:Fr})=>{o(()=>{Nt(D,Ee,(L,M)=>O(L,M)),It(D,$,(L,M)=>{X(ne=>{if(M)return{...ne,[L]:M};let{[L]:Vi,...Nr}=ne;return Nr})}),vt(D,Fr,(L,M)=>{N(ne=>({...ne,[L]:M}))})})})})},[We,y,c,e.config.validation.change,e.field.event?.change,e.field.name,e.field.type,X,O,N,a,te]),Er=Ce(g=>{if(!y){let p=g.target.value;e.config.validation.blur&&te(p)}},[y,e.config.validation.blur,te]);return Re(e.config.inputs[e.field.type],g=>lr(Wn,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations,children:lr(g,{...Rr,...e.ariaAttributes,...e.dataAttributes,...Ar,onBlur:Er,onChange:Cr})}))}import{twMerge as Ri}from"tailwind-merge";import{jsx as cr}from"react/jsx-runtime";function ur(e){let t=on(e.column?.advanced?.cols);return cr("div",{className:"flex w-full flex-col gap-4",children:cr("div",{className:Ri("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children})})}import{Fragment as Si}from"react";import{jsx as Ye,jsxs as Ai}from"react/jsx-runtime";function Xe(e){let{column:t,field:n}=e.components;return ye(e.fields).map((r,o)=>Ai(Si,{children:[Ot(r)&&Ye(t,{column:r,children:Ye(Xe,{...e,fields:r.fields})}),Vt(r)&&Ye(n,{disabled:e.disabled,field:r,style:e.style,children:e.children})]},o))}import{jsx as Ci}from"react/jsx-runtime";function dr(e){return n=>Ci(Xe,{...n,components:{column:ur,field:e}})}import{useSetAtom as fr}from"jotai";import{startTransition as mr,useActionState as Ei}from"react";function pr(e,t,n){let{onSuccess:r,preserveValues:o=!1,validation:i=!0}=n??{},a=fr(kn),l=fr(or),s={data:null,error:null,success:!1},[u,c,y]=Ei(async(N,X)=>{let[ee,H]=e(),O=sn(ee,H,n?.translations);if(i===!1)return t?await t(X,O):N;let A=Ct(X),q=O.safeParse(A);if(!q.success){let h=cn(q.error);return mr(()=>{a(h)}),He(A,{description:"Please correct the errors and try again.",details:[],title:"There were validation errors submitting the form."})}if(t)try{let h=await t(A,O);return h.success?(r?.(h.data),o||mr(()=>{l()}),gr(A,o)):He(A,h.error)}catch(h){return b.error("Error executing form action:",h),He(A,{title:"An unexpected error occurred submitting the form.",details:Fi(h)})}return gr(q.data,o)},s);return[c,u,y]}function Fi(e){let t=e instanceof Error?e.message:["Unknown error"];return Array.isArray(t)?t:[t]}function gr(e,t=!1){return{data:t?e:null,error:null,success:!0}}function He(e,t){return{data:e,error:t,success:!1}}import{startTransition as ki,useCallback as br,useRef as $e}from"react";import{useCallback as Ni}from"react";import{useSetAtom as qe}from"jotai";function yr(){let e=qe(Nn),t=qe(jn),n=qe(ir);return Ni(r=>{let o=Array.isArray(r)?r:[r];e(o),t(o),n(o)},[e,t,n])}function xr(){let e=yr(),t=$e({}),n=$e([]),r=$e(new Set),o=br((l,s,u)=>{l in t.current||(t.current[l]=s,n.current.push(u))},[]),i=br(l=>{t.current[l]&&(delete t.current[l],n.current=n.current.filter(s=>s.name!==l),r.current.add(l),ki(()=>{r.current.size>0&&(e(Array.from(r.current)),r.current.clear())}))},[e]);function a(){return[t.current,n.current]}return[a,o,i]}import{Fragment as vi,jsx as Q,jsxs as wi}from"react/jsx-runtime";var Ii=dr(Vn);function hr(e){let t=e.translations?.[e.lang??""],[n,r,o]=xr(),[i,a,l]=pr(n,e.action,{onSuccess:e.onSuccess,validation:e.config.validation.submit,translations:t}),s=e.config.validation.showError&&!a.success&&a.error,u=a.data??e.value;return wi(vi,{children:[s&&Re(e.config.alert,c=>Q("div",{className:"mb-4 w-full",children:Q(c,{description:a.error?.description,details:a.error?.details,title:a.error.title})})),Q(Yn,{action:i,config:e.config,control:e.children,definition:e.definition,isPending:l,noValidate:!0,readOnly:e.readOnly,sections:e.sections,children:({disabled:c,fields:y})=>Q(Ii,{disabled:c,fields:y,style:e.config.style,children:N=>Q(sr,{...N,config:e.config,context:e.context,onMount:r,onUnmount:o,onValueChange:e.onValueChange,translations:t,value:u})})})]})}import{Provider as Pi}from"jotai";import{jsx as Tr}from"react/jsx-runtime";function Oi(e){return Tr(Pi,{children:Tr(hr,{...e})})}export{Oi as Form};
|
|
1
|
+
// src/component/field/field-error.tsx
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
function FieldError(props) {
|
|
4
|
+
if (!props.errors || props.errors.length === 0) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
|
+
"ul",
|
|
9
|
+
{
|
|
10
|
+
className: "text-sm text-red-600 dark:text-red-500",
|
|
11
|
+
id: props.name ? `${props.name}-error` : void 0,
|
|
12
|
+
children: props.errors?.map((error, index) => /* @__PURE__ */ jsx("li", { children: error }, props.name ? `${props.name}-error-${index}` : index))
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ../luna-core/src/util/constant.ts
|
|
18
|
+
var INPUT = "input";
|
|
19
|
+
var INPUT_EMAIL = "input/email";
|
|
20
|
+
var INPUT_NUMBER = "input/number";
|
|
21
|
+
var TEXTAREA = "textarea";
|
|
22
|
+
var RADIO = "radio";
|
|
23
|
+
var CHECKBOX = "checkbox";
|
|
24
|
+
var SELECT = "select";
|
|
25
|
+
var SELECT_MONTH = "select/month";
|
|
26
|
+
var SELECT_YEAR = "select/year";
|
|
27
|
+
var COLUMN = "column";
|
|
28
|
+
var LABEL = "label";
|
|
29
|
+
var VALUE = "value";
|
|
30
|
+
var OPTIONS = "options";
|
|
31
|
+
var TYPE_EMAIL = "email";
|
|
32
|
+
var TYPE_NUMBER = "number";
|
|
33
|
+
var TYPE_PASSWORD = "password";
|
|
34
|
+
var TYPE_TEL = "tel";
|
|
35
|
+
var TYPE_TEXT = "text";
|
|
36
|
+
var ARIA_ERROR_MESSAGE = "aria-errormessage";
|
|
37
|
+
var ARIA_INVALID = "aria-invalid";
|
|
38
|
+
var DATA_INVALID = "data-invalid";
|
|
39
|
+
var DATA_READONLY = "data-readonly";
|
|
40
|
+
var PREFIX_ARIA = "aria";
|
|
41
|
+
var PREFIX_DATA = "data";
|
|
42
|
+
var MIN = "min";
|
|
43
|
+
var MAX = "max";
|
|
44
|
+
var MIN_LENGTH = "minLength";
|
|
45
|
+
var MAX_LENGTH = "maxLength";
|
|
46
|
+
var $REF = "$ref";
|
|
47
|
+
var SOURCE = "source";
|
|
48
|
+
var STATE = "state";
|
|
49
|
+
var COMMON_URL = "http://luna.internal";
|
|
50
|
+
var VERTICAL = "vertical";
|
|
51
|
+
var HORIZONTAL = "horizontal";
|
|
52
|
+
|
|
53
|
+
// ../luna-core/src/util/is-type.ts
|
|
54
|
+
function isObject(value) {
|
|
55
|
+
return value !== null && Object.prototype.toString.call(value) === "[object Object]";
|
|
56
|
+
}
|
|
57
|
+
function isEmpty(value) {
|
|
58
|
+
return value === null || value === void 0 || value === "";
|
|
59
|
+
}
|
|
60
|
+
function isValue(value) {
|
|
61
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
62
|
+
}
|
|
63
|
+
function isString(value) {
|
|
64
|
+
return typeof value === "string";
|
|
65
|
+
}
|
|
66
|
+
function isDataSource(value) {
|
|
67
|
+
return isObject(value) && "url" in value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ../luna-core/src/util/extract.ts
|
|
71
|
+
var REGEX_TYPE = /[^/]+$/;
|
|
72
|
+
function getEntity(selected, collection = [], entity = VALUE) {
|
|
73
|
+
if (Array.isArray(collection)) {
|
|
74
|
+
return collection.find((item) => {
|
|
75
|
+
const current = getCurrentValue(item, entity);
|
|
76
|
+
if (current !== void 0 && `${current}` === selected) {
|
|
77
|
+
return item;
|
|
78
|
+
}
|
|
79
|
+
}) ?? { value: selected };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getCurrentValue(value, entity = VALUE) {
|
|
83
|
+
if (value !== null && value !== void 0) {
|
|
84
|
+
if (isValue(value)) {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
if (isObject(value)) {
|
|
88
|
+
const result = getValue(value, entity);
|
|
89
|
+
if (isValue(result)) {
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function getValue(value, namespace) {
|
|
96
|
+
const result = extract(value, namespace);
|
|
97
|
+
if (isValue(result)) {
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getArray(value, namespace) {
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
const result = extract(value, namespace);
|
|
106
|
+
if (Array.isArray(result)) {
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function extract(value, namespace) {
|
|
112
|
+
if (!namespace || !isObject(value)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const keys = namespace.split(".").filter((key) => key !== "");
|
|
116
|
+
if (keys.length === 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
let result = value;
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
if (isObject(result) && key in result) {
|
|
122
|
+
const obj = result;
|
|
123
|
+
result = obj[key];
|
|
124
|
+
} else {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function toOptions(data, options = { label: LABEL, value: VALUE }) {
|
|
131
|
+
return data.map((item) => {
|
|
132
|
+
if (isObject(item)) {
|
|
133
|
+
const label = extract(item, options.label);
|
|
134
|
+
const value = extract(item, options.value);
|
|
135
|
+
if (isValue(label) && isValue(value)) {
|
|
136
|
+
return {
|
|
137
|
+
label: `${label}`,
|
|
138
|
+
value: `${value}`
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return item;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function getType(value = TYPE_TEXT) {
|
|
146
|
+
if (value) {
|
|
147
|
+
const result = value.match(REGEX_TYPE);
|
|
148
|
+
if (result) {
|
|
149
|
+
const [type] = result;
|
|
150
|
+
if (type !== INPUT) {
|
|
151
|
+
return type.trim().toLowerCase();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return TYPE_TEXT;
|
|
156
|
+
}
|
|
157
|
+
function getFormData(formData) {
|
|
158
|
+
const data = {};
|
|
159
|
+
for (const key of formData.keys()) {
|
|
160
|
+
const values = formData.getAll(key);
|
|
161
|
+
data[key] = values.length > 1 ? values : values[0];
|
|
162
|
+
}
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ../luna-core/src/util/string.ts
|
|
167
|
+
var REGEX_MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
168
|
+
function interpolate(template, values = {}) {
|
|
169
|
+
if (isString(template)) {
|
|
170
|
+
return replacePlaceholders(template, values);
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(template)) {
|
|
173
|
+
return template.map((item) => {
|
|
174
|
+
return interpolate(item, values);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (isObject(template)) {
|
|
178
|
+
const results = {};
|
|
179
|
+
for (const key in template) {
|
|
180
|
+
results[key] = interpolate(template[key], values);
|
|
181
|
+
}
|
|
182
|
+
return results;
|
|
183
|
+
}
|
|
184
|
+
return template;
|
|
185
|
+
}
|
|
186
|
+
function isInterpolated(template) {
|
|
187
|
+
if (isString(template)) {
|
|
188
|
+
return /{([^}]+)}/.test(template);
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(template)) {
|
|
191
|
+
return template.some((item) => isInterpolated(item));
|
|
192
|
+
}
|
|
193
|
+
if (isObject(template)) {
|
|
194
|
+
return Object.values(template).some((value) => isInterpolated(value));
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
function replacePlaceholders(template, values = {}) {
|
|
199
|
+
return template.replace(/{([^}]+)}/g, (match, key) => {
|
|
200
|
+
const value = key.includes(".") ? extract(values, key) : values[key];
|
|
201
|
+
if (isValue(value)) {
|
|
202
|
+
return String(value);
|
|
203
|
+
}
|
|
204
|
+
return match;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function formatMarkdown(text, callback) {
|
|
208
|
+
if (!text || text.trim().length === 0) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
let match;
|
|
212
|
+
let lastIndex = 0;
|
|
213
|
+
let hasMatch = false;
|
|
214
|
+
const parts = [];
|
|
215
|
+
while ((match = REGEX_MARKDOWN_LINK.exec(text)) !== null) {
|
|
216
|
+
const [fullMatch, linkText, url] = match;
|
|
217
|
+
const index = match.index;
|
|
218
|
+
hasMatch = true;
|
|
219
|
+
if (index > lastIndex) {
|
|
220
|
+
parts.push(text.substring(lastIndex, index));
|
|
221
|
+
}
|
|
222
|
+
const value = callback ? callback(index, url, linkText) : fullMatch;
|
|
223
|
+
parts.push(value);
|
|
224
|
+
lastIndex = index + fullMatch.length;
|
|
225
|
+
}
|
|
226
|
+
if (!hasMatch) {
|
|
227
|
+
return text;
|
|
228
|
+
}
|
|
229
|
+
if (lastIndex < text.length) {
|
|
230
|
+
parts.push(text.substring(lastIndex));
|
|
231
|
+
}
|
|
232
|
+
return parts;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ../luna-core/src/util/logger.ts
|
|
236
|
+
var logger = {
|
|
237
|
+
error: (...args) => {
|
|
238
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
239
|
+
getConsole().error("[Luna Form]", ...args);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
warn: (...args) => {
|
|
243
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
244
|
+
getConsole().warn("[Luna Form]", ...args);
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
info: (...args) => {
|
|
248
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
249
|
+
getConsole().info("[Luna Form]", ...args);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var isConsoleAvailable = () => typeof getConsole() !== "undefined";
|
|
254
|
+
var isProduction = () => false;
|
|
255
|
+
var getConsole = () => globalThis.console;
|
|
256
|
+
|
|
257
|
+
// ../luna-core/src/handle/proxy-event.ts
|
|
258
|
+
function handleProxyEvent(events = [], callback) {
|
|
259
|
+
const values = [];
|
|
260
|
+
const sources = [];
|
|
261
|
+
const states = [];
|
|
262
|
+
events.forEach((event) => {
|
|
263
|
+
if (event.action === VALUE) {
|
|
264
|
+
values.push(event);
|
|
265
|
+
}
|
|
266
|
+
if (event.action === SOURCE) {
|
|
267
|
+
sources.push(event);
|
|
268
|
+
}
|
|
269
|
+
if (event.action === STATE) {
|
|
270
|
+
states.push(event);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
callback({ sources, states, values });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ../luna-core/src/handle/source-event.ts
|
|
277
|
+
function handleSourceEvent(selected = null, events = [], setSource) {
|
|
278
|
+
events.forEach((event) => {
|
|
279
|
+
const { target, source } = event;
|
|
280
|
+
if (!selected) {
|
|
281
|
+
setSource(target, void 0);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (isDataSource(source)) {
|
|
285
|
+
const newUrl = interpolate(source.url, selected);
|
|
286
|
+
const newBody = source.body ? interpolate(source.body, selected) : source.body;
|
|
287
|
+
setSource(target, {
|
|
288
|
+
...source,
|
|
289
|
+
url: newUrl,
|
|
290
|
+
body: newBody
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ../luna-core/src/util/operator.ts
|
|
297
|
+
var operators = {
|
|
298
|
+
eq,
|
|
299
|
+
gt,
|
|
300
|
+
gte,
|
|
301
|
+
in: includes,
|
|
302
|
+
lt,
|
|
303
|
+
lte,
|
|
304
|
+
neq,
|
|
305
|
+
nin
|
|
306
|
+
};
|
|
307
|
+
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/;
|
|
308
|
+
var DMY_DATE_REGEX = /^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
309
|
+
function isISODateString(value) {
|
|
310
|
+
return typeof value === "string" && ISO_DATE_REGEX.test(value);
|
|
311
|
+
}
|
|
312
|
+
function isDMYDateString(value) {
|
|
313
|
+
return typeof value === "string" && DMY_DATE_REGEX.test(value);
|
|
314
|
+
}
|
|
315
|
+
function parseDMYDate(value) {
|
|
316
|
+
const match = value.match(DMY_DATE_REGEX);
|
|
317
|
+
if (match) {
|
|
318
|
+
const [, day, month, year, hours, minutes, seconds] = match;
|
|
319
|
+
return new Date(
|
|
320
|
+
Number(year),
|
|
321
|
+
Number(month) - 1,
|
|
322
|
+
Number(day),
|
|
323
|
+
Number(hours ?? 0),
|
|
324
|
+
Number(minutes ?? 0),
|
|
325
|
+
Number(seconds ?? 0)
|
|
326
|
+
).getTime();
|
|
327
|
+
}
|
|
328
|
+
return NaN;
|
|
329
|
+
}
|
|
330
|
+
function toComparableNumber(value) {
|
|
331
|
+
if (isISODateString(value)) {
|
|
332
|
+
return new Date(value).getTime();
|
|
333
|
+
}
|
|
334
|
+
if (isDMYDateString(value)) {
|
|
335
|
+
return parseDMYDate(value);
|
|
336
|
+
}
|
|
337
|
+
return Number(value);
|
|
338
|
+
}
|
|
339
|
+
function eq(current, value) {
|
|
340
|
+
return current === value;
|
|
341
|
+
}
|
|
342
|
+
function neq(current, value) {
|
|
343
|
+
return current !== value;
|
|
344
|
+
}
|
|
345
|
+
function includes(current, value) {
|
|
346
|
+
return Array.isArray(value) && value.includes(String(current));
|
|
347
|
+
}
|
|
348
|
+
function nin(current, value) {
|
|
349
|
+
return Array.isArray(value) && !value.includes(String(current));
|
|
350
|
+
}
|
|
351
|
+
function gt(current, value) {
|
|
352
|
+
return toComparableNumber(current) > toComparableNumber(value);
|
|
353
|
+
}
|
|
354
|
+
function gte(current, value) {
|
|
355
|
+
return toComparableNumber(current) >= toComparableNumber(value);
|
|
356
|
+
}
|
|
357
|
+
function lt(current, value) {
|
|
358
|
+
return toComparableNumber(current) < toComparableNumber(value);
|
|
359
|
+
}
|
|
360
|
+
function lte(current, value) {
|
|
361
|
+
return toComparableNumber(current) <= toComparableNumber(value);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// ../luna-core/src/handle/state-event.ts
|
|
365
|
+
function handleStateEvent(selected = null, events = [], setState) {
|
|
366
|
+
events.forEach((event) => {
|
|
367
|
+
const { target, state, when } = event;
|
|
368
|
+
if (!selected) {
|
|
369
|
+
setState(target);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const matches = evaluateCondition(selected, when);
|
|
373
|
+
setState(target, matches ? state : void 0);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function evaluateCondition(selected, when) {
|
|
377
|
+
if (when === void 0) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
if (isString(when)) {
|
|
381
|
+
return getValue2(selected, "value") === when;
|
|
382
|
+
}
|
|
383
|
+
if (Array.isArray(when)) {
|
|
384
|
+
const current = getValue2(selected, "value");
|
|
385
|
+
return when.includes(String(current));
|
|
386
|
+
}
|
|
387
|
+
return evaluateOperator(selected, when);
|
|
388
|
+
}
|
|
389
|
+
function evaluateOperator(selected = null, condition) {
|
|
390
|
+
const current = getValue2(selected, condition.field ?? "value");
|
|
391
|
+
const { operator = "eq", value } = condition;
|
|
392
|
+
const operation = operators[operator];
|
|
393
|
+
if (operation) {
|
|
394
|
+
return operation(current, value);
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
function getValue2(selected, field) {
|
|
399
|
+
if (isObject(selected)) {
|
|
400
|
+
return field.includes(".") ? extract(selected, field) : selected[field];
|
|
401
|
+
}
|
|
402
|
+
return selected;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ../luna-core/src/handle/value-event.ts
|
|
406
|
+
function handleValueEvent(selected = null, events = [], setValue) {
|
|
407
|
+
events.forEach((event) => {
|
|
408
|
+
Object.entries(event.value).forEach(([target, value]) => {
|
|
409
|
+
setValue(target, selected ? interpolate(value, selected) : void 0);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ../luna-core/src/util/is-input.ts
|
|
415
|
+
var isSelectMonth = (field) => createTypeChecker(SELECT_MONTH)(field);
|
|
416
|
+
var isSelectYear = (field) => createTypeChecker(SELECT_YEAR)(field);
|
|
417
|
+
var isCheckbox = createTypeChecker(CHECKBOX);
|
|
418
|
+
var isInput = createTypeChecker(INPUT);
|
|
419
|
+
var isRadio = createTypeChecker(RADIO);
|
|
420
|
+
var isSelect = createTypeChecker(SELECT);
|
|
421
|
+
var isTextArea = createTypeChecker(TEXTAREA);
|
|
422
|
+
var isText = createTypeChecker(
|
|
423
|
+
TYPE_TEXT,
|
|
424
|
+
TYPE_EMAIL,
|
|
425
|
+
TYPE_PASSWORD,
|
|
426
|
+
TYPE_TEL
|
|
427
|
+
);
|
|
428
|
+
var isEmail = createTypeChecker(INPUT_EMAIL, TYPE_EMAIL);
|
|
429
|
+
var isNumber = createTypeChecker(INPUT_NUMBER, TYPE_NUMBER);
|
|
430
|
+
function isClickable(field) {
|
|
431
|
+
return isRadio(field) || isCheckbox(field);
|
|
432
|
+
}
|
|
433
|
+
function isColumn(slot) {
|
|
434
|
+
return slot.type === COLUMN;
|
|
435
|
+
}
|
|
436
|
+
function isField(slot) {
|
|
437
|
+
return slot.type !== COLUMN;
|
|
438
|
+
}
|
|
439
|
+
function isOptions(field) {
|
|
440
|
+
return isSelect(field) || isRadio(field);
|
|
441
|
+
}
|
|
442
|
+
function isTextable(field) {
|
|
443
|
+
return isInput(field) || isTextArea(field);
|
|
444
|
+
}
|
|
445
|
+
function isValidValue(value) {
|
|
446
|
+
return value !== void 0 && value !== null && value !== "";
|
|
447
|
+
}
|
|
448
|
+
function createTypeChecker(...types) {
|
|
449
|
+
return (field) => {
|
|
450
|
+
const inputType = isString(field.type) ? field.type : void 0;
|
|
451
|
+
if (!inputType) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
return types.some((type) => {
|
|
455
|
+
return inputType === type || inputType?.startsWith(`${type}/`);
|
|
456
|
+
});
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ../luna-core/src/util/build.ts
|
|
461
|
+
function buildOptions(field, values = {}) {
|
|
462
|
+
if (isSelect(field) && field.disabled) {
|
|
463
|
+
const current = field.name ? values?.[field.name] : void 0;
|
|
464
|
+
if (current && isObject(current)) {
|
|
465
|
+
return [current];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function buildOrientation(field) {
|
|
470
|
+
if (isRadio(field) || isCheckbox(field)) {
|
|
471
|
+
return HORIZONTAL;
|
|
472
|
+
}
|
|
473
|
+
return field.advanced?.orientation ?? VERTICAL;
|
|
474
|
+
}
|
|
475
|
+
function buildReverse(field) {
|
|
476
|
+
if (!isCheckbox(field)) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
return field.advanced?.reverse !== false;
|
|
480
|
+
}
|
|
481
|
+
function buildDisabled(field, disabled) {
|
|
482
|
+
const readonly = field.readonly ?? false;
|
|
483
|
+
return disabled ? disabled : readonly;
|
|
484
|
+
}
|
|
485
|
+
function buildSource(field) {
|
|
486
|
+
if (isRadio(field) || isSelect(field) && !field.disabled) {
|
|
487
|
+
const source = field.source;
|
|
488
|
+
if (Array.isArray(source) || isObject(source) && !($REF in source)) {
|
|
489
|
+
return source;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ../luna-core/src/util/date.ts
|
|
495
|
+
var REGEX_DIGITS = /^\d+$/;
|
|
496
|
+
function getMonth() {
|
|
497
|
+
return Array.from({ length: 12 }, (_, i) => ({
|
|
498
|
+
value: (i + 1).toString(),
|
|
499
|
+
label: new Date(0, i).toLocaleString("default", {
|
|
500
|
+
month: "long"
|
|
501
|
+
})
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
504
|
+
function getYear(min2, max2) {
|
|
505
|
+
if (max2 >= min2) {
|
|
506
|
+
return Array.from({ length: max2 - min2 + 1 }, (_, i) => {
|
|
507
|
+
const year = min2 + i;
|
|
508
|
+
return {
|
|
509
|
+
value: year.toString(),
|
|
510
|
+
label: year.toString()
|
|
511
|
+
};
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
function getCurrentYear() {
|
|
517
|
+
return (/* @__PURE__ */ new Date()).getFullYear();
|
|
518
|
+
}
|
|
519
|
+
function getConvert(value, current) {
|
|
520
|
+
if (typeof value === "number") {
|
|
521
|
+
return value;
|
|
522
|
+
}
|
|
523
|
+
const now2 = current ?? getCurrentYear();
|
|
524
|
+
const trimmed = value.trim().toLowerCase();
|
|
525
|
+
if (trimmed.startsWith("current")) {
|
|
526
|
+
const match = trimmed.match(/^current([+-])(\d+)$/);
|
|
527
|
+
if (match) {
|
|
528
|
+
const [, operator, offsetStr] = match;
|
|
529
|
+
const offset = parseInt(offsetStr, 10);
|
|
530
|
+
if (!isNaN(offset)) {
|
|
531
|
+
return operator === "+" ? now2 + offset : now2 - offset;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return now2;
|
|
535
|
+
}
|
|
536
|
+
if (REGEX_DIGITS.test(trimmed)) {
|
|
537
|
+
return parseInt(trimmed, 10);
|
|
538
|
+
}
|
|
539
|
+
return now2;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// ../luna-core/src/helper/input.ts
|
|
543
|
+
var now = getCurrentYear();
|
|
544
|
+
function buildOptionSelect(field) {
|
|
545
|
+
if (isSelect(field)) {
|
|
546
|
+
return defineOption(field);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function defineOption(select) {
|
|
550
|
+
if (isSelectMonth(select)) {
|
|
551
|
+
return getMonth();
|
|
552
|
+
}
|
|
553
|
+
if (isSelectYear(select)) {
|
|
554
|
+
const min2 = select.advanced?.length?.min ?? now;
|
|
555
|
+
const max2 = select.advanced?.length?.max ?? now + 5;
|
|
556
|
+
return getYear(getConvert(min2, now), getConvert(max2, now));
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
function buildCommon(field, disabled = false) {
|
|
560
|
+
const commonProps = {
|
|
561
|
+
disabled,
|
|
562
|
+
id: field.name,
|
|
563
|
+
name: field.name,
|
|
564
|
+
placeholder: field.placeholder,
|
|
565
|
+
required: field.required
|
|
566
|
+
};
|
|
567
|
+
if (isInput(field)) {
|
|
568
|
+
return {
|
|
569
|
+
...commonProps,
|
|
570
|
+
...defineInput(field)
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
if (isSelect(field)) {
|
|
574
|
+
return {
|
|
575
|
+
...commonProps,
|
|
576
|
+
...defineSelect(field)
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
if (isTextArea(field)) {
|
|
580
|
+
return {
|
|
581
|
+
...commonProps,
|
|
582
|
+
...defineTextArea(field)
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
return commonProps;
|
|
586
|
+
}
|
|
587
|
+
function defineInput(input) {
|
|
588
|
+
const type = getType(input.type);
|
|
589
|
+
const copy = { ...input, type };
|
|
590
|
+
return {
|
|
591
|
+
...defineAutoComplete(input),
|
|
592
|
+
...defineNumberLimits(copy),
|
|
593
|
+
...isText(copy) ? defineLength(copy) : {},
|
|
594
|
+
type
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function defineSelect(field) {
|
|
598
|
+
const options = buildOptionSelect(field);
|
|
599
|
+
if (options) {
|
|
600
|
+
return { options };
|
|
601
|
+
}
|
|
602
|
+
return {};
|
|
603
|
+
}
|
|
604
|
+
function defineTextArea(field) {
|
|
605
|
+
return {
|
|
606
|
+
...defineAutoComplete(field),
|
|
607
|
+
...defineLength(field)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function defineAutoComplete(input) {
|
|
611
|
+
const autoComplete = input.advanced?.autocomplete;
|
|
612
|
+
if (autoComplete) {
|
|
613
|
+
return { autoComplete };
|
|
614
|
+
}
|
|
615
|
+
return {};
|
|
616
|
+
}
|
|
617
|
+
function defineNumberLimits(input) {
|
|
618
|
+
if (isNumber(input)) {
|
|
619
|
+
return defineMinMax(input);
|
|
620
|
+
}
|
|
621
|
+
return {};
|
|
622
|
+
}
|
|
623
|
+
function defineLength(input) {
|
|
624
|
+
return defineConstraints(input, { min: MIN_LENGTH, max: MAX_LENGTH });
|
|
625
|
+
}
|
|
626
|
+
function defineMinMax(input) {
|
|
627
|
+
return defineConstraints(input, { min: MIN, max: MAX });
|
|
628
|
+
}
|
|
629
|
+
function defineConstraints(input, keys) {
|
|
630
|
+
const result = {};
|
|
631
|
+
const length = input.advanced?.length;
|
|
632
|
+
if (length) {
|
|
633
|
+
if (length.min !== void 0) {
|
|
634
|
+
result[keys.min] = length.min;
|
|
635
|
+
}
|
|
636
|
+
if (length.max !== void 0) {
|
|
637
|
+
result[keys.max] = length.max;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
function resolveSource(field, value) {
|
|
643
|
+
const current = buildSource(field);
|
|
644
|
+
if (current) {
|
|
645
|
+
return current;
|
|
646
|
+
}
|
|
647
|
+
return buildOptions(field, value);
|
|
648
|
+
}
|
|
649
|
+
function getInputValue(field, value) {
|
|
650
|
+
const newValue = isObject(value) && field.name in value ? value[field.name] : value;
|
|
651
|
+
return getCurrentValue(newValue, field.advanced?.entity);
|
|
652
|
+
}
|
|
653
|
+
function mergeOptionsProps(field, commonProps, options) {
|
|
654
|
+
return isOptions(field) && Array.isArray(options) ? { ...commonProps, [OPTIONS]: options } : commonProps;
|
|
655
|
+
}
|
|
656
|
+
function getPreselectedValue(field, commonProps, value) {
|
|
657
|
+
if (field.required && !isValidValue(value)) {
|
|
658
|
+
if (isSelect(field)) {
|
|
659
|
+
if (field.advanced?.preselected !== false && OPTIONS in commonProps) {
|
|
660
|
+
const options = commonProps[OPTIONS];
|
|
661
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
662
|
+
return options[0];
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return value;
|
|
668
|
+
}
|
|
669
|
+
function getOptions(field, data) {
|
|
670
|
+
if (isSelect(field) && Array.isArray(data)) {
|
|
671
|
+
return toOptions(data, field.advanced?.options);
|
|
672
|
+
}
|
|
673
|
+
return data;
|
|
674
|
+
}
|
|
675
|
+
function prepareInputProps(field, commonProps, data, value) {
|
|
676
|
+
const currentValue = getInputValue(field, value);
|
|
677
|
+
const options = Array.isArray(data) ? getOptions(field, data) : data;
|
|
678
|
+
const commonPropsWithOptions = mergeOptionsProps(field, commonProps, options);
|
|
679
|
+
const defaultValue = getPreselectedValue(
|
|
680
|
+
field,
|
|
681
|
+
commonPropsWithOptions,
|
|
682
|
+
currentValue
|
|
683
|
+
);
|
|
684
|
+
return {
|
|
685
|
+
commonPropsWithOptions,
|
|
686
|
+
defaultValue
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
function prepareInputValue(field, value) {
|
|
690
|
+
if (isCheckbox(field)) {
|
|
691
|
+
return {
|
|
692
|
+
checked: isValidValue(value) ? value : false
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
return { value: value ?? "" };
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// ../luna-core/src/util/prepare.ts
|
|
699
|
+
var REGEX_REF = /^#\/definition\//;
|
|
700
|
+
function prepare(base = [], definition) {
|
|
701
|
+
const resolved = resolveRefs(base, definition);
|
|
702
|
+
return Array.isArray(resolved) ? resolved.sort((a, b) => getOrder(a) - getOrder(b)) : [];
|
|
703
|
+
}
|
|
704
|
+
function resolveRefs(base, definition, cache = /* @__PURE__ */ new Map(), visited = /* @__PURE__ */ new WeakSet()) {
|
|
705
|
+
if (!isDefinition(definition) || !base || typeof base !== "object") {
|
|
706
|
+
return base;
|
|
707
|
+
}
|
|
708
|
+
if (cache.has(base)) {
|
|
709
|
+
return cache.get(base);
|
|
710
|
+
}
|
|
711
|
+
if (visited.has(base)) {
|
|
712
|
+
return base;
|
|
713
|
+
}
|
|
714
|
+
visited.add(base);
|
|
715
|
+
if (Array.isArray(base)) {
|
|
716
|
+
return base.map((item) => resolveRefs(item, definition, cache, visited));
|
|
717
|
+
}
|
|
718
|
+
if ($REF in base && isString(base[$REF])) {
|
|
719
|
+
const path = base[$REF].replace(REGEX_REF, "");
|
|
720
|
+
const resolved = extract(definition, path);
|
|
721
|
+
if (resolved !== null) {
|
|
722
|
+
return resolveRefs(resolved, definition, cache, visited);
|
|
723
|
+
}
|
|
724
|
+
return base;
|
|
725
|
+
}
|
|
726
|
+
const result = {};
|
|
727
|
+
for (const [key, value] of Object.entries(base)) {
|
|
728
|
+
result[key] = resolveRefs(value, definition, cache, visited);
|
|
729
|
+
}
|
|
730
|
+
visited.delete(base);
|
|
731
|
+
cache.set(base, result);
|
|
732
|
+
return result;
|
|
733
|
+
}
|
|
734
|
+
function entries(values) {
|
|
735
|
+
return Object.entries(values ?? {});
|
|
736
|
+
}
|
|
737
|
+
function getOrder(item) {
|
|
738
|
+
return item.order ?? Number.MAX_VALUE;
|
|
739
|
+
}
|
|
740
|
+
function isDefinition(definition) {
|
|
741
|
+
return definition !== void 0 && isObject(definition) && Object.keys(definition).length > 0;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// ../luna-core/src/util/attributes.ts
|
|
745
|
+
function getPrefixedAttributes(prefix, record) {
|
|
746
|
+
const attrs = {};
|
|
747
|
+
for (const [key, value] of entries(record)) {
|
|
748
|
+
attrs[`${prefix}-${key}`] = value;
|
|
749
|
+
}
|
|
750
|
+
return attrs;
|
|
751
|
+
}
|
|
752
|
+
function getAriaAttributes(record) {
|
|
753
|
+
return getPrefixedAttributes(PREFIX_ARIA, record);
|
|
754
|
+
}
|
|
755
|
+
function getDataAttributes(record) {
|
|
756
|
+
return getPrefixedAttributes(PREFIX_DATA, record);
|
|
757
|
+
}
|
|
758
|
+
function buildAriaAttributes(field, errors) {
|
|
759
|
+
const ariaAttributes = getAriaAttributes(field.advanced?.aria);
|
|
760
|
+
if (errors && errors.length > 0) {
|
|
761
|
+
ariaAttributes[ARIA_INVALID] = "true";
|
|
762
|
+
ariaAttributes[ARIA_ERROR_MESSAGE] = `${field.name}-error`;
|
|
763
|
+
}
|
|
764
|
+
return ariaAttributes;
|
|
765
|
+
}
|
|
766
|
+
function buildDataAttributes(field) {
|
|
767
|
+
return getDataAttributes(field.advanced?.data);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// ../luna-core/src/util/column.ts
|
|
771
|
+
var cols = {
|
|
772
|
+
1: "md:grid-cols-1",
|
|
773
|
+
2: "md:grid-cols-2",
|
|
774
|
+
3: "md:grid-cols-3"
|
|
775
|
+
};
|
|
776
|
+
var span = {
|
|
777
|
+
1: "md:col-span-1",
|
|
778
|
+
2: "md:col-span-2",
|
|
779
|
+
3: "md:col-span-3"
|
|
780
|
+
};
|
|
781
|
+
function getColumn(value, defaultCols = 2) {
|
|
782
|
+
return cols[value && value in cols ? value : defaultCols];
|
|
783
|
+
}
|
|
784
|
+
function getSpan(value) {
|
|
785
|
+
if (value && value in span) {
|
|
786
|
+
return span[value];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// ../luna-core/src/util/schema.ts
|
|
791
|
+
import { z } from "zod";
|
|
792
|
+
|
|
793
|
+
// ../luna-core/src/util/translate.ts
|
|
794
|
+
function translate(key, dictionary) {
|
|
795
|
+
if (!key) {
|
|
796
|
+
return "";
|
|
797
|
+
}
|
|
798
|
+
if (!dictionary) {
|
|
799
|
+
return key;
|
|
800
|
+
}
|
|
801
|
+
return dictionary[key] ?? key;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ../luna-core/src/util/schema.ts
|
|
805
|
+
var approach = [
|
|
806
|
+
[isNumber, getNumber],
|
|
807
|
+
[isEmail, getEmail],
|
|
808
|
+
[isSelectYear, getYearSchema],
|
|
809
|
+
[isSelectMonth, getMonthSchema],
|
|
810
|
+
[isCheckbox, getBoolean],
|
|
811
|
+
[isRadio, getRadio]
|
|
812
|
+
];
|
|
813
|
+
function buildSchema(schemas, fields = [], translations) {
|
|
814
|
+
const schema = z.object(schemas);
|
|
815
|
+
if (fields.length === 0) {
|
|
816
|
+
return schema;
|
|
817
|
+
}
|
|
818
|
+
return applyCustomValidation(schema, fields, translations);
|
|
819
|
+
}
|
|
820
|
+
function flatten(error) {
|
|
821
|
+
const results = {};
|
|
822
|
+
const errors = z.flattenError(error).fieldErrors;
|
|
823
|
+
for (const [key, value] of Object.entries(errors)) {
|
|
824
|
+
if (value !== void 0) {
|
|
825
|
+
results[key] = value;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return results;
|
|
829
|
+
}
|
|
830
|
+
function getSchema(input, translations) {
|
|
831
|
+
for (const [check, getSchema2] of approach) {
|
|
832
|
+
if (check(input)) {
|
|
833
|
+
return getSchema2(input, translations);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return getText(input, translations);
|
|
837
|
+
}
|
|
838
|
+
function getEmail(input, translations) {
|
|
839
|
+
const baseSchema = z.string().trim();
|
|
840
|
+
if (input.required) {
|
|
841
|
+
const message = getRequiredMessage(input, translations);
|
|
842
|
+
const schema = baseSchema.min(1, message).pipe(applyEmail(input, translations));
|
|
843
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
844
|
+
}
|
|
845
|
+
return baseSchema.pipe(applyEmail(input, translations)).or(z.literal("")).nullable();
|
|
846
|
+
}
|
|
847
|
+
function getBoolean(input, translations) {
|
|
848
|
+
let schema = z.coerce.boolean();
|
|
849
|
+
if (input.required) {
|
|
850
|
+
schema = schema.refine((value) => value === true, {
|
|
851
|
+
message: getRequiredMessage(input, translations)
|
|
852
|
+
});
|
|
853
|
+
return z.preprocess((value) => value === null ? false : value, schema);
|
|
854
|
+
}
|
|
855
|
+
return schema.nullable();
|
|
856
|
+
}
|
|
857
|
+
function getRadio(input, translations) {
|
|
858
|
+
let schema = z.coerce.string();
|
|
859
|
+
if (input.required) {
|
|
860
|
+
schema = schema.min(1, getRequiredMessage(input, translations));
|
|
861
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
862
|
+
}
|
|
863
|
+
return schema.or(z.literal("")).nullable();
|
|
864
|
+
}
|
|
865
|
+
function getText(input, translations) {
|
|
866
|
+
let schema = z.coerce.string().trim();
|
|
867
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
868
|
+
if (input.required) {
|
|
869
|
+
schema = applyRequired(schema, input, translations);
|
|
870
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
871
|
+
}
|
|
872
|
+
return schema.nullable();
|
|
873
|
+
}
|
|
874
|
+
function getNumber(input, translations) {
|
|
875
|
+
let schema = z.coerce.number().int();
|
|
876
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
877
|
+
if (input.required) {
|
|
878
|
+
schema = applyRequired(schema, input, translations);
|
|
879
|
+
return z.preprocess((value) => value === null ? void 0 : value, schema);
|
|
880
|
+
}
|
|
881
|
+
return schema.nullable();
|
|
882
|
+
}
|
|
883
|
+
function getYearSchema(input, translations) {
|
|
884
|
+
if (input.required) {
|
|
885
|
+
return z.preprocess(
|
|
886
|
+
normalize,
|
|
887
|
+
z.coerce.number({ message: getRequiredMessage(input, translations) }).int()
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
return z.coerce.number().int().nullable();
|
|
891
|
+
}
|
|
892
|
+
function getMonthSchema(input, translations) {
|
|
893
|
+
const message = getRequiredMessage(input, translations);
|
|
894
|
+
const schema = z.coerce.number().int().min(1, message).max(12, message);
|
|
895
|
+
return !input.required ? schema.nullable() : schema;
|
|
896
|
+
}
|
|
897
|
+
function normalize(value) {
|
|
898
|
+
return value === null || value === "" ? void 0 : value;
|
|
899
|
+
}
|
|
900
|
+
function applyEmail(input, translations) {
|
|
901
|
+
const message = input.validation?.email ? translate(input.validation?.email, translations) : void 0;
|
|
902
|
+
return z.email(message);
|
|
903
|
+
}
|
|
904
|
+
function applyMinAndMax(schema, input, translations) {
|
|
905
|
+
schema = min(schema, input, translations);
|
|
906
|
+
schema = max(schema, input, translations);
|
|
907
|
+
return schema;
|
|
908
|
+
}
|
|
909
|
+
function applyRequired(schema, input, translations) {
|
|
910
|
+
const min2 = input.advanced?.length?.min;
|
|
911
|
+
if (min2 === void 0 || min2 < 1) {
|
|
912
|
+
return schema.min(1, getRequiredMessage(input, translations));
|
|
913
|
+
}
|
|
914
|
+
return schema;
|
|
915
|
+
}
|
|
916
|
+
var min = (schema, input, translations) => applyConstraint(schema, input, MIN, translations);
|
|
917
|
+
var max = (schema, input, translations) => applyConstraint(schema, input, MAX, translations);
|
|
918
|
+
function applyConstraint(schema, input, method, translations) {
|
|
919
|
+
const value = input.advanced?.length?.[method];
|
|
920
|
+
if (value !== void 0) {
|
|
921
|
+
const message = input.validation?.length?.[method] ? translate(input.validation?.length?.[method], translations) : void 0;
|
|
922
|
+
return schema[method](value, message);
|
|
923
|
+
}
|
|
924
|
+
return schema;
|
|
925
|
+
}
|
|
926
|
+
function applyCustomValidation(schema, fields = [], translations) {
|
|
927
|
+
const rules = getRules(fields);
|
|
928
|
+
if (rules.length === 0) {
|
|
929
|
+
return schema;
|
|
930
|
+
}
|
|
931
|
+
return schema.superRefine((data, context) => {
|
|
932
|
+
for (const { name, rule } of rules) {
|
|
933
|
+
if (!evaluate(data, name, rule)) {
|
|
934
|
+
const message = translate(rule.message, translations);
|
|
935
|
+
context.addIssue({
|
|
936
|
+
code: "custom",
|
|
937
|
+
message,
|
|
938
|
+
path: [name]
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
function evaluate(data, name, rule) {
|
|
945
|
+
const operator = rule.operator ?? "eq";
|
|
946
|
+
const operation = operators[operator];
|
|
947
|
+
if (operation) {
|
|
948
|
+
return operation(data[name], data[rule.field]);
|
|
949
|
+
}
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
function getRules(fields) {
|
|
953
|
+
const results = [];
|
|
954
|
+
for (const field of fields) {
|
|
955
|
+
const custom = field.validation?.custom;
|
|
956
|
+
if (!custom) {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
const rules = Array.isArray(custom) ? custom : [custom];
|
|
960
|
+
for (const rule of rules) {
|
|
961
|
+
results.push({ name: field.name, rule });
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return results;
|
|
965
|
+
}
|
|
966
|
+
function validateCustom(value, rules, getValue3, translations) {
|
|
967
|
+
const errors = [];
|
|
968
|
+
const collections = Array.isArray(rules) ? rules : [rules];
|
|
969
|
+
for (const rule of collections) {
|
|
970
|
+
const operator = rule.operator ?? "eq";
|
|
971
|
+
const operation = operators[operator];
|
|
972
|
+
if (operation && !operation(value, getValue3(rule.field))) {
|
|
973
|
+
if (rule.message) {
|
|
974
|
+
const message = translate(rule.message, translations);
|
|
975
|
+
errors.push(message);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return errors;
|
|
980
|
+
}
|
|
981
|
+
function getRequiredMessage(input, translations) {
|
|
982
|
+
return input.validation?.required ? translate(input.validation?.required, translations) : void 0;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// ../luna-core/src/util/url.ts
|
|
986
|
+
function matchRemotePattern(urlStr, patterns) {
|
|
987
|
+
if (!patterns || !isExternalUrl(urlStr)) {
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
if (patterns.length === 0) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
try {
|
|
994
|
+
const url = new URL(urlStr);
|
|
995
|
+
const protocol = url.protocol.replace(":", "");
|
|
996
|
+
const hostname = url.hostname;
|
|
997
|
+
const port = url.port || getPort(protocol);
|
|
998
|
+
return patterns.some((pattern) => {
|
|
999
|
+
if (pattern.protocol && pattern.protocol !== protocol) {
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
if (pattern.hostname && pattern.hostname !== hostname) {
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
if (pattern.port !== void 0 && String(pattern.port) !== port) {
|
|
1006
|
+
return false;
|
|
1007
|
+
}
|
|
1008
|
+
return true;
|
|
1009
|
+
});
|
|
1010
|
+
} catch {
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function getPort(protocol) {
|
|
1015
|
+
return protocol === "https" ? "443" : "80";
|
|
1016
|
+
}
|
|
1017
|
+
function isExternalUrl(url) {
|
|
1018
|
+
return /^(https?:)?\/\//.test(url);
|
|
1019
|
+
}
|
|
1020
|
+
function mergeUrl(baseUrl, targetUrl) {
|
|
1021
|
+
try {
|
|
1022
|
+
if (!baseUrl) {
|
|
1023
|
+
return targetUrl;
|
|
1024
|
+
}
|
|
1025
|
+
if (!targetUrl) {
|
|
1026
|
+
return baseUrl;
|
|
1027
|
+
}
|
|
1028
|
+
const url1 = new URL(baseUrl, COMMON_URL);
|
|
1029
|
+
const url2 = new URL(targetUrl, COMMON_URL);
|
|
1030
|
+
url2.searchParams.forEach((value, key) => {
|
|
1031
|
+
url1.searchParams.set(key, value);
|
|
1032
|
+
});
|
|
1033
|
+
const result = url1.toString();
|
|
1034
|
+
return baseUrl.startsWith("/") || !baseUrl.includes("://") ? result.replace(COMMON_URL, "") : result;
|
|
1035
|
+
} catch {
|
|
1036
|
+
return targetUrl || baseUrl;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// ../luna-core/src/util/source.ts
|
|
1041
|
+
function mergeSource(sources) {
|
|
1042
|
+
if (!Array.isArray(sources) || sources.length === 0) {
|
|
1043
|
+
return null;
|
|
1044
|
+
}
|
|
1045
|
+
return sources.reduce((previous, current) => {
|
|
1046
|
+
const url = mergeUrl(previous.url, current.url);
|
|
1047
|
+
const body = getBody(previous, current);
|
|
1048
|
+
const headers = getHeaders(previous, current);
|
|
1049
|
+
return {
|
|
1050
|
+
...previous,
|
|
1051
|
+
...current,
|
|
1052
|
+
url,
|
|
1053
|
+
body,
|
|
1054
|
+
headers
|
|
1055
|
+
};
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
function getBody(previous, current) {
|
|
1059
|
+
if (isObject(current.body) && isObject(previous?.body)) {
|
|
1060
|
+
return {
|
|
1061
|
+
...previous.body,
|
|
1062
|
+
...current.body
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
return current.body ?? previous?.body;
|
|
1066
|
+
}
|
|
1067
|
+
function getHeaders(previous, current) {
|
|
1068
|
+
if (isObject(current.headers) && isObject(previous?.headers)) {
|
|
1069
|
+
return {
|
|
1070
|
+
...previous.headers,
|
|
1071
|
+
...current.headers
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
return current.headers ?? previous?.headers;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// ../luna-core/src/util/style.ts
|
|
1078
|
+
function mergeStyle(globalStyle, localStyle) {
|
|
1079
|
+
return { ...globalStyle, ...localStyle };
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/component/field/field-base.tsx
|
|
1083
|
+
import { twMerge } from "tailwind-merge";
|
|
1084
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1085
|
+
function FieldBase(props) {
|
|
1086
|
+
const errors = props.errors && props.errors.length > 0;
|
|
1087
|
+
return /* @__PURE__ */ jsx2(
|
|
1088
|
+
"div",
|
|
1089
|
+
{
|
|
1090
|
+
"data-slot": "field",
|
|
1091
|
+
"data-clickable": props.isClickable ? "true" : "false",
|
|
1092
|
+
...errors && { [DATA_INVALID]: "true" },
|
|
1093
|
+
...props.disabled && { [DATA_READONLY]: "true" },
|
|
1094
|
+
"data-orientation": props.orientation,
|
|
1095
|
+
className: twMerge(
|
|
1096
|
+
"group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500",
|
|
1097
|
+
"data-[clickable=true]:items-start",
|
|
1098
|
+
props.isCheckbox && (props.isReversed ? "flex-row-reverse!" : "flex-row!"),
|
|
1099
|
+
"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",
|
|
1100
|
+
props.className
|
|
1101
|
+
),
|
|
1102
|
+
children: props.children
|
|
1103
|
+
}
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// src/component/field/field-vertical.tsx
|
|
1108
|
+
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
1109
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1110
|
+
function FieldVertical(props) {
|
|
1111
|
+
return /* @__PURE__ */ jsx3(
|
|
1112
|
+
FieldBase,
|
|
1113
|
+
{
|
|
1114
|
+
...props,
|
|
1115
|
+
orientation: VERTICAL,
|
|
1116
|
+
className: twMerge2(
|
|
1117
|
+
"gap-3 has-[>[data-slot=field-content]]:items-start",
|
|
1118
|
+
!props.isClickable && "[&>*]:w-full"
|
|
1119
|
+
),
|
|
1120
|
+
children: props.children
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// src/component/field/field-horizontal.tsx
|
|
1126
|
+
import { twMerge as twMerge3 } from "tailwind-merge";
|
|
1127
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1128
|
+
function FieldHorizontal(props) {
|
|
1129
|
+
return /* @__PURE__ */ jsx4(
|
|
1130
|
+
FieldBase,
|
|
1131
|
+
{
|
|
1132
|
+
...props,
|
|
1133
|
+
orientation: HORIZONTAL,
|
|
1134
|
+
className: twMerge3(
|
|
1135
|
+
"gap-2 md:flex-row md:gap-4",
|
|
1136
|
+
"[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start",
|
|
1137
|
+
"[&_[role=checkbox]]:mt-[1.5px]",
|
|
1138
|
+
props.isClickable && "md:flex-col",
|
|
1139
|
+
!props.isClickable && [
|
|
1140
|
+
"md:justify-between",
|
|
1141
|
+
"[&>*:not([data-slot=field-content])]:w-full",
|
|
1142
|
+
"[&>*:not([data-slot=field-content])]:md:w-1/2",
|
|
1143
|
+
"[&>*:not([data-slot=field-content])]:xl:w-2/5"
|
|
1144
|
+
]
|
|
1145
|
+
),
|
|
1146
|
+
children: props.children
|
|
1147
|
+
}
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/component/field/field-group.tsx
|
|
1152
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1153
|
+
function FieldGroup(props) {
|
|
1154
|
+
const clickable = isClickable(props.field);
|
|
1155
|
+
const checkbox = isCheckbox(props.field);
|
|
1156
|
+
const reversed = buildReverse(props.field);
|
|
1157
|
+
if (props.orientation === VERTICAL) {
|
|
1158
|
+
return /* @__PURE__ */ jsx5(
|
|
1159
|
+
FieldVertical,
|
|
1160
|
+
{
|
|
1161
|
+
disabled: props.disabled,
|
|
1162
|
+
errors: props.errors,
|
|
1163
|
+
isCheckbox: checkbox,
|
|
1164
|
+
isReversed: reversed,
|
|
1165
|
+
isClickable: clickable,
|
|
1166
|
+
children: props.children
|
|
1167
|
+
}
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
return /* @__PURE__ */ jsx5(
|
|
1171
|
+
FieldHorizontal,
|
|
1172
|
+
{
|
|
1173
|
+
disabled: props.disabled,
|
|
1174
|
+
errors: props.errors,
|
|
1175
|
+
isCheckbox: checkbox,
|
|
1176
|
+
isReversed: reversed,
|
|
1177
|
+
isClickable: clickable,
|
|
1178
|
+
children: props.children
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
// src/component/input/input-base.tsx
|
|
1184
|
+
function InputBase(props) {
|
|
1185
|
+
if (!props.field.type) {
|
|
1186
|
+
return null;
|
|
1187
|
+
}
|
|
1188
|
+
const commonProps = buildCommon(props.field, props.disabled);
|
|
1189
|
+
const dataAttributes = buildDataAttributes(props.field);
|
|
1190
|
+
const ariaAttributes = buildAriaAttributes(props.field, props.errors);
|
|
1191
|
+
const field = {
|
|
1192
|
+
...props.field,
|
|
1193
|
+
disabled: commonProps.disabled
|
|
1194
|
+
};
|
|
1195
|
+
return props.children({
|
|
1196
|
+
ariaAttributes,
|
|
1197
|
+
commonProps,
|
|
1198
|
+
dataAttributes,
|
|
1199
|
+
field,
|
|
1200
|
+
orientation: props.orientation
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// src/component/field/field.tsx
|
|
1205
|
+
import { twMerge as twMerge4 } from "tailwind-merge";
|
|
1206
|
+
import { jsx as jsx6, jsxs } from "react/jsx-runtime";
|
|
1207
|
+
function Field(props) {
|
|
1208
|
+
const cols2 = props.field.advanced?.cols;
|
|
1209
|
+
const errors = props.field.name ? props.errors?.[props.field.name] : void 0;
|
|
1210
|
+
const { orientation } = mergeStyle(props.style, {
|
|
1211
|
+
orientation: buildOrientation(props.field)
|
|
1212
|
+
});
|
|
1213
|
+
const disabled = buildDisabled(props.field, props.disabled);
|
|
1214
|
+
return /* @__PURE__ */ jsxs("div", { className: twMerge4("flex flex-col gap-3", getSpan(cols2)), children: [
|
|
1215
|
+
/* @__PURE__ */ jsx6(
|
|
1216
|
+
FieldGroup,
|
|
1217
|
+
{
|
|
1218
|
+
disabled,
|
|
1219
|
+
errors,
|
|
1220
|
+
field: props.field,
|
|
1221
|
+
orientation,
|
|
1222
|
+
children: /* @__PURE__ */ jsx6(
|
|
1223
|
+
InputBase,
|
|
1224
|
+
{
|
|
1225
|
+
disabled,
|
|
1226
|
+
errors,
|
|
1227
|
+
field: props.field,
|
|
1228
|
+
orientation,
|
|
1229
|
+
children: props.children
|
|
1230
|
+
}
|
|
1231
|
+
)
|
|
1232
|
+
}
|
|
1233
|
+
),
|
|
1234
|
+
/* @__PURE__ */ jsx6(FieldError, { errors, name: props.field.name })
|
|
1235
|
+
] });
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/client/lib/store-helper.ts
|
|
1239
|
+
import { atom } from "jotai";
|
|
1240
|
+
import { atomFamily } from "jotai-family";
|
|
1241
|
+
import { deepEqual } from "fast-equals";
|
|
1242
|
+
function createRecordAtomFamily(baseAtom) {
|
|
1243
|
+
return atomFamily(
|
|
1244
|
+
(name) => atom(
|
|
1245
|
+
(get) => {
|
|
1246
|
+
return get(baseAtom)[name] ?? void 0;
|
|
1247
|
+
},
|
|
1248
|
+
(get, set, newValue) => {
|
|
1249
|
+
const current = get(baseAtom);
|
|
1250
|
+
if (newValue !== void 0 && newValue !== null) {
|
|
1251
|
+
const currentValue = current[name];
|
|
1252
|
+
if (!currentValue || !deepEqual(currentValue, newValue)) {
|
|
1253
|
+
set(baseAtom, { ...current, [name]: newValue });
|
|
1254
|
+
}
|
|
1255
|
+
} else if (current[name]) {
|
|
1256
|
+
const { [name]: _unused, ...rest } = current;
|
|
1257
|
+
set(baseAtom, rest);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
)
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
function createClearAllAtom(baseAtom) {
|
|
1264
|
+
return atom(null, (get, set) => {
|
|
1265
|
+
const current = get(baseAtom);
|
|
1266
|
+
if (current && Object.keys(current).length > 0) {
|
|
1267
|
+
set(baseAtom, {});
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
function createClearAtom(baseAtom) {
|
|
1272
|
+
return atom(null, (get, set, names) => {
|
|
1273
|
+
const current = get(baseAtom);
|
|
1274
|
+
const next = { ...current };
|
|
1275
|
+
let hasChanges = false;
|
|
1276
|
+
for (const name of names) {
|
|
1277
|
+
if (next[name]) {
|
|
1278
|
+
delete next[name];
|
|
1279
|
+
hasChanges = true;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (hasChanges) {
|
|
1283
|
+
set(baseAtom, next);
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
function createBulkReportAtom(baseAtom) {
|
|
1288
|
+
return atom(null, (get, set, newValue) => {
|
|
1289
|
+
const current = get(baseAtom);
|
|
1290
|
+
if (!deepEqual(current, newValue)) {
|
|
1291
|
+
set(baseAtom, newValue);
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
function createNestedRecordAtomFamily(baseAtom, options = {}) {
|
|
1296
|
+
const { merge: merge2, validateTarget } = options;
|
|
1297
|
+
return atomFamily(
|
|
1298
|
+
(contributorName) => atom(
|
|
1299
|
+
(get) => {
|
|
1300
|
+
const current = get(baseAtom)[contributorName];
|
|
1301
|
+
if (current && merge2) {
|
|
1302
|
+
return merge2(Object.values(current));
|
|
1303
|
+
}
|
|
1304
|
+
return void 0;
|
|
1305
|
+
},
|
|
1306
|
+
(get, set, target, value) => {
|
|
1307
|
+
if (validateTarget && !validateTarget(target)) {
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const current = get(baseAtom);
|
|
1311
|
+
const targetContributions = { ...current[target] ?? {} };
|
|
1312
|
+
if (value !== void 0 && value !== null) {
|
|
1313
|
+
const currentContribution = targetContributions[contributorName];
|
|
1314
|
+
if (!currentContribution || !deepEqual(currentContribution, value)) {
|
|
1315
|
+
targetContributions[contributorName] = value;
|
|
1316
|
+
set(baseAtom, {
|
|
1317
|
+
...current,
|
|
1318
|
+
[target]: targetContributions
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
} else if (targetContributions[contributorName]) {
|
|
1322
|
+
delete targetContributions[contributorName];
|
|
1323
|
+
if (Object.keys(targetContributions).length === 0) {
|
|
1324
|
+
const { [target]: _unused, ...rest } = current;
|
|
1325
|
+
set(baseAtom, rest);
|
|
1326
|
+
} else {
|
|
1327
|
+
set(baseAtom, {
|
|
1328
|
+
...current,
|
|
1329
|
+
[target]: targetContributions
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
)
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
function createNestedClearAtom(baseAtom) {
|
|
1338
|
+
return atom(null, (get, set, contributorNames) => {
|
|
1339
|
+
const current = get(baseAtom);
|
|
1340
|
+
const next = { ...current };
|
|
1341
|
+
let hasChanges = false;
|
|
1342
|
+
for (const name of contributorNames) {
|
|
1343
|
+
if (next[name]) {
|
|
1344
|
+
delete next[name];
|
|
1345
|
+
hasChanges = true;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
for (const target in next) {
|
|
1349
|
+
const targetContributions = { ...next[target] };
|
|
1350
|
+
let targetChanged = false;
|
|
1351
|
+
for (const contributorName of contributorNames) {
|
|
1352
|
+
if (targetContributions[contributorName]) {
|
|
1353
|
+
delete targetContributions[contributorName];
|
|
1354
|
+
targetChanged = true;
|
|
1355
|
+
hasChanges = true;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
if (targetChanged) {
|
|
1359
|
+
if (Object.keys(targetContributions).length === 0) {
|
|
1360
|
+
delete next[target];
|
|
1361
|
+
} else {
|
|
1362
|
+
next[target] = targetContributions;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
if (hasChanges) {
|
|
1367
|
+
set(baseAtom, next);
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function createAtomStore(initialValue = {}) {
|
|
1372
|
+
const baseAtom = atom(initialValue);
|
|
1373
|
+
return {
|
|
1374
|
+
atom: baseAtom,
|
|
1375
|
+
clearAll: createClearAllAtom(baseAtom),
|
|
1376
|
+
clear: createClearAtom(baseAtom),
|
|
1377
|
+
bulkReport: createBulkReportAtom(baseAtom),
|
|
1378
|
+
report: createRecordAtomFamily(baseAtom)
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// src/client/lib/error-store.ts
|
|
1383
|
+
var store = createAtomStore();
|
|
1384
|
+
var clearInputErrorAtom = store.clear;
|
|
1385
|
+
var reportErrorAtom = store.bulkReport;
|
|
1386
|
+
var reportInputErrorAtom = store.report;
|
|
1387
|
+
|
|
1388
|
+
// src/client/component/wrapper/with-error.tsx
|
|
1389
|
+
import { useAtomValue } from "jotai";
|
|
1390
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1391
|
+
function withErrors(Component) {
|
|
1392
|
+
const WithErrors = (props) => {
|
|
1393
|
+
const errors = useAtomValue(reportInputErrorAtom(props.field.name));
|
|
1394
|
+
return /* @__PURE__ */ jsx7(
|
|
1395
|
+
Component,
|
|
1396
|
+
{
|
|
1397
|
+
...props,
|
|
1398
|
+
errors: errors ? { [props.field.name]: errors } : void 0
|
|
1399
|
+
}
|
|
1400
|
+
);
|
|
1401
|
+
};
|
|
1402
|
+
return WithErrors;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// src/client/lib/state-store.ts
|
|
1406
|
+
var store2 = createAtomStore();
|
|
1407
|
+
var fieldStateAtom = store2.atom;
|
|
1408
|
+
var reportFieldStateAtom = store2.report;
|
|
1409
|
+
|
|
1410
|
+
// src/client/component/wrapper/with-field-state.tsx
|
|
1411
|
+
import { useAtomValue as useAtomValue2 } from "jotai";
|
|
1412
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1413
|
+
function withFieldState(Component) {
|
|
1414
|
+
const WithFieldState = (props) => {
|
|
1415
|
+
const fieldState = useAtomValue2(reportFieldStateAtom(props.field.name));
|
|
1416
|
+
const hidden = fieldState?.hidden ?? props.field.hidden ?? false;
|
|
1417
|
+
if (hidden) {
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
const disabled = fieldState?.disabled ?? props.disabled;
|
|
1421
|
+
return /* @__PURE__ */ jsx8(Component, { ...props, disabled });
|
|
1422
|
+
};
|
|
1423
|
+
return WithFieldState;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// src/client/component/wrapper/index.tsx
|
|
1427
|
+
var Field2 = withFieldState(withErrors(Field));
|
|
1428
|
+
|
|
1429
|
+
// src/component/control.tsx
|
|
1430
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1431
|
+
function Control(props) {
|
|
1432
|
+
const content = typeof props.children === "function" ? props.children({ isPending: props.isPending }) : props.children;
|
|
1433
|
+
return /* @__PURE__ */ jsx9("div", { "data-slot": "field-control", className: "w-full", children: content });
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// src/component/group.tsx
|
|
1437
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1438
|
+
function Group(props) {
|
|
1439
|
+
return /* @__PURE__ */ jsx10(
|
|
1440
|
+
"div",
|
|
1441
|
+
{
|
|
1442
|
+
"data-slot": "field-group",
|
|
1443
|
+
"data-compact": props.compact,
|
|
1444
|
+
className: "flex w-full flex-col gap-8 data-[compact=true]:gap-3",
|
|
1445
|
+
children: props.children
|
|
1446
|
+
}
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// src/lib/string.tsx
|
|
1451
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1452
|
+
function formatMarkdown2(text) {
|
|
1453
|
+
return formatMarkdown(
|
|
1454
|
+
text,
|
|
1455
|
+
(index, url, text2) => {
|
|
1456
|
+
return /* @__PURE__ */ jsx11(
|
|
1457
|
+
"a",
|
|
1458
|
+
{
|
|
1459
|
+
className: "underline",
|
|
1460
|
+
href: url,
|
|
1461
|
+
rel: "noopener noreferrer",
|
|
1462
|
+
target: "_blank",
|
|
1463
|
+
children: text2
|
|
1464
|
+
},
|
|
1465
|
+
`${url}-${index}`
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
// src/component/legend.tsx
|
|
1472
|
+
import { Fragment, jsx as jsx12, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1473
|
+
function Legend(props) {
|
|
1474
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1475
|
+
props.title && /* @__PURE__ */ jsx12("legend", { className: "mb-3 font-medium text-slate-800 dark:text-slate-200", children: formatMarkdown2(props.title) }),
|
|
1476
|
+
props.description && /* @__PURE__ */ jsx12("p", { className: "-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.description) })
|
|
1477
|
+
] });
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/component/field/field-set.tsx
|
|
1481
|
+
import { jsx as jsx13, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1482
|
+
function FieldSet(props) {
|
|
1483
|
+
const fields = props.section.fields || [];
|
|
1484
|
+
const { compact } = mergeStyle(props.style, {
|
|
1485
|
+
compact: props.section.compact
|
|
1486
|
+
});
|
|
1487
|
+
if (!props.section.title && !props.section.description) {
|
|
1488
|
+
return /* @__PURE__ */ jsx13(Group, { compact, children: props.children });
|
|
1489
|
+
}
|
|
1490
|
+
return /* @__PURE__ */ jsxs3(
|
|
1491
|
+
"fieldset",
|
|
1492
|
+
{
|
|
1493
|
+
"data-slot": "field-set",
|
|
1494
|
+
"data-empty": fields.length === 0,
|
|
1495
|
+
className: "flex flex-col data-[empty=false]:gap-6",
|
|
1496
|
+
id: props.section.id?.toString(),
|
|
1497
|
+
children: [
|
|
1498
|
+
/* @__PURE__ */ jsx13(
|
|
1499
|
+
Legend,
|
|
1500
|
+
{
|
|
1501
|
+
description: props.section.description,
|
|
1502
|
+
title: props.section.title
|
|
1503
|
+
}
|
|
1504
|
+
),
|
|
1505
|
+
/* @__PURE__ */ jsx13(Group, { compact, children: props.children })
|
|
1506
|
+
]
|
|
1507
|
+
}
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// src/component/form.tsx
|
|
1512
|
+
import { Fragment as Fragment2 } from "react";
|
|
1513
|
+
|
|
1514
|
+
// src/component/separator.tsx
|
|
1515
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1516
|
+
function Separator() {
|
|
1517
|
+
return /* @__PURE__ */ jsx14("div", { "data-slot": "field-separator", className: "relative -my-2 h-5 text-sm", children: /* @__PURE__ */ jsx14("div", { className: "absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800" }) });
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/component/form.tsx
|
|
1521
|
+
import { jsx as jsx15, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1522
|
+
function Form(props) {
|
|
1523
|
+
const sections = prepare(props.sections, props.definition);
|
|
1524
|
+
return /* @__PURE__ */ jsx15("div", { className: "h-full w-full", children: /* @__PURE__ */ jsx15("form", { noValidate: props.noValidate, action: props.action, children: /* @__PURE__ */ jsxs4(Group, { children: [
|
|
1525
|
+
sections.map((section, index) => /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
1526
|
+
/* @__PURE__ */ jsx15(FieldSet, { section, style: props.config.style, children: props.children({
|
|
1527
|
+
disabled: props.readOnly,
|
|
1528
|
+
fields: section.fields
|
|
1529
|
+
}) }),
|
|
1530
|
+
section.separator && /* @__PURE__ */ jsx15(Separator, {})
|
|
1531
|
+
] }, index)),
|
|
1532
|
+
props.control && /* @__PURE__ */ jsx15(Control, { isPending: props.isPending, children: props.control })
|
|
1533
|
+
] }) }) });
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// src/component/description.tsx
|
|
1537
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
1538
|
+
function Description(props) {
|
|
1539
|
+
return /* @__PURE__ */ jsx16("p", { className: "-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400", children: props.children });
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/component/formatted-description.tsx
|
|
1543
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
1544
|
+
function FormattedDescription(props) {
|
|
1545
|
+
const content = formatMarkdown2(props.text);
|
|
1546
|
+
if (content) {
|
|
1547
|
+
return /* @__PURE__ */ jsx17(Description, { children: content });
|
|
1548
|
+
}
|
|
1549
|
+
return null;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// src/component/label.tsx
|
|
1553
|
+
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
1554
|
+
import { jsx as jsx18, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1555
|
+
function Label(props) {
|
|
1556
|
+
const showOptionalLabel = props.style?.showOptionalLabel ?? true;
|
|
1557
|
+
const normal = isRadio(props.field) || isCheckbox(props.field);
|
|
1558
|
+
return /* @__PURE__ */ jsxs5(
|
|
1559
|
+
"label",
|
|
1560
|
+
{
|
|
1561
|
+
"data-slot": "field-label",
|
|
1562
|
+
"data-normal": normal,
|
|
1563
|
+
className: twMerge5(
|
|
1564
|
+
"flex w-fit items-center gap-2 text-sm leading-snug font-medium select-none",
|
|
1565
|
+
"data-[normal=true]:font-normal",
|
|
1566
|
+
"group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"
|
|
1567
|
+
),
|
|
1568
|
+
htmlFor: props.field.name,
|
|
1569
|
+
children: [
|
|
1570
|
+
props.children,
|
|
1571
|
+
showOptionalLabel && !props.field.required && /* @__PURE__ */ jsx18("span", { className: "text-sm text-slate-600 dark:text-slate-400", children: translate("(Optional)", props.translations) })
|
|
1572
|
+
]
|
|
1573
|
+
}
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// src/component/input-label.tsx
|
|
1578
|
+
import { jsx as jsx19, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1579
|
+
function InputLabel(props) {
|
|
1580
|
+
const label = isInterpolated(props.field.label) ? interpolate(props.field.label, {
|
|
1581
|
+
context: props.context,
|
|
1582
|
+
env: props.config?.env
|
|
1583
|
+
}) : props.field.label;
|
|
1584
|
+
const description = isInterpolated(props.field.description) ? interpolate(props.field.description, {
|
|
1585
|
+
context: props.context,
|
|
1586
|
+
env: props.config?.env
|
|
1587
|
+
}) : props.field.description;
|
|
1588
|
+
return /* @__PURE__ */ jsxs6(
|
|
1589
|
+
"div",
|
|
1590
|
+
{
|
|
1591
|
+
"data-slot": "field-content",
|
|
1592
|
+
className: "flex w-full flex-1 flex-col gap-1.5 leading-snug",
|
|
1593
|
+
children: [
|
|
1594
|
+
/* @__PURE__ */ jsx19(
|
|
1595
|
+
Label,
|
|
1596
|
+
{
|
|
1597
|
+
field: props.field,
|
|
1598
|
+
style: props.config?.style,
|
|
1599
|
+
translations: props.translations,
|
|
1600
|
+
children: translate(label, props.translations)
|
|
1601
|
+
}
|
|
1602
|
+
),
|
|
1603
|
+
props.orientation === HORIZONTAL && /* @__PURE__ */ jsx19(
|
|
1604
|
+
FormattedDescription,
|
|
1605
|
+
{
|
|
1606
|
+
text: translate(description, props.translations)
|
|
1607
|
+
}
|
|
1608
|
+
)
|
|
1609
|
+
]
|
|
1610
|
+
}
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// src/component/input-group.tsx
|
|
1615
|
+
import { Fragment as Fragment3, jsx as jsx20, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1616
|
+
function InputGroup(props) {
|
|
1617
|
+
return /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1618
|
+
props.field.name && props.field.label && /* @__PURE__ */ jsx20(
|
|
1619
|
+
InputLabel,
|
|
1620
|
+
{
|
|
1621
|
+
config: props.config,
|
|
1622
|
+
context: props.context,
|
|
1623
|
+
field: props.field,
|
|
1624
|
+
orientation: props.orientation,
|
|
1625
|
+
translations: props.translations
|
|
1626
|
+
}
|
|
1627
|
+
),
|
|
1628
|
+
props.children,
|
|
1629
|
+
props.orientation === VERTICAL && props.field.description && /* @__PURE__ */ jsx20(
|
|
1630
|
+
FormattedDescription,
|
|
1631
|
+
{
|
|
1632
|
+
text: translate(props.field.description, props.translations)
|
|
1633
|
+
}
|
|
1634
|
+
)
|
|
1635
|
+
] });
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
// src/lib/render-If-exists.ts
|
|
1639
|
+
function renderIfExists(value, render) {
|
|
1640
|
+
if (!value) {
|
|
1641
|
+
return null;
|
|
1642
|
+
}
|
|
1643
|
+
return render(value);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// src/client/component/input.tsx
|
|
1647
|
+
import { useCallback as useCallback3, useRef as useRef3, useTransition } from "react";
|
|
1648
|
+
|
|
1649
|
+
// src/client/lib/source-store.ts
|
|
1650
|
+
import { atom as atom2 } from "jotai";
|
|
1651
|
+
var merge = (values) => {
|
|
1652
|
+
const merged = mergeSource(values);
|
|
1653
|
+
if (merged) {
|
|
1654
|
+
return merged;
|
|
1655
|
+
}
|
|
1656
|
+
return void 0;
|
|
1657
|
+
};
|
|
1658
|
+
var validate = (target) => target.trim() !== "";
|
|
1659
|
+
var sourceAtom = atom2({});
|
|
1660
|
+
var reportSourceAtom = createNestedRecordAtomFamily(
|
|
1661
|
+
sourceAtom,
|
|
1662
|
+
{
|
|
1663
|
+
merge,
|
|
1664
|
+
validateTarget: validate
|
|
1665
|
+
}
|
|
1666
|
+
);
|
|
1667
|
+
var clearInputSourceAtom = createNestedClearAtom(sourceAtom);
|
|
1668
|
+
|
|
1669
|
+
// src/client/hook/use-data-source.ts
|
|
1670
|
+
import { useAtom } from "jotai";
|
|
1671
|
+
|
|
1672
|
+
// src/client/hook/use-fetch.ts
|
|
1673
|
+
import useSWR from "swr";
|
|
1674
|
+
function useFetch(dataSource = null, config, disabled = false) {
|
|
1675
|
+
const { data, error } = useSWR(
|
|
1676
|
+
buildSource2(dataSource, config, disabled),
|
|
1677
|
+
config.fetcher.provider
|
|
1678
|
+
);
|
|
1679
|
+
if (error) {
|
|
1680
|
+
logger.error("Error fetching data source:", error);
|
|
1681
|
+
}
|
|
1682
|
+
if (dataSource) {
|
|
1683
|
+
if (Array.isArray(dataSource)) {
|
|
1684
|
+
return dataSource;
|
|
1685
|
+
}
|
|
1686
|
+
if (data) {
|
|
1687
|
+
return getArray(data, dataSource.namespace);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
return null;
|
|
1691
|
+
}
|
|
1692
|
+
function buildSource2(dataSource = null, config, disabled = false) {
|
|
1693
|
+
if (dataSource && !Array.isArray(dataSource) && !disabled) {
|
|
1694
|
+
if (dataSource.url) {
|
|
1695
|
+
const interpolated = isInterpolated(dataSource.url);
|
|
1696
|
+
if (!interpolated) {
|
|
1697
|
+
const allowed = matchRemotePattern(
|
|
1698
|
+
dataSource.url,
|
|
1699
|
+
config.fetcher.remotePatterns
|
|
1700
|
+
);
|
|
1701
|
+
if (allowed) {
|
|
1702
|
+
return dataSource;
|
|
1703
|
+
}
|
|
1704
|
+
logger.warn(
|
|
1705
|
+
`URL blocked by remotePatterns: ${dataSource.url}. Check your luna.config.ts`
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return null;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// src/client/hook/use-data-source.ts
|
|
1714
|
+
function useDataSource(field, config, value) {
|
|
1715
|
+
const dataSource = resolveSource(field, value);
|
|
1716
|
+
const [source, setSource] = useAtom(reportSourceAtom(field.name));
|
|
1717
|
+
const currentSource = source ?? dataSource;
|
|
1718
|
+
const data = useFetch(currentSource, config, field.disabled);
|
|
1719
|
+
return [data, setSource];
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// src/client/hook/use-input.ts
|
|
1723
|
+
import { useEffect, useEffectEvent, useMemo } from "react";
|
|
1724
|
+
function useInput(field, onMount, onUnmount, translations) {
|
|
1725
|
+
const { name } = field;
|
|
1726
|
+
const schema = useMemo(
|
|
1727
|
+
() => getSchema(field, translations),
|
|
1728
|
+
[field, translations]
|
|
1729
|
+
);
|
|
1730
|
+
const onMountHandler = useEffectEvent((name2) => {
|
|
1731
|
+
if (name2) {
|
|
1732
|
+
onMount(name2, schema, field);
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
const onUnmountHandler = useEffectEvent((name2) => {
|
|
1736
|
+
if (name2) {
|
|
1737
|
+
onUnmount(name2);
|
|
1738
|
+
}
|
|
1739
|
+
});
|
|
1740
|
+
useEffect(() => {
|
|
1741
|
+
onMountHandler(name);
|
|
1742
|
+
return () => {
|
|
1743
|
+
onUnmountHandler(name);
|
|
1744
|
+
};
|
|
1745
|
+
}, [name]);
|
|
1746
|
+
return schema;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// src/client/component/input.tsx
|
|
1750
|
+
import { useSetAtom, useStore } from "jotai";
|
|
1751
|
+
|
|
1752
|
+
// src/client/hook/use-timeout.ts
|
|
1753
|
+
import { useCallback, useEffect as useEffect2, useRef } from "react";
|
|
1754
|
+
function useTimeout() {
|
|
1755
|
+
const timeoutRef = useRef(null);
|
|
1756
|
+
useEffect2(() => {
|
|
1757
|
+
return () => {
|
|
1758
|
+
if (timeoutRef.current) {
|
|
1759
|
+
clearTimeout(timeoutRef.current);
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
}, []);
|
|
1763
|
+
function clearTimeoutRef() {
|
|
1764
|
+
if (timeoutRef.current) {
|
|
1765
|
+
clearTimeout(timeoutRef.current);
|
|
1766
|
+
timeoutRef.current = null;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
const setTimeoutRef = useCallback((callback, delay) => {
|
|
1770
|
+
clearTimeoutRef();
|
|
1771
|
+
timeoutRef.current = setTimeout(callback, delay);
|
|
1772
|
+
}, []);
|
|
1773
|
+
return setTimeoutRef;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// src/client/lib/value-store.ts
|
|
1777
|
+
var store3 = createAtomStore();
|
|
1778
|
+
var valueAtom = store3.atom;
|
|
1779
|
+
var clearAllValueAtom = store3.clearAll;
|
|
1780
|
+
var clearInputValueAtom = store3.clear;
|
|
1781
|
+
var reportValueAtom = store3.report;
|
|
1782
|
+
|
|
1783
|
+
// src/client/hook/use-value.ts
|
|
1784
|
+
import { useAtom as useAtom2 } from "jotai";
|
|
1785
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
1786
|
+
function useValue(field, currentValue) {
|
|
1787
|
+
const { name } = field;
|
|
1788
|
+
const skipNextOnChangeRef = useRef2(false);
|
|
1789
|
+
const [value, setValue] = useAtom2(reportValueAtom(name));
|
|
1790
|
+
useEffect3(() => {
|
|
1791
|
+
if (!currentValue || !(name in currentValue)) {
|
|
1792
|
+
return;
|
|
1793
|
+
}
|
|
1794
|
+
const newValue = currentValue[name];
|
|
1795
|
+
if (isValidValue(newValue)) {
|
|
1796
|
+
logger.info("useValue: setting skipNextOnChange to true", {
|
|
1797
|
+
fieldName: name,
|
|
1798
|
+
newValue
|
|
1799
|
+
});
|
|
1800
|
+
skipNextOnChangeRef.current = true;
|
|
1801
|
+
setValue(newValue);
|
|
1802
|
+
}
|
|
1803
|
+
}, [name, currentValue, setValue]);
|
|
1804
|
+
const shouldSkipOnChange = useCallback2(() => {
|
|
1805
|
+
if (skipNextOnChangeRef.current) {
|
|
1806
|
+
skipNextOnChangeRef.current = false;
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
return false;
|
|
1810
|
+
}, []);
|
|
1811
|
+
return {
|
|
1812
|
+
setValue,
|
|
1813
|
+
shouldSkipOnChange,
|
|
1814
|
+
value
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
// src/client/component/input.tsx
|
|
1819
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
1820
|
+
function Input(props) {
|
|
1821
|
+
const entity = props.field.advanced?.entity;
|
|
1822
|
+
const store4 = useStore();
|
|
1823
|
+
const setTimeoutRef = useTimeout();
|
|
1824
|
+
const [, startTransition3] = useTransition();
|
|
1825
|
+
const { setValue, shouldSkipOnChange, value } = useValue(
|
|
1826
|
+
props.field,
|
|
1827
|
+
props.value
|
|
1828
|
+
);
|
|
1829
|
+
const valueRef = useRef3(value);
|
|
1830
|
+
valueRef.current = value;
|
|
1831
|
+
const translationsRef = useRef3(props.translations);
|
|
1832
|
+
translationsRef.current = props.translations;
|
|
1833
|
+
const hasTextable = isTextable(props.field);
|
|
1834
|
+
const hasClickable = isClickable(props.field);
|
|
1835
|
+
const setValues = useSetAtom(valueAtom);
|
|
1836
|
+
const setFieldStates = useSetAtom(fieldStateAtom);
|
|
1837
|
+
const setErrors = useSetAtom(reportInputErrorAtom(props.field.name));
|
|
1838
|
+
const [data, setSource] = useDataSource(props.field, props.config, value);
|
|
1839
|
+
const schema = useInput(
|
|
1840
|
+
props.field,
|
|
1841
|
+
props.onMount,
|
|
1842
|
+
props.onUnmount,
|
|
1843
|
+
props.translations
|
|
1844
|
+
);
|
|
1845
|
+
const placeholder = translate(
|
|
1846
|
+
props.commonProps.placeholder,
|
|
1847
|
+
props.translations
|
|
1848
|
+
);
|
|
1849
|
+
const commonProps = {
|
|
1850
|
+
...props.commonProps,
|
|
1851
|
+
placeholder
|
|
1852
|
+
};
|
|
1853
|
+
const { commonPropsWithOptions, defaultValue } = prepareInputProps(
|
|
1854
|
+
props.field,
|
|
1855
|
+
commonProps,
|
|
1856
|
+
data,
|
|
1857
|
+
value
|
|
1858
|
+
);
|
|
1859
|
+
const onValueChangeRef = useRef3(null);
|
|
1860
|
+
onValueChangeRef.current = (value2) => {
|
|
1861
|
+
setValue(value2);
|
|
1862
|
+
if (props.onValueChange) {
|
|
1863
|
+
props.onValueChange({ name: props.field.name, value: value2 });
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
const inputProps = prepareInputValue(props.field, defaultValue);
|
|
1867
|
+
const validated = useCallback3(
|
|
1868
|
+
(value2) => {
|
|
1869
|
+
const results = schema.safeParse(value2);
|
|
1870
|
+
const errors = results.error?.issues.map((issue) => issue.message) ?? [];
|
|
1871
|
+
const custom = props.field.validation?.custom;
|
|
1872
|
+
const customErrors = custom ? validateCustom(
|
|
1873
|
+
value2,
|
|
1874
|
+
custom,
|
|
1875
|
+
(name) => store4.get(reportValueAtom(name)),
|
|
1876
|
+
translationsRef.current
|
|
1877
|
+
) : [];
|
|
1878
|
+
setErrors([...errors, ...customErrors]);
|
|
1879
|
+
},
|
|
1880
|
+
[props.field.validation?.custom, schema, setErrors, store4]
|
|
1881
|
+
);
|
|
1882
|
+
const handleTriggerEvent = useCallback3(
|
|
1883
|
+
(value2, callback) => {
|
|
1884
|
+
if (hasTextable) {
|
|
1885
|
+
setTimeoutRef(() => {
|
|
1886
|
+
callback({ value: value2 });
|
|
1887
|
+
}, 500);
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
const currentValue = getEntity(value2, data, entity);
|
|
1891
|
+
callback(currentValue);
|
|
1892
|
+
},
|
|
1893
|
+
[data, entity, hasTextable, setTimeoutRef]
|
|
1894
|
+
);
|
|
1895
|
+
const onChange = useCallback3(
|
|
1896
|
+
(event) => {
|
|
1897
|
+
const inputValue = event.target.value;
|
|
1898
|
+
logger.info("onChange fired", {
|
|
1899
|
+
fieldName: props.field.name,
|
|
1900
|
+
fieldType: props.field.type,
|
|
1901
|
+
inputValue,
|
|
1902
|
+
currentValue: valueRef.current,
|
|
1903
|
+
hasTextable,
|
|
1904
|
+
hasClickable
|
|
1905
|
+
});
|
|
1906
|
+
if (!hasClickable && shouldSkipOnChange()) {
|
|
1907
|
+
logger.info("shouldSkipOnChange returned true", {
|
|
1908
|
+
fieldName: props.field.name,
|
|
1909
|
+
willSkip: !hasTextable || inputValue === valueRef.current,
|
|
1910
|
+
reason: !hasTextable ? "not textable (checkbox/radio/select)" : "value unchanged"
|
|
1911
|
+
});
|
|
1912
|
+
if (!hasTextable || inputValue === valueRef.current) {
|
|
1913
|
+
logger.info("SKIPPING onChange", { fieldName: props.field.name });
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
logger.info("onChange processing", {
|
|
1918
|
+
fieldName: props.field.name,
|
|
1919
|
+
inputValue
|
|
1920
|
+
});
|
|
1921
|
+
onValueChangeRef.current?.(inputValue);
|
|
1922
|
+
if (props.config.validation.change) {
|
|
1923
|
+
validated(inputValue);
|
|
1924
|
+
}
|
|
1925
|
+
const events = props.field.event?.change;
|
|
1926
|
+
if (events) {
|
|
1927
|
+
handleTriggerEvent(inputValue, (selected) => {
|
|
1928
|
+
handleProxyEvent(events, ({ sources, states, values }) => {
|
|
1929
|
+
startTransition3(() => {
|
|
1930
|
+
handleSourceEvent(
|
|
1931
|
+
selected,
|
|
1932
|
+
sources,
|
|
1933
|
+
(target, source) => setSource(target, source)
|
|
1934
|
+
);
|
|
1935
|
+
handleStateEvent(selected, states, (target, state) => {
|
|
1936
|
+
setFieldStates((prev) => {
|
|
1937
|
+
if (state) {
|
|
1938
|
+
return { ...prev, [target]: state };
|
|
1939
|
+
}
|
|
1940
|
+
const { [target]: _removed, ...rest } = prev;
|
|
1941
|
+
return rest;
|
|
1942
|
+
});
|
|
1943
|
+
});
|
|
1944
|
+
handleValueEvent(selected, values, (target, value2) => {
|
|
1945
|
+
setValues((prev) => ({
|
|
1946
|
+
...prev,
|
|
1947
|
+
[target]: value2
|
|
1948
|
+
}));
|
|
1949
|
+
});
|
|
1950
|
+
});
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
},
|
|
1955
|
+
[
|
|
1956
|
+
handleTriggerEvent,
|
|
1957
|
+
hasClickable,
|
|
1958
|
+
hasTextable,
|
|
1959
|
+
props.config.validation.change,
|
|
1960
|
+
props.field.event?.change,
|
|
1961
|
+
props.field.name,
|
|
1962
|
+
props.field.type,
|
|
1963
|
+
setFieldStates,
|
|
1964
|
+
setSource,
|
|
1965
|
+
setValues,
|
|
1966
|
+
shouldSkipOnChange,
|
|
1967
|
+
validated
|
|
1968
|
+
]
|
|
1969
|
+
);
|
|
1970
|
+
const onBlur = useCallback3(
|
|
1971
|
+
(event) => {
|
|
1972
|
+
if (!hasClickable) {
|
|
1973
|
+
const value2 = event.target.value;
|
|
1974
|
+
if (props.config.validation.blur) {
|
|
1975
|
+
validated(value2);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
},
|
|
1979
|
+
[hasClickable, props.config.validation.blur, validated]
|
|
1980
|
+
);
|
|
1981
|
+
return renderIfExists(props.config.inputs[props.field.type], (Component) => /* @__PURE__ */ jsx21(
|
|
1982
|
+
InputGroup,
|
|
1983
|
+
{
|
|
1984
|
+
config: props.config,
|
|
1985
|
+
context: props.context,
|
|
1986
|
+
field: props.field,
|
|
1987
|
+
orientation: props.orientation,
|
|
1988
|
+
translations: props.translations,
|
|
1989
|
+
children: /* @__PURE__ */ jsx21(
|
|
1990
|
+
Component,
|
|
1991
|
+
{
|
|
1992
|
+
...commonPropsWithOptions,
|
|
1993
|
+
...props.ariaAttributes,
|
|
1994
|
+
...props.dataAttributes,
|
|
1995
|
+
...inputProps,
|
|
1996
|
+
onBlur,
|
|
1997
|
+
onChange
|
|
1998
|
+
}
|
|
1999
|
+
)
|
|
2000
|
+
}
|
|
2001
|
+
));
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
// src/component/column.tsx
|
|
2005
|
+
import { twMerge as twMerge6 } from "tailwind-merge";
|
|
2006
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
|
2007
|
+
function Column(props) {
|
|
2008
|
+
const cols2 = getColumn(props.column?.advanced?.cols);
|
|
2009
|
+
return /* @__PURE__ */ jsx22("div", { className: "flex w-full flex-col gap-4", children: /* @__PURE__ */ jsx22("div", { className: twMerge6("grid grid-cols-1 gap-3 sm:gap-4", cols2), children: props.children }) });
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// src/component/slot/slot-base.tsx
|
|
2013
|
+
import { Fragment as Fragment4 } from "react";
|
|
2014
|
+
import { jsx as jsx23, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2015
|
+
function SlotBase(props) {
|
|
2016
|
+
const { column: Column2, field: Field3 } = props.components;
|
|
2017
|
+
return prepare(props.fields).map((field, index) => /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
2018
|
+
isColumn(field) && /* @__PURE__ */ jsx23(Column2, { column: field, children: /* @__PURE__ */ jsx23(SlotBase, { ...props, fields: field.fields }) }),
|
|
2019
|
+
isField(field) && /* @__PURE__ */ jsx23(Field3, { disabled: props.disabled, field, style: props.style, children: props.children })
|
|
2020
|
+
] }, index));
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
// src/component/slot/slot-create.tsx
|
|
2024
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2025
|
+
function createSlot(Field3) {
|
|
2026
|
+
const CreateSlot = (props) => /* @__PURE__ */ jsx24(SlotBase, { ...props, components: { column: Column, field: Field3 } });
|
|
2027
|
+
return CreateSlot;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
// src/client/hook/use-form-action.ts
|
|
2031
|
+
import { useSetAtom as useSetAtom2 } from "jotai";
|
|
2032
|
+
import { startTransition, useActionState } from "react";
|
|
2033
|
+
function useFormState(getSchema2, action, options) {
|
|
2034
|
+
const { onSuccess, preserveValues = false, validation = true } = options ?? {};
|
|
2035
|
+
const setError = useSetAtom2(reportErrorAtom);
|
|
2036
|
+
const clearValues = useSetAtom2(clearAllValueAtom);
|
|
2037
|
+
const initialState = {
|
|
2038
|
+
data: null,
|
|
2039
|
+
error: null,
|
|
2040
|
+
success: false
|
|
2041
|
+
};
|
|
2042
|
+
const [state, formAction, isPending] = useActionState(
|
|
2043
|
+
async (prevState, formData) => {
|
|
2044
|
+
const [schemas, fields] = getSchema2();
|
|
2045
|
+
const schema = buildSchema(schemas, fields, options?.translations);
|
|
2046
|
+
if (validation === false) {
|
|
2047
|
+
if (action) {
|
|
2048
|
+
return await action(formData, schema);
|
|
2049
|
+
}
|
|
2050
|
+
return prevState;
|
|
2051
|
+
}
|
|
2052
|
+
const form = getFormData(formData);
|
|
2053
|
+
const validated = schema.safeParse(form);
|
|
2054
|
+
if (!validated.success) {
|
|
2055
|
+
const errors = flatten(validated.error);
|
|
2056
|
+
startTransition(() => {
|
|
2057
|
+
setError(errors);
|
|
2058
|
+
});
|
|
2059
|
+
return failure(form, {
|
|
2060
|
+
description: "Please correct the errors and try again.",
|
|
2061
|
+
details: [],
|
|
2062
|
+
title: "There were validation errors submitting the form."
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
if (action) {
|
|
2066
|
+
try {
|
|
2067
|
+
const result = await action(form, schema);
|
|
2068
|
+
if (!result.success) {
|
|
2069
|
+
return failure(form, result.error);
|
|
2070
|
+
}
|
|
2071
|
+
onSuccess?.(result.data);
|
|
2072
|
+
if (!preserveValues) {
|
|
2073
|
+
startTransition(() => {
|
|
2074
|
+
clearValues();
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
return success(form, preserveValues);
|
|
2078
|
+
} catch (error) {
|
|
2079
|
+
logger.error("Error executing form action:", error);
|
|
2080
|
+
return failure(form, {
|
|
2081
|
+
title: "An unexpected error occurred submitting the form.",
|
|
2082
|
+
details: buildError(error)
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
return success(validated.data, preserveValues);
|
|
2087
|
+
},
|
|
2088
|
+
initialState
|
|
2089
|
+
);
|
|
2090
|
+
return [formAction, state, isPending];
|
|
2091
|
+
}
|
|
2092
|
+
function buildError(error) {
|
|
2093
|
+
const detail = error instanceof Error ? error.message : ["Unknown error"];
|
|
2094
|
+
return Array.isArray(detail) ? detail : [detail];
|
|
2095
|
+
}
|
|
2096
|
+
function success(value, preserveValues = false) {
|
|
2097
|
+
const data = preserveValues ? value : null;
|
|
2098
|
+
return {
|
|
2099
|
+
data,
|
|
2100
|
+
error: null,
|
|
2101
|
+
success: true
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
function failure(value, error) {
|
|
2105
|
+
return {
|
|
2106
|
+
data: value,
|
|
2107
|
+
error,
|
|
2108
|
+
success: false
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/client/hook/use-schema.ts
|
|
2113
|
+
import { startTransition as startTransition2, useCallback as useCallback5, useRef as useRef4 } from "react";
|
|
2114
|
+
|
|
2115
|
+
// src/client/hook/use-store.ts
|
|
2116
|
+
import { useCallback as useCallback4 } from "react";
|
|
2117
|
+
import { useSetAtom as useSetAtom3 } from "jotai";
|
|
2118
|
+
function useStore2() {
|
|
2119
|
+
const clearErrors = useSetAtom3(clearInputErrorAtom);
|
|
2120
|
+
const clearSources = useSetAtom3(clearInputSourceAtom);
|
|
2121
|
+
const clearValues = useSetAtom3(clearInputValueAtom);
|
|
2122
|
+
return useCallback4(
|
|
2123
|
+
(names) => {
|
|
2124
|
+
const target = Array.isArray(names) ? names : [names];
|
|
2125
|
+
clearErrors(target);
|
|
2126
|
+
clearSources(target);
|
|
2127
|
+
clearValues(target);
|
|
2128
|
+
},
|
|
2129
|
+
[clearErrors, clearSources, clearValues]
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
// src/client/hook/use-schema.ts
|
|
2134
|
+
function useSchema() {
|
|
2135
|
+
const clear = useStore2();
|
|
2136
|
+
const schemaRef = useRef4({});
|
|
2137
|
+
const fieldsRef = useRef4([]);
|
|
2138
|
+
const pendingUnmounts = useRef4(/* @__PURE__ */ new Set());
|
|
2139
|
+
const onMount = useCallback5((name, schema, field) => {
|
|
2140
|
+
if (!(name in schemaRef.current)) {
|
|
2141
|
+
schemaRef.current[name] = schema;
|
|
2142
|
+
fieldsRef.current.push(field);
|
|
2143
|
+
}
|
|
2144
|
+
}, []);
|
|
2145
|
+
const onUnmount = useCallback5(
|
|
2146
|
+
(name) => {
|
|
2147
|
+
if (schemaRef.current[name]) {
|
|
2148
|
+
delete schemaRef.current[name];
|
|
2149
|
+
fieldsRef.current = fieldsRef.current.filter((field) => {
|
|
2150
|
+
return field.name !== name;
|
|
2151
|
+
});
|
|
2152
|
+
pendingUnmounts.current.add(name);
|
|
2153
|
+
startTransition2(() => {
|
|
2154
|
+
if (pendingUnmounts.current.size > 0) {
|
|
2155
|
+
clear(Array.from(pendingUnmounts.current));
|
|
2156
|
+
pendingUnmounts.current.clear();
|
|
2157
|
+
}
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
},
|
|
2161
|
+
[clear]
|
|
2162
|
+
);
|
|
2163
|
+
function getSchema2() {
|
|
2164
|
+
return [schemaRef.current, fieldsRef.current];
|
|
2165
|
+
}
|
|
2166
|
+
return [getSchema2, onMount, onUnmount];
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
// src/client/component/form-content.tsx
|
|
2170
|
+
import { Fragment as Fragment5, jsx as jsx25, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2171
|
+
var Slot = createSlot(Field2);
|
|
2172
|
+
function FormContent(props) {
|
|
2173
|
+
const translations = props.translations?.[props.lang ?? ""];
|
|
2174
|
+
const [schema, onMount, onUnmount] = useSchema();
|
|
2175
|
+
const [action, state, isPending] = useFormState(schema, props.action, {
|
|
2176
|
+
onSuccess: props.onSuccess,
|
|
2177
|
+
validation: props.config.validation.submit,
|
|
2178
|
+
translations
|
|
2179
|
+
});
|
|
2180
|
+
const isShowingError = props.config.validation.showError && !state.success && state.error;
|
|
2181
|
+
const value = state.data ?? props.value;
|
|
2182
|
+
return /* @__PURE__ */ jsxs9(Fragment5, { children: [
|
|
2183
|
+
isShowingError && renderIfExists(props.config.alert, (Alert) => /* @__PURE__ */ jsx25("div", { className: "mb-4 w-full", children: /* @__PURE__ */ jsx25(
|
|
2184
|
+
Alert,
|
|
2185
|
+
{
|
|
2186
|
+
description: state.error?.description,
|
|
2187
|
+
details: state.error?.details,
|
|
2188
|
+
title: state.error.title
|
|
2189
|
+
}
|
|
2190
|
+
) })),
|
|
2191
|
+
/* @__PURE__ */ jsx25(
|
|
2192
|
+
Form,
|
|
2193
|
+
{
|
|
2194
|
+
action,
|
|
2195
|
+
config: props.config,
|
|
2196
|
+
control: props.children,
|
|
2197
|
+
definition: props.definition,
|
|
2198
|
+
isPending,
|
|
2199
|
+
noValidate: true,
|
|
2200
|
+
readOnly: props.readOnly,
|
|
2201
|
+
sections: props.sections,
|
|
2202
|
+
children: ({ disabled, fields }) => /* @__PURE__ */ jsx25(Slot, { disabled, fields, style: props.config.style, children: (internal) => /* @__PURE__ */ jsx25(
|
|
2203
|
+
Input,
|
|
2204
|
+
{
|
|
2205
|
+
...internal,
|
|
2206
|
+
config: props.config,
|
|
2207
|
+
context: props.context,
|
|
2208
|
+
onMount,
|
|
2209
|
+
onUnmount,
|
|
2210
|
+
onValueChange: props.onValueChange,
|
|
2211
|
+
translations,
|
|
2212
|
+
value
|
|
2213
|
+
}
|
|
2214
|
+
) })
|
|
2215
|
+
}
|
|
2216
|
+
)
|
|
2217
|
+
] });
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
// src/client/component/form.tsx
|
|
2221
|
+
import { Provider } from "jotai";
|
|
2222
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
2223
|
+
function Form2(props) {
|
|
2224
|
+
return /* @__PURE__ */ jsx26(Provider, { children: /* @__PURE__ */ jsx26(FormContent, { ...props }) });
|
|
2225
|
+
}
|
|
2226
|
+
export {
|
|
2227
|
+
Form2 as Form
|
|
2228
|
+
};
|