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