react-luna-form 0.0.23 → 0.0.24

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.
@@ -1 +1,1062 @@
1
- import{jsx as kt}from"react/jsx-runtime";function W(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return kt("div",{"data-slot":"field-control",className:"w-full",children:t})}import{jsx as Pt}from"react/jsx-runtime";function T(e){return Pt("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 E="input",q="input/email",z="input/number";var Z="textarea",J="radio",Q="checkbox",j="select",ee="select/month",te="select/year";var _="column";var ne="label",v="value",I="options",M="email",re="number",oe="password",ie="tel",A="text",le="aria-errormessage",ae="aria-invalid",se="data-invalid",ce="data-readonly",de="aria",ue="data",fe="min",me="max",pe="minLength",ge="maxLength",b="$ref";var u="vertical",R="horizontal";function l(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function f(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function p(e){return typeof e=="string"}var wt=/[^/]+$/;function xe(e,t=v){if(e!=null){if(f(e))return e;if(l(e)){let n=Lt(e,t);if(f(n))return n}}}function Lt(e,t){let n=g(e,t);if(f(n))return n}function g(e,t){if(!t||!l(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(l(r)&&o in r)r=r[o];else return null;return r}function ye(e,t={label:ne,value:v}){return e.map(n=>{if(l(n)){let r=g(n,t.label),o=g(n,t.value);if(f(r)&&f(o))return{label:`${r}`,value:`${o}`}}return n})}function be(e=A){if(e){let t=e.match(wt);if(t){let[n]=t;if(n!==E)return n.trim().toLowerCase()}}return A}var Dt=/\[([^\]]+)\]\(([^)]+)\)/g;function C(e,t={}){if(p(e))return _t(e,t);if(Array.isArray(e))return e.map(n=>C(n,t));if(l(e)){let n={};for(let r in e)n[r]=C(e[r],t);return n}return e}function h(e){return p(e)?/{([^}]+)}/.test(e):Array.isArray(e)?e.some(t=>h(t)):l(e)?Object.values(e).some(t=>h(t)):!1}function _t(e,t={}){return e.replace(/{([^}]+)}/g,(n,r)=>{let o=r.includes(".")?g(t,r):t[r];return f(o)?String(o):n})}function Re(e,t){if(!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=Dt.exec(e))!==null;){let[a,m,It]=n,S=n.index;o=!0,S>r&&i.push(e.substring(r,S));let Ot=t?t(S,It,m):a;i.push(Ot),r=S+a.length}return o?(r<e.length&&i.push(e.substring(r)),i):e}var Te=e=>c(ee)(e),Ae=e=>c(te)(e),s=c(Q),Ce=c(E),x=c(J),d=c(j),he=c(Z),Ne=c(A,M,oe,ie),Xn=c(q,M),Fe=c(z,re);function Se(e){return x(e)||s(e)}function Ee(e){return e.type===_}function Ie(e){return e.type!==_}function Oe(e){return d(e)||x(e)}function V(e){return e!=null&&e!==""}function c(...e){return t=>{let n=p(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function ke(e,t={}){if(d(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&l(n))return[n]}}function Pe(e){return x(e)||s(e)?R:e.advanced?.orientation??u}function we(e){return s(e)?e.advanced?.reverse!==!1:!1}function Le(e,t){let n=e.readonly??!1;return t||n}function De(e){if(x(e)||d(e)&&!e.disabled){let t=e.source;if(Array.isArray(t)||l(t)&&!(b in t))return t}}var vt=/^\d+$/;function _e(){return Array.from({length:12},(e,t)=>({value:(t+1).toString(),label:new Date(0,t).toLocaleString("default",{month:"long"})}))}function ve(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 G(){return new Date().getFullYear()}function X(e,t){if(typeof e=="number")return e;let n=t??G(),r=e.trim().toLowerCase();if(r.startsWith("current")){let o=r.match(/^current([+-])(\d+)$/);if(o){let[,i,a]=o,m=parseInt(a,10);if(!isNaN(m))return i==="+"?n+m:n-m}return n}return vt.test(r)?parseInt(r,10):n}var O=G();function Mt(e){if(d(e))return Vt(e)}function Vt(e){if(Te(e))return _e();if(Ae(e)){let t=e.advanced?.length?.min??O,n=e.advanced?.length?.max??O+5;return ve(X(t,O),X(n,O))}}function Me(e,t=!1){let n={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return Ce(e)?{...n,...Gt(e)}:d(e)?{...n,...Xt(e)}:he(e)?{...n,...Yt(e)}:n}function Gt(e){let t=be(e.type),n={...e,type:t};return{...Ve(e),...Ut(n),...Ne(n)?Ge(n):{},type:t}}function Xt(e){let t=Mt(e);return t?{options:t}:{}}function Yt(e){return{...Ve(e),...Ge(e)}}function Ve(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Ut(e){return Fe(e)?Bt(e):{}}function Ge(e){return Xe(e,{min:pe,max:ge})}function Bt(e){return Xe(e,{min:fe,max:me})}function Xe(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 Ye(e,t){let n=De(e);return n||ke(e,t)}function $t(e,t){let n=l(t)&&e.name in t?t[e.name]:t;return xe(n,e.advanced?.entity)}function Ht(e,t,n){return Oe(e)&&Array.isArray(n)?{...t,[I]:n}:t}function Kt(e,t,n){if(e.required&&!V(n)&&d(e)&&e.advanced?.preselected!==!1&&I in t){let r=t[I];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function Wt(e,t){return d(e)&&Array.isArray(t)?ye(t,e.advanced?.options):t}function Ue(e,t,n,r){let o=$t(e,r),i=Array.isArray(n)?Wt(e,n):n,a=Ht(e,t,i),m=Kt(e,a,o);return{commonPropsWithOptions:a,defaultValue:m}}function Be(e,t){return s(e)?{defaultChecked:V(t)}:{defaultValue:t}}var qt=/^#\/definition\//;function P(e=[],t){let n=k(e,t);return Array.isArray(n)?n.sort((r,o)=>$e(r)-$e(o)):[]}function k(e,t,n=new Map,r=new WeakSet){if(!zt(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=>k(i,t,n,r));if(b in e&&p(e[b])){let i=e[b].replace(qt,""),a=g(t,i);return a!==null?k(a,t,n,r):e}let o={};for(let[i,a]of Object.entries(e))o[i]=k(a,t,n,r);return r.delete(e),n.set(e,o),o}function He(e){return Object.entries(e??{})}function $e(e){return e.order??Number.MAX_VALUE}function zt(e){return e!==void 0&&l(e)&&Object.keys(e).length>0}function Ke(e,t){let n={};for(let[r,o]of He(t))n[`${e}-${r}`]=o;return n}function Zt(e){return Ke(de,e)}function Jt(e){return Ke(ue,e)}function We(e,t){let n=Zt(e.advanced?.aria);return t&&t.length>0&&(n[ae]="true",n[le]=`${e.name}-error`),n}function qe(e){return Jt(e.advanced?.data)}var ze={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},Ze={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function Je(e,t=2){return ze[e&&e in ze?e:t]}function Qe(e){if(e&&e in Ze)return Ze[e]}function y(e,t){return e?t?t[e]??e:e:""}function w(e,t){return{...e,...t}}import{jsx as Qt}from"react/jsx-runtime";function N(e){return Re(e,(t,n,r)=>Qt("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}import{Fragment as jt,jsx as je,jsxs as en}from"react/jsx-runtime";function et(e){return en(jt,{children:[e.title&&je("legend",{className:"mb-3 font-medium text-slate-800 dark:text-slate-200",children:N(e.title)}),e.description&&je("p",{className:"-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:N(e.description)})]})}import{jsx as Y,jsxs as tn}from"react/jsx-runtime";function tt(e){let t=e.section.fields||[],{compact:n}=w(e.style,{compact:e.section.compact});return!e.section.title&&!e.section.description?Y(T,{compact:n,children:e.children}):tn("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:[Y(et,{description:e.section.description,title:e.section.title}),Y(T,{compact:n,children:e.children})]})}import{Fragment as nn}from"react";import{jsx as nt}from"react/jsx-runtime";function rt(){return nt("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:nt("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800"})})}import{jsx as F,jsxs as ot}from"react/jsx-runtime";function it(e){let t=P(e.sections,e.definition);return F("div",{className:"h-full w-full",children:F("form",{noValidate:e.noValidate,action:e.action,children:ot(T,{children:[t.map((n,r)=>ot(nn,{children:[F(tt,{section:n,style:e.config.style,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.separator&&F(rt,{})]},r)),e.control&&F(W,{isPending:e.isPending,children:e.control})]})})})}import{jsx as rn}from"react/jsx-runtime";function lt(e){return rn("p",{className:"-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400",children:e.children})}import{jsx as on}from"react/jsx-runtime";function L(e){let t=N(e.text);return t?on(lt,{children:t}):null}import{twMerge as ln}from"tailwind-merge";import{jsx as an,jsxs as sn}from"react/jsx-runtime";function at(e){let t=e.style?.showOptionalLabel??!0,n=x(e.field)||s(e.field);return sn("label",{"data-slot":"field-label","data-normal":n,className:ln("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&&an("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:y("(Optional)",e.translations)})]})}import{jsx as st,jsxs as cn}from"react/jsx-runtime";function ct(e){let t=h(e.field.label)?C(e.field.label,{context:e.context,env:e.config?.env}):e.field.label,n=h(e.field.description)?C(e.field.description,{context:e.context,env:e.config?.env}):e.field.description;return cn("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[st(at,{field:e.field,style:e.config?.style,translations:e.translations,children:y(t,e.translations)}),e.orientation===R&&st(L,{text:y(n,e.translations)})]})}import{Fragment as dn,jsx as dt,jsxs as un}from"react/jsx-runtime";function ut(e){return un(dn,{children:[e.field.name&&e.field.label&&dt(ct,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations}),e.children,e.orientation===u&&e.field.description&&dt(L,{text:y(e.field.description,e.translations)})]})}function ft(e,t){return e?t(e):null}import{jsx as mt}from"react/jsx-runtime";function pt(e){let t=Ye(e.field,e.value),{commonPropsWithOptions:n,defaultValue:r}=Ue(e.field,e.commonProps,t,e.value),o=Be(e.field,r);return ft(e.config.inputs[e.field.type],i=>mt(ut,{config:e.config,context:e.context,field:e.field,orientation:e.orientation,translations:e.translations,children:mt(i,{...e.ariaAttributes,...n,...e.dataAttributes,...o})}))}import{jsx as gt}from"react/jsx-runtime";function xt(e){return!e.errors||e.errors.length===0?null:gt("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)=>gt("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}import{twMerge as fn}from"tailwind-merge";import{jsx as mn}from"react/jsx-runtime";function D(e){let t=e.errors&&e.errors.length>0;return mn("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[se]:"true"},...e.disabled&&{[ce]:"true"},"data-orientation":e.orientation,className:fn("group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500","data-[clickable=true]:items-start",e.isCheckbox&&(e.isReversed?"flex-row-reverse!":"flex-row!"),"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",e.className),children:e.children})}import{twMerge as pn}from"tailwind-merge";import{jsx as gn}from"react/jsx-runtime";function yt(e){return gn(D,{...e,orientation:u,className:pn("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}import{twMerge as xn}from"tailwind-merge";import{jsx as yn}from"react/jsx-runtime";function bt(e){return yn(D,{...e,orientation:R,className:xn("gap-2 md:flex-row md:gap-4","[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start","[&_[role=checkbox]]:mt-[1.5px]",e.isClickable&&"md:flex-col",!e.isClickable&&["md:justify-between","[&>*:not([data-slot=field-content])]:w-full","[&>*:not([data-slot=field-content])]:md:w-1/2","[&>*:not([data-slot=field-content])]:xl:w-2/5"]),children:e.children})}import{jsx as Rt}from"react/jsx-runtime";function Tt(e){let t=Se(e.field),n=s(e.field),r=we(e.field);return e.orientation===u?Rt(yt,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):Rt(bt,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function At(e){if(!e.field.type)return null;let t=Me(e.field,e.disabled),n=qe(e.field),r=We(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,orientation:e.orientation})}import{twMerge as bn}from"tailwind-merge";import{jsx as U,jsxs as Rn}from"react/jsx-runtime";function Ct(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{orientation:r}=w(e.style,{orientation:Pe(e.field)}),o=Le(e.field,e.disabled);return Rn("div",{className:bn("flex flex-col gap-3",Qe(t)),children:[U(Tt,{disabled:o,errors:n,field:e.field,orientation:r,children:U(At,{disabled:o,errors:n,field:e.field,orientation:r,children:e.children})}),U(xt,{errors:n,name:e.field.name})]})}import{twMerge as Tn}from"tailwind-merge";import{jsx as ht}from"react/jsx-runtime";function Nt(e){let t=Je(e.column?.advanced?.cols);return ht("div",{className:"flex w-full flex-col gap-4",children:ht("div",{className:Tn("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children})})}import{Fragment as An}from"react";import{jsx as B,jsxs as Cn}from"react/jsx-runtime";function $(e){let{column:t,field:n}=e.components;return P(e.fields).map((r,o)=>Cn(An,{children:[Ee(r)&&B(t,{column:r,children:B($,{...e,fields:r.fields})}),Ie(r)&&B(n,{disabled:e.disabled,field:r,style:e.style,children:e.children})]},o))}import{jsx as hn}from"react/jsx-runtime";function Ft(e){return n=>hn($,{...n,components:{column:Nt,field:e}})}var St=Ft(Ct);import{jsx as H}from"react/jsx-runtime";function K(e){let t=e.translations?.[e.lang??""];return H(it,{config:e.config,control:e.children,definition:e.definition,readOnly:e.readOnly,sections:e.sections,children:({disabled:n,fields:r})=>H(St,{disabled:n,fields:r,style:e.config.style,children:o=>H(pt,{...o,config:e.config,context:e.context,translations:t,value:e.value})})})}import{Suspense as Nn}from"react";import{jsx as Et}from"react/jsx-runtime";function Fn(e){return Et(Nn,{fallback:Et(K,{config:e.config,sections:e.sections,readOnly:!0}),children:e.children})}export{Fn as Fallback,K as Form};
1
+ // src/component/control.tsx
2
+ import { jsx } from "react/jsx-runtime";
3
+ function Control(props) {
4
+ const content = typeof props.children === "function" ? props.children({ isPending: props.isPending }) : props.children;
5
+ return /* @__PURE__ */ jsx("div", { "data-slot": "field-control", className: "w-full", children: content });
6
+ }
7
+
8
+ // src/component/group.tsx
9
+ import { jsx as jsx2 } from "react/jsx-runtime";
10
+ function Group(props) {
11
+ return /* @__PURE__ */ jsx2(
12
+ "div",
13
+ {
14
+ "data-slot": "field-group",
15
+ "data-compact": props.compact,
16
+ className: "flex w-full flex-col gap-8 data-[compact=true]:gap-3",
17
+ children: props.children
18
+ }
19
+ );
20
+ }
21
+
22
+ // ../luna-core/src/util/constant.ts
23
+ var INPUT = "input";
24
+ var INPUT_EMAIL = "input/email";
25
+ var INPUT_NUMBER = "input/number";
26
+ var TEXTAREA = "textarea";
27
+ var RADIO = "radio";
28
+ var CHECKBOX = "checkbox";
29
+ var SELECT = "select";
30
+ var SELECT_MONTH = "select/month";
31
+ var SELECT_YEAR = "select/year";
32
+ var COLUMN = "column";
33
+ var LABEL = "label";
34
+ var VALUE = "value";
35
+ var OPTIONS = "options";
36
+ var TYPE_EMAIL = "email";
37
+ var TYPE_NUMBER = "number";
38
+ var TYPE_PASSWORD = "password";
39
+ var TYPE_TEL = "tel";
40
+ var TYPE_TEXT = "text";
41
+ var ARIA_ERROR_MESSAGE = "aria-errormessage";
42
+ var ARIA_INVALID = "aria-invalid";
43
+ var DATA_INVALID = "data-invalid";
44
+ var DATA_READONLY = "data-readonly";
45
+ var PREFIX_ARIA = "aria";
46
+ var PREFIX_DATA = "data";
47
+ var MIN = "min";
48
+ var MAX = "max";
49
+ var MIN_LENGTH = "minLength";
50
+ var MAX_LENGTH = "maxLength";
51
+ var $REF = "$ref";
52
+ var VERTICAL = "vertical";
53
+ var HORIZONTAL = "horizontal";
54
+
55
+ // ../luna-core/src/util/is-type.ts
56
+ function isObject(value) {
57
+ return value !== null && Object.prototype.toString.call(value) === "[object Object]";
58
+ }
59
+ function isValue(value) {
60
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
61
+ }
62
+ function isString(value) {
63
+ return typeof value === "string";
64
+ }
65
+
66
+ // ../luna-core/src/util/extract.ts
67
+ var REGEX_TYPE = /[^/]+$/;
68
+ function getCurrentValue(value, entity = VALUE) {
69
+ if (value !== null && value !== void 0) {
70
+ if (isValue(value)) {
71
+ return value;
72
+ }
73
+ if (isObject(value)) {
74
+ const result = getValue(value, entity);
75
+ if (isValue(result)) {
76
+ return result;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ function getValue(value, namespace) {
82
+ const result = extract(value, namespace);
83
+ if (isValue(result)) {
84
+ return result;
85
+ }
86
+ }
87
+ function extract(value, namespace) {
88
+ if (!namespace || !isObject(value)) {
89
+ return null;
90
+ }
91
+ const keys = namespace.split(".").filter((key) => key !== "");
92
+ if (keys.length === 0) {
93
+ return null;
94
+ }
95
+ let result = value;
96
+ for (const key of keys) {
97
+ if (isObject(result) && key in result) {
98
+ const obj = result;
99
+ result = obj[key];
100
+ } else {
101
+ return null;
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+ function toOptions(data, options = { label: LABEL, value: VALUE }) {
107
+ return data.map((item) => {
108
+ if (isObject(item)) {
109
+ const label = extract(item, options.label);
110
+ const value = extract(item, options.value);
111
+ if (isValue(label) && isValue(value)) {
112
+ return {
113
+ label: `${label}`,
114
+ value: `${value}`
115
+ };
116
+ }
117
+ }
118
+ return item;
119
+ });
120
+ }
121
+ function getType(value = TYPE_TEXT) {
122
+ if (value) {
123
+ const result = value.match(REGEX_TYPE);
124
+ if (result) {
125
+ const [type] = result;
126
+ if (type !== INPUT) {
127
+ return type.trim().toLowerCase();
128
+ }
129
+ }
130
+ }
131
+ return TYPE_TEXT;
132
+ }
133
+
134
+ // ../luna-core/src/util/string.ts
135
+ var REGEX_MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
136
+ function interpolate(template, values = {}) {
137
+ if (isString(template)) {
138
+ return replacePlaceholders(template, values);
139
+ }
140
+ if (Array.isArray(template)) {
141
+ return template.map((item) => {
142
+ return interpolate(item, values);
143
+ });
144
+ }
145
+ if (isObject(template)) {
146
+ const results = {};
147
+ for (const key in template) {
148
+ results[key] = interpolate(template[key], values);
149
+ }
150
+ return results;
151
+ }
152
+ return template;
153
+ }
154
+ function isInterpolated(template) {
155
+ if (isString(template)) {
156
+ return /{([^}]+)}/.test(template);
157
+ }
158
+ if (Array.isArray(template)) {
159
+ return template.some((item) => isInterpolated(item));
160
+ }
161
+ if (isObject(template)) {
162
+ return Object.values(template).some((value) => isInterpolated(value));
163
+ }
164
+ return false;
165
+ }
166
+ function replacePlaceholders(template, values = {}) {
167
+ return template.replace(/{([^}]+)}/g, (match, key) => {
168
+ const value = key.includes(".") ? extract(values, key) : values[key];
169
+ if (isValue(value)) {
170
+ return String(value);
171
+ }
172
+ return match;
173
+ });
174
+ }
175
+ function formatMarkdown(text, callback) {
176
+ if (!text || text.trim().length === 0) {
177
+ return null;
178
+ }
179
+ let match;
180
+ let lastIndex = 0;
181
+ let hasMatch = false;
182
+ const parts = [];
183
+ while ((match = REGEX_MARKDOWN_LINK.exec(text)) !== null) {
184
+ const [fullMatch, linkText, url] = match;
185
+ const index = match.index;
186
+ hasMatch = true;
187
+ if (index > lastIndex) {
188
+ parts.push(text.substring(lastIndex, index));
189
+ }
190
+ const value = callback ? callback(index, url, linkText) : fullMatch;
191
+ parts.push(value);
192
+ lastIndex = index + fullMatch.length;
193
+ }
194
+ if (!hasMatch) {
195
+ return text;
196
+ }
197
+ if (lastIndex < text.length) {
198
+ parts.push(text.substring(lastIndex));
199
+ }
200
+ return parts;
201
+ }
202
+
203
+ // ../luna-core/src/util/is-input.ts
204
+ var isSelectMonth = (field) => createTypeChecker(SELECT_MONTH)(field);
205
+ var isSelectYear = (field) => createTypeChecker(SELECT_YEAR)(field);
206
+ var isCheckbox = createTypeChecker(CHECKBOX);
207
+ var isInput = createTypeChecker(INPUT);
208
+ var isRadio = createTypeChecker(RADIO);
209
+ var isSelect = createTypeChecker(SELECT);
210
+ var isTextArea = createTypeChecker(TEXTAREA);
211
+ var isText = createTypeChecker(
212
+ TYPE_TEXT,
213
+ TYPE_EMAIL,
214
+ TYPE_PASSWORD,
215
+ TYPE_TEL
216
+ );
217
+ var isEmail = createTypeChecker(INPUT_EMAIL, TYPE_EMAIL);
218
+ var isNumber = createTypeChecker(INPUT_NUMBER, TYPE_NUMBER);
219
+ function isClickable(field) {
220
+ return isRadio(field) || isCheckbox(field);
221
+ }
222
+ function isColumn(slot) {
223
+ return slot.type === COLUMN;
224
+ }
225
+ function isField(slot) {
226
+ return slot.type !== COLUMN;
227
+ }
228
+ function isOptions(field) {
229
+ return isSelect(field) || isRadio(field);
230
+ }
231
+ function isValidValue(value) {
232
+ return value !== void 0 && value !== null && value !== "";
233
+ }
234
+ function createTypeChecker(...types) {
235
+ return (field) => {
236
+ const inputType = isString(field.type) ? field.type : void 0;
237
+ if (!inputType) {
238
+ return false;
239
+ }
240
+ return types.some((type) => {
241
+ return inputType === type || inputType?.startsWith(`${type}/`);
242
+ });
243
+ };
244
+ }
245
+
246
+ // ../luna-core/src/util/build.ts
247
+ function buildOptions(field, values = {}) {
248
+ if (isSelect(field) && field.disabled) {
249
+ const current = field.name ? values?.[field.name] : void 0;
250
+ if (current && isObject(current)) {
251
+ return [current];
252
+ }
253
+ }
254
+ }
255
+ function buildOrientation(field) {
256
+ if (isRadio(field) || isCheckbox(field)) {
257
+ return HORIZONTAL;
258
+ }
259
+ return field.advanced?.orientation ?? VERTICAL;
260
+ }
261
+ function buildReverse(field) {
262
+ if (!isCheckbox(field)) {
263
+ return false;
264
+ }
265
+ return field.advanced?.reverse !== false;
266
+ }
267
+ function buildDisabled(field, disabled) {
268
+ const readonly = field.readonly ?? false;
269
+ return disabled ? disabled : readonly;
270
+ }
271
+ function buildSource(field) {
272
+ if (isRadio(field) || isSelect(field) && !field.disabled) {
273
+ const source = field.source;
274
+ if (Array.isArray(source) || isObject(source) && !($REF in source)) {
275
+ return source;
276
+ }
277
+ }
278
+ }
279
+
280
+ // ../luna-core/src/util/date.ts
281
+ var REGEX_DIGITS = /^\d+$/;
282
+ function getMonth() {
283
+ return Array.from({ length: 12 }, (_, i) => ({
284
+ value: (i + 1).toString(),
285
+ label: new Date(0, i).toLocaleString("default", {
286
+ month: "long"
287
+ })
288
+ }));
289
+ }
290
+ function getYear(min, max) {
291
+ if (max >= min) {
292
+ return Array.from({ length: max - min + 1 }, (_, i) => {
293
+ const year = min + i;
294
+ return {
295
+ value: year.toString(),
296
+ label: year.toString()
297
+ };
298
+ });
299
+ }
300
+ return [];
301
+ }
302
+ function getCurrentYear() {
303
+ return (/* @__PURE__ */ new Date()).getFullYear();
304
+ }
305
+ function getConvert(value, current) {
306
+ if (typeof value === "number") {
307
+ return value;
308
+ }
309
+ const now2 = current ?? getCurrentYear();
310
+ const trimmed = value.trim().toLowerCase();
311
+ if (trimmed.startsWith("current")) {
312
+ const match = trimmed.match(/^current([+-])(\d+)$/);
313
+ if (match) {
314
+ const [, operator, offsetStr] = match;
315
+ const offset = parseInt(offsetStr, 10);
316
+ if (!isNaN(offset)) {
317
+ return operator === "+" ? now2 + offset : now2 - offset;
318
+ }
319
+ }
320
+ return now2;
321
+ }
322
+ if (REGEX_DIGITS.test(trimmed)) {
323
+ return parseInt(trimmed, 10);
324
+ }
325
+ return now2;
326
+ }
327
+
328
+ // ../luna-core/src/helper/input.ts
329
+ var now = getCurrentYear();
330
+ function buildOptionSelect(field) {
331
+ if (isSelect(field)) {
332
+ return defineOption(field);
333
+ }
334
+ }
335
+ function defineOption(select) {
336
+ if (isSelectMonth(select)) {
337
+ return getMonth();
338
+ }
339
+ if (isSelectYear(select)) {
340
+ const min = select.advanced?.length?.min ?? now;
341
+ const max = select.advanced?.length?.max ?? now + 5;
342
+ return getYear(getConvert(min, now), getConvert(max, now));
343
+ }
344
+ }
345
+ function buildCommon(field, disabled = false) {
346
+ const commonProps = {
347
+ disabled,
348
+ id: field.name,
349
+ name: field.name,
350
+ placeholder: field.placeholder,
351
+ required: field.required
352
+ };
353
+ if (isInput(field)) {
354
+ return {
355
+ ...commonProps,
356
+ ...defineInput(field)
357
+ };
358
+ }
359
+ if (isSelect(field)) {
360
+ return {
361
+ ...commonProps,
362
+ ...defineSelect(field)
363
+ };
364
+ }
365
+ if (isTextArea(field)) {
366
+ return {
367
+ ...commonProps,
368
+ ...defineTextArea(field)
369
+ };
370
+ }
371
+ return commonProps;
372
+ }
373
+ function defineInput(input) {
374
+ const type = getType(input.type);
375
+ const copy = { ...input, type };
376
+ return {
377
+ ...defineAutoComplete(input),
378
+ ...defineNumberLimits(copy),
379
+ ...isText(copy) ? defineLength(copy) : {},
380
+ type
381
+ };
382
+ }
383
+ function defineSelect(field) {
384
+ const options = buildOptionSelect(field);
385
+ if (options) {
386
+ return { options };
387
+ }
388
+ return {};
389
+ }
390
+ function defineTextArea(field) {
391
+ return {
392
+ ...defineAutoComplete(field),
393
+ ...defineLength(field)
394
+ };
395
+ }
396
+ function defineAutoComplete(input) {
397
+ const autoComplete = input.advanced?.autocomplete;
398
+ if (autoComplete) {
399
+ return { autoComplete };
400
+ }
401
+ return {};
402
+ }
403
+ function defineNumberLimits(input) {
404
+ if (isNumber(input)) {
405
+ return defineMinMax(input);
406
+ }
407
+ return {};
408
+ }
409
+ function defineLength(input) {
410
+ return defineConstraints(input, { min: MIN_LENGTH, max: MAX_LENGTH });
411
+ }
412
+ function defineMinMax(input) {
413
+ return defineConstraints(input, { min: MIN, max: MAX });
414
+ }
415
+ function defineConstraints(input, keys) {
416
+ const result = {};
417
+ const length = input.advanced?.length;
418
+ if (length) {
419
+ if (length.min !== void 0) {
420
+ result[keys.min] = length.min;
421
+ }
422
+ if (length.max !== void 0) {
423
+ result[keys.max] = length.max;
424
+ }
425
+ }
426
+ return result;
427
+ }
428
+ function resolveSource(field, value) {
429
+ const current = buildSource(field);
430
+ if (current) {
431
+ return current;
432
+ }
433
+ return buildOptions(field, value);
434
+ }
435
+ function getInputValue(field, value) {
436
+ const newValue = isObject(value) && field.name in value ? value[field.name] : value;
437
+ return getCurrentValue(newValue, field.advanced?.entity);
438
+ }
439
+ function mergeOptionsProps(field, commonProps, options) {
440
+ return isOptions(field) && Array.isArray(options) ? { ...commonProps, [OPTIONS]: options } : commonProps;
441
+ }
442
+ function getPreselectedValue(field, commonProps, value) {
443
+ if (field.required && !isValidValue(value)) {
444
+ if (isSelect(field)) {
445
+ if (field.advanced?.preselected !== false && OPTIONS in commonProps) {
446
+ const options = commonProps[OPTIONS];
447
+ if (Array.isArray(options) && options.length === 1) {
448
+ return options[0];
449
+ }
450
+ }
451
+ }
452
+ }
453
+ return value;
454
+ }
455
+ function getOptions(field, data) {
456
+ if (isSelect(field) && Array.isArray(data)) {
457
+ return toOptions(data, field.advanced?.options);
458
+ }
459
+ return data;
460
+ }
461
+ function prepareInputProps(field, commonProps, data, value) {
462
+ const currentValue = getInputValue(field, value);
463
+ const options = Array.isArray(data) ? getOptions(field, data) : data;
464
+ const commonPropsWithOptions = mergeOptionsProps(field, commonProps, options);
465
+ const defaultValue = getPreselectedValue(
466
+ field,
467
+ commonPropsWithOptions,
468
+ currentValue
469
+ );
470
+ return {
471
+ commonPropsWithOptions,
472
+ defaultValue
473
+ };
474
+ }
475
+ function prepareDefaultValue(field, value) {
476
+ if (isCheckbox(field)) {
477
+ return {
478
+ defaultChecked: isValidValue(value)
479
+ };
480
+ }
481
+ return { defaultValue: value };
482
+ }
483
+
484
+ // ../luna-core/src/util/prepare.ts
485
+ var REGEX_REF = /^#\/definition\//;
486
+ function prepare(base = [], definition) {
487
+ const resolved = resolveRefs(base, definition);
488
+ return Array.isArray(resolved) ? resolved.sort((a, b) => getOrder(a) - getOrder(b)) : [];
489
+ }
490
+ function resolveRefs(base, definition, cache = /* @__PURE__ */ new Map(), visited = /* @__PURE__ */ new WeakSet()) {
491
+ if (!isDefinition(definition) || !base || typeof base !== "object") {
492
+ return base;
493
+ }
494
+ if (cache.has(base)) {
495
+ return cache.get(base);
496
+ }
497
+ if (visited.has(base)) {
498
+ return base;
499
+ }
500
+ visited.add(base);
501
+ if (Array.isArray(base)) {
502
+ return base.map((item) => resolveRefs(item, definition, cache, visited));
503
+ }
504
+ if ($REF in base && isString(base[$REF])) {
505
+ const path = base[$REF].replace(REGEX_REF, "");
506
+ const resolved = extract(definition, path);
507
+ if (resolved !== null) {
508
+ return resolveRefs(resolved, definition, cache, visited);
509
+ }
510
+ return base;
511
+ }
512
+ const result = {};
513
+ for (const [key, value] of Object.entries(base)) {
514
+ result[key] = resolveRefs(value, definition, cache, visited);
515
+ }
516
+ visited.delete(base);
517
+ cache.set(base, result);
518
+ return result;
519
+ }
520
+ function entries(values) {
521
+ return Object.entries(values ?? {});
522
+ }
523
+ function getOrder(item) {
524
+ return item.order ?? Number.MAX_VALUE;
525
+ }
526
+ function isDefinition(definition) {
527
+ return definition !== void 0 && isObject(definition) && Object.keys(definition).length > 0;
528
+ }
529
+
530
+ // ../luna-core/src/util/attributes.ts
531
+ function getPrefixedAttributes(prefix, record) {
532
+ const attrs = {};
533
+ for (const [key, value] of entries(record)) {
534
+ attrs[`${prefix}-${key}`] = value;
535
+ }
536
+ return attrs;
537
+ }
538
+ function getAriaAttributes(record) {
539
+ return getPrefixedAttributes(PREFIX_ARIA, record);
540
+ }
541
+ function getDataAttributes(record) {
542
+ return getPrefixedAttributes(PREFIX_DATA, record);
543
+ }
544
+ function buildAriaAttributes(field, errors) {
545
+ const ariaAttributes = getAriaAttributes(field.advanced?.aria);
546
+ if (errors && errors.length > 0) {
547
+ ariaAttributes[ARIA_INVALID] = "true";
548
+ ariaAttributes[ARIA_ERROR_MESSAGE] = `${field.name}-error`;
549
+ }
550
+ return ariaAttributes;
551
+ }
552
+ function buildDataAttributes(field) {
553
+ return getDataAttributes(field.advanced?.data);
554
+ }
555
+
556
+ // ../luna-core/src/util/column.ts
557
+ var cols = {
558
+ 1: "md:grid-cols-1",
559
+ 2: "md:grid-cols-2",
560
+ 3: "md:grid-cols-3"
561
+ };
562
+ var span = {
563
+ 1: "md:col-span-1",
564
+ 2: "md:col-span-2",
565
+ 3: "md:col-span-3"
566
+ };
567
+ function getColumn(value, defaultCols = 2) {
568
+ return cols[value && value in cols ? value : defaultCols];
569
+ }
570
+ function getSpan(value) {
571
+ if (value && value in span) {
572
+ return span[value];
573
+ }
574
+ }
575
+
576
+ // ../luna-core/src/util/translate.ts
577
+ function translate(key, dictionary) {
578
+ if (!key) {
579
+ return "";
580
+ }
581
+ if (!dictionary) {
582
+ return key;
583
+ }
584
+ return dictionary[key] ?? key;
585
+ }
586
+
587
+ // ../luna-core/src/util/style.ts
588
+ function mergeStyle(globalStyle, localStyle) {
589
+ return { ...globalStyle, ...localStyle };
590
+ }
591
+
592
+ // src/lib/string.tsx
593
+ import { jsx as jsx3 } from "react/jsx-runtime";
594
+ function formatMarkdown2(text) {
595
+ return formatMarkdown(
596
+ text,
597
+ (index, url, text2) => {
598
+ return /* @__PURE__ */ jsx3(
599
+ "a",
600
+ {
601
+ className: "underline",
602
+ href: url,
603
+ rel: "noopener noreferrer",
604
+ target: "_blank",
605
+ children: text2
606
+ },
607
+ `${url}-${index}`
608
+ );
609
+ }
610
+ );
611
+ }
612
+
613
+ // src/component/legend.tsx
614
+ import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
615
+ function Legend(props) {
616
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
617
+ props.title && /* @__PURE__ */ jsx4("legend", { className: "mb-3 font-medium text-slate-800 dark:text-slate-200", children: formatMarkdown2(props.title) }),
618
+ props.description && /* @__PURE__ */ jsx4("p", { className: "-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.description) })
619
+ ] });
620
+ }
621
+
622
+ // src/component/field/field-set.tsx
623
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
624
+ function FieldSet(props) {
625
+ const fields = props.section.fields || [];
626
+ const { compact } = mergeStyle(props.style, {
627
+ compact: props.section.compact
628
+ });
629
+ if (!props.section.title && !props.section.description) {
630
+ return /* @__PURE__ */ jsx5(Group, { compact, children: props.children });
631
+ }
632
+ return /* @__PURE__ */ jsxs2(
633
+ "fieldset",
634
+ {
635
+ "data-slot": "field-set",
636
+ "data-empty": fields.length === 0,
637
+ className: "flex flex-col data-[empty=false]:gap-6",
638
+ id: props.section.id?.toString(),
639
+ children: [
640
+ /* @__PURE__ */ jsx5(
641
+ Legend,
642
+ {
643
+ description: props.section.description,
644
+ title: props.section.title
645
+ }
646
+ ),
647
+ /* @__PURE__ */ jsx5(Group, { compact, children: props.children })
648
+ ]
649
+ }
650
+ );
651
+ }
652
+
653
+ // src/component/form.tsx
654
+ import { Fragment as Fragment2 } from "react";
655
+
656
+ // src/component/separator.tsx
657
+ import { jsx as jsx6 } from "react/jsx-runtime";
658
+ function Separator() {
659
+ return /* @__PURE__ */ jsx6("div", { "data-slot": "field-separator", className: "relative -my-2 h-5 text-sm", children: /* @__PURE__ */ jsx6("div", { className: "absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800" }) });
660
+ }
661
+
662
+ // src/component/form.tsx
663
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
664
+ function Form(props) {
665
+ const sections = prepare(props.sections, props.definition);
666
+ return /* @__PURE__ */ jsx7("div", { className: "h-full w-full", children: /* @__PURE__ */ jsx7("form", { noValidate: props.noValidate, action: props.action, children: /* @__PURE__ */ jsxs3(Group, { children: [
667
+ sections.map((section, index) => /* @__PURE__ */ jsxs3(Fragment2, { children: [
668
+ /* @__PURE__ */ jsx7(FieldSet, { section, style: props.config.style, children: props.children({
669
+ disabled: props.readOnly,
670
+ fields: section.fields
671
+ }) }),
672
+ section.separator && /* @__PURE__ */ jsx7(Separator, {})
673
+ ] }, index)),
674
+ props.control && /* @__PURE__ */ jsx7(Control, { isPending: props.isPending, children: props.control })
675
+ ] }) }) });
676
+ }
677
+
678
+ // src/component/description.tsx
679
+ import { jsx as jsx8 } from "react/jsx-runtime";
680
+ function Description(props) {
681
+ return /* @__PURE__ */ jsx8("p", { className: "-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400", children: props.children });
682
+ }
683
+
684
+ // src/component/formatted-description.tsx
685
+ import { jsx as jsx9 } from "react/jsx-runtime";
686
+ function FormattedDescription(props) {
687
+ const content = formatMarkdown2(props.text);
688
+ if (content) {
689
+ return /* @__PURE__ */ jsx9(Description, { children: content });
690
+ }
691
+ return null;
692
+ }
693
+
694
+ // src/component/label.tsx
695
+ import { twMerge } from "tailwind-merge";
696
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
697
+ function Label(props) {
698
+ const showOptionalLabel = props.style?.showOptionalLabel ?? true;
699
+ const normal = isRadio(props.field) || isCheckbox(props.field);
700
+ return /* @__PURE__ */ jsxs4(
701
+ "label",
702
+ {
703
+ "data-slot": "field-label",
704
+ "data-normal": normal,
705
+ className: twMerge(
706
+ "flex w-fit items-center gap-2 text-sm leading-snug font-medium select-none",
707
+ "data-[normal=true]:font-normal",
708
+ "group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"
709
+ ),
710
+ htmlFor: props.field.name,
711
+ children: [
712
+ props.children,
713
+ showOptionalLabel && !props.field.required && /* @__PURE__ */ jsx10("span", { className: "text-sm text-slate-600 dark:text-slate-400", children: translate("(Optional)", props.translations) })
714
+ ]
715
+ }
716
+ );
717
+ }
718
+
719
+ // src/component/input-label.tsx
720
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
721
+ function InputLabel(props) {
722
+ const label = isInterpolated(props.field.label) ? interpolate(props.field.label, {
723
+ context: props.context,
724
+ env: props.config?.env
725
+ }) : props.field.label;
726
+ const description = isInterpolated(props.field.description) ? interpolate(props.field.description, {
727
+ context: props.context,
728
+ env: props.config?.env
729
+ }) : props.field.description;
730
+ return /* @__PURE__ */ jsxs5(
731
+ "div",
732
+ {
733
+ "data-slot": "field-content",
734
+ className: "flex w-full flex-1 flex-col gap-1.5 leading-snug",
735
+ children: [
736
+ /* @__PURE__ */ jsx11(
737
+ Label,
738
+ {
739
+ field: props.field,
740
+ style: props.config?.style,
741
+ translations: props.translations,
742
+ children: translate(label, props.translations)
743
+ }
744
+ ),
745
+ props.orientation === HORIZONTAL && /* @__PURE__ */ jsx11(
746
+ FormattedDescription,
747
+ {
748
+ text: translate(description, props.translations)
749
+ }
750
+ )
751
+ ]
752
+ }
753
+ );
754
+ }
755
+
756
+ // src/component/input-group.tsx
757
+ import { Fragment as Fragment3, jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
758
+ function InputGroup(props) {
759
+ return /* @__PURE__ */ jsxs6(Fragment3, { children: [
760
+ props.field.name && props.field.label && /* @__PURE__ */ jsx12(
761
+ InputLabel,
762
+ {
763
+ config: props.config,
764
+ context: props.context,
765
+ field: props.field,
766
+ orientation: props.orientation,
767
+ translations: props.translations
768
+ }
769
+ ),
770
+ props.children,
771
+ props.orientation === VERTICAL && props.field.description && /* @__PURE__ */ jsx12(
772
+ FormattedDescription,
773
+ {
774
+ text: translate(props.field.description, props.translations)
775
+ }
776
+ )
777
+ ] });
778
+ }
779
+
780
+ // src/lib/render-If-exists.ts
781
+ function renderIfExists(value, render) {
782
+ if (!value) {
783
+ return null;
784
+ }
785
+ return render(value);
786
+ }
787
+
788
+ // src/server/component/input.tsx
789
+ import { jsx as jsx13 } from "react/jsx-runtime";
790
+ function Input(props) {
791
+ const source = resolveSource(props.field, props.value);
792
+ const { commonPropsWithOptions, defaultValue } = prepareInputProps(
793
+ props.field,
794
+ props.commonProps,
795
+ source,
796
+ props.value
797
+ );
798
+ const defaultProps = prepareDefaultValue(props.field, defaultValue);
799
+ return renderIfExists(props.config.inputs[props.field.type], (Component) => /* @__PURE__ */ jsx13(
800
+ InputGroup,
801
+ {
802
+ config: props.config,
803
+ context: props.context,
804
+ field: props.field,
805
+ orientation: props.orientation,
806
+ translations: props.translations,
807
+ children: /* @__PURE__ */ jsx13(
808
+ Component,
809
+ {
810
+ ...props.ariaAttributes,
811
+ ...commonPropsWithOptions,
812
+ ...props.dataAttributes,
813
+ ...defaultProps
814
+ }
815
+ )
816
+ }
817
+ ));
818
+ }
819
+
820
+ // src/component/field/field-error.tsx
821
+ import { jsx as jsx14 } from "react/jsx-runtime";
822
+ function FieldError(props) {
823
+ if (!props.errors || props.errors.length === 0) {
824
+ return null;
825
+ }
826
+ return /* @__PURE__ */ jsx14(
827
+ "ul",
828
+ {
829
+ className: "text-sm text-red-600 dark:text-red-500",
830
+ id: props.name ? `${props.name}-error` : void 0,
831
+ children: props.errors?.map((error, index) => /* @__PURE__ */ jsx14("li", { children: error }, props.name ? `${props.name}-error-${index}` : index))
832
+ }
833
+ );
834
+ }
835
+
836
+ // src/component/field/field-base.tsx
837
+ import { twMerge as twMerge2 } from "tailwind-merge";
838
+ import { jsx as jsx15 } from "react/jsx-runtime";
839
+ function FieldBase(props) {
840
+ const errors = props.errors && props.errors.length > 0;
841
+ return /* @__PURE__ */ jsx15(
842
+ "div",
843
+ {
844
+ "data-slot": "field",
845
+ "data-clickable": props.isClickable ? "true" : "false",
846
+ ...errors && { [DATA_INVALID]: "true" },
847
+ ...props.disabled && { [DATA_READONLY]: "true" },
848
+ "data-orientation": props.orientation,
849
+ className: twMerge2(
850
+ "group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500",
851
+ "data-[clickable=true]:items-start",
852
+ props.isCheckbox && (props.isReversed ? "flex-row-reverse!" : "flex-row!"),
853
+ "data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",
854
+ props.className
855
+ ),
856
+ children: props.children
857
+ }
858
+ );
859
+ }
860
+
861
+ // src/component/field/field-vertical.tsx
862
+ import { twMerge as twMerge3 } from "tailwind-merge";
863
+ import { jsx as jsx16 } from "react/jsx-runtime";
864
+ function FieldVertical(props) {
865
+ return /* @__PURE__ */ jsx16(
866
+ FieldBase,
867
+ {
868
+ ...props,
869
+ orientation: VERTICAL,
870
+ className: twMerge3(
871
+ "gap-3 has-[>[data-slot=field-content]]:items-start",
872
+ !props.isClickable && "[&>*]:w-full"
873
+ ),
874
+ children: props.children
875
+ }
876
+ );
877
+ }
878
+
879
+ // src/component/field/field-horizontal.tsx
880
+ import { twMerge as twMerge4 } from "tailwind-merge";
881
+ import { jsx as jsx17 } from "react/jsx-runtime";
882
+ function FieldHorizontal(props) {
883
+ return /* @__PURE__ */ jsx17(
884
+ FieldBase,
885
+ {
886
+ ...props,
887
+ orientation: HORIZONTAL,
888
+ className: twMerge4(
889
+ "gap-2 md:flex-row md:gap-4",
890
+ "[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start",
891
+ "[&_[role=checkbox]]:mt-[1.5px]",
892
+ props.isClickable && "md:flex-col",
893
+ !props.isClickable && [
894
+ "md:justify-between",
895
+ "[&>*:not([data-slot=field-content])]:w-full",
896
+ "[&>*:not([data-slot=field-content])]:md:w-1/2",
897
+ "[&>*:not([data-slot=field-content])]:xl:w-2/5"
898
+ ]
899
+ ),
900
+ children: props.children
901
+ }
902
+ );
903
+ }
904
+
905
+ // src/component/field/field-group.tsx
906
+ import { jsx as jsx18 } from "react/jsx-runtime";
907
+ function FieldGroup(props) {
908
+ const clickable = isClickable(props.field);
909
+ const checkbox = isCheckbox(props.field);
910
+ const reversed = buildReverse(props.field);
911
+ if (props.orientation === VERTICAL) {
912
+ return /* @__PURE__ */ jsx18(
913
+ FieldVertical,
914
+ {
915
+ disabled: props.disabled,
916
+ errors: props.errors,
917
+ isCheckbox: checkbox,
918
+ isReversed: reversed,
919
+ isClickable: clickable,
920
+ children: props.children
921
+ }
922
+ );
923
+ }
924
+ return /* @__PURE__ */ jsx18(
925
+ FieldHorizontal,
926
+ {
927
+ disabled: props.disabled,
928
+ errors: props.errors,
929
+ isCheckbox: checkbox,
930
+ isReversed: reversed,
931
+ isClickable: clickable,
932
+ children: props.children
933
+ }
934
+ );
935
+ }
936
+
937
+ // src/component/input/input-base.tsx
938
+ function InputBase(props) {
939
+ if (!props.field.type) {
940
+ return null;
941
+ }
942
+ const commonProps = buildCommon(props.field, props.disabled);
943
+ const dataAttributes = buildDataAttributes(props.field);
944
+ const ariaAttributes = buildAriaAttributes(props.field, props.errors);
945
+ const field = {
946
+ ...props.field,
947
+ disabled: commonProps.disabled
948
+ };
949
+ return props.children({
950
+ ariaAttributes,
951
+ commonProps,
952
+ dataAttributes,
953
+ field,
954
+ orientation: props.orientation
955
+ });
956
+ }
957
+
958
+ // src/component/field/field.tsx
959
+ import { twMerge as twMerge5 } from "tailwind-merge";
960
+ import { jsx as jsx19, jsxs as jsxs7 } from "react/jsx-runtime";
961
+ function Field(props) {
962
+ const cols2 = props.field.advanced?.cols;
963
+ const errors = props.field.name ? props.errors?.[props.field.name] : void 0;
964
+ const { orientation } = mergeStyle(props.style, {
965
+ orientation: buildOrientation(props.field)
966
+ });
967
+ const disabled = buildDisabled(props.field, props.disabled);
968
+ return /* @__PURE__ */ jsxs7("div", { className: twMerge5("flex flex-col gap-3", getSpan(cols2)), children: [
969
+ /* @__PURE__ */ jsx19(
970
+ FieldGroup,
971
+ {
972
+ disabled,
973
+ errors,
974
+ field: props.field,
975
+ orientation,
976
+ children: /* @__PURE__ */ jsx19(
977
+ InputBase,
978
+ {
979
+ disabled,
980
+ errors,
981
+ field: props.field,
982
+ orientation,
983
+ children: props.children
984
+ }
985
+ )
986
+ }
987
+ ),
988
+ /* @__PURE__ */ jsx19(FieldError, { errors, name: props.field.name })
989
+ ] });
990
+ }
991
+
992
+ // src/component/column.tsx
993
+ import { twMerge as twMerge6 } from "tailwind-merge";
994
+ import { jsx as jsx20 } from "react/jsx-runtime";
995
+ function Column(props) {
996
+ const cols2 = getColumn(props.column?.advanced?.cols);
997
+ return /* @__PURE__ */ jsx20("div", { className: "flex w-full flex-col gap-4", children: /* @__PURE__ */ jsx20("div", { className: twMerge6("grid grid-cols-1 gap-3 sm:gap-4", cols2), children: props.children }) });
998
+ }
999
+
1000
+ // src/component/slot/slot-base.tsx
1001
+ import { Fragment as Fragment4 } from "react";
1002
+ import { jsx as jsx21, jsxs as jsxs8 } from "react/jsx-runtime";
1003
+ function SlotBase(props) {
1004
+ const { column: Column2, field: Field2 } = props.components;
1005
+ return prepare(props.fields).map((field, index) => /* @__PURE__ */ jsxs8(Fragment4, { children: [
1006
+ isColumn(field) && /* @__PURE__ */ jsx21(Column2, { column: field, children: /* @__PURE__ */ jsx21(SlotBase, { ...props, fields: field.fields }) }),
1007
+ isField(field) && /* @__PURE__ */ jsx21(Field2, { disabled: props.disabled, field, style: props.style, children: props.children })
1008
+ ] }, index));
1009
+ }
1010
+
1011
+ // src/component/slot/slot-create.tsx
1012
+ import { jsx as jsx22 } from "react/jsx-runtime";
1013
+ function createSlot(Field2) {
1014
+ const CreateSlot = (props) => /* @__PURE__ */ jsx22(SlotBase, { ...props, components: { column: Column, field: Field2 } });
1015
+ return CreateSlot;
1016
+ }
1017
+
1018
+ // src/component/slot/slot.tsx
1019
+ var Slot = createSlot(Field);
1020
+
1021
+ // src/server/component/form.tsx
1022
+ import { jsx as jsx23 } from "react/jsx-runtime";
1023
+ function Form2(props) {
1024
+ const translations = props.translations?.[props.lang ?? ""];
1025
+ return /* @__PURE__ */ jsx23(
1026
+ Form,
1027
+ {
1028
+ config: props.config,
1029
+ control: props.children,
1030
+ definition: props.definition,
1031
+ readOnly: props.readOnly,
1032
+ sections: props.sections,
1033
+ children: ({ disabled, fields }) => /* @__PURE__ */ jsx23(Slot, { disabled, fields, style: props.config.style, children: (internal) => /* @__PURE__ */ jsx23(
1034
+ Input,
1035
+ {
1036
+ ...internal,
1037
+ config: props.config,
1038
+ context: props.context,
1039
+ translations,
1040
+ value: props.value
1041
+ }
1042
+ ) })
1043
+ }
1044
+ );
1045
+ }
1046
+
1047
+ // src/server/component/fallback.tsx
1048
+ import { Suspense } from "react";
1049
+ import { jsx as jsx24 } from "react/jsx-runtime";
1050
+ function Fallback(props) {
1051
+ return /* @__PURE__ */ jsx24(
1052
+ Suspense,
1053
+ {
1054
+ fallback: /* @__PURE__ */ jsx24(Form2, { config: props.config, sections: props.sections, readOnly: true }),
1055
+ children: props.children
1056
+ }
1057
+ );
1058
+ }
1059
+ export {
1060
+ Fallback,
1061
+ Form2 as Form
1062
+ };