lutra 0.0.5 → 0.0.7
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/datatable/DataTable.svelte +2 -8
- package/dist/datatable/DataTable.svelte.d.ts +1 -0
- package/dist/datatable/DataTableRow.svelte +32 -0
- package/dist/datatable/DataTableRow.svelte.d.ts +3 -0
- package/dist/form/FieldError.svelte +14 -0
- package/dist/form/FieldError.svelte.d.ts +17 -0
- package/dist/form/Form.svelte +73 -2
- package/dist/form/Form.svelte.d.ts +5 -0
- package/dist/form/Input.svelte +52 -14
- package/dist/form/Input.svelte.d.ts +17 -3
- package/dist/form/client.svelte.d.ts +45 -0
- package/dist/form/client.svelte.js +85 -0
- package/dist/form/form.d.ts +50 -32
- package/dist/form/form.js +319 -28
- package/dist/form/index.d.ts +4 -0
- package/dist/form/index.js +4 -0
- package/dist/form/server.d.ts +21 -0
- package/dist/form/server.js +48 -0
- package/dist/form/types.d.ts +53 -0
- package/dist/layout/Theme.svelte +6 -1
- package/dist/style.css +19 -3
- package/dist/typo/H2.svelte +1 -1
- package/dist/typo/H4.svelte +1 -1
- package/dist/typo/H5.svelte +1 -1
- package/dist/typo/H6.svelte +1 -1
- package/package.json +9 -3
package/dist/form/form.js
CHANGED
@@ -1,31 +1,322 @@
|
|
1
|
-
import {
|
2
|
-
import { ZodArray, ZodNullable, ZodObject,
|
3
|
-
|
4
|
-
export const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
import { Bodyguard } from "@auth70/bodyguard";
|
2
|
+
import { ZodArray, ZodNullable, ZodOptional, ZodEffects, ZodObject, ZodDefault, ZodString, ZodNumber, ZodBoolean, ZodDate, array } from "zod";
|
3
|
+
import { zerialize, dezerialize } from "@auth70/zodex-esm";
|
4
|
+
export const bodyguard = new Bodyguard();
|
5
|
+
/**
|
6
|
+
* Map a Zod type to a field type as a string.
|
7
|
+
* @param {Zod.ZodType} schema - The Zod schema to map to a field type.
|
8
|
+
* @returns {string} - The field type as a string.
|
9
|
+
*/
|
10
|
+
function mapZodTypeToFieldType(schema) {
|
11
|
+
if (schema instanceof ZodNullable) {
|
12
|
+
return mapZodTypeToFieldType(schema.unwrap());
|
13
|
+
}
|
14
|
+
if (schema instanceof ZodOptional) {
|
15
|
+
return mapZodTypeToFieldType(schema.unwrap());
|
16
|
+
}
|
17
|
+
if (schema instanceof ZodEffects) {
|
18
|
+
return mapZodTypeToFieldType(schema._def?.schema ?? schema);
|
19
|
+
}
|
11
20
|
if (schema instanceof ZodArray) {
|
12
|
-
return
|
21
|
+
return `Array<${mapZodTypeToFieldType(schema.element)}>`;
|
13
22
|
}
|
14
|
-
// check if schema is an object
|
15
23
|
if (schema instanceof ZodObject) {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
return 'object';
|
25
|
+
}
|
26
|
+
if (schema instanceof ZodDefault) {
|
27
|
+
return mapZodTypeToFieldType(schema._def.innerType);
|
28
|
+
}
|
29
|
+
if (schema instanceof ZodDate) {
|
30
|
+
return 'date';
|
31
|
+
}
|
32
|
+
if (schema instanceof ZodString) {
|
33
|
+
return 'string';
|
34
|
+
}
|
35
|
+
if (schema instanceof ZodNumber) {
|
36
|
+
return 'number';
|
37
|
+
}
|
38
|
+
if (schema instanceof ZodBoolean) {
|
39
|
+
return 'boolean';
|
40
|
+
}
|
41
|
+
return schema.constructor.name;
|
42
|
+
}
|
43
|
+
/**
|
44
|
+
* Get fields from a Zod schema.
|
45
|
+
* @param {ZodObject<any>} schema - The schema to get fields from.
|
46
|
+
* @returns {Record<string, any>} - The fields from the schema.
|
47
|
+
*/
|
48
|
+
export function getFieldsFromSchema(schema, data, parents) {
|
49
|
+
if (!parents)
|
50
|
+
parents = [];
|
51
|
+
else
|
52
|
+
parents = [...parents];
|
53
|
+
const fields = {};
|
54
|
+
if (schema instanceof ZodEffects) {
|
55
|
+
return getFieldsFromSchema(schema._def.schema, data);
|
56
|
+
}
|
57
|
+
if (!(schema instanceof ZodObject)) {
|
58
|
+
console.error('[lutra] getFieldsFromSchema: Schema is not an object:', schema.constructor.name);
|
59
|
+
return fields;
|
60
|
+
}
|
61
|
+
for (const key in schema.shape) {
|
62
|
+
const field = schema.shape[key];
|
63
|
+
// Fields can be wrapped like ZodDefault._def.innerType._def.InnerType, etc. We want the last inner type's definition.
|
64
|
+
// On the way, let's check if any of the _def include a defaultValue.
|
65
|
+
let required = true;
|
66
|
+
let defaultValue = undefined;
|
67
|
+
let min = undefined;
|
68
|
+
let max = undefined;
|
69
|
+
let pattern = undefined;
|
70
|
+
let minlength = undefined;
|
71
|
+
let maxlength = undefined;
|
72
|
+
let type = field;
|
73
|
+
while (type instanceof ZodEffects || type instanceof ZodOptional || type instanceof ZodDefault || type instanceof ZodNullable) {
|
74
|
+
if (type instanceof ZodOptional || type instanceof ZodNullable) {
|
75
|
+
required = false;
|
76
|
+
type = type._def.innerType;
|
77
|
+
}
|
78
|
+
if (type instanceof ZodDefault) {
|
79
|
+
defaultValue = type._def.defaultValue();
|
80
|
+
type = type._def.innerType;
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
type = type._def.innerType;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
// Check for min/max/regex checks
|
87
|
+
if (type._def.checks) {
|
88
|
+
for (const check of type._def.checks) {
|
89
|
+
if (check.kind === 'min') {
|
90
|
+
if (field instanceof ZodString || field._def?.innerType instanceof ZodString) {
|
91
|
+
minlength = check.value;
|
92
|
+
}
|
93
|
+
else {
|
94
|
+
min = check.value;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
if (check.kind === 'max') {
|
98
|
+
if (field instanceof ZodString || field._def?.innerType instanceof ZodString) {
|
99
|
+
maxlength = check.value;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
max = check.value;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
if (check.kind === 'regex') {
|
106
|
+
pattern = check.regex.source;
|
107
|
+
}
|
108
|
+
if (check.kind === 'email') {
|
109
|
+
// ...
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if (type instanceof ZodObject) {
|
114
|
+
const children = getFieldsFromSchema(type, data, [...parents, key]);
|
115
|
+
Object.entries(children).forEach(([childKey, childField]) => {
|
116
|
+
const name = [...parents, key, childKey].join('.');
|
117
|
+
fields[name] = {
|
118
|
+
name,
|
119
|
+
tainted: childField.tainted,
|
120
|
+
coerce: childField.coerce,
|
121
|
+
min: childField.min,
|
122
|
+
max: childField.max,
|
123
|
+
minlength: childField.minlength,
|
124
|
+
maxlength: childField.maxlength,
|
125
|
+
pattern: childField.pattern,
|
126
|
+
required: childField.required,
|
127
|
+
defaultValue: childField.defaultValue,
|
128
|
+
isArray: childField.isArray,
|
129
|
+
type: childField.type,
|
130
|
+
};
|
131
|
+
});
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
fields[key] = {
|
135
|
+
name: [...parents, key].join('.'),
|
136
|
+
tainted: false,
|
137
|
+
min,
|
138
|
+
max,
|
139
|
+
minlength,
|
140
|
+
maxlength,
|
141
|
+
pattern,
|
142
|
+
required,
|
143
|
+
defaultValue,
|
144
|
+
isArray: field instanceof ZodArray,
|
145
|
+
type: mapZodTypeToFieldType(field instanceof ZodArray ? field.element : field),
|
146
|
+
};
|
147
|
+
}
|
148
|
+
}
|
149
|
+
return fields;
|
150
|
+
}
|
151
|
+
/**
|
152
|
+
* Server page load call. Optionally with a default object to populate the form with from locals.
|
153
|
+
* @param {ZodType} schema - The schema to parse the form with.
|
154
|
+
* @param {RequestEvent} event - The event to load the (possible) form from.
|
155
|
+
* @param {JSONLike} obj - The default object to populate the form with.
|
156
|
+
* @returns {Promise<Form<Z>>} - The form to use.
|
157
|
+
*/
|
158
|
+
export async function loadForm(schema, event, obj) {
|
159
|
+
// If there is a form in locals, it's been passed in from parseForm. Return it.
|
160
|
+
if (event.locals.form) {
|
161
|
+
return event.locals.form;
|
162
|
+
}
|
163
|
+
// Serialize the schema to send over the wire.
|
164
|
+
const serializedSchema = zerialize(schema);
|
165
|
+
// Get the fields from the schema.
|
166
|
+
const fields = getFieldsFromSchema(schema);
|
167
|
+
// Create the form object.
|
168
|
+
const form = event.locals.form;
|
169
|
+
return {
|
170
|
+
valid: form ? form.valid : (obj ? true : false),
|
171
|
+
tainted: form ? form.tainted : false,
|
172
|
+
schema: serializedSchema,
|
173
|
+
posted: form ? form.posted : false,
|
174
|
+
fields,
|
175
|
+
data: Object.assign(Object.fromEntries(Object.entries(fields).map(([key, value]) => {
|
176
|
+
// If the key is in the passed object, use that value. Otherwise, try to use the default value.
|
177
|
+
return [key, value.defaultValue];
|
178
|
+
})), obj ? obj : {}),
|
179
|
+
};
|
180
|
+
}
|
181
|
+
/**
|
182
|
+
* Parse zod issues into form issues (with a path string).
|
183
|
+
* @param {ZodIssue[]} issues - The issues to parse.
|
184
|
+
* @returns {FormIssue[]} - The parsed issues.
|
185
|
+
*/
|
186
|
+
export function parseFormIssues(issues) {
|
187
|
+
return JSON.parse(JSON.stringify(issues.map((issue) => {
|
188
|
+
return {
|
189
|
+
...issue,
|
190
|
+
name: arrayPathToStringPath(issue.path),
|
191
|
+
};
|
192
|
+
})));
|
193
|
+
}
|
194
|
+
/**
|
195
|
+
* Parse a form using a schema.
|
196
|
+
* @param {ZodType} schema - The schema to parse the form with.
|
197
|
+
* @param {Request} request - The request to parse.
|
198
|
+
* @param {BodyguardFormConfig} opts - The options for the form validation.
|
199
|
+
* @returns {Promise<{ valid: false } | { valid: true, data: Infer<Z> }>} - The result of the form validation.
|
200
|
+
*/
|
201
|
+
export async function parseForm(schema, event, opts) {
|
202
|
+
// Use bodyguard to parse the form.
|
203
|
+
const data = await bodyguard.softForm(event.request, schema.parse, opts);
|
204
|
+
// Get the fields from the schema.
|
205
|
+
const fields = getFieldsFromSchema(schema, data);
|
206
|
+
// Serialize the schema to send over the wire.
|
207
|
+
const serializedSchema = zerialize(schema);
|
208
|
+
// Create the form object.
|
209
|
+
const form = {
|
210
|
+
valid: data.success,
|
211
|
+
tainted: !data.success,
|
212
|
+
schema: serializedSchema,
|
213
|
+
posted: true,
|
214
|
+
fields: Object.fromEntries(Object.entries(fields).map(([key, field]) => {
|
215
|
+
// Mark fields as tainted if they were in the request.
|
216
|
+
return [key, {
|
217
|
+
...field,
|
218
|
+
tainted: data.success ? false : data.value.hasOwnProperty(key),
|
219
|
+
}];
|
220
|
+
})),
|
221
|
+
data: data.value ? data.value : {},
|
222
|
+
issues: data.success ? undefined : parseFormIssues(data.error.issues),
|
223
|
+
};
|
224
|
+
// Attach the form to the locals to pass it to the client via loadForm.
|
225
|
+
event.locals.form = form;
|
226
|
+
return form;
|
227
|
+
}
|
228
|
+
/**
|
229
|
+
* Convert an array path from a Zod issue to a string path for a form field.
|
230
|
+
* @param {(string | number)[]} path - The path to convert.
|
231
|
+
* @returns {string} - The string path.
|
232
|
+
*/
|
233
|
+
export function arrayPathToStringPath(path) {
|
234
|
+
// Joins the path with dots. For arrays, it adds brackets.
|
235
|
+
return path.map((p) => {
|
236
|
+
if (p.toString().match(/^\d+$/)) {
|
237
|
+
return `${p}[]`;
|
238
|
+
}
|
239
|
+
return p;
|
240
|
+
}).join('.');
|
241
|
+
}
|
242
|
+
/**
|
243
|
+
* Get a value from an object using a string path.
|
244
|
+
* @param {any} obj - The object to get the value from.
|
245
|
+
* @param {string} path - The path to get the value from.
|
246
|
+
* @returns {string | number | Date | boolean | object | undefined} - The value from the object.
|
247
|
+
*/
|
248
|
+
export function getFromObjWithStringPath(obj, path) {
|
249
|
+
const parts = path.split('.');
|
250
|
+
let current = obj;
|
251
|
+
for (let i = 0; i < parts.length; i++) {
|
252
|
+
const part = parts[i];
|
253
|
+
// Support for array access patterns: foo[] or foo[0]
|
254
|
+
const arrayMatch = part.match(/^(.+?)(\[\d*\])?$/);
|
255
|
+
if (arrayMatch) {
|
256
|
+
const [, key, indexPart] = arrayMatch;
|
257
|
+
// Navigate into 'properties' if it exists
|
258
|
+
if (current.properties && current.properties[key]) {
|
259
|
+
current = current.properties[key];
|
260
|
+
}
|
261
|
+
else if (current[key]) {
|
262
|
+
current = current[key];
|
263
|
+
}
|
264
|
+
else {
|
265
|
+
// The path is invalid for the given structure or the index is not a number
|
266
|
+
return undefined;
|
267
|
+
}
|
268
|
+
// If indexPart is defined, it means we're dealing with an array index
|
269
|
+
if (indexPart) {
|
270
|
+
// Dealing with an array index, e.g., [0]
|
271
|
+
const index = parseInt(indexPart.slice(1, -1), 10);
|
272
|
+
if (!Array.isArray(current) || isNaN(index)) {
|
273
|
+
return undefined;
|
274
|
+
}
|
275
|
+
current = current[index];
|
276
|
+
}
|
277
|
+
}
|
278
|
+
else {
|
279
|
+
// Direct property access
|
280
|
+
if (current.properties && current.properties[part]) {
|
281
|
+
current = current.properties[part];
|
282
|
+
}
|
283
|
+
else if (current[part]) {
|
284
|
+
current = current[part];
|
285
|
+
}
|
286
|
+
else {
|
287
|
+
return undefined;
|
288
|
+
}
|
289
|
+
}
|
290
|
+
if (current === undefined) {
|
291
|
+
return undefined;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
// The value must be directly returnable without checking type,
|
295
|
+
// as we might be looking for an object structure.
|
296
|
+
return current;
|
297
|
+
}
|
298
|
+
/**
|
299
|
+
* Get individual validators for each field in a form.
|
300
|
+
* @param {Form} form - The form to get the validators from.
|
301
|
+
* @returns {Record<keyof Infer<T>, (value: any) => boolean>} - The validators for each field.
|
302
|
+
*/
|
303
|
+
export function getIndividualValidators(form) {
|
304
|
+
const schema = form.schema;
|
305
|
+
const fields = form.fields;
|
306
|
+
if (!schema || !fields) {
|
307
|
+
console.error('[lutra] getIndividualValidators: Schema or fields not found:', schema, fields);
|
308
|
+
return {};
|
309
|
+
}
|
310
|
+
// Match the dot-notation form fields with the object schema fields.
|
311
|
+
// For each field, create a validator function by dezerilizing the schema for that field from the schema.
|
312
|
+
// Return the validators, not the parsed data.
|
313
|
+
const validators = Object.fromEntries(Object.entries(fields).map(([key, field]) => {
|
314
|
+
const schemaField = getFromObjWithStringPath(schema, key);
|
315
|
+
if (!schemaField) {
|
316
|
+
console.error('[lutra] getIndividualValidators: Schema field not found:', key);
|
317
|
+
return [key, (value) => true];
|
318
|
+
}
|
319
|
+
return [key, dezerialize(schemaField)];
|
320
|
+
}));
|
321
|
+
return validators;
|
322
|
+
}
|
package/dist/form/index.d.ts
CHANGED
@@ -2,6 +2,7 @@ export { default as Button } from './Button.svelte';
|
|
2
2
|
export { default as FieldContainer } from './FieldContainer.svelte';
|
3
3
|
export { default as FieldSection } from './FieldSection.svelte';
|
4
4
|
export { default as FieldActions } from './FieldActions.svelte';
|
5
|
+
export { default as FieldError } from './FieldError.svelte';
|
5
6
|
export { default as FieldContent } from './FieldContent.svelte';
|
6
7
|
export { default as Fieldset } from './Fieldset.svelte';
|
7
8
|
export { default as Form } from './Form.svelte';
|
@@ -9,3 +10,6 @@ export { default as Input } from './Input.svelte';
|
|
9
10
|
export { default as InputLength } from './InputLength.svelte';
|
10
11
|
export { default as Label } from './Label.svelte';
|
11
12
|
export { default as Select } from './Select.svelte';
|
13
|
+
export * from './types.js';
|
14
|
+
export * from './form.js';
|
15
|
+
export * from './client.svelte.js';
|
package/dist/form/index.js
CHANGED
@@ -2,6 +2,7 @@ export { default as Button } from './Button.svelte';
|
|
2
2
|
export { default as FieldContainer } from './FieldContainer.svelte';
|
3
3
|
export { default as FieldSection } from './FieldSection.svelte';
|
4
4
|
export { default as FieldActions } from './FieldActions.svelte';
|
5
|
+
export { default as FieldError } from './FieldError.svelte';
|
5
6
|
export { default as FieldContent } from './FieldContent.svelte';
|
6
7
|
export { default as Fieldset } from './Fieldset.svelte';
|
7
8
|
export { default as Form } from './Form.svelte';
|
@@ -9,3 +10,6 @@ export { default as Input } from './Input.svelte';
|
|
9
10
|
export { default as InputLength } from './InputLength.svelte';
|
10
11
|
export { default as Label } from './Label.svelte';
|
11
12
|
export { default as Select } from './Select.svelte';
|
13
|
+
export * from './types.js';
|
14
|
+
export * from './form.js';
|
15
|
+
export * from './client.svelte.js';
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Bodyguard } from "@auth70/bodyguard";
|
2
|
+
import type { ActionFailure, RequestEvent } from "@sveltejs/kit";
|
3
|
+
import type { z, ZodType } from "zod";
|
4
|
+
export declare const bodyguard: Bodyguard;
|
5
|
+
export type Issue = {
|
6
|
+
message: string;
|
7
|
+
path: string[];
|
8
|
+
field: string;
|
9
|
+
};
|
10
|
+
export declare class FormError extends Error {
|
11
|
+
issues: Issue[];
|
12
|
+
constructor(issues: Issue[], message?: string);
|
13
|
+
}
|
14
|
+
export declare function formHandler<T, Z extends ZodType<any, any>>(event: RequestEvent, schema: Z, onSuccess: (data: z.infer<Z>) => Promise<T>, { castNumbers, castBooleans, }?: {
|
15
|
+
castNumbers?: boolean;
|
16
|
+
castBooleans?: boolean;
|
17
|
+
}): Promise<T | ActionFailure<{
|
18
|
+
issues: any;
|
19
|
+
}> | ActionFailure<{
|
20
|
+
message: any;
|
21
|
+
}>>;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { Bodyguard } from "@auth70/bodyguard";
|
2
|
+
import { fail } from "@sveltejs/kit";
|
3
|
+
export const bodyguard = new Bodyguard();
|
4
|
+
export class FormError extends Error {
|
5
|
+
issues;
|
6
|
+
constructor(issues, message = 'Form error') {
|
7
|
+
super(message);
|
8
|
+
this.issues = issues;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
export async function formHandler(event, schema, onSuccess, { castNumbers, castBooleans, } = {
|
12
|
+
castNumbers: false,
|
13
|
+
castBooleans: false,
|
14
|
+
}) {
|
15
|
+
const data = await bodyguard.softForm(event.request, schema.parse, {
|
16
|
+
castNumbers: castNumbers || false,
|
17
|
+
castBooleans: castBooleans || false,
|
18
|
+
});
|
19
|
+
if (!data.success) {
|
20
|
+
try {
|
21
|
+
const issues = JSON.parse(data.error);
|
22
|
+
console.error('[lutra] Bodyguard failed:', data);
|
23
|
+
return fail(400, {
|
24
|
+
issues,
|
25
|
+
});
|
26
|
+
}
|
27
|
+
catch (err) {
|
28
|
+
console.error('[lutra] Bodyguard failed:', data);
|
29
|
+
return fail(400, {
|
30
|
+
issues: data.error
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}
|
34
|
+
try {
|
35
|
+
return Promise.resolve(onSuccess(data.value));
|
36
|
+
}
|
37
|
+
catch (err) {
|
38
|
+
console.error('[lutra] Error in form handler:', err);
|
39
|
+
if (err?.issues) {
|
40
|
+
return fail(400, {
|
41
|
+
issues: err?.issues ?? [],
|
42
|
+
});
|
43
|
+
}
|
44
|
+
return fail(500, {
|
45
|
+
message: err.message
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}
|
package/dist/form/types.d.ts
CHANGED
@@ -1,4 +1,57 @@
|
|
1
|
+
import type { ZodType, infer as Infer, ZodTuple, ZodBigInt, ZodNaN, ZodSet, ZodVoid, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodRecord, ZodMap, ZodDiscriminatedUnion, ZodUnion, ZodIntersection, ZodNativeEnum, ZodEnum, ZodFunction, ZodLazy, ZodLiteral, ZodCatch, ZodPipeline, ZodBranded, ZodPromise, ZodArray, ZodNullable, ZodOptional, ZodEffects, ZodObject, ZodDefault, ZodString, ZodNumber, ZodBoolean, ZodDate } from "zod";
|
1
2
|
export type Autocomplete = 'on' | 'off' | AutocompleteSingleToken | AutocompleteBilling | AutocompleteShipping;
|
2
3
|
export type AutocompleteBilling = 'billing' | `billing ${AutocompleteSingleToken}`;
|
3
4
|
export type AutocompleteShipping = 'shipping' | `shipping ${AutocompleteSingleToken}`;
|
4
5
|
export type AutocompleteSingleToken = `section-${string}` | "name" | "honorific-prefix" | "given-name" | "additional-name" | "family-name" | "honorific-suffix" | "nickname" | "email" | "username" | "new-password" | "current-password" | "one-time-code" | "organization-title" | "organization" | "street-address" | "address-line1" | "address-line2" | "address-line3" | "address-level4" | "address-level3" | "address-level2" | "address-level1" | "country" | "country-name" | "postal-code" | "cc-name" | "cc-given-name" | "cc-additional-name" | "cc-family-name" | "cc-number" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-csc" | "cc-type" | "transaction-currency" | "transaction-amount" | "language" | "bday" | "bday-day" | "bday-month" | "bday-year" | "sex" | "tel" | "tel-country-code" | "tel-national" | "tel-area-code" | "tel-local" | "tel-extension" | "impp" | "url" | "photo" | "webauthn";
|
6
|
+
export type Modifiers = ZodOptional<ZodTypes> | ZodNullable<ZodTypes> | ZodDefault<ZodTypes>;
|
7
|
+
export type Primitives = ZodString | ZodNumber | ZodNaN | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid;
|
8
|
+
export type ListCollections = ZodTuple<any, any> | ZodSet<ZodTypes> | ZodArray<ZodTypes>;
|
9
|
+
export type KVCollections = ZodObject<any> | ZodRecord<any, ZodTypes> | ZodMap<ZodTypes, ZodTypes>;
|
10
|
+
export type ADTs = ZodUnion<readonly [ZodTypes, ...ZodTypes[]]> | ZodDiscriminatedUnion<any, ZodObject<{
|
11
|
+
[k: string]: ZodTypes;
|
12
|
+
}>[]> | ZodIntersection<ZodTypes, ZodTypes> | ZodNativeEnum<any> | ZodEnum<any>;
|
13
|
+
export type ZodTypes = Modifiers | Primitives | ListCollections | KVCollections | ADTs | ZodFunction<any, ZodTypes> | ZodLazy<ZodTypes> | ZodLiteral<any> | ZodEffects<any, any> | ZodCatch<ZodTypes> | ZodPromise<ZodTypes> | ZodBranded<ZodTypes, any> | ZodPipeline<ZodTypes, ZodTypes>;
|
14
|
+
export type ZTypeName<T extends ZodTypes> = T["_def"]["typeName"];
|
15
|
+
export type FormIssue = {
|
16
|
+
name: string;
|
17
|
+
code: string;
|
18
|
+
message?: string;
|
19
|
+
minimum?: number;
|
20
|
+
maximum?: number;
|
21
|
+
exact?: boolean;
|
22
|
+
validation?: string;
|
23
|
+
};
|
24
|
+
export type Form<T extends ZodType<any, any>> = {
|
25
|
+
/** Whether the form is valid. */
|
26
|
+
valid: boolean;
|
27
|
+
/** Whether the user has interacted with the form. */
|
28
|
+
tainted?: boolean;
|
29
|
+
/** Whether the form has been posted. */
|
30
|
+
posted: boolean;
|
31
|
+
/** The schema to parse the form with. */
|
32
|
+
schema?: T;
|
33
|
+
/** The fields of the form. */
|
34
|
+
fields: Record<string, FormField>;
|
35
|
+
/** The data of the form. */
|
36
|
+
data?: Infer<T>;
|
37
|
+
/** Original data for form before editing */
|
38
|
+
originalData?: Infer<T>;
|
39
|
+
/** The issues of the form. */
|
40
|
+
issues?: FormIssue[];
|
41
|
+
};
|
42
|
+
export type FormField = {
|
43
|
+
name: string;
|
44
|
+
tainted: boolean;
|
45
|
+
coerce?: boolean;
|
46
|
+
min?: number;
|
47
|
+
max?: number;
|
48
|
+
minlength?: number;
|
49
|
+
maxlength?: number;
|
50
|
+
hasIssue?: boolean;
|
51
|
+
pattern?: string;
|
52
|
+
required: boolean;
|
53
|
+
defaultValue?: string | number | boolean;
|
54
|
+
isArray: boolean;
|
55
|
+
type: string;
|
56
|
+
children?: Record<string, FormField>;
|
57
|
+
};
|
package/dist/layout/Theme.svelte
CHANGED
@@ -13,7 +13,6 @@ if (theme === "invert") {
|
|
13
13
|
}
|
14
14
|
const existingTheme = getContext("theme");
|
15
15
|
setContext("theme", theme);
|
16
|
-
console.log("theme", theme);
|
17
16
|
</script>
|
18
17
|
|
19
18
|
<svelte:body style="background-color: var(--bg-app);" />
|
@@ -43,6 +42,7 @@ console.log("theme", theme);
|
|
43
42
|
--border-color: var(--l-border-color);
|
44
43
|
--border-subtle-color: var(--l-border-subtle-color);
|
45
44
|
--focus-color: var(--l-focus-color);
|
45
|
+
--focus-color-error: var(--l-focus-color-error);
|
46
46
|
--border: var(--l-border);
|
47
47
|
--border-subtle: var(--l-border-subtle);
|
48
48
|
--focus-outline: var(--l-focus-outline);
|
@@ -58,6 +58,8 @@ console.log("theme", theme);
|
|
58
58
|
--text-warn-icon: var(--l-text-warn-icon);
|
59
59
|
/* fields */
|
60
60
|
--field-bg: var(--l-field-bg);
|
61
|
+
--field-border-color: var(--l-field-border-color);
|
62
|
+
--field-border-color-error: var(--l-field-border-color-error);
|
61
63
|
--field-border: var(--l-field-border);
|
62
64
|
--field-text: var(--l-field-text);
|
63
65
|
--field-placeholder: var(--l-field-placeholder);
|
@@ -133,6 +135,7 @@ console.log("theme", theme);
|
|
133
135
|
--border-color: var(--d-border-color);
|
134
136
|
--border-subtle-color: var(--d-border-subtle-color);
|
135
137
|
--focus-color: var(--d-focus-color);
|
138
|
+
--focus-color-error: var(--d-focus-color-error);
|
136
139
|
--border: var(--d-border);
|
137
140
|
--border-subtle: var(--d-border-subtle);
|
138
141
|
--focus-outline: var(--d-focus-outline);
|
@@ -149,6 +152,8 @@ console.log("theme", theme);
|
|
149
152
|
--text-warn-icon: var(--d-text-warn-icon);
|
150
153
|
/* fields */
|
151
154
|
--field-bg: var(--d-field-bg);
|
155
|
+
--field-border-color: var(--d-field-border-color);
|
156
|
+
--field-border-color-error: var(--d-field-border-color-error);
|
152
157
|
--field-border: var(--d-field-border);
|
153
158
|
--field-text: var(--d-field-text);
|
154
159
|
--field-placeholder: var(--d-field-placeholder);
|
package/dist/style.css
CHANGED
@@ -29,7 +29,9 @@
|
|
29
29
|
--field-radius: 0.35em;
|
30
30
|
--border-size: 1px;
|
31
31
|
--border-style: solid;
|
32
|
-
--
|
32
|
+
--field-border-size: 1px;
|
33
|
+
--field-border-style: solid;
|
34
|
+
--focus-size: 2px;
|
33
35
|
--mix-amount: 80%;
|
34
36
|
/* Transitions */
|
35
37
|
--menu-trans: 0.1s ease-in-out;
|
@@ -46,6 +48,7 @@
|
|
46
48
|
--l-border-color: hsl(215, 6%, 80%);
|
47
49
|
--l-border-subtle-color: hsl(215, 5%, 87%);
|
48
50
|
--l-focus-color: hsl(215, 60%, 55%);
|
51
|
+
--l-focus-color-error: hsl(353, 76%, 58%);
|
49
52
|
--l-border: var(--border-size) var(--border-style) var(--l-border-color);
|
50
53
|
--l-border-subtle: var(--border-size) var(--border-style) var(--l-border-subtle-color);
|
51
54
|
--l-focus-outline: var(--focus-size) solid var(--l-focus-color);
|
@@ -61,7 +64,9 @@
|
|
61
64
|
--l-text-warn-icon: #e74c3c;
|
62
65
|
/* fields */
|
63
66
|
--l-field-bg: transparent;
|
64
|
-
--l-field-border: var(--l-border);
|
67
|
+
--l-field-border-color: var(--l-border-color);
|
68
|
+
--l-field-border-color-error: var(--l-focus-color-error);
|
69
|
+
--l-field-border: var(--field-border-size) var(--field-border-style) var(--l-field-border-color);
|
65
70
|
--l-field-text: var(--l-text);
|
66
71
|
--l-field-placeholder: #999;
|
67
72
|
--l-field-label: #333;
|
@@ -138,6 +143,7 @@
|
|
138
143
|
--d-border-color: hsl(215, 8%, 30%);
|
139
144
|
--d-border-subtle-color: hsl(215, 5%, 25%);
|
140
145
|
--d-focus-color: rgb(77, 144, 254);
|
146
|
+
--d-focus-color-error: red;
|
141
147
|
--d-border: var(--border-size) var(--border-style) var(--d-border-color);
|
142
148
|
--d-border-subtle: var(--border-size) var(--border-style) var(--d-border-subtle-color);
|
143
149
|
--d-focus-outline: var(--focus-size) solid var(--d-focus-color);
|
@@ -154,7 +160,9 @@
|
|
154
160
|
--d-text-warn-icon: #ff6b6b;
|
155
161
|
/* fields */
|
156
162
|
--d-field-bg: transparent;
|
157
|
-
--d-field-border: var(--d-border);
|
163
|
+
--d-field-border-color: var(--d-border-color);
|
164
|
+
--d-field-border-color-error: red;
|
165
|
+
--d-field-border: var(--field-border-size) var(--field-border-style) var(--d-field-border-color);
|
158
166
|
--d-field-text: var(--d-text);
|
159
167
|
--d-field-placeholder: #666;
|
160
168
|
--d-field-label: #ccc;
|
@@ -421,6 +429,14 @@ input, textarea, select {
|
|
421
429
|
transition: border-color 0.1s;
|
422
430
|
}
|
423
431
|
|
432
|
+
input:user-invalid {
|
433
|
+
border-color: var(--field-border-color-error);
|
434
|
+
}
|
435
|
+
|
436
|
+
input:user-invalid:focus-visible {
|
437
|
+
outline-color: var(--focus-color-error);
|
438
|
+
}
|
439
|
+
|
424
440
|
select {
|
425
441
|
padding-right: 2em;
|
426
442
|
appearance: none;
|
package/dist/typo/H2.svelte
CHANGED
package/dist/typo/H4.svelte
CHANGED
package/dist/typo/H5.svelte
CHANGED
package/dist/typo/H6.svelte
CHANGED