react-luna-form 0.0.26 → 0.0.27
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 +2741 -1
- package/dist/client/esm/index.js +2708 -1
- package/dist/config/cjs/index.js +229 -1
- package/dist/config/esm/index.js +206 -1
- package/dist/server/cjs/index.js +1446 -1
- package/dist/server/esm/index.js +1423 -1
- package/dist/types/luna-core/src/handle/state-event.d.ts +1 -1
- package/dist/types/luna-core/src/index.d.ts +1 -0
- package/dist/types/luna-core/src/type.d.ts +16 -2
- package/dist/types/luna-core/src/util/constant.d.ts +4 -0
- package/dist/types/luna-core/src/util/extract.d.ts +2 -1
- package/dist/types/luna-core/src/util/is-input.d.ts +4 -3
- package/dist/types/luna-core/src/util/is-type.d.ts +1 -0
- package/dist/types/luna-core/src/util/list.d.ts +4 -0
- package/dist/types/luna-core/src/util/prepare.d.ts +2 -2
- package/dist/types/luna-core/src/util/string.d.ts +1 -0
- package/dist/types/luna-react/src/client/component/field/field-list.d.ts +2 -0
- package/dist/types/luna-react/src/client/component/{wrapper/with-error.d.ts → field/field-with-error.d.ts} +1 -1
- package/dist/types/luna-react/src/client/component/{wrapper/with-field-state.d.ts → field/field-with-state.d.ts} +1 -1
- package/dist/types/luna-react/src/client/component/guard/list-guard.d.ts +2 -0
- package/dist/types/luna-react/src/client/component/guard/visibility-guard.d.ts +6 -0
- package/dist/types/luna-react/src/client/component/slot/slot.d.ts +7 -0
- package/dist/types/luna-react/src/client/hook/use-field-list.d.ts +2 -0
- package/dist/types/luna-react/src/component/column.d.ts +2 -3
- package/dist/types/luna-react/src/component/field/field-base.d.ts +4 -2
- package/dist/types/luna-react/src/component/field/field-horizontal.d.ts +2 -8
- package/dist/types/luna-react/src/component/field/field-list-item.d.ts +8 -0
- package/dist/types/luna-react/src/component/field/field-list.d.ts +7 -0
- package/dist/types/luna-react/src/component/field/field-set-advanced.d.ts +5 -0
- package/dist/types/luna-react/src/component/field/field-set-base.d.ts +7 -0
- package/dist/types/luna-react/src/component/field/field-vertical.d.ts +2 -8
- package/dist/types/luna-react/src/component/list.d.ts +5 -0
- package/dist/types/luna-react/src/component/slot/list-slot.d.ts +2 -0
- package/dist/types/luna-react/src/component/slot/slot-base.d.ts +8 -6
- package/dist/types/luna-react/src/component/slot/slot-create.d.ts +4 -3
- package/dist/types/luna-react/src/component/slot/slot-list.d.ts +12 -0
- package/dist/types/luna-react/src/component/slot/slot.d.ts +1 -0
- package/package.json +5 -5
- package/dist/types/luna-react/src/component/input/input-attributes.d.ts +0 -3
- package/dist/types/luna-react/src/component/input/input-common.d.ts +0 -2
- package/dist/types/luna-react/src/component/input/input-option-select.d.ts +0 -5
- /package/dist/types/luna-react/src/client/component/{wrapper/index.d.ts → field/field.d.ts} +0 -0
package/dist/client/cjs/index.js
CHANGED
|
@@ -1 +1,2741 @@
|
|
|
1
|
-
"use strict";var lo=Object.create;var ye=Object.defineProperty;var so=Object.getOwnPropertyDescriptor;var co=Object.getOwnPropertyNames;var uo=Object.getPrototypeOf,fo=Object.prototype.hasOwnProperty;var mo=(e,t)=>{for(var n in t)ye(e,n,{get:t[n],enumerable:!0})},mt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of co(t))!fo.call(e,o)&&o!==n&&ye(e,o,{get:()=>t[o],enumerable:!(r=so(t,o))||r.enumerable});return e};var po=(e,t,n)=>(n=e!=null?lo(uo(e)):{},mt(t||!e||!e.__esModule?ye(n,"default",{value:e,enumerable:!0}):n,e)),go=e=>mt(ye({},"__esModule",{value:!0}),e);var Ai={};mo(Ai,{Form:()=>Qr});module.exports=go(Ai);var Xe=require("react/jsx-runtime");function pt(e){return!e.errors||e.errors.length===0?null:(0,Xe.jsx)("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)=>(0,Xe.jsx)("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}var be="input",gt="input/email",yt="input/number";var bt="textarea",xt="radio",ht="checkbox",Tt="select",Rt="select/month",St="select/year";var He="column";var At="label",q="value",xe="options",$e="email",Ct="number",Et="password",Ft="tel",le="text",Nt="aria-errormessage",vt="aria-invalid",kt="data-invalid",It="data-readonly",wt="aria",Pt="data",he="min",Te="max",Ot="minLength",Vt="maxLength",Z="$ref";var Dt="source",Lt="state",Re="http://luna.internal",P="vertical",W="horizontal";function d(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function Se(e){return e==null||e===""}function O(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function F(e){return typeof e=="string"}function Mt(e){return d(e)&&"url"in e}var yo=/[^/]+$/;function _t(e,t=[],n=q){if(Array.isArray(t))return t.find(r=>{let o=qe(r,n);if(o!==void 0&&`${o}`===e)return r})??{value:e}}function qe(e,t=q){if(e!=null){if(O(e))return e;if(d(e)){let n=bo(e,t);if(O(n))return n}}}function bo(e,t){let n=R(e,t);if(O(n))return n}function Ut(e,t){if(Array.isArray(e))return e;let n=R(e,t);return Array.isArray(n)?n:null}function R(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 Bt(e,t={label:At,value:q}){return e.map(n=>{if(d(n)){let r=R(n,t.label),o=R(n,t.value);if(O(r)&&O(o))return{label:`${r}`,value:`${o}`}}return n})}function Gt(e=le){if(e){let t=e.match(yo);if(t){let[n]=t;if(n!==be)return n.trim().toLowerCase()}}return le}function Yt(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 xo=/\[([^\]]+)\]\(([^)]+)\)/g;function S(e,t={}){if(F(e))return ho(e,t);if(Array.isArray(e))return e.map(n=>S(n,t));if(d(e)){let n={};for(let r in e)n[r]=S(e[r],t);return n}return e}function M(e){return F(e)?/{([^}]+)}/.test(e):Array.isArray(e)?e.some(t=>M(t)):d(e)?Object.values(e).some(t=>M(t)):!1}function ho(e,t={}){return e.replace(/{([^}]+)}/g,(n,r)=>{let o=r.includes(".")?R(t,r):t[r];return O(o)?String(o):n})}function Xt(e,t){if(!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=xo.exec(e))!==null;){let[a,l,s]=n,c=n.index;o=!0,c>r&&i.push(e.substring(r,c));let u=t?t(c,s,l):a;i.push(u),r=c+a.length}return o?(r<e.length&&i.push(e.substring(r)),i):e}var se={error:(...e)=>{Ze()&&!We()&&Ae().error("[Luna Form]",...e)},warn:(...e)=>{Ze()&&!We()&&Ae().warn("[Luna Form]",...e)},info:(...e)=>{Ze()&&!We()&&Ae().info("[Luna Form]",...e)}},Ze=()=>typeof Ae()<"u",We=()=>!0,Ae=()=>globalThis.console;function Ht(e=[],t){let n=[],r=[],o=[];e.forEach(i=>{i.action===q&&n.push(i),i.action===Dt&&r.push(i),i.action===Lt&&o.push(i)}),t({sources:r,states:o,values:n})}function $t(e=null,t=[],n){t.forEach(r=>{let{target:o,source:i}=r;if(!e){n(o,void 0);return}if(Mt(i)){let a=S(i.url,e),l=i.body?S(i.body,e):i.body;n(o,{...i,url:a,body:l})}})}var ce={eq:Co,gt:vo,gte:ko,in:Fo,lt:Io,lte:wo,neq:Eo,nin:No},To=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,qt=/^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;function Ro(e){return typeof e=="string"&&To.test(e)}function So(e){return typeof e=="string"&&qt.test(e)}function Ao(e){let t=e.match(qt);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 Ro(e)?new Date(e).getTime():So(e)?Ao(e):Number(e)}function Co(e,t){return e===t}function Eo(e,t){return e!==t}function Fo(e,t){return Array.isArray(t)&&t.includes(String(e))}function No(e,t){return Array.isArray(t)&&!t.includes(String(e))}function vo(e,t){return V(e)>V(t)}function ko(e,t){return V(e)>=V(t)}function Io(e,t){return V(e)<V(t)}function wo(e,t){return V(e)<=V(t)}function Zt(e=null,t=[],n){t.forEach(r=>{let{target:o,state:i,when:a}=r;if(!e){n(o);return}let l=Po(e,a);n(o,l?i:void 0)})}function Po(e,t){if(t===void 0)return!0;if(F(t))return ze(e,"value")===t;if(Array.isArray(t)){let n=ze(e,"value");return t.includes(String(n))}return Oo(e,t)}function Oo(e=null,t){let n=ze(e,t.field??"value"),{operator:r="eq",value:o}=t,i=ce[r];return i?i(n,o):!1}function ze(e,t){return d(e)?t.includes(".")?R(e,t):e[t]:e}function Wt(e=null,t=[],n){t.forEach(r=>{Object.entries(r.value).forEach(([o,i])=>{n(o,e?S(i,e):void 0)})})}var Ce=e=>A(Rt)(e),Ee=e=>A(St)(e),b=A(ht),Ke=A(be),N=A(xt),v=A(Tt),je=A(bt),zt=A(le,$e,Et,Ft),Kt=A(gt,$e),Fe=A(yt,Ct);function Ne(e){return N(e)||b(e)}function jt(e){return e.type===He}function Jt(e){return e.type!==He}function Qt(e){return v(e)||N(e)}function en(e){return Ke(e)||je(e)}function ue(e){return e!=null&&e!==""}function A(...e){return t=>{let n=F(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function tn(e,t={}){if(v(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&d(n))return[n]}}function nn(e){return N(e)||b(e)?W:e.advanced?.orientation??P}function rn(e){return b(e)?e.advanced?.reverse!==!1:!1}function on(e,t){let n=e.readonly??!1;return t||n}function an(e){if(N(e)||v(e)&&!e.disabled){let t=e.source;if(Array.isArray(t)||d(t)&&!(Z in t))return t}}var Vo=/^\d+$/;function ln(){return Array.from({length:12},(e,t)=>({value:(t+1).toString(),label:new Date(0,t).toLocaleString("default",{month:"long"})}))}function sn(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 Je(){return new Date().getFullYear()}function Qe(e,t){if(typeof e=="number")return e;let n=t??Je(),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 Vo.test(r)?parseInt(r,10):n}var ve=Je();function Do(e){if(v(e))return Lo(e)}function Lo(e){if(Ce(e))return ln();if(Ee(e)){let t=e.advanced?.length?.min??ve,n=e.advanced?.length?.max??ve+5;return sn(Qe(t,ve),Qe(n,ve))}}function cn(e,t=!1){let n={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return Ke(e)?{...n,...Mo(e)}:v(e)?{...n,..._o(e)}:je(e)?{...n,...Uo(e)}:n}function Mo(e){let t=Gt(e.type),n={...e,type:t};return{...un(e),...Bo(n),...zt(n)?dn(n):{},type:t}}function _o(e){let t=Do(e);return t?{options:t}:{}}function Uo(e){return{...un(e),...dn(e)}}function un(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Bo(e){return Fe(e)?Go(e):{}}function dn(e){return fn(e,{min:Ot,max:Vt})}function Go(e){return fn(e,{min:he,max:Te})}function fn(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 mn(e,t){let n=an(e);return n||tn(e,t)}function Yo(e,t){let n=d(t)&&e.name in t?t[e.name]:t;return qe(n,e.advanced?.entity)}function Xo(e,t,n){return Qt(e)&&Array.isArray(n)?{...t,[xe]:n}:t}function Ho(e,t,n){if(e.required&&!ue(n)&&v(e)&&e.advanced?.preselected!==!1&&xe in t){let r=t[xe];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function $o(e,t){return v(e)&&Array.isArray(t)?Bt(t,e.advanced?.options):t}function pn(e,t,n,r){let o=Yo(e,r),i=Array.isArray(n)?$o(e,n):n,a=Xo(e,t,i),l=Ho(e,a,o);return{commonPropsWithOptions:a,defaultValue:l}}function gn(e,t){return b(e)?{checked:ue(t)?t:!1}:{value:t??""}}var qo=/^#\/definition\//;function Ie(e=[],t){let n=ke(e,t);return Array.isArray(n)?n.sort((r,o)=>yn(r)-yn(o)):[]}function ke(e,t,n=new Map,r=new WeakSet){if(!Zo(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=>ke(i,t,n,r));if(Z in e&&F(e[Z])){let i=e[Z].replace(qo,""),a=R(t,i);return a!==null?ke(a,t,n,r):e}let o={};for(let[i,a]of Object.entries(e))o[i]=ke(a,t,n,r);return r.delete(e),n.set(e,o),o}function bn(e){return Object.entries(e??{})}function yn(e){return e.order??Number.MAX_VALUE}function Zo(e){return e!==void 0&&d(e)&&Object.keys(e).length>0}function xn(e,t){let n={};for(let[r,o]of bn(t))n[`${e}-${r}`]=o;return n}function Wo(e){return xn(wt,e)}function zo(e){return xn(Pt,e)}function hn(e,t){let n=Wo(e.advanced?.aria);return t&&t.length>0&&(n[vt]="true",n[Nt]=`${e.name}-error`),n}function Tn(e){return zo(e.advanced?.data)}var Rn={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},Sn={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function An(e,t=2){return Rn[e&&e in Rn?e:t]}function Cn(e){if(e&&e in Sn)return Sn[e]}var f=require("zod");function m(e,t){return e?t?t[e]??e:e:""}var Ko=[[Fe,ti],[Kt,jo],[Ee,ni],[Ce,ri],[b,Jo],[N,Qo]];function Fn(e,t=[],n){let r=f.z.object(e);return t.length===0?r:li(r,t,n)}function Nn(e){let t={},n=f.z.flattenError(e).fieldErrors;for(let[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t}function vn(e,t){for(let[n,r]of Ko)if(n(e))return r(e,t);return ei(e,t)}function jo(e,t){let n=f.z.string().trim();if(e.required){let r=z(e,t),o=n.min(1,r).pipe(En(e,t));return f.z.preprocess(i=>Se(i)?"":i,o)}return n.pipe(En(e,t)).or(f.z.literal("")).nullable()}function Jo(e,t){let n=f.z.coerce.boolean();return e.required?(n=n.refine(r=>r===!0,{message:z(e,t)}),f.z.preprocess(r=>r===null?!1:r,n)):n.nullable()}function Qo(e,t){let n=f.z.coerce.string();return e.required?(n=n.min(1,z(e,t)),f.z.preprocess(r=>Se(r)?"":r,n)):n.or(f.z.literal("")).nullable()}function ei(e,t){let n=f.z.coerce.string().trim();return n=kn(n,e,t),e.required?(n=In(n,e,t),f.z.preprocess(r=>Se(r)?"":r,n)):n.nullable()}function ti(e,t){let n=f.z.coerce.number().int();return n=kn(n,e,t),e.required?(n=In(n,e,t),f.z.preprocess(r=>r===null?void 0:r,n)):n.nullable()}function ni(e,t){return e.required?f.z.preprocess(oi,f.z.coerce.number({message:z(e,t)}).int()):f.z.coerce.number().int().nullable()}function ri(e,t){let n=z(e,t),r=f.z.coerce.number().int().min(1,n).max(12,n);return e.required?r:r.nullable()}function oi(e){return e===null||e===""?void 0:e}function En(e,t){let n=e.validation?.email?m(e.validation?.email,t):void 0;return f.z.email(n)}function kn(e,t,n){return e=ii(e,t,n),e=ai(e,t,n),e}function In(e,t,n){let r=t.advanced?.length?.min;return r===void 0||r<1?e.min(1,z(t,n)):e}var ii=(e,t,n)=>wn(e,t,he,n),ai=(e,t,n)=>wn(e,t,Te,n);function wn(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 li(e,t=[],n){let r=ci(t);return r.length===0?e:e.superRefine((o,i)=>{for(let{name:a,rule:l}of r)if(!si(o,a,l)){let s=m(l.message,n);i.addIssue({code:"custom",message:s,path:[a]})}})}function si(e,t,n){let r=n.operator??"eq",o=ce[r];return o?o(e[t],e[n.field]):!1}function ci(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 Pn(e,t,n,r){let o=[],i=Array.isArray(t)?t:[t];for(let a of i){let l=a.operator??"eq",s=ce[l];if(s&&!s(e,n(a.field))&&a.message){let c=m(a.message,r);o.push(c)}}return o}function z(e,t){return e.validation?.required?m(e.validation?.required,t):void 0}function On(e,t){if(!t||!di(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||ui(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 ui(e){return e==="https"?"443":"80"}function di(e){return/^(https?:)?\/\//.test(e)}function Vn(e,t){try{if(!e)return t;if(!t)return e;let n=new URL(e,Re);new URL(t,Re).searchParams.forEach((i,a)=>{n.searchParams.set(a,i)});let o=n.toString();return e.startsWith("/")||!e.includes("://")?o.replace(Re,""):o}catch{return t||e}}function Dn(e){return!Array.isArray(e)||e.length===0?null:e.reduce((t,n)=>{let r=Vn(t.url,n.url),o=fi(t,n),i=mi(t,n);return{...t,...n,url:r,body:o,headers:i}})}function fi(e,t){return d(t.body)&&d(e?.body)?{...e.body,...t.body}:t.body??e?.body}function mi(e,t){return d(t.headers)&&d(e?.headers)?{...e.headers,...t.headers}:t.headers??e?.headers}function we(e,t){return{...e,...t}}var Ln=require("tailwind-merge"),Mn=require("react/jsx-runtime");function Pe(e){let t=e.errors&&e.errors.length>0;return(0,Mn.jsx)("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[kt]:"true"},...e.disabled&&{[It]:"true"},"data-orientation":e.orientation,className:(0,Ln.twMerge)("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})}var _n=require("tailwind-merge"),Bn=require("react/jsx-runtime");function Un(e){return(0,Bn.jsx)(Pe,{...e,orientation:P,className:(0,_n.twMerge)("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}var Gn=require("tailwind-merge"),Xn=require("react/jsx-runtime");function Yn(e){return(0,Xn.jsx)(Pe,{...e,orientation:W,className:(0,Gn.twMerge)("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})}var et=require("react/jsx-runtime");function Hn(e){let t=Ne(e.field),n=b(e.field),r=rn(e.field);return e.orientation===P?(0,et.jsx)(Un,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):(0,et.jsx)(Yn,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function $n(e){if(!e.field.type)return null;let t=cn(e.field,e.disabled),n=Tn(e.field),r=hn(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,orientation:e.orientation})}var qn=require("tailwind-merge"),K=require("react/jsx-runtime");function Zn(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{orientation:r}=we(e.style,{orientation:nn(e.field)}),o=on(e.field,e.disabled);return(0,K.jsxs)("div",{className:(0,qn.twMerge)("flex flex-col gap-3",Cn(t)),children:[(0,K.jsx)(Hn,{disabled:o,errors:n,field:e.field,orientation:r,children:(0,K.jsx)($n,{disabled:o,errors:n,field:e.field,orientation:r,children:e.children})}),(0,K.jsx)(pt,{errors:n,name:e.field.name})]})}var D=require("jotai"),tt=require("jotai-family"),Oe=require("fast-equals");function pi(e){return(0,tt.atomFamily)(t=>(0,D.atom)(n=>n(e)[t]??void 0,(n,r,o)=>{let i=n(e);if(o!=null){let a=i[t];(!a||!(0,Oe.deepEqual)(a,o))&&r(e,{...i,[t]:o})}else if(i[t]){let{[t]:a,...l}=i;r(e,l)}}))}function gi(e){return(0,D.atom)(null,(t,n)=>{let r=t(e);r&&Object.keys(r).length>0&&n(e,{})})}function yi(e){return(0,D.atom)(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 bi(e){return(0,D.atom)(null,(t,n,r)=>{let o=t(e);(0,Oe.deepEqual)(o,r)||n(e,r)})}function Wn(e,t={}){let{merge:n,validateTarget:r}=t;return(0,tt.atomFamily)(o=>(0,D.atom)(i=>{let a=i(e)[o];if(a&&n)return n(Object.values(a))},(i,a,l,s)=>{if(r&&!r(l))return;let c=i(e),u={...c[l]??{}};if(s!=null){let y=u[o];(!y||!(0,Oe.deepEqual)(y,s))&&(u[o]=s,a(e,{...c,[l]:u}))}else if(u[o])if(delete u[o],Object.keys(u).length===0){let{[l]:y,...w}=c;a(e,w)}else a(e,{...c,[l]:u})}))}function zn(e){return(0,D.atom)(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]},c=!1;for(let u of r)s[u]&&(delete s[u],c=!0,a=!0);c&&(Object.keys(s).length===0?delete i[l]:i[l]=s)}a&&n(e,i)})}function j(e={}){let t=(0,D.atom)(e);return{atom:t,clearAll:gi(t),clear:yi(t),bulkReport:bi(t),report:pi(t)}}var nt=j(),Kn=nt.clear,jn=nt.bulkReport,Ve=nt.report;var Jn=require("jotai"),er=require("react/jsx-runtime");function Qn(e){return n=>{let r=(0,Jn.useAtomValue)(Ve(n.field.name));return(0,er.jsx)(e,{...n,errors:r?{[n.field.name]:r}:void 0})}}var tr=j(),nr=tr.atom,rr=tr.report;var or=require("jotai"),ar=require("react/jsx-runtime");function ir(e){return n=>{let r=(0,or.useAtomValue)(rr(n.field.name));if(r?.hidden??n.field.hidden??!1)return null;let i=r?.disabled??n.disabled;return(0,ar.jsx)(e,{...n,disabled:i})}}var lr=ir(Qn(Zn));var cr=require("react/jsx-runtime");function sr(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return(0,cr.jsx)("div",{"data-slot":"field-control",className:"w-full",children:t})}var De=require("react");var rt=require("react/jsx-runtime");function ur(e){return(0,rt.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:`size-4 transition-transform duration-200 ${e.expanded?"rotate-90":""}`,children:(0,rt.jsx)("path",{fillRule:"evenodd",d:"M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})})}var dr=require("react/jsx-runtime");function J(e){return(0,dr.jsx)("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})}var fr=require("react/jsx-runtime");function L(e){return Xt(e,(t,n,r)=>(0,fr.jsx)("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}var _=require("react/jsx-runtime");function mr(e){return(0,_.jsxs)(_.Fragment,{children:[e.title&&(0,_.jsx)("legend",{className:"mb-3 font-medium text-slate-800 dark:text-slate-200",children:L(e.title)}),e.description&&(0,_.jsx)("p",{className:"-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:L(e.description)})]})}var p=require("react/jsx-runtime");function pr(e){let t=e.section.fields||[],[n,r]=(0,De.useState)(!1),{compact:o}=we(e.style,{compact:e.section.compact});return!e.section.title&&!e.section.description?(0,p.jsx)(J,{compact:o,children:e.children}):e.section.advanced?(0,p.jsxs)("fieldset",{"data-slot":"field-set","data-advanced":"true","data-expanded":n,"data-empty":t.length===0,className:"flex flex-col",id:e.section.id?.toString(),children:[(0,p.jsx)("legend",{children:(0,p.jsxs)("button",{type:"button",onClick:()=>r(i=>!i),className:"flex cursor-pointer items-center gap-2 text-base font-medium text-slate-600 dark:text-slate-400",children:[(0,p.jsx)(ur,{expanded:n}),(0,p.jsx)("span",{children:L(e.section.title)})]})}),(0,p.jsx)(De.Activity,{mode:n?"visible":"hidden",children:(0,p.jsxs)("div",{className:"mt-3 flex flex-col gap-4 border-l-2 border-slate-300 pl-4 dark:border-slate-600","data-slot":"field-set-content",children:[e.section.description&&(0,p.jsx)("p",{className:"text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:L(e.section.description)}),(0,p.jsx)(J,{compact:o,children:e.children})]})})]}):(0,p.jsxs)("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:[(0,p.jsx)(mr,{description:e.section.description,title:e.section.title}),(0,p.jsx)(J,{compact:o,children:e.children})]})}var yr=require("react");var ot=require("react/jsx-runtime");function gr(){return(0,ot.jsx)("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:(0,ot.jsx)("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800"})})}var k=require("react/jsx-runtime");function br(e){let t=Ie(e.sections,e.definition);return(0,k.jsx)("div",{className:"h-full w-full",children:(0,k.jsx)("form",{noValidate:e.noValidate,action:e.action,children:(0,k.jsxs)(J,{children:[t.map((n,r)=>(0,k.jsxs)(yr.Fragment,{children:[(0,k.jsx)(pr,{section:n,style:e.config.style,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.separator&&(0,k.jsx)(gr,{})]},r)),e.control&&(0,k.jsx)(sr,{isPending:e.isPending,children:e.control})]})})})}var hr=require("react/jsx-runtime");function xr(e){return(0,hr.jsx)("p",{className:"-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400",children:e.children})}var Tr=require("react/jsx-runtime");function Le(e){let t=L(e.text);return t?(0,Tr.jsx)(xr,{children:t}):null}var Rr=require("tailwind-merge"),Me=require("react/jsx-runtime");function Sr(e){let t=e.style?.showOptionalLabel??!0,n=N(e.field)||b(e.field);return(0,Me.jsxs)("label",{"data-slot":"field-label","data-normal":n,className:(0,Rr.twMerge)("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&&(0,Me.jsx)("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:m("(Optional)",e.translations)})]})}var de=require("react/jsx-runtime");function Ar(e){let t=M(e.field.label)?S(e.field.label,{context:e.context,env:e.config?.env}):e.field.label,n=M(e.field.description)?S(e.field.description,{context:e.context,env:e.config?.env}):e.field.description;return(0,de.jsxs)("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[(0,de.jsx)(Sr,{field:e.field,style:e.config?.style,translations:e.translations,children:m(t,e.translations)}),e.orientation===W&&(0,de.jsx)(Le,{text:m(n,e.translations)})]})}var U=require("react/jsx-runtime");function Cr(e){return(0,U.jsxs)(U.Fragment,{children:[e.field.name&&e.field.label&&(0,U.jsx)(Ar,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations}),e.children,e.orientation===P&&e.field.description&&(0,U.jsx)(Le,{text:m(e.field.description,e.translations)})]})}function _e(e,t){return e?t(e):null}var x=require("react");var Er=require("jotai");var xi=e=>{let t=Dn(e);if(t)return t},hi=e=>e.trim()!=="",Fr=(0,Er.atom)({}),Nr=Wn(Fr,{merge:xi,validateTarget:hi}),vr=zn(Fr);var wr=require("jotai");var kr=po(require("swr"),1);function Ir(e=null,t,n=!1){let{data:r,error:o}=(0,kr.default)(Ti(e,t,n),t.fetcher.provider);if(o&&se.error("Error fetching data source:",o),e){if(Array.isArray(e))return e;if(r)return Ut(r,e.namespace)}return null}function Ti(e=null,t,n=!1){if(e&&!Array.isArray(e)&&!n&&e.url&&!M(e.url)){if(On(e.url,t.fetcher.remotePatterns))return e;se.warn(`URL blocked by remotePatterns: ${e.url}. Check your luna.config.ts`)}return null}function Pr(e,t,n){let r=mn(e,n),[o,i]=(0,wr.useAtom)(Nr(e.name));return[Ir(o??r,t,e.disabled),i]}var B=require("react");function Or(e,t,n,r){let{name:o}=e,i=(0,B.useMemo)(()=>vn(e,r),[e,r]),a=(0,B.useEffectEvent)(s=>{s&&t(s,i,e)}),l=(0,B.useEffectEvent)(s=>{s&&n(s)});return(0,B.useEffect)(()=>(a(o),()=>{l(o)}),[o]),i}var te=require("jotai");var Q=require("react");function Vr(){let e=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{e.current&&clearTimeout(e.current)},[]);function t(){e.current&&(clearTimeout(e.current),e.current=null)}return(0,Q.useCallback)((r,o)=>{t(),e.current=setTimeout(r,o)},[])}var Ue=j(),Dr=Ue.atom,Lr=Ue.clearAll,Mr=Ue.clear,Be=Ue.report;var _r=require("jotai"),ee=require("react");function Ur(e,t){let{name:n}=e,r=(0,ee.useRef)(!1),[o,i]=(0,_r.useAtom)(Be(n));(0,ee.useEffect)(()=>{if(!t||!(n in t))return;let l=t[n];ue(l)&&(r.current=!0,i(l))},[n,t,i]);let a=(0,ee.useCallback)(()=>r.current?(r.current=!1,!0):!1,[]);return{setValue:i,shouldSkipOnChange:a,value:o}}var it=require("react/jsx-runtime");function Br(e){let t=e.field.advanced?.entity,n=(0,te.useStore)(),r=Vr(),[,o]=(0,x.useTransition)(),{setValue:i,shouldSkipOnChange:a,value:l}=Ur(e.field,e.value),s=(0,x.useRef)(l);s.current=l;let c=(0,x.useRef)(e.translations);c.current=e.translations;let u=en(e.field),y=Ne(e.field),w=(0,te.useSetAtom)(Dr),re=(0,te.useSetAtom)(nr),me=(0,te.useSetAtom)(Ve(e.field.name)),[oe,G]=Pr(e.field,e.config,l),E=Or(e.field,e.onMount,e.onUnmount,e.translations),ie=m(e.commonProps.placeholder,e.translations),h={...e.commonProps,placeholder:ie},{commonPropsWithOptions:eo,defaultValue:to}=pn(e.field,h,oe,l),dt=(0,x.useRef)(null);dt.current=g=>{i(g),e.onValueChange&&e.onValueChange({name:e.field.name,value:g})};let no=gn(e.field,to),pe=(0,x.useCallback)(g=>{let Y=E.safeParse(g).error?.issues.map(ae=>ae.message)??[],X=e.field.validation?.custom,Ye=X?Pn(g,X,ae=>n.get(Be(ae)),c.current):[];me([...Y,...Ye])},[e.field.validation?.custom,E,me,n]),ft=(0,x.useCallback)((g,T)=>{if(u){r(()=>{T({value:g})},500);return}let Y=_t(g,oe,t);T(Y)},[oe,t,u,r]),ro=(0,x.useCallback)(g=>{let T=g.target.value;if(!y&&a()&&(!u||T===s.current))return;dt.current?.(T),e.config.validation.change&&pe(T);let Y=e.field.event?.change;Y&&ft(T,X=>{Ht(Y,({sources:Ye,states:ae,values:io})=>{o(()=>{$t(X,Ye,(H,$)=>G(H,$)),Zt(X,ae,(H,$)=>{re(ge=>{if($)return{...ge,[H]:$};let{[H]:Ci,...ao}=ge;return ao})}),Wt(X,io,(H,$)=>{w(ge=>({...ge,[H]:$}))})})})})},[ft,y,u,e.config.validation.change,e.field.event?.change,re,G,w,a,pe]),oo=(0,x.useCallback)(g=>{if(!y){let T=g.target.value;e.config.validation.blur&&pe(T)}},[y,e.config.validation.blur,pe]);return _e(e.config.inputs[e.field.type],g=>(0,it.jsx)(Cr,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations,children:(0,it.jsx)(g,{...eo,...e.ariaAttributes,...e.dataAttributes,...no,onBlur:oo,onChange:ro})}))}var Gr=require("tailwind-merge"),at=require("react/jsx-runtime");function Yr(e){let t=An(e.column?.advanced?.cols);return(0,at.jsx)("div",{className:"flex w-full flex-col gap-4",children:(0,at.jsx)("div",{className:(0,Gr.twMerge)("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children})})}var Xr=require("react"),ne=require("react/jsx-runtime");function lt(e){let{column:t,field:n}=e.components;return Ie(e.fields).map((r,o)=>(0,ne.jsxs)(Xr.Fragment,{children:[jt(r)&&(0,ne.jsx)(t,{column:r,children:(0,ne.jsx)(lt,{...e,fields:r.fields})}),Jt(r)&&(0,ne.jsx)(n,{disabled:e.disabled,field:r,style:e.style,children:e.children})]},o))}var $r=require("react/jsx-runtime");function Hr(e){return n=>(0,$r.jsx)(lt,{...n,components:{column:Yr,field:e}})}var ct=require("jotai");var fe=require("react");function Zr(e,t,n){let{onSuccess:r,preserveValues:o=!1,validation:i=!0}=n??{},a=(0,ct.useSetAtom)(jn),l=(0,ct.useSetAtom)(Lr),s={data:null,error:null,success:!1},[c,u,y]=(0,fe.useActionState)(async(w,re)=>{let[me,oe]=e(),G=Fn(me,oe,n?.translations);if(i===!1)return t?await t(re,G):w;let E=Yt(re),ie=G.safeParse(E);if(!ie.success){let h=Nn(ie.error);return(0,fe.startTransition)(()=>{a(h)}),st(E,{description:"Please correct the errors and try again.",details:[],title:"There were validation errors submitting the form."})}if(t)try{let h=await t(E,G);return h.success?(r?.(h.data),o||(0,fe.startTransition)(()=>{l()}),qr(E,o)):st(E,h.error)}catch(h){return se.error("Error executing form action:",h),st(E,{title:"An unexpected error occurred submitting the form.",details:Ri(h)})}return qr(ie.data,o)},s);return[u,c,y]}function Ri(e){let t=e instanceof Error?e.message:["Unknown error"];return Array.isArray(t)?t:[t]}function qr(e,t=!1){return{data:t?e:null,error:null,success:!0}}function st(e,t){return{data:e,error:t,success:!1}}var I=require("react");var Wr=require("react"),Ge=require("jotai");function zr(){let e=(0,Ge.useSetAtom)(Kn),t=(0,Ge.useSetAtom)(vr),n=(0,Ge.useSetAtom)(Mr);return(0,Wr.useCallback)(r=>{let o=Array.isArray(r)?r:[r];e(o),t(o),n(o)},[e,t,n])}function Kr(){let e=zr(),t=(0,I.useRef)({}),n=(0,I.useRef)([]),r=(0,I.useRef)(new Set),o=(0,I.useCallback)((l,s,c)=>{l in t.current||(t.current[l]=s,n.current.push(c))},[]),i=(0,I.useCallback)(l=>{t.current[l]&&(delete t.current[l],n.current=n.current.filter(s=>s.name!==l),r.current.add(l),(0,I.startTransition)(()=>{r.current.size>0&&(e(Array.from(r.current)),r.current.clear())}))},[e]);function a(){return[t.current,n.current]}return[a,o,i]}var C=require("react/jsx-runtime"),Si=Hr(lr);function jr(e){let t=e.translations?.[e.lang??""],[n,r,o]=Kr(),[i,a,l]=Zr(n,e.action,{onSuccess:e.onSuccess,validation:e.config.validation.submit,translations:t}),s=e.config.validation.showError&&!a.success&&a.error,c=a.data??e.value;return(0,C.jsxs)(C.Fragment,{children:[s&&_e(e.config.alert,u=>(0,C.jsx)("div",{className:"mb-4 w-full",children:(0,C.jsx)(u,{description:a.error?.description,details:a.error?.details,title:a.error.title})})),(0,C.jsx)(br,{action:i,config:e.config,control:e.children,definition:e.definition,isPending:l,noValidate:!0,readOnly:e.readOnly,sections:e.sections,children:({disabled:u,fields:y})=>(0,C.jsx)(Si,{disabled:u,fields:y,style:e.config.style,children:w=>(0,C.jsx)(Br,{...w,config:e.config,context:e.context,onMount:r,onUnmount:o,onValueChange:e.onValueChange,translations:t,value:c})})})]})}var Jr=require("jotai"),ut=require("react/jsx-runtime");function Qr(e){return(0,ut.jsx)(Jr.Provider,{children:(0,ut.jsx)(jr,{...e})})}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/client/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Form: () => Form2
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/component/control.tsx
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
+
function Control(props) {
|
|
40
|
+
const content = typeof props.children === "function" ? props.children({ isPending: props.isPending }) : props.children;
|
|
41
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-slot": "field-control", className: "w-full", children: content });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/component/field/field-set-advanced.tsx
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
|
|
47
|
+
// src/component/chevron-icon.tsx
|
|
48
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
49
|
+
function ChevronIcon(props) {
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
51
|
+
"svg",
|
|
52
|
+
{
|
|
53
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
54
|
+
viewBox: "0 0 20 20",
|
|
55
|
+
fill: "currentColor",
|
|
56
|
+
className: `size-4 transition-transform duration-200 ${props.expanded ? "rotate-90" : ""}`,
|
|
57
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
58
|
+
"path",
|
|
59
|
+
{
|
|
60
|
+
fillRule: "evenodd",
|
|
61
|
+
d: "M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",
|
|
62
|
+
clipRule: "evenodd"
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ../luna-core/src/util/constant.ts
|
|
70
|
+
var INPUT = "input";
|
|
71
|
+
var INPUT_EMAIL = "input/email";
|
|
72
|
+
var INPUT_NUMBER = "input/number";
|
|
73
|
+
var TEXTAREA = "textarea";
|
|
74
|
+
var RADIO = "radio";
|
|
75
|
+
var CHECKBOX = "checkbox";
|
|
76
|
+
var LIST = "list";
|
|
77
|
+
var SELECT = "select";
|
|
78
|
+
var SELECT_MONTH = "select/month";
|
|
79
|
+
var SELECT_YEAR = "select/year";
|
|
80
|
+
var COLUMN = "column";
|
|
81
|
+
var FIELDS = "fields";
|
|
82
|
+
var LABEL = "label";
|
|
83
|
+
var VALUE = "value";
|
|
84
|
+
var OPTIONS = "options";
|
|
85
|
+
var TYPE_EMAIL = "email";
|
|
86
|
+
var TYPE_NUMBER = "number";
|
|
87
|
+
var TYPE_PASSWORD = "password";
|
|
88
|
+
var TYPE_TEL = "tel";
|
|
89
|
+
var TYPE_TEXT = "text";
|
|
90
|
+
var ARIA_ERROR_MESSAGE = "aria-errormessage";
|
|
91
|
+
var ARIA_INVALID = "aria-invalid";
|
|
92
|
+
var DATA_INVALID = "data-invalid";
|
|
93
|
+
var DATA_READONLY = "data-readonly";
|
|
94
|
+
var PREFIX_ARIA = "aria";
|
|
95
|
+
var PREFIX_DATA = "data";
|
|
96
|
+
var MIN = "min";
|
|
97
|
+
var MAX = "max";
|
|
98
|
+
var MIN_LENGTH = "minLength";
|
|
99
|
+
var MAX_LENGTH = "maxLength";
|
|
100
|
+
var $REF = "$ref";
|
|
101
|
+
var SOURCE = "source";
|
|
102
|
+
var STATE = "state";
|
|
103
|
+
var COMMON_URL = "http://luna.internal";
|
|
104
|
+
var VERTICAL = "vertical";
|
|
105
|
+
var HORIZONTAL = "horizontal";
|
|
106
|
+
var TYPE = "type";
|
|
107
|
+
|
|
108
|
+
// ../luna-core/src/util/is-type.ts
|
|
109
|
+
function isObject(value) {
|
|
110
|
+
return value !== null && Object.prototype.toString.call(value) === "[object Object]";
|
|
111
|
+
}
|
|
112
|
+
function isEmpty(value) {
|
|
113
|
+
return value === null || value === void 0 || value === "";
|
|
114
|
+
}
|
|
115
|
+
function isValue(value) {
|
|
116
|
+
return isString(value) || typeof value === "number" || isBoolean(value);
|
|
117
|
+
}
|
|
118
|
+
function isString(value) {
|
|
119
|
+
return typeof value === "string";
|
|
120
|
+
}
|
|
121
|
+
function isDataSource(value) {
|
|
122
|
+
return isObject(value) && "url" in value;
|
|
123
|
+
}
|
|
124
|
+
function isBoolean(value) {
|
|
125
|
+
return typeof value === "boolean";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ../luna-core/src/util/extract.ts
|
|
129
|
+
var REGEX_TYPE = /[^/]+$/;
|
|
130
|
+
var REGEX_NUMERIC = /^\d+$/;
|
|
131
|
+
function getEntity(selected, collection = [], entity = VALUE) {
|
|
132
|
+
if (Array.isArray(collection)) {
|
|
133
|
+
return collection.find((item) => {
|
|
134
|
+
const current = getCurrentValue(item, entity);
|
|
135
|
+
if (current !== void 0 && `${current}` === selected) {
|
|
136
|
+
return item;
|
|
137
|
+
}
|
|
138
|
+
}) ?? { value: selected };
|
|
139
|
+
}
|
|
140
|
+
return { value: selected };
|
|
141
|
+
}
|
|
142
|
+
function getCurrentValue(value, entity = VALUE) {
|
|
143
|
+
if (value !== null && value !== void 0) {
|
|
144
|
+
if (isValue(value)) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
if (isObject(value)) {
|
|
148
|
+
const result = getValue(value, entity);
|
|
149
|
+
if (isValue(result)) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function getValue(value, namespace) {
|
|
156
|
+
const result = extract(value, namespace);
|
|
157
|
+
if (isValue(result)) {
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function getArray(value, namespace) {
|
|
162
|
+
if (Array.isArray(value)) {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
const result = extract(value, namespace);
|
|
166
|
+
if (Array.isArray(result)) {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
function extract(value, namespace) {
|
|
172
|
+
if (!namespace || !isObject(value)) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const keys = namespace.split(".").filter((key) => key !== "");
|
|
176
|
+
if (keys.length === 0) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
let result = value;
|
|
180
|
+
for (const key of keys) {
|
|
181
|
+
if (isObject(result) && key in result) {
|
|
182
|
+
const obj = result;
|
|
183
|
+
result = obj[key];
|
|
184
|
+
} else {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
function toOptions(data, options = { label: LABEL, value: VALUE }) {
|
|
191
|
+
return data.map((item) => {
|
|
192
|
+
if (isObject(item)) {
|
|
193
|
+
const label = extract(item, options.label);
|
|
194
|
+
const value = extract(item, options.value);
|
|
195
|
+
if (isValue(label) && isValue(value)) {
|
|
196
|
+
return {
|
|
197
|
+
label: `${label}`,
|
|
198
|
+
value: `${value}`
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return item;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function getType(value = TYPE_TEXT) {
|
|
206
|
+
if (value) {
|
|
207
|
+
const result = value.match(REGEX_TYPE);
|
|
208
|
+
if (result) {
|
|
209
|
+
const [type] = result;
|
|
210
|
+
if (type !== INPUT) {
|
|
211
|
+
return type.trim().toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return TYPE_TEXT;
|
|
216
|
+
}
|
|
217
|
+
function getFormData(formData) {
|
|
218
|
+
const data = {};
|
|
219
|
+
for (const key of formData.keys()) {
|
|
220
|
+
const values = formData.getAll(key);
|
|
221
|
+
data[key] = values.length > 1 ? values : values[0];
|
|
222
|
+
}
|
|
223
|
+
return data;
|
|
224
|
+
}
|
|
225
|
+
function unflatten(data) {
|
|
226
|
+
const result = {};
|
|
227
|
+
for (const key in data) {
|
|
228
|
+
const parts = key.split(".");
|
|
229
|
+
if (parts.length === 1) {
|
|
230
|
+
result[key] = data[key];
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
let current = result;
|
|
234
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
235
|
+
const part = parts[i];
|
|
236
|
+
const next = parts[i + 1];
|
|
237
|
+
const isNextIndex = REGEX_NUMERIC.test(next);
|
|
238
|
+
if (!(part in current)) {
|
|
239
|
+
current[part] = isNextIndex ? [] : {};
|
|
240
|
+
}
|
|
241
|
+
current = current[part];
|
|
242
|
+
}
|
|
243
|
+
const last = parts[parts.length - 1];
|
|
244
|
+
current[last] = data[key];
|
|
245
|
+
}
|
|
246
|
+
compactArrays(result);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function compactArrays(obj) {
|
|
250
|
+
for (const key in obj) {
|
|
251
|
+
const value = obj[key];
|
|
252
|
+
if (Array.isArray(value)) {
|
|
253
|
+
const compacted = value.filter((item) => item !== void 0);
|
|
254
|
+
compacted.forEach((item) => {
|
|
255
|
+
if (item !== null && typeof item === "object" && !Array.isArray(item)) {
|
|
256
|
+
compactArrays(item);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
obj[key] = compacted;
|
|
260
|
+
} else if (value !== null && typeof value === "object") {
|
|
261
|
+
compactArrays(value);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ../luna-core/src/util/string.ts
|
|
267
|
+
var REGEX_MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
268
|
+
function interpolate(template, values = {}) {
|
|
269
|
+
if (isString(template)) {
|
|
270
|
+
return replacePlaceholders(template, values);
|
|
271
|
+
}
|
|
272
|
+
if (Array.isArray(template)) {
|
|
273
|
+
return template.map((item) => {
|
|
274
|
+
return interpolate(item, values);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (isObject(template)) {
|
|
278
|
+
const results = {};
|
|
279
|
+
for (const key in template) {
|
|
280
|
+
results[key] = interpolate(template[key], values);
|
|
281
|
+
}
|
|
282
|
+
return results;
|
|
283
|
+
}
|
|
284
|
+
return template;
|
|
285
|
+
}
|
|
286
|
+
function interpolateIfNeeded(template, values = {}) {
|
|
287
|
+
return isInterpolated(template) ? interpolate(template, values) : template;
|
|
288
|
+
}
|
|
289
|
+
function isInterpolated(template) {
|
|
290
|
+
if (isString(template)) {
|
|
291
|
+
return /{([^}]+)}/.test(template);
|
|
292
|
+
}
|
|
293
|
+
if (Array.isArray(template)) {
|
|
294
|
+
return template.some((item) => isInterpolated(item));
|
|
295
|
+
}
|
|
296
|
+
if (isObject(template)) {
|
|
297
|
+
return Object.values(template).some((value) => isInterpolated(value));
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
function replacePlaceholders(template, values = {}) {
|
|
302
|
+
return template.replace(/{([^}]+)}/g, (match, key) => {
|
|
303
|
+
const value = key.includes(".") ? extract(values, key) : values[key];
|
|
304
|
+
if (isValue(value)) {
|
|
305
|
+
return String(value);
|
|
306
|
+
}
|
|
307
|
+
return match;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function formatMarkdown(text, callback) {
|
|
311
|
+
if (!text || text.trim().length === 0) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
let match;
|
|
315
|
+
let lastIndex = 0;
|
|
316
|
+
let hasMatch = false;
|
|
317
|
+
const parts = [];
|
|
318
|
+
while ((match = REGEX_MARKDOWN_LINK.exec(text)) !== null) {
|
|
319
|
+
const [fullMatch, linkText, url] = match;
|
|
320
|
+
const index = match.index;
|
|
321
|
+
hasMatch = true;
|
|
322
|
+
if (index > lastIndex) {
|
|
323
|
+
parts.push(text.substring(lastIndex, index));
|
|
324
|
+
}
|
|
325
|
+
const value = callback ? callback(index, url, linkText) : fullMatch;
|
|
326
|
+
parts.push(value);
|
|
327
|
+
lastIndex = index + fullMatch.length;
|
|
328
|
+
}
|
|
329
|
+
if (!hasMatch) {
|
|
330
|
+
return text;
|
|
331
|
+
}
|
|
332
|
+
if (lastIndex < text.length) {
|
|
333
|
+
parts.push(text.substring(lastIndex));
|
|
334
|
+
}
|
|
335
|
+
return parts;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ../luna-core/src/util/logger.ts
|
|
339
|
+
var logger = {
|
|
340
|
+
error: (...args) => {
|
|
341
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
342
|
+
getConsole().error("[Luna Form]", ...args);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
warn: (...args) => {
|
|
346
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
347
|
+
getConsole().warn("[Luna Form]", ...args);
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
info: (...args) => {
|
|
351
|
+
if (isConsoleAvailable() && !isProduction()) {
|
|
352
|
+
getConsole().info("[Luna Form]", ...args);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
var isConsoleAvailable = () => typeof getConsole() !== "undefined";
|
|
357
|
+
var isProduction = () => false;
|
|
358
|
+
var getConsole = () => globalThis.console;
|
|
359
|
+
|
|
360
|
+
// ../luna-core/src/handle/proxy-event.ts
|
|
361
|
+
function handleProxyEvent(events = [], callback) {
|
|
362
|
+
const values = [];
|
|
363
|
+
const sources = [];
|
|
364
|
+
const states = [];
|
|
365
|
+
for (const event of events) {
|
|
366
|
+
if (event.action === VALUE) {
|
|
367
|
+
values.push(event);
|
|
368
|
+
}
|
|
369
|
+
if (event.action === SOURCE) {
|
|
370
|
+
sources.push(event);
|
|
371
|
+
}
|
|
372
|
+
if (event.action === STATE) {
|
|
373
|
+
states.push(event);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
callback({ sources, states, values });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ../luna-core/src/handle/source-event.ts
|
|
380
|
+
function handleSourceEvent(selected = null, events = [], setSource) {
|
|
381
|
+
for (const event of events) {
|
|
382
|
+
const { target, source } = event;
|
|
383
|
+
if (!selected) {
|
|
384
|
+
setSource(target, void 0);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (isDataSource(source)) {
|
|
388
|
+
const newUrl = interpolate(source.url, selected);
|
|
389
|
+
const newBody = source.body ? interpolate(source.body, selected) : source.body;
|
|
390
|
+
setSource(target, {
|
|
391
|
+
...source,
|
|
392
|
+
url: newUrl,
|
|
393
|
+
body: newBody
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// ../luna-core/src/util/operator.ts
|
|
400
|
+
var operators = {
|
|
401
|
+
eq,
|
|
402
|
+
gt,
|
|
403
|
+
gte,
|
|
404
|
+
in: includes,
|
|
405
|
+
lt,
|
|
406
|
+
lte,
|
|
407
|
+
neq,
|
|
408
|
+
nin
|
|
409
|
+
};
|
|
410
|
+
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/;
|
|
411
|
+
var DMY_DATE_REGEX = /^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
412
|
+
function isISODateString(value) {
|
|
413
|
+
return typeof value === "string" && ISO_DATE_REGEX.test(value);
|
|
414
|
+
}
|
|
415
|
+
function isDMYDateString(value) {
|
|
416
|
+
return typeof value === "string" && DMY_DATE_REGEX.test(value);
|
|
417
|
+
}
|
|
418
|
+
function parseDMYDate(value) {
|
|
419
|
+
const match = value.match(DMY_DATE_REGEX);
|
|
420
|
+
if (match) {
|
|
421
|
+
const [, day, month, year, hours, minutes, seconds] = match;
|
|
422
|
+
return new Date(
|
|
423
|
+
Number(year),
|
|
424
|
+
Number(month) - 1,
|
|
425
|
+
Number(day),
|
|
426
|
+
Number(hours ?? 0),
|
|
427
|
+
Number(minutes ?? 0),
|
|
428
|
+
Number(seconds ?? 0)
|
|
429
|
+
).getTime();
|
|
430
|
+
}
|
|
431
|
+
return NaN;
|
|
432
|
+
}
|
|
433
|
+
function toComparableNumber(value) {
|
|
434
|
+
if (isISODateString(value)) {
|
|
435
|
+
return new Date(value).getTime();
|
|
436
|
+
}
|
|
437
|
+
if (isDMYDateString(value)) {
|
|
438
|
+
return parseDMYDate(value);
|
|
439
|
+
}
|
|
440
|
+
return Number(value);
|
|
441
|
+
}
|
|
442
|
+
function eq(current, value) {
|
|
443
|
+
return current === value;
|
|
444
|
+
}
|
|
445
|
+
function neq(current, value) {
|
|
446
|
+
return current !== value;
|
|
447
|
+
}
|
|
448
|
+
function includes(current, value) {
|
|
449
|
+
return Array.isArray(value) && value.includes(String(current));
|
|
450
|
+
}
|
|
451
|
+
function nin(current, value) {
|
|
452
|
+
return Array.isArray(value) && !value.includes(String(current));
|
|
453
|
+
}
|
|
454
|
+
function gt(current, value) {
|
|
455
|
+
return toComparableNumber(current) > toComparableNumber(value);
|
|
456
|
+
}
|
|
457
|
+
function gte(current, value) {
|
|
458
|
+
return toComparableNumber(current) >= toComparableNumber(value);
|
|
459
|
+
}
|
|
460
|
+
function lt(current, value) {
|
|
461
|
+
return toComparableNumber(current) < toComparableNumber(value);
|
|
462
|
+
}
|
|
463
|
+
function lte(current, value) {
|
|
464
|
+
return toComparableNumber(current) <= toComparableNumber(value);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// ../luna-core/src/handle/state-event.ts
|
|
468
|
+
function handleStateEvent(selected = null, events = [], setState) {
|
|
469
|
+
for (const event of events) {
|
|
470
|
+
const { target, state, when } = event;
|
|
471
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
472
|
+
if (!selected) {
|
|
473
|
+
setState(targets);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
logger.info(`Selected value for state event: ${JSON.stringify(selected)}, evaluating condition: ${JSON.stringify(when)}`);
|
|
477
|
+
const matches = evaluateCondition(selected, when);
|
|
478
|
+
logger.info(`Condition evaluated to: ${matches}, setting state for targets: ${targets.join(", ")}`);
|
|
479
|
+
setState(targets, matches ? state : void 0);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function evaluateCondition(selected, when) {
|
|
483
|
+
if (when === void 0) {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
if (isString(when)) {
|
|
487
|
+
logger.info(`Evaluating string condition: ${when} against selected value: ${JSON.stringify(selected)} using VALUE field`);
|
|
488
|
+
logger.info(`Extracted value for comparison: ${JSON.stringify(getValue2(selected, VALUE))}`);
|
|
489
|
+
logger.info(`Comparison result: ${getValue2(selected, VALUE) === when}`);
|
|
490
|
+
return getValue2(selected, VALUE) === when;
|
|
491
|
+
}
|
|
492
|
+
if (isBoolean(when)) {
|
|
493
|
+
return Boolean(getValue2(selected, VALUE)) === when;
|
|
494
|
+
}
|
|
495
|
+
if (Array.isArray(when)) {
|
|
496
|
+
return when.includes(String(getValue2(selected, VALUE)));
|
|
497
|
+
}
|
|
498
|
+
return evaluateOperator(selected, when);
|
|
499
|
+
}
|
|
500
|
+
function evaluateOperator(selected = null, condition) {
|
|
501
|
+
const current = getValue2(selected, condition.field ?? VALUE);
|
|
502
|
+
const { operator = "eq", value } = condition;
|
|
503
|
+
const operation = operators[operator];
|
|
504
|
+
if (operation) {
|
|
505
|
+
return operation(current, value);
|
|
506
|
+
}
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
function getValue2(selected, field) {
|
|
510
|
+
if (isObject(selected)) {
|
|
511
|
+
return extract(selected, field);
|
|
512
|
+
}
|
|
513
|
+
return selected;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// ../luna-core/src/handle/value-event.ts
|
|
517
|
+
function handleValueEvent(selected = null, events = [], setValue) {
|
|
518
|
+
for (const event of events) {
|
|
519
|
+
for (const [target, value] of Object.entries(event.value)) {
|
|
520
|
+
setValue(target, selected ? interpolate(value, selected) : void 0);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// ../luna-core/src/util/is-input.ts
|
|
526
|
+
var isSelectMonth = (field) => createTypeChecker(SELECT_MONTH)(field);
|
|
527
|
+
var isSelectYear = (field) => createTypeChecker(SELECT_YEAR)(field);
|
|
528
|
+
var isCheckbox = createTypeChecker(CHECKBOX);
|
|
529
|
+
var isInput = createTypeChecker(INPUT);
|
|
530
|
+
var isRadio = createTypeChecker(RADIO);
|
|
531
|
+
var isSelect = createTypeChecker(SELECT);
|
|
532
|
+
var isTextArea = createTypeChecker(TEXTAREA);
|
|
533
|
+
var isText = createTypeChecker(
|
|
534
|
+
TYPE_TEXT,
|
|
535
|
+
TYPE_EMAIL,
|
|
536
|
+
TYPE_PASSWORD,
|
|
537
|
+
TYPE_TEL
|
|
538
|
+
);
|
|
539
|
+
var isEmail = createTypeChecker(INPUT_EMAIL, TYPE_EMAIL);
|
|
540
|
+
var isNumber = createTypeChecker(INPUT_NUMBER, TYPE_NUMBER);
|
|
541
|
+
function isClickable(field) {
|
|
542
|
+
return isRadio(field) || isCheckbox(field);
|
|
543
|
+
}
|
|
544
|
+
function isList(slot) {
|
|
545
|
+
return slot.type === LIST;
|
|
546
|
+
}
|
|
547
|
+
function isColumn(slot) {
|
|
548
|
+
return slot.type === COLUMN;
|
|
549
|
+
}
|
|
550
|
+
function isField(slot) {
|
|
551
|
+
return slot.type !== COLUMN && slot.type !== LIST;
|
|
552
|
+
}
|
|
553
|
+
function isOptions(field) {
|
|
554
|
+
return isSelect(field) || isRadio(field);
|
|
555
|
+
}
|
|
556
|
+
function isTextable(field) {
|
|
557
|
+
return isInput(field) || isTextArea(field);
|
|
558
|
+
}
|
|
559
|
+
function isValidValue(value) {
|
|
560
|
+
return value !== void 0 && value !== null && value !== "";
|
|
561
|
+
}
|
|
562
|
+
function createTypeChecker(...types) {
|
|
563
|
+
return (field) => {
|
|
564
|
+
const inputType = isString(field.type) ? field.type : void 0;
|
|
565
|
+
if (!inputType) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
return types.some((type) => {
|
|
569
|
+
return inputType === type || inputType?.startsWith(`${type}/`);
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// ../luna-core/src/util/build.ts
|
|
575
|
+
function buildOptions(field, values = {}) {
|
|
576
|
+
if (isSelect(field) && field.disabled) {
|
|
577
|
+
const current = field.name ? values?.[field.name] : void 0;
|
|
578
|
+
if (current && isObject(current)) {
|
|
579
|
+
return [current];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function buildOrientation(field) {
|
|
584
|
+
if (isRadio(field) || isCheckbox(field)) {
|
|
585
|
+
return HORIZONTAL;
|
|
586
|
+
}
|
|
587
|
+
return field.advanced?.orientation ?? VERTICAL;
|
|
588
|
+
}
|
|
589
|
+
function buildReverse(field) {
|
|
590
|
+
if (!isCheckbox(field)) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
return field.advanced?.reverse !== false;
|
|
594
|
+
}
|
|
595
|
+
function buildDisabled(field, disabled) {
|
|
596
|
+
const readonly = field.readonly ?? false;
|
|
597
|
+
return disabled ? disabled : readonly;
|
|
598
|
+
}
|
|
599
|
+
function buildSource(field) {
|
|
600
|
+
if (isRadio(field) || isSelect(field) && !field.disabled) {
|
|
601
|
+
const source = field.source;
|
|
602
|
+
if (Array.isArray(source) || isObject(source) && !($REF in source)) {
|
|
603
|
+
return source;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// ../luna-core/src/util/date.ts
|
|
609
|
+
var REGEX_DIGITS = /^\d+$/;
|
|
610
|
+
function getMonth() {
|
|
611
|
+
return Array.from({ length: 12 }, (_, i) => ({
|
|
612
|
+
value: (i + 1).toString(),
|
|
613
|
+
label: new Date(0, i).toLocaleString("default", {
|
|
614
|
+
month: "long"
|
|
615
|
+
})
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
function getYear(min2, max2) {
|
|
619
|
+
if (max2 >= min2) {
|
|
620
|
+
return Array.from({ length: max2 - min2 + 1 }, (_, i) => {
|
|
621
|
+
const year = min2 + i;
|
|
622
|
+
return {
|
|
623
|
+
value: year.toString(),
|
|
624
|
+
label: year.toString()
|
|
625
|
+
};
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
return [];
|
|
629
|
+
}
|
|
630
|
+
function getCurrentYear() {
|
|
631
|
+
return (/* @__PURE__ */ new Date()).getFullYear();
|
|
632
|
+
}
|
|
633
|
+
function getConvert(value, current) {
|
|
634
|
+
if (typeof value === "number") {
|
|
635
|
+
return value;
|
|
636
|
+
}
|
|
637
|
+
const now2 = current ?? getCurrentYear();
|
|
638
|
+
const trimmed = value.trim().toLowerCase();
|
|
639
|
+
if (trimmed.startsWith("current")) {
|
|
640
|
+
const match = trimmed.match(/^current([+-])(\d+)$/);
|
|
641
|
+
if (match) {
|
|
642
|
+
const [, operator, offsetStr] = match;
|
|
643
|
+
const offset = parseInt(offsetStr, 10);
|
|
644
|
+
if (!isNaN(offset)) {
|
|
645
|
+
return operator === "+" ? now2 + offset : now2 - offset;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return now2;
|
|
649
|
+
}
|
|
650
|
+
if (REGEX_DIGITS.test(trimmed)) {
|
|
651
|
+
return parseInt(trimmed, 10);
|
|
652
|
+
}
|
|
653
|
+
return now2;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// ../luna-core/src/helper/input.ts
|
|
657
|
+
var now = getCurrentYear();
|
|
658
|
+
function buildOptionSelect(field) {
|
|
659
|
+
if (isSelect(field)) {
|
|
660
|
+
return defineOption(field);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function defineOption(select) {
|
|
664
|
+
if (isSelectMonth(select)) {
|
|
665
|
+
return getMonth();
|
|
666
|
+
}
|
|
667
|
+
if (isSelectYear(select)) {
|
|
668
|
+
const min2 = select.advanced?.length?.min ?? now;
|
|
669
|
+
const max2 = select.advanced?.length?.max ?? now + 5;
|
|
670
|
+
return getYear(getConvert(min2, now), getConvert(max2, now));
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
function buildCommon(field, disabled = false) {
|
|
674
|
+
const commonProps = {
|
|
675
|
+
disabled,
|
|
676
|
+
id: field.name,
|
|
677
|
+
name: field.name,
|
|
678
|
+
placeholder: field.placeholder,
|
|
679
|
+
required: field.required
|
|
680
|
+
};
|
|
681
|
+
if (isInput(field)) {
|
|
682
|
+
return {
|
|
683
|
+
...commonProps,
|
|
684
|
+
...defineInput(field)
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
if (isSelect(field)) {
|
|
688
|
+
return {
|
|
689
|
+
...commonProps,
|
|
690
|
+
...defineSelect(field)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
if (isTextArea(field)) {
|
|
694
|
+
return {
|
|
695
|
+
...commonProps,
|
|
696
|
+
...defineTextArea(field)
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
return commonProps;
|
|
700
|
+
}
|
|
701
|
+
function defineInput(input) {
|
|
702
|
+
const type = getType(input.type);
|
|
703
|
+
const copy = { ...input, type };
|
|
704
|
+
return {
|
|
705
|
+
...defineAutoComplete(input),
|
|
706
|
+
...defineNumberLimits(copy),
|
|
707
|
+
...isText(copy) ? defineLength(copy) : {},
|
|
708
|
+
type
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
function defineSelect(field) {
|
|
712
|
+
const options = buildOptionSelect(field);
|
|
713
|
+
if (options) {
|
|
714
|
+
return { options };
|
|
715
|
+
}
|
|
716
|
+
return {};
|
|
717
|
+
}
|
|
718
|
+
function defineTextArea(field) {
|
|
719
|
+
return {
|
|
720
|
+
...defineAutoComplete(field),
|
|
721
|
+
...defineLength(field)
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function defineAutoComplete(input) {
|
|
725
|
+
const autoComplete = input.advanced?.autocomplete;
|
|
726
|
+
if (autoComplete) {
|
|
727
|
+
return { autoComplete };
|
|
728
|
+
}
|
|
729
|
+
return {};
|
|
730
|
+
}
|
|
731
|
+
function defineNumberLimits(input) {
|
|
732
|
+
if (isNumber(input)) {
|
|
733
|
+
return defineMinMax(input);
|
|
734
|
+
}
|
|
735
|
+
return {};
|
|
736
|
+
}
|
|
737
|
+
function defineLength(input) {
|
|
738
|
+
return defineConstraints(input, { min: MIN_LENGTH, max: MAX_LENGTH });
|
|
739
|
+
}
|
|
740
|
+
function defineMinMax(input) {
|
|
741
|
+
return defineConstraints(input, { min: MIN, max: MAX });
|
|
742
|
+
}
|
|
743
|
+
function defineConstraints(input, keys) {
|
|
744
|
+
const result = {};
|
|
745
|
+
const length = input.advanced?.length;
|
|
746
|
+
if (length) {
|
|
747
|
+
if (length.min !== void 0) {
|
|
748
|
+
result[keys.min] = length.min;
|
|
749
|
+
}
|
|
750
|
+
if (length.max !== void 0) {
|
|
751
|
+
result[keys.max] = length.max;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return result;
|
|
755
|
+
}
|
|
756
|
+
function resolveSource(field, value) {
|
|
757
|
+
const current = buildSource(field);
|
|
758
|
+
if (current) {
|
|
759
|
+
return current;
|
|
760
|
+
}
|
|
761
|
+
return buildOptions(field, value);
|
|
762
|
+
}
|
|
763
|
+
function getInputValue(field, value) {
|
|
764
|
+
const newValue = isObject(value) && field.name in value ? value[field.name] : value;
|
|
765
|
+
return getCurrentValue(newValue, field.advanced?.entity);
|
|
766
|
+
}
|
|
767
|
+
function mergeOptionsProps(field, commonProps, options) {
|
|
768
|
+
return isOptions(field) && Array.isArray(options) ? { ...commonProps, [OPTIONS]: options } : commonProps;
|
|
769
|
+
}
|
|
770
|
+
function getPreselectedValue(field, commonProps, value) {
|
|
771
|
+
if (field.required && !isValidValue(value)) {
|
|
772
|
+
if (isSelect(field)) {
|
|
773
|
+
if (field.advanced?.preselected !== false && OPTIONS in commonProps) {
|
|
774
|
+
const options = commonProps[OPTIONS];
|
|
775
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
776
|
+
return options[0];
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
return value;
|
|
782
|
+
}
|
|
783
|
+
function getOptions(field, data) {
|
|
784
|
+
if (isSelect(field) && Array.isArray(data)) {
|
|
785
|
+
return toOptions(data, field.advanced?.options);
|
|
786
|
+
}
|
|
787
|
+
return data;
|
|
788
|
+
}
|
|
789
|
+
function prepareInputProps(field, commonProps, data, value) {
|
|
790
|
+
const currentValue = getInputValue(field, value);
|
|
791
|
+
const options = Array.isArray(data) ? getOptions(field, data) : data;
|
|
792
|
+
const commonPropsWithOptions = mergeOptionsProps(field, commonProps, options);
|
|
793
|
+
const defaultValue = getPreselectedValue(
|
|
794
|
+
field,
|
|
795
|
+
commonPropsWithOptions,
|
|
796
|
+
currentValue
|
|
797
|
+
);
|
|
798
|
+
return {
|
|
799
|
+
commonPropsWithOptions,
|
|
800
|
+
defaultValue
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function prepareInputValue(field, value) {
|
|
804
|
+
if (isCheckbox(field)) {
|
|
805
|
+
return {
|
|
806
|
+
checked: isValidValue(value) ? value : false
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return { value: value ?? "" };
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// ../luna-core/src/util/prepare.ts
|
|
813
|
+
var REGEX_REF = /^#\/definition\//;
|
|
814
|
+
function prepare(base = [], definition) {
|
|
815
|
+
const resolved = resolveRefs(base, definition);
|
|
816
|
+
return Array.isArray(resolved) ? resolved.filter(filter).sort((a, b) => getOrder(a) - getOrder(b)) : [];
|
|
817
|
+
}
|
|
818
|
+
function resolveRefs(base, definition, cache = /* @__PURE__ */ new Map(), visited = /* @__PURE__ */ new WeakSet()) {
|
|
819
|
+
if (!isDefinition(definition) || !base || typeof base !== "object") {
|
|
820
|
+
return base;
|
|
821
|
+
}
|
|
822
|
+
if (cache.has(base)) {
|
|
823
|
+
return cache.get(base);
|
|
824
|
+
}
|
|
825
|
+
if (visited.has(base)) {
|
|
826
|
+
return base;
|
|
827
|
+
}
|
|
828
|
+
visited.add(base);
|
|
829
|
+
if (Array.isArray(base)) {
|
|
830
|
+
return base.map((item) => resolveRefs(item, definition, cache, visited));
|
|
831
|
+
}
|
|
832
|
+
if ($REF in base && isString(base[$REF])) {
|
|
833
|
+
const path = base[$REF].replace(REGEX_REF, "");
|
|
834
|
+
const resolved = extract(definition, path);
|
|
835
|
+
if (resolved !== null) {
|
|
836
|
+
return resolveRefs(resolved, definition, cache, visited);
|
|
837
|
+
}
|
|
838
|
+
return base;
|
|
839
|
+
}
|
|
840
|
+
const result = {};
|
|
841
|
+
for (const [key, value] of Object.entries(base)) {
|
|
842
|
+
result[key] = resolveRefs(value, definition, cache, visited);
|
|
843
|
+
}
|
|
844
|
+
visited.delete(base);
|
|
845
|
+
cache.set(base, result);
|
|
846
|
+
return result;
|
|
847
|
+
}
|
|
848
|
+
function entries(values) {
|
|
849
|
+
return Object.entries(values ?? {});
|
|
850
|
+
}
|
|
851
|
+
function getOrder(item) {
|
|
852
|
+
return item.order ?? Number.MAX_VALUE;
|
|
853
|
+
}
|
|
854
|
+
function isDefinition(definition) {
|
|
855
|
+
return definition !== void 0 && isObject(definition) && Object.keys(definition).length > 0;
|
|
856
|
+
}
|
|
857
|
+
function filter(base) {
|
|
858
|
+
if (TYPE in base) {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
if (Array.isArray(base[FIELDS])) {
|
|
862
|
+
return base[FIELDS].length > 0;
|
|
863
|
+
}
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// ../luna-core/src/util/attributes.ts
|
|
868
|
+
function getPrefixedAttributes(prefix, record) {
|
|
869
|
+
const attrs = {};
|
|
870
|
+
for (const [key, value] of entries(record)) {
|
|
871
|
+
attrs[`${prefix}-${key}`] = value;
|
|
872
|
+
}
|
|
873
|
+
return attrs;
|
|
874
|
+
}
|
|
875
|
+
function getAriaAttributes(record) {
|
|
876
|
+
return getPrefixedAttributes(PREFIX_ARIA, record);
|
|
877
|
+
}
|
|
878
|
+
function getDataAttributes(record) {
|
|
879
|
+
return getPrefixedAttributes(PREFIX_DATA, record);
|
|
880
|
+
}
|
|
881
|
+
function buildAriaAttributes(field, errors) {
|
|
882
|
+
const ariaAttributes = getAriaAttributes(field.advanced?.aria);
|
|
883
|
+
if (errors && errors.length > 0) {
|
|
884
|
+
ariaAttributes[ARIA_INVALID] = "true";
|
|
885
|
+
ariaAttributes[ARIA_ERROR_MESSAGE] = `${field.name}-error`;
|
|
886
|
+
}
|
|
887
|
+
return ariaAttributes;
|
|
888
|
+
}
|
|
889
|
+
function buildDataAttributes(field) {
|
|
890
|
+
return getDataAttributes(field.advanced?.data);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// ../luna-core/src/util/column.ts
|
|
894
|
+
var cols = {
|
|
895
|
+
1: "md:grid-cols-1",
|
|
896
|
+
2: "md:grid-cols-2",
|
|
897
|
+
3: "md:grid-cols-3"
|
|
898
|
+
};
|
|
899
|
+
var span = {
|
|
900
|
+
1: "md:col-span-1",
|
|
901
|
+
2: "md:col-span-2",
|
|
902
|
+
3: "md:col-span-3"
|
|
903
|
+
};
|
|
904
|
+
function getColumn(value, defaultCols = 2) {
|
|
905
|
+
return cols[value && value in cols ? value : defaultCols];
|
|
906
|
+
}
|
|
907
|
+
function getSpan(value) {
|
|
908
|
+
if (value && value in span) {
|
|
909
|
+
return span[value];
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// ../luna-core/src/util/list.ts
|
|
914
|
+
function getInitialCount(list, value) {
|
|
915
|
+
const min2 = list.advanced?.length?.min ?? 1;
|
|
916
|
+
if (value) {
|
|
917
|
+
const data = extract(value, list.name);
|
|
918
|
+
if (Array.isArray(data)) {
|
|
919
|
+
return Math.max(data.length, min2);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return Math.max(min2, 0);
|
|
923
|
+
}
|
|
924
|
+
function isMultiFieldList(list) {
|
|
925
|
+
if (!Array.isArray(list.fields) || list.fields.length === 0) {
|
|
926
|
+
return false;
|
|
927
|
+
}
|
|
928
|
+
return list.fields.length > 1 || list.fields[0].type === COLUMN;
|
|
929
|
+
}
|
|
930
|
+
function getInitialList(list, value) {
|
|
931
|
+
const count = getInitialCount(list, value);
|
|
932
|
+
return Array.from({ length: count }, (_, index) => index);
|
|
933
|
+
}
|
|
934
|
+
function getLabel(list) {
|
|
935
|
+
return list.label ?? list.name;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// ../luna-core/src/util/schema.ts
|
|
939
|
+
var import_zod = require("zod");
|
|
940
|
+
|
|
941
|
+
// ../luna-core/src/util/translate.ts
|
|
942
|
+
function translate(key, dictionary) {
|
|
943
|
+
if (!key) {
|
|
944
|
+
return "";
|
|
945
|
+
}
|
|
946
|
+
if (!dictionary) {
|
|
947
|
+
return key;
|
|
948
|
+
}
|
|
949
|
+
return dictionary[key] ?? key;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// ../luna-core/src/util/schema.ts
|
|
953
|
+
var approach = [
|
|
954
|
+
[isNumber, getNumber],
|
|
955
|
+
[isEmail, getEmail],
|
|
956
|
+
[isSelectYear, getYearSchema],
|
|
957
|
+
[isSelectMonth, getMonthSchema],
|
|
958
|
+
[isCheckbox, getBoolean],
|
|
959
|
+
[isRadio, getRadio]
|
|
960
|
+
];
|
|
961
|
+
function buildSchema(schemas, fields = [], translations) {
|
|
962
|
+
const schema = import_zod.z.object(schemas);
|
|
963
|
+
if (fields.length === 0) {
|
|
964
|
+
return schema;
|
|
965
|
+
}
|
|
966
|
+
return applyCustomValidation(schema, fields, translations);
|
|
967
|
+
}
|
|
968
|
+
function flatten(error) {
|
|
969
|
+
const results = {};
|
|
970
|
+
const errors = import_zod.z.flattenError(error).fieldErrors;
|
|
971
|
+
for (const [key, value] of Object.entries(errors)) {
|
|
972
|
+
if (value !== void 0) {
|
|
973
|
+
results[key] = value;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return results;
|
|
977
|
+
}
|
|
978
|
+
function getSchema(input, translations) {
|
|
979
|
+
for (const [check, getSchema2] of approach) {
|
|
980
|
+
if (check(input)) {
|
|
981
|
+
return getSchema2(input, translations);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return getText(input, translations);
|
|
985
|
+
}
|
|
986
|
+
function getEmail(input, translations) {
|
|
987
|
+
const baseSchema = import_zod.z.string().trim();
|
|
988
|
+
if (input.required) {
|
|
989
|
+
const message = getRequiredMessage(input, translations);
|
|
990
|
+
const schema = baseSchema.min(1, message).pipe(applyEmail(input, translations));
|
|
991
|
+
return import_zod.z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
992
|
+
}
|
|
993
|
+
return baseSchema.pipe(applyEmail(input, translations)).or(import_zod.z.literal("")).nullable();
|
|
994
|
+
}
|
|
995
|
+
function getBoolean(input, translations) {
|
|
996
|
+
let schema = import_zod.z.coerce.boolean();
|
|
997
|
+
if (input.required) {
|
|
998
|
+
schema = schema.refine((value) => value === true, {
|
|
999
|
+
message: getRequiredMessage(input, translations)
|
|
1000
|
+
});
|
|
1001
|
+
return import_zod.z.preprocess((value) => value === null ? false : value, schema);
|
|
1002
|
+
}
|
|
1003
|
+
return schema.nullable();
|
|
1004
|
+
}
|
|
1005
|
+
function getRadio(input, translations) {
|
|
1006
|
+
let schema = import_zod.z.coerce.string();
|
|
1007
|
+
if (input.required) {
|
|
1008
|
+
schema = schema.min(1, getRequiredMessage(input, translations));
|
|
1009
|
+
return import_zod.z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
1010
|
+
}
|
|
1011
|
+
return schema.or(import_zod.z.literal("")).nullable();
|
|
1012
|
+
}
|
|
1013
|
+
function getText(input, translations) {
|
|
1014
|
+
let schema = import_zod.z.coerce.string().trim();
|
|
1015
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
1016
|
+
if (input.required) {
|
|
1017
|
+
schema = applyRequired(schema, input, translations);
|
|
1018
|
+
return import_zod.z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
1019
|
+
}
|
|
1020
|
+
return schema.nullable();
|
|
1021
|
+
}
|
|
1022
|
+
function getNumber(input, translations) {
|
|
1023
|
+
let schema = import_zod.z.coerce.number().int();
|
|
1024
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
1025
|
+
if (input.required) {
|
|
1026
|
+
schema = applyRequired(schema, input, translations);
|
|
1027
|
+
return import_zod.z.preprocess((value) => value === null ? void 0 : value, schema);
|
|
1028
|
+
}
|
|
1029
|
+
return schema.nullable();
|
|
1030
|
+
}
|
|
1031
|
+
function getYearSchema(input, translations) {
|
|
1032
|
+
if (input.required) {
|
|
1033
|
+
return import_zod.z.preprocess(
|
|
1034
|
+
normalize,
|
|
1035
|
+
import_zod.z.coerce.number({ message: getRequiredMessage(input, translations) }).int()
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
return import_zod.z.coerce.number().int().nullable();
|
|
1039
|
+
}
|
|
1040
|
+
function getMonthSchema(input, translations) {
|
|
1041
|
+
const message = getRequiredMessage(input, translations);
|
|
1042
|
+
const schema = import_zod.z.coerce.number().int().min(1, message).max(12, message);
|
|
1043
|
+
return !input.required ? schema.nullable() : schema;
|
|
1044
|
+
}
|
|
1045
|
+
function normalize(value) {
|
|
1046
|
+
return value === null || value === "" ? void 0 : value;
|
|
1047
|
+
}
|
|
1048
|
+
function applyEmail(input, translations) {
|
|
1049
|
+
const message = input.validation?.email ? translate(input.validation?.email, translations) : void 0;
|
|
1050
|
+
return import_zod.z.email(message);
|
|
1051
|
+
}
|
|
1052
|
+
function applyMinAndMax(schema, input, translations) {
|
|
1053
|
+
schema = min(schema, input, translations);
|
|
1054
|
+
schema = max(schema, input, translations);
|
|
1055
|
+
return schema;
|
|
1056
|
+
}
|
|
1057
|
+
function applyRequired(schema, input, translations) {
|
|
1058
|
+
const min2 = input.advanced?.length?.min;
|
|
1059
|
+
if (min2 === void 0 || min2 < 1) {
|
|
1060
|
+
return schema.min(1, getRequiredMessage(input, translations));
|
|
1061
|
+
}
|
|
1062
|
+
return schema;
|
|
1063
|
+
}
|
|
1064
|
+
var min = (schema, input, translations) => applyConstraint(schema, input, MIN, translations);
|
|
1065
|
+
var max = (schema, input, translations) => applyConstraint(schema, input, MAX, translations);
|
|
1066
|
+
function applyConstraint(schema, input, method, translations) {
|
|
1067
|
+
const value = input.advanced?.length?.[method];
|
|
1068
|
+
if (value !== void 0) {
|
|
1069
|
+
const message = input.validation?.length?.[method] ? translate(input.validation?.length?.[method], translations) : void 0;
|
|
1070
|
+
return schema[method](value, message);
|
|
1071
|
+
}
|
|
1072
|
+
return schema;
|
|
1073
|
+
}
|
|
1074
|
+
function applyCustomValidation(schema, fields = [], translations) {
|
|
1075
|
+
const rules = getRules(fields);
|
|
1076
|
+
if (rules.length === 0) {
|
|
1077
|
+
return schema;
|
|
1078
|
+
}
|
|
1079
|
+
return schema.superRefine((data, context) => {
|
|
1080
|
+
for (const { name, rule } of rules) {
|
|
1081
|
+
if (!evaluate(data, name, rule)) {
|
|
1082
|
+
const message = translate(rule.message, translations);
|
|
1083
|
+
context.addIssue({
|
|
1084
|
+
code: "custom",
|
|
1085
|
+
message,
|
|
1086
|
+
path: [name]
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
function evaluate(data, name, rule) {
|
|
1093
|
+
const operator = rule.operator ?? "eq";
|
|
1094
|
+
const operation = operators[operator];
|
|
1095
|
+
if (operation) {
|
|
1096
|
+
return operation(data[name], data[rule.field]);
|
|
1097
|
+
}
|
|
1098
|
+
return false;
|
|
1099
|
+
}
|
|
1100
|
+
function getRules(fields) {
|
|
1101
|
+
const results = [];
|
|
1102
|
+
for (const field of fields) {
|
|
1103
|
+
const custom = field.validation?.custom;
|
|
1104
|
+
if (!custom) {
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
const rules = Array.isArray(custom) ? custom : [custom];
|
|
1108
|
+
for (const rule of rules) {
|
|
1109
|
+
results.push({ name: field.name, rule });
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return results;
|
|
1113
|
+
}
|
|
1114
|
+
function validateCustom(value, rules, getValue3, translations) {
|
|
1115
|
+
const errors = [];
|
|
1116
|
+
const collections = Array.isArray(rules) ? rules : [rules];
|
|
1117
|
+
for (const rule of collections) {
|
|
1118
|
+
const operator = rule.operator ?? "eq";
|
|
1119
|
+
const operation = operators[operator];
|
|
1120
|
+
if (operation && !operation(value, getValue3(rule.field))) {
|
|
1121
|
+
if (rule.message) {
|
|
1122
|
+
const message = translate(rule.message, translations);
|
|
1123
|
+
errors.push(message);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return errors;
|
|
1128
|
+
}
|
|
1129
|
+
function getRequiredMessage(input, translations) {
|
|
1130
|
+
return input.validation?.required ? translate(input.validation?.required, translations) : void 0;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// ../luna-core/src/util/url.ts
|
|
1134
|
+
function matchRemotePattern(urlStr, patterns) {
|
|
1135
|
+
if (!patterns || !isExternalUrl(urlStr)) {
|
|
1136
|
+
return true;
|
|
1137
|
+
}
|
|
1138
|
+
if (patterns.length === 0) {
|
|
1139
|
+
return false;
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
const url = new URL(urlStr);
|
|
1143
|
+
const protocol = url.protocol.replace(":", "");
|
|
1144
|
+
const hostname = url.hostname;
|
|
1145
|
+
const port = url.port || getPort(protocol);
|
|
1146
|
+
return patterns.some((pattern) => {
|
|
1147
|
+
if (pattern.protocol && pattern.protocol !== protocol) {
|
|
1148
|
+
return false;
|
|
1149
|
+
}
|
|
1150
|
+
if (pattern.hostname && pattern.hostname !== hostname) {
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
if (pattern.port !== void 0 && String(pattern.port) !== port) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
return true;
|
|
1157
|
+
});
|
|
1158
|
+
} catch {
|
|
1159
|
+
return false;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
function getPort(protocol) {
|
|
1163
|
+
return protocol === "https" ? "443" : "80";
|
|
1164
|
+
}
|
|
1165
|
+
function isExternalUrl(url) {
|
|
1166
|
+
return /^(https?:)?\/\//.test(url);
|
|
1167
|
+
}
|
|
1168
|
+
function mergeUrl(baseUrl, targetUrl) {
|
|
1169
|
+
try {
|
|
1170
|
+
if (!baseUrl) {
|
|
1171
|
+
return targetUrl;
|
|
1172
|
+
}
|
|
1173
|
+
if (!targetUrl) {
|
|
1174
|
+
return baseUrl;
|
|
1175
|
+
}
|
|
1176
|
+
const url1 = new URL(baseUrl, COMMON_URL);
|
|
1177
|
+
const url2 = new URL(targetUrl, COMMON_URL);
|
|
1178
|
+
url2.searchParams.forEach((value, key) => {
|
|
1179
|
+
url1.searchParams.set(key, value);
|
|
1180
|
+
});
|
|
1181
|
+
const result = url1.toString();
|
|
1182
|
+
return baseUrl.startsWith("/") || !baseUrl.includes("://") ? result.replace(COMMON_URL, "") : result;
|
|
1183
|
+
} catch {
|
|
1184
|
+
return targetUrl || baseUrl;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// ../luna-core/src/util/source.ts
|
|
1189
|
+
function mergeSource(sources) {
|
|
1190
|
+
if (!Array.isArray(sources) || sources.length === 0) {
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
return sources.reduce((previous, current) => {
|
|
1194
|
+
const url = mergeUrl(previous.url, current.url);
|
|
1195
|
+
const body = getBody(previous, current);
|
|
1196
|
+
const headers = getHeaders(previous, current);
|
|
1197
|
+
return {
|
|
1198
|
+
...previous,
|
|
1199
|
+
...current,
|
|
1200
|
+
url,
|
|
1201
|
+
body,
|
|
1202
|
+
headers
|
|
1203
|
+
};
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
function getBody(previous, current) {
|
|
1207
|
+
if (isObject(current.body) && isObject(previous?.body)) {
|
|
1208
|
+
return {
|
|
1209
|
+
...previous.body,
|
|
1210
|
+
...current.body
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
return current.body ?? previous?.body;
|
|
1214
|
+
}
|
|
1215
|
+
function getHeaders(previous, current) {
|
|
1216
|
+
if (isObject(current.headers) && isObject(previous?.headers)) {
|
|
1217
|
+
return {
|
|
1218
|
+
...previous.headers,
|
|
1219
|
+
...current.headers
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
return current.headers ?? previous?.headers;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// ../luna-core/src/util/style.ts
|
|
1226
|
+
function mergeStyle(globalStyle, localStyle) {
|
|
1227
|
+
return { ...globalStyle, ...localStyle };
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// src/lib/string.tsx
|
|
1231
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1232
|
+
function formatMarkdown2(text) {
|
|
1233
|
+
return formatMarkdown(
|
|
1234
|
+
text,
|
|
1235
|
+
(index, url, text2) => {
|
|
1236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1237
|
+
"a",
|
|
1238
|
+
{
|
|
1239
|
+
className: "underline",
|
|
1240
|
+
href: url,
|
|
1241
|
+
rel: "noopener noreferrer",
|
|
1242
|
+
target: "_blank",
|
|
1243
|
+
children: text2
|
|
1244
|
+
},
|
|
1245
|
+
`${url}-${index}`
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// src/component/field/field-set-advanced.tsx
|
|
1252
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1253
|
+
function FieldSetAdvanced(props) {
|
|
1254
|
+
const { fields = [] } = props.section;
|
|
1255
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
1256
|
+
const handleOpen = (0, import_react.useCallback)(() => setIsOpen((previous) => !previous), []);
|
|
1257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1258
|
+
"fieldset",
|
|
1259
|
+
{
|
|
1260
|
+
"data-slot": "field-set",
|
|
1261
|
+
"data-advanced": "true",
|
|
1262
|
+
"data-expanded": isOpen,
|
|
1263
|
+
"data-empty": fields.length === 0,
|
|
1264
|
+
className: "flex flex-col",
|
|
1265
|
+
id: props.section.id?.toString(),
|
|
1266
|
+
children: [
|
|
1267
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1268
|
+
"button",
|
|
1269
|
+
{
|
|
1270
|
+
className: "flex cursor-pointer items-center gap-2 text-base font-medium text-slate-600 dark:text-slate-400",
|
|
1271
|
+
onClick: handleOpen,
|
|
1272
|
+
type: "button",
|
|
1273
|
+
children: [
|
|
1274
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChevronIcon, { expanded: isOpen }),
|
|
1275
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: formatMarkdown2(props.section.title) })
|
|
1276
|
+
]
|
|
1277
|
+
}
|
|
1278
|
+
) }),
|
|
1279
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react.Activity, { mode: isOpen ? "visible" : "hidden", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1280
|
+
"div",
|
|
1281
|
+
{
|
|
1282
|
+
className: "mt-3 ml-1.5 flex flex-col gap-4 border-l-2 border-slate-300 pl-4 dark:border-slate-600",
|
|
1283
|
+
"data-slot": "field-set-content",
|
|
1284
|
+
children: [
|
|
1285
|
+
props.section.description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.section.description) }),
|
|
1286
|
+
props.group
|
|
1287
|
+
]
|
|
1288
|
+
}
|
|
1289
|
+
) })
|
|
1290
|
+
]
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// src/component/legend.tsx
|
|
1296
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1297
|
+
function Legend(props) {
|
|
1298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1299
|
+
props.title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { className: "mb-3 font-medium text-slate-800 dark:text-slate-200", children: formatMarkdown2(props.title) }),
|
|
1300
|
+
props.description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.description) })
|
|
1301
|
+
] });
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// src/component/field/field-set-base.tsx
|
|
1305
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1306
|
+
function FieldSetBase(props) {
|
|
1307
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1308
|
+
"fieldset",
|
|
1309
|
+
{
|
|
1310
|
+
"data-slot": "field-set",
|
|
1311
|
+
"data-empty": props.empty,
|
|
1312
|
+
className: "flex flex-col data-[empty=false]:gap-6",
|
|
1313
|
+
id: props.id,
|
|
1314
|
+
children: [
|
|
1315
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Legend, { description: props.description, title: props.title }),
|
|
1316
|
+
props.children
|
|
1317
|
+
]
|
|
1318
|
+
}
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// src/component/group.tsx
|
|
1323
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1324
|
+
function Group(props) {
|
|
1325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1326
|
+
"div",
|
|
1327
|
+
{
|
|
1328
|
+
"data-slot": "field-group",
|
|
1329
|
+
"data-compact": props.compact,
|
|
1330
|
+
className: "flex w-full flex-col gap-8 data-[compact=true]:gap-3",
|
|
1331
|
+
children: props.children
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// src/component/field/field-set.tsx
|
|
1337
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1338
|
+
function FieldSet(props) {
|
|
1339
|
+
const { fields = [] } = props.section;
|
|
1340
|
+
const { compact } = mergeStyle(props.style, {
|
|
1341
|
+
compact: props.section.compact
|
|
1342
|
+
});
|
|
1343
|
+
const group = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Group, { compact, children: props.children });
|
|
1344
|
+
if (!props.section.title && !props.section.description) {
|
|
1345
|
+
return group;
|
|
1346
|
+
}
|
|
1347
|
+
if (props.section.advanced) {
|
|
1348
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FieldSetAdvanced, { section: props.section, group });
|
|
1349
|
+
}
|
|
1350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1351
|
+
FieldSetBase,
|
|
1352
|
+
{
|
|
1353
|
+
description: props.section.description,
|
|
1354
|
+
empty: fields.length === 0,
|
|
1355
|
+
id: props.section.id?.toString(),
|
|
1356
|
+
title: props.section.title,
|
|
1357
|
+
children: group
|
|
1358
|
+
}
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// src/client/component/guard/visibility-guard.tsx
|
|
1363
|
+
var import_jotai2 = require("jotai");
|
|
1364
|
+
|
|
1365
|
+
// src/client/lib/store-helper.ts
|
|
1366
|
+
var import_jotai = require("jotai");
|
|
1367
|
+
var import_jotai_family = require("jotai-family");
|
|
1368
|
+
var import_fast_equals = require("fast-equals");
|
|
1369
|
+
function createRecordAtomFamily(baseAtom) {
|
|
1370
|
+
return (0, import_jotai_family.atomFamily)(
|
|
1371
|
+
(name) => (0, import_jotai.atom)(
|
|
1372
|
+
(get) => {
|
|
1373
|
+
return get(baseAtom)[name] ?? void 0;
|
|
1374
|
+
},
|
|
1375
|
+
(get, set, newValue) => {
|
|
1376
|
+
const current = get(baseAtom);
|
|
1377
|
+
if (newValue !== void 0 && newValue !== null) {
|
|
1378
|
+
const currentValue = current[name];
|
|
1379
|
+
if (!currentValue || !(0, import_fast_equals.deepEqual)(currentValue, newValue)) {
|
|
1380
|
+
set(baseAtom, { ...current, [name]: newValue });
|
|
1381
|
+
}
|
|
1382
|
+
} else if (current[name]) {
|
|
1383
|
+
const { [name]: _unused, ...rest } = current;
|
|
1384
|
+
set(baseAtom, rest);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
)
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1390
|
+
function createClearAllAtom(baseAtom) {
|
|
1391
|
+
return (0, import_jotai.atom)(null, (get, set) => {
|
|
1392
|
+
const current = get(baseAtom);
|
|
1393
|
+
if (current && Object.keys(current).length > 0) {
|
|
1394
|
+
set(baseAtom, {});
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
function createClearAtom(baseAtom) {
|
|
1399
|
+
return (0, import_jotai.atom)(null, (get, set, names) => {
|
|
1400
|
+
const current = get(baseAtom);
|
|
1401
|
+
const next = { ...current };
|
|
1402
|
+
let hasChanges = false;
|
|
1403
|
+
for (const name of names) {
|
|
1404
|
+
if (next[name]) {
|
|
1405
|
+
delete next[name];
|
|
1406
|
+
hasChanges = true;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (hasChanges) {
|
|
1410
|
+
set(baseAtom, next);
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
function createBulkReportAtom(baseAtom) {
|
|
1415
|
+
return (0, import_jotai.atom)(null, (get, set, newValue) => {
|
|
1416
|
+
const current = get(baseAtom);
|
|
1417
|
+
if (!(0, import_fast_equals.deepEqual)(current, newValue)) {
|
|
1418
|
+
set(baseAtom, newValue);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
function createNestedRecordAtomFamily(baseAtom, options = {}) {
|
|
1423
|
+
const { merge: merge2, validateTarget } = options;
|
|
1424
|
+
return (0, import_jotai_family.atomFamily)(
|
|
1425
|
+
(contributorName) => (0, import_jotai.atom)(
|
|
1426
|
+
(get) => {
|
|
1427
|
+
const current = get(baseAtom)[contributorName];
|
|
1428
|
+
if (current && merge2) {
|
|
1429
|
+
return merge2(Object.values(current));
|
|
1430
|
+
}
|
|
1431
|
+
return void 0;
|
|
1432
|
+
},
|
|
1433
|
+
(get, set, target, value) => {
|
|
1434
|
+
if (validateTarget && !validateTarget(target)) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
const current = get(baseAtom);
|
|
1438
|
+
const targetContributions = { ...current[target] ?? {} };
|
|
1439
|
+
if (value !== void 0 && value !== null) {
|
|
1440
|
+
const currentContribution = targetContributions[contributorName];
|
|
1441
|
+
if (!currentContribution || !(0, import_fast_equals.deepEqual)(currentContribution, value)) {
|
|
1442
|
+
targetContributions[contributorName] = value;
|
|
1443
|
+
set(baseAtom, {
|
|
1444
|
+
...current,
|
|
1445
|
+
[target]: targetContributions
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
} else if (targetContributions[contributorName]) {
|
|
1449
|
+
delete targetContributions[contributorName];
|
|
1450
|
+
if (Object.keys(targetContributions).length === 0) {
|
|
1451
|
+
const { [target]: _unused, ...rest } = current;
|
|
1452
|
+
set(baseAtom, rest);
|
|
1453
|
+
} else {
|
|
1454
|
+
set(baseAtom, {
|
|
1455
|
+
...current,
|
|
1456
|
+
[target]: targetContributions
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
)
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
function createNestedClearAtom(baseAtom) {
|
|
1465
|
+
return (0, import_jotai.atom)(null, (get, set, contributorNames) => {
|
|
1466
|
+
const current = get(baseAtom);
|
|
1467
|
+
const next = { ...current };
|
|
1468
|
+
let hasChanges = false;
|
|
1469
|
+
for (const name of contributorNames) {
|
|
1470
|
+
if (next[name]) {
|
|
1471
|
+
delete next[name];
|
|
1472
|
+
hasChanges = true;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
for (const target in next) {
|
|
1476
|
+
const targetContributions = { ...next[target] };
|
|
1477
|
+
let targetChanged = false;
|
|
1478
|
+
for (const contributorName of contributorNames) {
|
|
1479
|
+
if (targetContributions[contributorName]) {
|
|
1480
|
+
delete targetContributions[contributorName];
|
|
1481
|
+
targetChanged = true;
|
|
1482
|
+
hasChanges = true;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
if (targetChanged) {
|
|
1486
|
+
if (Object.keys(targetContributions).length === 0) {
|
|
1487
|
+
delete next[target];
|
|
1488
|
+
} else {
|
|
1489
|
+
next[target] = targetContributions;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (hasChanges) {
|
|
1494
|
+
set(baseAtom, next);
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
function createAtomStore(initialValue = {}) {
|
|
1499
|
+
const baseAtom = (0, import_jotai.atom)(initialValue);
|
|
1500
|
+
return {
|
|
1501
|
+
atom: baseAtom,
|
|
1502
|
+
clearAll: createClearAllAtom(baseAtom),
|
|
1503
|
+
clear: createClearAtom(baseAtom),
|
|
1504
|
+
bulkReport: createBulkReportAtom(baseAtom),
|
|
1505
|
+
report: createRecordAtomFamily(baseAtom)
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// src/client/lib/state-store.ts
|
|
1510
|
+
var store = createAtomStore();
|
|
1511
|
+
var fieldStateAtom = store.atom;
|
|
1512
|
+
var reportFieldStateAtom = store.report;
|
|
1513
|
+
|
|
1514
|
+
// src/client/component/guard/visibility-guard.tsx
|
|
1515
|
+
function isColumnHidden(column, states) {
|
|
1516
|
+
return column.fields.every((field) => isFieldHidden(field, states));
|
|
1517
|
+
}
|
|
1518
|
+
function isFieldHidden(field, states) {
|
|
1519
|
+
return states[field.name]?.hidden ?? field.hidden ?? false;
|
|
1520
|
+
}
|
|
1521
|
+
function isEntryHidden(entry, states) {
|
|
1522
|
+
return isColumn(entry) ? isColumnHidden(entry, states) : isFieldHidden(entry, states);
|
|
1523
|
+
}
|
|
1524
|
+
function VisibilityGuard(props) {
|
|
1525
|
+
const states = (0, import_jotai2.useAtomValue)(fieldStateAtom);
|
|
1526
|
+
if (props.container) {
|
|
1527
|
+
const hidden = states[props.container.name]?.hidden ?? props.container.hidden ?? false;
|
|
1528
|
+
if (hidden) {
|
|
1529
|
+
return null;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
if (props.fields.length === 0) {
|
|
1533
|
+
return null;
|
|
1534
|
+
}
|
|
1535
|
+
const allHidden = props.fields.every((entry) => isEntryHidden(entry, states));
|
|
1536
|
+
if (allHidden) {
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
return props.children;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/component/separator.tsx
|
|
1543
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1544
|
+
function Separator() {
|
|
1545
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { "data-slot": "field-separator", className: "relative -my-2 h-5 text-sm", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800" }) });
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// src/component/form.tsx
|
|
1549
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1550
|
+
function Form(props) {
|
|
1551
|
+
const sections = prepare(props.sections, props.definition);
|
|
1552
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "h-full w-full", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("form", { noValidate: props.noValidate, action: props.action, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Group, { children: [
|
|
1553
|
+
sections.map((section, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(VisibilityGuard, { fields: section.fields ?? [], children: [
|
|
1554
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FieldSet, { section, style: props.config.style, children: props.children({
|
|
1555
|
+
disabled: props.readOnly,
|
|
1556
|
+
fields: section.fields
|
|
1557
|
+
}) }),
|
|
1558
|
+
section.separator && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Separator, {})
|
|
1559
|
+
] }, index)),
|
|
1560
|
+
props.control && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Control, { isPending: props.isPending, children: props.control })
|
|
1561
|
+
] }) }) });
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// src/component/description.tsx
|
|
1565
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1566
|
+
function Description(props) {
|
|
1567
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400", children: props.children });
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// src/component/formatted-description.tsx
|
|
1571
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1572
|
+
function FormattedDescription(props) {
|
|
1573
|
+
const content = formatMarkdown2(props.text);
|
|
1574
|
+
if (content) {
|
|
1575
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Description, { children: content });
|
|
1576
|
+
}
|
|
1577
|
+
return null;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/component/label.tsx
|
|
1581
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
1582
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1583
|
+
function Label(props) {
|
|
1584
|
+
const showOptionalLabel = props.style?.showOptionalLabel ?? true;
|
|
1585
|
+
const normal = isRadio(props.field) || isCheckbox(props.field);
|
|
1586
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1587
|
+
"label",
|
|
1588
|
+
{
|
|
1589
|
+
"data-slot": "field-label",
|
|
1590
|
+
"data-normal": normal,
|
|
1591
|
+
className: (0, import_tailwind_merge.twMerge)(
|
|
1592
|
+
"flex w-fit items-center gap-2 text-sm leading-snug font-medium select-none",
|
|
1593
|
+
"data-[normal=true]:font-normal",
|
|
1594
|
+
"group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"
|
|
1595
|
+
),
|
|
1596
|
+
htmlFor: props.field.name,
|
|
1597
|
+
children: [
|
|
1598
|
+
props.children,
|
|
1599
|
+
showOptionalLabel && !props.field.required && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "text-sm text-slate-600 dark:text-slate-400", children: translate("(Optional)", props.translations) })
|
|
1600
|
+
]
|
|
1601
|
+
}
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// src/component/input-label.tsx
|
|
1606
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1607
|
+
function InputLabel(props) {
|
|
1608
|
+
const interpolateOpts = {
|
|
1609
|
+
context: props.context,
|
|
1610
|
+
env: props.config?.env
|
|
1611
|
+
};
|
|
1612
|
+
const label = interpolateIfNeeded(props.field.label, interpolateOpts);
|
|
1613
|
+
const description = interpolateIfNeeded(
|
|
1614
|
+
props.field.description,
|
|
1615
|
+
interpolateOpts
|
|
1616
|
+
);
|
|
1617
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1618
|
+
"div",
|
|
1619
|
+
{
|
|
1620
|
+
"data-slot": "field-content",
|
|
1621
|
+
className: "flex w-full flex-1 flex-col gap-1.5 leading-snug",
|
|
1622
|
+
children: [
|
|
1623
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1624
|
+
Label,
|
|
1625
|
+
{
|
|
1626
|
+
field: props.field,
|
|
1627
|
+
style: props.config?.style,
|
|
1628
|
+
translations: props.translations,
|
|
1629
|
+
children: translate(label, props.translations)
|
|
1630
|
+
}
|
|
1631
|
+
),
|
|
1632
|
+
props.orientation === HORIZONTAL && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1633
|
+
FormattedDescription,
|
|
1634
|
+
{
|
|
1635
|
+
text: translate(description, props.translations)
|
|
1636
|
+
}
|
|
1637
|
+
)
|
|
1638
|
+
]
|
|
1639
|
+
}
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// src/component/input-group.tsx
|
|
1644
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1645
|
+
function InputGroup(props) {
|
|
1646
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
1647
|
+
props.field.name && props.field.label && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1648
|
+
InputLabel,
|
|
1649
|
+
{
|
|
1650
|
+
config: props.config,
|
|
1651
|
+
context: props.context,
|
|
1652
|
+
field: props.field,
|
|
1653
|
+
orientation: props.orientation,
|
|
1654
|
+
translations: props.translations
|
|
1655
|
+
}
|
|
1656
|
+
),
|
|
1657
|
+
props.children,
|
|
1658
|
+
props.orientation === VERTICAL && props.field.description && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1659
|
+
FormattedDescription,
|
|
1660
|
+
{
|
|
1661
|
+
text: translate(props.field.description, props.translations)
|
|
1662
|
+
}
|
|
1663
|
+
)
|
|
1664
|
+
] });
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// src/lib/render-If-exists.ts
|
|
1668
|
+
function renderIfExists(value, render) {
|
|
1669
|
+
if (!value) {
|
|
1670
|
+
return null;
|
|
1671
|
+
}
|
|
1672
|
+
return render(value);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// src/client/lib/error-store.ts
|
|
1676
|
+
var store2 = createAtomStore();
|
|
1677
|
+
var clearInputErrorAtom = store2.clear;
|
|
1678
|
+
var reportErrorAtom = store2.bulkReport;
|
|
1679
|
+
var reportInputErrorAtom = store2.report;
|
|
1680
|
+
|
|
1681
|
+
// src/client/component/input.tsx
|
|
1682
|
+
var import_react5 = require("react");
|
|
1683
|
+
|
|
1684
|
+
// src/client/lib/source-store.ts
|
|
1685
|
+
var import_jotai3 = require("jotai");
|
|
1686
|
+
var merge = (values) => {
|
|
1687
|
+
const merged = mergeSource(values);
|
|
1688
|
+
if (merged) {
|
|
1689
|
+
return merged;
|
|
1690
|
+
}
|
|
1691
|
+
return void 0;
|
|
1692
|
+
};
|
|
1693
|
+
var validate = (target) => target.trim() !== "";
|
|
1694
|
+
var sourceAtom = (0, import_jotai3.atom)({});
|
|
1695
|
+
var reportSourceAtom = createNestedRecordAtomFamily(
|
|
1696
|
+
sourceAtom,
|
|
1697
|
+
{
|
|
1698
|
+
merge,
|
|
1699
|
+
validateTarget: validate
|
|
1700
|
+
}
|
|
1701
|
+
);
|
|
1702
|
+
var clearInputSourceAtom = createNestedClearAtom(sourceAtom);
|
|
1703
|
+
|
|
1704
|
+
// src/client/hook/use-data-source.ts
|
|
1705
|
+
var import_jotai4 = require("jotai");
|
|
1706
|
+
|
|
1707
|
+
// src/client/hook/use-fetch.ts
|
|
1708
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
1709
|
+
function useFetch(dataSource = null, config, disabled = false) {
|
|
1710
|
+
const { data, error } = (0, import_swr.default)(
|
|
1711
|
+
buildSource2(dataSource, config, disabled),
|
|
1712
|
+
config.fetcher.provider
|
|
1713
|
+
);
|
|
1714
|
+
if (error) {
|
|
1715
|
+
logger.error("Error fetching data source:", error);
|
|
1716
|
+
}
|
|
1717
|
+
if (dataSource) {
|
|
1718
|
+
if (Array.isArray(dataSource)) {
|
|
1719
|
+
return dataSource;
|
|
1720
|
+
}
|
|
1721
|
+
if (data) {
|
|
1722
|
+
return getArray(data, dataSource.namespace);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
function buildSource2(dataSource = null, config, disabled = false) {
|
|
1728
|
+
if (dataSource && !Array.isArray(dataSource) && !disabled) {
|
|
1729
|
+
if (dataSource.url) {
|
|
1730
|
+
const interpolated = isInterpolated(dataSource.url);
|
|
1731
|
+
if (!interpolated) {
|
|
1732
|
+
const allowed = matchRemotePattern(
|
|
1733
|
+
dataSource.url,
|
|
1734
|
+
config.fetcher.remotePatterns
|
|
1735
|
+
);
|
|
1736
|
+
if (allowed) {
|
|
1737
|
+
return dataSource;
|
|
1738
|
+
}
|
|
1739
|
+
logger.warn(
|
|
1740
|
+
`URL blocked by remotePatterns: ${dataSource.url}. Check your luna.config.ts`
|
|
1741
|
+
);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return null;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
// src/client/hook/use-data-source.ts
|
|
1749
|
+
function useDataSource(field, config, value) {
|
|
1750
|
+
const dataSource = resolveSource(field, value);
|
|
1751
|
+
const [source, setSource] = (0, import_jotai4.useAtom)(reportSourceAtom(field.name));
|
|
1752
|
+
const currentSource = source ?? dataSource;
|
|
1753
|
+
const data = useFetch(currentSource, config, field.disabled);
|
|
1754
|
+
return [data, setSource];
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// src/client/hook/use-input.ts
|
|
1758
|
+
var import_react2 = require("react");
|
|
1759
|
+
function useInput(field, onMount, onUnmount, translations) {
|
|
1760
|
+
const { name } = field;
|
|
1761
|
+
const schema = (0, import_react2.useMemo)(
|
|
1762
|
+
() => getSchema(field, translations),
|
|
1763
|
+
[field, translations]
|
|
1764
|
+
);
|
|
1765
|
+
const onMountHandler = (0, import_react2.useEffectEvent)((name2) => {
|
|
1766
|
+
if (name2) {
|
|
1767
|
+
onMount(name2, schema, field);
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
const onUnmountHandler = (0, import_react2.useEffectEvent)((name2) => {
|
|
1771
|
+
if (name2) {
|
|
1772
|
+
onUnmount(name2);
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
(0, import_react2.useEffect)(() => {
|
|
1776
|
+
onMountHandler(name);
|
|
1777
|
+
return () => {
|
|
1778
|
+
onUnmountHandler(name);
|
|
1779
|
+
};
|
|
1780
|
+
}, [name]);
|
|
1781
|
+
return schema;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
// src/client/component/input.tsx
|
|
1785
|
+
var import_jotai6 = require("jotai");
|
|
1786
|
+
|
|
1787
|
+
// src/client/hook/use-timeout.ts
|
|
1788
|
+
var import_react3 = require("react");
|
|
1789
|
+
function useTimeout() {
|
|
1790
|
+
const timeoutRef = (0, import_react3.useRef)(null);
|
|
1791
|
+
(0, import_react3.useEffect)(() => {
|
|
1792
|
+
return () => {
|
|
1793
|
+
if (timeoutRef.current) {
|
|
1794
|
+
clearTimeout(timeoutRef.current);
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
}, []);
|
|
1798
|
+
const setTimeoutRef = (0, import_react3.useCallback)((callback, delay) => {
|
|
1799
|
+
if (timeoutRef.current) {
|
|
1800
|
+
clearTimeout(timeoutRef.current);
|
|
1801
|
+
timeoutRef.current = null;
|
|
1802
|
+
}
|
|
1803
|
+
timeoutRef.current = setTimeout(callback, delay);
|
|
1804
|
+
}, []);
|
|
1805
|
+
return setTimeoutRef;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
// src/client/lib/value-store.ts
|
|
1809
|
+
var store3 = createAtomStore();
|
|
1810
|
+
var valueAtom = store3.atom;
|
|
1811
|
+
var clearAllValueAtom = store3.clearAll;
|
|
1812
|
+
var clearInputValueAtom = store3.clear;
|
|
1813
|
+
var reportValueAtom = store3.report;
|
|
1814
|
+
|
|
1815
|
+
// src/client/hook/use-value.ts
|
|
1816
|
+
var import_jotai5 = require("jotai");
|
|
1817
|
+
var import_react4 = require("react");
|
|
1818
|
+
function useValue(field, currentValue) {
|
|
1819
|
+
const { name } = field;
|
|
1820
|
+
const skipNextOnChangeRef = (0, import_react4.useRef)(false);
|
|
1821
|
+
const [value, setValue] = (0, import_jotai5.useAtom)(reportValueAtom(name));
|
|
1822
|
+
const onCurrentValueChange = (0, import_react4.useEffectEvent)(
|
|
1823
|
+
(currentValue2) => {
|
|
1824
|
+
const newValue = resolveValue(name, currentValue2);
|
|
1825
|
+
if (isValidValue(newValue)) {
|
|
1826
|
+
skipNextOnChangeRef.current = true;
|
|
1827
|
+
setValue(newValue);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
);
|
|
1831
|
+
(0, import_react4.useEffect)(() => {
|
|
1832
|
+
if (!currentValue) {
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
onCurrentValueChange(currentValue);
|
|
1836
|
+
}, [currentValue]);
|
|
1837
|
+
const shouldSkipOnChange = (0, import_react4.useCallback)(() => {
|
|
1838
|
+
if (skipNextOnChangeRef.current) {
|
|
1839
|
+
skipNextOnChangeRef.current = false;
|
|
1840
|
+
return true;
|
|
1841
|
+
}
|
|
1842
|
+
return false;
|
|
1843
|
+
}, []);
|
|
1844
|
+
return {
|
|
1845
|
+
setValue,
|
|
1846
|
+
shouldSkipOnChange,
|
|
1847
|
+
value
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
function resolveValue(name, currentValue) {
|
|
1851
|
+
if (name in currentValue) {
|
|
1852
|
+
return currentValue[name];
|
|
1853
|
+
}
|
|
1854
|
+
if (!name.includes(".")) {
|
|
1855
|
+
return void 0;
|
|
1856
|
+
}
|
|
1857
|
+
const keys = name.split(".");
|
|
1858
|
+
let result = currentValue;
|
|
1859
|
+
for (const key of keys) {
|
|
1860
|
+
if (result === null || result === void 0) {
|
|
1861
|
+
return void 0;
|
|
1862
|
+
}
|
|
1863
|
+
if (Array.isArray(result)) {
|
|
1864
|
+
const index = Number(key);
|
|
1865
|
+
result = Number.isInteger(index) ? result[index] : void 0;
|
|
1866
|
+
} else if (typeof result === "object") {
|
|
1867
|
+
result = result[key];
|
|
1868
|
+
} else {
|
|
1869
|
+
return void 0;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return result;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
// src/client/component/input.tsx
|
|
1876
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1877
|
+
function Input(props) {
|
|
1878
|
+
const entity = props.field.advanced?.entity;
|
|
1879
|
+
const store4 = (0, import_jotai6.useStore)();
|
|
1880
|
+
const setTimeoutRef = useTimeout();
|
|
1881
|
+
const [, startTransition2] = (0, import_react5.useTransition)();
|
|
1882
|
+
const { setValue, shouldSkipOnChange, value } = useValue(
|
|
1883
|
+
props.field,
|
|
1884
|
+
props.value
|
|
1885
|
+
);
|
|
1886
|
+
const valueRef = (0, import_react5.useRef)(value);
|
|
1887
|
+
valueRef.current = value;
|
|
1888
|
+
const translationsRef = (0, import_react5.useRef)(props.translations);
|
|
1889
|
+
translationsRef.current = props.translations;
|
|
1890
|
+
const hasTextable = isTextable(props.field);
|
|
1891
|
+
const hasClickable = isClickable(props.field);
|
|
1892
|
+
const setValues = (0, import_jotai6.useSetAtom)(valueAtom);
|
|
1893
|
+
const setFieldStates = (0, import_jotai6.useSetAtom)(fieldStateAtom);
|
|
1894
|
+
const setErrors = (0, import_jotai6.useSetAtom)(reportInputErrorAtom(props.field.name));
|
|
1895
|
+
const [data, setSource] = useDataSource(props.field, props.config, value);
|
|
1896
|
+
const schema = useInput(
|
|
1897
|
+
props.field,
|
|
1898
|
+
props.onMount,
|
|
1899
|
+
props.onUnmount,
|
|
1900
|
+
props.translations
|
|
1901
|
+
);
|
|
1902
|
+
const placeholder = translate(
|
|
1903
|
+
props.commonProps.placeholder,
|
|
1904
|
+
props.translations
|
|
1905
|
+
);
|
|
1906
|
+
const commonProps = {
|
|
1907
|
+
...props.commonProps,
|
|
1908
|
+
placeholder
|
|
1909
|
+
};
|
|
1910
|
+
const { commonPropsWithOptions, defaultValue } = prepareInputProps(
|
|
1911
|
+
props.field,
|
|
1912
|
+
commonProps,
|
|
1913
|
+
data,
|
|
1914
|
+
value
|
|
1915
|
+
);
|
|
1916
|
+
const onValueChangeRef = (0, import_react5.useRef)(null);
|
|
1917
|
+
onValueChangeRef.current = (value2) => {
|
|
1918
|
+
setValue(value2);
|
|
1919
|
+
if (props.onValueChange) {
|
|
1920
|
+
props.onValueChange({ name: props.field.name, value: value2 });
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
const inputProps = prepareInputValue(props.field, defaultValue);
|
|
1924
|
+
const validated = (0, import_react5.useCallback)(
|
|
1925
|
+
(value2) => {
|
|
1926
|
+
const results = schema.safeParse(value2);
|
|
1927
|
+
const errors = results.error?.issues.map((issue) => issue.message) ?? [];
|
|
1928
|
+
const custom = props.field.validation?.custom;
|
|
1929
|
+
const customErrors = custom ? validateCustom(
|
|
1930
|
+
value2,
|
|
1931
|
+
custom,
|
|
1932
|
+
(name) => store4.get(reportValueAtom(name)),
|
|
1933
|
+
translationsRef.current
|
|
1934
|
+
) : [];
|
|
1935
|
+
setErrors([...errors, ...customErrors]);
|
|
1936
|
+
},
|
|
1937
|
+
[props.field.validation?.custom, schema, setErrors, store4]
|
|
1938
|
+
);
|
|
1939
|
+
const handleTriggerEvent = (0, import_react5.useCallback)(
|
|
1940
|
+
(value2, callback) => {
|
|
1941
|
+
if (hasTextable) {
|
|
1942
|
+
setTimeoutRef(() => {
|
|
1943
|
+
callback({ value: value2 });
|
|
1944
|
+
}, 500);
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
callback(getEntity(value2, data, entity));
|
|
1948
|
+
},
|
|
1949
|
+
[data, entity, hasTextable, setTimeoutRef]
|
|
1950
|
+
);
|
|
1951
|
+
const onChange = (0, import_react5.useCallback)(
|
|
1952
|
+
(event) => {
|
|
1953
|
+
const inputValue = event.target.value;
|
|
1954
|
+
if (!hasClickable && shouldSkipOnChange()) {
|
|
1955
|
+
if (!hasTextable || inputValue === valueRef.current) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
onValueChangeRef.current?.(inputValue);
|
|
1960
|
+
if (props.config.validation.change) {
|
|
1961
|
+
validated(inputValue);
|
|
1962
|
+
}
|
|
1963
|
+
const events = props.field.event?.change;
|
|
1964
|
+
if (events) {
|
|
1965
|
+
handleTriggerEvent(inputValue, (selected) => {
|
|
1966
|
+
handleProxyEvent(events, ({ sources, states, values }) => {
|
|
1967
|
+
startTransition2(() => {
|
|
1968
|
+
handleSourceEvent(
|
|
1969
|
+
selected,
|
|
1970
|
+
sources,
|
|
1971
|
+
(target, source) => setSource(target, source)
|
|
1972
|
+
);
|
|
1973
|
+
handleStateEvent(selected, states, (targets, state) => {
|
|
1974
|
+
logger.info(
|
|
1975
|
+
`Setting field states for targets: ${targets.join(
|
|
1976
|
+
", "
|
|
1977
|
+
)} with state: ${JSON.stringify(state)}`
|
|
1978
|
+
);
|
|
1979
|
+
setFieldStates((prev) => {
|
|
1980
|
+
if (state) {
|
|
1981
|
+
return targets.reduce(
|
|
1982
|
+
(acc, target) => ({
|
|
1983
|
+
...acc,
|
|
1984
|
+
[target]: state
|
|
1985
|
+
}),
|
|
1986
|
+
prev
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
return targets.reduce((acc, target) => {
|
|
1990
|
+
const { [target]: _removed, ...rest } = acc;
|
|
1991
|
+
return rest;
|
|
1992
|
+
}, prev);
|
|
1993
|
+
});
|
|
1994
|
+
});
|
|
1995
|
+
handleValueEvent(selected, values, (target, value2) => {
|
|
1996
|
+
setValues((prev) => ({
|
|
1997
|
+
...prev,
|
|
1998
|
+
[target]: value2
|
|
1999
|
+
}));
|
|
2000
|
+
});
|
|
2001
|
+
});
|
|
2002
|
+
});
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
},
|
|
2006
|
+
[
|
|
2007
|
+
handleTriggerEvent,
|
|
2008
|
+
hasClickable,
|
|
2009
|
+
hasTextable,
|
|
2010
|
+
props.config.validation.change,
|
|
2011
|
+
props.field.event?.change,
|
|
2012
|
+
setFieldStates,
|
|
2013
|
+
setSource,
|
|
2014
|
+
setValues,
|
|
2015
|
+
shouldSkipOnChange,
|
|
2016
|
+
validated
|
|
2017
|
+
]
|
|
2018
|
+
);
|
|
2019
|
+
const onBlur = (0, import_react5.useCallback)(
|
|
2020
|
+
(event) => {
|
|
2021
|
+
if (!hasClickable) {
|
|
2022
|
+
const value2 = event.target.value;
|
|
2023
|
+
if (props.config.validation.blur) {
|
|
2024
|
+
validated(value2);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
},
|
|
2028
|
+
[hasClickable, props.config.validation.blur, validated]
|
|
2029
|
+
);
|
|
2030
|
+
return renderIfExists(props.config.inputs[props.field.type], (Component) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2031
|
+
InputGroup,
|
|
2032
|
+
{
|
|
2033
|
+
config: props.config,
|
|
2034
|
+
context: props.context,
|
|
2035
|
+
field: props.field,
|
|
2036
|
+
orientation: props.orientation,
|
|
2037
|
+
translations: props.translations,
|
|
2038
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2039
|
+
Component,
|
|
2040
|
+
{
|
|
2041
|
+
...commonPropsWithOptions,
|
|
2042
|
+
...props.ariaAttributes,
|
|
2043
|
+
...props.dataAttributes,
|
|
2044
|
+
...inputProps,
|
|
2045
|
+
onBlur,
|
|
2046
|
+
onChange
|
|
2047
|
+
}
|
|
2048
|
+
)
|
|
2049
|
+
}
|
|
2050
|
+
));
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
// src/component/field/field-error.tsx
|
|
2054
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2055
|
+
function FieldError(props) {
|
|
2056
|
+
if (!props.errors || props.errors.length === 0) {
|
|
2057
|
+
return null;
|
|
2058
|
+
}
|
|
2059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2060
|
+
"ul",
|
|
2061
|
+
{
|
|
2062
|
+
className: "text-sm text-red-600 dark:text-red-500",
|
|
2063
|
+
id: props.name ? `${props.name}-error` : void 0,
|
|
2064
|
+
children: props.errors?.map((error, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("li", { children: error }, props.name ? `${props.name}-error-${index}` : index))
|
|
2065
|
+
}
|
|
2066
|
+
);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
// src/component/field/field-base.tsx
|
|
2070
|
+
var import_tailwind_merge2 = require("tailwind-merge");
|
|
2071
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2072
|
+
function FieldBase(props) {
|
|
2073
|
+
const errors = props.errors && props.errors.length > 0;
|
|
2074
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2075
|
+
"div",
|
|
2076
|
+
{
|
|
2077
|
+
"data-slot": "field",
|
|
2078
|
+
"data-clickable": props.isClickable ? "true" : "false",
|
|
2079
|
+
...errors && { [DATA_INVALID]: "true" },
|
|
2080
|
+
...props.disabled && { [DATA_READONLY]: "true" },
|
|
2081
|
+
"data-orientation": props.orientation,
|
|
2082
|
+
className: (0, import_tailwind_merge2.twMerge)(
|
|
2083
|
+
"group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500",
|
|
2084
|
+
"data-[clickable=true]:items-start",
|
|
2085
|
+
props.isCheckbox && (props.isReversed ? "flex-row-reverse!" : "flex-row!"),
|
|
2086
|
+
"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",
|
|
2087
|
+
props.className
|
|
2088
|
+
),
|
|
2089
|
+
children: props.children
|
|
2090
|
+
}
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
// src/component/field/field-vertical.tsx
|
|
2095
|
+
var import_tailwind_merge3 = require("tailwind-merge");
|
|
2096
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2097
|
+
function FieldVertical(props) {
|
|
2098
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2099
|
+
FieldBase,
|
|
2100
|
+
{
|
|
2101
|
+
...props,
|
|
2102
|
+
orientation: VERTICAL,
|
|
2103
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
2104
|
+
"gap-3 has-[>[data-slot=field-content]]:items-start",
|
|
2105
|
+
!props.isClickable && "[&>*]:w-full"
|
|
2106
|
+
),
|
|
2107
|
+
children: props.children
|
|
2108
|
+
}
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/component/field/field-horizontal.tsx
|
|
2113
|
+
var import_tailwind_merge4 = require("tailwind-merge");
|
|
2114
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2115
|
+
function FieldHorizontal(props) {
|
|
2116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2117
|
+
FieldBase,
|
|
2118
|
+
{
|
|
2119
|
+
...props,
|
|
2120
|
+
orientation: HORIZONTAL,
|
|
2121
|
+
className: (0, import_tailwind_merge4.twMerge)(
|
|
2122
|
+
"gap-2 md:flex-row md:gap-4",
|
|
2123
|
+
"[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start",
|
|
2124
|
+
"[&_[role=checkbox]]:mt-[1.5px]",
|
|
2125
|
+
props.isClickable && "md:flex-col",
|
|
2126
|
+
!props.isClickable && [
|
|
2127
|
+
"md:justify-between",
|
|
2128
|
+
"[&>*:not([data-slot=field-content])]:w-full",
|
|
2129
|
+
"[&>*:not([data-slot=field-content])]:md:w-1/2",
|
|
2130
|
+
"[&>*:not([data-slot=field-content])]:xl:w-2/5"
|
|
2131
|
+
]
|
|
2132
|
+
),
|
|
2133
|
+
children: props.children
|
|
2134
|
+
}
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
// src/component/field/field-group.tsx
|
|
2139
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2140
|
+
function FieldGroup(props) {
|
|
2141
|
+
const clickable = isClickable(props.field);
|
|
2142
|
+
const checkbox = isCheckbox(props.field);
|
|
2143
|
+
const reversed = buildReverse(props.field);
|
|
2144
|
+
if (props.orientation === VERTICAL) {
|
|
2145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2146
|
+
FieldVertical,
|
|
2147
|
+
{
|
|
2148
|
+
disabled: props.disabled,
|
|
2149
|
+
errors: props.errors,
|
|
2150
|
+
isCheckbox: checkbox,
|
|
2151
|
+
isReversed: reversed,
|
|
2152
|
+
isClickable: clickable,
|
|
2153
|
+
children: props.children
|
|
2154
|
+
}
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2158
|
+
FieldHorizontal,
|
|
2159
|
+
{
|
|
2160
|
+
disabled: props.disabled,
|
|
2161
|
+
errors: props.errors,
|
|
2162
|
+
isCheckbox: checkbox,
|
|
2163
|
+
isReversed: reversed,
|
|
2164
|
+
isClickable: clickable,
|
|
2165
|
+
children: props.children
|
|
2166
|
+
}
|
|
2167
|
+
);
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
// src/component/input/input-base.tsx
|
|
2171
|
+
function InputBase(props) {
|
|
2172
|
+
if (!props.field.type) {
|
|
2173
|
+
return null;
|
|
2174
|
+
}
|
|
2175
|
+
const commonProps = buildCommon(props.field, props.disabled);
|
|
2176
|
+
const dataAttributes = buildDataAttributes(props.field);
|
|
2177
|
+
const ariaAttributes = buildAriaAttributes(props.field, props.errors);
|
|
2178
|
+
const field = {
|
|
2179
|
+
...props.field,
|
|
2180
|
+
disabled: commonProps.disabled
|
|
2181
|
+
};
|
|
2182
|
+
return props.children({
|
|
2183
|
+
ariaAttributes,
|
|
2184
|
+
commonProps,
|
|
2185
|
+
dataAttributes,
|
|
2186
|
+
field,
|
|
2187
|
+
orientation: props.orientation
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/component/field/field.tsx
|
|
2192
|
+
var import_tailwind_merge5 = require("tailwind-merge");
|
|
2193
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2194
|
+
function Field(props) {
|
|
2195
|
+
const cols2 = props.field.advanced?.cols;
|
|
2196
|
+
const errors = props.field.name ? props.errors?.[props.field.name] : void 0;
|
|
2197
|
+
const { orientation } = mergeStyle(props.style, {
|
|
2198
|
+
orientation: buildOrientation(props.field)
|
|
2199
|
+
});
|
|
2200
|
+
const disabled = buildDisabled(props.field, props.disabled);
|
|
2201
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: (0, import_tailwind_merge5.twMerge)("flex flex-col gap-3", getSpan(cols2)), children: [
|
|
2202
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2203
|
+
FieldGroup,
|
|
2204
|
+
{
|
|
2205
|
+
disabled,
|
|
2206
|
+
errors,
|
|
2207
|
+
field: props.field,
|
|
2208
|
+
orientation,
|
|
2209
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2210
|
+
InputBase,
|
|
2211
|
+
{
|
|
2212
|
+
disabled,
|
|
2213
|
+
errors,
|
|
2214
|
+
field: props.field,
|
|
2215
|
+
orientation,
|
|
2216
|
+
children: props.children
|
|
2217
|
+
}
|
|
2218
|
+
)
|
|
2219
|
+
}
|
|
2220
|
+
),
|
|
2221
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FieldError, { errors, name: props.field.name })
|
|
2222
|
+
] });
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
// src/client/component/field/field-with-error.tsx
|
|
2226
|
+
var import_jotai7 = require("jotai");
|
|
2227
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2228
|
+
function withError(Component) {
|
|
2229
|
+
const WithError = (props) => {
|
|
2230
|
+
const errors = (0, import_jotai7.useAtomValue)(reportInputErrorAtom(props.field.name));
|
|
2231
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2232
|
+
Component,
|
|
2233
|
+
{
|
|
2234
|
+
...props,
|
|
2235
|
+
errors: errors ? { [props.field.name]: errors } : void 0
|
|
2236
|
+
}
|
|
2237
|
+
);
|
|
2238
|
+
};
|
|
2239
|
+
return WithError;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
// src/client/component/field/field-with-state.tsx
|
|
2243
|
+
var import_jotai8 = require("jotai");
|
|
2244
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2245
|
+
function withState(Component) {
|
|
2246
|
+
const WithFieldState = (props) => {
|
|
2247
|
+
const fieldState = (0, import_jotai8.useAtomValue)(reportFieldStateAtom(props.field.name));
|
|
2248
|
+
const hidden = fieldState?.hidden ?? props.field.hidden ?? false;
|
|
2249
|
+
if (hidden) {
|
|
2250
|
+
return null;
|
|
2251
|
+
}
|
|
2252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Component, { ...props, disabled: fieldState?.disabled ?? props.disabled });
|
|
2253
|
+
};
|
|
2254
|
+
return WithFieldState;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
// src/client/component/field/field.tsx
|
|
2258
|
+
var Field2 = withState(withError(Field));
|
|
2259
|
+
|
|
2260
|
+
// src/component/field/field-list-item.tsx
|
|
2261
|
+
var import_tailwind_merge6 = require("tailwind-merge");
|
|
2262
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2263
|
+
function FieldListItem(props) {
|
|
2264
|
+
function handleRemove() {
|
|
2265
|
+
if (props.canRemove && props.onRemove) {
|
|
2266
|
+
props.onRemove(props.index);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
const removeButton = props.canRemove && props.onRemove != null && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2270
|
+
"button",
|
|
2271
|
+
{
|
|
2272
|
+
"aria-label": `Remove ${props.label} item ${props.index + 1}`,
|
|
2273
|
+
className: (0, import_tailwind_merge6.twMerge)(
|
|
2274
|
+
"rounded p-1 text-xl text-slate-400",
|
|
2275
|
+
"transition-colors duration-150",
|
|
2276
|
+
"hover:text-red-500",
|
|
2277
|
+
"focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:outline-none",
|
|
2278
|
+
"dark:text-slate-500 dark:hover:text-red-400"
|
|
2279
|
+
),
|
|
2280
|
+
onClick: handleRemove,
|
|
2281
|
+
type: "button",
|
|
2282
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { "aria-hidden": "true", children: "\xD7" })
|
|
2283
|
+
}
|
|
2284
|
+
);
|
|
2285
|
+
if (props.isMultiField) {
|
|
2286
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rounded-lg border border-slate-100 p-4 dark:border-slate-900", children: [
|
|
2287
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "mb-3 flex items-center justify-between", children: [
|
|
2288
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { className: "text-sm font-medium text-slate-400 dark:text-slate-500", children: [
|
|
2289
|
+
props.label,
|
|
2290
|
+
" ",
|
|
2291
|
+
props.index + 1
|
|
2292
|
+
] }),
|
|
2293
|
+
removeButton
|
|
2294
|
+
] }),
|
|
2295
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Group, { children: props.children })
|
|
2296
|
+
] });
|
|
2297
|
+
}
|
|
2298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex items-start gap-2", children: [
|
|
2299
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Group, { children: props.children }),
|
|
2300
|
+
removeButton && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "shrink-0", children: removeButton })
|
|
2301
|
+
] });
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/client/component/field/field-list.tsx
|
|
2305
|
+
var import_tailwind_merge7 = require("tailwind-merge");
|
|
2306
|
+
|
|
2307
|
+
// src/client/hook/use-field-list.ts
|
|
2308
|
+
var import_jotai9 = require("jotai");
|
|
2309
|
+
var import_react6 = require("react");
|
|
2310
|
+
function useFieldList(field, value) {
|
|
2311
|
+
const min2 = field.advanced?.length?.min ?? 1;
|
|
2312
|
+
const max2 = field.advanced?.length?.max ?? Infinity;
|
|
2313
|
+
const [items, setItems] = (0, import_react6.useState)(
|
|
2314
|
+
() => getInitialList(field, value)
|
|
2315
|
+
);
|
|
2316
|
+
const nextId = (0, import_react6.useRef)(items.length);
|
|
2317
|
+
const itemsRef = (0, import_react6.useRef)(items);
|
|
2318
|
+
itemsRef.current = items;
|
|
2319
|
+
const setValues = (0, import_jotai9.useSetAtom)(valueAtom);
|
|
2320
|
+
const addItem = (0, import_react6.useCallback)(() => {
|
|
2321
|
+
setItems((previous) => {
|
|
2322
|
+
if (previous.length >= max2) {
|
|
2323
|
+
return previous;
|
|
2324
|
+
}
|
|
2325
|
+
const id = nextId.current++;
|
|
2326
|
+
return [...previous, id];
|
|
2327
|
+
});
|
|
2328
|
+
}, [max2]);
|
|
2329
|
+
const handleRemove = (0, import_react6.useCallback)(
|
|
2330
|
+
(index) => {
|
|
2331
|
+
if (items.length <= min2) {
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
const stableId = items[index];
|
|
2335
|
+
setItems((previous) => {
|
|
2336
|
+
if (previous.length <= min2) {
|
|
2337
|
+
return previous;
|
|
2338
|
+
}
|
|
2339
|
+
return previous.filter((_, i) => i !== index);
|
|
2340
|
+
});
|
|
2341
|
+
setValues((current) => {
|
|
2342
|
+
const next = { ...current };
|
|
2343
|
+
const prefix = `${field.name}.`;
|
|
2344
|
+
const leafNames = [];
|
|
2345
|
+
for (const row of field.fields) {
|
|
2346
|
+
if (isColumn(row)) {
|
|
2347
|
+
for (const columnField of row.fields) {
|
|
2348
|
+
leafNames.push(columnField.name);
|
|
2349
|
+
}
|
|
2350
|
+
} else {
|
|
2351
|
+
leafNames.push(row.name);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
for (const name of leafNames) {
|
|
2355
|
+
delete next[`${prefix}${stableId}.${name}`];
|
|
2356
|
+
}
|
|
2357
|
+
return next;
|
|
2358
|
+
});
|
|
2359
|
+
},
|
|
2360
|
+
[field.name, field.fields, items, min2, setValues]
|
|
2361
|
+
);
|
|
2362
|
+
const canAdd = items.length < max2;
|
|
2363
|
+
const canRemove = items.length > min2;
|
|
2364
|
+
return [items, addItem, handleRemove, canAdd, canRemove, max2];
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
// src/client/component/field/field-list.tsx
|
|
2368
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2369
|
+
function FieldList(props) {
|
|
2370
|
+
const [items, addItem, handleRemove, canAdd, canRemove, max2] = useFieldList(
|
|
2371
|
+
props.field,
|
|
2372
|
+
props.value
|
|
2373
|
+
);
|
|
2374
|
+
const label = getLabel(props.field);
|
|
2375
|
+
const action = props.field.advanced?.action ?? "Add item";
|
|
2376
|
+
const hasLimit = max2 !== Infinity;
|
|
2377
|
+
const isMultiField = isMultiFieldList(props.field);
|
|
2378
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
2379
|
+
items.map((key, index) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2380
|
+
FieldListItem,
|
|
2381
|
+
{
|
|
2382
|
+
canRemove,
|
|
2383
|
+
index,
|
|
2384
|
+
isMultiField,
|
|
2385
|
+
label,
|
|
2386
|
+
onRemove: handleRemove,
|
|
2387
|
+
children: props.children(key)
|
|
2388
|
+
},
|
|
2389
|
+
key
|
|
2390
|
+
)),
|
|
2391
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
2392
|
+
"button",
|
|
2393
|
+
{
|
|
2394
|
+
"aria-disabled": !canAdd,
|
|
2395
|
+
"aria-label": hasLimit ? `${action}, ${items.length} of ${max2}` : action,
|
|
2396
|
+
className: (0, import_tailwind_merge7.twMerge)(
|
|
2397
|
+
"flex w-full items-center gap-1.5 rounded py-1",
|
|
2398
|
+
"text-sm font-medium text-slate-500",
|
|
2399
|
+
"transition-colors duration-150",
|
|
2400
|
+
"hover:text-slate-800",
|
|
2401
|
+
"focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:ring-offset-2 focus-visible:outline-none",
|
|
2402
|
+
"dark:text-slate-400 dark:hover:text-slate-200",
|
|
2403
|
+
!canAdd && "cursor-not-allowed opacity-50 hover:text-slate-500 dark:hover:text-slate-400"
|
|
2404
|
+
),
|
|
2405
|
+
disabled: !canAdd,
|
|
2406
|
+
onClick: addItem,
|
|
2407
|
+
type: "button",
|
|
2408
|
+
children: [
|
|
2409
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { "aria-hidden": "true", children: "+" }),
|
|
2410
|
+
action,
|
|
2411
|
+
hasLimit && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
2412
|
+
"span",
|
|
2413
|
+
{
|
|
2414
|
+
"aria-hidden": "true",
|
|
2415
|
+
className: "ml-auto text-slate-400 tabular-nums dark:text-slate-500",
|
|
2416
|
+
children: [
|
|
2417
|
+
items.length,
|
|
2418
|
+
" / ",
|
|
2419
|
+
max2
|
|
2420
|
+
]
|
|
2421
|
+
}
|
|
2422
|
+
)
|
|
2423
|
+
]
|
|
2424
|
+
}
|
|
2425
|
+
)
|
|
2426
|
+
] });
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/component/list.tsx
|
|
2430
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2431
|
+
function List(props) {
|
|
2432
|
+
const empty = Array.isArray(props.field.fields) && props.field.fields.length === 0;
|
|
2433
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2434
|
+
FieldSetBase,
|
|
2435
|
+
{
|
|
2436
|
+
description: props.field.description,
|
|
2437
|
+
empty,
|
|
2438
|
+
id: props.field.name,
|
|
2439
|
+
title: props.field.label,
|
|
2440
|
+
children: props.children
|
|
2441
|
+
}
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
// src/client/component/guard/list-guard.tsx
|
|
2446
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2447
|
+
function ListGuard({ children, field, value }) {
|
|
2448
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(VisibilityGuard, { container: field, fields: field.fields, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(List, { field, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(FieldList, { field, value, children }) }) });
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// src/component/column.tsx
|
|
2452
|
+
var import_tailwind_merge8 = require("tailwind-merge");
|
|
2453
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
2454
|
+
function Column(props) {
|
|
2455
|
+
const cols2 = getColumn(props.column?.advanced?.cols);
|
|
2456
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "flex w-full flex-col gap-4", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: (0, import_tailwind_merge8.twMerge)("grid grid-cols-1 gap-3 sm:gap-4", cols2), children: props.children }) });
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
// src/component/slot/slot-base.tsx
|
|
2460
|
+
var import_react7 = require("react");
|
|
2461
|
+
|
|
2462
|
+
// src/component/slot/slot-list.tsx
|
|
2463
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
2464
|
+
function SlotList(props) {
|
|
2465
|
+
const fields = Array.isArray(props.field.fields) ? props.field.fields.map((field) => {
|
|
2466
|
+
if (isField(field)) {
|
|
2467
|
+
return {
|
|
2468
|
+
...field,
|
|
2469
|
+
name: `${props.field.name}.${props.index}.${field.name}`
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
if (isColumn(field)) {
|
|
2473
|
+
return {
|
|
2474
|
+
...field,
|
|
2475
|
+
fields: field.fields.map((columnField) => ({
|
|
2476
|
+
...columnField,
|
|
2477
|
+
name: `${props.field.name}.${props.index}.${columnField.name}`
|
|
2478
|
+
}))
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
return field;
|
|
2482
|
+
}) : [];
|
|
2483
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
|
|
2484
|
+
SlotBase,
|
|
2485
|
+
{
|
|
2486
|
+
children: props.children,
|
|
2487
|
+
components: props.components,
|
|
2488
|
+
disabled: props.disabled,
|
|
2489
|
+
fields,
|
|
2490
|
+
style: props.style,
|
|
2491
|
+
value: props.value
|
|
2492
|
+
}
|
|
2493
|
+
);
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
// src/component/slot/slot-base.tsx
|
|
2497
|
+
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
2498
|
+
function SlotBase(props) {
|
|
2499
|
+
const { field: Field3, list: List2 } = props.components;
|
|
2500
|
+
return prepare(props.fields).map((field, index) => /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_react7.Fragment, { children: [
|
|
2501
|
+
isColumn(field) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Column, { column: field, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(SlotBase, { ...props, fields: field.fields }) }),
|
|
2502
|
+
isField(field) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Field3, { disabled: props.disabled, field, style: props.style, children: props.children }),
|
|
2503
|
+
isList(field) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(List2, { field, value: props.value, children: (index2) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
2504
|
+
SlotList,
|
|
2505
|
+
{
|
|
2506
|
+
children: props.children,
|
|
2507
|
+
components: props.components,
|
|
2508
|
+
disabled: props.disabled,
|
|
2509
|
+
field,
|
|
2510
|
+
index: index2,
|
|
2511
|
+
style: props.style,
|
|
2512
|
+
value: props.value
|
|
2513
|
+
}
|
|
2514
|
+
) })
|
|
2515
|
+
] }, index));
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
// src/component/slot/slot-create.tsx
|
|
2519
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
2520
|
+
function createSlot(components) {
|
|
2521
|
+
const CreateSlot = (props) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(SlotBase, { ...props, components });
|
|
2522
|
+
return CreateSlot;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
// src/client/component/slot/slot.tsx
|
|
2526
|
+
var Slot = createSlot({ field: Field2, list: ListGuard });
|
|
2527
|
+
|
|
2528
|
+
// src/client/hook/use-form-action.ts
|
|
2529
|
+
var import_jotai10 = require("jotai");
|
|
2530
|
+
var import_react8 = require("react");
|
|
2531
|
+
function useFormState(getSchema2, action, options) {
|
|
2532
|
+
const {
|
|
2533
|
+
onSuccess,
|
|
2534
|
+
preserveValues = false,
|
|
2535
|
+
validation = true,
|
|
2536
|
+
translations
|
|
2537
|
+
} = options ?? {};
|
|
2538
|
+
const setError = (0, import_jotai10.useSetAtom)(reportErrorAtom);
|
|
2539
|
+
const clearValues = (0, import_jotai10.useSetAtom)(clearAllValueAtom);
|
|
2540
|
+
const initialState = {
|
|
2541
|
+
data: null,
|
|
2542
|
+
error: null,
|
|
2543
|
+
success: false
|
|
2544
|
+
};
|
|
2545
|
+
const [state, formAction, isPending] = (0, import_react8.useActionState)(
|
|
2546
|
+
async (prevState, formData) => {
|
|
2547
|
+
const [schemas, fields] = getSchema2();
|
|
2548
|
+
const schema = buildSchema(schemas, fields, translations);
|
|
2549
|
+
if (validation === false) {
|
|
2550
|
+
if (action) {
|
|
2551
|
+
return await action(formData, schema);
|
|
2552
|
+
}
|
|
2553
|
+
return prevState;
|
|
2554
|
+
}
|
|
2555
|
+
const form = getFormData(formData);
|
|
2556
|
+
const validated = schema.safeParse(form);
|
|
2557
|
+
if (!validated.success) {
|
|
2558
|
+
const errors = flatten(validated.error);
|
|
2559
|
+
(0, import_react8.startTransition)(() => {
|
|
2560
|
+
setError(errors);
|
|
2561
|
+
});
|
|
2562
|
+
return failure(form, {
|
|
2563
|
+
description: translate(
|
|
2564
|
+
"Please correct the errors and try again.",
|
|
2565
|
+
translations
|
|
2566
|
+
),
|
|
2567
|
+
details: [],
|
|
2568
|
+
title: translate(
|
|
2569
|
+
"There were validation errors submitting the form.",
|
|
2570
|
+
translations
|
|
2571
|
+
)
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
const unflattened = unflatten(form);
|
|
2575
|
+
if (action) {
|
|
2576
|
+
try {
|
|
2577
|
+
const result = await action(unflattened, schema);
|
|
2578
|
+
if (!result.success) {
|
|
2579
|
+
return failure(unflattened, result.error);
|
|
2580
|
+
}
|
|
2581
|
+
onSuccess?.(result.data);
|
|
2582
|
+
if (!preserveValues) {
|
|
2583
|
+
(0, import_react8.startTransition)(() => {
|
|
2584
|
+
clearValues();
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
return success(unflattened, preserveValues);
|
|
2588
|
+
} catch (error) {
|
|
2589
|
+
logger.error("Error executing form action:", error);
|
|
2590
|
+
return failure(unflattened, {
|
|
2591
|
+
title: translate(
|
|
2592
|
+
"An unexpected error occurred submitting the form.",
|
|
2593
|
+
translations
|
|
2594
|
+
),
|
|
2595
|
+
details: buildError(error, translations)
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
return success(validated.data, preserveValues);
|
|
2600
|
+
},
|
|
2601
|
+
initialState
|
|
2602
|
+
);
|
|
2603
|
+
return [formAction, state, isPending];
|
|
2604
|
+
}
|
|
2605
|
+
function buildError(error, translations) {
|
|
2606
|
+
if (error instanceof Error) {
|
|
2607
|
+
return [error.message];
|
|
2608
|
+
}
|
|
2609
|
+
return [translate("Unknown error", translations)];
|
|
2610
|
+
}
|
|
2611
|
+
function success(value, preserveValues = false) {
|
|
2612
|
+
const data = preserveValues ? value : null;
|
|
2613
|
+
return {
|
|
2614
|
+
data,
|
|
2615
|
+
error: null,
|
|
2616
|
+
success: true
|
|
2617
|
+
};
|
|
2618
|
+
}
|
|
2619
|
+
function failure(value, error) {
|
|
2620
|
+
return {
|
|
2621
|
+
data: value,
|
|
2622
|
+
error,
|
|
2623
|
+
success: false
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
// src/client/hook/use-schema.ts
|
|
2628
|
+
var import_react10 = require("react");
|
|
2629
|
+
|
|
2630
|
+
// src/client/hook/use-store.ts
|
|
2631
|
+
var import_react9 = require("react");
|
|
2632
|
+
var import_jotai11 = require("jotai");
|
|
2633
|
+
function useStore2() {
|
|
2634
|
+
const clearErrors = (0, import_jotai11.useSetAtom)(clearInputErrorAtom);
|
|
2635
|
+
const clearValues = (0, import_jotai11.useSetAtom)(clearInputValueAtom);
|
|
2636
|
+
const clearSources = (0, import_jotai11.useSetAtom)(clearInputSourceAtom);
|
|
2637
|
+
return (0, import_react9.useCallback)(
|
|
2638
|
+
(names) => {
|
|
2639
|
+
const target = Array.isArray(names) ? names : [names];
|
|
2640
|
+
clearErrors(target);
|
|
2641
|
+
clearSources(target);
|
|
2642
|
+
clearValues(target);
|
|
2643
|
+
},
|
|
2644
|
+
[clearErrors, clearSources, clearValues]
|
|
2645
|
+
);
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
// src/client/hook/use-schema.ts
|
|
2649
|
+
function useSchema() {
|
|
2650
|
+
const clear = useStore2();
|
|
2651
|
+
const schemaRef = (0, import_react10.useRef)({});
|
|
2652
|
+
const fieldsRef = (0, import_react10.useRef)([]);
|
|
2653
|
+
const onMount = (0, import_react10.useCallback)((name, schema, field) => {
|
|
2654
|
+
if (!(name in schemaRef.current)) {
|
|
2655
|
+
schemaRef.current[name] = schema;
|
|
2656
|
+
fieldsRef.current.push(field);
|
|
2657
|
+
}
|
|
2658
|
+
}, []);
|
|
2659
|
+
const onUnmount = (0, import_react10.useCallback)(
|
|
2660
|
+
(name) => {
|
|
2661
|
+
if (schemaRef.current[name]) {
|
|
2662
|
+
delete schemaRef.current[name];
|
|
2663
|
+
fieldsRef.current = fieldsRef.current.filter((field) => {
|
|
2664
|
+
return field.name !== name;
|
|
2665
|
+
});
|
|
2666
|
+
clear([name]);
|
|
2667
|
+
}
|
|
2668
|
+
},
|
|
2669
|
+
[clear]
|
|
2670
|
+
);
|
|
2671
|
+
const getSchema2 = (0, import_react10.useCallback)(() => {
|
|
2672
|
+
return [schemaRef.current, fieldsRef.current];
|
|
2673
|
+
}, []);
|
|
2674
|
+
return [getSchema2, onMount, onUnmount];
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
// src/client/component/form-content.tsx
|
|
2678
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
2679
|
+
function FormContent(props) {
|
|
2680
|
+
const translations = props.translations?.[props.lang ?? ""];
|
|
2681
|
+
const [schema, onMount, onUnmount] = useSchema();
|
|
2682
|
+
const [action, state, isPending] = useFormState(schema, props.action, {
|
|
2683
|
+
onSuccess: props.onSuccess,
|
|
2684
|
+
validation: props.config.validation.submit,
|
|
2685
|
+
translations
|
|
2686
|
+
});
|
|
2687
|
+
const isShowingError = props.config.validation.showError && !state.success && state.error;
|
|
2688
|
+
const value = state.data ?? props.value;
|
|
2689
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_jsx_runtime33.Fragment, { children: [
|
|
2690
|
+
isShowingError && renderIfExists(props.config.alert, (Alert) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "mb-4 w-full", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
2691
|
+
Alert,
|
|
2692
|
+
{
|
|
2693
|
+
description: state.error?.description,
|
|
2694
|
+
details: state.error?.details,
|
|
2695
|
+
title: state.error.title
|
|
2696
|
+
}
|
|
2697
|
+
) })),
|
|
2698
|
+
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
2699
|
+
Form,
|
|
2700
|
+
{
|
|
2701
|
+
action,
|
|
2702
|
+
config: props.config,
|
|
2703
|
+
control: props.children,
|
|
2704
|
+
definition: props.definition,
|
|
2705
|
+
isPending,
|
|
2706
|
+
noValidate: true,
|
|
2707
|
+
readOnly: props.readOnly,
|
|
2708
|
+
sections: props.sections,
|
|
2709
|
+
children: ({ disabled, fields }) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
2710
|
+
Slot,
|
|
2711
|
+
{
|
|
2712
|
+
disabled,
|
|
2713
|
+
fields,
|
|
2714
|
+
style: props.config.style,
|
|
2715
|
+
value,
|
|
2716
|
+
children: (internal) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
2717
|
+
Input,
|
|
2718
|
+
{
|
|
2719
|
+
...internal,
|
|
2720
|
+
config: props.config,
|
|
2721
|
+
context: props.context,
|
|
2722
|
+
onMount,
|
|
2723
|
+
onUnmount,
|
|
2724
|
+
onValueChange: props.onValueChange,
|
|
2725
|
+
translations,
|
|
2726
|
+
value
|
|
2727
|
+
}
|
|
2728
|
+
)
|
|
2729
|
+
}
|
|
2730
|
+
)
|
|
2731
|
+
}
|
|
2732
|
+
)
|
|
2733
|
+
] });
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
// src/client/component/form.tsx
|
|
2737
|
+
var import_jotai12 = require("jotai");
|
|
2738
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
2739
|
+
function Form2(props) {
|
|
2740
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_jotai12.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FormContent, { ...props }) });
|
|
2741
|
+
}
|