@voltro/client 0.54.0 → 0.56.0
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/CHANGELOG.md +639 -2
- package/dist/form.d.ts +28 -1
- package/dist/form.js +2 -2
- package/dist/formData-DtlF8t8h.js +641 -0
- package/dist/index.d.ts +483 -6
- package/dist/index.js +942 -860
- package/package.json +2 -2
- package/dist/formData-BO7zkG_F.js +0 -386
package/dist/form.d.ts
CHANGED
|
@@ -174,6 +174,33 @@ export declare const formSections: (fields: ReadonlyArray<FieldDescriptor>) => R
|
|
|
174
174
|
*/
|
|
175
175
|
export declare const resolveValidationMessage: (issue: Pick<FieldIssue, "id" | "params" | "fallback">, options?: ValidateOptions) => string;
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Keep only the keys the input schema DECLARES.
|
|
179
|
+
*
|
|
180
|
+
* The two submit paths had drifted apart on this, and the server sided with
|
|
181
|
+
* neither: `formDataToInput` (the no-JS path) documents "unknown keys are
|
|
182
|
+
* dropped", while the JS path validated with a decode that IGNORES excess
|
|
183
|
+
* properties and then sent the object UNCHANGED. Since 0.37 the server
|
|
184
|
+
* refuses an undeclared input field — so a form carrying anything beyond the
|
|
185
|
+
* mutation's input (a display toggle, a repeat control, a file held before
|
|
186
|
+
* upload, which is nearly every real form) passed client validation and was
|
|
187
|
+
* rejected on the wire, with a message pointing at no field. Measured by a
|
|
188
|
+
* deployment with `renderFormBinding`, our own harness.
|
|
189
|
+
*
|
|
190
|
+
* `toInput` is the seam for this and stays the recommended one — but it only
|
|
191
|
+
* protects a form that HAS one, and the failure mode of not having one was a
|
|
192
|
+
* green tick followed by a server refusal. Dropping matches the no-JS path,
|
|
193
|
+
* so the two submits now agree; a genuinely mistyped key still surfaces,
|
|
194
|
+
* because the field it was meant to be is then missing and fails validation.
|
|
195
|
+
*
|
|
196
|
+
* Non-struct schemas (a scalar input) are returned untouched — there is no
|
|
197
|
+
* declared key set to restrict against.
|
|
198
|
+
*/
|
|
199
|
+
export declare const restrictToSchema: (schema: Schema.Schema.Any, input: unknown) => {
|
|
200
|
+
readonly input: unknown;
|
|
201
|
+
readonly dropped: ReadonlyArray<string>;
|
|
202
|
+
};
|
|
203
|
+
|
|
177
204
|
/**
|
|
178
205
|
* Derive table COLUMNS from a query's output `Schema` — an
|
|
179
206
|
* `Schema.Array(Schema.Struct({...}))`. Drills into the array's element and maps
|
|
@@ -223,6 +250,6 @@ export declare interface ValidationResult {
|
|
|
223
250
|
/** The default widget kinds the framework can render from a schema. `'custom'`
|
|
224
251
|
* means "no default widget" — the field needs a render-prop (a nested object,
|
|
225
252
|
* an array of objects, or a multi-branch union). Mirrors innovation/01's set. */
|
|
226
|
-
export declare type WidgetKind = 'text' | 'textarea' | 'number' | 'checkbox' | 'switch' | 'select' | 'radio' | 'async-select' | 'multi-select' | 'date' | 'datetime' | 'daterange' | 'file' | 'hidden' | 'array' | 'reference' | 'custom';
|
|
253
|
+
export declare type WidgetKind = 'text' | 'textarea' | 'rich-text' | 'number' | 'checkbox' | 'switch' | 'select' | 'radio' | 'async-select' | 'multi-select' | 'date' | 'datetime' | 'daterange' | 'file' | 'hidden' | 'array' | 'reference' | 'custom';
|
|
227
254
|
|
|
228
255
|
export { }
|
package/dist/form.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { C as e, S as t, _ as n, a as r, b as i, g as a, i as o, n as s, o as c, r as l, t as u, v as d, w as f, x as p, y as m } from "./formData-DtlF8t8h.js";
|
|
2
|
+
export { u as FORM_FLASH_SCRIPT_ID, s as FORM_KEY_FIELD, l as FORM_PATH_PREFIX, o as FORM_REDIRECT_FIELD, a as decodeFieldIssues, n as documentLocale, r as formActionPath, c as formDataToInput, p as formField, t as formSections, d as resolveValidationMessage, m as restrictToSchema, e as schemaToColumns, f as schemaToFields, i as validateFields };
|
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { JSONSchema as e, Schema as t } from "effect";
|
|
2
|
+
import * as n from "effect/SchemaAST";
|
|
3
|
+
//#region src/schemaFields.ts
|
|
4
|
+
var r = (e) => ({ jsonSchema: { "x-voltro": e } }), i = "#/$defs/", a = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), o = (e, t) => {
|
|
5
|
+
let n = e;
|
|
6
|
+
for (let e = 0; e < 8; e += 1) {
|
|
7
|
+
let e = n.$ref;
|
|
8
|
+
if (typeof e != "string" || !e.startsWith(i)) return n;
|
|
9
|
+
let r = t[e.slice(8)];
|
|
10
|
+
if (!r || typeof r != "object") return n;
|
|
11
|
+
n = r;
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}, s = (e) => {
|
|
15
|
+
if (!e || typeof e != "object") return !1;
|
|
16
|
+
let t = e;
|
|
17
|
+
if (t.type === "null" || t.const === null) return !0;
|
|
18
|
+
let n = t.enum;
|
|
19
|
+
return Array.isArray(n) && n.length === 1 && n[0] === null;
|
|
20
|
+
}, c = (e, t) => {
|
|
21
|
+
let n = e.type;
|
|
22
|
+
if (Array.isArray(n) && n.includes("null")) {
|
|
23
|
+
let t = n.filter((e) => e !== "null");
|
|
24
|
+
return {
|
|
25
|
+
node: {
|
|
26
|
+
...e,
|
|
27
|
+
type: t.length === 1 ? t[0] : t
|
|
28
|
+
},
|
|
29
|
+
nullable: !0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
for (let n of ["anyOf", "oneOf"]) {
|
|
33
|
+
let r = e[n];
|
|
34
|
+
if (!Array.isArray(r)) continue;
|
|
35
|
+
let i = r.filter((e) => !s(e));
|
|
36
|
+
if (i.length !== r.length) return i.length === 1 ? {
|
|
37
|
+
node: o(i[0], t),
|
|
38
|
+
nullable: !0
|
|
39
|
+
} : {
|
|
40
|
+
node: {
|
|
41
|
+
...e,
|
|
42
|
+
[n]: i
|
|
43
|
+
},
|
|
44
|
+
nullable: !0
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
node: e,
|
|
49
|
+
nullable: !1
|
|
50
|
+
};
|
|
51
|
+
}, l = (e) => e.map((e) => ({
|
|
52
|
+
value: String(e),
|
|
53
|
+
label: a(String(e))
|
|
54
|
+
})), u = (e) => {
|
|
55
|
+
let t = e.enum;
|
|
56
|
+
if (Array.isArray(t) && t.length > 0) return {
|
|
57
|
+
widget: "select",
|
|
58
|
+
options: l(t)
|
|
59
|
+
};
|
|
60
|
+
let n = e.type, r = Array.isArray(n) ? n.find((e) => e !== "null") : n, i = e.format;
|
|
61
|
+
switch (r) {
|
|
62
|
+
case "string": return i === "date" ? { widget: "date" } : i === "date-time" ? { widget: "datetime" } : { widget: "text" };
|
|
63
|
+
case "integer":
|
|
64
|
+
case "number": return { widget: "number" };
|
|
65
|
+
case "boolean": return { widget: "checkbox" };
|
|
66
|
+
case "array": return { widget: "multi-select" };
|
|
67
|
+
default: return { widget: "custom" };
|
|
68
|
+
}
|
|
69
|
+
}, ee = (e) => {
|
|
70
|
+
let t = e.$ref;
|
|
71
|
+
if (typeof t != "string" || !t.startsWith(i)) return;
|
|
72
|
+
let n = t.slice(8);
|
|
73
|
+
if (/DateTime/i.test(n) || /Timestamp/i.test(n)) return "datetime";
|
|
74
|
+
if (/Date/.test(n)) return "date";
|
|
75
|
+
}, d = (e) => typeof e["x-voltro"] == "object" && e["x-voltro"] !== null ? e["x-voltro"] : {}, f = 4, p = (e, t, n, r = "", i, s = 0) => Object.entries(e).flatMap(([e, l]) => {
|
|
76
|
+
let { node: m, nullable: h } = c(o(l, n), n), g = o(m, n), _ = d(g), v = r === "" ? e : `${r}.${e}`, y = g.properties;
|
|
77
|
+
if (g.type === "object" && y !== void 0 && s < f && _.widget === void 0) return p(y, new Set(Array.isArray(g.required) ? g.required : []), n, v, {
|
|
78
|
+
path: _.section ?? v,
|
|
79
|
+
label: _.label ?? a(e)
|
|
80
|
+
}, s + 1);
|
|
81
|
+
let b = ee(l), { widget: x, options: S } = u(g);
|
|
82
|
+
b !== void 0 && (x = b);
|
|
83
|
+
let C;
|
|
84
|
+
if (g.type === "array") {
|
|
85
|
+
let e = g.items;
|
|
86
|
+
if (typeof e == "object" && e && !Array.isArray(e)) {
|
|
87
|
+
let t = o(e, n), r = t.properties;
|
|
88
|
+
t.type === "object" && r !== void 0 && (x = "array", C = p(r, new Set(Array.isArray(t.required) ? t.required : []), n));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
_.widget !== void 0 && (x = _.widget), _.reference !== void 0 && _.widget === void 0 && (x = "reference");
|
|
92
|
+
let w = typeof g.description == "string" ? g.description : void 0, T = _.section ?? i?.path;
|
|
93
|
+
return [{
|
|
94
|
+
name: v,
|
|
95
|
+
label: _.label ?? a(e),
|
|
96
|
+
widget: x,
|
|
97
|
+
required: t.has(e),
|
|
98
|
+
nullable: h,
|
|
99
|
+
...S ? { options: S } : {},
|
|
100
|
+
jsonSchema: g,
|
|
101
|
+
...T === void 0 ? {} : {
|
|
102
|
+
section: T,
|
|
103
|
+
sectionLabel: i?.label ?? a(T)
|
|
104
|
+
},
|
|
105
|
+
...w === void 0 ? {} : { description: w },
|
|
106
|
+
..._.order === void 0 ? {} : { order: _.order },
|
|
107
|
+
...C === void 0 ? {} : { item: C },
|
|
108
|
+
..._.reference === void 0 ? {} : { reference: _.reference }
|
|
109
|
+
}];
|
|
110
|
+
}), m = (e) => e.map((e, t) => [e, t]).sort((e, t) => (e[0].order ?? e[1]) - (t[0].order ?? t[1]) || e[1] - t[1]).map(([e]) => e), h = (t) => {
|
|
111
|
+
try {
|
|
112
|
+
return e.make(t);
|
|
113
|
+
} catch {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}, g = (e) => {
|
|
117
|
+
let t = h(e);
|
|
118
|
+
if (t === void 0) return [];
|
|
119
|
+
let n = t.$defs ?? {}, r = o(t, n), i = r.properties;
|
|
120
|
+
return i ? m(p(i, new Set(Array.isArray(r.required) ? r.required : []), n)) : [];
|
|
121
|
+
}, _ = (e) => {
|
|
122
|
+
let t = h(e);
|
|
123
|
+
if (t === void 0) return [];
|
|
124
|
+
let n = t.$defs ?? {}, r = o(t, n);
|
|
125
|
+
if (r.type !== "array") return [];
|
|
126
|
+
let i = r.items;
|
|
127
|
+
if (!i || typeof i != "object") return [];
|
|
128
|
+
let a = o(i, n), s = a.properties;
|
|
129
|
+
return s ? p(s, new Set(Array.isArray(a.required) ? a.required : []), n) : [];
|
|
130
|
+
}, v = (e) => {
|
|
131
|
+
let t = [];
|
|
132
|
+
for (let n of e) {
|
|
133
|
+
let e = t[t.length - 1];
|
|
134
|
+
if (e !== void 0 && e.name === n.section) {
|
|
135
|
+
e.fields.push(n);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
t.push({
|
|
139
|
+
name: n.section,
|
|
140
|
+
label: n.sectionLabel,
|
|
141
|
+
fields: [n]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
}, y = {
|
|
146
|
+
en: {
|
|
147
|
+
"validation.required": "Required",
|
|
148
|
+
"validation.invalid": "Invalid value",
|
|
149
|
+
"validation.minLength": "Must be at least {min} characters",
|
|
150
|
+
"validation.maxLength": "Must be at most {max} characters",
|
|
151
|
+
"validation.pattern": "Invalid format",
|
|
152
|
+
"validation.minValue": "Must be at least {min}",
|
|
153
|
+
"validation.maxValue": "Must be at most {max}",
|
|
154
|
+
"validation.minItems": "Add at least {min}",
|
|
155
|
+
"validation.maxItems": "No more than {max}",
|
|
156
|
+
"validation.integer": "Must be a whole number",
|
|
157
|
+
"validation.checking": "Still checking…",
|
|
158
|
+
"validation.invalidEmail": "Enter a valid email address",
|
|
159
|
+
"validation.invalidUrl": "Enter a valid URL",
|
|
160
|
+
"validation.invalidUuid": "Enter a valid identifier",
|
|
161
|
+
"validation.betweenLength": "Must be between {min} and {max} characters",
|
|
162
|
+
"validation.exactLength": "Must be exactly {amount} characters",
|
|
163
|
+
"validation.minDate": "Must not be earlier than {min}",
|
|
164
|
+
"validation.maxDate": "Must not be later than {max}",
|
|
165
|
+
"validation.invalidFileType": "This file type is not allowed",
|
|
166
|
+
"validation.fileTooLarge": "File is too large"
|
|
167
|
+
},
|
|
168
|
+
de: {
|
|
169
|
+
"validation.required": "Pflichtfeld",
|
|
170
|
+
"validation.invalid": "Ungültiger Wert",
|
|
171
|
+
"validation.minLength": "Mindestens {min} Zeichen",
|
|
172
|
+
"validation.maxLength": "Höchstens {max} Zeichen",
|
|
173
|
+
"validation.pattern": "Ungültiges Format",
|
|
174
|
+
"validation.minValue": "Mindestens {min}",
|
|
175
|
+
"validation.maxValue": "Höchstens {max}",
|
|
176
|
+
"validation.minItems": "Mindestens {min}",
|
|
177
|
+
"validation.maxItems": "Höchstens {max}",
|
|
178
|
+
"validation.integer": "Ganze Zahl erforderlich",
|
|
179
|
+
"validation.checking": "Prüfung läuft…",
|
|
180
|
+
"validation.invalidEmail": "Bitte eine gültige E-Mail-Adresse eingeben",
|
|
181
|
+
"validation.invalidUrl": "Bitte eine gültige URL eingeben",
|
|
182
|
+
"validation.invalidUuid": "Bitte eine gültige Kennung eingeben",
|
|
183
|
+
"validation.betweenLength": "Muss zwischen {min} und {max} Zeichen haben",
|
|
184
|
+
"validation.exactLength": "Muss genau {amount} Zeichen haben",
|
|
185
|
+
"validation.minDate": "Darf nicht früher sein als {min}",
|
|
186
|
+
"validation.maxDate": "Darf nicht später sein als {max}",
|
|
187
|
+
"validation.invalidFileType": "Dieser Dateityp ist nicht erlaubt",
|
|
188
|
+
"validation.fileTooLarge": "Die Datei ist zu groß"
|
|
189
|
+
}
|
|
190
|
+
}, b = (e, t) => e.replace(/\{(\w+)\}/g, (e, n) => {
|
|
191
|
+
let r = t?.[n];
|
|
192
|
+
return r === void 0 ? e : String(r);
|
|
193
|
+
}), x = () => {
|
|
194
|
+
let e = globalThis.document?.documentElement?.lang ?? "";
|
|
195
|
+
return e === "" ? "en" : e;
|
|
196
|
+
}, S = (e, t) => {
|
|
197
|
+
let n = t?.messages?.(e.id, e.params, e.fallback);
|
|
198
|
+
if (n !== void 0) return n;
|
|
199
|
+
let r = y[(t?.locale ?? x()).toLowerCase().split("-")[0] ?? "en"]?.[e.id] ?? y.en?.[e.id];
|
|
200
|
+
return r === void 0 ? e.fallback : b(r, e.params);
|
|
201
|
+
}, C = (e) => {
|
|
202
|
+
let t = /^([a-z][\w-]*(?:\.[\w-]+)+)\|(\{.*\})$/.exec(e);
|
|
203
|
+
if (t !== null && t[1] !== void 0 && t[2] !== void 0) try {
|
|
204
|
+
return {
|
|
205
|
+
id: t[1],
|
|
206
|
+
params: JSON.parse(t[2]),
|
|
207
|
+
fallback: e
|
|
208
|
+
};
|
|
209
|
+
} catch {}
|
|
210
|
+
return /^[a-z][\w-]*(?:\.[\w-]+)+$/.test(e) ? {
|
|
211
|
+
id: e,
|
|
212
|
+
fallback: e
|
|
213
|
+
} : {
|
|
214
|
+
id: "validation.custom",
|
|
215
|
+
fallback: e
|
|
216
|
+
};
|
|
217
|
+
}, w = {
|
|
218
|
+
email: "validation.invalidEmail",
|
|
219
|
+
"idn-email": "validation.invalidEmail",
|
|
220
|
+
uri: "validation.invalidUrl",
|
|
221
|
+
url: "validation.invalidUrl",
|
|
222
|
+
uuid: "validation.invalidUuid"
|
|
223
|
+
}, T = (e, t) => {
|
|
224
|
+
let r = e.ast;
|
|
225
|
+
for (let e of t.split(".")) {
|
|
226
|
+
if (r === void 0) return {};
|
|
227
|
+
if (/^\d+$/.test(e)) {
|
|
228
|
+
r = r.rest?.[0]?.type;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
let t;
|
|
232
|
+
try {
|
|
233
|
+
t = n.getPropertySignatures(r);
|
|
234
|
+
} catch {
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
r = t.find((t) => String(t.name) === e)?.type;
|
|
238
|
+
}
|
|
239
|
+
let i = {}, a = r;
|
|
240
|
+
for (let e = 0; e < 12 && a !== void 0; e += 1) {
|
|
241
|
+
let e = a.annotations?.[n.JSONSchemaAnnotationId] ?? {};
|
|
242
|
+
i.min === void 0 && typeof e.minLength == "number" && (i.min = e.minLength), i.max === void 0 && typeof e.maxLength == "number" && (i.max = e.maxLength), a = a.from;
|
|
243
|
+
}
|
|
244
|
+
return i;
|
|
245
|
+
}, E = (e) => {
|
|
246
|
+
let r = e[n.SchemaIdAnnotationId], i = e[n.JSONSchemaAnnotationId] ?? {};
|
|
247
|
+
switch (r) {
|
|
248
|
+
case t.MinLengthSchemaId: return {
|
|
249
|
+
id: "validation.minLength",
|
|
250
|
+
params: { min: i.minLength }
|
|
251
|
+
};
|
|
252
|
+
case t.MaxLengthSchemaId: return {
|
|
253
|
+
id: "validation.maxLength",
|
|
254
|
+
params: { max: i.maxLength }
|
|
255
|
+
};
|
|
256
|
+
case t.LengthSchemaId: return {
|
|
257
|
+
id: "validation.exactLength",
|
|
258
|
+
params: { amount: i.minLength }
|
|
259
|
+
};
|
|
260
|
+
case t.PatternSchemaId: {
|
|
261
|
+
let e = typeof i.format == "string" ? w[i.format] : void 0;
|
|
262
|
+
return e === void 0 ? {
|
|
263
|
+
id: "validation.pattern",
|
|
264
|
+
params: { pattern: i.pattern }
|
|
265
|
+
} : { id: e };
|
|
266
|
+
}
|
|
267
|
+
case t.GreaterThanOrEqualToSchemaId: return {
|
|
268
|
+
id: "validation.minValue",
|
|
269
|
+
params: { min: i.minimum }
|
|
270
|
+
};
|
|
271
|
+
case t.LessThanOrEqualToSchemaId: return {
|
|
272
|
+
id: "validation.maxValue",
|
|
273
|
+
params: { max: i.maximum }
|
|
274
|
+
};
|
|
275
|
+
case t.GreaterThanSchemaId: return {
|
|
276
|
+
id: "validation.minValue",
|
|
277
|
+
params: {
|
|
278
|
+
min: i.exclusiveMinimum,
|
|
279
|
+
exclusive: !0
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
case t.LessThanSchemaId: return {
|
|
283
|
+
id: "validation.maxValue",
|
|
284
|
+
params: {
|
|
285
|
+
max: i.exclusiveMaximum,
|
|
286
|
+
exclusive: !0
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
case t.IntSchemaId: return { id: "validation.integer" };
|
|
290
|
+
case t.MinItemsSchemaId: return {
|
|
291
|
+
id: "validation.minItems",
|
|
292
|
+
params: {
|
|
293
|
+
count: i.minItems,
|
|
294
|
+
min: i.minItems
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
case t.MaxItemsSchemaId: return {
|
|
298
|
+
id: "validation.maxItems",
|
|
299
|
+
params: {
|
|
300
|
+
count: i.maxItems,
|
|
301
|
+
max: i.maxItems
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
case t.BetweenSchemaId: return {
|
|
305
|
+
id: "validation.minValue",
|
|
306
|
+
params: {
|
|
307
|
+
min: i.minimum,
|
|
308
|
+
max: i.maximum
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
default: {
|
|
312
|
+
let e = String(r ?? "");
|
|
313
|
+
return /GreaterThanOrEqualToDate|GreaterThanDate/.test(e) ? { id: "validation.minDate" } : /LessThanOrEqualToDate|LessThanDate/.test(e) ? { id: "validation.maxDate" } : { id: "validation.invalid" };
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}, D = (e, t) => {
|
|
317
|
+
let r = e[n.MessageAnnotationId];
|
|
318
|
+
if (typeof r == "function") try {
|
|
319
|
+
let e = r(t);
|
|
320
|
+
if (typeof e == "string") return e;
|
|
321
|
+
if (typeof e == "object" && e && typeof e.message == "string") return e.message;
|
|
322
|
+
} catch {}
|
|
323
|
+
}, O = (e) => Array.isArray(e) ? e.map((e) => String(e)) : [String(e)], k = (e) => {
|
|
324
|
+
let t = [], n = (e, n, r, i) => {
|
|
325
|
+
t.push({
|
|
326
|
+
path: e.join("."),
|
|
327
|
+
id: n,
|
|
328
|
+
...r === void 0 ? {} : { params: r },
|
|
329
|
+
fallback: i
|
|
330
|
+
});
|
|
331
|
+
}, r = (e, t) => {
|
|
332
|
+
let r = C(t);
|
|
333
|
+
n(e, r.id, r.params, r.fallback);
|
|
334
|
+
}, i = (e, t) => {
|
|
335
|
+
switch (e._tag) {
|
|
336
|
+
case "Composite": {
|
|
337
|
+
let n = e.issues;
|
|
338
|
+
if (n === void 0) return;
|
|
339
|
+
for (let e of Array.isArray(n) ? n : [n]) i(e, t);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
case "Pointer":
|
|
343
|
+
e.issue !== void 0 && i(e.issue, [...t, ...O(e.path)]);
|
|
344
|
+
return;
|
|
345
|
+
case "Refinement": {
|
|
346
|
+
if (e.kind === "From") {
|
|
347
|
+
e.issue !== void 0 && i(e.issue, t);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
let a = e.ast?.annotations ?? {}, o = D(a, e);
|
|
351
|
+
if (o !== void 0) return r(t, o);
|
|
352
|
+
let s = E(a);
|
|
353
|
+
if (s.id !== "validation.invalid") {
|
|
354
|
+
n(t, s.id, s.params, A(e));
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (e.issue !== void 0 && (e.issue._tag === "Pointer" || e.issue._tag === "Composite" || e.issue._tag === "Type")) {
|
|
358
|
+
i(e.issue, t);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
n(t, "validation.invalid", void 0, A(e));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
case "Transformation":
|
|
365
|
+
e.issue !== void 0 && i(e.issue, t);
|
|
366
|
+
return;
|
|
367
|
+
case "Missing":
|
|
368
|
+
n(t, "validation.required", void 0, "Required");
|
|
369
|
+
return;
|
|
370
|
+
case "Type": {
|
|
371
|
+
if (typeof e.message == "string" && e.message.length > 0) return r(t, e.message);
|
|
372
|
+
let i = e.ast?.annotations, a = i === void 0 ? void 0 : D(i, e);
|
|
373
|
+
if (a !== void 0) return r(t, a);
|
|
374
|
+
n(t, "validation.invalid", void 0, A(e));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
default:
|
|
378
|
+
n(t, "validation.invalid", void 0, A(e));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
return i(e.issue, []), t;
|
|
383
|
+
}, A = (e) => typeof e.message == "string" && e.message.length > 0 ? e.message : "Invalid value", j = (e, t) => {
|
|
384
|
+
if (typeof t != "object" || !t || Array.isArray(t)) return {
|
|
385
|
+
input: t,
|
|
386
|
+
dropped: []
|
|
387
|
+
};
|
|
388
|
+
let r;
|
|
389
|
+
try {
|
|
390
|
+
r = n.getPropertySignatures(e.ast).map((e) => String(e.name));
|
|
391
|
+
} catch {
|
|
392
|
+
return {
|
|
393
|
+
input: t,
|
|
394
|
+
dropped: []
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
if (r.length === 0) return {
|
|
398
|
+
input: t,
|
|
399
|
+
dropped: []
|
|
400
|
+
};
|
|
401
|
+
let i = new Set(r), a = Object.entries(t), o = a.filter(([e]) => !i.has(e)).map(([e]) => e);
|
|
402
|
+
return o.length === 0 ? {
|
|
403
|
+
input: t,
|
|
404
|
+
dropped: []
|
|
405
|
+
} : {
|
|
406
|
+
input: Object.fromEntries(a.filter(([e]) => i.has(e))),
|
|
407
|
+
dropped: o
|
|
408
|
+
};
|
|
409
|
+
}, M = (e, n, r) => {
|
|
410
|
+
let i = t.decodeUnknownEither(e, { errors: "all" })(n);
|
|
411
|
+
if (i._tag === "Right") return {
|
|
412
|
+
valid: !0,
|
|
413
|
+
errors: {},
|
|
414
|
+
issues: []
|
|
415
|
+
};
|
|
416
|
+
let a = k(i.left).map((t) => {
|
|
417
|
+
if (t.id !== "validation.minLength" && t.id !== "validation.maxLength") return t;
|
|
418
|
+
let n = T(e, t.path);
|
|
419
|
+
return n.min === void 0 || n.max === void 0 ? t : n.min === n.max ? {
|
|
420
|
+
...t,
|
|
421
|
+
id: "validation.exactLength",
|
|
422
|
+
params: { amount: n.min }
|
|
423
|
+
} : {
|
|
424
|
+
...t,
|
|
425
|
+
id: "validation.betweenLength",
|
|
426
|
+
params: {
|
|
427
|
+
min: n.min,
|
|
428
|
+
max: n.max
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}), o = {};
|
|
432
|
+
for (let e of a) e.path !== "" && !(e.path in o) && (o[e.path] = S(e, r));
|
|
433
|
+
return {
|
|
434
|
+
valid: !1,
|
|
435
|
+
errors: o,
|
|
436
|
+
issues: a
|
|
437
|
+
};
|
|
438
|
+
}, N = [
|
|
439
|
+
"bold",
|
|
440
|
+
"italic",
|
|
441
|
+
"code",
|
|
442
|
+
"strike"
|
|
443
|
+
], te = 5e3, ne = (e) => {
|
|
444
|
+
let t = "";
|
|
445
|
+
for (let n of e) {
|
|
446
|
+
let e = n.codePointAt(0) ?? 0;
|
|
447
|
+
e > 32 && e !== 127 && (t += n);
|
|
448
|
+
}
|
|
449
|
+
return t.toLowerCase();
|
|
450
|
+
}, P = (e) => {
|
|
451
|
+
let t = ne(e);
|
|
452
|
+
return t.length === 0 ? !1 : t.startsWith("#") || t.startsWith("/") ? !t.startsWith("//") : t.startsWith("https://") || t.startsWith("http://") || t.startsWith("mailto:");
|
|
453
|
+
}, re = t.String.pipe(t.filter((e) => P(e) || "href must be http(s), mailto:, a #fragment or a /path")), F = t.Struct({
|
|
454
|
+
type: t.Literal("text"),
|
|
455
|
+
text: t.String,
|
|
456
|
+
marks: t.optional(t.Array(t.Literal(...N)))
|
|
457
|
+
}), I = t.Struct({
|
|
458
|
+
type: t.Literal("link"),
|
|
459
|
+
href: re,
|
|
460
|
+
content: t.Array(F)
|
|
461
|
+
}), L = t.Union(F, I), R = t.Struct({
|
|
462
|
+
type: t.Literal("listItem"),
|
|
463
|
+
content: t.Array(L)
|
|
464
|
+
}), z = t.Union(t.Struct({
|
|
465
|
+
type: t.Literal("paragraph"),
|
|
466
|
+
content: t.Array(L)
|
|
467
|
+
}), t.Struct({
|
|
468
|
+
type: t.Literal("heading"),
|
|
469
|
+
level: t.Literal(1, 2, 3),
|
|
470
|
+
content: t.Array(L)
|
|
471
|
+
}), t.Struct({
|
|
472
|
+
type: t.Literal("blockquote"),
|
|
473
|
+
content: t.Array(L)
|
|
474
|
+
}), t.Struct({
|
|
475
|
+
type: t.Literal("bulletList"),
|
|
476
|
+
content: t.Array(R)
|
|
477
|
+
}), t.Struct({
|
|
478
|
+
type: t.Literal("orderedList"),
|
|
479
|
+
content: t.Array(R)
|
|
480
|
+
}), t.Struct({
|
|
481
|
+
type: t.Literal("codeBlock"),
|
|
482
|
+
text: t.String
|
|
483
|
+
})), B = (e) => {
|
|
484
|
+
let t = 1, n = (e) => {
|
|
485
|
+
for (let r of e) {
|
|
486
|
+
t += 1;
|
|
487
|
+
let e = r.content;
|
|
488
|
+
Array.isArray(e) && n(e);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
return n(e.content), t;
|
|
492
|
+
}, V = t.Struct({
|
|
493
|
+
type: t.Literal("doc"),
|
|
494
|
+
content: t.Array(z)
|
|
495
|
+
}).pipe(t.filter((e) => B(e) <= 5e3 || "rich text document exceeds 5000 nodes"), t.annotations(r({ widget: "rich-text" }))), H = {
|
|
496
|
+
type: "doc",
|
|
497
|
+
content: []
|
|
498
|
+
}, U = (e) => typeof e == "object" && !!e && e.type === "doc" && Array.isArray(e.content), W = /(\*\*([^*]+)\*\*)|(~~([^~]+)~~)|(\*([^*]+)\*)|(`([^`]+)`)|(\[([^\]]*)\]\(([^)\s]+)\))/, G = (e, t) => t && t.length > 0 ? {
|
|
499
|
+
type: "text",
|
|
500
|
+
text: e,
|
|
501
|
+
marks: t
|
|
502
|
+
} : {
|
|
503
|
+
type: "text",
|
|
504
|
+
text: e
|
|
505
|
+
}, K = (e) => {
|
|
506
|
+
let t = [], n = e;
|
|
507
|
+
for (;;) {
|
|
508
|
+
let e = W.exec(n);
|
|
509
|
+
if (e === null || e.index === void 0) break;
|
|
510
|
+
e.index > 0 && t.push(G(n.slice(0, e.index))), e[2] === void 0 ? e[4] === void 0 ? e[6] === void 0 ? e[8] === void 0 ? e[11] !== void 0 && (P(e[11]) ? t.push({
|
|
511
|
+
type: "link",
|
|
512
|
+
href: e[11],
|
|
513
|
+
content: [{
|
|
514
|
+
type: "text",
|
|
515
|
+
text: e[10] ?? ""
|
|
516
|
+
}]
|
|
517
|
+
}) : t.push(G(e[0]))) : t.push(G(e[8], ["code"])) : t.push(G(e[6], ["italic"])) : t.push(G(e[4], ["strike"])) : t.push(G(e[2], ["bold"])), n = n.slice(e.index + e[0].length);
|
|
518
|
+
}
|
|
519
|
+
return n.length > 0 && t.push(G(n)), t;
|
|
520
|
+
}, q = (e, t) => e.map((e) => ({
|
|
521
|
+
type: "listItem",
|
|
522
|
+
content: K(e.replace(t, ""))
|
|
523
|
+
})), J = (e) => {
|
|
524
|
+
if (e.length === 0) return null;
|
|
525
|
+
let t = e[0];
|
|
526
|
+
if (t.startsWith("```")) return {
|
|
527
|
+
type: "codeBlock",
|
|
528
|
+
text: e.slice(1).filter((e) => !e.startsWith("```")).join("\n")
|
|
529
|
+
};
|
|
530
|
+
let n = /^(#{1,3})\s+(.*)$/.exec(t);
|
|
531
|
+
return n === null ? e.every((e) => /^[-*]\s+/.test(e)) ? {
|
|
532
|
+
type: "bulletList",
|
|
533
|
+
content: q(e, /^[-*]\s+/)
|
|
534
|
+
} : e.every((e) => /^\d+\.\s+/.test(e)) ? {
|
|
535
|
+
type: "orderedList",
|
|
536
|
+
content: q(e, /^\d+\.\s+/)
|
|
537
|
+
} : e.every((e) => e.startsWith(">")) ? {
|
|
538
|
+
type: "blockquote",
|
|
539
|
+
content: K(e.map((e) => e.replace(/^>\s?/, "")).join(" "))
|
|
540
|
+
} : {
|
|
541
|
+
type: "paragraph",
|
|
542
|
+
content: K(e.join(" "))
|
|
543
|
+
} : {
|
|
544
|
+
type: "heading",
|
|
545
|
+
level: n[1].length,
|
|
546
|
+
content: K(n[2])
|
|
547
|
+
};
|
|
548
|
+
}, Y = (e) => {
|
|
549
|
+
let t = [], n = [], r = () => {
|
|
550
|
+
let e = J(n);
|
|
551
|
+
e !== null && t.push(e), n = [];
|
|
552
|
+
};
|
|
553
|
+
for (let t of e.replace(/\r\n/g, "\n").split("\n")) t.trim() === "" ? r() : n.push(t);
|
|
554
|
+
return r(), {
|
|
555
|
+
type: "doc",
|
|
556
|
+
content: t
|
|
557
|
+
};
|
|
558
|
+
}, X = (e) => e.map((e) => {
|
|
559
|
+
if (e.type === "link") return `[${e.content.map((e) => e.text).join("")}](${e.href})`;
|
|
560
|
+
let t = e.marks ?? [];
|
|
561
|
+
return t.includes("bold") ? `**${e.text}**` : t.includes("strike") ? `~~${e.text}~~` : t.includes("italic") ? `*${e.text}*` : t.includes("code") ? `\`${e.text}\`` : e.text;
|
|
562
|
+
}).join(""), ie = (e) => U(e) ? e.content.map((e) => {
|
|
563
|
+
switch (e.type) {
|
|
564
|
+
case "heading": return `${"#".repeat(e.level)} ${X(e.content)}`;
|
|
565
|
+
case "bulletList": return e.content.map((e) => `- ${X(e.content)}`).join("\n");
|
|
566
|
+
case "orderedList": return e.content.map((e, t) => `${t + 1}. ${X(e.content)}`).join("\n");
|
|
567
|
+
case "blockquote": return `> ${X(e.content)}`;
|
|
568
|
+
case "codeBlock": return [
|
|
569
|
+
"```",
|
|
570
|
+
e.text,
|
|
571
|
+
"```"
|
|
572
|
+
].join("\n");
|
|
573
|
+
default: return X(e.content);
|
|
574
|
+
}
|
|
575
|
+
}).join("\n\n") : "", ae = (e) => {
|
|
576
|
+
if (!U(e)) return "";
|
|
577
|
+
let t = (e) => e.map((e) => e.type === "link" ? e.content.map((e) => e.text).join("") : e.text).join("");
|
|
578
|
+
return e.content.map((e) => {
|
|
579
|
+
switch (e.type) {
|
|
580
|
+
case "bulletList":
|
|
581
|
+
case "orderedList": return e.content.map((e) => t(e.content)).join("\n");
|
|
582
|
+
case "codeBlock": return e.text;
|
|
583
|
+
default: return t(e.content);
|
|
584
|
+
}
|
|
585
|
+
}).join("\n\n");
|
|
586
|
+
}, oe = "__voltro_form_flash__", Z = "/form/", se = (e) => `${Z}${encodeURIComponent(e)}`, Q = "__voltro_form", ce = "__voltro_redirect", $ = (e) => {
|
|
587
|
+
let t = Number(e);
|
|
588
|
+
return Number.isNaN(t) ? e : t;
|
|
589
|
+
}, le = (e) => {
|
|
590
|
+
let t = e.jsonSchema.items;
|
|
591
|
+
if (!t || typeof t != "object") return;
|
|
592
|
+
let n = t.type;
|
|
593
|
+
return typeof n == "string" ? n : void 0;
|
|
594
|
+
}, ue = (e, t) => {
|
|
595
|
+
switch (e.widget) {
|
|
596
|
+
case "rich-text": return t === "" ? {
|
|
597
|
+
type: "doc",
|
|
598
|
+
content: []
|
|
599
|
+
} : Y(t);
|
|
600
|
+
case "number": return t === "" ? void 0 : $(t);
|
|
601
|
+
case "date":
|
|
602
|
+
case "datetime": return t === "" ? void 0 : t;
|
|
603
|
+
default: return t;
|
|
604
|
+
}
|
|
605
|
+
}, de = (e, t) => {
|
|
606
|
+
let n = /* @__PURE__ */ new Map();
|
|
607
|
+
for (let [e, r] of t) {
|
|
608
|
+
let t = n.get(e);
|
|
609
|
+
t === void 0 ? n.set(e, [r]) : t.push(r);
|
|
610
|
+
}
|
|
611
|
+
let r = {}, i = (e, t) => {
|
|
612
|
+
let n = e.split("."), i = r;
|
|
613
|
+
for (let e of n.slice(0, -1)) {
|
|
614
|
+
let t = i[e];
|
|
615
|
+
if (typeof t != "object" || !t) {
|
|
616
|
+
let t = {};
|
|
617
|
+
i[e] = t, i = t;
|
|
618
|
+
} else i = t;
|
|
619
|
+
}
|
|
620
|
+
i[n[n.length - 1]] = t;
|
|
621
|
+
};
|
|
622
|
+
for (let t of g(e)) {
|
|
623
|
+
if (t.widget === "array") continue;
|
|
624
|
+
let e = n.get(t.name);
|
|
625
|
+
if (t.widget === "checkbox" || t.widget === "switch") {
|
|
626
|
+
i(t.name, e !== void 0);
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (t.widget === "multi-select") {
|
|
630
|
+
let n = le(t), r = e ?? [];
|
|
631
|
+
i(t.name, n === "number" || n === "integer" ? r.filter((e) => e !== "").map($) : r.filter((e) => e !== ""));
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (e === void 0) continue;
|
|
635
|
+
let r = ue(t, e[0]);
|
|
636
|
+
r !== void 0 && i(t.name, r);
|
|
637
|
+
}
|
|
638
|
+
return r;
|
|
639
|
+
};
|
|
640
|
+
//#endregion
|
|
641
|
+
export { _ as C, v as S, x as _, se as a, M as b, te as c, U as d, P as f, k as g, ie as h, ce as i, V as l, ae as m, Q as n, de as o, Y as p, Z as r, N as s, oe as t, H as u, S as v, g as w, r as x, j as y };
|