solid-hook-form 1.6.2 → 1.6.3
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/main.d.ts +74 -4
- package/dist/main.js +339 -1381
- package/dist/main.jsx +403 -0
- package/package.json +8 -6
- package/dist/form_context.d.ts +0 -1
- package/dist/form_provider.d.ts +0 -7
- package/dist/logic/create_errors.d.ts +0 -10
- package/dist/logic/create_fields.d.ts +0 -6
- package/dist/logic/create_rules.d.ts +0 -8
- package/dist/logic/format_value.d.ts +0 -4
- package/dist/logic/get_value.d.ts +0 -1
- package/dist/logic/set_value.d.ts +0 -1
- package/dist/logic/validate.d.ts +0 -5
- package/dist/main.umd.cjs +0 -29
- package/dist/types/errors.d.ts +0 -10
- package/dist/types/form.d.ts +0 -32
- package/dist/types/path.d.ts +0 -1
- package/dist/types/validate.d.ts +0 -21
- package/dist/use_form.d.ts +0 -9
- package/dist/use_form_context.d.ts +0 -2
- package/dist/utils/get.d.ts +0 -1
- package/dist/utils/resolver.d.ts +0 -5
- package/dist/utils/set.d.ts +0 -1
package/dist/main.jsx
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// src/use_form.ts
|
|
2
|
+
import { createMemo, createSignal as createSignal2 } from "solid-js";
|
|
3
|
+
|
|
4
|
+
// src/logic/get_value.ts
|
|
5
|
+
var getFieldValue = (event) => {
|
|
6
|
+
const field = event.target;
|
|
7
|
+
if (field instanceof HTMLSelectElement) {
|
|
8
|
+
return field.value;
|
|
9
|
+
}
|
|
10
|
+
if (field instanceof HTMLInputElement && field.type === "checkbox") {
|
|
11
|
+
return field.checked;
|
|
12
|
+
}
|
|
13
|
+
if (field instanceof HTMLInputElement && field.type === "file") {
|
|
14
|
+
return [...field.files || []];
|
|
15
|
+
}
|
|
16
|
+
return field.value;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/logic/set_value.ts
|
|
20
|
+
var setFieldValue = (field, value) => {
|
|
21
|
+
if (field instanceof HTMLSelectElement) {
|
|
22
|
+
field.value = value;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (field instanceof HTMLInputElement && field.type === "checkbox") {
|
|
26
|
+
field.checked = value;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (field instanceof HTMLInputElement && field.type === "file") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
field.value = value;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// node_modules/react-hook-form/dist/index.esm.mjs
|
|
36
|
+
import React from "react";
|
|
37
|
+
var isDateObject = (value) => value instanceof Date;
|
|
38
|
+
var isNullOrUndefined = (value) => value == null;
|
|
39
|
+
var isObjectType = (value) => typeof value === "object";
|
|
40
|
+
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
|
|
41
|
+
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
|
|
42
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
43
|
+
var isUndefined = (val) => val === void 0;
|
|
44
|
+
var get = (object, path, defaultValue) => {
|
|
45
|
+
if (!path || !isObject(object)) {
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
48
|
+
const result = compact(path.split(/[,[\].]+?/)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], object);
|
|
49
|
+
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
|
|
50
|
+
};
|
|
51
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
52
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
|
|
53
|
+
var set = (object, path, value) => {
|
|
54
|
+
let index = -1;
|
|
55
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
56
|
+
const length = tempPath.length;
|
|
57
|
+
const lastIndex = length - 1;
|
|
58
|
+
while (++index < length) {
|
|
59
|
+
const key = tempPath[index];
|
|
60
|
+
let newValue = value;
|
|
61
|
+
if (index !== lastIndex) {
|
|
62
|
+
const objValue = object[key];
|
|
63
|
+
newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
|
|
64
|
+
}
|
|
65
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
object[key] = newValue;
|
|
69
|
+
object = object[key];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var VALIDATION_MODE = {
|
|
73
|
+
onBlur: "onBlur",
|
|
74
|
+
onChange: "onChange",
|
|
75
|
+
onSubmit: "onSubmit",
|
|
76
|
+
onTouched: "onTouched",
|
|
77
|
+
all: "all"
|
|
78
|
+
};
|
|
79
|
+
var HookFormContext = React.createContext(null);
|
|
80
|
+
var defaultOptions = {
|
|
81
|
+
mode: VALIDATION_MODE.onSubmit,
|
|
82
|
+
reValidateMode: VALIDATION_MODE.onChange,
|
|
83
|
+
shouldFocusError: true
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/logic/validate.ts
|
|
87
|
+
var getRuleValue = (rule) => {
|
|
88
|
+
if (rule instanceof RegExp) {
|
|
89
|
+
return rule;
|
|
90
|
+
}
|
|
91
|
+
if (typeof rule === "string" || typeof rule === "number") {
|
|
92
|
+
return rule;
|
|
93
|
+
}
|
|
94
|
+
return rule.value;
|
|
95
|
+
};
|
|
96
|
+
var getRuleMessage = (rule) => {
|
|
97
|
+
if (typeof rule === "string") {
|
|
98
|
+
return rule;
|
|
99
|
+
}
|
|
100
|
+
if (typeof rule.message === "string") {
|
|
101
|
+
return rule.message;
|
|
102
|
+
}
|
|
103
|
+
return "";
|
|
104
|
+
};
|
|
105
|
+
var validate = (values, name, rules = {}) => {
|
|
106
|
+
const value = get(values, name);
|
|
107
|
+
if (rules.required && !value) {
|
|
108
|
+
return { type: "required", message: getRuleMessage(rules.required) };
|
|
109
|
+
}
|
|
110
|
+
if (rules.min && Number(value) < Number(getRuleValue(rules.min))) {
|
|
111
|
+
return { type: "min", message: getRuleMessage(rules.min) };
|
|
112
|
+
}
|
|
113
|
+
if (rules.max && Number(value) > Number(getRuleValue(rules.max))) {
|
|
114
|
+
return { type: "max", message: getRuleMessage(rules.max) };
|
|
115
|
+
}
|
|
116
|
+
if (rules.minLength && value.length < getRuleValue(rules.minLength)) {
|
|
117
|
+
return { type: "minLength", message: getRuleMessage(rules.minLength) };
|
|
118
|
+
}
|
|
119
|
+
if (rules.maxLength && value.length > getRuleValue(rules.maxLength)) {
|
|
120
|
+
return { type: "maxLength", message: getRuleMessage(rules.maxLength) };
|
|
121
|
+
}
|
|
122
|
+
if (rules.pattern && !getRuleValue(rules.pattern).test(value)) {
|
|
123
|
+
return { type: "pattern", message: getRuleMessage(rules.pattern) };
|
|
124
|
+
}
|
|
125
|
+
if (rules.validate) {
|
|
126
|
+
const message = rules.validate(value, values);
|
|
127
|
+
if (message === false) {
|
|
128
|
+
return { type: "validate" };
|
|
129
|
+
}
|
|
130
|
+
if (typeof message === "string") {
|
|
131
|
+
return { type: "validate", message };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/logic/create_errors.ts
|
|
137
|
+
import { createSignal } from "solid-js";
|
|
138
|
+
var createErrors = () => {
|
|
139
|
+
const [errors, setErrors] = createSignal({});
|
|
140
|
+
const getError = (name) => {
|
|
141
|
+
return get(errors(), name);
|
|
142
|
+
};
|
|
143
|
+
const appendError = (name, error) => {
|
|
144
|
+
setErrors((prev) => {
|
|
145
|
+
const newState = { ...prev, [name]: error };
|
|
146
|
+
return newState;
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
const removeError = (name) => {
|
|
150
|
+
setErrors((prev) => {
|
|
151
|
+
const newState = { ...prev };
|
|
152
|
+
delete newState[name];
|
|
153
|
+
return newState;
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const resetErrors = () => {
|
|
157
|
+
setErrors({});
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
errors,
|
|
161
|
+
appendError,
|
|
162
|
+
removeError,
|
|
163
|
+
resetErrors,
|
|
164
|
+
getError
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/logic/create_rules.ts
|
|
169
|
+
var createRules = () => {
|
|
170
|
+
const rules = {};
|
|
171
|
+
const addRule = (name, options) => {
|
|
172
|
+
rules[name] = {
|
|
173
|
+
required: options.required,
|
|
174
|
+
min: options.min,
|
|
175
|
+
max: options.max,
|
|
176
|
+
minLength: options.minLength,
|
|
177
|
+
maxLength: options.maxLength,
|
|
178
|
+
pattern: options.pattern,
|
|
179
|
+
valueAsNumber: options.valueAsNumber,
|
|
180
|
+
validate: options.validate
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const getRule = (name) => {
|
|
184
|
+
return rules[name];
|
|
185
|
+
};
|
|
186
|
+
return { rules, addRule, getRule };
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/logic/create_fields.ts
|
|
190
|
+
var createFields = () => {
|
|
191
|
+
const fields = {};
|
|
192
|
+
const getField = (name) => {
|
|
193
|
+
return fields[name];
|
|
194
|
+
};
|
|
195
|
+
const setField = (name, element) => {
|
|
196
|
+
fields[name] = element;
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
fields,
|
|
200
|
+
getField,
|
|
201
|
+
setField
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/logic/format_value.ts
|
|
206
|
+
var formatValue = (value, rules) => {
|
|
207
|
+
if (rules.valueAsNumber) {
|
|
208
|
+
return Number(value);
|
|
209
|
+
}
|
|
210
|
+
return value;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/utils/resolver.ts
|
|
214
|
+
var getResolverFields = (fields) => {
|
|
215
|
+
return Object.entries(fields).reduce((acc, [name, ref]) => {
|
|
216
|
+
acc[name] = {
|
|
217
|
+
ref,
|
|
218
|
+
name
|
|
219
|
+
};
|
|
220
|
+
return acc;
|
|
221
|
+
}, {});
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/use_form.ts
|
|
225
|
+
var useForm = (arg = { defaultValues: {} }) => {
|
|
226
|
+
const { defaultValues, mode = "onInput", resolver } = arg;
|
|
227
|
+
const { fields, getField, setField } = createFields();
|
|
228
|
+
const { rules, addRule, getRule } = createRules();
|
|
229
|
+
const [values, setValues] = createSignal2(defaultValues);
|
|
230
|
+
const { errors, appendError, removeError, resetErrors, getError } = createErrors();
|
|
231
|
+
const isValid = createMemo(() => {
|
|
232
|
+
return !Object.keys(errors()).length;
|
|
233
|
+
});
|
|
234
|
+
const setFieldError = (name, error) => {
|
|
235
|
+
const field = getField(name);
|
|
236
|
+
if (field) {
|
|
237
|
+
error.ref = field;
|
|
238
|
+
}
|
|
239
|
+
appendError(name, error);
|
|
240
|
+
};
|
|
241
|
+
const clearFieldError = (name) => {
|
|
242
|
+
removeError(name);
|
|
243
|
+
};
|
|
244
|
+
const runSchema = async (names) => {
|
|
245
|
+
if (!resolver) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const result = await resolver(values(), null, {
|
|
249
|
+
fields: getResolverFields(fields),
|
|
250
|
+
shouldUseNativeValidation: false
|
|
251
|
+
});
|
|
252
|
+
for (const name of names) {
|
|
253
|
+
const error = get(result.errors, name);
|
|
254
|
+
if (error) {
|
|
255
|
+
setFieldError(name, error);
|
|
256
|
+
} else {
|
|
257
|
+
clearFieldError(name);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const validateField = (name) => {
|
|
262
|
+
if (resolver) {
|
|
263
|
+
runSchema([name]);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const rule = getRule(name);
|
|
267
|
+
const error = validate(values(), name, rule);
|
|
268
|
+
if (error) {
|
|
269
|
+
setFieldError(name, error);
|
|
270
|
+
} else {
|
|
271
|
+
clearFieldError(name);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const validateAllFields = async () => {
|
|
275
|
+
if (resolver) {
|
|
276
|
+
await runSchema(Object.keys(fields));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
Object.keys(rules).forEach((key) => {
|
|
280
|
+
validateField(key);
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const focusFirstError = () => {
|
|
284
|
+
const names = Object.keys(fields);
|
|
285
|
+
for (const name of names) {
|
|
286
|
+
const error = getError(name);
|
|
287
|
+
if (error) {
|
|
288
|
+
error.ref?.focus();
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const onFieldChange = (event, name) => {
|
|
294
|
+
const value = formatValue(getFieldValue(event), rules[name]);
|
|
295
|
+
setValues((prev) => {
|
|
296
|
+
const newState = { ...prev };
|
|
297
|
+
set(newState, name, value);
|
|
298
|
+
return newState;
|
|
299
|
+
});
|
|
300
|
+
validateField(name);
|
|
301
|
+
};
|
|
302
|
+
const register = (name, options = {}) => {
|
|
303
|
+
addRule(name, options);
|
|
304
|
+
return {
|
|
305
|
+
name,
|
|
306
|
+
// value: get(values(), name),
|
|
307
|
+
onInput(event) {
|
|
308
|
+
if (mode === "onChange") {
|
|
309
|
+
onFieldChange(event, name);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
onChange(event) {
|
|
313
|
+
if (mode === "onChange") {
|
|
314
|
+
onFieldChange(event, name);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
ref(element) {
|
|
318
|
+
const field = getField(name);
|
|
319
|
+
if (field) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
setField(name, element);
|
|
323
|
+
if (element) {
|
|
324
|
+
setFieldValue(element, get(values(), name));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
const getValues = (name) => {
|
|
330
|
+
if (name) {
|
|
331
|
+
return get(values(), name);
|
|
332
|
+
}
|
|
333
|
+
return values();
|
|
334
|
+
};
|
|
335
|
+
const setValue = (name, value) => {
|
|
336
|
+
setValues((prev) => {
|
|
337
|
+
const newValues = { ...prev };
|
|
338
|
+
set(newValues, name, value);
|
|
339
|
+
return newValues;
|
|
340
|
+
});
|
|
341
|
+
const field = getField(name);
|
|
342
|
+
if (field) {
|
|
343
|
+
setFieldValue(field, value);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const onSubmit = (submit) => {
|
|
347
|
+
return async (event) => {
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
await validateAllFields();
|
|
350
|
+
if (isValid()) {
|
|
351
|
+
submit(getValues());
|
|
352
|
+
}
|
|
353
|
+
focusFirstError();
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
const reset = (newDefaultValues = {}) => {
|
|
357
|
+
const newValues = {
|
|
358
|
+
...structuredClone(defaultValues),
|
|
359
|
+
...newDefaultValues
|
|
360
|
+
};
|
|
361
|
+
setValues(() => newValues);
|
|
362
|
+
resetErrors();
|
|
363
|
+
Object.entries(fields).forEach(([name, field]) => {
|
|
364
|
+
if (field) {
|
|
365
|
+
setFieldValue(field, get(newValues, name));
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
return {
|
|
370
|
+
values,
|
|
371
|
+
errors,
|
|
372
|
+
isValid,
|
|
373
|
+
register,
|
|
374
|
+
getValues,
|
|
375
|
+
setValue,
|
|
376
|
+
onSubmit,
|
|
377
|
+
reset
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// src/form_context.ts
|
|
382
|
+
import { createContext } from "solid-js";
|
|
383
|
+
var FormContext = createContext();
|
|
384
|
+
|
|
385
|
+
// src/form_provider.tsx
|
|
386
|
+
var FormProvider = (props) => {
|
|
387
|
+
return <FormContext.Provider value={props.form}>{props.children}</FormContext.Provider>;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/use_form_context.ts
|
|
391
|
+
import { useContext } from "solid-js";
|
|
392
|
+
var useFormContext = () => {
|
|
393
|
+
const form = useContext(FormContext);
|
|
394
|
+
if (!form) {
|
|
395
|
+
throw new Error("useFormContext: cannot find a FormProvider");
|
|
396
|
+
}
|
|
397
|
+
return form;
|
|
398
|
+
};
|
|
399
|
+
export {
|
|
400
|
+
FormProvider,
|
|
401
|
+
useForm,
|
|
402
|
+
useFormContext
|
|
403
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-hook-form",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./dist/main.
|
|
5
|
+
"main": "./dist/main.js",
|
|
6
6
|
"module": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/main.d.ts",
|
|
11
|
+
"solid": "./dist/main.jsx",
|
|
12
|
+
"default": "./dist/main.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
@@ -21,16 +22,17 @@
|
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@solidjs/testing-library": "^0.8.10",
|
|
23
24
|
"@testing-library/user-event": "^14.6.1",
|
|
25
|
+
"esbuild-plugin-solid": "^0.6.0",
|
|
24
26
|
"happy-dom": "^17.4.4",
|
|
25
27
|
"react-hook-form": "^7.55.0",
|
|
28
|
+
"tsup": "^8.5.0",
|
|
26
29
|
"typescript": "~5.7.2",
|
|
27
30
|
"vite": "^6.0.11",
|
|
28
|
-
"vite-plugin-dts": "^4.5.0",
|
|
29
31
|
"vite-plugin-solid": "^2.11.6",
|
|
30
32
|
"vitest": "^3.1.1"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
|
-
"build": "tsc &&
|
|
35
|
+
"build": "tsc && tsup",
|
|
34
36
|
"test": "vitest run"
|
|
35
37
|
},
|
|
36
38
|
"author": "thorn_pear",
|
package/dist/form_context.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const FormContext: import('solid-js').Context<unknown>;
|
package/dist/form_provider.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ParentProps } from 'solid-js';
|
|
2
|
-
import { FormValues, UseFormReturn } from './types/form';
|
|
3
|
-
type FormProviderProps<T extends FormValues> = ParentProps & {
|
|
4
|
-
form: UseFormReturn<T>;
|
|
5
|
-
};
|
|
6
|
-
export declare const FormProvider: <T extends FormValues>(props: FormProviderProps<T>) => import("solid-js").JSX.Element;
|
|
7
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FieldError } from '../types/errors';
|
|
2
|
-
import { FormValues } from '../types/form';
|
|
3
|
-
import { Path } from '../types/path';
|
|
4
|
-
export declare const createErrors: <F extends FormValues>() => {
|
|
5
|
-
errors: import('solid-js').Accessor<Partial<Record<Path<F>, FieldError>>>;
|
|
6
|
-
appendError: (name: Path<F>, error: FieldError) => void;
|
|
7
|
-
removeError: (name: Path<F>) => void;
|
|
8
|
-
resetErrors: () => void;
|
|
9
|
-
getError: (name: string) => any;
|
|
10
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FormValues } from '../types/form';
|
|
2
|
-
import { Path } from '../types/path';
|
|
3
|
-
import { Rules } from '../types/validate';
|
|
4
|
-
export declare const createRules: <F extends FormValues>() => {
|
|
5
|
-
rules: Record<string, Rules<F, Path<F>>>;
|
|
6
|
-
addRule: (name: string, options: Rules<F, Path<F>>) => void;
|
|
7
|
-
getRule: (name: string) => Rules<F, Path<F>>;
|
|
8
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getFieldValue: (event: Event) => string | boolean | File[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const setFieldValue: (field: HTMLElement, value: any) => void;
|
package/dist/logic/validate.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { FieldError } from '../types/errors';
|
|
2
|
-
import { FormValues } from '../types/form';
|
|
3
|
-
import { Path } from '../types/path';
|
|
4
|
-
import { Rules } from '../types/validate';
|
|
5
|
-
export declare const validate: <F extends FormValues>(values: F, name: Path<F>, rules?: Rules<F, Path<F>>) => FieldError | undefined;
|
package/dist/main.umd.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
(function(z,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],U):(z=typeof globalThis<"u"?globalThis:z||self,U(z["solid-hook-form"]={},z.solid))})(this,function(z,U){"use strict";const ze=n=>{const u=n.target;return u instanceof HTMLSelectElement?u.value:u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked:u instanceof HTMLInputElement&&u.type==="file"?[...u.files||[]]:u.value},ge=(n,u)=>{if(n instanceof HTMLSelectElement){n.value=u;return}if(n instanceof HTMLInputElement&&n.type==="checkbox"){n.checked=u;return}n instanceof HTMLInputElement&&n.type==="file"||(n.value=u)};function xe(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var le={exports:{}},p={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react.production.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var we;function Ve(){if(we)return p;we=1;var n=Symbol.for("react.transitional.element"),u=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),T=Symbol.for("react.profiler"),k=Symbol.for("react.consumer"),N=Symbol.for("react.context"),j=Symbol.for("react.forward_ref"),L=Symbol.for("react.suspense"),$=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),x=Symbol.iterator;function K(t){return t===null||typeof t!="object"?null:(t=x&&t[x]||t["@@iterator"],typeof t=="function"?t:null)}var X={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Z=Object.assign,oe={};function q(t,o,f){this.props=t,this.context=o,this.refs=oe,this.updater=f||X}q.prototype.isReactComponent={},q.prototype.setState=function(t,o){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,o,"setState")},q.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function V(){}V.prototype=q.prototype;function G(t,o,f){this.props=t,this.context=o,this.refs=oe,this.updater=f||X}var I=G.prototype=new V;I.constructor=G,Z(I,q.prototype),I.isPureReactComponent=!0;var J=Array.isArray,b={H:null,A:null,T:null,S:null,V:null},ee=Object.prototype.hasOwnProperty;function te(t,o,f,c,R,S){return f=S.ref,{$$typeof:n,type:t,key:o,ref:f!==void 0?f:null,props:S}}function Y(t,o){return te(t.type,o,void 0,void 0,void 0,t.props)}function F(t){return typeof t=="object"&&t!==null&&t.$$typeof===n}function ue(t){var o={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(f){return o[f]})}var C=/\/+/g;function se(t,o){return typeof t=="object"&&t!==null&&t.key!=null?ue(""+t.key):o.toString(36)}function B(){}function l(t){switch(t.status){case"fulfilled":return t.value;case"rejected":throw t.reason;default:switch(typeof t.status=="string"?t.then(B,B):(t.status="pending",t.then(function(o){t.status==="pending"&&(t.status="fulfilled",t.value=o)},function(o){t.status==="pending"&&(t.status="rejected",t.reason=o)})),t.status){case"fulfilled":return t.value;case"rejected":throw t.reason}}throw t}function E(t,o,f,c,R){var S=typeof t;(S==="undefined"||S==="boolean")&&(t=null);var m=!1;if(t===null)m=!0;else switch(S){case"bigint":case"string":case"number":m=!0;break;case"object":switch(t.$$typeof){case n:case u:m=!0;break;case M:return m=t._init,E(m(t._payload),o,f,c,R)}}if(m)return R=R(t),m=c===""?"."+se(t,0):c,J(R)?(f="",m!=null&&(f=m.replace(C,"$&/")+"/"),E(R,o,f,"",function(ie){return ie})):R!=null&&(F(R)&&(R=Y(R,f+(R.key==null||t&&t.key===R.key?"":(""+R.key).replace(C,"$&/")+"/")+m)),o.push(R)),1;m=0;var W=c===""?".":c+":";if(J(t))for(var A=0;A<t.length;A++)c=t[A],S=W+se(c,A),m+=E(c,o,f,S,R);else if(A=K(t),typeof A=="function")for(t=A.call(t),A=0;!(c=t.next()).done;)c=c.value,S=W+se(c,A++),m+=E(c,o,f,S,R);else if(S==="object"){if(typeof t.then=="function")return E(l(t),o,f,c,R);throw o=String(t),Error("Objects are not valid as a React child (found: "+(o==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":o)+"). If you meant to render a collection of children, use an array instead.")}return m}function w(t,o,f){if(t==null)return t;var c=[],R=0;return E(t,c,"","",function(S){return o.call(f,S,R++)}),c}function P(t){if(t._status===-1){var o=t._result;o=o(),o.then(function(f){(t._status===0||t._status===-1)&&(t._status=1,t._result=f)},function(f){(t._status===0||t._status===-1)&&(t._status=2,t._result=f)}),t._status===-1&&(t._status=0,t._result=o)}if(t._status===1)return t._result.default;throw t._result}var D=typeof reportError=="function"?reportError:function(t){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var o=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof t=="object"&&t!==null&&typeof t.message=="string"?String(t.message):String(t),error:t});if(!window.dispatchEvent(o))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",t);return}console.error(t)};function pe(){}return p.Children={map:w,forEach:function(t,o,f){w(t,function(){o.apply(this,arguments)},f)},count:function(t){var o=0;return w(t,function(){o++}),o},toArray:function(t){return w(t,function(o){return o})||[]},only:function(t){if(!F(t))throw Error("React.Children.only expected to receive a single React element child.");return t}},p.Component=q,p.Fragment=y,p.Profiler=T,p.PureComponent=G,p.StrictMode=v,p.Suspense=L,p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=b,p.__COMPILER_RUNTIME={__proto__:null,c:function(t){return b.H.useMemoCache(t)}},p.cache=function(t){return function(){return t.apply(null,arguments)}},p.cloneElement=function(t,o,f){if(t==null)throw Error("The argument must be a React element, but you passed "+t+".");var c=Z({},t.props),R=t.key,S=void 0;if(o!=null)for(m in o.ref!==void 0&&(S=void 0),o.key!==void 0&&(R=""+o.key),o)!ee.call(o,m)||m==="key"||m==="__self"||m==="__source"||m==="ref"&&o.ref===void 0||(c[m]=o[m]);var m=arguments.length-2;if(m===1)c.children=f;else if(1<m){for(var W=Array(m),A=0;A<m;A++)W[A]=arguments[A+2];c.children=W}return te(t.type,R,void 0,void 0,S,c)},p.createContext=function(t){return t={$$typeof:N,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null},t.Provider=t,t.Consumer={$$typeof:k,_context:t},t},p.createElement=function(t,o,f){var c,R={},S=null;if(o!=null)for(c in o.key!==void 0&&(S=""+o.key),o)ee.call(o,c)&&c!=="key"&&c!=="__self"&&c!=="__source"&&(R[c]=o[c]);var m=arguments.length-2;if(m===1)R.children=f;else if(1<m){for(var W=Array(m),A=0;A<m;A++)W[A]=arguments[A+2];R.children=W}if(t&&t.defaultProps)for(c in m=t.defaultProps,m)R[c]===void 0&&(R[c]=m[c]);return te(t,S,void 0,void 0,null,R)},p.createRef=function(){return{current:null}},p.forwardRef=function(t){return{$$typeof:j,render:t}},p.isValidElement=F,p.lazy=function(t){return{$$typeof:M,_payload:{_status:-1,_result:t},_init:P}},p.memo=function(t,o){return{$$typeof:$,type:t,compare:o===void 0?null:o}},p.startTransition=function(t){var o=b.T,f={};b.T=f;try{var c=t(),R=b.S;R!==null&&R(f,c),typeof c=="object"&&c!==null&&typeof c.then=="function"&&c.then(pe,D)}catch(S){D(S)}finally{b.T=o}},p.unstable_useCacheRefresh=function(){return b.H.useCacheRefresh()},p.use=function(t){return b.H.use(t)},p.useActionState=function(t,o,f){return b.H.useActionState(t,o,f)},p.useCallback=function(t,o){return b.H.useCallback(t,o)},p.useContext=function(t){return b.H.useContext(t)},p.useDebugValue=function(){},p.useDeferredValue=function(t,o){return b.H.useDeferredValue(t,o)},p.useEffect=function(t,o,f){var c=b.H;if(typeof f=="function")throw Error("useEffect CRUD overload is not enabled in this build of React.");return c.useEffect(t,o)},p.useId=function(){return b.H.useId()},p.useImperativeHandle=function(t,o,f){return b.H.useImperativeHandle(t,o,f)},p.useInsertionEffect=function(t,o){return b.H.useInsertionEffect(t,o)},p.useLayoutEffect=function(t,o){return b.H.useLayoutEffect(t,o)},p.useMemo=function(t,o){return b.H.useMemo(t,o)},p.useOptimistic=function(t,o){return b.H.useOptimistic(t,o)},p.useReducer=function(t,o,f){return b.H.useReducer(t,o,f)},p.useRef=function(t){return b.H.useRef(t)},p.useState=function(t){return b.H.useState(t)},p.useSyncExternalStore=function(t,o,f){return b.H.useSyncExternalStore(t,o,f)},p.useTransition=function(){return b.H.useTransition()},p.version="19.1.0",p}var ce={exports:{}};/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react.development.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/ce.exports;var Re;function Ge(){return Re||(Re=1,function(n,u){process.env.NODE_ENV!=="production"&&function(){function y(e,r){Object.defineProperty(k.prototype,e,{get:function(){console.warn("%s(...) is deprecated in plain JavaScript React classes. %s",r[0],r[1])}})}function v(e){return e===null||typeof e!="object"?null:(e=je&&e[je]||e["@@iterator"],typeof e=="function"?e:null)}function T(e,r){e=(e=e.constructor)&&(e.displayName||e.name)||"ReactClass";var s=e+"."+r;Pe[s]||(console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",r,e),Pe[s]=!0)}function k(e,r,s){this.props=e,this.context=r,this.refs=_e,this.updater=s||Ne}function N(){}function j(e,r,s){this.props=e,this.context=r,this.refs=_e,this.updater=s||Ne}function L(e){return""+e}function $(e){try{L(e);var r=!1}catch{r=!0}if(r){r=console;var s=r.error,i=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",i),L(e)}}function M(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===lt?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case t:return"Fragment";case f:return"Profiler";case o:return"StrictMode";case m:return"Suspense";case W:return"SuspenseList";case ft:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case pe:return"Portal";case R:return(e.displayName||"Context")+".Provider";case c:return(e._context.displayName||"Context")+".Consumer";case S:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case A:return r=e.displayName||null,r!==null?r:M(e.type)||"Memo";case ie:r=e._payload,e=e._init;try{return M(e(r))}catch{}}return null}function x(e){if(e===t)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===ie)return"<...>";try{var r=M(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function K(){var e=g.A;return e===null?null:e.getOwner()}function X(){return Error("react-stack-top-frame")}function Z(e){if(me.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function oe(e,r){function s(){Ie||(Ie=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}function q(){var e=M(this.type);return He[e]||(He[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function V(e,r,s,i,a,_,d,O){return s=_.ref,e={$$typeof:D,type:e,key:r,props:_,_owner:a},(s!==void 0?s:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:q}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:d}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function G(e,r){return r=V(e.type,r,void 0,void 0,e._owner,e.props,e._debugStack,e._debugTask),e._store&&(r._store.validated=e._store.validated),r}function I(e){return typeof e=="object"&&e!==null&&e.$$typeof===D}function J(e){var r={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return r[s]})}function b(e,r){return typeof e=="object"&&e!==null&&e.key!=null?($(e.key),J(""+e.key)):r.toString(36)}function ee(){}function te(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:switch(typeof e.status=="string"?e.then(ee,ee):(e.status="pending",e.then(function(r){e.status==="pending"&&(e.status="fulfilled",e.value=r)},function(r){e.status==="pending"&&(e.status="rejected",e.reason=r)})),e.status){case"fulfilled":return e.value;case"rejected":throw e.reason}}throw e}function Y(e,r,s,i,a){var _=typeof e;(_==="undefined"||_==="boolean")&&(e=null);var d=!1;if(e===null)d=!0;else switch(_){case"bigint":case"string":case"number":d=!0;break;case"object":switch(e.$$typeof){case D:case pe:d=!0;break;case ie:return d=e._init,Y(d(e._payload),r,s,i,a)}}if(d){d=e,a=a(d);var O=i===""?"."+b(d,0):i;return Me(a)?(s="",O!=null&&(s=O.replace(Ue,"$&/")+"/"),Y(a,r,s,"",function(Q){return Q})):a!=null&&(I(a)&&(a.key!=null&&(d&&d.key===a.key||$(a.key)),s=G(a,s+(a.key==null||d&&d.key===a.key?"":(""+a.key).replace(Ue,"$&/")+"/")+O),i!==""&&d!=null&&I(d)&&d.key==null&&d._store&&!d._store.validated&&(s._store.validated=2),a=s),r.push(a)),1}if(d=0,O=i===""?".":i+":",Me(e))for(var h=0;h<e.length;h++)i=e[h],_=O+b(i,h),d+=Y(i,r,s,_,a);else if(h=v(e),typeof h=="function")for(h===e.entries&&(Ye||console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."),Ye=!0),e=h.call(e),h=0;!(i=e.next()).done;)i=i.value,_=O+b(i,h++),d+=Y(i,r,s,_,a);else if(_==="object"){if(typeof e.then=="function")return Y(te(e),r,s,i,a);throw r=String(e),Error("Objects are not valid as a React child (found: "+(r==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":r)+"). If you meant to render a collection of children, use an array instead.")}return d}function F(e,r,s){if(e==null)return e;var i=[],a=0;return Y(e,i,"","",function(_){return r.call(s,_,a++)}),i}function ue(e){if(e._status===-1){var r=e._result;r=r(),r.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=r)}if(e._status===1)return r=e._result,r===void 0&&console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
18
|
-
|
|
19
|
-
Your code should look like:
|
|
20
|
-
const MyComponent = lazy(() => import('./MyComponent'))
|
|
21
|
-
|
|
22
|
-
Did you accidentally put curly braces around the import?`,r),"default"in r||console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
23
|
-
|
|
24
|
-
Your code should look like:
|
|
25
|
-
const MyComponent = lazy(() => import('./MyComponent'))`,r),r.default;throw e._result}function C(){var e=g.H;return e===null&&console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
26
|
-
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
27
|
-
2. You might be breaking the Rules of Hooks
|
|
28
|
-
3. You might have more than one copy of React in the same app
|
|
29
|
-
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`),e}function se(){}function B(e){if(ye===null)try{var r=("require"+Math.random()).slice(0,7);ye=(n&&n[r]).call(n,"timers").setImmediate}catch{ye=function(i){Fe===!1&&(Fe=!0,typeof MessageChannel>"u"&&console.error("This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."));var a=new MessageChannel;a.port1.onmessage=i,a.port2.postMessage(void 0)}}return ye(e)}function l(e){return 1<e.length&&typeof AggregateError=="function"?new AggregateError(e):e[0]}function E(e,r){r!==he-1&&console.error("You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. "),he=r}function w(e,r,s){var i=g.actQueue;if(i!==null)if(i.length!==0)try{P(i),B(function(){return w(e,r,s)});return}catch(a){g.thrownErrors.push(a)}else g.actQueue=null;0<g.thrownErrors.length?(i=l(g.thrownErrors),g.thrownErrors.length=0,s(i)):r(e)}function P(e){if(!Ee){Ee=!0;var r=0;try{for(;r<e.length;r++){var s=e[r];do{g.didUsePromise=!1;var i=s(!1);if(i!==null){if(g.didUsePromise){e[r]=s,e.splice(0,r);return}s=i}else break}while(!0)}e.length=0}catch(a){e.splice(0,r+1),g.thrownErrors.push(a)}finally{Ee=!1}}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var D=Symbol.for("react.transitional.element"),pe=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),R=Symbol.for("react.context"),S=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),A=Symbol.for("react.memo"),ie=Symbol.for("react.lazy"),ft=Symbol.for("react.activity"),je=Symbol.iterator,Pe={},Ne={isMounted:function(){return!1},enqueueForceUpdate:function(e){T(e,"forceUpdate")},enqueueReplaceState:function(e){T(e,"replaceState")},enqueueSetState:function(e){T(e,"setState")}},Le=Object.assign,_e={};Object.freeze(_e),k.prototype.isReactComponent={},k.prototype.setState=function(e,r){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,r,"setState")},k.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};var H={isMounted:["isMounted","Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."],replaceState:["replaceState","Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."]},de;for(de in H)H.hasOwnProperty(de)&&y(de,H[de]);N.prototype=k.prototype,H=j.prototype=new N,H.constructor=j,Le(H,k.prototype),H.isPureReactComponent=!0;var Me=Array.isArray,lt=Symbol.for("react.client.reference"),g={H:null,A:null,T:null,S:null,V:null,actQueue:null,isBatchingLegacy:!1,didScheduleLegacyUpdate:!1,didUsePromise:!1,thrownErrors:[],getCurrentStack:null,recentlyCreatedOwnerStacks:0},me=Object.prototype.hasOwnProperty,$e=console.createTask?console.createTask:function(){return null};H={"react-stack-bottom-frame":function(e){return e()}};var Ie,De,He={},pt=H["react-stack-bottom-frame"].bind(H,X)(),dt=$e(x(X)),Ye=!1,Ue=/\/+/g,qe=typeof reportError=="function"?reportError:function(e){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var r=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof e=="object"&&e!==null&&typeof e.message=="string"?String(e.message):String(e),error:e});if(!window.dispatchEvent(r))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)},Fe=!1,ye=null,he=0,ve=!1,Ee=!1,We=typeof queueMicrotask=="function"?function(e){queueMicrotask(function(){return queueMicrotask(e)})}:B;H=Object.freeze({__proto__:null,c:function(e){return C().useMemoCache(e)}}),u.Children={map:F,forEach:function(e,r,s){F(e,function(){r.apply(this,arguments)},s)},count:function(e){var r=0;return F(e,function(){r++}),r},toArray:function(e){return F(e,function(r){return r})||[]},only:function(e){if(!I(e))throw Error("React.Children.only expected to receive a single React element child.");return e}},u.Component=k,u.Fragment=t,u.Profiler=f,u.PureComponent=j,u.StrictMode=o,u.Suspense=m,u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=g,u.__COMPILER_RUNTIME=H,u.act=function(e){var r=g.actQueue,s=he;he++;var i=g.actQueue=r!==null?r:[],a=!1;try{var _=e()}catch(h){g.thrownErrors.push(h)}if(0<g.thrownErrors.length)throw E(r,s),e=l(g.thrownErrors),g.thrownErrors.length=0,e;if(_!==null&&typeof _=="object"&&typeof _.then=="function"){var d=_;return We(function(){a||ve||(ve=!0,console.error("You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"))}),{then:function(h,Q){a=!0,d.then(function(ae){if(E(r,s),s===0){try{P(i),B(function(){return w(ae,h,Q)})}catch(yt){g.thrownErrors.push(yt)}if(0<g.thrownErrors.length){var mt=l(g.thrownErrors);g.thrownErrors.length=0,Q(mt)}}else h(ae)},function(ae){E(r,s),0<g.thrownErrors.length&&(ae=l(g.thrownErrors),g.thrownErrors.length=0),Q(ae)})}}}var O=_;if(E(r,s),s===0&&(P(i),i.length!==0&&We(function(){a||ve||(ve=!0,console.error("A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"))}),g.actQueue=null),0<g.thrownErrors.length)throw e=l(g.thrownErrors),g.thrownErrors.length=0,e;return{then:function(h,Q){a=!0,s===0?(g.actQueue=i,B(function(){return w(O,h,Q)})):h(O)}}},u.cache=function(e){return function(){return e.apply(null,arguments)}},u.captureOwnerStack=function(){var e=g.getCurrentStack;return e===null?null:e()},u.cloneElement=function(e,r,s){if(e==null)throw Error("The argument must be a React element, but you passed "+e+".");var i=Le({},e.props),a=e.key,_=e._owner;if(r!=null){var d;e:{if(me.call(r,"ref")&&(d=Object.getOwnPropertyDescriptor(r,"ref").get)&&d.isReactWarning){d=!1;break e}d=r.ref!==void 0}d&&(_=K()),Z(r)&&($(r.key),a=""+r.key);for(O in r)!me.call(r,O)||O==="key"||O==="__self"||O==="__source"||O==="ref"&&r.ref===void 0||(i[O]=r[O])}var O=arguments.length-2;if(O===1)i.children=s;else if(1<O){d=Array(O);for(var h=0;h<O;h++)d[h]=arguments[h+2];i.children=d}for(i=V(e.type,a,void 0,void 0,_,i,e._debugStack,e._debugTask),a=2;a<arguments.length;a++)_=arguments[a],I(_)&&_._store&&(_._store.validated=1);return i},u.createContext=function(e){return e={$$typeof:R,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:c,_context:e},e._currentRenderer=null,e._currentRenderer2=null,e},u.createElement=function(e,r,s){for(var i=2;i<arguments.length;i++){var a=arguments[i];I(a)&&a._store&&(a._store.validated=1)}if(i={},a=null,r!=null)for(h in De||!("__self"in r)||"key"in r||(De=!0,console.warn("Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform")),Z(r)&&($(r.key),a=""+r.key),r)me.call(r,h)&&h!=="key"&&h!=="__self"&&h!=="__source"&&(i[h]=r[h]);var _=arguments.length-2;if(_===1)i.children=s;else if(1<_){for(var d=Array(_),O=0;O<_;O++)d[O]=arguments[O+2];Object.freeze&&Object.freeze(d),i.children=d}if(e&&e.defaultProps)for(h in _=e.defaultProps,_)i[h]===void 0&&(i[h]=_[h]);a&&oe(i,typeof e=="function"?e.displayName||e.name||"Unknown":e);var h=1e4>g.recentlyCreatedOwnerStacks++;return V(e,a,void 0,void 0,K(),i,h?Error("react-stack-top-frame"):pt,h?$e(x(e)):dt)},u.createRef=function(){var e={current:null};return Object.seal(e),e},u.forwardRef=function(e){e!=null&&e.$$typeof===A?console.error("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."):typeof e!="function"?console.error("forwardRef requires a render function but was given %s.",e===null?"null":typeof e):e.length!==0&&e.length!==2&&console.error("forwardRef render functions accept exactly two parameters: props and ref. %s",e.length===1?"Did you forget to use the ref parameter?":"Any additional parameter will be undefined."),e!=null&&e.defaultProps!=null&&console.error("forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?");var r={$$typeof:S,render:e},s;return Object.defineProperty(r,"displayName",{enumerable:!1,configurable:!0,get:function(){return s},set:function(i){s=i,e.name||e.displayName||(Object.defineProperty(e,"name",{value:i}),e.displayName=i)}}),r},u.isValidElement=I,u.lazy=function(e){return{$$typeof:ie,_payload:{_status:-1,_result:e},_init:ue}},u.memo=function(e,r){e==null&&console.error("memo: The first argument must be a component. Instead received: %s",e===null?"null":typeof e),r={$$typeof:A,type:e,compare:r===void 0?null:r};var s;return Object.defineProperty(r,"displayName",{enumerable:!1,configurable:!0,get:function(){return s},set:function(i){s=i,e.name||e.displayName||(Object.defineProperty(e,"name",{value:i}),e.displayName=i)}}),r},u.startTransition=function(e){var r=g.T,s={};g.T=s,s._updatedFibers=new Set;try{var i=e(),a=g.S;a!==null&&a(s,i),typeof i=="object"&&i!==null&&typeof i.then=="function"&&i.then(se,qe)}catch(_){qe(_)}finally{r===null&&s._updatedFibers&&(e=s._updatedFibers.size,s._updatedFibers.clear(),10<e&&console.warn("Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table.")),g.T=r}},u.unstable_useCacheRefresh=function(){return C().useCacheRefresh()},u.use=function(e){return C().use(e)},u.useActionState=function(e,r,s){return C().useActionState(e,r,s)},u.useCallback=function(e,r){return C().useCallback(e,r)},u.useContext=function(e){var r=C();return e.$$typeof===c&&console.error("Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"),r.useContext(e)},u.useDebugValue=function(e,r){return C().useDebugValue(e,r)},u.useDeferredValue=function(e,r){return C().useDeferredValue(e,r)},u.useEffect=function(e,r,s){e==null&&console.warn("React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?");var i=C();if(typeof s=="function")throw Error("useEffect CRUD overload is not enabled in this build of React.");return i.useEffect(e,r)},u.useId=function(){return C().useId()},u.useImperativeHandle=function(e,r,s){return C().useImperativeHandle(e,r,s)},u.useInsertionEffect=function(e,r){return e==null&&console.warn("React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"),C().useInsertionEffect(e,r)},u.useLayoutEffect=function(e,r){return e==null&&console.warn("React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"),C().useLayoutEffect(e,r)},u.useMemo=function(e,r){return C().useMemo(e,r)},u.useOptimistic=function(e,r){return C().useOptimistic(e,r)},u.useReducer=function(e,r,s){return C().useReducer(e,r,s)},u.useRef=function(e){return C().useRef(e)},u.useState=function(e){return C().useState(e)},u.useSyncExternalStore=function(e,r,s){return C().useSyncExternalStore(e,r,s)},u.useTransition=function(){return C().useTransition()},u.version="19.1.0",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}(ce,ce.exports)),ce.exports}var Te;function Be(){return Te||(Te=1,process.env.NODE_ENV==="production"?le.exports=Ve():le.exports=Ge()),le.exports}var Qe=Be();const Ke=xe(Qe);var Xe=n=>n instanceof Date,be=n=>n==null;const Ze=n=>typeof n=="object";var Oe=n=>!be(n)&&!Array.isArray(n)&&Ze(n)&&!Xe(n),Ce=n=>Array.isArray(n)?n.filter(Boolean):[],Se=n=>n===void 0,re=(n,u,y)=>{if(!u||!Oe(n))return y;const v=Ce(u.split(/[,[\].]+?/)).reduce((T,k)=>be(T)?T:T[k],n);return Se(v)||v===n?Se(n[u])?y:n[u]:v},Je=n=>/^\w*$/.test(n),et=n=>Ce(n.replace(/["|']|\]/g,"").split(/\.|\[/)),Ae=(n,u,y)=>{let v=-1;const T=Je(u)?[u]:et(u),k=T.length,N=k-1;for(;++v<k;){const j=T[v];let L=y;if(v!==N){const $=n[j];L=Oe($)||Array.isArray($)?$:isNaN(+T[v+1])?{}:[]}if(j==="__proto__"||j==="constructor"||j==="prototype")return;n[j]=L,n=n[j]}};Ke.createContext(null);const fe=n=>n instanceof RegExp||typeof n=="string"||typeof n=="number"?n:n.value,ne=n=>typeof n=="string"?n:typeof n.message=="string"?n.message:"",tt=(n,u,y={})=>{const v=re(n,u);if(y.required&&!v)return{type:"required",message:ne(y.required)};if(y.min&&Number(v)<Number(fe(y.min)))return{type:"min",message:ne(y.min)};if(y.max&&Number(v)>Number(fe(y.max)))return{type:"max",message:ne(y.max)};if(y.minLength&&v.length<fe(y.minLength))return{type:"minLength",message:ne(y.minLength)};if(y.maxLength&&v.length>fe(y.maxLength))return{type:"maxLength",message:ne(y.maxLength)};if(y.pattern&&!fe(y.pattern).test(v))return{type:"pattern",message:ne(y.pattern)};if(y.validate){const T=y.validate(v,n);if(T===!1)return{type:"validate"};if(typeof T=="string")return{type:"validate",message:T}}},rt=()=>{const[n,u]=U.createSignal({});return{errors:n,appendError:(N,j)=>{u(L=>({...L,[N]:j}))},removeError:N=>{u(j=>{const L={...j};return delete L[N],L})},resetErrors:()=>{u({})},getError:N=>re(n(),N)}},nt=()=>{const n={};return{rules:n,addRule:(v,T)=>{n[v]={required:T.required,min:T.min,max:T.max,minLength:T.minLength,maxLength:T.maxLength,pattern:T.pattern,valueAsNumber:T.valueAsNumber,validate:T.validate}},getRule:v=>n[v]}},ot=()=>{const n={};return{fields:n,getField:v=>n[v],setField:(v,T)=>{n[v]=T}}},ut=(n,u)=>u.valueAsNumber?Number(n):n,st=n=>Object.entries(n).reduce((u,[y,v])=>(u[y]={ref:v,name:y},u),{}),it=(n={defaultValues:{}})=>{const{defaultValues:u,mode:y="onInput",resolver:v}=n,{fields:T,getField:k,setField:N}=ot(),{rules:j,addRule:L,getRule:$}=nt(),[M,x]=U.createSignal(u),{errors:K,appendError:X,removeError:Z,resetErrors:oe,getError:q}=rt(),V=U.createMemo(()=>!Object.keys(K()).length),G=(l,E)=>{const w=k(l);w&&(E.ref=w),X(l,E)},I=l=>{Z(l)},J=async l=>{if(!v)return;const E=await v(M(),null,{fields:st(T),shouldUseNativeValidation:!1});for(const w of l){const P=re(E.errors,w);P?G(w,P):I(w)}},b=l=>{if(v){J([l]);return}const E=$(l),w=tt(M(),l,E);w?G(l,w):I(l)},ee=async()=>{if(v){await J(Object.keys(T));return}Object.keys(j).forEach(l=>{b(l)})},te=()=>{var E;const l=Object.keys(T);for(const w of l){const P=q(w);if(P){(E=P.ref)==null||E.focus();break}}},Y=(l,E)=>{const w=ut(ze(l),j[E]);x(P=>{const D={...P};return Ae(D,E,w),D}),b(E)},F=(l,E={})=>(L(l,E),{name:l,onInput(w){y==="onChange"&&Y(w,l)},onChange(w){y==="onChange"&&Y(w,l)},ref(w){k(l)||(N(l,w),w&&ge(w,re(M(),l)))}}),ue=l=>l?re(M(),l):M();return{values:M,errors:K,isValid:V,register:F,getValues:ue,setValue:(l,E)=>{x(P=>{const D={...P};return Ae(D,l,E),D});const w=k(l);w&&ge(w,E)},onSubmit:l=>async E=>{E.preventDefault(),await ee(),V()&&l(ue()),te()},reset:(l={})=>{const E={...structuredClone(u),...l};x(()=>E),oe(),Object.entries(T).forEach(([w,P])=>{P&&ge(P,re(E,w))})}}},ke=U.createContext(),at=n=>U.createComponent(ke.Provider,{get value(){return n.form},get children(){return n.children}}),ct=()=>{const n=U.useContext(ke);if(!n)throw new Error("useFormContext: cannot find a FormProvider");return n};z.FormProvider=at,z.useForm=it,z.useFormContext=ct,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types/errors.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FormValues } from './form';
|
|
2
|
-
import { Rules } from './validate';
|
|
3
|
-
import { LiteralUnion, Path } from 'react-hook-form';
|
|
4
|
-
export type Message = string;
|
|
5
|
-
export type FieldError = {
|
|
6
|
-
type: LiteralUnion<keyof Rules, string>;
|
|
7
|
-
ref?: HTMLElement;
|
|
8
|
-
message?: Message;
|
|
9
|
-
};
|
|
10
|
-
export type FieldErrors<F extends FormValues = FormValues> = Partial<Record<Path<F>, FieldError>>;
|
package/dist/types/form.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Accessor } from 'solid-js';
|
|
2
|
-
import { FieldPath, FieldPathValue, Path } from './path';
|
|
3
|
-
import { Rules } from './validate';
|
|
4
|
-
import { FieldErrors } from './errors';
|
|
5
|
-
export type FormValues = Record<string, any>;
|
|
6
|
-
export type Ref = HTMLElement | null;
|
|
7
|
-
export type RegisterReturn<F extends FormValues> = {
|
|
8
|
-
name: Path<F>;
|
|
9
|
-
ref(ref: Ref): void;
|
|
10
|
-
onInput(event: Event): void;
|
|
11
|
-
onChange(event: Event): void;
|
|
12
|
-
};
|
|
13
|
-
export type Register<T extends FormValues> = (name: Path<T>, options?: Rules<T, Path<T>>) => RegisterReturn<T>;
|
|
14
|
-
export type GetValues<F extends FormValues> = {
|
|
15
|
-
(): F;
|
|
16
|
-
<N extends FieldPath<F>>(name: N): FieldPathValue<F, N>;
|
|
17
|
-
};
|
|
18
|
-
export type SetValue<F extends FormValues> = (name: Path<F>, value: FieldPathValue<F, Path<F>>) => void;
|
|
19
|
-
export type SubmitCallback<F extends FormValues> = (values: F) => void;
|
|
20
|
-
export type OnSubmit<F extends FormValues> = (submit: SubmitCallback<F>) => (event: SubmitEvent) => void;
|
|
21
|
-
export type Reset<F extends FormValues> = (newDefaultValues?: Partial<F>) => void;
|
|
22
|
-
export type UseFormReturn<F extends FormValues = FormValues> = {
|
|
23
|
-
values: Accessor<F>;
|
|
24
|
-
errors: Accessor<FieldErrors<F>>;
|
|
25
|
-
isValid: Accessor<boolean>;
|
|
26
|
-
register: Register<F>;
|
|
27
|
-
getValues: GetValues<F>;
|
|
28
|
-
setValue: SetValue<F>;
|
|
29
|
-
onSubmit: OnSubmit<F>;
|
|
30
|
-
reset: Reset<F>;
|
|
31
|
-
};
|
|
32
|
-
export type FormFields = Record<string, Ref>;
|
package/dist/types/path.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Path, FieldPath, ArrayPath, PathValue, FieldPathValue, FieldPathValues, } from 'react-hook-form';
|