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