react-luna-form 0.0.45 → 0.0.46
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/esm/index.js
CHANGED
|
@@ -1,3366 +1 @@
|
|
|
1
|
-
// src/component/control.tsx
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
function Control(props) {
|
|
4
|
-
const content = typeof props.children === "function" ? props.children({ isPending: props.isPending }) : props.children;
|
|
5
|
-
return /* @__PURE__ */ jsx("div", { "data-slot": "field-control", className: "w-full", children: content });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// src/component/chevron-icon.tsx
|
|
9
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
10
|
-
function ChevronIcon(props) {
|
|
11
|
-
return /* @__PURE__ */ jsx2(
|
|
12
|
-
"svg",
|
|
13
|
-
{
|
|
14
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
15
|
-
viewBox: "0 0 20 20",
|
|
16
|
-
fill: "currentColor",
|
|
17
|
-
className: `size-4 transition-transform duration-200 ${props.expanded ? "rotate-90" : ""}`,
|
|
18
|
-
children: /* @__PURE__ */ jsx2(
|
|
19
|
-
"path",
|
|
20
|
-
{
|
|
21
|
-
fillRule: "evenodd",
|
|
22
|
-
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",
|
|
23
|
-
clipRule: "evenodd"
|
|
24
|
-
}
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/component/collapsible.tsx
|
|
31
|
-
import { Activity } from "react";
|
|
32
|
-
|
|
33
|
-
// src/client/context/keep-value-context.tsx
|
|
34
|
-
import { createContext } from "react";
|
|
35
|
-
var KeepValueContext = createContext(false);
|
|
36
|
-
|
|
37
|
-
// src/component/collapsible.tsx
|
|
38
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
39
|
-
function Collapsible({
|
|
40
|
-
children,
|
|
41
|
-
visible
|
|
42
|
-
}) {
|
|
43
|
-
return /* @__PURE__ */ jsx3(Activity, { mode: visible ? "visible" : "hidden", children: /* @__PURE__ */ jsx3(KeepValueContext, { value: true, children }) });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ../luna-core/src/util/constant.ts
|
|
47
|
-
var INPUT = "input";
|
|
48
|
-
var INPUT_DATE = "input/date";
|
|
49
|
-
var INPUT_EMAIL = "input/email";
|
|
50
|
-
var INPUT_NUMBER = "input/number";
|
|
51
|
-
var INPUT_TIME = "input/time";
|
|
52
|
-
var TEXTAREA = "textarea";
|
|
53
|
-
var RADIO = "radio";
|
|
54
|
-
var CHECKBOX = "checkbox";
|
|
55
|
-
var LIST = "list";
|
|
56
|
-
var SELECT = "select";
|
|
57
|
-
var SELECT_DAY = "select/day";
|
|
58
|
-
var SELECT_MONTH = "select/month";
|
|
59
|
-
var SELECT_TIMEZONE = "select/timezone";
|
|
60
|
-
var SELECT_YEAR = "select/year";
|
|
61
|
-
var CHIPS = "chips";
|
|
62
|
-
var CHIPS_DAYS = "chips/day";
|
|
63
|
-
var CHIPS_MONTHS = "chips/month";
|
|
64
|
-
var COLUMN = "column";
|
|
65
|
-
var DESCRIPTION = "description";
|
|
66
|
-
var FIELDS = "fields";
|
|
67
|
-
var LABEL = "label";
|
|
68
|
-
var VALUE = "value";
|
|
69
|
-
var OPTIONS = "options";
|
|
70
|
-
var TYPE_EMAIL = "email";
|
|
71
|
-
var TYPE_NUMBER = "number";
|
|
72
|
-
var TYPE_PASSWORD = "password";
|
|
73
|
-
var TYPE_TEL = "tel";
|
|
74
|
-
var TYPE_TEXT = "text";
|
|
75
|
-
var ARIA_ERROR_MESSAGE = "aria-errormessage";
|
|
76
|
-
var ARIA_INVALID = "aria-invalid";
|
|
77
|
-
var DATA_INVALID = "data-invalid";
|
|
78
|
-
var DATA_READONLY = "data-readonly";
|
|
79
|
-
var PREFIX_ARIA = "aria";
|
|
80
|
-
var PREFIX_DATA = "data";
|
|
81
|
-
var MAX = "max";
|
|
82
|
-
var MAX_LENGTH = "maxLength";
|
|
83
|
-
var MIN = "min";
|
|
84
|
-
var MIN_LENGTH = "minLength";
|
|
85
|
-
var $REF = "$ref";
|
|
86
|
-
var SOURCE = "source";
|
|
87
|
-
var STATE = "state";
|
|
88
|
-
var COMMON_URL = "http://luna.internal";
|
|
89
|
-
var TYPE = "type";
|
|
90
|
-
var TIMEZONE_REGIONS = {
|
|
91
|
-
Africa: "Africa",
|
|
92
|
-
America: "Americas",
|
|
93
|
-
Asia: "Asia / Pacific",
|
|
94
|
-
Atlantic: "Atlantic",
|
|
95
|
-
Australia: "Asia / Pacific",
|
|
96
|
-
Europe: "Europe",
|
|
97
|
-
Indian: "Asia / Pacific",
|
|
98
|
-
Pacific: "Asia / Pacific"
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// ../luna-core/src/util/is-type.ts
|
|
102
|
-
function isObject(value) {
|
|
103
|
-
return value !== null && Object.prototype.toString.call(value) === "[object Object]";
|
|
104
|
-
}
|
|
105
|
-
function isEmpty(value) {
|
|
106
|
-
return value === null || value === void 0 || value === "";
|
|
107
|
-
}
|
|
108
|
-
function isValue(value) {
|
|
109
|
-
return isString(value) || typeof value === "number" || isBoolean(value);
|
|
110
|
-
}
|
|
111
|
-
function isString(value) {
|
|
112
|
-
return typeof value === "string";
|
|
113
|
-
}
|
|
114
|
-
function isDataSource(value) {
|
|
115
|
-
return isObject(value) && "url" in value;
|
|
116
|
-
}
|
|
117
|
-
function isBoolean(value) {
|
|
118
|
-
return typeof value === "boolean";
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ../luna-core/src/util/extract.ts
|
|
122
|
-
var REGEX_NUMERIC = /^\d+$/;
|
|
123
|
-
function getEntity(selected, collection = [], entity = VALUE) {
|
|
124
|
-
if (Array.isArray(collection)) {
|
|
125
|
-
return collection.find((item) => {
|
|
126
|
-
const current = getCurrentValue(item, entity);
|
|
127
|
-
if (current !== void 0 && `${current}` === selected) {
|
|
128
|
-
return item;
|
|
129
|
-
}
|
|
130
|
-
}) ?? { value: selected };
|
|
131
|
-
}
|
|
132
|
-
return { value: selected };
|
|
133
|
-
}
|
|
134
|
-
function getCurrentValue(value, entity = VALUE) {
|
|
135
|
-
if (value != null) {
|
|
136
|
-
if (Array.isArray(value) && value.every(isValue)) {
|
|
137
|
-
return value;
|
|
138
|
-
}
|
|
139
|
-
if (isValue(value)) {
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
142
|
-
if (isObject(value)) {
|
|
143
|
-
const result = getValue(value, entity);
|
|
144
|
-
if (isValue(result)) {
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function getValue(value, namespace) {
|
|
151
|
-
const result = extract(value, namespace);
|
|
152
|
-
if (isValue(result)) {
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function getArray(value, namespace) {
|
|
157
|
-
if (Array.isArray(value)) {
|
|
158
|
-
return value;
|
|
159
|
-
}
|
|
160
|
-
const result = extract(value, namespace);
|
|
161
|
-
if (Array.isArray(result)) {
|
|
162
|
-
return result;
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
function extract(value, namespace) {
|
|
167
|
-
if (!namespace || !isObject(value)) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
const keys = namespace.split(".").filter((key) => key !== "");
|
|
171
|
-
if (keys.length === 0) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
let result = value;
|
|
175
|
-
for (const key of keys) {
|
|
176
|
-
if (isObject(result) && key in result) {
|
|
177
|
-
const obj = result;
|
|
178
|
-
result = obj[key];
|
|
179
|
-
} else {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
function toOptions(data, options = {
|
|
186
|
-
description: DESCRIPTION,
|
|
187
|
-
label: LABEL,
|
|
188
|
-
value: VALUE
|
|
189
|
-
}) {
|
|
190
|
-
return data.map((item) => {
|
|
191
|
-
if (isObject(item)) {
|
|
192
|
-
const label = extract(item, options.label);
|
|
193
|
-
const value = extract(item, options.value);
|
|
194
|
-
if (isValue(label) && isValue(value)) {
|
|
195
|
-
const description = extract(item, options.description);
|
|
196
|
-
return {
|
|
197
|
-
label: `${label}`,
|
|
198
|
-
value: `${value}`,
|
|
199
|
-
...isValue(description) && { description: `${description}` }
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return item;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
function getType(value = TYPE_TEXT) {
|
|
207
|
-
const lastSlash = value.lastIndexOf("/");
|
|
208
|
-
const type = lastSlash === -1 ? value : value.slice(lastSlash + 1);
|
|
209
|
-
if (type && type !== INPUT) {
|
|
210
|
-
return type.trim().toLowerCase();
|
|
211
|
-
}
|
|
212
|
-
return TYPE_TEXT;
|
|
213
|
-
}
|
|
214
|
-
function getFormData(formData) {
|
|
215
|
-
const data = {};
|
|
216
|
-
for (const key of formData.keys()) {
|
|
217
|
-
const values = formData.getAll(key);
|
|
218
|
-
data[key] = values.length > 1 ? values : values[0];
|
|
219
|
-
}
|
|
220
|
-
return data;
|
|
221
|
-
}
|
|
222
|
-
function unflatten(data) {
|
|
223
|
-
const result = {};
|
|
224
|
-
for (const key of Object.keys(data)) {
|
|
225
|
-
const parts = key.split(".");
|
|
226
|
-
if (parts.length === 1) {
|
|
227
|
-
result[key] = data[key];
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
let current = result;
|
|
231
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
232
|
-
const part = parts[i];
|
|
233
|
-
const next = parts[i + 1];
|
|
234
|
-
const isNextIndex = REGEX_NUMERIC.test(next);
|
|
235
|
-
if (!(part in current)) {
|
|
236
|
-
current[part] = isNextIndex ? [] : {};
|
|
237
|
-
}
|
|
238
|
-
current = current[part];
|
|
239
|
-
}
|
|
240
|
-
const last = parts[parts.length - 1];
|
|
241
|
-
current[last] = data[key];
|
|
242
|
-
}
|
|
243
|
-
compactArrays(result);
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
function compactArrays(obj) {
|
|
247
|
-
for (const key of Object.keys(obj)) {
|
|
248
|
-
const value = obj[key];
|
|
249
|
-
if (Array.isArray(value)) {
|
|
250
|
-
const compacted = value.filter((item) => item !== void 0);
|
|
251
|
-
for (const item of compacted) {
|
|
252
|
-
if (isObject(item)) {
|
|
253
|
-
compactArrays(item);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
obj[key] = compacted;
|
|
257
|
-
} else if (isObject(value)) {
|
|
258
|
-
compactArrays(value);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// ../luna-core/src/util/string.ts
|
|
264
|
-
var REGEX_MARKDOWN_LINK = /\[([^\]]{1,500})\]\(([^)]{1,2000})\)/g;
|
|
265
|
-
function interpolate(template, values = {}) {
|
|
266
|
-
if (isString(template)) {
|
|
267
|
-
return replacePlaceholders(template, values);
|
|
268
|
-
}
|
|
269
|
-
if (Array.isArray(template)) {
|
|
270
|
-
return template.map((item) => {
|
|
271
|
-
return interpolate(item, values);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
if (isObject(template)) {
|
|
275
|
-
const results = {};
|
|
276
|
-
for (const key in template) {
|
|
277
|
-
results[key] = interpolate(template[key], values);
|
|
278
|
-
}
|
|
279
|
-
return results;
|
|
280
|
-
}
|
|
281
|
-
return template;
|
|
282
|
-
}
|
|
283
|
-
function interpolateIfNeeded(template, values = {}) {
|
|
284
|
-
return isInterpolated(template) ? interpolate(template, values) : template;
|
|
285
|
-
}
|
|
286
|
-
function isInterpolated(template) {
|
|
287
|
-
if (isString(template)) {
|
|
288
|
-
return /{([^}]{1,200})}/.test(template);
|
|
289
|
-
}
|
|
290
|
-
if (Array.isArray(template)) {
|
|
291
|
-
return template.some((item) => isInterpolated(item));
|
|
292
|
-
}
|
|
293
|
-
if (isObject(template)) {
|
|
294
|
-
return Object.values(template).some((value) => isInterpolated(value));
|
|
295
|
-
}
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
function replacePlaceholders(template, values = {}) {
|
|
299
|
-
return template.replace(/{([^}]{1,200})}/g, (match, key) => {
|
|
300
|
-
const value = key.includes(".") ? extract(values, key) : values[key];
|
|
301
|
-
if (isValue(value)) {
|
|
302
|
-
return String(value);
|
|
303
|
-
}
|
|
304
|
-
return match;
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
function formatMarkdown(text, callback) {
|
|
308
|
-
if (!isString(text)) {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
if (!text || text.trim().length === 0) {
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
let match;
|
|
315
|
-
let lastIndex = 0;
|
|
316
|
-
let hasMatch = false;
|
|
317
|
-
const parts = [];
|
|
318
|
-
while ((match = REGEX_MARKDOWN_LINK.exec(text)) !== null) {
|
|
319
|
-
const [fullMatch, linkText, url] = match;
|
|
320
|
-
const index = match.index;
|
|
321
|
-
hasMatch = true;
|
|
322
|
-
if (index > lastIndex) {
|
|
323
|
-
parts.push(text.substring(lastIndex, index));
|
|
324
|
-
}
|
|
325
|
-
const value = callback ? callback(index, url, linkText) : fullMatch;
|
|
326
|
-
parts.push(value);
|
|
327
|
-
lastIndex = index + fullMatch.length;
|
|
328
|
-
}
|
|
329
|
-
if (!hasMatch) {
|
|
330
|
-
return text;
|
|
331
|
-
}
|
|
332
|
-
if (lastIndex < text.length) {
|
|
333
|
-
parts.push(text.substring(lastIndex));
|
|
334
|
-
}
|
|
335
|
-
return parts;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// ../luna-core/src/util/logger.ts
|
|
339
|
-
var logger = {
|
|
340
|
-
error: (...args) => {
|
|
341
|
-
if (isConsoleAvailable() && !isProduction()) {
|
|
342
|
-
getConsole().error("[Luna Form]", ...args);
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
warn: (...args) => {
|
|
346
|
-
if (isConsoleAvailable() && !isProduction()) {
|
|
347
|
-
getConsole().warn("[Luna Form]", ...args);
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
info: (...args) => {
|
|
351
|
-
if (isConsoleAvailable() && !isProduction()) {
|
|
352
|
-
getConsole().info("[Luna Form]", ...args);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
var isConsoleAvailable = () => typeof getConsole() !== "undefined";
|
|
357
|
-
var isProduction = () => false;
|
|
358
|
-
var getConsole = () => globalThis.console;
|
|
359
|
-
|
|
360
|
-
// ../luna-core/src/handle/proxy-event.ts
|
|
361
|
-
function handleProxyEvent(events = [], callback) {
|
|
362
|
-
const values = [];
|
|
363
|
-
const sources = [];
|
|
364
|
-
const states = [];
|
|
365
|
-
for (const event of events) {
|
|
366
|
-
if (event.action === VALUE) {
|
|
367
|
-
values.push(event);
|
|
368
|
-
}
|
|
369
|
-
if (event.action === SOURCE) {
|
|
370
|
-
sources.push(event);
|
|
371
|
-
}
|
|
372
|
-
if (event.action === STATE) {
|
|
373
|
-
states.push(event);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
callback({ sources, states, values });
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// ../luna-core/src/handle/source-event.ts
|
|
380
|
-
function handleSourceEvent(selected = null, events = [], setSource) {
|
|
381
|
-
for (const event of events) {
|
|
382
|
-
const { target, source } = event;
|
|
383
|
-
if (!selected) {
|
|
384
|
-
setSource(target, void 0);
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
if (isDataSource(source)) {
|
|
388
|
-
const newUrl = interpolate(source.url, selected);
|
|
389
|
-
const newBody = source.body ? interpolate(source.body, selected) : source.body;
|
|
390
|
-
setSource(target, {
|
|
391
|
-
...source,
|
|
392
|
-
url: newUrl,
|
|
393
|
-
body: newBody
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// ../luna-core/src/util/operator.ts
|
|
400
|
-
var operators = {
|
|
401
|
-
eq,
|
|
402
|
-
gt,
|
|
403
|
-
gte,
|
|
404
|
-
in: includes,
|
|
405
|
-
lt,
|
|
406
|
-
lte,
|
|
407
|
-
neq,
|
|
408
|
-
nin
|
|
409
|
-
};
|
|
410
|
-
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/;
|
|
411
|
-
var DMY_DATE_REGEX = /^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
412
|
-
function isISODateString(value) {
|
|
413
|
-
return typeof value === "string" && ISO_DATE_REGEX.test(value);
|
|
414
|
-
}
|
|
415
|
-
function isDMYDateString(value) {
|
|
416
|
-
return typeof value === "string" && DMY_DATE_REGEX.test(value);
|
|
417
|
-
}
|
|
418
|
-
function parseDMYDate(value) {
|
|
419
|
-
const match = value.match(DMY_DATE_REGEX);
|
|
420
|
-
if (match) {
|
|
421
|
-
const [, day, month, year, hours, minutes, seconds] = match;
|
|
422
|
-
return new Date(
|
|
423
|
-
Number(year),
|
|
424
|
-
Number(month) - 1,
|
|
425
|
-
Number(day),
|
|
426
|
-
Number(hours ?? 0),
|
|
427
|
-
Number(minutes ?? 0),
|
|
428
|
-
Number(seconds ?? 0)
|
|
429
|
-
).getTime();
|
|
430
|
-
}
|
|
431
|
-
return NaN;
|
|
432
|
-
}
|
|
433
|
-
function toComparableNumber(value) {
|
|
434
|
-
if (isISODateString(value)) {
|
|
435
|
-
return new Date(value).getTime();
|
|
436
|
-
}
|
|
437
|
-
if (isDMYDateString(value)) {
|
|
438
|
-
return parseDMYDate(value);
|
|
439
|
-
}
|
|
440
|
-
return Number(value);
|
|
441
|
-
}
|
|
442
|
-
function eq(current, value) {
|
|
443
|
-
return current === value;
|
|
444
|
-
}
|
|
445
|
-
function neq(current, value) {
|
|
446
|
-
return current !== value;
|
|
447
|
-
}
|
|
448
|
-
function includes(current, value) {
|
|
449
|
-
return Array.isArray(value) && value.includes(String(current));
|
|
450
|
-
}
|
|
451
|
-
function nin(current, value) {
|
|
452
|
-
return Array.isArray(value) && !value.includes(String(current));
|
|
453
|
-
}
|
|
454
|
-
function gt(current, value) {
|
|
455
|
-
return toComparableNumber(current) > toComparableNumber(value);
|
|
456
|
-
}
|
|
457
|
-
function gte(current, value) {
|
|
458
|
-
return toComparableNumber(current) >= toComparableNumber(value);
|
|
459
|
-
}
|
|
460
|
-
function lt(current, value) {
|
|
461
|
-
return toComparableNumber(current) < toComparableNumber(value);
|
|
462
|
-
}
|
|
463
|
-
function lte(current, value) {
|
|
464
|
-
return toComparableNumber(current) <= toComparableNumber(value);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// ../luna-core/src/handle/state-event.ts
|
|
468
|
-
function handleStateEvent(selected = null, events = [], setState) {
|
|
469
|
-
for (const event of events) {
|
|
470
|
-
const { target, state, when } = event;
|
|
471
|
-
const targets = Array.isArray(target) ? target : [target];
|
|
472
|
-
if (!selected) {
|
|
473
|
-
setState(targets);
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
const matches = evaluateCondition(selected, when);
|
|
477
|
-
setState(targets, matches ? state : void 0);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
function evaluateCondition(selected, when) {
|
|
481
|
-
if (when === void 0) {
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
if (isString(when)) {
|
|
485
|
-
return getValue2(selected, VALUE) === when;
|
|
486
|
-
}
|
|
487
|
-
if (isBoolean(when)) {
|
|
488
|
-
return Boolean(getValue2(selected, VALUE)) === when;
|
|
489
|
-
}
|
|
490
|
-
if (Array.isArray(when)) {
|
|
491
|
-
return when.includes(String(getValue2(selected, VALUE)));
|
|
492
|
-
}
|
|
493
|
-
return evaluateOperator(selected, when);
|
|
494
|
-
}
|
|
495
|
-
function evaluateOperator(selected = null, condition) {
|
|
496
|
-
const current = getValue2(selected, condition.field ?? VALUE);
|
|
497
|
-
const { operator = "eq", value } = condition;
|
|
498
|
-
const operation = operators[operator];
|
|
499
|
-
if (operation) {
|
|
500
|
-
return operation(current, value);
|
|
501
|
-
}
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
function getValue2(selected, field) {
|
|
505
|
-
if (isObject(selected)) {
|
|
506
|
-
return extract(selected, field);
|
|
507
|
-
}
|
|
508
|
-
return selected;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// ../luna-core/src/handle/value-event.ts
|
|
512
|
-
function handleValueEvent(selected = null, events = [], setValue) {
|
|
513
|
-
for (const event of events) {
|
|
514
|
-
for (const [target, value] of Object.entries(event.value)) {
|
|
515
|
-
setValue(target, selected ? interpolate(value, selected) : void 0);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// ../luna-core/src/util/is-input.ts
|
|
521
|
-
var isSelectDay = (field) => createTypeChecker(SELECT_DAY)(field);
|
|
522
|
-
var isSelectMonth = (field) => createTypeChecker(SELECT_MONTH)(field);
|
|
523
|
-
var isSelectYear = (field) => createTypeChecker(SELECT_YEAR)(field);
|
|
524
|
-
var isSelectTimezone = (field) => createTypeChecker(SELECT_TIMEZONE)(field);
|
|
525
|
-
var isChipsDays = (field) => createTypeChecker(CHIPS_DAYS)(field);
|
|
526
|
-
var isChipsMonths = (field) => createTypeChecker(CHIPS_MONTHS)(field);
|
|
527
|
-
var isDate = createTypeChecker(INPUT_DATE);
|
|
528
|
-
var isTime = createTypeChecker(INPUT_TIME);
|
|
529
|
-
var isCheckbox = createTypeChecker(CHECKBOX);
|
|
530
|
-
var isChips = createTypeChecker(CHIPS);
|
|
531
|
-
var isRadio = createTypeChecker(RADIO);
|
|
532
|
-
var isInput = createTypeChecker(INPUT);
|
|
533
|
-
var isSelect = createTypeChecker(SELECT);
|
|
534
|
-
var isTextArea = createTypeChecker(TEXTAREA);
|
|
535
|
-
var isText = createTypeChecker(
|
|
536
|
-
TYPE_TEXT,
|
|
537
|
-
TYPE_EMAIL,
|
|
538
|
-
TYPE_PASSWORD,
|
|
539
|
-
TYPE_TEL
|
|
540
|
-
);
|
|
541
|
-
var isEmail = createTypeChecker(INPUT_EMAIL, TYPE_EMAIL);
|
|
542
|
-
var isNumber = createTypeChecker(INPUT_NUMBER, TYPE_NUMBER);
|
|
543
|
-
function isClickable(field) {
|
|
544
|
-
return isRadio(field) || isCheckbox(field);
|
|
545
|
-
}
|
|
546
|
-
function isList(slot) {
|
|
547
|
-
return slot.type === LIST;
|
|
548
|
-
}
|
|
549
|
-
function isColumn(slot) {
|
|
550
|
-
return slot.type === COLUMN;
|
|
551
|
-
}
|
|
552
|
-
function isField(slot) {
|
|
553
|
-
return slot.type !== COLUMN && slot.type !== LIST;
|
|
554
|
-
}
|
|
555
|
-
function isOptions(field) {
|
|
556
|
-
return isSelect(field) || isRadio(field) || isChips(field);
|
|
557
|
-
}
|
|
558
|
-
function isTextable(field) {
|
|
559
|
-
return isInput(field) || isTextArea(field);
|
|
560
|
-
}
|
|
561
|
-
function isValidValue(value) {
|
|
562
|
-
return value !== void 0 && value !== null && value !== "";
|
|
563
|
-
}
|
|
564
|
-
function createTypeChecker(...types) {
|
|
565
|
-
return (field) => {
|
|
566
|
-
const inputType = isString(field.type) ? field.type : void 0;
|
|
567
|
-
if (!inputType) {
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
return types.some((type) => {
|
|
571
|
-
return inputType === type || inputType?.startsWith(`${type}/`);
|
|
572
|
-
});
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// ../luna-core/src/util/build.ts
|
|
577
|
-
function buildOptions(field, values = {}) {
|
|
578
|
-
if (isSelect(field) && field.disabled) {
|
|
579
|
-
const current = field.name ? values?.[field.name] : void 0;
|
|
580
|
-
if (current && isObject(current)) {
|
|
581
|
-
return [current];
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
function buildOrientation(field) {
|
|
586
|
-
if (isRadio(field) || isCheckbox(field)) {
|
|
587
|
-
return true;
|
|
588
|
-
}
|
|
589
|
-
return field.advanced?.horizontal ?? false;
|
|
590
|
-
}
|
|
591
|
-
function buildReverse(field) {
|
|
592
|
-
if (!isCheckbox(field)) {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
return field.advanced?.reverse !== false;
|
|
596
|
-
}
|
|
597
|
-
function buildDisabled(field, disabled) {
|
|
598
|
-
const readonly = field.readonly ?? false;
|
|
599
|
-
return disabled ? disabled : readonly;
|
|
600
|
-
}
|
|
601
|
-
function buildSource(field) {
|
|
602
|
-
if (isRadio(field) || isChips(field) || isSelect(field) && !field.disabled) {
|
|
603
|
-
const source = field.source;
|
|
604
|
-
if (Array.isArray(source) || isObject(source) && !($REF in source)) {
|
|
605
|
-
return source;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// ../luna-core/src/util/date.ts
|
|
611
|
-
import { isValid, parse, format as fnsFormat } from "date-fns";
|
|
612
|
-
var REGEX_DIGITS = /^\d+$/;
|
|
613
|
-
var REF = new Date(2e3, 0, 1);
|
|
614
|
-
var getSupportedTimezones = () => "supportedValuesOf" in Intl ? Intl.supportedValuesOf("timeZone") : [];
|
|
615
|
-
function getMonth() {
|
|
616
|
-
return Array.from({ length: 12 }, (_, i) => ({
|
|
617
|
-
value: (i + 1).toString(),
|
|
618
|
-
label: new Date(0, i).toLocaleString("default", {
|
|
619
|
-
month: "long"
|
|
620
|
-
})
|
|
621
|
-
}));
|
|
622
|
-
}
|
|
623
|
-
function getWeekDays() {
|
|
624
|
-
return Array.from({ length: 7 }, (_, i) => ({
|
|
625
|
-
value: i.toString(),
|
|
626
|
-
label: new Date(2e3, 0, 2 + i).toLocaleString("default", {
|
|
627
|
-
weekday: "long"
|
|
628
|
-
})
|
|
629
|
-
}));
|
|
630
|
-
}
|
|
631
|
-
function getYear(min2, max2) {
|
|
632
|
-
if (max2 >= min2) {
|
|
633
|
-
return Array.from({ length: max2 - min2 + 1 }, (_, i) => {
|
|
634
|
-
const year = min2 + i;
|
|
635
|
-
return {
|
|
636
|
-
value: year.toString(),
|
|
637
|
-
label: year.toString()
|
|
638
|
-
};
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
return [];
|
|
642
|
-
}
|
|
643
|
-
function getCurrentYear() {
|
|
644
|
-
return (/* @__PURE__ */ new Date()).getFullYear();
|
|
645
|
-
}
|
|
646
|
-
function getUserTimezone() {
|
|
647
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
648
|
-
}
|
|
649
|
-
function getTimezoneRegion(tz) {
|
|
650
|
-
const slash = tz.indexOf("/");
|
|
651
|
-
const prefix = slash === -1 ? tz : tz.slice(0, slash);
|
|
652
|
-
return TIMEZONE_REGIONS[prefix] ?? "Other";
|
|
653
|
-
}
|
|
654
|
-
function getTimeZoneName(longNameParts, defaultTimeZone) {
|
|
655
|
-
const fullName = longNameParts.find((part) => {
|
|
656
|
-
return part.type === "timeZoneName";
|
|
657
|
-
})?.value ?? defaultTimeZone;
|
|
658
|
-
return fullName.replace(
|
|
659
|
-
/\s+(?:Standard|Daylight(?: Saving)?|Summer|Winter)\s+Time$/,
|
|
660
|
-
""
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
function getTimezoneInfo(tz, date) {
|
|
664
|
-
const offsetParts = new Intl.DateTimeFormat("en", {
|
|
665
|
-
timeZone: tz,
|
|
666
|
-
timeZoneName: "longOffset"
|
|
667
|
-
}).formatToParts(date);
|
|
668
|
-
const longNameParts = new Intl.DateTimeFormat("en", {
|
|
669
|
-
timeZone: tz,
|
|
670
|
-
timeZoneName: "long"
|
|
671
|
-
}).formatToParts(date);
|
|
672
|
-
const raw = offsetParts.find((part) => {
|
|
673
|
-
return part.type === "timeZoneName";
|
|
674
|
-
})?.value ?? "GMT+00:00";
|
|
675
|
-
const offset = raw.replace("GMT", "UTC");
|
|
676
|
-
const longName = getTimeZoneName(longNameParts, tz);
|
|
677
|
-
return { offset, longName };
|
|
678
|
-
}
|
|
679
|
-
function getTimezoneCity(tz) {
|
|
680
|
-
return tz.slice(tz.lastIndexOf("/") + 1).replace(/_/g, " ");
|
|
681
|
-
}
|
|
682
|
-
function getTimezones() {
|
|
683
|
-
const date = /* @__PURE__ */ new Date();
|
|
684
|
-
const detectedTimezone = getUserTimezone();
|
|
685
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
686
|
-
const detectedCity = getTimezoneCity(detectedTimezone);
|
|
687
|
-
const { offset: detectedOffset, longName: detectedLongName } = getTimezoneInfo(detectedTimezone, date);
|
|
688
|
-
const detectedItem = {
|
|
689
|
-
value: detectedTimezone,
|
|
690
|
-
label: `${detectedCity} - ${detectedLongName} (${detectedOffset})`
|
|
691
|
-
};
|
|
692
|
-
for (const tz of getSupportedTimezones()) {
|
|
693
|
-
if (tz === detectedTimezone) {
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
const city = getTimezoneCity(tz);
|
|
697
|
-
const { offset, longName } = getTimezoneInfo(tz, date);
|
|
698
|
-
const item = {
|
|
699
|
-
value: tz,
|
|
700
|
-
label: `${city} - ${longName} (${offset})`
|
|
701
|
-
};
|
|
702
|
-
const region = getTimezoneRegion(tz);
|
|
703
|
-
if (region === "Other") {
|
|
704
|
-
continue;
|
|
705
|
-
}
|
|
706
|
-
const existing = groupMap.get(region);
|
|
707
|
-
if (existing) {
|
|
708
|
-
existing.push(item);
|
|
709
|
-
} else {
|
|
710
|
-
groupMap.set(region, [item]);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
for (const items of groupMap.values()) {
|
|
714
|
-
items.sort((a, b) => a.label.localeCompare(b.label));
|
|
715
|
-
}
|
|
716
|
-
const sortedGroups = Array.from(groupMap.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([label, items]) => ({ label, items }));
|
|
717
|
-
return [{ label: "Suggested", items: [detectedItem] }, ...sortedGroups];
|
|
718
|
-
}
|
|
719
|
-
function getConvert(value, current) {
|
|
720
|
-
if (typeof value === "number") {
|
|
721
|
-
return value;
|
|
722
|
-
}
|
|
723
|
-
const now2 = current ?? getCurrentYear();
|
|
724
|
-
const trimmed = value.trim().toLowerCase();
|
|
725
|
-
if (trimmed.startsWith("current")) {
|
|
726
|
-
const match = trimmed.match(/^current([+-])(\d+)$/);
|
|
727
|
-
if (match) {
|
|
728
|
-
const [, operator, offsetStr] = match;
|
|
729
|
-
const offset = parseInt(offsetStr, 10);
|
|
730
|
-
if (!isNaN(offset)) {
|
|
731
|
-
return operator === "+" ? now2 + offset : now2 - offset;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
return now2;
|
|
735
|
-
}
|
|
736
|
-
if (REGEX_DIGITS.test(trimmed)) {
|
|
737
|
-
return parseInt(trimmed, 10);
|
|
738
|
-
}
|
|
739
|
-
return now2;
|
|
740
|
-
}
|
|
741
|
-
function toNativeDate(value, fromFormat) {
|
|
742
|
-
if (!value) {
|
|
743
|
-
return "";
|
|
744
|
-
}
|
|
745
|
-
try {
|
|
746
|
-
const date = parse(value, fromFormat, REF);
|
|
747
|
-
return isValid(date) ? fnsFormat(date, "yyyy-MM-dd") : "";
|
|
748
|
-
} catch {
|
|
749
|
-
return "";
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
function toNativeTime(value, fromFormat) {
|
|
753
|
-
if (!value) {
|
|
754
|
-
return "";
|
|
755
|
-
}
|
|
756
|
-
try {
|
|
757
|
-
const date = parse(value, fromFormat, REF);
|
|
758
|
-
return isValid(date) ? fnsFormat(date, "HH:mm:ss") : "";
|
|
759
|
-
} catch {
|
|
760
|
-
return "";
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
function fromNativeTime(native, toFormat = "HH:mm") {
|
|
764
|
-
if (!native) {
|
|
765
|
-
return "";
|
|
766
|
-
}
|
|
767
|
-
try {
|
|
768
|
-
const format = native.split(":").length === 3 ? "HH:mm:ss" : "HH:mm";
|
|
769
|
-
const date = parse(native, format, REF);
|
|
770
|
-
return isValid(date) ? fnsFormat(date, toFormat) : "";
|
|
771
|
-
} catch {
|
|
772
|
-
return "";
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
function fromNativeDate(native, toFormat = "MMMM d, yyyy") {
|
|
776
|
-
if (!native) {
|
|
777
|
-
return "";
|
|
778
|
-
}
|
|
779
|
-
try {
|
|
780
|
-
const date = parse(native, "yyyy-MM-dd", REF);
|
|
781
|
-
return isValid(date) ? fnsFormat(date, toFormat) : "";
|
|
782
|
-
} catch {
|
|
783
|
-
return "";
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function getTimeFormat(field) {
|
|
787
|
-
return field.advanced?.format ?? "HH:mm";
|
|
788
|
-
}
|
|
789
|
-
function getDateFormat(field) {
|
|
790
|
-
return field.advanced?.format ?? "MMMM d, yyyy";
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
// ../luna-core/src/helper/input.ts
|
|
794
|
-
var now = getCurrentYear();
|
|
795
|
-
function buildOptionChips(field) {
|
|
796
|
-
if (isChips(field)) {
|
|
797
|
-
return defineOptionChips(field);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
function defineOptionChips(field) {
|
|
801
|
-
if (isChipsDays(field)) {
|
|
802
|
-
return getWeekDays();
|
|
803
|
-
}
|
|
804
|
-
if (isChipsMonths(field)) {
|
|
805
|
-
return getMonth();
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
function buildOptionSelect(field) {
|
|
809
|
-
if (isSelect(field)) {
|
|
810
|
-
return defineOptionSelect(field);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
function defineOptionSelect(select) {
|
|
814
|
-
if (isSelectDay(select)) {
|
|
815
|
-
return getWeekDays();
|
|
816
|
-
}
|
|
817
|
-
if (isSelectMonth(select)) {
|
|
818
|
-
return getMonth();
|
|
819
|
-
}
|
|
820
|
-
if (isSelectYear(select)) {
|
|
821
|
-
const min2 = select.advanced?.length?.min ?? now;
|
|
822
|
-
const max2 = select.advanced?.length?.max ?? now + 5;
|
|
823
|
-
return getYear(getConvert(min2, now), getConvert(max2, now));
|
|
824
|
-
}
|
|
825
|
-
if (isSelectTimezone(select)) {
|
|
826
|
-
return getTimezones();
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
function buildCommon(field, disabled = false) {
|
|
830
|
-
const commonProps = {
|
|
831
|
-
disabled,
|
|
832
|
-
id: field.name,
|
|
833
|
-
name: field.name,
|
|
834
|
-
placeholder: field.placeholder,
|
|
835
|
-
required: field.required
|
|
836
|
-
};
|
|
837
|
-
if (isInput(field)) {
|
|
838
|
-
return {
|
|
839
|
-
...commonProps,
|
|
840
|
-
...defineInput(field)
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
if (isSelect(field)) {
|
|
844
|
-
return {
|
|
845
|
-
...commonProps,
|
|
846
|
-
...defineWithOptions(field, buildOptionSelect)
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
if (isTextArea(field)) {
|
|
850
|
-
return {
|
|
851
|
-
...commonProps,
|
|
852
|
-
...defineTextArea(field)
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
if (isChips(field)) {
|
|
856
|
-
return {
|
|
857
|
-
...commonProps,
|
|
858
|
-
...defineChips(field)
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
return commonProps;
|
|
862
|
-
}
|
|
863
|
-
function defineInput(input) {
|
|
864
|
-
const type = getType(input.type);
|
|
865
|
-
const copy = { ...input, type };
|
|
866
|
-
return {
|
|
867
|
-
...defineTime(input),
|
|
868
|
-
...defineAutoComplete(input),
|
|
869
|
-
...defineNumberLimits(copy),
|
|
870
|
-
...isText(copy) ? defineLength(copy) : {},
|
|
871
|
-
type
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function defineWithOptions(field, builder) {
|
|
875
|
-
const options = builder(field);
|
|
876
|
-
if (options) {
|
|
877
|
-
return { options };
|
|
878
|
-
}
|
|
879
|
-
return {};
|
|
880
|
-
}
|
|
881
|
-
function defineChips(field) {
|
|
882
|
-
const withOptions = defineWithOptions(field, buildOptionChips);
|
|
883
|
-
const multiple = field.advanced?.multiple ?? true;
|
|
884
|
-
return { ...withOptions, multiple };
|
|
885
|
-
}
|
|
886
|
-
function defineTextArea(field) {
|
|
887
|
-
return {
|
|
888
|
-
...defineAutoComplete(field),
|
|
889
|
-
...defineLength(field)
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
function defineAutoComplete(input) {
|
|
893
|
-
const autoComplete = input.advanced?.autocomplete;
|
|
894
|
-
if (autoComplete) {
|
|
895
|
-
return { autoComplete };
|
|
896
|
-
}
|
|
897
|
-
return {};
|
|
898
|
-
}
|
|
899
|
-
function defineNumberLimits(input) {
|
|
900
|
-
if (isNumber(input)) {
|
|
901
|
-
return defineMinMax(input);
|
|
902
|
-
}
|
|
903
|
-
return {};
|
|
904
|
-
}
|
|
905
|
-
function defineTime(field) {
|
|
906
|
-
if (isTime(field)) {
|
|
907
|
-
const format = getTimeFormat(field);
|
|
908
|
-
const withSeconds = format === "HH:mm:ss" || format === "hh:mm:ss a";
|
|
909
|
-
return {
|
|
910
|
-
step: withSeconds ? "1" : "60"
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
return {};
|
|
914
|
-
}
|
|
915
|
-
function defineLength(input) {
|
|
916
|
-
return defineConstraints(input, { min: MIN_LENGTH, max: MAX_LENGTH });
|
|
917
|
-
}
|
|
918
|
-
function defineMinMax(input) {
|
|
919
|
-
return defineConstraints(input, { min: MIN, max: MAX });
|
|
920
|
-
}
|
|
921
|
-
function defineConstraints(input, keys) {
|
|
922
|
-
const result = {};
|
|
923
|
-
const length = input.advanced?.length;
|
|
924
|
-
if (length) {
|
|
925
|
-
if (length.min !== void 0) {
|
|
926
|
-
result[keys.min] = length.min;
|
|
927
|
-
}
|
|
928
|
-
if (length.max !== void 0) {
|
|
929
|
-
result[keys.max] = length.max;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
return result;
|
|
933
|
-
}
|
|
934
|
-
function resolveSource(field, value) {
|
|
935
|
-
const current = buildSource(field);
|
|
936
|
-
if (current) {
|
|
937
|
-
return current;
|
|
938
|
-
}
|
|
939
|
-
return buildOptions(field, value);
|
|
940
|
-
}
|
|
941
|
-
function getInputValue(field, value) {
|
|
942
|
-
const newValue = isObject(value) && field.name in value ? value[field.name] : value;
|
|
943
|
-
const currentValue = getCurrentValue(newValue, field.advanced?.entity);
|
|
944
|
-
if (isTime(field) && isValidValue(currentValue)) {
|
|
945
|
-
return getTimeValue(field, currentValue);
|
|
946
|
-
}
|
|
947
|
-
if (isDate(field) && isValidValue(currentValue)) {
|
|
948
|
-
return getDateValue(field, currentValue);
|
|
949
|
-
}
|
|
950
|
-
return currentValue;
|
|
951
|
-
}
|
|
952
|
-
function getTimeValue(field, currentValue) {
|
|
953
|
-
const format = getTimeFormat(field);
|
|
954
|
-
return isString(currentValue) ? toNativeTime(currentValue, format) : currentValue;
|
|
955
|
-
}
|
|
956
|
-
function mergeOptionsProps(field, commonProps, options) {
|
|
957
|
-
return isOptions(field) && Array.isArray(options) ? { ...commonProps, [OPTIONS]: options } : commonProps;
|
|
958
|
-
}
|
|
959
|
-
function getPreselectedValue(field, commonProps, value) {
|
|
960
|
-
if (field.required && !isValidValue(value)) {
|
|
961
|
-
if (isSelect(field)) {
|
|
962
|
-
if (field.advanced?.preselected !== false && OPTIONS in commonProps) {
|
|
963
|
-
const options = commonProps[OPTIONS];
|
|
964
|
-
if (Array.isArray(options) && options.length === 1) {
|
|
965
|
-
return options[0];
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
return value;
|
|
971
|
-
}
|
|
972
|
-
function getOptions(field, data) {
|
|
973
|
-
if (isOptions(field) && Array.isArray(data)) {
|
|
974
|
-
return toOptions(data, field.advanced?.options);
|
|
975
|
-
}
|
|
976
|
-
return data;
|
|
977
|
-
}
|
|
978
|
-
function prepareInputProps(field, commonProps, data, value) {
|
|
979
|
-
const currentValue = getInputValue(field, value);
|
|
980
|
-
const options = Array.isArray(data) ? getOptions(field, data) : data;
|
|
981
|
-
const commonPropsWithOptions = mergeOptionsProps(field, commonProps, options);
|
|
982
|
-
const defaultValue = getPreselectedValue(
|
|
983
|
-
field,
|
|
984
|
-
commonPropsWithOptions,
|
|
985
|
-
currentValue
|
|
986
|
-
);
|
|
987
|
-
return {
|
|
988
|
-
commonPropsWithOptions,
|
|
989
|
-
defaultValue
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
function prepareInputValue(field, value) {
|
|
993
|
-
if (isCheckbox(field)) {
|
|
994
|
-
return {
|
|
995
|
-
checked: isValidValue(value) ? value : false
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
if (isChips(field)) {
|
|
999
|
-
return { value: Array.isArray(value) ? value : [] };
|
|
1000
|
-
}
|
|
1001
|
-
if (isDate(field)) {
|
|
1002
|
-
if (isString(value) && isValidValue(value)) {
|
|
1003
|
-
return { value: fromNativeDate(value, getDateFormat(field)) };
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
return { value: value ?? "" };
|
|
1007
|
-
}
|
|
1008
|
-
function getDateValue(field, currentValue) {
|
|
1009
|
-
const format = getDateFormat(field);
|
|
1010
|
-
return isString(currentValue) ? toNativeDate(currentValue, format) : currentValue;
|
|
1011
|
-
}
|
|
1012
|
-
function getFormatProps(dateFormat, timeFormat) {
|
|
1013
|
-
const format = dateFormat ?? timeFormat;
|
|
1014
|
-
return format ? { "data-format": format } : {};
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
// ../luna-core/src/util/prepare.ts
|
|
1018
|
-
var REGEX_REF = /^#\/definition\//;
|
|
1019
|
-
function prepare(base = [], definition) {
|
|
1020
|
-
const resolved = resolveRefs(base, definition);
|
|
1021
|
-
return Array.isArray(resolved) ? resolved.filter(filter).sort((a, b) => getOrder(a) - getOrder(b)) : [];
|
|
1022
|
-
}
|
|
1023
|
-
function resolveRefs(base, definition, cache = /* @__PURE__ */ new Map(), visited = /* @__PURE__ */ new WeakSet()) {
|
|
1024
|
-
if (!isDefinition(definition) || !base || typeof base !== "object") {
|
|
1025
|
-
return base;
|
|
1026
|
-
}
|
|
1027
|
-
if (cache.has(base)) {
|
|
1028
|
-
return cache.get(base);
|
|
1029
|
-
}
|
|
1030
|
-
if (visited.has(base)) {
|
|
1031
|
-
return base;
|
|
1032
|
-
}
|
|
1033
|
-
visited.add(base);
|
|
1034
|
-
if (Array.isArray(base)) {
|
|
1035
|
-
return base.map((item) => resolveRefs(item, definition, cache, visited));
|
|
1036
|
-
}
|
|
1037
|
-
if ($REF in base && isString(base[$REF])) {
|
|
1038
|
-
const path = base[$REF].replace(REGEX_REF, "");
|
|
1039
|
-
const resolved = extract(definition, path);
|
|
1040
|
-
if (resolved !== null) {
|
|
1041
|
-
return resolveRefs(resolved, definition, cache, visited);
|
|
1042
|
-
}
|
|
1043
|
-
return base;
|
|
1044
|
-
}
|
|
1045
|
-
const result = {};
|
|
1046
|
-
for (const [key, value] of Object.entries(base)) {
|
|
1047
|
-
result[key] = resolveRefs(value, definition, cache, visited);
|
|
1048
|
-
}
|
|
1049
|
-
visited.delete(base);
|
|
1050
|
-
cache.set(base, result);
|
|
1051
|
-
return result;
|
|
1052
|
-
}
|
|
1053
|
-
function entries(values) {
|
|
1054
|
-
return Object.entries(values ?? {});
|
|
1055
|
-
}
|
|
1056
|
-
function getOrder(item) {
|
|
1057
|
-
return item.order ?? Number.MAX_VALUE;
|
|
1058
|
-
}
|
|
1059
|
-
function isDefinition(definition) {
|
|
1060
|
-
return definition !== void 0 && isObject(definition) && Object.keys(definition).length > 0;
|
|
1061
|
-
}
|
|
1062
|
-
function filter(base) {
|
|
1063
|
-
if (TYPE in base) {
|
|
1064
|
-
return true;
|
|
1065
|
-
}
|
|
1066
|
-
if (Array.isArray(base[FIELDS])) {
|
|
1067
|
-
return base[FIELDS].length > 0;
|
|
1068
|
-
}
|
|
1069
|
-
return true;
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
// ../luna-core/src/util/attributes.ts
|
|
1073
|
-
function getPrefixedAttributes(prefix, record) {
|
|
1074
|
-
const attrs = {};
|
|
1075
|
-
for (const [key, value] of entries(record)) {
|
|
1076
|
-
attrs[`${prefix}-${key}`] = value;
|
|
1077
|
-
}
|
|
1078
|
-
return attrs;
|
|
1079
|
-
}
|
|
1080
|
-
function getAriaAttributes(record) {
|
|
1081
|
-
return getPrefixedAttributes(PREFIX_ARIA, record);
|
|
1082
|
-
}
|
|
1083
|
-
function getDataAttributes(record) {
|
|
1084
|
-
return getPrefixedAttributes(PREFIX_DATA, record);
|
|
1085
|
-
}
|
|
1086
|
-
function buildAriaAttributes(field, errors) {
|
|
1087
|
-
const ariaAttributes = getAriaAttributes(field.advanced?.aria);
|
|
1088
|
-
if (errors && errors.length > 0) {
|
|
1089
|
-
ariaAttributes[ARIA_INVALID] = "true";
|
|
1090
|
-
ariaAttributes[ARIA_ERROR_MESSAGE] = `${field.name}-error`;
|
|
1091
|
-
}
|
|
1092
|
-
return ariaAttributes;
|
|
1093
|
-
}
|
|
1094
|
-
function buildDataAttributes(field) {
|
|
1095
|
-
return getDataAttributes(field.advanced?.data);
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// ../luna-core/src/util/column.ts
|
|
1099
|
-
var cols = {
|
|
1100
|
-
1: "md:grid-cols-1",
|
|
1101
|
-
2: "md:grid-cols-2",
|
|
1102
|
-
3: "md:grid-cols-3"
|
|
1103
|
-
};
|
|
1104
|
-
var span = {
|
|
1105
|
-
1: "md:col-span-1",
|
|
1106
|
-
2: "md:col-span-2",
|
|
1107
|
-
3: "md:col-span-3"
|
|
1108
|
-
};
|
|
1109
|
-
function getColumn(value, defaultCols = 2) {
|
|
1110
|
-
return cols[value && value in cols ? value : defaultCols];
|
|
1111
|
-
}
|
|
1112
|
-
function getSpan(value) {
|
|
1113
|
-
if (value && value in span) {
|
|
1114
|
-
return span[value];
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
// ../luna-core/src/util/list.ts
|
|
1119
|
-
function getInitialCount(list, value) {
|
|
1120
|
-
const min2 = list.advanced?.length?.min ?? 1;
|
|
1121
|
-
if (value) {
|
|
1122
|
-
const data = extract(value, list.name);
|
|
1123
|
-
if (Array.isArray(data)) {
|
|
1124
|
-
return Math.max(data.length, min2);
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
return Math.max(min2, 0);
|
|
1128
|
-
}
|
|
1129
|
-
function isMultiFieldList(list) {
|
|
1130
|
-
if (!Array.isArray(list.fields) || list.fields.length === 0) {
|
|
1131
|
-
return false;
|
|
1132
|
-
}
|
|
1133
|
-
return list.fields.length > 1 || list.fields[0].type === COLUMN;
|
|
1134
|
-
}
|
|
1135
|
-
function getInitialList(list, value) {
|
|
1136
|
-
const count = getInitialCount(list, value);
|
|
1137
|
-
return Array.from({ length: count }, (_, index) => index);
|
|
1138
|
-
}
|
|
1139
|
-
function getLabel(list) {
|
|
1140
|
-
return list.label ?? list.name;
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// ../luna-core/src/util/schema.ts
|
|
1144
|
-
import { z } from "zod";
|
|
1145
|
-
|
|
1146
|
-
// ../luna-core/src/util/translate.ts
|
|
1147
|
-
function translate(key, dictionary) {
|
|
1148
|
-
if (!key) {
|
|
1149
|
-
return "";
|
|
1150
|
-
}
|
|
1151
|
-
if (!dictionary) {
|
|
1152
|
-
return key;
|
|
1153
|
-
}
|
|
1154
|
-
return dictionary[key] ?? key;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
// ../luna-core/src/util/schema.ts
|
|
1158
|
-
var approach = [
|
|
1159
|
-
[isNumber, getNumber],
|
|
1160
|
-
[isEmail, getEmail],
|
|
1161
|
-
[isSelectYear, getYearSchema],
|
|
1162
|
-
[isSelectMonth, getMonthSchema],
|
|
1163
|
-
[isCheckbox, getBoolean],
|
|
1164
|
-
[isRadio, getRadio]
|
|
1165
|
-
];
|
|
1166
|
-
function buildSchema(schemas, fields = [], translations) {
|
|
1167
|
-
const schema = z.object(schemas);
|
|
1168
|
-
if (fields.length === 0) {
|
|
1169
|
-
return schema;
|
|
1170
|
-
}
|
|
1171
|
-
return applyCustomValidation(schema, fields, translations);
|
|
1172
|
-
}
|
|
1173
|
-
function flatten(error) {
|
|
1174
|
-
const results = {};
|
|
1175
|
-
const errors = z.flattenError(error).fieldErrors;
|
|
1176
|
-
for (const [key, value] of Object.entries(errors)) {
|
|
1177
|
-
if (value !== void 0) {
|
|
1178
|
-
results[key] = value;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return results;
|
|
1182
|
-
}
|
|
1183
|
-
function getSchema(input, translations) {
|
|
1184
|
-
for (const [check, getSchema2] of approach) {
|
|
1185
|
-
if (check(input)) {
|
|
1186
|
-
return getSchema2(input, translations);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
return getText(input, translations);
|
|
1190
|
-
}
|
|
1191
|
-
function getEmail(input, translations) {
|
|
1192
|
-
const baseSchema = z.string().trim();
|
|
1193
|
-
if (input.required) {
|
|
1194
|
-
const message = getRequiredMessage(input, translations);
|
|
1195
|
-
const schema = baseSchema.min(1, message).pipe(applyEmail(input, translations));
|
|
1196
|
-
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
1197
|
-
}
|
|
1198
|
-
return baseSchema.pipe(applyEmail(input, translations)).or(z.literal("")).nullable();
|
|
1199
|
-
}
|
|
1200
|
-
function getBoolean(input, translations) {
|
|
1201
|
-
let schema = z.coerce.boolean();
|
|
1202
|
-
if (input.required) {
|
|
1203
|
-
schema = schema.refine((value) => value === true, {
|
|
1204
|
-
message: getRequiredMessage(input, translations)
|
|
1205
|
-
});
|
|
1206
|
-
return z.preprocess((value) => value === null ? false : value, schema);
|
|
1207
|
-
}
|
|
1208
|
-
return schema.nullable();
|
|
1209
|
-
}
|
|
1210
|
-
function getRadio(input, translations) {
|
|
1211
|
-
let schema = z.coerce.string();
|
|
1212
|
-
if (input.required) {
|
|
1213
|
-
schema = schema.min(1, getRequiredMessage(input, translations));
|
|
1214
|
-
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
1215
|
-
}
|
|
1216
|
-
return schema.or(z.literal("")).nullable();
|
|
1217
|
-
}
|
|
1218
|
-
function getText(input, translations) {
|
|
1219
|
-
let schema = z.coerce.string().trim();
|
|
1220
|
-
schema = applyMinAndMax(schema, input, translations);
|
|
1221
|
-
if (input.required) {
|
|
1222
|
-
schema = applyRequired(schema, input, translations);
|
|
1223
|
-
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
1224
|
-
}
|
|
1225
|
-
return schema.nullable();
|
|
1226
|
-
}
|
|
1227
|
-
function getNumber(input, translations) {
|
|
1228
|
-
let schema = z.coerce.number().int();
|
|
1229
|
-
schema = applyMinAndMax(schema, input, translations);
|
|
1230
|
-
if (input.required) {
|
|
1231
|
-
schema = applyRequired(schema, input, translations);
|
|
1232
|
-
return z.preprocess((value) => value === null ? void 0 : value, schema);
|
|
1233
|
-
}
|
|
1234
|
-
return schema.nullable();
|
|
1235
|
-
}
|
|
1236
|
-
function getYearSchema(input, translations) {
|
|
1237
|
-
if (input.required) {
|
|
1238
|
-
return z.preprocess(
|
|
1239
|
-
normalize,
|
|
1240
|
-
z.coerce.number({ message: getRequiredMessage(input, translations) }).int()
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
return z.coerce.number().int().nullable();
|
|
1244
|
-
}
|
|
1245
|
-
function getMonthSchema(input, translations) {
|
|
1246
|
-
const message = getRequiredMessage(input, translations);
|
|
1247
|
-
const schema = z.coerce.number().int().min(1, message).max(12, message);
|
|
1248
|
-
return !input.required ? schema.nullable() : schema;
|
|
1249
|
-
}
|
|
1250
|
-
function normalize(value) {
|
|
1251
|
-
return value === null || value === "" ? void 0 : value;
|
|
1252
|
-
}
|
|
1253
|
-
function applyEmail(input, translations) {
|
|
1254
|
-
const message = input.validation?.email ? translate(input.validation?.email, translations) : void 0;
|
|
1255
|
-
return z.email(message);
|
|
1256
|
-
}
|
|
1257
|
-
function applyMinAndMax(schema, input, translations) {
|
|
1258
|
-
schema = min(schema, input, translations);
|
|
1259
|
-
schema = max(schema, input, translations);
|
|
1260
|
-
return schema;
|
|
1261
|
-
}
|
|
1262
|
-
function applyRequired(schema, input, translations) {
|
|
1263
|
-
const min2 = input.advanced?.length?.min;
|
|
1264
|
-
if (min2 === void 0 || min2 < 1) {
|
|
1265
|
-
return schema.min(1, getRequiredMessage(input, translations));
|
|
1266
|
-
}
|
|
1267
|
-
return schema;
|
|
1268
|
-
}
|
|
1269
|
-
var min = (schema, input, translations) => applyConstraint(schema, input, MIN, translations);
|
|
1270
|
-
var max = (schema, input, translations) => applyConstraint(schema, input, MAX, translations);
|
|
1271
|
-
function applyConstraint(schema, input, method, translations) {
|
|
1272
|
-
const value = input.advanced?.length?.[method];
|
|
1273
|
-
if (value !== void 0) {
|
|
1274
|
-
const message = input.validation?.length?.[method] ? translate(input.validation?.length?.[method], translations) : void 0;
|
|
1275
|
-
return schema[method](value, message);
|
|
1276
|
-
}
|
|
1277
|
-
return schema;
|
|
1278
|
-
}
|
|
1279
|
-
function applyCustomValidation(schema, fields = [], translations) {
|
|
1280
|
-
const rules = getRules(fields);
|
|
1281
|
-
if (rules.length === 0) {
|
|
1282
|
-
return schema;
|
|
1283
|
-
}
|
|
1284
|
-
return schema.superRefine((data, context) => {
|
|
1285
|
-
for (const { name, rule } of rules) {
|
|
1286
|
-
if (!evaluate(data, name, rule)) {
|
|
1287
|
-
const message = translate(rule.message, translations);
|
|
1288
|
-
context.addIssue({
|
|
1289
|
-
code: "custom",
|
|
1290
|
-
message,
|
|
1291
|
-
path: [name]
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
function evaluate(data, name, rule) {
|
|
1298
|
-
const operator = rule.operator ?? "eq";
|
|
1299
|
-
const operation = operators[operator];
|
|
1300
|
-
if (operation) {
|
|
1301
|
-
return operation(data[name], data[rule.field]);
|
|
1302
|
-
}
|
|
1303
|
-
return false;
|
|
1304
|
-
}
|
|
1305
|
-
function getRules(fields) {
|
|
1306
|
-
const results = [];
|
|
1307
|
-
for (const field of fields) {
|
|
1308
|
-
const custom = field.validation?.custom;
|
|
1309
|
-
if (!custom) {
|
|
1310
|
-
continue;
|
|
1311
|
-
}
|
|
1312
|
-
const rules = Array.isArray(custom) ? custom : [custom];
|
|
1313
|
-
for (const rule of rules) {
|
|
1314
|
-
results.push({ name: field.name, rule });
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
return results;
|
|
1318
|
-
}
|
|
1319
|
-
function validateCustom(value, rules, getValue3, translations) {
|
|
1320
|
-
const errors = [];
|
|
1321
|
-
const collections = Array.isArray(rules) ? rules : [rules];
|
|
1322
|
-
for (const rule of collections) {
|
|
1323
|
-
const operator = rule.operator ?? "eq";
|
|
1324
|
-
const operation = operators[operator];
|
|
1325
|
-
if (operation && !operation(value, getValue3(rule.field))) {
|
|
1326
|
-
if (rule.message) {
|
|
1327
|
-
const message = translate(rule.message, translations);
|
|
1328
|
-
errors.push(message);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
return errors;
|
|
1333
|
-
}
|
|
1334
|
-
function getRequiredMessage(input, translations) {
|
|
1335
|
-
return input.validation?.required ? translate(input.validation?.required, translations) : void 0;
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
// ../luna-core/src/util/url.ts
|
|
1339
|
-
function matchRemotePattern(urlStr, patterns) {
|
|
1340
|
-
if (!patterns || !isExternalUrl(urlStr)) {
|
|
1341
|
-
return true;
|
|
1342
|
-
}
|
|
1343
|
-
if (patterns.length === 0) {
|
|
1344
|
-
return false;
|
|
1345
|
-
}
|
|
1346
|
-
try {
|
|
1347
|
-
const url = new URL(urlStr);
|
|
1348
|
-
const protocol = url.protocol.replace(":", "");
|
|
1349
|
-
const hostname = url.hostname;
|
|
1350
|
-
const port = url.port || getPort(protocol);
|
|
1351
|
-
return patterns.some((pattern) => {
|
|
1352
|
-
if (pattern.protocol && pattern.protocol !== protocol) {
|
|
1353
|
-
return false;
|
|
1354
|
-
}
|
|
1355
|
-
if (pattern.hostname && pattern.hostname !== hostname) {
|
|
1356
|
-
return false;
|
|
1357
|
-
}
|
|
1358
|
-
if (pattern.port !== void 0 && String(pattern.port) !== port) {
|
|
1359
|
-
return false;
|
|
1360
|
-
}
|
|
1361
|
-
return true;
|
|
1362
|
-
});
|
|
1363
|
-
} catch {
|
|
1364
|
-
return false;
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
function getPort(protocol) {
|
|
1368
|
-
return protocol === "https" ? "443" : "80";
|
|
1369
|
-
}
|
|
1370
|
-
function isExternalUrl(url) {
|
|
1371
|
-
return /^(https?:)?\/\//.test(url);
|
|
1372
|
-
}
|
|
1373
|
-
function mergeUrl(baseUrl, targetUrl) {
|
|
1374
|
-
try {
|
|
1375
|
-
if (!baseUrl) {
|
|
1376
|
-
return targetUrl;
|
|
1377
|
-
}
|
|
1378
|
-
if (!targetUrl) {
|
|
1379
|
-
return baseUrl;
|
|
1380
|
-
}
|
|
1381
|
-
const url1 = new URL(baseUrl, COMMON_URL);
|
|
1382
|
-
const url2 = new URL(targetUrl, COMMON_URL);
|
|
1383
|
-
url2.searchParams.forEach((value, key) => {
|
|
1384
|
-
url1.searchParams.set(key, value);
|
|
1385
|
-
});
|
|
1386
|
-
const result = url1.toString();
|
|
1387
|
-
return baseUrl.startsWith("/") || !baseUrl.includes("://") ? result.replace(COMMON_URL, "") : result;
|
|
1388
|
-
} catch {
|
|
1389
|
-
return targetUrl || baseUrl;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
// ../luna-core/src/util/source.ts
|
|
1394
|
-
function mergeSource(sources) {
|
|
1395
|
-
if (!Array.isArray(sources) || sources.length === 0) {
|
|
1396
|
-
return null;
|
|
1397
|
-
}
|
|
1398
|
-
return sources.reduce((previous, current) => {
|
|
1399
|
-
const url = mergeUrl(previous.url, current.url);
|
|
1400
|
-
const body = getBody(previous, current);
|
|
1401
|
-
const headers = getHeaders(previous, current);
|
|
1402
|
-
return {
|
|
1403
|
-
...previous,
|
|
1404
|
-
...current,
|
|
1405
|
-
url,
|
|
1406
|
-
body,
|
|
1407
|
-
headers
|
|
1408
|
-
};
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
|
-
function getBody(previous, current) {
|
|
1412
|
-
if (isObject(current.body) && isObject(previous?.body)) {
|
|
1413
|
-
return {
|
|
1414
|
-
...previous.body,
|
|
1415
|
-
...current.body
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
return current.body ?? previous?.body;
|
|
1419
|
-
}
|
|
1420
|
-
function getHeaders(previous, current) {
|
|
1421
|
-
if (isObject(current.headers) && isObject(previous?.headers)) {
|
|
1422
|
-
return {
|
|
1423
|
-
...previous.headers,
|
|
1424
|
-
...current.headers
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
return current.headers ?? previous?.headers;
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
// ../luna-core/src/util/style.ts
|
|
1431
|
-
function mergeStyle(globalStyle, localStyle) {
|
|
1432
|
-
return { ...globalStyle, ...localStyle };
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
// src/lib/string.tsx
|
|
1436
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1437
|
-
function formatMarkdown2(text) {
|
|
1438
|
-
return formatMarkdown(
|
|
1439
|
-
text,
|
|
1440
|
-
(index, url, text2) => {
|
|
1441
|
-
return /* @__PURE__ */ jsx4(
|
|
1442
|
-
"a",
|
|
1443
|
-
{
|
|
1444
|
-
className: "underline",
|
|
1445
|
-
href: url,
|
|
1446
|
-
rel: "noopener noreferrer",
|
|
1447
|
-
target: "_blank",
|
|
1448
|
-
children: text2
|
|
1449
|
-
},
|
|
1450
|
-
`${url}-${index}`
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
// src/component/field/field-set-advanced.tsx
|
|
1457
|
-
import { useCallback, useState } from "react";
|
|
1458
|
-
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
1459
|
-
function FieldSetAdvanced(props) {
|
|
1460
|
-
const { fields = [] } = props.section;
|
|
1461
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
1462
|
-
const handleOpen = useCallback(() => setIsOpen((previous) => !previous), []);
|
|
1463
|
-
return /* @__PURE__ */ jsxs(
|
|
1464
|
-
"fieldset",
|
|
1465
|
-
{
|
|
1466
|
-
"data-slot": "field-set",
|
|
1467
|
-
"data-advanced": "true",
|
|
1468
|
-
"data-expanded": isOpen,
|
|
1469
|
-
"data-empty": fields.length === 0,
|
|
1470
|
-
className: "flex flex-col",
|
|
1471
|
-
id: props.section.id?.toString(),
|
|
1472
|
-
children: [
|
|
1473
|
-
/* @__PURE__ */ jsx5("legend", { children: /* @__PURE__ */ jsxs(
|
|
1474
|
-
"button",
|
|
1475
|
-
{
|
|
1476
|
-
className: "flex cursor-pointer items-center gap-2 text-base font-medium text-slate-600 dark:text-slate-400",
|
|
1477
|
-
onClick: handleOpen,
|
|
1478
|
-
type: "button",
|
|
1479
|
-
children: [
|
|
1480
|
-
/* @__PURE__ */ jsx5(ChevronIcon, { expanded: isOpen }),
|
|
1481
|
-
/* @__PURE__ */ jsx5("span", { children: formatMarkdown2(props.section.title) })
|
|
1482
|
-
]
|
|
1483
|
-
}
|
|
1484
|
-
) }),
|
|
1485
|
-
/* @__PURE__ */ jsx5(Collapsible, { visible: isOpen, children: /* @__PURE__ */ jsxs(
|
|
1486
|
-
"div",
|
|
1487
|
-
{
|
|
1488
|
-
className: "mt-3 ml-1.5 flex flex-col gap-4 border-l-2 border-slate-300 pl-4 dark:border-slate-600",
|
|
1489
|
-
"data-slot": "field-set-content",
|
|
1490
|
-
children: [
|
|
1491
|
-
props.section.description && /* @__PURE__ */ jsx5("p", { className: "text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.section.description) }),
|
|
1492
|
-
props.group
|
|
1493
|
-
]
|
|
1494
|
-
}
|
|
1495
|
-
) })
|
|
1496
|
-
]
|
|
1497
|
-
}
|
|
1498
|
-
);
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
// src/component/legend.tsx
|
|
1502
|
-
import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1503
|
-
function Legend(props) {
|
|
1504
|
-
const content = /* @__PURE__ */ jsxs2("div", { className: "flex flex-col", children: [
|
|
1505
|
-
props.title && /* @__PURE__ */ jsx6("legend", { className: "mb-3 font-medium text-slate-800 dark:text-slate-200", children: formatMarkdown2(props.title) }),
|
|
1506
|
-
props.description && /* @__PURE__ */ jsx6("p", { className: "-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400", children: formatMarkdown2(props.description) })
|
|
1507
|
-
] });
|
|
1508
|
-
if (props.step) {
|
|
1509
|
-
return /* @__PURE__ */ jsxs2("div", { className: "flex flex-row items-start gap-4", children: [
|
|
1510
|
-
/* @__PURE__ */ jsx6("div", { className: "bg-primary text-primary-foreground flex h-6 w-6 shrink-0 items-center justify-center rounded-full", children: /* @__PURE__ */ jsx6("span", { className: "text-sm font-bold", children: props.step }) }),
|
|
1511
|
-
content
|
|
1512
|
-
] });
|
|
1513
|
-
}
|
|
1514
|
-
return content;
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
// src/component/field/field-set-base.tsx
|
|
1518
|
-
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1519
|
-
function FieldSetBase(props) {
|
|
1520
|
-
return /* @__PURE__ */ jsxs3(
|
|
1521
|
-
"fieldset",
|
|
1522
|
-
{
|
|
1523
|
-
className: "flex flex-col data-[empty=false]:gap-6",
|
|
1524
|
-
"data-empty": props.empty,
|
|
1525
|
-
"data-slot": "field-set",
|
|
1526
|
-
id: props.id,
|
|
1527
|
-
children: [
|
|
1528
|
-
/* @__PURE__ */ jsx7(
|
|
1529
|
-
Legend,
|
|
1530
|
-
{
|
|
1531
|
-
description: props.description,
|
|
1532
|
-
step: props.step,
|
|
1533
|
-
title: props.title
|
|
1534
|
-
}
|
|
1535
|
-
),
|
|
1536
|
-
props.children
|
|
1537
|
-
]
|
|
1538
|
-
}
|
|
1539
|
-
);
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
// src/component/group.tsx
|
|
1543
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1544
|
-
function Group(props) {
|
|
1545
|
-
return /* @__PURE__ */ jsx8(
|
|
1546
|
-
"div",
|
|
1547
|
-
{
|
|
1548
|
-
"data-slot": "field-group",
|
|
1549
|
-
"data-compact": props.compact,
|
|
1550
|
-
className: "flex w-full flex-col gap-8 data-[compact=true]:gap-3",
|
|
1551
|
-
children: props.children
|
|
1552
|
-
}
|
|
1553
|
-
);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
// src/component/field/field-set.tsx
|
|
1557
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1558
|
-
function FieldSet(props) {
|
|
1559
|
-
const { fields = [] } = props.section;
|
|
1560
|
-
const step = props.advanced?.step ? props.step : void 0;
|
|
1561
|
-
const { compact } = mergeStyle(props.style, {
|
|
1562
|
-
compact: props.section.advanced?.compact
|
|
1563
|
-
});
|
|
1564
|
-
const group = /* @__PURE__ */ jsx9(Group, { compact, children: props.children });
|
|
1565
|
-
if (!props.section.title && !props.section.description) {
|
|
1566
|
-
return group;
|
|
1567
|
-
}
|
|
1568
|
-
if (props.section.advanced?.collapsible) {
|
|
1569
|
-
return /* @__PURE__ */ jsx9(FieldSetAdvanced, { section: props.section, group });
|
|
1570
|
-
}
|
|
1571
|
-
return /* @__PURE__ */ jsx9(
|
|
1572
|
-
FieldSetBase,
|
|
1573
|
-
{
|
|
1574
|
-
description: props.section.description,
|
|
1575
|
-
empty: fields.length === 0,
|
|
1576
|
-
id: props.section.id?.toString(),
|
|
1577
|
-
step,
|
|
1578
|
-
title: props.section.title,
|
|
1579
|
-
children: group
|
|
1580
|
-
}
|
|
1581
|
-
);
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
// src/component/separator.tsx
|
|
1585
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1586
|
-
function Separator() {
|
|
1587
|
-
return /* @__PURE__ */ jsx10("div", { "data-slot": "field-separator", className: "relative -my-2 h-5 text-sm", children: /* @__PURE__ */ jsx10("div", { className: "absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800" }) });
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
// src/client/component/guard/visibility-guard.tsx
|
|
1591
|
-
import { useAtomValue } from "jotai";
|
|
1592
|
-
|
|
1593
|
-
// src/client/lib/store-helper.ts
|
|
1594
|
-
import { atom } from "jotai";
|
|
1595
|
-
import { atomFamily } from "jotai-family";
|
|
1596
|
-
import { deepEqual } from "fast-equals";
|
|
1597
|
-
function omitKey(obj, key) {
|
|
1598
|
-
const { [key]: _removed, ...rest } = obj;
|
|
1599
|
-
return rest;
|
|
1600
|
-
}
|
|
1601
|
-
function createRecordAtomFamily(baseAtom) {
|
|
1602
|
-
return atomFamily(
|
|
1603
|
-
(name) => atom(
|
|
1604
|
-
(get) => {
|
|
1605
|
-
return get(baseAtom)[name] ?? void 0;
|
|
1606
|
-
},
|
|
1607
|
-
(get, set, newValue) => {
|
|
1608
|
-
const current = get(baseAtom);
|
|
1609
|
-
if (newValue !== void 0 && newValue !== null) {
|
|
1610
|
-
const currentValue = current[name];
|
|
1611
|
-
if (!deepEqual(currentValue, newValue)) {
|
|
1612
|
-
set(baseAtom, { ...current, [name]: newValue });
|
|
1613
|
-
}
|
|
1614
|
-
} else if (name in current) {
|
|
1615
|
-
set(baseAtom, omitKey(current, name));
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
)
|
|
1619
|
-
);
|
|
1620
|
-
}
|
|
1621
|
-
function createClearAllAtom(baseAtom) {
|
|
1622
|
-
return atom(null, (get, set) => {
|
|
1623
|
-
const current = get(baseAtom);
|
|
1624
|
-
if (current && Object.keys(current).length > 0) {
|
|
1625
|
-
set(baseAtom, {});
|
|
1626
|
-
}
|
|
1627
|
-
});
|
|
1628
|
-
}
|
|
1629
|
-
function createClearAtom(baseAtom) {
|
|
1630
|
-
return atom(null, (get, set, names) => {
|
|
1631
|
-
const current = get(baseAtom);
|
|
1632
|
-
const next = { ...current };
|
|
1633
|
-
let hasChanges = false;
|
|
1634
|
-
for (const name of names) {
|
|
1635
|
-
if (name in next) {
|
|
1636
|
-
delete next[name];
|
|
1637
|
-
hasChanges = true;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (hasChanges) {
|
|
1641
|
-
set(baseAtom, next);
|
|
1642
|
-
}
|
|
1643
|
-
});
|
|
1644
|
-
}
|
|
1645
|
-
function createBulkReportAtom(baseAtom) {
|
|
1646
|
-
return atom(null, (get, set, newValue) => {
|
|
1647
|
-
const current = get(baseAtom);
|
|
1648
|
-
if (!deepEqual(current, newValue)) {
|
|
1649
|
-
set(baseAtom, newValue);
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
}
|
|
1653
|
-
function createNestedRecordAtomFamily(baseAtom, options = {}) {
|
|
1654
|
-
const { merge: merge2, validateTarget } = options;
|
|
1655
|
-
return atomFamily(
|
|
1656
|
-
(contributorName) => atom(
|
|
1657
|
-
(get) => {
|
|
1658
|
-
const current = get(baseAtom)[contributorName];
|
|
1659
|
-
if (current && merge2) {
|
|
1660
|
-
return merge2(Object.values(current));
|
|
1661
|
-
}
|
|
1662
|
-
return void 0;
|
|
1663
|
-
},
|
|
1664
|
-
(get, set, target, value) => {
|
|
1665
|
-
if (validateTarget && !validateTarget(target)) {
|
|
1666
|
-
return;
|
|
1667
|
-
}
|
|
1668
|
-
const current = get(baseAtom);
|
|
1669
|
-
const targetContributions = { ...current[target] ?? {} };
|
|
1670
|
-
if (value !== void 0 && value !== null) {
|
|
1671
|
-
const currentContribution = targetContributions[contributorName];
|
|
1672
|
-
if (!currentContribution || !deepEqual(currentContribution, value)) {
|
|
1673
|
-
targetContributions[contributorName] = value;
|
|
1674
|
-
set(baseAtom, {
|
|
1675
|
-
...current,
|
|
1676
|
-
[target]: targetContributions
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
} else if (contributorName in targetContributions) {
|
|
1680
|
-
delete targetContributions[contributorName];
|
|
1681
|
-
if (Object.keys(targetContributions).length === 0) {
|
|
1682
|
-
set(baseAtom, omitKey(current, target));
|
|
1683
|
-
} else {
|
|
1684
|
-
set(baseAtom, {
|
|
1685
|
-
...current,
|
|
1686
|
-
[target]: targetContributions
|
|
1687
|
-
});
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
)
|
|
1692
|
-
);
|
|
1693
|
-
}
|
|
1694
|
-
function createNestedClearAtom(baseAtom) {
|
|
1695
|
-
return atom(null, (get, set, contributorNames) => {
|
|
1696
|
-
const current = get(baseAtom);
|
|
1697
|
-
const next = { ...current };
|
|
1698
|
-
let hasChanges = false;
|
|
1699
|
-
for (const name of contributorNames) {
|
|
1700
|
-
if (name in next) {
|
|
1701
|
-
delete next[name];
|
|
1702
|
-
hasChanges = true;
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
for (const target in next) {
|
|
1706
|
-
const targetContributions = { ...next[target] };
|
|
1707
|
-
let targetChanged = false;
|
|
1708
|
-
for (const contributorName of contributorNames) {
|
|
1709
|
-
if (contributorName in targetContributions) {
|
|
1710
|
-
delete targetContributions[contributorName];
|
|
1711
|
-
targetChanged = true;
|
|
1712
|
-
hasChanges = true;
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
if (targetChanged) {
|
|
1716
|
-
if (Object.keys(targetContributions).length === 0) {
|
|
1717
|
-
delete next[target];
|
|
1718
|
-
} else {
|
|
1719
|
-
next[target] = targetContributions;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
if (hasChanges) {
|
|
1724
|
-
set(baseAtom, next);
|
|
1725
|
-
}
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
function createAtomStore(initialValue = {}) {
|
|
1729
|
-
const baseAtom = atom(initialValue);
|
|
1730
|
-
return {
|
|
1731
|
-
atom: baseAtom,
|
|
1732
|
-
clearAll: createClearAllAtom(baseAtom),
|
|
1733
|
-
clear: createClearAtom(baseAtom),
|
|
1734
|
-
bulkReport: createBulkReportAtom(baseAtom),
|
|
1735
|
-
report: createRecordAtomFamily(baseAtom)
|
|
1736
|
-
};
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
// src/client/lib/state-store.ts
|
|
1740
|
-
var store = createAtomStore();
|
|
1741
|
-
var fieldStateAtom = store.atom;
|
|
1742
|
-
var reportFieldStateAtom = store.report;
|
|
1743
|
-
|
|
1744
|
-
// src/client/component/guard/visibility-guard.tsx
|
|
1745
|
-
function isColumnHidden(column, states) {
|
|
1746
|
-
return column.fields.every((field) => isFieldHidden(field, states));
|
|
1747
|
-
}
|
|
1748
|
-
function isFieldHidden(field, states) {
|
|
1749
|
-
return states[field.name]?.hidden ?? field.hidden ?? false;
|
|
1750
|
-
}
|
|
1751
|
-
function isEntryHidden(entry, states) {
|
|
1752
|
-
return isColumn(entry) ? isColumnHidden(entry, states) : isFieldHidden(entry, states);
|
|
1753
|
-
}
|
|
1754
|
-
function VisibilityGuard(props) {
|
|
1755
|
-
const states = useAtomValue(fieldStateAtom);
|
|
1756
|
-
if (props.container) {
|
|
1757
|
-
const hidden = states[props.container.name]?.hidden ?? props.container.hidden ?? false;
|
|
1758
|
-
if (hidden) {
|
|
1759
|
-
return null;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
if (props.fields.length === 0) {
|
|
1763
|
-
return null;
|
|
1764
|
-
}
|
|
1765
|
-
const allHidden = props.fields.every((entry) => isEntryHidden(entry, states));
|
|
1766
|
-
if (allHidden) {
|
|
1767
|
-
return null;
|
|
1768
|
-
}
|
|
1769
|
-
return props.children;
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
// src/component/form.tsx
|
|
1773
|
-
import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1774
|
-
function Form(props) {
|
|
1775
|
-
const sections = prepare(props.sections, props.definition);
|
|
1776
|
-
return /* @__PURE__ */ jsx11("div", { className: "h-full w-full", children: /* @__PURE__ */ jsx11("form", { noValidate: props.noValidate, action: props.action, children: /* @__PURE__ */ jsxs4(Group, { children: [
|
|
1777
|
-
sections.map((section, index) => /* @__PURE__ */ jsxs4(
|
|
1778
|
-
VisibilityGuard,
|
|
1779
|
-
{
|
|
1780
|
-
fields: section.fields ?? [],
|
|
1781
|
-
children: [
|
|
1782
|
-
/* @__PURE__ */ jsx11(
|
|
1783
|
-
FieldSet,
|
|
1784
|
-
{
|
|
1785
|
-
advanced: props.advanced,
|
|
1786
|
-
section,
|
|
1787
|
-
step: index + 1,
|
|
1788
|
-
style: props.config.style,
|
|
1789
|
-
children: props.children({
|
|
1790
|
-
disabled: props.readOnly,
|
|
1791
|
-
fields: section.fields
|
|
1792
|
-
})
|
|
1793
|
-
}
|
|
1794
|
-
),
|
|
1795
|
-
section.advanced?.separator && /* @__PURE__ */ jsx11(Separator, {})
|
|
1796
|
-
]
|
|
1797
|
-
},
|
|
1798
|
-
`key-${section.id}-${index}`
|
|
1799
|
-
)),
|
|
1800
|
-
props.control && /* @__PURE__ */ jsx11(Control, { isPending: props.isPending, children: props.control })
|
|
1801
|
-
] }) }) });
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
// src/component/description.tsx
|
|
1805
|
-
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
1806
|
-
function Description(props) {
|
|
1807
|
-
return /* @__PURE__ */ jsx12("p", { className: "-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400", children: props.children });
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
// src/component/formatted-description.tsx
|
|
1811
|
-
import { useState as useState2 } from "react";
|
|
1812
|
-
import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1813
|
-
function FormattedDescription(props) {
|
|
1814
|
-
const interpolateOpts = {
|
|
1815
|
-
context: props.context,
|
|
1816
|
-
env: props.config?.env
|
|
1817
|
-
};
|
|
1818
|
-
const [isExpanded, setIsExpanded] = useState2(() => {
|
|
1819
|
-
if (isObject(props.text) && "collapsed" in props.text) {
|
|
1820
|
-
return !props.text.collapsed;
|
|
1821
|
-
}
|
|
1822
|
-
return true;
|
|
1823
|
-
});
|
|
1824
|
-
const handleExpandToggle = () => setIsExpanded((previous) => !previous);
|
|
1825
|
-
const title = isObject(props.text) && isString(props.text.title) ? formatMarkdown2(
|
|
1826
|
-
translate(
|
|
1827
|
-
interpolateIfNeeded(props.text.title, interpolateOpts),
|
|
1828
|
-
props.translations
|
|
1829
|
-
)
|
|
1830
|
-
) : void 0;
|
|
1831
|
-
const message = formatMarkdown2(
|
|
1832
|
-
translate(
|
|
1833
|
-
interpolateIfNeeded(
|
|
1834
|
-
isString(props.text) ? props.text : props.text?.message,
|
|
1835
|
-
interpolateOpts
|
|
1836
|
-
),
|
|
1837
|
-
props.translations
|
|
1838
|
-
)
|
|
1839
|
-
);
|
|
1840
|
-
if (message) {
|
|
1841
|
-
return /* @__PURE__ */ jsxs5("div", { className: "flex flex-col gap-2", children: [
|
|
1842
|
-
title && /* @__PURE__ */ jsxs5(
|
|
1843
|
-
"button",
|
|
1844
|
-
{
|
|
1845
|
-
className: "flex items-center gap-1 text-left text-xs font-medium text-slate-700 hover:text-slate-900 dark:text-slate-300 dark:hover:text-slate-100",
|
|
1846
|
-
onClick: handleExpandToggle,
|
|
1847
|
-
type: "button",
|
|
1848
|
-
children: [
|
|
1849
|
-
title,
|
|
1850
|
-
/* @__PURE__ */ jsx13(ChevronIcon, { expanded: isExpanded })
|
|
1851
|
-
]
|
|
1852
|
-
}
|
|
1853
|
-
),
|
|
1854
|
-
isExpanded && /* @__PURE__ */ jsx13(Description, { children: message })
|
|
1855
|
-
] });
|
|
1856
|
-
}
|
|
1857
|
-
return null;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
// src/component/label.tsx
|
|
1861
|
-
import { twMerge } from "tailwind-merge";
|
|
1862
|
-
import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1863
|
-
function Label(props) {
|
|
1864
|
-
const showOptionalLabel = props.style?.showOptionalLabel ?? true;
|
|
1865
|
-
const normal = isRadio(props.field) || isCheckbox(props.field);
|
|
1866
|
-
return /* @__PURE__ */ jsxs6(
|
|
1867
|
-
"label",
|
|
1868
|
-
{
|
|
1869
|
-
"data-slot": "field-label",
|
|
1870
|
-
"data-normal": normal,
|
|
1871
|
-
className: twMerge(
|
|
1872
|
-
"flex w-fit items-center gap-2 text-sm leading-snug font-medium select-none",
|
|
1873
|
-
"data-[normal=true]:font-normal",
|
|
1874
|
-
"group-data-[readonly=true]:cursor-not-allowed group-data-[readonly=true]:opacity-50"
|
|
1875
|
-
),
|
|
1876
|
-
htmlFor: props.field.name,
|
|
1877
|
-
children: [
|
|
1878
|
-
props.children,
|
|
1879
|
-
showOptionalLabel && !props.field.required && /* @__PURE__ */ jsx14("span", { className: "text-sm text-slate-600 dark:text-slate-400", children: translate("(Optional)", props.translations) })
|
|
1880
|
-
]
|
|
1881
|
-
}
|
|
1882
|
-
);
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
// src/component/input-label.tsx
|
|
1886
|
-
import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1887
|
-
function InputLabel(props) {
|
|
1888
|
-
const interpolateOpts = {
|
|
1889
|
-
context: props.context,
|
|
1890
|
-
env: props.config?.env
|
|
1891
|
-
};
|
|
1892
|
-
const label = interpolateIfNeeded(props.field.label, interpolateOpts);
|
|
1893
|
-
return /* @__PURE__ */ jsxs7(
|
|
1894
|
-
"div",
|
|
1895
|
-
{
|
|
1896
|
-
"data-slot": "field-content",
|
|
1897
|
-
className: "flex w-full flex-1 flex-col gap-1.5 leading-snug",
|
|
1898
|
-
children: [
|
|
1899
|
-
/* @__PURE__ */ jsx15(
|
|
1900
|
-
Label,
|
|
1901
|
-
{
|
|
1902
|
-
field: props.field,
|
|
1903
|
-
style: props.config?.style,
|
|
1904
|
-
translations: props.translations,
|
|
1905
|
-
children: translate(label, props.translations)
|
|
1906
|
-
}
|
|
1907
|
-
),
|
|
1908
|
-
props.horizontal === true && /* @__PURE__ */ jsx15(
|
|
1909
|
-
FormattedDescription,
|
|
1910
|
-
{
|
|
1911
|
-
config: props.config,
|
|
1912
|
-
context: props.context,
|
|
1913
|
-
text: props.field.description,
|
|
1914
|
-
translations: props.translations
|
|
1915
|
-
}
|
|
1916
|
-
)
|
|
1917
|
-
]
|
|
1918
|
-
}
|
|
1919
|
-
);
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
// src/component/input-group.tsx
|
|
1923
|
-
import { Fragment, jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1924
|
-
function InputGroup(props) {
|
|
1925
|
-
return /* @__PURE__ */ jsxs8(Fragment, { children: [
|
|
1926
|
-
props.field.name && props.field.label && /* @__PURE__ */ jsx16(
|
|
1927
|
-
InputLabel,
|
|
1928
|
-
{
|
|
1929
|
-
config: props.config,
|
|
1930
|
-
context: props.context,
|
|
1931
|
-
field: props.field,
|
|
1932
|
-
horizontal: props.horizontal,
|
|
1933
|
-
translations: props.translations
|
|
1934
|
-
}
|
|
1935
|
-
),
|
|
1936
|
-
props.children,
|
|
1937
|
-
props.horizontal === false && /* @__PURE__ */ jsx16(
|
|
1938
|
-
FormattedDescription,
|
|
1939
|
-
{
|
|
1940
|
-
config: props.config,
|
|
1941
|
-
context: props.context,
|
|
1942
|
-
text: props.field.description,
|
|
1943
|
-
translations: props.translations
|
|
1944
|
-
}
|
|
1945
|
-
)
|
|
1946
|
-
] });
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
// src/lib/render-If-exists.ts
|
|
1950
|
-
function renderIfExists(value, render) {
|
|
1951
|
-
if (!value) {
|
|
1952
|
-
return null;
|
|
1953
|
-
}
|
|
1954
|
-
return render(value);
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
// src/client/component/input-base.tsx
|
|
1958
|
-
import { useCallback as useCallback5, useEffect as useEffect4, useRef as useRef4 } from "react";
|
|
1959
|
-
|
|
1960
|
-
// src/client/lib/error-store.ts
|
|
1961
|
-
var store2 = createAtomStore();
|
|
1962
|
-
var clearInputErrorAtom = store2.clear;
|
|
1963
|
-
var reportErrorAtom = store2.bulkReport;
|
|
1964
|
-
var reportInputErrorAtom = store2.report;
|
|
1965
|
-
|
|
1966
|
-
// src/client/lib/value-store.ts
|
|
1967
|
-
var store3 = createAtomStore();
|
|
1968
|
-
var valueAtom = store3.atom;
|
|
1969
|
-
var clearAllValueAtom = store3.clearAll;
|
|
1970
|
-
var clearInputValueAtom = store3.clear;
|
|
1971
|
-
var reportValueAtom = store3.report;
|
|
1972
|
-
|
|
1973
|
-
// src/client/hook/use-input-core.ts
|
|
1974
|
-
import { useCallback as useCallback3, useRef as useRef2, useTransition } from "react";
|
|
1975
|
-
|
|
1976
|
-
// src/client/hook/use-input.ts
|
|
1977
|
-
import { useContext, useEffect, useEffectEvent, useMemo } from "react";
|
|
1978
|
-
function useInput(field, onMount, onUnmount, translations) {
|
|
1979
|
-
const { name } = field;
|
|
1980
|
-
const schema = useMemo(
|
|
1981
|
-
() => getSchema(field, translations),
|
|
1982
|
-
[field, translations]
|
|
1983
|
-
);
|
|
1984
|
-
const keepValue = useContext(KeepValueContext);
|
|
1985
|
-
const onMountHandler = useEffectEvent((name2) => {
|
|
1986
|
-
if (name2) {
|
|
1987
|
-
onMount(name2, schema, field);
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
const onUnmountHandler = useEffectEvent((name2) => {
|
|
1991
|
-
if (name2) {
|
|
1992
|
-
onUnmount(name2, {
|
|
1993
|
-
keepValue
|
|
1994
|
-
});
|
|
1995
|
-
}
|
|
1996
|
-
});
|
|
1997
|
-
useEffect(() => {
|
|
1998
|
-
onMountHandler(name);
|
|
1999
|
-
return () => {
|
|
2000
|
-
onUnmountHandler(name);
|
|
2001
|
-
};
|
|
2002
|
-
}, [name]);
|
|
2003
|
-
return schema;
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
// src/client/hook/use-input-core.ts
|
|
2007
|
-
import { useSetAtom, useStore } from "jotai";
|
|
2008
|
-
|
|
2009
|
-
// src/client/hook/use-timeout.ts
|
|
2010
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useRef } from "react";
|
|
2011
|
-
function useTimeout() {
|
|
2012
|
-
const timeoutRef = useRef(null);
|
|
2013
|
-
useEffect2(() => {
|
|
2014
|
-
return () => {
|
|
2015
|
-
if (timeoutRef.current) {
|
|
2016
|
-
clearTimeout(timeoutRef.current);
|
|
2017
|
-
}
|
|
2018
|
-
};
|
|
2019
|
-
}, []);
|
|
2020
|
-
const setTimeoutRef = useCallback2((callback, delay) => {
|
|
2021
|
-
if (timeoutRef.current) {
|
|
2022
|
-
clearTimeout(timeoutRef.current);
|
|
2023
|
-
timeoutRef.current = null;
|
|
2024
|
-
}
|
|
2025
|
-
timeoutRef.current = setTimeout(callback, delay);
|
|
2026
|
-
}, []);
|
|
2027
|
-
return setTimeoutRef;
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
// src/client/hook/use-input-core.ts
|
|
2031
|
-
function useInputCore(props, deps) {
|
|
2032
|
-
const store4 = useStore();
|
|
2033
|
-
const entity = props.field.advanced?.entity;
|
|
2034
|
-
const setTimeoutRef = useTimeout();
|
|
2035
|
-
const [, startTransition2] = useTransition();
|
|
2036
|
-
const { setValue, shouldSkipOnChange, value, setSource } = deps;
|
|
2037
|
-
const valueRef = useRef2(value);
|
|
2038
|
-
valueRef.current = value;
|
|
2039
|
-
const translationsRef = useRef2(props.translations);
|
|
2040
|
-
translationsRef.current = props.translations;
|
|
2041
|
-
const hasClickable = isClickable(props.field);
|
|
2042
|
-
const setValues = useSetAtom(valueAtom);
|
|
2043
|
-
const setFieldStates = useSetAtom(fieldStateAtom);
|
|
2044
|
-
const setErrors = useSetAtom(reportInputErrorAtom(props.field.name));
|
|
2045
|
-
const schema = useInput(
|
|
2046
|
-
props.field,
|
|
2047
|
-
props.onMount,
|
|
2048
|
-
props.onUnmount,
|
|
2049
|
-
props.translations
|
|
2050
|
-
);
|
|
2051
|
-
const placeholder = translate(
|
|
2052
|
-
props.commonProps.placeholder,
|
|
2053
|
-
props.translations
|
|
2054
|
-
);
|
|
2055
|
-
const commonProps = {
|
|
2056
|
-
...props.commonProps,
|
|
2057
|
-
placeholder
|
|
2058
|
-
};
|
|
2059
|
-
const onValueChangeRef = useRef2(null);
|
|
2060
|
-
onValueChangeRef.current = (value2) => {
|
|
2061
|
-
setValue(value2);
|
|
2062
|
-
if (props.onValueChange) {
|
|
2063
|
-
const attributes = props.dataAttributes ?? {};
|
|
2064
|
-
props.onValueChange({
|
|
2065
|
-
data: Object.keys(attributes).length > 0 ? attributes : void 0,
|
|
2066
|
-
name: props.field.name,
|
|
2067
|
-
type: props.field.type,
|
|
2068
|
-
value: value2
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
};
|
|
2072
|
-
const applyChangeEventsRef = useRef2(
|
|
2073
|
-
null
|
|
2074
|
-
);
|
|
2075
|
-
applyChangeEventsRef.current = (selected) => {
|
|
2076
|
-
const events = props.field.event?.change;
|
|
2077
|
-
if (!events) {
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
handleProxyEvent(events, ({ sources, states, values }) => {
|
|
2081
|
-
startTransition2(() => {
|
|
2082
|
-
handleSourceEvent(
|
|
2083
|
-
selected,
|
|
2084
|
-
sources,
|
|
2085
|
-
(target, source) => setSource(target, source)
|
|
2086
|
-
);
|
|
2087
|
-
handleStateEvent(selected, states, (targets, state) => {
|
|
2088
|
-
setFieldStates((previous) => {
|
|
2089
|
-
if (state) {
|
|
2090
|
-
return targets.reduce(
|
|
2091
|
-
(acc, target) => ({
|
|
2092
|
-
...acc,
|
|
2093
|
-
[target]: state
|
|
2094
|
-
}),
|
|
2095
|
-
previous
|
|
2096
|
-
);
|
|
2097
|
-
}
|
|
2098
|
-
return targets.reduce(
|
|
2099
|
-
(acc, target) => omitKey(acc, target),
|
|
2100
|
-
previous
|
|
2101
|
-
);
|
|
2102
|
-
});
|
|
2103
|
-
if (state?.hidden === true) {
|
|
2104
|
-
setValues((previous) => {
|
|
2105
|
-
let changed = false;
|
|
2106
|
-
const next = { ...previous };
|
|
2107
|
-
for (const key of Object.keys(previous)) {
|
|
2108
|
-
if (targets.some(
|
|
2109
|
-
(target) => key === target || key.startsWith(`${target}.`)
|
|
2110
|
-
)) {
|
|
2111
|
-
delete next[key];
|
|
2112
|
-
changed = true;
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
return changed ? next : previous;
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
});
|
|
2119
|
-
handleValueEvent(selected, values, (target, value2) => {
|
|
2120
|
-
setValues((previous) => ({
|
|
2121
|
-
...previous,
|
|
2122
|
-
[target]: value2
|
|
2123
|
-
}));
|
|
2124
|
-
});
|
|
2125
|
-
});
|
|
2126
|
-
});
|
|
2127
|
-
};
|
|
2128
|
-
const validated = useCallback3(
|
|
2129
|
-
(value2) => {
|
|
2130
|
-
const results = schema.safeParse(value2);
|
|
2131
|
-
const errors = results.error?.issues.map((issue) => issue.message) ?? [];
|
|
2132
|
-
const custom = props.field.validation?.custom;
|
|
2133
|
-
const customErrors = custom ? validateCustom(
|
|
2134
|
-
value2,
|
|
2135
|
-
custom,
|
|
2136
|
-
(name) => store4.get(reportValueAtom(name)),
|
|
2137
|
-
translationsRef.current
|
|
2138
|
-
) : [];
|
|
2139
|
-
setErrors([...errors, ...customErrors]);
|
|
2140
|
-
},
|
|
2141
|
-
[props.field.validation?.custom, schema, setErrors, store4]
|
|
2142
|
-
);
|
|
2143
|
-
const onBlur = useCallback3(
|
|
2144
|
-
(event) => {
|
|
2145
|
-
if (!hasClickable) {
|
|
2146
|
-
const value2 = event.target.value;
|
|
2147
|
-
if (props.config.validation.blur) {
|
|
2148
|
-
validated(value2);
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
},
|
|
2152
|
-
[hasClickable, props.config.validation.blur, validated]
|
|
2153
|
-
);
|
|
2154
|
-
return {
|
|
2155
|
-
applyChangeEventsRef,
|
|
2156
|
-
commonProps,
|
|
2157
|
-
entity,
|
|
2158
|
-
hasClickable,
|
|
2159
|
-
onBlur,
|
|
2160
|
-
onValueChangeRef,
|
|
2161
|
-
setTimeoutRef,
|
|
2162
|
-
shouldSkipOnChange,
|
|
2163
|
-
validated,
|
|
2164
|
-
valueRef
|
|
2165
|
-
};
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
// src/client/hook/use-value.ts
|
|
2169
|
-
import { deepEqual as deepEqual2 } from "fast-equals";
|
|
2170
|
-
import { useAtom } from "jotai";
|
|
2171
|
-
import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef3, useEffectEvent as useEffectEvent2 } from "react";
|
|
2172
|
-
function useValue(field, currentValue) {
|
|
2173
|
-
const { name } = field;
|
|
2174
|
-
const skipNextOnChangeRef = useRef3(false);
|
|
2175
|
-
const [value, setValue] = useAtom(reportValueAtom(name));
|
|
2176
|
-
const onCurrentValueChange = useEffectEvent2(
|
|
2177
|
-
(currentValue2) => {
|
|
2178
|
-
const newValue = resolveValue(name, currentValue2);
|
|
2179
|
-
if (isValidValue(newValue)) {
|
|
2180
|
-
if (!deepEqual2(value, newValue)) {
|
|
2181
|
-
skipNextOnChangeRef.current = true;
|
|
2182
|
-
}
|
|
2183
|
-
setValue(newValue);
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
);
|
|
2187
|
-
useEffect3(() => {
|
|
2188
|
-
if (!currentValue) {
|
|
2189
|
-
return;
|
|
2190
|
-
}
|
|
2191
|
-
onCurrentValueChange(currentValue);
|
|
2192
|
-
}, [currentValue]);
|
|
2193
|
-
const shouldSkipOnChange = useCallback4(() => {
|
|
2194
|
-
if (skipNextOnChangeRef.current) {
|
|
2195
|
-
skipNextOnChangeRef.current = false;
|
|
2196
|
-
return true;
|
|
2197
|
-
}
|
|
2198
|
-
return false;
|
|
2199
|
-
}, []);
|
|
2200
|
-
return {
|
|
2201
|
-
setValue,
|
|
2202
|
-
shouldSkipOnChange,
|
|
2203
|
-
value
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
function resolveValue(name, currentValue) {
|
|
2207
|
-
if (name in currentValue) {
|
|
2208
|
-
return currentValue[name];
|
|
2209
|
-
}
|
|
2210
|
-
if (!name.includes(".")) {
|
|
2211
|
-
return void 0;
|
|
2212
|
-
}
|
|
2213
|
-
const keys = name.split(".");
|
|
2214
|
-
let result = currentValue;
|
|
2215
|
-
for (const key of keys) {
|
|
2216
|
-
if (result === null || result === void 0) {
|
|
2217
|
-
return void 0;
|
|
2218
|
-
}
|
|
2219
|
-
if (Array.isArray(result)) {
|
|
2220
|
-
const index = Number(key);
|
|
2221
|
-
result = Number.isInteger(index) ? result[index] : void 0;
|
|
2222
|
-
} else if (typeof result === "object") {
|
|
2223
|
-
result = result[key];
|
|
2224
|
-
} else {
|
|
2225
|
-
return void 0;
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
return result;
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
// src/client/component/input-base.tsx
|
|
2232
|
-
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
2233
|
-
function InputBase(props) {
|
|
2234
|
-
const {
|
|
2235
|
-
useSource,
|
|
2236
|
-
useExtraProps,
|
|
2237
|
-
getValue: getValue3,
|
|
2238
|
-
shouldSkipChange,
|
|
2239
|
-
dispatchChange,
|
|
2240
|
-
buildInitialSelected,
|
|
2241
|
-
isInitialReady
|
|
2242
|
-
} = props.strategies;
|
|
2243
|
-
const { setValue, shouldSkipOnChange, value } = useValue(
|
|
2244
|
-
props.field,
|
|
2245
|
-
props.value
|
|
2246
|
-
);
|
|
2247
|
-
const { data, setSource } = useSource(props.field, props.config, value);
|
|
2248
|
-
const {
|
|
2249
|
-
applyChangeEventsRef,
|
|
2250
|
-
commonProps,
|
|
2251
|
-
entity,
|
|
2252
|
-
hasClickable,
|
|
2253
|
-
onBlur,
|
|
2254
|
-
onValueChangeRef,
|
|
2255
|
-
setTimeoutRef,
|
|
2256
|
-
validated,
|
|
2257
|
-
valueRef
|
|
2258
|
-
} = useInputCore(props, { setValue, shouldSkipOnChange, value, setSource });
|
|
2259
|
-
const extraProps = useExtraProps?.(props.field);
|
|
2260
|
-
const initialEventsProcessedRef = useRef4(false);
|
|
2261
|
-
const { commonPropsWithOptions, defaultValue } = prepareInputProps(
|
|
2262
|
-
props.field,
|
|
2263
|
-
commonProps,
|
|
2264
|
-
data,
|
|
2265
|
-
value
|
|
2266
|
-
);
|
|
2267
|
-
const inputProps = prepareInputValue(props.field, defaultValue);
|
|
2268
|
-
useEffect4(() => {
|
|
2269
|
-
if (initialEventsProcessedRef.current || !props.value) {
|
|
2270
|
-
return;
|
|
2271
|
-
}
|
|
2272
|
-
if (!props.field.event?.change) {
|
|
2273
|
-
initialEventsProcessedRef.current = true;
|
|
2274
|
-
return;
|
|
2275
|
-
}
|
|
2276
|
-
if (!isValidValue(defaultValue)) {
|
|
2277
|
-
return;
|
|
2278
|
-
}
|
|
2279
|
-
if (!isInitialReady(props.field, defaultValue, data)) {
|
|
2280
|
-
return;
|
|
2281
|
-
}
|
|
2282
|
-
initialEventsProcessedRef.current = true;
|
|
2283
|
-
const selected = buildInitialSelected(defaultValue, data, entity);
|
|
2284
|
-
applyChangeEventsRef.current?.(selected);
|
|
2285
|
-
}, [
|
|
2286
|
-
applyChangeEventsRef,
|
|
2287
|
-
buildInitialSelected,
|
|
2288
|
-
data,
|
|
2289
|
-
defaultValue,
|
|
2290
|
-
entity,
|
|
2291
|
-
isInitialReady,
|
|
2292
|
-
props.field,
|
|
2293
|
-
props.value
|
|
2294
|
-
]);
|
|
2295
|
-
const onChange = useCallback5(
|
|
2296
|
-
(event) => {
|
|
2297
|
-
const inputValue = getValue3(event, props.field);
|
|
2298
|
-
if (shouldSkipChange({
|
|
2299
|
-
shouldSkipOnChange,
|
|
2300
|
-
hasClickable,
|
|
2301
|
-
inputValue,
|
|
2302
|
-
valueRef
|
|
2303
|
-
})) {
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
onValueChangeRef.current?.(inputValue);
|
|
2307
|
-
if (props.config.validation.change) {
|
|
2308
|
-
validated(inputValue);
|
|
2309
|
-
}
|
|
2310
|
-
if (props.field.event?.change) {
|
|
2311
|
-
dispatchChange({
|
|
2312
|
-
applyChangeEventsRef,
|
|
2313
|
-
data,
|
|
2314
|
-
entity,
|
|
2315
|
-
inputValue,
|
|
2316
|
-
setTimeoutRef
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
},
|
|
2320
|
-
[
|
|
2321
|
-
applyChangeEventsRef,
|
|
2322
|
-
data,
|
|
2323
|
-
dispatchChange,
|
|
2324
|
-
entity,
|
|
2325
|
-
getValue3,
|
|
2326
|
-
hasClickable,
|
|
2327
|
-
onValueChangeRef,
|
|
2328
|
-
props.config.validation.change,
|
|
2329
|
-
props.field,
|
|
2330
|
-
setTimeoutRef,
|
|
2331
|
-
shouldSkipChange,
|
|
2332
|
-
shouldSkipOnChange,
|
|
2333
|
-
validated,
|
|
2334
|
-
valueRef
|
|
2335
|
-
]
|
|
2336
|
-
);
|
|
2337
|
-
return renderIfExists(props.config.inputs[props.field.type], (Component) => /* @__PURE__ */ jsx17(
|
|
2338
|
-
InputGroup,
|
|
2339
|
-
{
|
|
2340
|
-
config: props.config,
|
|
2341
|
-
context: props.context,
|
|
2342
|
-
field: props.field,
|
|
2343
|
-
horizontal: props.horizontal,
|
|
2344
|
-
translations: props.translations,
|
|
2345
|
-
children: /* @__PURE__ */ jsx17(
|
|
2346
|
-
Component,
|
|
2347
|
-
{
|
|
2348
|
-
...commonPropsWithOptions,
|
|
2349
|
-
...props.ariaAttributes,
|
|
2350
|
-
...props.dataAttributes,
|
|
2351
|
-
...extraProps,
|
|
2352
|
-
...inputProps,
|
|
2353
|
-
onBlur,
|
|
2354
|
-
onChange
|
|
2355
|
-
}
|
|
2356
|
-
)
|
|
2357
|
-
}
|
|
2358
|
-
));
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
// src/client/component/input-create.tsx
|
|
2362
|
-
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2363
|
-
function createInput(strategies) {
|
|
2364
|
-
return function CreateInput(props) {
|
|
2365
|
-
return /* @__PURE__ */ jsx18(InputBase, { ...props, strategies });
|
|
2366
|
-
};
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
|
-
// src/client/hook/use-format.ts
|
|
2370
|
-
function useFormat(field) {
|
|
2371
|
-
const dateFormat = isDate(field) ? getDateFormat(field) : null;
|
|
2372
|
-
const timeFormat = isTime(field) ? getTimeFormat(field) : null;
|
|
2373
|
-
return {
|
|
2374
|
-
dateFormat,
|
|
2375
|
-
timeFormat
|
|
2376
|
-
};
|
|
2377
|
-
}
|
|
2378
|
-
|
|
2379
|
-
// src/client/lib/source-store.ts
|
|
2380
|
-
import { atom as atom2 } from "jotai";
|
|
2381
|
-
var merge = (values) => {
|
|
2382
|
-
const merged = mergeSource(values);
|
|
2383
|
-
if (merged) {
|
|
2384
|
-
return merged;
|
|
2385
|
-
}
|
|
2386
|
-
return void 0;
|
|
2387
|
-
};
|
|
2388
|
-
var validate = (target) => target.trim() !== "";
|
|
2389
|
-
var sourceAtom = atom2({});
|
|
2390
|
-
var reportSourceAtom = createNestedRecordAtomFamily(
|
|
2391
|
-
sourceAtom,
|
|
2392
|
-
{
|
|
2393
|
-
merge,
|
|
2394
|
-
validateTarget: validate
|
|
2395
|
-
}
|
|
2396
|
-
);
|
|
2397
|
-
var clearInputSourceAtom = createNestedClearAtom(sourceAtom);
|
|
2398
|
-
|
|
2399
|
-
// src/client/hook/use-write-only-source.tsx
|
|
2400
|
-
import { useSetAtom as useSetAtom2 } from "jotai";
|
|
2401
|
-
function useWriteOnlySource(field) {
|
|
2402
|
-
const setSource = useSetAtom2(reportSourceAtom(field.name));
|
|
2403
|
-
return { data: null, setSource };
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
// src/client/component/input-dateable.tsx
|
|
2407
|
-
var InputDateable = createInput({
|
|
2408
|
-
useSource: useWriteOnlySource,
|
|
2409
|
-
useExtraProps: (field) => {
|
|
2410
|
-
const { dateFormat, timeFormat } = useFormat(field);
|
|
2411
|
-
return getFormatProps(dateFormat, timeFormat);
|
|
2412
|
-
},
|
|
2413
|
-
getValue: (event, field) => {
|
|
2414
|
-
const raw = event.target.value;
|
|
2415
|
-
const timeFormat = isTime(field) ? getTimeFormat(field) : null;
|
|
2416
|
-
if (timeFormat !== null) {
|
|
2417
|
-
return fromNativeTime(raw, timeFormat);
|
|
2418
|
-
}
|
|
2419
|
-
const dateFormat = isDate(field) ? getDateFormat(field) : null;
|
|
2420
|
-
if (dateFormat !== null) {
|
|
2421
|
-
const converted = fromNativeDate(raw, dateFormat);
|
|
2422
|
-
return converted || raw;
|
|
2423
|
-
}
|
|
2424
|
-
return raw;
|
|
2425
|
-
},
|
|
2426
|
-
shouldSkipChange: ({ shouldSkipOnChange, inputValue, valueRef }) => shouldSkipOnChange() && inputValue === valueRef.current,
|
|
2427
|
-
dispatchChange: ({ applyChangeEventsRef, inputValue, setTimeoutRef }) => {
|
|
2428
|
-
setTimeoutRef(() => {
|
|
2429
|
-
applyChangeEventsRef.current?.({ value: inputValue });
|
|
2430
|
-
}, 300);
|
|
2431
|
-
},
|
|
2432
|
-
buildInitialSelected: (defaultValue) => ({ value: String(defaultValue) }),
|
|
2433
|
-
isInitialReady: (_field, defaultValue) => isValidValue(defaultValue)
|
|
2434
|
-
});
|
|
2435
|
-
|
|
2436
|
-
// src/client/hook/use-data-source.ts
|
|
2437
|
-
import { useAtom as useAtom2 } from "jotai";
|
|
2438
|
-
|
|
2439
|
-
// src/client/hook/use-fetch.ts
|
|
2440
|
-
import useSWR from "swr";
|
|
2441
|
-
function useFetch(dataSource = null, config, disabled = false) {
|
|
2442
|
-
const { data, error } = useSWR(
|
|
2443
|
-
buildSource2(dataSource, config, disabled),
|
|
2444
|
-
config.fetcher.provider
|
|
2445
|
-
);
|
|
2446
|
-
if (error) {
|
|
2447
|
-
logger.error("Error fetching data source:", error);
|
|
2448
|
-
}
|
|
2449
|
-
if (dataSource) {
|
|
2450
|
-
if (Array.isArray(dataSource)) {
|
|
2451
|
-
return dataSource;
|
|
2452
|
-
}
|
|
2453
|
-
if (data) {
|
|
2454
|
-
return getArray(data, dataSource.namespace);
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
return null;
|
|
2458
|
-
}
|
|
2459
|
-
function buildSource2(dataSource = null, config, disabled = false) {
|
|
2460
|
-
if (dataSource && !Array.isArray(dataSource) && !disabled) {
|
|
2461
|
-
if (dataSource.url) {
|
|
2462
|
-
const interpolated = isInterpolated(dataSource.url);
|
|
2463
|
-
if (!interpolated) {
|
|
2464
|
-
const allowed = matchRemotePattern(
|
|
2465
|
-
dataSource.url,
|
|
2466
|
-
config.fetcher.remotePatterns
|
|
2467
|
-
);
|
|
2468
|
-
if (allowed) {
|
|
2469
|
-
return dataSource;
|
|
2470
|
-
}
|
|
2471
|
-
logger.warn(
|
|
2472
|
-
`URL blocked by remotePatterns: ${dataSource.url}. Check your luna.config.ts`
|
|
2473
|
-
);
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
return null;
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
// src/client/hook/use-data-source.ts
|
|
2481
|
-
function useDataSource(field, config, value) {
|
|
2482
|
-
const dataSource = resolveSource(field, value);
|
|
2483
|
-
const [source, setSource] = useAtom2(reportSourceAtom(field.name));
|
|
2484
|
-
const currentSource = source ?? dataSource;
|
|
2485
|
-
const data = useFetch(currentSource, config, field.disabled);
|
|
2486
|
-
return [data, setSource];
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
// src/client/component/input-selectable.tsx
|
|
2490
|
-
function useSelectableSource(field, config, value) {
|
|
2491
|
-
const [data, setSource] = useDataSource(field, config, value);
|
|
2492
|
-
return { data, setSource };
|
|
2493
|
-
}
|
|
2494
|
-
var InputSelectable = createInput({
|
|
2495
|
-
useSource: useSelectableSource,
|
|
2496
|
-
getValue: (event) => event.target.value,
|
|
2497
|
-
shouldSkipChange: ({ shouldSkipOnChange, hasClickable }) => !hasClickable && shouldSkipOnChange(),
|
|
2498
|
-
dispatchChange: ({ applyChangeEventsRef, data, entity, inputValue }) => {
|
|
2499
|
-
applyChangeEventsRef.current?.(getEntity(inputValue, data, entity));
|
|
2500
|
-
},
|
|
2501
|
-
buildInitialSelected: (defaultValue, data, entity) => getEntity(String(defaultValue), data, entity),
|
|
2502
|
-
isInitialReady: (field, defaultValue, data) => (!isOptions(field) || !!data && data.length > 0) && isValidValue(defaultValue)
|
|
2503
|
-
});
|
|
2504
|
-
|
|
2505
|
-
// src/client/component/input-textable.tsx
|
|
2506
|
-
var InputTextable = createInput({
|
|
2507
|
-
useSource: useWriteOnlySource,
|
|
2508
|
-
getValue: (event) => event.target.value,
|
|
2509
|
-
shouldSkipChange: ({ shouldSkipOnChange, inputValue, valueRef }) => shouldSkipOnChange() && inputValue === valueRef.current,
|
|
2510
|
-
dispatchChange: ({ applyChangeEventsRef, inputValue, setTimeoutRef }) => {
|
|
2511
|
-
setTimeoutRef(() => {
|
|
2512
|
-
applyChangeEventsRef.current?.({ value: inputValue });
|
|
2513
|
-
}, 300);
|
|
2514
|
-
},
|
|
2515
|
-
buildInitialSelected: (defaultValue) => ({ value: String(defaultValue) }),
|
|
2516
|
-
isInitialReady: (_field, defaultValue) => isValidValue(defaultValue)
|
|
2517
|
-
});
|
|
2518
|
-
|
|
2519
|
-
// src/client/component/input.tsx
|
|
2520
|
-
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
2521
|
-
function Input(props) {
|
|
2522
|
-
if (isDate(props.field) || isTime(props.field)) {
|
|
2523
|
-
return /* @__PURE__ */ jsx19(InputDateable, { ...props });
|
|
2524
|
-
}
|
|
2525
|
-
if (isTextable(props.field)) {
|
|
2526
|
-
return /* @__PURE__ */ jsx19(InputTextable, { ...props });
|
|
2527
|
-
}
|
|
2528
|
-
return /* @__PURE__ */ jsx19(InputSelectable, { ...props });
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
// src/component/field/field-error.tsx
|
|
2532
|
-
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2533
|
-
function FieldError(props) {
|
|
2534
|
-
if (!props.errors || props.errors.length === 0) {
|
|
2535
|
-
return null;
|
|
2536
|
-
}
|
|
2537
|
-
return /* @__PURE__ */ jsx20(
|
|
2538
|
-
"ul",
|
|
2539
|
-
{
|
|
2540
|
-
className: "text-sm text-red-600 dark:text-red-500",
|
|
2541
|
-
id: props.name ? `${props.name}-error` : void 0,
|
|
2542
|
-
children: props.errors?.map((error, index) => /* @__PURE__ */ jsx20("li", { children: error }, props.name ? `${props.name}-error-${index}` : index))
|
|
2543
|
-
}
|
|
2544
|
-
);
|
|
2545
|
-
}
|
|
2546
|
-
|
|
2547
|
-
// src/component/field/field-base.tsx
|
|
2548
|
-
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
2549
|
-
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
2550
|
-
function FieldBase(props) {
|
|
2551
|
-
const errors = props.errors && props.errors.length > 0;
|
|
2552
|
-
return /* @__PURE__ */ jsx21(
|
|
2553
|
-
"div",
|
|
2554
|
-
{
|
|
2555
|
-
"data-slot": "field",
|
|
2556
|
-
"data-clickable": props.isClickable ? "true" : "false",
|
|
2557
|
-
...errors && { [DATA_INVALID]: "true" },
|
|
2558
|
-
...props.disabled && { [DATA_READONLY]: "true" },
|
|
2559
|
-
"data-orientation": props.orientation,
|
|
2560
|
-
className: twMerge2(
|
|
2561
|
-
"group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500",
|
|
2562
|
-
"data-[clickable=true]:items-start",
|
|
2563
|
-
props.isCheckbox && (props.isReversed ? "flex-row-reverse!" : "flex-row!"),
|
|
2564
|
-
"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",
|
|
2565
|
-
props.className
|
|
2566
|
-
),
|
|
2567
|
-
children: props.children
|
|
2568
|
-
}
|
|
2569
|
-
);
|
|
2570
|
-
}
|
|
2571
|
-
|
|
2572
|
-
// src/component/field/field-vertical.tsx
|
|
2573
|
-
import { twMerge as twMerge3 } from "tailwind-merge";
|
|
2574
|
-
import { jsx as jsx22 } from "react/jsx-runtime";
|
|
2575
|
-
function FieldVertical(props) {
|
|
2576
|
-
return /* @__PURE__ */ jsx22(
|
|
2577
|
-
FieldBase,
|
|
2578
|
-
{
|
|
2579
|
-
...props,
|
|
2580
|
-
orientation: "vertical",
|
|
2581
|
-
className: twMerge3(
|
|
2582
|
-
"gap-3 has-[>[data-slot=field-content]]:items-start",
|
|
2583
|
-
!props.isClickable && "[&>*]:w-full"
|
|
2584
|
-
),
|
|
2585
|
-
children: props.children
|
|
2586
|
-
}
|
|
2587
|
-
);
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
// src/component/field/field-horizontal.tsx
|
|
2591
|
-
import { twMerge as twMerge4 } from "tailwind-merge";
|
|
2592
|
-
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2593
|
-
function FieldHorizontal(props) {
|
|
2594
|
-
return /* @__PURE__ */ jsx23(
|
|
2595
|
-
FieldBase,
|
|
2596
|
-
{
|
|
2597
|
-
...props,
|
|
2598
|
-
orientation: "horizontal",
|
|
2599
|
-
className: twMerge4(
|
|
2600
|
-
"gap-2 md:flex-row md:gap-4",
|
|
2601
|
-
"[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start",
|
|
2602
|
-
"[&_[role=checkbox]]:mt-[1.5px]",
|
|
2603
|
-
props.isClickable && "md:flex-col",
|
|
2604
|
-
!props.isClickable && [
|
|
2605
|
-
"md:justify-between",
|
|
2606
|
-
"[&>*:not([data-slot=field-content])]:w-full",
|
|
2607
|
-
"[&>*:not([data-slot=field-content])]:md:w-1/2",
|
|
2608
|
-
"[&>*:not([data-slot=field-content])]:xl:w-2/5"
|
|
2609
|
-
]
|
|
2610
|
-
),
|
|
2611
|
-
children: props.children
|
|
2612
|
-
}
|
|
2613
|
-
);
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
// src/component/field/field-group.tsx
|
|
2617
|
-
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2618
|
-
function FieldGroup(props) {
|
|
2619
|
-
const clickable = isClickable(props.field);
|
|
2620
|
-
const checkbox = isCheckbox(props.field);
|
|
2621
|
-
const reversed = buildReverse(props.field);
|
|
2622
|
-
if (!props.horizontal) {
|
|
2623
|
-
return /* @__PURE__ */ jsx24(
|
|
2624
|
-
FieldVertical,
|
|
2625
|
-
{
|
|
2626
|
-
disabled: props.disabled,
|
|
2627
|
-
errors: props.errors,
|
|
2628
|
-
isCheckbox: checkbox,
|
|
2629
|
-
isReversed: reversed,
|
|
2630
|
-
isClickable: clickable,
|
|
2631
|
-
children: props.children
|
|
2632
|
-
}
|
|
2633
|
-
);
|
|
2634
|
-
}
|
|
2635
|
-
return /* @__PURE__ */ jsx24(
|
|
2636
|
-
FieldHorizontal,
|
|
2637
|
-
{
|
|
2638
|
-
disabled: props.disabled,
|
|
2639
|
-
errors: props.errors,
|
|
2640
|
-
isCheckbox: checkbox,
|
|
2641
|
-
isReversed: reversed,
|
|
2642
|
-
isClickable: clickable,
|
|
2643
|
-
children: props.children
|
|
2644
|
-
}
|
|
2645
|
-
);
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
// src/component/input/input-base.tsx
|
|
2649
|
-
function InputBase2(props) {
|
|
2650
|
-
if (!props.field.type) {
|
|
2651
|
-
return null;
|
|
2652
|
-
}
|
|
2653
|
-
const commonProps = buildCommon(props.field, props.disabled);
|
|
2654
|
-
const dataAttributes = buildDataAttributes(props.field);
|
|
2655
|
-
const ariaAttributes = buildAriaAttributes(props.field, props.errors);
|
|
2656
|
-
const field = {
|
|
2657
|
-
...props.field,
|
|
2658
|
-
disabled: commonProps.disabled
|
|
2659
|
-
};
|
|
2660
|
-
return props.children({
|
|
2661
|
-
ariaAttributes,
|
|
2662
|
-
commonProps,
|
|
2663
|
-
dataAttributes,
|
|
2664
|
-
field,
|
|
2665
|
-
horizontal: props.horizontal
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
// src/component/field/field.tsx
|
|
2670
|
-
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
2671
|
-
import { jsx as jsx25, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2672
|
-
function Field(props) {
|
|
2673
|
-
const cols2 = props.field.advanced?.cols;
|
|
2674
|
-
const errors = props.field.name ? props.errors?.[props.field.name] : void 0;
|
|
2675
|
-
const { horizontal } = mergeStyle(props.style, {
|
|
2676
|
-
horizontal: buildOrientation(props.field)
|
|
2677
|
-
});
|
|
2678
|
-
const disabled = buildDisabled(props.field, props.disabled);
|
|
2679
|
-
return /* @__PURE__ */ jsxs9("div", { className: twMerge5("flex flex-col gap-3", getSpan(cols2)), children: [
|
|
2680
|
-
/* @__PURE__ */ jsx25(
|
|
2681
|
-
FieldGroup,
|
|
2682
|
-
{
|
|
2683
|
-
disabled,
|
|
2684
|
-
errors,
|
|
2685
|
-
field: props.field,
|
|
2686
|
-
horizontal,
|
|
2687
|
-
children: /* @__PURE__ */ jsx25(
|
|
2688
|
-
InputBase2,
|
|
2689
|
-
{
|
|
2690
|
-
disabled,
|
|
2691
|
-
errors,
|
|
2692
|
-
field: props.field,
|
|
2693
|
-
horizontal,
|
|
2694
|
-
children: props.children
|
|
2695
|
-
}
|
|
2696
|
-
)
|
|
2697
|
-
}
|
|
2698
|
-
),
|
|
2699
|
-
/* @__PURE__ */ jsx25(FieldError, { errors, name: props.field.name })
|
|
2700
|
-
] });
|
|
2701
|
-
}
|
|
2702
|
-
|
|
2703
|
-
// src/client/component/field/field-with-state.tsx
|
|
2704
|
-
import { useAtomValue as useAtomValue2 } from "jotai";
|
|
2705
|
-
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
2706
|
-
function createFieldHOC(atomFamily2) {
|
|
2707
|
-
return (Component, apply) => {
|
|
2708
|
-
const WithField = (props) => {
|
|
2709
|
-
const value = useAtomValue2(atomFamily2(props.field.name));
|
|
2710
|
-
const patch = apply(value, props);
|
|
2711
|
-
if (patch === null) return null;
|
|
2712
|
-
return /* @__PURE__ */ jsx26(Component, { ...props, ...patch });
|
|
2713
|
-
};
|
|
2714
|
-
return WithField;
|
|
2715
|
-
};
|
|
2716
|
-
}
|
|
2717
|
-
var applyError = createFieldHOC(reportInputErrorAtom);
|
|
2718
|
-
function withError(Component) {
|
|
2719
|
-
return applyError(
|
|
2720
|
-
Component,
|
|
2721
|
-
(errors, props) => ({
|
|
2722
|
-
errors: errors ? { [props.field.name]: errors } : void 0
|
|
2723
|
-
})
|
|
2724
|
-
);
|
|
2725
|
-
}
|
|
2726
|
-
var applyState = createFieldHOC(reportFieldStateAtom);
|
|
2727
|
-
function withState(Component) {
|
|
2728
|
-
return applyState(Component, (fieldState, props) => {
|
|
2729
|
-
const hidden = fieldState?.hidden ?? props.field.hidden ?? false;
|
|
2730
|
-
if (hidden) return null;
|
|
2731
|
-
return { disabled: fieldState?.disabled ?? props.disabled };
|
|
2732
|
-
});
|
|
2733
|
-
}
|
|
2734
|
-
|
|
2735
|
-
// src/client/component/field/field.tsx
|
|
2736
|
-
var Field2 = withState(withError(Field));
|
|
2737
|
-
|
|
2738
|
-
// src/component/field/field-list-item.tsx
|
|
2739
|
-
import { twMerge as twMerge6 } from "tailwind-merge";
|
|
2740
|
-
import { useState as useState3 } from "react";
|
|
2741
|
-
import { jsx as jsx27, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2742
|
-
function FieldListItem(props) {
|
|
2743
|
-
const [isOpen, setIsOpen] = useState3(
|
|
2744
|
-
props.collapsible ? !props.collapsed : true
|
|
2745
|
-
);
|
|
2746
|
-
function handleRemove() {
|
|
2747
|
-
if (props.canRemove && props.onRemove) {
|
|
2748
|
-
props.onRemove(props.index);
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
function handleToggle() {
|
|
2752
|
-
setIsOpen((previous) => !previous);
|
|
2753
|
-
}
|
|
2754
|
-
const removeButton = props.canRemove && props.onRemove != null && /* @__PURE__ */ jsx27(
|
|
2755
|
-
"button",
|
|
2756
|
-
{
|
|
2757
|
-
"aria-label": `Remove ${props.label} item ${props.index + 1}`,
|
|
2758
|
-
className: twMerge6(
|
|
2759
|
-
"rounded p-1 text-xl text-slate-400",
|
|
2760
|
-
"transition-colors duration-150",
|
|
2761
|
-
"hover:text-red-500",
|
|
2762
|
-
"focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:outline-none",
|
|
2763
|
-
"dark:text-slate-500 dark:hover:text-red-400"
|
|
2764
|
-
),
|
|
2765
|
-
onClick: handleRemove,
|
|
2766
|
-
type: "button",
|
|
2767
|
-
children: /* @__PURE__ */ jsx27("span", { "aria-hidden": "true", children: "\xD7" })
|
|
2768
|
-
}
|
|
2769
|
-
);
|
|
2770
|
-
if (props.isMultiField) {
|
|
2771
|
-
return /* @__PURE__ */ jsxs10(
|
|
2772
|
-
"div",
|
|
2773
|
-
{
|
|
2774
|
-
"data-slot": "list-item-card",
|
|
2775
|
-
className: "rounded-lg border border-slate-100 p-4 dark:border-slate-900",
|
|
2776
|
-
children: [
|
|
2777
|
-
/* @__PURE__ */ jsxs10("div", { className: "mb-3 flex items-center justify-between", children: [
|
|
2778
|
-
/* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-2", children: [
|
|
2779
|
-
props.collapsible && /* @__PURE__ */ jsx27(
|
|
2780
|
-
"button",
|
|
2781
|
-
{
|
|
2782
|
-
"aria-label": isOpen ? "Collapse" : "Expand",
|
|
2783
|
-
className: twMerge6(
|
|
2784
|
-
"rounded p-1 text-slate-400 hover:bg-slate-50",
|
|
2785
|
-
"transition-colors duration-150",
|
|
2786
|
-
"dark:text-slate-500 dark:hover:bg-slate-800"
|
|
2787
|
-
),
|
|
2788
|
-
onClick: handleToggle,
|
|
2789
|
-
type: "button",
|
|
2790
|
-
children: /* @__PURE__ */ jsx27(ChevronIcon, { expanded: isOpen })
|
|
2791
|
-
}
|
|
2792
|
-
),
|
|
2793
|
-
/* @__PURE__ */ jsxs10("span", { className: "text-sm font-medium text-slate-300 dark:text-slate-400", children: [
|
|
2794
|
-
props.label,
|
|
2795
|
-
" ",
|
|
2796
|
-
props.index + 1,
|
|
2797
|
-
!isOpen && props.preview && /* @__PURE__ */ jsx27("div", { className: "flex items-center gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-slate-400 dark:text-slate-500", children: props.preview })
|
|
2798
|
-
] })
|
|
2799
|
-
] }),
|
|
2800
|
-
removeButton
|
|
2801
|
-
] }),
|
|
2802
|
-
/* @__PURE__ */ jsx27(Collapsible, { visible: isOpen, children: /* @__PURE__ */ jsx27(Group, { children: props.children }) })
|
|
2803
|
-
]
|
|
2804
|
-
}
|
|
2805
|
-
);
|
|
2806
|
-
}
|
|
2807
|
-
return /* @__PURE__ */ jsxs10("div", { className: "flex items-start gap-2", children: [
|
|
2808
|
-
props.collapsible && /* @__PURE__ */ jsx27(
|
|
2809
|
-
"button",
|
|
2810
|
-
{
|
|
2811
|
-
"aria-label": isOpen ? "Collapse" : "Expand",
|
|
2812
|
-
className: twMerge6(
|
|
2813
|
-
"rounded p-1 text-slate-400 hover:bg-slate-50",
|
|
2814
|
-
"transition-colors duration-150",
|
|
2815
|
-
"dark:text-slate-500 dark:hover:bg-slate-800",
|
|
2816
|
-
isOpen && "mt-7"
|
|
2817
|
-
),
|
|
2818
|
-
onClick: handleToggle,
|
|
2819
|
-
type: "button",
|
|
2820
|
-
children: /* @__PURE__ */ jsx27(ChevronIcon, { expanded: isOpen })
|
|
2821
|
-
}
|
|
2822
|
-
),
|
|
2823
|
-
/* @__PURE__ */ jsx27("div", { className: "flex grow flex-col", children: /* @__PURE__ */ jsx27(Collapsible, { visible: isOpen, children: /* @__PURE__ */ jsx27(Group, { children: props.children }) }) }),
|
|
2824
|
-
removeButton && /* @__PURE__ */ jsx27("div", { className: twMerge6("shrink-0", isOpen && "mt-7"), children: removeButton })
|
|
2825
|
-
] });
|
|
2826
|
-
}
|
|
2827
|
-
|
|
2828
|
-
// src/client/component/field/field-preview-item.tsx
|
|
2829
|
-
import { useAtomValue as useAtomValue3 } from "jotai";
|
|
2830
|
-
import { Fragment as Fragment2, jsx as jsx28, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2831
|
-
function FieldPreviewItem({
|
|
2832
|
-
name,
|
|
2833
|
-
separator
|
|
2834
|
-
}) {
|
|
2835
|
-
const value = useAtomValue3(reportValueAtom(name));
|
|
2836
|
-
if (value == null || value === "") {
|
|
2837
|
-
return null;
|
|
2838
|
-
}
|
|
2839
|
-
if (isObject(value) || Array.isArray(value)) {
|
|
2840
|
-
return null;
|
|
2841
|
-
}
|
|
2842
|
-
return /* @__PURE__ */ jsxs11(Fragment2, { children: [
|
|
2843
|
-
separator && /* @__PURE__ */ jsx28("span", { className: "text-xs text-slate-300 dark:text-slate-600", children: "\xB7" }),
|
|
2844
|
-
/* @__PURE__ */ jsx28("span", { className: "max-w-[150px] overflow-hidden text-xs text-ellipsis", children: `${value}` })
|
|
2845
|
-
] });
|
|
2846
|
-
}
|
|
2847
|
-
|
|
2848
|
-
// src/client/component/field/field-preview.tsx
|
|
2849
|
-
import { jsx as jsx29 } from "react/jsx-runtime";
|
|
2850
|
-
function FieldPreview({
|
|
2851
|
-
name,
|
|
2852
|
-
previews
|
|
2853
|
-
}) {
|
|
2854
|
-
return /* @__PURE__ */ jsx29("div", { className: "flex items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap", children: previews.map((preview, index) => /* @__PURE__ */ jsx29(
|
|
2855
|
-
FieldPreviewItem,
|
|
2856
|
-
{
|
|
2857
|
-
name: `${name}.${preview}`,
|
|
2858
|
-
separator: index > 0
|
|
2859
|
-
},
|
|
2860
|
-
preview
|
|
2861
|
-
)) });
|
|
2862
|
-
}
|
|
2863
|
-
|
|
2864
|
-
// src/client/component/field/field-list.tsx
|
|
2865
|
-
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
2866
|
-
|
|
2867
|
-
// src/client/hook/use-field-list.ts
|
|
2868
|
-
import { useSetAtom as useSetAtom3 } from "jotai";
|
|
2869
|
-
import { useCallback as useCallback6, useLayoutEffect, useRef as useRef5, useState as useState4 } from "react";
|
|
2870
|
-
function useFieldList(field, value) {
|
|
2871
|
-
const min2 = field.advanced?.length?.min ?? 1;
|
|
2872
|
-
const max2 = field.advanced?.length?.max ?? Infinity;
|
|
2873
|
-
const [items, setItems] = useState4(
|
|
2874
|
-
() => getInitialList(field, value)
|
|
2875
|
-
);
|
|
2876
|
-
const nextId = useRef5(items.length);
|
|
2877
|
-
const itemsRef = useRef5(items);
|
|
2878
|
-
useLayoutEffect(() => {
|
|
2879
|
-
itemsRef.current = items;
|
|
2880
|
-
});
|
|
2881
|
-
const setValues = useSetAtom3(valueAtom);
|
|
2882
|
-
const addItem = useCallback6(() => {
|
|
2883
|
-
setItems((previous) => {
|
|
2884
|
-
if (previous.length >= max2) {
|
|
2885
|
-
return previous;
|
|
2886
|
-
}
|
|
2887
|
-
const id = nextId.current++;
|
|
2888
|
-
return [...previous, id];
|
|
2889
|
-
});
|
|
2890
|
-
}, [max2]);
|
|
2891
|
-
const handleRemove = useCallback6(
|
|
2892
|
-
(index) => {
|
|
2893
|
-
if (itemsRef.current.length <= min2) {
|
|
2894
|
-
return;
|
|
2895
|
-
}
|
|
2896
|
-
const stableId = itemsRef.current[index];
|
|
2897
|
-
setItems((previous) => {
|
|
2898
|
-
if (previous.length <= min2) {
|
|
2899
|
-
return previous;
|
|
2900
|
-
}
|
|
2901
|
-
return previous.filter((_, i) => i !== index);
|
|
2902
|
-
});
|
|
2903
|
-
setValues((current) => {
|
|
2904
|
-
const next = { ...current };
|
|
2905
|
-
const prefix = `${field.name}.`;
|
|
2906
|
-
const leafNames = [];
|
|
2907
|
-
for (const row of field.fields) {
|
|
2908
|
-
if (isColumn(row)) {
|
|
2909
|
-
for (const columnField of row.fields) {
|
|
2910
|
-
leafNames.push(columnField.name);
|
|
2911
|
-
}
|
|
2912
|
-
} else {
|
|
2913
|
-
leafNames.push(row.name);
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
for (const name of leafNames) {
|
|
2917
|
-
delete next[`${prefix}${stableId}.${name}`];
|
|
2918
|
-
}
|
|
2919
|
-
return next;
|
|
2920
|
-
});
|
|
2921
|
-
},
|
|
2922
|
-
[field.name, field.fields, min2, setValues]
|
|
2923
|
-
);
|
|
2924
|
-
const canAdd = items.length < max2;
|
|
2925
|
-
const canRemove = items.length > min2;
|
|
2926
|
-
return [items, addItem, handleRemove, canAdd, canRemove, max2];
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
// src/client/component/field/field-list.tsx
|
|
2930
|
-
import { Fragment as Fragment3, jsx as jsx30, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
2931
|
-
function FieldList(props) {
|
|
2932
|
-
const [items, addItem, handleRemove, canAdd, canRemove, max2] = useFieldList(
|
|
2933
|
-
props.field,
|
|
2934
|
-
props.value
|
|
2935
|
-
);
|
|
2936
|
-
const label = getLabel(props.field);
|
|
2937
|
-
const action = props.field.advanced?.action ?? "Add item";
|
|
2938
|
-
const hasLimit = max2 !== Infinity;
|
|
2939
|
-
const isMultiField = isMultiFieldList(props.field);
|
|
2940
|
-
const previews = props.field.advanced?.preview;
|
|
2941
|
-
return /* @__PURE__ */ jsxs12(Fragment3, { children: [
|
|
2942
|
-
items.map((key, index) => /* @__PURE__ */ jsx30(
|
|
2943
|
-
FieldListItem,
|
|
2944
|
-
{
|
|
2945
|
-
canRemove,
|
|
2946
|
-
collapsible: props.field.advanced?.collapsible,
|
|
2947
|
-
collapsed: props.field.advanced?.collapsed,
|
|
2948
|
-
index,
|
|
2949
|
-
isMultiField,
|
|
2950
|
-
label,
|
|
2951
|
-
onRemove: handleRemove,
|
|
2952
|
-
preview: previews && /* @__PURE__ */ jsx30(
|
|
2953
|
-
FieldPreview,
|
|
2954
|
-
{
|
|
2955
|
-
name: `${props.field.name}.${key}`,
|
|
2956
|
-
previews
|
|
2957
|
-
}
|
|
2958
|
-
),
|
|
2959
|
-
children: props.children(key)
|
|
2960
|
-
},
|
|
2961
|
-
key
|
|
2962
|
-
)),
|
|
2963
|
-
/* @__PURE__ */ jsxs12(
|
|
2964
|
-
"button",
|
|
2965
|
-
{
|
|
2966
|
-
"aria-disabled": !canAdd,
|
|
2967
|
-
"aria-label": hasLimit ? `${action}, ${items.length} of ${max2}` : action,
|
|
2968
|
-
className: twMerge7(
|
|
2969
|
-
"flex w-full items-center gap-1.5 rounded py-1",
|
|
2970
|
-
"text-sm font-medium text-slate-500",
|
|
2971
|
-
"transition-colors duration-150",
|
|
2972
|
-
"hover:text-slate-800",
|
|
2973
|
-
"focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:ring-offset-2 focus-visible:outline-none",
|
|
2974
|
-
"dark:text-slate-400 dark:hover:text-slate-200",
|
|
2975
|
-
!canAdd && "cursor-not-allowed opacity-50 hover:text-slate-500 dark:hover:text-slate-400"
|
|
2976
|
-
),
|
|
2977
|
-
disabled: !canAdd,
|
|
2978
|
-
onClick: addItem,
|
|
2979
|
-
type: "button",
|
|
2980
|
-
children: [
|
|
2981
|
-
/* @__PURE__ */ jsx30("span", { "aria-hidden": "true", children: "+" }),
|
|
2982
|
-
action,
|
|
2983
|
-
hasLimit && /* @__PURE__ */ jsxs12(
|
|
2984
|
-
"span",
|
|
2985
|
-
{
|
|
2986
|
-
"aria-hidden": "true",
|
|
2987
|
-
className: "ml-auto text-slate-400 tabular-nums dark:text-slate-500",
|
|
2988
|
-
children: [
|
|
2989
|
-
items.length,
|
|
2990
|
-
" / ",
|
|
2991
|
-
max2
|
|
2992
|
-
]
|
|
2993
|
-
}
|
|
2994
|
-
)
|
|
2995
|
-
]
|
|
2996
|
-
}
|
|
2997
|
-
)
|
|
2998
|
-
] });
|
|
2999
|
-
}
|
|
3000
|
-
|
|
3001
|
-
// src/component/list.tsx
|
|
3002
|
-
import { jsx as jsx31 } from "react/jsx-runtime";
|
|
3003
|
-
function List(props) {
|
|
3004
|
-
const empty = Array.isArray(props.field.fields) && props.field.fields.length === 0;
|
|
3005
|
-
return /* @__PURE__ */ jsx31(
|
|
3006
|
-
FieldSetBase,
|
|
3007
|
-
{
|
|
3008
|
-
description: props.field.description,
|
|
3009
|
-
empty,
|
|
3010
|
-
id: props.field.name,
|
|
3011
|
-
title: props.field.label,
|
|
3012
|
-
children: props.children
|
|
3013
|
-
}
|
|
3014
|
-
);
|
|
3015
|
-
}
|
|
3016
|
-
|
|
3017
|
-
// src/client/component/guard/list-guard.tsx
|
|
3018
|
-
import { jsx as jsx32 } from "react/jsx-runtime";
|
|
3019
|
-
function ListGuard({ children, field, value }) {
|
|
3020
|
-
return /* @__PURE__ */ jsx32(VisibilityGuard, { container: field, fields: field.fields, children: /* @__PURE__ */ jsx32(List, { field, children: /* @__PURE__ */ jsx32(FieldList, { field, value, children }) }) });
|
|
3021
|
-
}
|
|
3022
|
-
|
|
3023
|
-
// src/component/column.tsx
|
|
3024
|
-
import { twMerge as twMerge8 } from "tailwind-merge";
|
|
3025
|
-
import { jsx as jsx33, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
3026
|
-
function Column(props) {
|
|
3027
|
-
const cols2 = getColumn(props.column?.advanced?.cols);
|
|
3028
|
-
return /* @__PURE__ */ jsxs13("div", { className: "flex w-full flex-col gap-4", children: [
|
|
3029
|
-
/* @__PURE__ */ jsx33("div", { className: twMerge8("grid grid-cols-1 gap-3 sm:gap-4", cols2), children: props.children }),
|
|
3030
|
-
props.column?.description && /* @__PURE__ */ jsx33(
|
|
3031
|
-
FormattedDescription,
|
|
3032
|
-
{
|
|
3033
|
-
config: props.config,
|
|
3034
|
-
context: props.context,
|
|
3035
|
-
text: props.column.description,
|
|
3036
|
-
translations: props.translations
|
|
3037
|
-
}
|
|
3038
|
-
)
|
|
3039
|
-
] });
|
|
3040
|
-
}
|
|
3041
|
-
|
|
3042
|
-
// src/component/slot/slot-base.tsx
|
|
3043
|
-
import { Fragment as Fragment4 } from "react";
|
|
3044
|
-
|
|
3045
|
-
// src/component/slot/slot-list.tsx
|
|
3046
|
-
import { jsx as jsx34 } from "react/jsx-runtime";
|
|
3047
|
-
function SlotList(props) {
|
|
3048
|
-
const fields = Array.isArray(props.field.fields) ? props.field.fields.map((field) => {
|
|
3049
|
-
if (isField(field)) {
|
|
3050
|
-
return {
|
|
3051
|
-
...field,
|
|
3052
|
-
name: `${props.field.name}.${props.index}.${field.name}`
|
|
3053
|
-
};
|
|
3054
|
-
}
|
|
3055
|
-
if (isColumn(field)) {
|
|
3056
|
-
return {
|
|
3057
|
-
...field,
|
|
3058
|
-
fields: field.fields.map((columnField) => ({
|
|
3059
|
-
...columnField,
|
|
3060
|
-
name: `${props.field.name}.${props.index}.${columnField.name}`
|
|
3061
|
-
}))
|
|
3062
|
-
};
|
|
3063
|
-
}
|
|
3064
|
-
return field;
|
|
3065
|
-
}) : [];
|
|
3066
|
-
return /* @__PURE__ */ jsx34(
|
|
3067
|
-
SlotBase,
|
|
3068
|
-
{
|
|
3069
|
-
children: props.children,
|
|
3070
|
-
components: props.components,
|
|
3071
|
-
config: props.config,
|
|
3072
|
-
context: props.context,
|
|
3073
|
-
disabled: props.disabled,
|
|
3074
|
-
fields,
|
|
3075
|
-
style: props.style,
|
|
3076
|
-
translations: props.translations,
|
|
3077
|
-
value: props.value
|
|
3078
|
-
}
|
|
3079
|
-
);
|
|
3080
|
-
}
|
|
3081
|
-
|
|
3082
|
-
// src/component/slot/slot-base.tsx
|
|
3083
|
-
import { jsx as jsx35, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3084
|
-
function SlotBase(props) {
|
|
3085
|
-
const { field: Field3, list: List2 } = props.components;
|
|
3086
|
-
return prepare(props.fields).map((field, index) => /* @__PURE__ */ jsxs14(Fragment4, { children: [
|
|
3087
|
-
isColumn(field) && /* @__PURE__ */ jsx35(
|
|
3088
|
-
Column,
|
|
3089
|
-
{
|
|
3090
|
-
column: field,
|
|
3091
|
-
config: props.config,
|
|
3092
|
-
context: props.context,
|
|
3093
|
-
translations: props.translations,
|
|
3094
|
-
children: /* @__PURE__ */ jsx35(SlotBase, { ...props, fields: field.fields })
|
|
3095
|
-
}
|
|
3096
|
-
),
|
|
3097
|
-
isField(field) && /* @__PURE__ */ jsx35(Field3, { disabled: props.disabled, field, style: props.style, children: props.children }),
|
|
3098
|
-
isList(field) && /* @__PURE__ */ jsx35(List2, { field, value: props.value, children: (index2) => /* @__PURE__ */ jsx35(
|
|
3099
|
-
SlotList,
|
|
3100
|
-
{
|
|
3101
|
-
children: props.children,
|
|
3102
|
-
components: props.components,
|
|
3103
|
-
config: props.config,
|
|
3104
|
-
context: props.context,
|
|
3105
|
-
disabled: props.disabled,
|
|
3106
|
-
field,
|
|
3107
|
-
index: index2,
|
|
3108
|
-
style: props.style,
|
|
3109
|
-
translations: props.translations,
|
|
3110
|
-
value: props.value
|
|
3111
|
-
}
|
|
3112
|
-
) })
|
|
3113
|
-
] }, index));
|
|
3114
|
-
}
|
|
3115
|
-
|
|
3116
|
-
// src/component/slot/slot-create.tsx
|
|
3117
|
-
import { jsx as jsx36 } from "react/jsx-runtime";
|
|
3118
|
-
function createSlot(components) {
|
|
3119
|
-
const CreateSlot = (props) => /* @__PURE__ */ jsx36(SlotBase, { ...props, components });
|
|
3120
|
-
return CreateSlot;
|
|
3121
|
-
}
|
|
3122
|
-
|
|
3123
|
-
// src/client/component/slot/slot.tsx
|
|
3124
|
-
var Slot = createSlot({ field: Field2, list: ListGuard });
|
|
3125
|
-
|
|
3126
|
-
// src/client/hook/use-form-action.ts
|
|
3127
|
-
import { useSetAtom as useSetAtom4 } from "jotai";
|
|
3128
|
-
import { startTransition, useActionState } from "react";
|
|
3129
|
-
function useFormState(getSchema2, action, options) {
|
|
3130
|
-
const {
|
|
3131
|
-
onSuccess,
|
|
3132
|
-
preserveValues = false,
|
|
3133
|
-
validation = true,
|
|
3134
|
-
translations
|
|
3135
|
-
} = options ?? {};
|
|
3136
|
-
const setError = useSetAtom4(reportErrorAtom);
|
|
3137
|
-
const clearValues = useSetAtom4(clearAllValueAtom);
|
|
3138
|
-
const initialState = {
|
|
3139
|
-
data: null,
|
|
3140
|
-
error: null,
|
|
3141
|
-
success: false
|
|
3142
|
-
};
|
|
3143
|
-
const [state, formAction, isPending] = useActionState(
|
|
3144
|
-
async (prevState, formData) => {
|
|
3145
|
-
const [schemas, fields] = getSchema2();
|
|
3146
|
-
const schema = buildSchema(schemas, fields, translations);
|
|
3147
|
-
if (validation === false) {
|
|
3148
|
-
if (action) {
|
|
3149
|
-
return await action(formData, schema);
|
|
3150
|
-
}
|
|
3151
|
-
return prevState;
|
|
3152
|
-
}
|
|
3153
|
-
const form = getFormData(formData);
|
|
3154
|
-
const normalized = normalizeDateFields(form, fields);
|
|
3155
|
-
const validated = schema.safeParse(normalized);
|
|
3156
|
-
if (!validated.success) {
|
|
3157
|
-
const errors = flatten(validated.error);
|
|
3158
|
-
startTransition(() => {
|
|
3159
|
-
setError(errors);
|
|
3160
|
-
});
|
|
3161
|
-
return failure(form, {
|
|
3162
|
-
description: translate(
|
|
3163
|
-
"Please correct the errors and try again.",
|
|
3164
|
-
translations
|
|
3165
|
-
),
|
|
3166
|
-
details: [],
|
|
3167
|
-
title: translate(
|
|
3168
|
-
"There were validation errors submitting the form.",
|
|
3169
|
-
translations
|
|
3170
|
-
)
|
|
3171
|
-
});
|
|
3172
|
-
}
|
|
3173
|
-
const unflattened = unflatten(normalized);
|
|
3174
|
-
if (action) {
|
|
3175
|
-
try {
|
|
3176
|
-
const result = await action(unflattened, schema);
|
|
3177
|
-
if (!result.success) {
|
|
3178
|
-
return failure(unflattened, result.error);
|
|
3179
|
-
}
|
|
3180
|
-
onSuccess?.(result.data);
|
|
3181
|
-
if (!preserveValues) {
|
|
3182
|
-
startTransition(() => {
|
|
3183
|
-
clearValues();
|
|
3184
|
-
});
|
|
3185
|
-
}
|
|
3186
|
-
return success(unflattened, preserveValues);
|
|
3187
|
-
} catch (error) {
|
|
3188
|
-
logger.error("Error executing form action:", error);
|
|
3189
|
-
return failure(unflattened, {
|
|
3190
|
-
title: translate(
|
|
3191
|
-
"An unexpected error occurred submitting the form.",
|
|
3192
|
-
translations
|
|
3193
|
-
),
|
|
3194
|
-
details: buildError(error, translations)
|
|
3195
|
-
});
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
return success(validated.data, preserveValues);
|
|
3199
|
-
},
|
|
3200
|
-
initialState
|
|
3201
|
-
);
|
|
3202
|
-
return [formAction, state, isPending];
|
|
3203
|
-
}
|
|
3204
|
-
function buildError(error, translations) {
|
|
3205
|
-
if (error instanceof Error) {
|
|
3206
|
-
return [error.message];
|
|
3207
|
-
}
|
|
3208
|
-
return [translate("Unknown error", translations)];
|
|
3209
|
-
}
|
|
3210
|
-
function success(value, preserveValues = false) {
|
|
3211
|
-
const data = preserveValues ? value : null;
|
|
3212
|
-
return {
|
|
3213
|
-
data,
|
|
3214
|
-
error: null,
|
|
3215
|
-
success: true
|
|
3216
|
-
};
|
|
3217
|
-
}
|
|
3218
|
-
function failure(value, error) {
|
|
3219
|
-
return {
|
|
3220
|
-
data: value,
|
|
3221
|
-
error,
|
|
3222
|
-
success: false
|
|
3223
|
-
};
|
|
3224
|
-
}
|
|
3225
|
-
function normalizeDateFields(form, fields) {
|
|
3226
|
-
const result = { ...form };
|
|
3227
|
-
for (const field of fields) {
|
|
3228
|
-
if (isDate(field) && typeof result[field.name] === "string" && result[field.name]) {
|
|
3229
|
-
const native = toNativeDate(
|
|
3230
|
-
result[field.name],
|
|
3231
|
-
getDateFormat(field)
|
|
3232
|
-
);
|
|
3233
|
-
if (native) {
|
|
3234
|
-
result[field.name] = native;
|
|
3235
|
-
}
|
|
3236
|
-
}
|
|
3237
|
-
}
|
|
3238
|
-
return result;
|
|
3239
|
-
}
|
|
3240
|
-
|
|
3241
|
-
// src/client/hook/use-schema.ts
|
|
3242
|
-
import { useCallback as useCallback8, useRef as useRef6 } from "react";
|
|
3243
|
-
|
|
3244
|
-
// src/client/hook/use-store.ts
|
|
3245
|
-
import { useCallback as useCallback7 } from "react";
|
|
3246
|
-
import { useSetAtom as useSetAtom5 } from "jotai";
|
|
3247
|
-
function useStore2() {
|
|
3248
|
-
const clearErrors = useSetAtom5(clearInputErrorAtom);
|
|
3249
|
-
const clearValues = useSetAtom5(clearInputValueAtom);
|
|
3250
|
-
const clearSources = useSetAtom5(clearInputSourceAtom);
|
|
3251
|
-
return useCallback7(
|
|
3252
|
-
(names, options) => {
|
|
3253
|
-
const target = Array.isArray(names) ? names : [names];
|
|
3254
|
-
clearErrors(target);
|
|
3255
|
-
clearSources(target);
|
|
3256
|
-
if (!options?.keepValue) {
|
|
3257
|
-
clearValues(target);
|
|
3258
|
-
}
|
|
3259
|
-
},
|
|
3260
|
-
[clearErrors, clearSources, clearValues]
|
|
3261
|
-
);
|
|
3262
|
-
}
|
|
3263
|
-
|
|
3264
|
-
// src/client/hook/use-schema.ts
|
|
3265
|
-
function useSchema() {
|
|
3266
|
-
const clear = useStore2();
|
|
3267
|
-
const schemaRef = useRef6({});
|
|
3268
|
-
const fieldsRef = useRef6([]);
|
|
3269
|
-
const onMount = useCallback8((name, schema, field) => {
|
|
3270
|
-
if (!(name in schemaRef.current)) {
|
|
3271
|
-
schemaRef.current[name] = schema;
|
|
3272
|
-
fieldsRef.current.push(field);
|
|
3273
|
-
}
|
|
3274
|
-
}, []);
|
|
3275
|
-
const onUnmount = useCallback8(
|
|
3276
|
-
(name, options) => {
|
|
3277
|
-
if (schemaRef.current[name]) {
|
|
3278
|
-
delete schemaRef.current[name];
|
|
3279
|
-
fieldsRef.current = fieldsRef.current.filter((field) => {
|
|
3280
|
-
return field.name !== name;
|
|
3281
|
-
});
|
|
3282
|
-
clear([name], {
|
|
3283
|
-
keepValue: options?.keepValue
|
|
3284
|
-
});
|
|
3285
|
-
}
|
|
3286
|
-
},
|
|
3287
|
-
[clear]
|
|
3288
|
-
);
|
|
3289
|
-
const getSchema2 = useCallback8(() => {
|
|
3290
|
-
return [schemaRef.current, fieldsRef.current];
|
|
3291
|
-
}, []);
|
|
3292
|
-
return [getSchema2, onMount, onUnmount];
|
|
3293
|
-
}
|
|
3294
|
-
|
|
3295
|
-
// src/client/component/form-content.tsx
|
|
3296
|
-
import { Fragment as Fragment5, jsx as jsx37, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
3297
|
-
function FormContent(props) {
|
|
3298
|
-
const translations = props.translations?.[props.lang ?? ""];
|
|
3299
|
-
const [schema, onMount, onUnmount] = useSchema();
|
|
3300
|
-
const [action, state, isPending] = useFormState(schema, props.action, {
|
|
3301
|
-
onSuccess: props.onSuccess,
|
|
3302
|
-
validation: props.config.validation.submit,
|
|
3303
|
-
translations
|
|
3304
|
-
});
|
|
3305
|
-
const isShowingError = props.config.validation.showError && !state.success && state.error;
|
|
3306
|
-
const value = state.data ?? props.value;
|
|
3307
|
-
return /* @__PURE__ */ jsxs15(Fragment5, { children: [
|
|
3308
|
-
isShowingError && renderIfExists(props.config.alert, (Alert) => /* @__PURE__ */ jsx37("div", { className: "mb-4 w-full", children: /* @__PURE__ */ jsx37(
|
|
3309
|
-
Alert,
|
|
3310
|
-
{
|
|
3311
|
-
description: state.error?.description,
|
|
3312
|
-
details: state.error?.details,
|
|
3313
|
-
title: state.error.title
|
|
3314
|
-
}
|
|
3315
|
-
) })),
|
|
3316
|
-
/* @__PURE__ */ jsx37(
|
|
3317
|
-
Form,
|
|
3318
|
-
{
|
|
3319
|
-
action,
|
|
3320
|
-
advanced: props.advanced,
|
|
3321
|
-
config: props.config,
|
|
3322
|
-
control: props.children,
|
|
3323
|
-
definition: props.definition,
|
|
3324
|
-
isPending,
|
|
3325
|
-
noValidate: true,
|
|
3326
|
-
readOnly: props.readOnly,
|
|
3327
|
-
sections: props.sections,
|
|
3328
|
-
children: ({ disabled, fields }) => /* @__PURE__ */ jsx37(
|
|
3329
|
-
Slot,
|
|
3330
|
-
{
|
|
3331
|
-
config: props.config,
|
|
3332
|
-
context: props.context,
|
|
3333
|
-
disabled,
|
|
3334
|
-
fields,
|
|
3335
|
-
style: props.config.style,
|
|
3336
|
-
translations,
|
|
3337
|
-
value,
|
|
3338
|
-
children: (internal) => /* @__PURE__ */ jsx37(
|
|
3339
|
-
Input,
|
|
3340
|
-
{
|
|
3341
|
-
...internal,
|
|
3342
|
-
config: props.config,
|
|
3343
|
-
context: props.context,
|
|
3344
|
-
onMount,
|
|
3345
|
-
onUnmount,
|
|
3346
|
-
onValueChange: props.onValueChange,
|
|
3347
|
-
translations,
|
|
3348
|
-
value
|
|
3349
|
-
}
|
|
3350
|
-
)
|
|
3351
|
-
}
|
|
3352
|
-
)
|
|
3353
|
-
}
|
|
3354
|
-
)
|
|
3355
|
-
] });
|
|
3356
|
-
}
|
|
3357
|
-
|
|
3358
|
-
// src/client/component/form.tsx
|
|
3359
|
-
import { Provider } from "jotai";
|
|
3360
|
-
import { jsx as jsx38 } from "react/jsx-runtime";
|
|
3361
|
-
function Form2(props) {
|
|
3362
|
-
return /* @__PURE__ */ jsx38(Provider, { children: /* @__PURE__ */ jsx38(FormContent, { ...props }) });
|
|
3363
|
-
}
|
|
3364
|
-
export {
|
|
3365
|
-
Form2 as Form
|
|
3366
|
-
};
|
|
1
|
+
import{jsx as ni}from"react/jsx-runtime";function _t(e){let t=typeof e.children=="function"?e.children({isPending:e.isPending}):e.children;return ni("div",{"data-slot":"field-control",className:"w-full",children:t})}import{jsx as $t}from"react/jsx-runtime";function W(e){return $t("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:$t("path",{fillRule:"evenodd",d:"M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})})}import{Activity as oi}from"react";import{createContext as ri}from"react";var Ce=ri(!1);import{jsx as zt}from"react/jsx-runtime";function ue({children:e,visible:t}){return zt(oi,{mode:t?"visible":"hidden",children:zt(Ce,{value:!0,children:e})})}var Fe="input",Gt="input/date",Ht="input/email",Bt="input/number";var Ut="input/time";var Yt="textarea",Xt="radio",Zt="checkbox",ct="list";var qt="select",Wt="select/day",Kt="select/month",Jt="select/timezone",Qt="select/year";var jt="chips",en="chips/day",tn="chips/month",de="column",nn="description",ut="fields",rn="label",V="value",Ae="options",dt="email",on="number",an="password",ln="tel",me="text",sn="aria-errormessage",cn="aria-invalid",un="data-invalid",dn="data-readonly",mn="aria",fn="data",Ne="max",pn="maxLength",ke="min",gn="minLength",re="$ref";var yn="source",xn="state",Ie="http://luna.internal";var bn="type",hn={Africa:"Africa",America:"Americas",Asia:"Asia / Pacific",Atlantic:"Atlantic",Australia:"Asia / Pacific",Europe:"Europe",Indian:"Asia / Pacific",Pacific:"Asia / Pacific"};function d(e){return e!==null&&Object.prototype.toString.call(e)==="[object Object]"}function Ee(e){return e==null||e===""}function _(e){return x(e)||typeof e=="number"||mt(e)}function x(e){return typeof e=="string"}function Tn(e){return d(e)&&"url"in e}function mt(e){return typeof e=="boolean"}var ii=/^\d+$/;function pt(e,t=[],n=V){return Array.isArray(t)?t.find(r=>{let o=gt(r,n);if(o!==void 0&&`${o}`===e)return r})??{value:e}:{value:e}}function gt(e,t=V){if(e!=null){if(Array.isArray(e)&&e.every(_)||_(e))return e;if(d(e)){let n=ai(e,t);if(_(n))return n}}}function ai(e,t){let n=F(e,t);if(_(n))return n}function Sn(e,t){if(Array.isArray(e))return e;let n=F(e,t);return Array.isArray(n)?n:null}function F(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 Rn(e,t={description:nn,label:rn,value:V}){return e.map(n=>{if(d(n)){let r=F(n,t.label),o=F(n,t.value);if(_(r)&&_(o)){let i=F(n,t.description);return{label:`${r}`,value:`${o}`,..._(i)&&{description:`${i}`}}}}return n})}function vn(e=me){let t=e.lastIndexOf("/"),n=t===-1?e:e.slice(t+1);return n&&n!==Fe?n.trim().toLowerCase():me}function Cn(e){let t={};for(let n of e.keys()){let r=e.getAll(n);t[n]=r.length>1?r:r[0]}return t}function Fn(e){let t={};for(let n of Object.keys(e)){let r=n.split(".");if(r.length===1){t[n]=e[n];continue}let o=t;for(let a=0;a<r.length-1;a++){let l=r[a],s=r[a+1],c=ii.test(s);l in o||(o[l]=c?[]:{}),o=o[l]}let i=r[r.length-1];o[i]=e[n]}return ft(t),t}function ft(e){for(let t of Object.keys(e)){let n=e[t];if(Array.isArray(n)){let r=n.filter(o=>o!==void 0);for(let o of r)d(o)&&ft(o);e[t]=r}else d(n)&&ft(n)}}var li=/\[([^\]]{1,500})\]\(([^)]{1,2000})\)/g;function Y(e,t={}){if(x(e))return si(e,t);if(Array.isArray(e))return e.map(n=>Y(n,t));if(d(e)){let n={};for(let r in e)n[r]=Y(e[r],t);return n}return e}function pe(e,t={}){return fe(e)?Y(e,t):e}function fe(e){return x(e)?/{([^}]{1,200})}/.test(e):Array.isArray(e)?e.some(t=>fe(t)):d(e)?Object.values(e).some(t=>fe(t)):!1}function si(e,t={}){return e.replace(/{([^}]{1,200})}/g,(n,r)=>{let o=r.includes(".")?F(t,r):t[r];return _(o)?String(o):n})}function An(e,t){if(!x(e)||!e||e.trim().length===0)return null;let n,r=0,o=!1,i=[];for(;(n=li.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 ge={error:(...e)=>{yt()&&!xt()&&we().error("[Luna Form]",...e)},warn:(...e)=>{yt()&&!xt()&&we().warn("[Luna Form]",...e)},info:(...e)=>{yt()&&!xt()&&we().info("[Luna Form]",...e)}},yt=()=>typeof we()<"u",xt=()=>!0,we=()=>globalThis.console;function Nn(e=[],t){let n=[],r=[],o=[];for(let i of e)i.action===V&&n.push(i),i.action===yn&&r.push(i),i.action===xn&&o.push(i);t({sources:r,states:o,values:n})}function kn(e=null,t=[],n){for(let r of t){let{target:o,source:i}=r;if(!e){n(o,void 0);continue}if(Tn(i)){let a=Y(i.url,e),l=i.body?Y(i.body,e):i.body;n(o,{...i,url:a,body:l})}}}var ye={eq:fi,gt:xi,gte:bi,in:gi,lt:hi,lte:Ti,neq:pi,nin:yi},ci=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,In=/^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;function ui(e){return typeof e=="string"&&ci.test(e)}function di(e){return typeof e=="string"&&In.test(e)}function mi(e){let t=e.match(In);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 X(e){return ui(e)?new Date(e).getTime():di(e)?mi(e):Number(e)}function fi(e,t){return e===t}function pi(e,t){return e!==t}function gi(e,t){return Array.isArray(t)&&t.includes(String(e))}function yi(e,t){return Array.isArray(t)&&!t.includes(String(e))}function xi(e,t){return X(e)>X(t)}function bi(e,t){return X(e)>=X(t)}function hi(e,t){return X(e)<X(t)}function Ti(e,t){return X(e)<=X(t)}function En(e=null,t=[],n){for(let r of t){let{target:o,state:i,when:a}=r,l=Array.isArray(o)?o:[o];if(!e){n(l);continue}let s=Si(e,a);n(l,s?i:void 0)}}function Si(e,t){return t===void 0?!0:x(t)?Pe(e,V)===t:mt(t)?!!Pe(e,V)===t:Array.isArray(t)?t.includes(String(Pe(e,V))):Ri(e,t)}function Ri(e=null,t){let n=Pe(e,t.field??V),{operator:r="eq",value:o}=t,i=ye[r];return i?i(n,o):!1}function Pe(e,t){return d(e)?F(e,t):e}function wn(e=null,t=[],n){for(let r of t)for(let[o,i]of Object.entries(r.value))n(o,e?Y(i,e):void 0)}var Pn=e=>h(Wt)(e),De=e=>h(Kt)(e),Le=e=>h(Qt)(e),Dn=e=>h(Jt)(e),Ln=e=>h(en)(e),Vn=e=>h(tn)(e),O=h(Gt),z=h(Ut),E=h(Zt),K=h(jt),G=h(Xt),bt=h(Fe),Z=h(qt),ht=h(Yt),On=h(me,dt,an,ln),Mn=h(Ht,dt),Ve=h(Bt,on);function Oe(e){return G(e)||E(e)}function _n(e){return e.type===ct}function q(e){return e.type===de}function Me(e){return e.type!==de&&e.type!==ct}function xe(e){return Z(e)||G(e)||K(e)}function $n(e){return bt(e)||ht(e)}function T(e){return e!=null&&e!==""}function h(...e){return t=>{let n=x(t.type)?t.type:void 0;return n?e.some(r=>n===r||n?.startsWith(`${r}/`)):!1}}function zn(e,t={}){if(Z(e)&&e.disabled){let n=e.name?t?.[e.name]:void 0;if(n&&d(n))return[n]}}function Gn(e){return G(e)||E(e)?!0:e.advanced?.horizontal??!1}function Hn(e){return E(e)?e.advanced?.reverse!==!1:!1}function Bn(e,t){let n=e.readonly??!1;return t||n}function Un(e){if(G(e)||K(e)||Z(e)&&!e.disabled){let t=e.source;if(Array.isArray(t)||d(t)&&!(re in t))return t}}import{isValid as _e,parse as $e,format as ze}from"date-fns";var vi=/^\d+$/,Ge=new Date(2e3,0,1),Ci=()=>"supportedValuesOf"in Intl?Intl.supportedValuesOf("timeZone"):[];function Tt(){return Array.from({length:12},(e,t)=>({value:(t+1).toString(),label:new Date(0,t).toLocaleString("default",{month:"long"})}))}function St(){return Array.from({length:7},(e,t)=>({value:t.toString(),label:new Date(2e3,0,2+t).toLocaleString("default",{weekday:"long"})}))}function Zn(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 Rt(){return new Date().getFullYear()}function Fi(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function Ai(e){let t=e.indexOf("/"),n=t===-1?e:e.slice(0,t);return hn[n]??"Other"}function Ni(e,t){return(e.find(r=>r.type==="timeZoneName")?.value??t).replace(/\s+(?:Standard|Daylight(?: Saving)?|Summer|Winter)\s+Time$/,"")}function Yn(e,t){let n=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"longOffset"}).formatToParts(t),r=new Intl.DateTimeFormat("en",{timeZone:e,timeZoneName:"long"}).formatToParts(t),i=(n.find(l=>l.type==="timeZoneName")?.value??"GMT+00:00").replace("GMT","UTC"),a=Ni(r,e);return{offset:i,longName:a}}function Xn(e){return e.slice(e.lastIndexOf("/")+1).replace(/_/g," ")}function qn(){let e=new Date,t=Fi(),n=new Map,r=Xn(t),{offset:o,longName:i}=Yn(t,e),a={value:t,label:`${r} - ${i} (${o})`};for(let s of Ci()){if(s===t)continue;let c=Xn(s),{offset:u,longName:m}=Yn(s,e),y={value:s,label:`${c} - ${m} (${u})`},f=Ai(s);if(f==="Other")continue;let C=n.get(f);C?C.push(y):n.set(f,[y])}for(let s of n.values())s.sort((c,u)=>c.label.localeCompare(u.label));let l=Array.from(n.entries()).sort(([s],[c])=>s.localeCompare(c)).map(([s,c])=>({label:s,items:c}));return[{label:"Suggested",items:[a]},...l]}function vt(e,t){if(typeof e=="number")return e;let n=t??Rt(),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 vi.test(r)?parseInt(r,10):n}function He(e,t){if(!e)return"";try{let n=$e(e,t,Ge);return _e(n)?ze(n,"yyyy-MM-dd"):""}catch{return""}}function Wn(e,t){if(!e)return"";try{let n=$e(e,t,Ge);return _e(n)?ze(n,"HH:mm:ss"):""}catch{return""}}function Kn(e,t="HH:mm"){if(!e)return"";try{let n=e.split(":").length===3?"HH:mm:ss":"HH:mm",r=$e(e,n,Ge);return _e(r)?ze(r,t):""}catch{return""}}function Be(e,t="MMMM d, yyyy"){if(!e)return"";try{let n=$e(e,"yyyy-MM-dd",Ge);return _e(n)?ze(n,t):""}catch{return""}}function J(e){return e.advanced?.format??"HH:mm"}function H(e){return e.advanced?.format??"MMMM d, yyyy"}var Ue=Rt();function ki(e){if(K(e))return Ii(e)}function Ii(e){if(Ln(e))return St();if(Vn(e))return Tt()}function Ei(e){if(Z(e))return wi(e)}function wi(e){if(Pn(e))return St();if(De(e))return Tt();if(Le(e)){let t=e.advanced?.length?.min??Ue,n=e.advanced?.length?.max??Ue+5;return Zn(vt(t,Ue),vt(n,Ue))}if(Dn(e))return qn()}function Jn(e,t=!1){let n={disabled:t,id:e.name,name:e.name,placeholder:e.placeholder,required:e.required};return bt(e)?{...n,...Pi(e)}:Z(e)?{...n,...Qn(e,Ei)}:ht(e)?{...n,...Li(e)}:K(e)?{...n,...Di(e)}:n}function Pi(e){let t=vn(e.type),n={...e,type:t};return{...Oi(e),...jn(e),...Vi(n),...On(n)?er(n):{},type:t}}function Qn(e,t){let n=t(e);return n?{options:n}:{}}function Di(e){let t=Qn(e,ki),n=e.advanced?.multiple??!0;return{...t,multiple:n}}function Li(e){return{...jn(e),...er(e)}}function jn(e){let t=e.advanced?.autocomplete;return t?{autoComplete:t}:{}}function Vi(e){return Ve(e)?Mi(e):{}}function Oi(e){if(z(e)){let t=J(e);return{step:t==="HH:mm:ss"||t==="hh:mm:ss a"?"1":"60"}}return{}}function er(e){return tr(e,{min:gn,max:pn})}function Mi(e){return tr(e,{min:ke,max:Ne})}function tr(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 nr(e,t){let n=Un(e);return n||zn(e,t)}function _i(e,t){let n=d(t)&&e.name in t?t[e.name]:t,r=gt(n,e.advanced?.entity);return z(e)&&T(r)?$i(e,r):O(e)&&T(r)?Bi(e,r):r}function $i(e,t){let n=J(e);return x(t)?Wn(t,n):t}function zi(e,t,n){return xe(e)&&Array.isArray(n)?{...t,[Ae]:n}:t}function Gi(e,t,n){if(e.required&&!T(n)&&Z(e)&&e.advanced?.preselected!==!1&&Ae in t){let r=t[Ae];if(Array.isArray(r)&&r.length===1)return r[0]}return n}function Hi(e,t){return xe(e)&&Array.isArray(t)?Rn(t,e.advanced?.options):t}function rr(e,t,n,r){let o=_i(e,r),i=Array.isArray(n)?Hi(e,n):n,a=zi(e,t,i),l=Gi(e,a,o);return{commonPropsWithOptions:a,defaultValue:l}}function or(e,t){return E(e)?{checked:T(t)?t:!1}:K(e)?{value:Array.isArray(t)?t:[]}:O(e)&&x(t)&&T(t)?{value:Be(t,H(e))}:{value:t??""}}function Bi(e,t){let n=H(e);return x(t)?He(t,n):t}function ir(e,t){let n=e??t;return n?{"data-format":n}:{}}var Ui=/^#\/definition\//;function Xe(e=[],t){let n=Ye(e,t);return Array.isArray(n)?n.filter(Xi).sort((r,o)=>ar(r)-ar(o)):[]}function Ye(e,t,n=new Map,r=new WeakSet){if(!Yi(t)||!e||typeof e!="object")return e;if(n.has(e))return n.get(e);if(r.has(e))return e;if(r.add(e),Array.isArray(e))return e.map(i=>Ye(i,t,n,r));if(re in e&&x(e[re])){let i=e[re].replace(Ui,""),a=F(t,i);return a!==null?Ye(a,t,n,r):e}let o={};for(let[i,a]of Object.entries(e))o[i]=Ye(a,t,n,r);return r.delete(e),n.set(e,o),o}function lr(e){return Object.entries(e??{})}function ar(e){return e.order??Number.MAX_VALUE}function Yi(e){return e!==void 0&&d(e)&&Object.keys(e).length>0}function Xi(e){return bn in e?!0:Array.isArray(e[ut])?e[ut].length>0:!0}function sr(e,t){let n={};for(let[r,o]of lr(t))n[`${e}-${r}`]=o;return n}function Zi(e){return sr(mn,e)}function qi(e){return sr(fn,e)}function cr(e,t){let n=Zi(e.advanced?.aria);return t&&t.length>0&&(n[cn]="true",n[sn]=`${e.name}-error`),n}function ur(e){return qi(e.advanced?.data)}var dr={1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3"},mr={1:"md:col-span-1",2:"md:col-span-2",3:"md:col-span-3"};function fr(e,t=2){return dr[e&&e in dr?e:t]}function pr(e){if(e&&e in mr)return mr[e]}function Wi(e,t){let n=e.advanced?.length?.min??1;if(t){let r=F(t,e.name);if(Array.isArray(r))return Math.max(r.length,n)}return Math.max(n,0)}function gr(e){return!Array.isArray(e.fields)||e.fields.length===0?!1:e.fields.length>1||e.fields[0].type===de}function yr(e,t){let n=Wi(e,t);return Array.from({length:n},(r,o)=>o)}function xr(e){return e.label??e.name}import{z as g}from"zod";function p(e,t){return e?t?t[e]??e:e:""}var Ki=[[Ve,ta],[Mn,Ji],[Le,na],[De,ra],[E,Qi],[G,ji]];function hr(e,t=[],n){let r=g.object(e);return t.length===0?r:la(r,t,n)}function Tr(e){let t={},n=g.flattenError(e).fieldErrors;for(let[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t}function Sr(e,t){for(let[n,r]of Ki)if(n(e))return r(e,t);return ea(e,t)}function Ji(e,t){let n=g.string().trim();if(e.required){let r=oe(e,t),o=n.min(1,r).pipe(br(e,t));return g.preprocess(i=>Ee(i)?"":i,o)}return n.pipe(br(e,t)).or(g.literal("")).nullable()}function Qi(e,t){let n=g.coerce.boolean();return e.required?(n=n.refine(r=>r===!0,{message:oe(e,t)}),g.preprocess(r=>r===null?!1:r,n)):n.nullable()}function ji(e,t){let n=g.coerce.string();return e.required?(n=n.min(1,oe(e,t)),g.preprocess(r=>Ee(r)?"":r,n)):n.or(g.literal("")).nullable()}function ea(e,t){let n=g.coerce.string().trim();return n=Rr(n,e,t),e.required?(n=vr(n,e,t),g.preprocess(r=>Ee(r)?"":r,n)):n.nullable()}function ta(e,t){let n=g.coerce.number().int();return n=Rr(n,e,t),e.required?(n=vr(n,e,t),g.preprocess(r=>r===null?void 0:r,n)):n.nullable()}function na(e,t){return e.required?g.preprocess(oa,g.coerce.number({message:oe(e,t)}).int()):g.coerce.number().int().nullable()}function ra(e,t){let n=oe(e,t),r=g.coerce.number().int().min(1,n).max(12,n);return e.required?r:r.nullable()}function oa(e){return e===null||e===""?void 0:e}function br(e,t){let n=e.validation?.email?p(e.validation?.email,t):void 0;return g.email(n)}function Rr(e,t,n){return e=ia(e,t,n),e=aa(e,t,n),e}function vr(e,t,n){let r=t.advanced?.length?.min;return r===void 0||r<1?e.min(1,oe(t,n)):e}var ia=(e,t,n)=>Cr(e,t,ke,n),aa=(e,t,n)=>Cr(e,t,Ne,n);function Cr(e,t,n,r){let o=t.advanced?.length?.[n];if(o!==void 0){let i=t.validation?.length?.[n]?p(t.validation?.length?.[n],r):void 0;return e[n](o,i)}return e}function la(e,t=[],n){let r=ca(t);return r.length===0?e:e.superRefine((o,i)=>{for(let{name:a,rule:l}of r)if(!sa(o,a,l)){let s=p(l.message,n);i.addIssue({code:"custom",message:s,path:[a]})}})}function sa(e,t,n){let r=n.operator??"eq",o=ye[r];return o?o(e[t],e[n.field]):!1}function ca(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 Fr(e,t,n,r){let o=[],i=Array.isArray(t)?t:[t];for(let a of i){let l=a.operator??"eq",s=ye[l];if(s&&!s(e,n(a.field))&&a.message){let c=p(a.message,r);o.push(c)}}return o}function oe(e,t){return e.validation?.required?p(e.validation?.required,t):void 0}function Ar(e,t){if(!t||!da(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||ua(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 ua(e){return e==="https"?"443":"80"}function da(e){return/^(https?:)?\/\//.test(e)}function Nr(e,t){try{if(!e)return t;if(!t)return e;let n=new URL(e,Ie);new URL(t,Ie).searchParams.forEach((i,a)=>{n.searchParams.set(a,i)});let o=n.toString();return e.startsWith("/")||!e.includes("://")?o.replace(Ie,""):o}catch{return t||e}}function kr(e){return!Array.isArray(e)||e.length===0?null:e.reduce((t,n)=>{let r=Nr(t.url,n.url),o=ma(t,n),i=fa(t,n);return{...t,...n,url:r,body:o,headers:i}})}function ma(e,t){return d(t.body)&&d(e?.body)?{...e.body,...t.body}:t.body??e?.body}function fa(e,t){return d(t.headers)&&d(e?.headers)?{...e.headers,...t.headers}:t.headers??e?.headers}function Ze(e,t){return{...e,...t}}import{jsx as pa}from"react/jsx-runtime";function B(e){return An(e,(t,n,r)=>pa("a",{className:"underline",href:n,rel:"noopener noreferrer",target:"_blank",children:r},`${n}-${t}`))}import{useCallback as ga,useState as ya}from"react";import{jsx as be,jsxs as Ct}from"react/jsx-runtime";function Ir(e){let{fields:t=[]}=e.section,[n,r]=ya(!1),o=ga(()=>r(i=>!i),[]);return Ct("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:[be("legend",{children:Ct("button",{className:"flex cursor-pointer items-center gap-2 text-base font-medium text-slate-600 dark:text-slate-400",onClick:o,type:"button",children:[be(W,{expanded:n}),be("span",{children:B(e.section.title)})]})}),be(ue,{visible:n,children:Ct("div",{className:"mt-3 ml-1.5 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&&be("p",{className:"text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:B(e.section.description)}),e.group]})})]})}import{jsx as qe,jsxs as Er}from"react/jsx-runtime";function wr(e){let t=Er("div",{className:"flex flex-col",children:[e.title&&qe("legend",{className:"mb-3 font-medium text-slate-800 dark:text-slate-200",children:B(e.title)}),e.description&&qe("p",{className:"-mt-2 text-sm leading-normal font-normal text-slate-600 dark:text-slate-400",children:B(e.description)})]});return e.step?Er("div",{className:"flex flex-row items-start gap-4",children:[qe("div",{className:"bg-primary text-primary-foreground flex h-6 w-6 shrink-0 items-center justify-center rounded-full",children:qe("span",{className:"text-sm font-bold",children:e.step})}),t]}):t}import{jsx as xa,jsxs as ba}from"react/jsx-runtime";function We(e){return ba("fieldset",{className:"flex flex-col data-[empty=false]:gap-6","data-empty":e.empty,"data-slot":"field-set",id:e.id,children:[xa(wr,{description:e.description,step:e.step,title:e.title}),e.children]})}import{jsx as ha}from"react/jsx-runtime";function Q(e){return ha("div",{"data-slot":"field-group","data-compact":e.compact,className:"flex w-full flex-col gap-8 data-[compact=true]:gap-3",children:e.children})}import{jsx as Ft}from"react/jsx-runtime";function Pr(e){let{fields:t=[]}=e.section,n=e.advanced?.step?e.step:void 0,{compact:r}=Ze(e.style,{compact:e.section.advanced?.compact}),o=Ft(Q,{compact:r,children:e.children});return!e.section.title&&!e.section.description?o:e.section.advanced?.collapsible?Ft(Ir,{section:e.section,group:o}):Ft(We,{description:e.section.description,empty:t.length===0,id:e.section.id?.toString(),step:n,title:e.section.title,children:o})}import{jsx as Dr}from"react/jsx-runtime";function Lr(){return Dr("div",{"data-slot":"field-separator",className:"relative -my-2 h-5 text-sm",children:Dr("div",{className:"absolute inset-0 top-1/2 h-px w-full bg-slate-200 dark:bg-slate-800"})})}import{useAtomValue as Ca}from"jotai";import{atom as j}from"jotai";import{atomFamily as Vr}from"jotai-family";import{deepEqual as At}from"fast-equals";function Ke(e,t){let{[t]:n,...r}=e;return r}function Ta(e){return Vr(t=>j(n=>n(e)[t]??void 0,(n,r,o)=>{let i=n(e);if(o!=null){let a=i[t];At(a,o)||r(e,{...i,[t]:o})}else t in i&&r(e,Ke(i,t))}))}function Sa(e){return j(null,(t,n)=>{let r=t(e);r&&Object.keys(r).length>0&&n(e,{})})}function Ra(e){return j(null,(t,n,r)=>{let i={...t(e)},a=!1;for(let l of r)l in i&&(delete i[l],a=!0);a&&n(e,i)})}function va(e){return j(null,(t,n,r)=>{let o=t(e);At(o,r)||n(e,r)})}function Or(e,t={}){let{merge:n,validateTarget:r}=t;return Vr(o=>j(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 m=u[o];(!m||!At(m,s))&&(u[o]=s,a(e,{...c,[l]:u}))}else o in u&&(delete u[o],Object.keys(u).length===0?a(e,Ke(c,l)):a(e,{...c,[l]:u}))}))}function Mr(e){return j(null,(t,n,r)=>{let i={...t(e)},a=!1;for(let l of r)l in i&&(delete i[l],a=!0);for(let l in i){let s={...i[l]},c=!1;for(let u of r)u in s&&(delete s[u],c=!0,a=!0);c&&(Object.keys(s).length===0?delete i[l]:i[l]=s)}a&&n(e,i)})}function ie(e={}){let t=j(e);return{atom:t,clearAll:Sa(t),clear:Ra(t),bulkReport:va(t),report:Ta(t)}}var _r=ie(),Je=_r.atom,$r=_r.report;function Fa(e,t){return e.fields.every(n=>zr(n,t))}function zr(e,t){return t[e.name]?.hidden??e.hidden??!1}function Aa(e,t){return q(e)?Fa(e,t):zr(e,t)}function Qe(e){let t=Ca(Je);return e.container&&(t[e.container.name]?.hidden??e.container.hidden??!1)||e.fields.length===0||e.fields.every(r=>Aa(r,t))?null:e.children}import{jsx as he,jsxs as Gr}from"react/jsx-runtime";function Hr(e){let t=Xe(e.sections,e.definition);return he("div",{className:"h-full w-full",children:he("form",{noValidate:e.noValidate,action:e.action,children:Gr(Q,{children:[t.map((n,r)=>Gr(Qe,{fields:n.fields??[],children:[he(Pr,{advanced:e.advanced,section:n,step:r+1,style:e.config.style,children:e.children({disabled:e.readOnly,fields:n.fields})}),n.advanced?.separator&&he(Lr,{})]},`key-${n.id}-${r}`)),e.control&&he(_t,{isPending:e.isPending,children:e.control})]})})})}import{jsx as Na}from"react/jsx-runtime";function Br(e){return Na("p",{className:"-mt-2 text-xs leading-normal font-normal text-slate-600 dark:text-slate-400",children:e.children})}import{useState as ka}from"react";import{jsx as Ur,jsxs as Yr}from"react/jsx-runtime";function ae(e){let t={context:e.context,env:e.config?.env},[n,r]=ka(()=>d(e.text)&&"collapsed"in e.text?!e.text.collapsed:!0),o=()=>r(l=>!l),i=d(e.text)&&x(e.text.title)?B(p(pe(e.text.title,t),e.translations)):void 0,a=B(p(pe(x(e.text)?e.text:e.text?.message,t),e.translations));return a?Yr("div",{className:"flex flex-col gap-2",children:[i&&Yr("button",{className:"flex items-center gap-1 text-left text-xs font-medium text-slate-700 hover:text-slate-900 dark:text-slate-300 dark:hover:text-slate-100",onClick:o,type:"button",children:[i,Ur(W,{expanded:n})]}),n&&Ur(Br,{children:a})]}):null}import{twMerge as Ia}from"tailwind-merge";import{jsx as Ea,jsxs as wa}from"react/jsx-runtime";function Xr(e){let t=e.style?.showOptionalLabel??!0,n=G(e.field)||E(e.field);return wa("label",{"data-slot":"field-label","data-normal":n,className:Ia("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&&Ea("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:p("(Optional)",e.translations)})]})}import{jsx as Zr,jsxs as Pa}from"react/jsx-runtime";function qr(e){let t={context:e.context,env:e.config?.env},n=pe(e.field.label,t);return Pa("div",{"data-slot":"field-content",className:"flex w-full flex-1 flex-col gap-1.5 leading-snug",children:[Zr(Xr,{field:e.field,style:e.config?.style,translations:e.translations,children:p(n,e.translations)}),e.horizontal===!0&&Zr(ae,{config:e.config,context:e.context,text:e.field.description,translations:e.translations})]})}import{Fragment as Da,jsx as Wr,jsxs as La}from"react/jsx-runtime";function Kr(e){return La(Da,{children:[e.field.name&&e.field.label&&Wr(qr,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations}),e.children,e.horizontal===!1&&Wr(ae,{config:e.config,context:e.context,text:e.field.description,translations:e.translations})]})}function je(e,t){return e?t(e):null}import{useCallback as Ka,useEffect as Ja,useRef as Qa}from"react";var Nt=ie(),Jr=Nt.clear,Qr=Nt.bulkReport,et=Nt.report;var tt=ie(),nt=tt.atom,jr=tt.clearAll,eo=tt.clear,le=tt.report;import{useCallback as oo,useRef as rt,useTransition as Ga}from"react";import{useContext as Va,useEffect as Oa,useEffectEvent as to,useMemo as Ma}from"react";function no(e,t,n,r){let{name:o}=e,i=Ma(()=>Sr(e,r),[e,r]),a=Va(Ce),l=to(c=>{c&&t(c,i,e)}),s=to(c=>{c&&n(c,{keepValue:a})});return Oa(()=>(l(o),()=>{s(o)}),[o]),i}import{useSetAtom as kt,useStore as Ha}from"jotai";import{useCallback as _a,useEffect as $a,useRef as za}from"react";function ro(){let e=za(null);return $a(()=>()=>{e.current&&clearTimeout(e.current)},[]),_a((n,r)=>{e.current&&(clearTimeout(e.current),e.current=null),e.current=setTimeout(n,r)},[])}function io(e,t){let n=Ha(),r=e.field.advanced?.entity,o=ro(),[,i]=Ga(),{setValue:a,shouldSkipOnChange:l,value:s,setSource:c}=t,u=rt(s);u.current=s;let m=rt(e.translations);m.current=e.translations;let y=Oe(e.field),f=kt(nt),C=kt(Je),S=kt(et(e.field.name)),N=no(e.field,e.onMount,e.onUnmount,e.translations),w=p(e.commonProps.placeholder,e.translations),P={...e.commonProps,placeholder:w},v=rt(null);v.current=R=>{if(a(R),e.onValueChange){let M=e.dataAttributes??{};e.onValueChange({data:Object.keys(M).length>0?M:void 0,name:e.field.name,type:e.field.type,value:R})}};let D=rt(null);D.current=R=>{let M=e.field.event?.change;M&&Nn(M,({sources:$,states:ee,values:ce})=>{i(()=>{kn(R,$,(b,I)=>c(b,I)),En(R,ee,(b,I)=>{C(U=>I?b.reduce((te,ne)=>({...te,[ne]:I}),U):b.reduce((te,ne)=>Ke(te,ne),U)),I?.hidden===!0&&f(U=>{let te=!1,ne={...U};for(let st of Object.keys(U))b.some(Mt=>st===Mt||st.startsWith(`${Mt}.`))&&(delete ne[st],te=!0);return te?ne:U})}),wn(R,ce,(b,I)=>{f(U=>({...U,[b]:I}))})})})};let L=oo(R=>{let $=N.safeParse(R).error?.issues.map(b=>b.message)??[],ee=e.field.validation?.custom,ce=ee?Fr(R,ee,b=>n.get(le(b)),m.current):[];S([...$,...ce])},[e.field.validation?.custom,N,S,n]),k=oo(R=>{if(!y){let M=R.target.value;e.config.validation.blur&&L(M)}},[y,e.config.validation.blur,L]);return{applyChangeEventsRef:D,commonProps:P,entity:r,hasClickable:y,onBlur:k,onValueChangeRef:v,setTimeoutRef:o,shouldSkipOnChange:l,validated:L,valueRef:u}}import{deepEqual as Ba}from"fast-equals";import{useAtom as Ua}from"jotai";import{useCallback as Ya,useEffect as Xa,useRef as Za,useEffectEvent as qa}from"react";function ao(e,t){let{name:n}=e,r=Za(!1),[o,i]=Ua(le(n)),a=qa(s=>{let c=Wa(n,s);T(c)&&(Ba(o,c)||(r.current=!0),i(c))});Xa(()=>{t&&a(t)},[t]);let l=Ya(()=>r.current?(r.current=!1,!0):!1,[]);return{setValue:i,shouldSkipOnChange:l,value:o}}function Wa(e,t){if(e in t)return t[e];if(!e.includes("."))return;let n=e.split("."),r=t;for(let o of n){if(r==null)return;if(Array.isArray(r)){let i=Number(o);r=Number.isInteger(i)?r[i]:void 0}else if(typeof r=="object")r=r[o];else return}return r}import{jsx as lo}from"react/jsx-runtime";function so(e){let{useSource:t,useExtraProps:n,getValue:r,shouldSkipChange:o,dispatchChange:i,buildInitialSelected:a,isInitialReady:l}=e.strategies,{setValue:s,shouldSkipOnChange:c,value:u}=ao(e.field,e.value),{data:m,setSource:y}=t(e.field,e.config,u),{applyChangeEventsRef:f,commonProps:C,entity:S,hasClickable:N,onBlur:w,onValueChangeRef:P,setTimeoutRef:v,validated:D,valueRef:L}=io(e,{setValue:s,shouldSkipOnChange:c,value:u,setSource:y}),k=n?.(e.field),R=Qa(!1),{commonPropsWithOptions:M,defaultValue:$}=rr(e.field,C,m,u),ee=or(e.field,$);Ja(()=>{if(R.current||!e.value)return;if(!e.field.event?.change){R.current=!0;return}if(!T($)||!l(e.field,$,m))return;R.current=!0;let b=a($,m,S);f.current?.(b)},[f,a,m,$,S,l,e.field,e.value]);let ce=Ka(b=>{let I=r(b,e.field);o({shouldSkipOnChange:c,hasClickable:N,inputValue:I,valueRef:L})||(P.current?.(I),e.config.validation.change&&D(I),e.field.event?.change&&i({applyChangeEventsRef:f,data:m,entity:S,inputValue:I,setTimeoutRef:v}))},[f,m,i,S,r,N,P,e.config.validation.change,e.field,v,o,c,D,L]);return je(e.config.inputs[e.field.type],b=>lo(Kr,{config:e.config,context:e.context,field:e.field,horizontal:e.horizontal,translations:e.translations,children:lo(b,{...M,...e.ariaAttributes,...e.dataAttributes,...k,...ee,onBlur:w,onChange:ce})}))}import{jsx as ja}from"react/jsx-runtime";function se(e){return function(n){return ja(so,{...n,strategies:e})}}function co(e){let t=O(e)?H(e):null,n=z(e)?J(e):null;return{dateFormat:t,timeFormat:n}}import{atom as el}from"jotai";var tl=e=>{let t=kr(e);if(t)return t},nl=e=>e.trim()!=="",uo=el({}),ot=Or(uo,{merge:tl,validateTarget:nl}),mo=Mr(uo);import{useSetAtom as rl}from"jotai";function it(e){return{data:null,setSource:rl(ot(e.name))}}var fo=se({useSource:it,useExtraProps:e=>{let{dateFormat:t,timeFormat:n}=co(e);return ir(t,n)},getValue:(e,t)=>{let n=e.target.value,r=z(t)?J(t):null;if(r!==null)return Kn(n,r);let o=O(t)?H(t):null;return o!==null&&Be(n,o)||n},shouldSkipChange:({shouldSkipOnChange:e,inputValue:t,valueRef:n})=>e()&&t===n.current,dispatchChange:({applyChangeEventsRef:e,inputValue:t,setTimeoutRef:n})=>{n(()=>{e.current?.({value:t})},300)},buildInitialSelected:e=>({value:String(e)}),isInitialReady:(e,t)=>T(t)});import{useAtom as al}from"jotai";import ol from"swr";function po(e=null,t,n=!1){let{data:r,error:o}=ol(il(e,t,n),t.fetcher.provider);if(o&&ge.error("Error fetching data source:",o),e){if(Array.isArray(e))return e;if(r)return Sn(r,e.namespace)}return null}function il(e=null,t,n=!1){if(e&&!Array.isArray(e)&&!n&&e.url&&!fe(e.url)){if(Ar(e.url,t.fetcher.remotePatterns))return e;ge.warn(`URL blocked by remotePatterns: ${e.url}. Check your luna.config.ts`)}return null}function go(e,t,n){let r=nr(e,n),[o,i]=al(ot(e.name));return[po(o??r,t,e.disabled),i]}function ll(e,t,n){let[r,o]=go(e,t,n);return{data:r,setSource:o}}var yo=se({useSource:ll,getValue:e=>e.target.value,shouldSkipChange:({shouldSkipOnChange:e,hasClickable:t})=>!t&&e(),dispatchChange:({applyChangeEventsRef:e,data:t,entity:n,inputValue:r})=>{e.current?.(pt(r,t,n))},buildInitialSelected:(e,t,n)=>pt(String(e),t,n),isInitialReady:(e,t,n)=>(!xe(e)||!!n&&n.length>0)&&T(t)});var xo=se({useSource:it,getValue:e=>e.target.value,shouldSkipChange:({shouldSkipOnChange:e,inputValue:t,valueRef:n})=>e()&&t===n.current,dispatchChange:({applyChangeEventsRef:e,inputValue:t,setTimeoutRef:n})=>{n(()=>{e.current?.({value:t})},300)},buildInitialSelected:e=>({value:String(e)}),isInitialReady:(e,t)=>T(t)});import{jsx as It}from"react/jsx-runtime";function bo(e){return O(e.field)||z(e.field)?It(fo,{...e}):$n(e.field)?It(xo,{...e}):It(yo,{...e})}import{jsx as ho}from"react/jsx-runtime";function To(e){return!e.errors||e.errors.length===0?null:ho("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)=>ho("li",{children:t},e.name?`${e.name}-error-${n}`:n))})}import{twMerge as sl}from"tailwind-merge";import{jsx as cl}from"react/jsx-runtime";function at(e){let t=e.errors&&e.errors.length>0;return cl("div",{"data-slot":"field","data-clickable":e.isClickable?"true":"false",...t&&{[un]:"true"},...e.disabled&&{[dn]:"true"},"data-orientation":e.orientation,className:sl("group flex w-full flex-col items-center data-[invalid=true]:text-red-600 data-[invalid=true]:dark:text-red-500","data-[clickable=true]:items-start",e.isCheckbox&&(e.isReversed?"flex-row-reverse!":"flex-row!"),"data-[clickable=true]:has-[>[data-slot=field-content]]:[&>:first-child]:mt-px",e.className),children:e.children})}import{twMerge as ul}from"tailwind-merge";import{jsx as dl}from"react/jsx-runtime";function So(e){return dl(at,{...e,orientation:"vertical",className:ul("gap-3 has-[>[data-slot=field-content]]:items-start",!e.isClickable&&"[&>*]:w-full"),children:e.children})}import{twMerge as ml}from"tailwind-merge";import{jsx as fl}from"react/jsx-runtime";function Ro(e){return fl(at,{...e,orientation:"horizontal",className:ml("gap-2 md:flex-row md:gap-4","[&>[data-slot=field-content]]:min-w-0 [&>[data-slot=field-content]]:flex-grow [&>[data-slot=field-content]]:self-start","[&_[role=checkbox]]:mt-[1.5px]",e.isClickable&&"md:flex-col",!e.isClickable&&["md:justify-between","[&>*:not([data-slot=field-content])]:w-full","[&>*:not([data-slot=field-content])]:md:w-1/2","[&>*:not([data-slot=field-content])]:xl:w-2/5"]),children:e.children})}import{jsx as vo}from"react/jsx-runtime";function Co(e){let t=Oe(e.field),n=E(e.field),r=Hn(e.field);return e.horizontal?vo(Ro,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children}):vo(So,{disabled:e.disabled,errors:e.errors,isCheckbox:n,isReversed:r,isClickable:t,children:e.children})}function Fo(e){if(!e.field.type)return null;let t=Jn(e.field,e.disabled),n=ur(e.field),r=cr(e.field,e.errors),o={...e.field,disabled:t.disabled};return e.children({ariaAttributes:r,commonProps:t,dataAttributes:n,field:o,horizontal:e.horizontal})}import{twMerge as pl}from"tailwind-merge";import{jsx as Et,jsxs as gl}from"react/jsx-runtime";function Ao(e){let t=e.field.advanced?.cols,n=e.field.name?e.errors?.[e.field.name]:void 0,{horizontal:r}=Ze(e.style,{horizontal:Gn(e.field)}),o=Bn(e.field,e.disabled);return gl("div",{className:pl("flex flex-col gap-3",pr(t)),children:[Et(Co,{disabled:o,errors:n,field:e.field,horizontal:r,children:Et(Fo,{disabled:o,errors:n,field:e.field,horizontal:r,children:e.children})}),Et(To,{errors:n,name:e.field.name})]})}import{useAtomValue as yl}from"jotai";import{jsx as hl}from"react/jsx-runtime";function No(e){return(t,n)=>o=>{let i=yl(e(o.field.name)),a=n(i,o);return a===null?null:hl(t,{...o,...a})}}var xl=No(et);function ko(e){return xl(e,(t,n)=>({errors:t?{[n.field.name]:t}:void 0}))}var bl=No($r);function Io(e){return bl(e,(t,n)=>t?.hidden??n.field.hidden??!1?null:{disabled:t?.disabled??n.disabled})}var Eo=Io(ko(Ao));import{twMerge as lt}from"tailwind-merge";import{useState as Tl}from"react";import{jsx as A,jsxs as Te}from"react/jsx-runtime";function wo(e){let[t,n]=Tl(e.collapsible?!e.collapsed:!0);function r(){e.canRemove&&e.onRemove&&e.onRemove(e.index)}function o(){n(a=>!a)}let i=e.canRemove&&e.onRemove!=null&&A("button",{"aria-label":`Remove ${e.label} item ${e.index+1}`,className:lt("rounded p-1 text-xl text-slate-400","transition-colors duration-150","hover:text-red-500","focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:outline-none","dark:text-slate-500 dark:hover:text-red-400"),onClick:r,type:"button",children:A("span",{"aria-hidden":"true",children:"\xD7"})});return e.isMultiField?Te("div",{"data-slot":"list-item-card",className:"rounded-lg border border-slate-100 p-4 dark:border-slate-900",children:[Te("div",{className:"mb-3 flex items-center justify-between",children:[Te("div",{className:"flex items-center gap-2",children:[e.collapsible&&A("button",{"aria-label":t?"Collapse":"Expand",className:lt("rounded p-1 text-slate-400 hover:bg-slate-50","transition-colors duration-150","dark:text-slate-500 dark:hover:bg-slate-800"),onClick:o,type:"button",children:A(W,{expanded:t})}),Te("span",{className:"text-sm font-medium text-slate-300 dark:text-slate-400",children:[e.label," ",e.index+1,!t&&e.preview&&A("div",{className:"flex items-center gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-slate-400 dark:text-slate-500",children:e.preview})]})]}),i]}),A(ue,{visible:t,children:A(Q,{children:e.children})})]}):Te("div",{className:"flex items-start gap-2",children:[e.collapsible&&A("button",{"aria-label":t?"Collapse":"Expand",className:lt("rounded p-1 text-slate-400 hover:bg-slate-50","transition-colors duration-150","dark:text-slate-500 dark:hover:bg-slate-800",t&&"mt-7"),onClick:o,type:"button",children:A(W,{expanded:t})}),A("div",{className:"flex grow flex-col",children:A(ue,{visible:t,children:A(Q,{children:e.children})})}),i&&A("div",{className:lt("shrink-0",t&&"mt-7"),children:i})]})}import{useAtomValue as Sl}from"jotai";import{Fragment as Rl,jsx as Po,jsxs as vl}from"react/jsx-runtime";function Do({name:e,separator:t}){let n=Sl(le(e));return n==null||n===""||d(n)||Array.isArray(n)?null:vl(Rl,{children:[t&&Po("span",{className:"text-xs text-slate-300 dark:text-slate-600",children:"\xB7"}),Po("span",{className:"max-w-[150px] overflow-hidden text-xs text-ellipsis",children:`${n}`})]})}import{jsx as Lo}from"react/jsx-runtime";function Vo({name:e,previews:t}){return Lo("div",{className:"flex items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap",children:t.map((n,r)=>Lo(Do,{name:`${e}.${n}`,separator:r>0},n))})}import{twMerge as Nl}from"tailwind-merge";import{useSetAtom as Cl}from"jotai";import{useCallback as Oo,useLayoutEffect as Fl,useRef as Mo,useState as Al}from"react";function _o(e,t){let n=e.advanced?.length?.min??1,r=e.advanced?.length?.max??1/0,[o,i]=Al(()=>yr(e,t)),a=Mo(o.length),l=Mo(o);Fl(()=>{l.current=o});let s=Cl(nt),c=Oo(()=>{i(f=>{if(f.length>=r)return f;let C=a.current++;return[...f,C]})},[r]),u=Oo(f=>{if(l.current.length<=n)return;let C=l.current[f];i(S=>S.length<=n?S:S.filter((N,w)=>w!==f)),s(S=>{let N={...S},w=`${e.name}.`,P=[];for(let v of e.fields)if(q(v))for(let D of v.fields)P.push(D.name);else P.push(v.name);for(let v of P)delete N[`${w}${C}.${v}`];return N})},[e.name,e.fields,n,s]),m=o.length<r,y=o.length>n;return[o,c,u,m,y,r]}import{Fragment as kl,jsx as wt,jsxs as Pt}from"react/jsx-runtime";function $o(e){let[t,n,r,o,i,a]=_o(e.field,e.value),l=xr(e.field),s=e.field.advanced?.action??"Add item",c=a!==1/0,u=gr(e.field),m=e.field.advanced?.preview;return Pt(kl,{children:[t.map((y,f)=>wt(wo,{canRemove:i,collapsible:e.field.advanced?.collapsible,collapsed:e.field.advanced?.collapsed,index:f,isMultiField:u,label:l,onRemove:r,preview:m&&wt(Vo,{name:`${e.field.name}.${y}`,previews:m}),children:e.children(y)},y)),Pt("button",{"aria-disabled":!o,"aria-label":c?`${s}, ${t.length} of ${a}`:s,className:Nl("flex w-full items-center gap-1.5 rounded py-1","text-sm font-medium text-slate-500","transition-colors duration-150","hover:text-slate-800","focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:ring-offset-2 focus-visible:outline-none","dark:text-slate-400 dark:hover:text-slate-200",!o&&"cursor-not-allowed opacity-50 hover:text-slate-500 dark:hover:text-slate-400"),disabled:!o,onClick:n,type:"button",children:[wt("span",{"aria-hidden":"true",children:"+"}),s,c&&Pt("span",{"aria-hidden":"true",className:"ml-auto text-slate-400 tabular-nums dark:text-slate-500",children:[t.length," / ",a]})]})]})}import{jsx as Il}from"react/jsx-runtime";function zo(e){let t=Array.isArray(e.field.fields)&&e.field.fields.length===0;return Il(We,{description:e.field.description,empty:t,id:e.field.name,title:e.field.label,children:e.children})}import{jsx as Dt}from"react/jsx-runtime";function Go({children:e,field:t,value:n}){return Dt(Qe,{container:t,fields:t.fields,children:Dt(zo,{field:t,children:Dt($o,{field:t,value:n,children:e})})})}import{twMerge as El}from"tailwind-merge";import{jsx as Ho,jsxs as wl}from"react/jsx-runtime";function Bo(e){let t=fr(e.column?.advanced?.cols);return wl("div",{className:"flex w-full flex-col gap-4",children:[Ho("div",{className:El("grid grid-cols-1 gap-3 sm:gap-4",t),children:e.children}),e.column?.description&&Ho(ae,{config:e.config,context:e.context,text:e.column.description,translations:e.translations})]})}import{Fragment as Dl}from"react";import{jsx as Pl}from"react/jsx-runtime";function Uo(e){let t=Array.isArray(e.field.fields)?e.field.fields.map(n=>Me(n)?{...n,name:`${e.field.name}.${e.index}.${n.name}`}:q(n)?{...n,fields:n.fields.map(r=>({...r,name:`${e.field.name}.${e.index}.${r.name}`}))}:n):[];return Pl(Se,{children:e.children,components:e.components,config:e.config,context:e.context,disabled:e.disabled,fields:t,style:e.style,translations:e.translations,value:e.value})}import{jsx as Re,jsxs as Ll}from"react/jsx-runtime";function Se(e){let{field:t,list:n}=e.components;return Xe(e.fields).map((r,o)=>Ll(Dl,{children:[q(r)&&Re(Bo,{column:r,config:e.config,context:e.context,translations:e.translations,children:Re(Se,{...e,fields:r.fields})}),Me(r)&&Re(t,{disabled:e.disabled,field:r,style:e.style,children:e.children}),_n(r)&&Re(n,{field:r,value:e.value,children:i=>Re(Uo,{children:e.children,components:e.components,config:e.config,context:e.context,disabled:e.disabled,field:r,index:i,style:e.style,translations:e.translations,value:e.value})})]},o))}import{jsx as Vl}from"react/jsx-runtime";function Yo(e){return n=>Vl(Se,{...n,components:e})}var Xo=Yo({field:Eo,list:Go});import{useSetAtom as Zo}from"jotai";import{startTransition as qo,useActionState as Ol}from"react";function Ko(e,t,n){let{onSuccess:r,preserveValues:o=!1,validation:i=!0,translations:a}=n??{},l=Zo(Qr),s=Zo(jr),c={data:null,error:null,success:!1},[u,m,y]=Ol(async(f,C)=>{let[S,N]=e(),w=hr(S,N,a);if(i===!1)return t?await t(C,w):f;let P=Cn(C),v=_l(P,N),D=w.safeParse(v);if(!D.success){let k=Tr(D.error);return qo(()=>{l(k)}),Lt(P,{description:p("Please correct the errors and try again.",a),details:[],title:p("There were validation errors submitting the form.",a)})}let L=Fn(v);if(t)try{let k=await t(L,w);return k.success?(r?.(k.data),o||qo(()=>{s()}),Wo(L,o)):Lt(L,k.error)}catch(k){return ge.error("Error executing form action:",k),Lt(L,{title:p("An unexpected error occurred submitting the form.",a),details:Ml(k,a)})}return Wo(D.data,o)},c);return[m,u,y]}function Ml(e,t){return e instanceof Error?[e.message]:[p("Unknown error",t)]}function Wo(e,t=!1){return{data:t?e:null,error:null,success:!0}}function Lt(e,t){return{data:e,error:t,success:!1}}function _l(e,t){let n={...e};for(let r of t)if(O(r)&&typeof n[r.name]=="string"&&n[r.name]){let o=He(n[r.name],H(r));o&&(n[r.name]=o)}return n}import{useCallback as Ot,useRef as Qo}from"react";import{useCallback as $l}from"react";import{useSetAtom as Vt}from"jotai";function Jo(){let e=Vt(Jr),t=Vt(eo),n=Vt(mo);return $l((r,o)=>{let i=Array.isArray(r)?r:[r];e(i),n(i),o?.keepValue||t(i)},[e,n,t])}function jo(){let e=Jo(),t=Qo({}),n=Qo([]),r=Ot((a,l,s)=>{a in t.current||(t.current[a]=l,n.current.push(s))},[]),o=Ot((a,l)=>{t.current[a]&&(delete t.current[a],n.current=n.current.filter(s=>s.name!==a),e([a],{keepValue:l?.keepValue}))},[e]);return[Ot(()=>[t.current,n.current],[]),r,o]}import{Fragment as zl,jsx as ve,jsxs as Gl}from"react/jsx-runtime";function ei(e){let t=e.translations?.[e.lang??""],[n,r,o]=jo(),[i,a,l]=Ko(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 Gl(zl,{children:[s&&je(e.config.alert,u=>ve("div",{className:"mb-4 w-full",children:ve(u,{description:a.error?.description,details:a.error?.details,title:a.error.title})})),ve(Hr,{action:i,advanced:e.advanced,config:e.config,control:e.children,definition:e.definition,isPending:l,noValidate:!0,readOnly:e.readOnly,sections:e.sections,children:({disabled:u,fields:m})=>ve(Xo,{config:e.config,context:e.context,disabled:u,fields:m,style:e.config.style,translations:t,value:c,children:y=>ve(bo,{...y,config:e.config,context:e.context,onMount:r,onUnmount:o,onValueChange:e.onValueChange,translations:t,value:c})})})]})}import{Provider as Hl}from"jotai";import{jsx as ti}from"react/jsx-runtime";function Bl(e){return ti(Hl,{children:ti(ei,{...e})})}export{Bl as Form};
|