react-luna-form 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/cjs/index.js +1 -1
- package/dist/client/esm/index.js +1 -1
- package/dist/server/cjs/index.js +1 -1
- package/dist/server/esm/index.js +1 -1
- package/dist/timezone/cjs/index.js +1 -0
- package/dist/timezone/esm/chunk-6YOSEW3U.js +1 -0
- package/dist/timezone/esm/chunk-AJTG6FUX.js +1 -0
- package/dist/timezone/esm/chunk-EFQWCKYQ.js +818 -0
- package/dist/timezone/esm/chunk-JRS2SJNX.js +818 -0
- package/dist/timezone/esm/index.js +1 -0
- package/dist/timezone/esm/input-timezone-3TSHVJH7.js +766 -0
- package/dist/timezone/esm/input-timezone-D6UUK3LG.js +1 -0
- package/dist/timezone/esm/input-timezone-E45Y56W6.js +766 -0
- package/dist/timezone/esm/input-timezone-K27DM6BM.js +1 -0
- package/dist/timezone/esm/timezone-data-G5A3C2I7.js +1 -0
- package/dist/timezone/esm/timezone-data-LPD7JMNB.js +412 -0
- package/dist/timezone/esm/timezone-data-STGETEL3.js +1 -0
- package/dist/timezone/esm/timezone-data-XTIMFTET.js +412 -0
- package/dist/types/luna-react/src/client/component/input-base.d.ts +7 -0
- package/dist/types/luna-react/src/client/component/input-create.d.ts +3 -0
- package/dist/types/luna-react/src/client/component/input-dateable.d.ts +1 -0
- package/dist/types/luna-react/src/client/component/input-registry.d.ts +8 -0
- package/dist/types/luna-react/src/client/component/input-selectable.d.ts +1 -0
- package/dist/types/luna-react/src/client/component/input-strategies.d.ts +29 -0
- package/dist/types/luna-react/src/client/component/input-textable.d.ts +1 -0
- package/dist/types/luna-react/src/client/component/input-timezone.d.ts +2 -0
- package/dist/types/luna-react/src/client/component/input.d.ts +2 -16
- package/dist/types/luna-react/src/client/hook/use-input-core.d.ts +42 -0
- package/dist/types/luna-react/src/client/hook/use-timezone-options.d.ts +7 -0
- package/dist/types/luna-react/src/client/hook/use-write-only-source.d.ts +7 -0
- package/dist/types/luna-react/src/timezone/index.d.ts +3 -0
- package/package.json +12 -3
- package/dist/types/luna-react/src/client/component/input-date.d.ts +0 -16
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
// ../luna-core/src/util/is-type.ts
|
|
2
|
+
function isObject(value) {
|
|
3
|
+
return value !== null && Object.prototype.toString.call(value) === "[object Object]";
|
|
4
|
+
}
|
|
5
|
+
function isEmpty(value) {
|
|
6
|
+
return value === null || value === void 0 || value === "";
|
|
7
|
+
}
|
|
8
|
+
function isValue(value) {
|
|
9
|
+
return isString(value) || typeof value === "number" || isBoolean(value);
|
|
10
|
+
}
|
|
11
|
+
function isString(value) {
|
|
12
|
+
return typeof value === "string";
|
|
13
|
+
}
|
|
14
|
+
function isDataSource(value) {
|
|
15
|
+
return isObject(value) && "url" in value;
|
|
16
|
+
}
|
|
17
|
+
function isBoolean(value) {
|
|
18
|
+
return typeof value === "boolean";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ../luna-core/src/util/constant.ts
|
|
22
|
+
var INPUT = "input";
|
|
23
|
+
var INPUT_DATE = "input/date";
|
|
24
|
+
var INPUT_EMAIL = "input/email";
|
|
25
|
+
var INPUT_NUMBER = "input/number";
|
|
26
|
+
var INPUT_TIME = "input/time";
|
|
27
|
+
var TEXTAREA = "textarea";
|
|
28
|
+
var RADIO = "radio";
|
|
29
|
+
var CHECKBOX = "checkbox";
|
|
30
|
+
var SELECT = "select";
|
|
31
|
+
var SELECT_MONTH = "select/month";
|
|
32
|
+
var SELECT_TIMEZONE = "select/timezone";
|
|
33
|
+
var SELECT_YEAR = "select/year";
|
|
34
|
+
var CHIPS = "chips";
|
|
35
|
+
var DESCRIPTION = "description";
|
|
36
|
+
var LABEL = "label";
|
|
37
|
+
var VALUE = "value";
|
|
38
|
+
var OPTIONS = "options";
|
|
39
|
+
var TYPE_EMAIL = "email";
|
|
40
|
+
var TYPE_NUMBER = "number";
|
|
41
|
+
var TYPE_PASSWORD = "password";
|
|
42
|
+
var TYPE_TEL = "tel";
|
|
43
|
+
var TYPE_TEXT = "text";
|
|
44
|
+
var MAX = "max";
|
|
45
|
+
var MIN = "min";
|
|
46
|
+
var SOURCE = "source";
|
|
47
|
+
var STATE = "state";
|
|
48
|
+
var COMMON_URL = "http://luna.internal";
|
|
49
|
+
|
|
50
|
+
// ../luna-core/src/util/extract.ts
|
|
51
|
+
function getEntity(selected, collection = [], entity = VALUE) {
|
|
52
|
+
if (Array.isArray(collection)) {
|
|
53
|
+
return collection.find((item) => {
|
|
54
|
+
const current = getCurrentValue(item, entity);
|
|
55
|
+
if (current !== void 0 && `${current}` === selected) {
|
|
56
|
+
return item;
|
|
57
|
+
}
|
|
58
|
+
}) ?? { value: selected };
|
|
59
|
+
}
|
|
60
|
+
return { value: selected };
|
|
61
|
+
}
|
|
62
|
+
function getCurrentValue(value, entity = VALUE) {
|
|
63
|
+
if (value != null) {
|
|
64
|
+
if (Array.isArray(value) && value.every(isValue)) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (isValue(value)) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
if (isObject(value)) {
|
|
71
|
+
const result = getValue(value, entity);
|
|
72
|
+
if (isValue(result)) {
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getValue(value, namespace) {
|
|
79
|
+
const result = extract(value, namespace);
|
|
80
|
+
if (isValue(result)) {
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function extract(value, namespace) {
|
|
85
|
+
if (!namespace || !isObject(value)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const keys = namespace.split(".").filter((key) => key !== "");
|
|
89
|
+
if (keys.length === 0) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
let result = value;
|
|
93
|
+
for (const key of keys) {
|
|
94
|
+
if (isObject(result) && key in result) {
|
|
95
|
+
const obj = result;
|
|
96
|
+
result = obj[key];
|
|
97
|
+
} else {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function toOptions(data, options = {
|
|
104
|
+
description: DESCRIPTION,
|
|
105
|
+
label: LABEL,
|
|
106
|
+
value: VALUE
|
|
107
|
+
}) {
|
|
108
|
+
return data.map((item) => {
|
|
109
|
+
if (isObject(item)) {
|
|
110
|
+
const label = extract(item, options.label);
|
|
111
|
+
const value = extract(item, options.value);
|
|
112
|
+
if (isValue(label) && isValue(value)) {
|
|
113
|
+
const description = extract(item, options.description);
|
|
114
|
+
return {
|
|
115
|
+
label: `${label}`,
|
|
116
|
+
value: `${value}`,
|
|
117
|
+
...isValue(description) && { description: `${description}` }
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return item;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ../luna-core/src/util/is-input.ts
|
|
126
|
+
var isSelectMonth = (field) => createTypeChecker(SELECT_MONTH)(field);
|
|
127
|
+
var isSelectYear = (field) => createTypeChecker(SELECT_YEAR)(field);
|
|
128
|
+
var isSelectTimezone = (field) => createTypeChecker(SELECT_TIMEZONE)(field);
|
|
129
|
+
var isDate = createTypeChecker(INPUT_DATE);
|
|
130
|
+
var isTime = createTypeChecker(INPUT_TIME);
|
|
131
|
+
var isCheckbox = createTypeChecker(CHECKBOX);
|
|
132
|
+
var isChips = createTypeChecker(CHIPS);
|
|
133
|
+
var isRadio = createTypeChecker(RADIO);
|
|
134
|
+
var isInput = createTypeChecker(INPUT);
|
|
135
|
+
var isSelect = createTypeChecker(SELECT);
|
|
136
|
+
var isTextArea = createTypeChecker(TEXTAREA);
|
|
137
|
+
var isText = createTypeChecker(
|
|
138
|
+
TYPE_TEXT,
|
|
139
|
+
TYPE_EMAIL,
|
|
140
|
+
TYPE_PASSWORD,
|
|
141
|
+
TYPE_TEL
|
|
142
|
+
);
|
|
143
|
+
var isEmail = createTypeChecker(INPUT_EMAIL, TYPE_EMAIL);
|
|
144
|
+
var isNumber = createTypeChecker(INPUT_NUMBER, TYPE_NUMBER);
|
|
145
|
+
function isClickable(field) {
|
|
146
|
+
return isRadio(field) || isCheckbox(field);
|
|
147
|
+
}
|
|
148
|
+
function isOptions(field) {
|
|
149
|
+
return isSelect(field) || isRadio(field);
|
|
150
|
+
}
|
|
151
|
+
function isValidValue(value) {
|
|
152
|
+
return value !== void 0 && value !== null && value !== "";
|
|
153
|
+
}
|
|
154
|
+
function createTypeChecker(...types) {
|
|
155
|
+
return (field) => {
|
|
156
|
+
const inputType = isString(field.type) ? field.type : void 0;
|
|
157
|
+
if (!inputType) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return types.some((type) => {
|
|
161
|
+
return inputType === type || inputType?.startsWith(`${type}/`);
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ../luna-core/src/util/timezone-compute.ts
|
|
167
|
+
var cachedResult = null;
|
|
168
|
+
function getCachedTimezones() {
|
|
169
|
+
return cachedResult;
|
|
170
|
+
}
|
|
171
|
+
function getUserTimezone() {
|
|
172
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
173
|
+
}
|
|
174
|
+
function getOffset(tz, date) {
|
|
175
|
+
const parts = new Intl.DateTimeFormat("en", {
|
|
176
|
+
timeZone: tz,
|
|
177
|
+
timeZoneName: "longOffset"
|
|
178
|
+
}).formatToParts(date);
|
|
179
|
+
const raw = parts.find((part) => part.type === "timeZoneName")?.value ?? "GMT+00:00";
|
|
180
|
+
return raw.replace("GMT", "UTC");
|
|
181
|
+
}
|
|
182
|
+
function getCity(tz) {
|
|
183
|
+
return tz.slice(tz.lastIndexOf("/") + 1).replace(/_/g, " ");
|
|
184
|
+
}
|
|
185
|
+
function computeTimezoneGroups(entries) {
|
|
186
|
+
if (cachedResult) {
|
|
187
|
+
return cachedResult;
|
|
188
|
+
}
|
|
189
|
+
const date = /* @__PURE__ */ new Date();
|
|
190
|
+
const detectedTimezone = getUserTimezone();
|
|
191
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
192
|
+
let detectedItem = null;
|
|
193
|
+
for (const entry of entries) {
|
|
194
|
+
const offset = getOffset(entry.value, date);
|
|
195
|
+
const item = {
|
|
196
|
+
value: entry.value,
|
|
197
|
+
label: `${entry.label} - (${offset})`
|
|
198
|
+
};
|
|
199
|
+
if (entry.value === detectedTimezone) {
|
|
200
|
+
detectedItem = item;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const existing = groupMap.get(entry.region);
|
|
204
|
+
if (existing) {
|
|
205
|
+
existing.push(item);
|
|
206
|
+
} else {
|
|
207
|
+
groupMap.set(entry.region, [item]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!detectedItem) {
|
|
211
|
+
detectedItem = {
|
|
212
|
+
value: detectedTimezone,
|
|
213
|
+
label: `${getCity(detectedTimezone)} - (${getOffset(detectedTimezone, date)})`
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
for (const items of groupMap.values()) {
|
|
217
|
+
items.sort((a, b) => a.label.localeCompare(b.label));
|
|
218
|
+
}
|
|
219
|
+
const sortedGroups = Array.from(groupMap.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([label, items]) => ({ label, items }));
|
|
220
|
+
cachedResult = [
|
|
221
|
+
{ label: "Suggested", items: [detectedItem] },
|
|
222
|
+
...sortedGroups
|
|
223
|
+
];
|
|
224
|
+
return cachedResult;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ../luna-core/src/util/string.ts
|
|
228
|
+
var REGEX_MARKDOWN_LINK = /\[([^\]]{1,500})\]\(([^)]{1,2000})\)/g;
|
|
229
|
+
function interpolate(template, values = {}) {
|
|
230
|
+
if (isString(template)) {
|
|
231
|
+
return replacePlaceholders(template, values);
|
|
232
|
+
}
|
|
233
|
+
if (Array.isArray(template)) {
|
|
234
|
+
return template.map((item) => {
|
|
235
|
+
return interpolate(item, values);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (isObject(template)) {
|
|
239
|
+
const results = {};
|
|
240
|
+
for (const key in template) {
|
|
241
|
+
results[key] = interpolate(template[key], values);
|
|
242
|
+
}
|
|
243
|
+
return results;
|
|
244
|
+
}
|
|
245
|
+
return template;
|
|
246
|
+
}
|
|
247
|
+
function interpolateIfNeeded(template, values = {}) {
|
|
248
|
+
return isInterpolated(template) ? interpolate(template, values) : template;
|
|
249
|
+
}
|
|
250
|
+
function isInterpolated(template) {
|
|
251
|
+
if (isString(template)) {
|
|
252
|
+
return /{([^}]{1,200})}/.test(template);
|
|
253
|
+
}
|
|
254
|
+
if (Array.isArray(template)) {
|
|
255
|
+
return template.some((item) => isInterpolated(item));
|
|
256
|
+
}
|
|
257
|
+
if (isObject(template)) {
|
|
258
|
+
return Object.values(template).some((value) => isInterpolated(value));
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
function replacePlaceholders(template, values = {}) {
|
|
263
|
+
return template.replace(/{([^}]{1,200})}/g, (match, key) => {
|
|
264
|
+
const value = key.includes(".") ? extract(values, key) : values[key];
|
|
265
|
+
if (isValue(value)) {
|
|
266
|
+
return String(value);
|
|
267
|
+
}
|
|
268
|
+
return match;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function formatMarkdown(text, callback) {
|
|
272
|
+
if (!isString(text)) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
if (!text || text.trim().length === 0) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
let match;
|
|
279
|
+
let lastIndex = 0;
|
|
280
|
+
let hasMatch = false;
|
|
281
|
+
const parts = [];
|
|
282
|
+
while ((match = REGEX_MARKDOWN_LINK.exec(text)) !== null) {
|
|
283
|
+
const [fullMatch, linkText, url] = match;
|
|
284
|
+
const index = match.index;
|
|
285
|
+
hasMatch = true;
|
|
286
|
+
if (index > lastIndex) {
|
|
287
|
+
parts.push(text.substring(lastIndex, index));
|
|
288
|
+
}
|
|
289
|
+
const value = callback ? callback(index, url, linkText) : fullMatch;
|
|
290
|
+
parts.push(value);
|
|
291
|
+
lastIndex = index + fullMatch.length;
|
|
292
|
+
}
|
|
293
|
+
if (!hasMatch) {
|
|
294
|
+
return text;
|
|
295
|
+
}
|
|
296
|
+
if (lastIndex < text.length) {
|
|
297
|
+
parts.push(text.substring(lastIndex));
|
|
298
|
+
}
|
|
299
|
+
return parts;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ../luna-core/src/handle/proxy-event.ts
|
|
303
|
+
function handleProxyEvent(events = [], callback) {
|
|
304
|
+
const values = [];
|
|
305
|
+
const sources = [];
|
|
306
|
+
const states = [];
|
|
307
|
+
for (const event of events) {
|
|
308
|
+
if (event.action === VALUE) {
|
|
309
|
+
values.push(event);
|
|
310
|
+
}
|
|
311
|
+
if (event.action === SOURCE) {
|
|
312
|
+
sources.push(event);
|
|
313
|
+
}
|
|
314
|
+
if (event.action === STATE) {
|
|
315
|
+
states.push(event);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
callback({ sources, states, values });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../luna-core/src/handle/source-event.ts
|
|
322
|
+
function handleSourceEvent(selected = null, events = [], setSource) {
|
|
323
|
+
for (const event of events) {
|
|
324
|
+
const { target, source } = event;
|
|
325
|
+
if (!selected) {
|
|
326
|
+
setSource(target, void 0);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (isDataSource(source)) {
|
|
330
|
+
const newUrl = interpolate(source.url, selected);
|
|
331
|
+
const newBody = source.body ? interpolate(source.body, selected) : source.body;
|
|
332
|
+
setSource(target, {
|
|
333
|
+
...source,
|
|
334
|
+
url: newUrl,
|
|
335
|
+
body: newBody
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// ../luna-core/src/util/operator.ts
|
|
342
|
+
var operators = {
|
|
343
|
+
eq,
|
|
344
|
+
gt,
|
|
345
|
+
gte,
|
|
346
|
+
in: includes,
|
|
347
|
+
lt,
|
|
348
|
+
lte,
|
|
349
|
+
neq,
|
|
350
|
+
nin
|
|
351
|
+
};
|
|
352
|
+
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/;
|
|
353
|
+
var DMY_DATE_REGEX = /^(\d{2})[/-](\d{2})[/-](\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
354
|
+
function isISODateString(value) {
|
|
355
|
+
return typeof value === "string" && ISO_DATE_REGEX.test(value);
|
|
356
|
+
}
|
|
357
|
+
function isDMYDateString(value) {
|
|
358
|
+
return typeof value === "string" && DMY_DATE_REGEX.test(value);
|
|
359
|
+
}
|
|
360
|
+
function parseDMYDate(value) {
|
|
361
|
+
const match = value.match(DMY_DATE_REGEX);
|
|
362
|
+
if (match) {
|
|
363
|
+
const [, day, month, year, hours, minutes, seconds] = match;
|
|
364
|
+
return new Date(
|
|
365
|
+
Number(year),
|
|
366
|
+
Number(month) - 1,
|
|
367
|
+
Number(day),
|
|
368
|
+
Number(hours ?? 0),
|
|
369
|
+
Number(minutes ?? 0),
|
|
370
|
+
Number(seconds ?? 0)
|
|
371
|
+
).getTime();
|
|
372
|
+
}
|
|
373
|
+
return NaN;
|
|
374
|
+
}
|
|
375
|
+
function toComparableNumber(value) {
|
|
376
|
+
if (isISODateString(value)) {
|
|
377
|
+
return new Date(value).getTime();
|
|
378
|
+
}
|
|
379
|
+
if (isDMYDateString(value)) {
|
|
380
|
+
return parseDMYDate(value);
|
|
381
|
+
}
|
|
382
|
+
return Number(value);
|
|
383
|
+
}
|
|
384
|
+
function eq(current, value) {
|
|
385
|
+
return current === value;
|
|
386
|
+
}
|
|
387
|
+
function neq(current, value) {
|
|
388
|
+
return current !== value;
|
|
389
|
+
}
|
|
390
|
+
function includes(current, value) {
|
|
391
|
+
return Array.isArray(value) && value.includes(String(current));
|
|
392
|
+
}
|
|
393
|
+
function nin(current, value) {
|
|
394
|
+
return Array.isArray(value) && !value.includes(String(current));
|
|
395
|
+
}
|
|
396
|
+
function gt(current, value) {
|
|
397
|
+
return toComparableNumber(current) > toComparableNumber(value);
|
|
398
|
+
}
|
|
399
|
+
function gte(current, value) {
|
|
400
|
+
return toComparableNumber(current) >= toComparableNumber(value);
|
|
401
|
+
}
|
|
402
|
+
function lt(current, value) {
|
|
403
|
+
return toComparableNumber(current) < toComparableNumber(value);
|
|
404
|
+
}
|
|
405
|
+
function lte(current, value) {
|
|
406
|
+
return toComparableNumber(current) <= toComparableNumber(value);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// ../luna-core/src/handle/state-event.ts
|
|
410
|
+
function handleStateEvent(selected = null, events = [], setState) {
|
|
411
|
+
for (const event of events) {
|
|
412
|
+
const { target, state, when } = event;
|
|
413
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
414
|
+
if (!selected) {
|
|
415
|
+
setState(targets);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
const matches = evaluateCondition(selected, when);
|
|
419
|
+
setState(targets, matches ? state : void 0);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function evaluateCondition(selected, when) {
|
|
423
|
+
if (when === void 0) {
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
if (isString(when)) {
|
|
427
|
+
return getValue2(selected, VALUE) === when;
|
|
428
|
+
}
|
|
429
|
+
if (isBoolean(when)) {
|
|
430
|
+
return Boolean(getValue2(selected, VALUE)) === when;
|
|
431
|
+
}
|
|
432
|
+
if (Array.isArray(when)) {
|
|
433
|
+
return when.includes(String(getValue2(selected, VALUE)));
|
|
434
|
+
}
|
|
435
|
+
return evaluateOperator(selected, when);
|
|
436
|
+
}
|
|
437
|
+
function evaluateOperator(selected = null, condition) {
|
|
438
|
+
const current = getValue2(selected, condition.field ?? VALUE);
|
|
439
|
+
const { operator = "eq", value } = condition;
|
|
440
|
+
const operation = operators[operator];
|
|
441
|
+
if (operation) {
|
|
442
|
+
return operation(current, value);
|
|
443
|
+
}
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
function getValue2(selected, field) {
|
|
447
|
+
if (isObject(selected)) {
|
|
448
|
+
return extract(selected, field);
|
|
449
|
+
}
|
|
450
|
+
return selected;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ../luna-core/src/handle/value-event.ts
|
|
454
|
+
function handleValueEvent(selected = null, events = [], setValue) {
|
|
455
|
+
for (const event of events) {
|
|
456
|
+
for (const [target, value] of Object.entries(event.value)) {
|
|
457
|
+
setValue(target, selected ? interpolate(value, selected) : void 0);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ../luna-core/src/util/date.ts
|
|
463
|
+
import { isValid, parse, format as fnsFormat } from "date-fns";
|
|
464
|
+
var REF = new Date(2e3, 0, 1);
|
|
465
|
+
function getCurrentYear() {
|
|
466
|
+
return (/* @__PURE__ */ new Date()).getFullYear();
|
|
467
|
+
}
|
|
468
|
+
function toNativeDate(value, fromFormat) {
|
|
469
|
+
if (!value) {
|
|
470
|
+
return "";
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
const date = parse(value, fromFormat, REF);
|
|
474
|
+
return isValid(date) ? fnsFormat(date, "yyyy-MM-dd") : "";
|
|
475
|
+
} catch {
|
|
476
|
+
return "";
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function toNativeTime(value, fromFormat) {
|
|
480
|
+
if (!value) {
|
|
481
|
+
return "";
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
const date = parse(value, fromFormat, REF);
|
|
485
|
+
return isValid(date) ? fnsFormat(date, "HH:mm:ss") : "";
|
|
486
|
+
} catch {
|
|
487
|
+
return "";
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function fromNativeDate(native, toFormat = "MMMM d, yyyy") {
|
|
491
|
+
if (!native) {
|
|
492
|
+
return "";
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
const date = parse(native, "yyyy-MM-dd", REF);
|
|
496
|
+
return isValid(date) ? fnsFormat(date, toFormat) : "";
|
|
497
|
+
} catch {
|
|
498
|
+
return "";
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function getTimeFormat(field) {
|
|
502
|
+
return field.advanced?.format ?? "HH:mm";
|
|
503
|
+
}
|
|
504
|
+
function getDateFormat(field) {
|
|
505
|
+
return field.advanced?.format ?? "MMMM d, yyyy";
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ../luna-core/src/helper/input.ts
|
|
509
|
+
var now = getCurrentYear();
|
|
510
|
+
function getInputValue(field, value) {
|
|
511
|
+
const newValue = isObject(value) && field.name in value ? value[field.name] : value;
|
|
512
|
+
const currentValue = getCurrentValue(newValue, field.advanced?.entity);
|
|
513
|
+
if (isTime(field) && isValidValue(currentValue)) {
|
|
514
|
+
return getTimeValue(field, currentValue);
|
|
515
|
+
}
|
|
516
|
+
if (isDate(field) && isValidValue(currentValue)) {
|
|
517
|
+
return getDateValue(field, currentValue);
|
|
518
|
+
}
|
|
519
|
+
return currentValue;
|
|
520
|
+
}
|
|
521
|
+
function getTimeValue(field, currentValue) {
|
|
522
|
+
const format = getTimeFormat(field);
|
|
523
|
+
return isString(currentValue) ? toNativeTime(currentValue, format) : currentValue;
|
|
524
|
+
}
|
|
525
|
+
function mergeOptionsProps(field, commonProps, options) {
|
|
526
|
+
return isOptions(field) && Array.isArray(options) ? { ...commonProps, [OPTIONS]: options } : commonProps;
|
|
527
|
+
}
|
|
528
|
+
function getPreselectedValue(field, commonProps, value) {
|
|
529
|
+
if (field.required && !isValidValue(value)) {
|
|
530
|
+
if (isSelect(field)) {
|
|
531
|
+
if (field.advanced?.preselected !== false && OPTIONS in commonProps) {
|
|
532
|
+
const options = commonProps[OPTIONS];
|
|
533
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
534
|
+
return options[0];
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
541
|
+
function getOptions(field, data) {
|
|
542
|
+
if (isOptions(field) && Array.isArray(data)) {
|
|
543
|
+
return toOptions(data, field.advanced?.options);
|
|
544
|
+
}
|
|
545
|
+
return data;
|
|
546
|
+
}
|
|
547
|
+
function prepareInputProps(field, commonProps, data, value) {
|
|
548
|
+
const currentValue = getInputValue(field, value);
|
|
549
|
+
const options = Array.isArray(data) ? getOptions(field, data) : data;
|
|
550
|
+
const commonPropsWithOptions = mergeOptionsProps(field, commonProps, options);
|
|
551
|
+
const defaultValue = getPreselectedValue(
|
|
552
|
+
field,
|
|
553
|
+
commonPropsWithOptions,
|
|
554
|
+
currentValue
|
|
555
|
+
);
|
|
556
|
+
return {
|
|
557
|
+
commonPropsWithOptions,
|
|
558
|
+
defaultValue
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function prepareInputValue(field, value) {
|
|
562
|
+
if (isCheckbox(field)) {
|
|
563
|
+
return {
|
|
564
|
+
checked: isValidValue(value) ? value : false
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
if (isChips(field)) {
|
|
568
|
+
return { value: Array.isArray(value) ? value : [] };
|
|
569
|
+
}
|
|
570
|
+
if (isDate(field)) {
|
|
571
|
+
if (isString(value) && isValidValue(value)) {
|
|
572
|
+
return { value: fromNativeDate(value, getDateFormat(field)) };
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return { value: value ?? "" };
|
|
576
|
+
}
|
|
577
|
+
function getDateValue(field, currentValue) {
|
|
578
|
+
const format = getDateFormat(field);
|
|
579
|
+
return isString(currentValue) ? toNativeDate(currentValue, format) : currentValue;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// ../luna-core/src/util/schema.ts
|
|
583
|
+
import { z } from "zod";
|
|
584
|
+
|
|
585
|
+
// ../luna-core/src/util/translate.ts
|
|
586
|
+
function translate(key, dictionary) {
|
|
587
|
+
if (!key) {
|
|
588
|
+
return "";
|
|
589
|
+
}
|
|
590
|
+
if (!dictionary) {
|
|
591
|
+
return key;
|
|
592
|
+
}
|
|
593
|
+
return dictionary[key] ?? key;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// ../luna-core/src/util/schema.ts
|
|
597
|
+
var approach = [
|
|
598
|
+
[isNumber, getNumber],
|
|
599
|
+
[isEmail, getEmail],
|
|
600
|
+
[isSelectYear, getYearSchema],
|
|
601
|
+
[isSelectMonth, getMonthSchema],
|
|
602
|
+
[isCheckbox, getBoolean],
|
|
603
|
+
[isRadio, getRadio]
|
|
604
|
+
];
|
|
605
|
+
function getSchema(input, translations) {
|
|
606
|
+
for (const [check, getSchema2] of approach) {
|
|
607
|
+
if (check(input)) {
|
|
608
|
+
return getSchema2(input, translations);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return getText(input, translations);
|
|
612
|
+
}
|
|
613
|
+
function getEmail(input, translations) {
|
|
614
|
+
const baseSchema = z.string().trim();
|
|
615
|
+
if (input.required) {
|
|
616
|
+
const message = getRequiredMessage(input, translations);
|
|
617
|
+
const schema = baseSchema.min(1, message).pipe(applyEmail(input, translations));
|
|
618
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
619
|
+
}
|
|
620
|
+
return baseSchema.pipe(applyEmail(input, translations)).or(z.literal("")).nullable();
|
|
621
|
+
}
|
|
622
|
+
function getBoolean(input, translations) {
|
|
623
|
+
let schema = z.coerce.boolean();
|
|
624
|
+
if (input.required) {
|
|
625
|
+
schema = schema.refine((value) => value === true, {
|
|
626
|
+
message: getRequiredMessage(input, translations)
|
|
627
|
+
});
|
|
628
|
+
return z.preprocess((value) => value === null ? false : value, schema);
|
|
629
|
+
}
|
|
630
|
+
return schema.nullable();
|
|
631
|
+
}
|
|
632
|
+
function getRadio(input, translations) {
|
|
633
|
+
let schema = z.coerce.string();
|
|
634
|
+
if (input.required) {
|
|
635
|
+
schema = schema.min(1, getRequiredMessage(input, translations));
|
|
636
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
637
|
+
}
|
|
638
|
+
return schema.or(z.literal("")).nullable();
|
|
639
|
+
}
|
|
640
|
+
function getText(input, translations) {
|
|
641
|
+
let schema = z.coerce.string().trim();
|
|
642
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
643
|
+
if (input.required) {
|
|
644
|
+
schema = applyRequired(schema, input, translations);
|
|
645
|
+
return z.preprocess((value) => isEmpty(value) ? "" : value, schema);
|
|
646
|
+
}
|
|
647
|
+
return schema.nullable();
|
|
648
|
+
}
|
|
649
|
+
function getNumber(input, translations) {
|
|
650
|
+
let schema = z.coerce.number().int();
|
|
651
|
+
schema = applyMinAndMax(schema, input, translations);
|
|
652
|
+
if (input.required) {
|
|
653
|
+
schema = applyRequired(schema, input, translations);
|
|
654
|
+
return z.preprocess((value) => value === null ? void 0 : value, schema);
|
|
655
|
+
}
|
|
656
|
+
return schema.nullable();
|
|
657
|
+
}
|
|
658
|
+
function getYearSchema(input, translations) {
|
|
659
|
+
if (input.required) {
|
|
660
|
+
return z.preprocess(
|
|
661
|
+
normalize,
|
|
662
|
+
z.coerce.number({ message: getRequiredMessage(input, translations) }).int()
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
return z.coerce.number().int().nullable();
|
|
666
|
+
}
|
|
667
|
+
function getMonthSchema(input, translations) {
|
|
668
|
+
const message = getRequiredMessage(input, translations);
|
|
669
|
+
const schema = z.coerce.number().int().min(1, message).max(12, message);
|
|
670
|
+
return !input.required ? schema.nullable() : schema;
|
|
671
|
+
}
|
|
672
|
+
function normalize(value) {
|
|
673
|
+
return value === null || value === "" ? void 0 : value;
|
|
674
|
+
}
|
|
675
|
+
function applyEmail(input, translations) {
|
|
676
|
+
const message = input.validation?.email ? translate(input.validation?.email, translations) : void 0;
|
|
677
|
+
return z.email(message);
|
|
678
|
+
}
|
|
679
|
+
function applyMinAndMax(schema, input, translations) {
|
|
680
|
+
schema = min(schema, input, translations);
|
|
681
|
+
schema = max(schema, input, translations);
|
|
682
|
+
return schema;
|
|
683
|
+
}
|
|
684
|
+
function applyRequired(schema, input, translations) {
|
|
685
|
+
const min2 = input.advanced?.length?.min;
|
|
686
|
+
if (min2 === void 0 || min2 < 1) {
|
|
687
|
+
return schema.min(1, getRequiredMessage(input, translations));
|
|
688
|
+
}
|
|
689
|
+
return schema;
|
|
690
|
+
}
|
|
691
|
+
var min = (schema, input, translations) => applyConstraint(schema, input, MIN, translations);
|
|
692
|
+
var max = (schema, input, translations) => applyConstraint(schema, input, MAX, translations);
|
|
693
|
+
function applyConstraint(schema, input, method, translations) {
|
|
694
|
+
const value = input.advanced?.length?.[method];
|
|
695
|
+
if (value !== void 0) {
|
|
696
|
+
const message = input.validation?.length?.[method] ? translate(input.validation?.length?.[method], translations) : void 0;
|
|
697
|
+
return schema[method](value, message);
|
|
698
|
+
}
|
|
699
|
+
return schema;
|
|
700
|
+
}
|
|
701
|
+
function validateCustom(value, rules, getValue3, translations) {
|
|
702
|
+
const errors = [];
|
|
703
|
+
const collections = Array.isArray(rules) ? rules : [rules];
|
|
704
|
+
for (const rule of collections) {
|
|
705
|
+
const operator = rule.operator ?? "eq";
|
|
706
|
+
const operation = operators[operator];
|
|
707
|
+
if (operation && !operation(value, getValue3(rule.field))) {
|
|
708
|
+
if (rule.message) {
|
|
709
|
+
const message = translate(rule.message, translations);
|
|
710
|
+
errors.push(message);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return errors;
|
|
715
|
+
}
|
|
716
|
+
function getRequiredMessage(input, translations) {
|
|
717
|
+
return input.validation?.required ? translate(input.validation?.required, translations) : void 0;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ../luna-core/src/util/url.ts
|
|
721
|
+
function mergeUrl(baseUrl, targetUrl) {
|
|
722
|
+
try {
|
|
723
|
+
if (!baseUrl) {
|
|
724
|
+
return targetUrl;
|
|
725
|
+
}
|
|
726
|
+
if (!targetUrl) {
|
|
727
|
+
return baseUrl;
|
|
728
|
+
}
|
|
729
|
+
const url1 = new URL(baseUrl, COMMON_URL);
|
|
730
|
+
const url2 = new URL(targetUrl, COMMON_URL);
|
|
731
|
+
url2.searchParams.forEach((value, key) => {
|
|
732
|
+
url1.searchParams.set(key, value);
|
|
733
|
+
});
|
|
734
|
+
const result = url1.toString();
|
|
735
|
+
return baseUrl.startsWith("/") || !baseUrl.includes("://") ? result.replace(COMMON_URL, "") : result;
|
|
736
|
+
} catch {
|
|
737
|
+
return targetUrl || baseUrl;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// ../luna-core/src/util/source.ts
|
|
742
|
+
function mergeSource(sources) {
|
|
743
|
+
if (!Array.isArray(sources) || sources.length === 0) {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
return sources.reduce((previous, current) => {
|
|
747
|
+
const url = mergeUrl(previous.url, current.url);
|
|
748
|
+
const body = getBody(previous, current);
|
|
749
|
+
const headers = getHeaders(previous, current);
|
|
750
|
+
return {
|
|
751
|
+
...previous,
|
|
752
|
+
...current,
|
|
753
|
+
url,
|
|
754
|
+
body,
|
|
755
|
+
headers
|
|
756
|
+
};
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function getBody(previous, current) {
|
|
760
|
+
if (isObject(current.body) && isObject(previous?.body)) {
|
|
761
|
+
return {
|
|
762
|
+
...previous.body,
|
|
763
|
+
...current.body
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
return current.body ?? previous?.body;
|
|
767
|
+
}
|
|
768
|
+
function getHeaders(previous, current) {
|
|
769
|
+
if (isObject(current.headers) && isObject(previous?.headers)) {
|
|
770
|
+
return {
|
|
771
|
+
...previous.headers,
|
|
772
|
+
...current.headers
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
return current.headers ?? previous?.headers;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// ../luna-core/src/util/load-timezones.ts
|
|
779
|
+
var pending = null;
|
|
780
|
+
function loadTimezones() {
|
|
781
|
+
const cached = getCachedTimezones();
|
|
782
|
+
if (cached) {
|
|
783
|
+
return Promise.resolve(cached);
|
|
784
|
+
}
|
|
785
|
+
if (pending) {
|
|
786
|
+
return pending;
|
|
787
|
+
}
|
|
788
|
+
pending = import("./timezone-data-XTIMFTET.js").then(({ TIMEZONE_STATIC }) => {
|
|
789
|
+
const groups = computeTimezoneGroups(TIMEZONE_STATIC);
|
|
790
|
+
pending = null;
|
|
791
|
+
return groups;
|
|
792
|
+
});
|
|
793
|
+
return pending;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export {
|
|
797
|
+
getEntity,
|
|
798
|
+
interpolateIfNeeded,
|
|
799
|
+
formatMarkdown,
|
|
800
|
+
handleProxyEvent,
|
|
801
|
+
handleSourceEvent,
|
|
802
|
+
handleStateEvent,
|
|
803
|
+
handleValueEvent,
|
|
804
|
+
isSelectTimezone,
|
|
805
|
+
isCheckbox,
|
|
806
|
+
isRadio,
|
|
807
|
+
isClickable,
|
|
808
|
+
isOptions,
|
|
809
|
+
isValidValue,
|
|
810
|
+
prepareInputProps,
|
|
811
|
+
prepareInputValue,
|
|
812
|
+
translate,
|
|
813
|
+
getSchema,
|
|
814
|
+
validateCustom,
|
|
815
|
+
mergeSource,
|
|
816
|
+
getUserTimezone,
|
|
817
|
+
loadTimezones
|
|
818
|
+
};
|