@formisch/qwik 0.1.0 → 0.1.1
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/README.md +1 -1
- package/dist/index.d.ts +392 -0
- package/dist/index.qwik.js +697 -0
- package/package.json +9 -17
- package/lib/components/Field/Field.qwik.cjs +0 -14
- package/lib/components/Field/Field.qwik.mjs +0 -14
- package/lib/components/FieldArray/FieldArray.qwik.cjs +0 -14
- package/lib/components/FieldArray/FieldArray.qwik.mjs +0 -14
- package/lib/components/Form/Form.qwik.cjs +0 -36
- package/lib/components/Form/Form.qwik.mjs +0 -36
- package/lib/hooks/useField/useField.qwik.cjs +0 -48
- package/lib/hooks/useField/useField.qwik.mjs +0 -48
- package/lib/hooks/useFieldArray/useFieldArray.qwik.cjs +0 -18
- package/lib/hooks/useFieldArray/useFieldArray.qwik.mjs +0 -18
- package/lib/hooks/useForm_/useForm_.qwik.cjs +0 -52
- package/lib/hooks/useForm_/useForm_.qwik.mjs +0 -35
- package/lib/hooks/usePathSignal/usePathSignal.qwik.cjs +0 -18
- package/lib/hooks/usePathSignal/usePathSignal.qwik.mjs +0 -18
- package/lib/hooks/useResolvedQrl/useResolvedQrl.qwik.cjs +0 -14
- package/lib/hooks/useResolvedQrl/useResolvedQrl.qwik.mjs +0 -14
- package/lib/index.qwik.cjs +0 -30
- package/lib/index.qwik.mjs +0 -30
- package/lib/packages/core/dist/index.qwik.qwik.cjs +0 -401
- package/lib/packages/core/dist/index.qwik.qwik.mjs +0 -379
- package/lib/packages/methods/dist/index.qwik.qwik.cjs +0 -178
- package/lib/packages/methods/dist/index.qwik.qwik.mjs +0 -178
- package/lib-types/components/Field/Field.d.ts +0 -16
- package/lib-types/components/Field/index.d.ts +0 -1
- package/lib-types/components/FieldArray/FieldArray.d.ts +0 -16
- package/lib-types/components/FieldArray/index.d.ts +0 -1
- package/lib-types/components/Form/Form.d.ts +0 -8
- package/lib-types/components/Form/index.d.ts +0 -1
- package/lib-types/components/Lifecycle/Lifecycle.d.ts +0 -6
- package/lib-types/components/Lifecycle/index.d.ts +0 -1
- package/lib-types/components/counter/counter.d.ts +0 -1
- package/lib-types/components/index.d.ts +0 -3
- package/lib-types/components/logo/logo.d.ts +0 -1
- package/lib-types/entry.dev.d.ts +0 -2
- package/lib-types/entry.ssr.d.ts +0 -14
- package/lib-types/hooks/index.d.ts +0 -3
- package/lib-types/hooks/useField/index.d.ts +0 -1
- package/lib-types/hooks/useField/useField.d.ts +0 -7
- package/lib-types/hooks/useField/useField_2.d.ts +0 -7
- package/lib-types/hooks/useFieldArray/index.d.ts +0 -1
- package/lib-types/hooks/useFieldArray/useFieldArray.d.ts +0 -7
- package/lib-types/hooks/useForm/index.d.ts +0 -1
- package/lib-types/hooks/useForm/useForm copy.d.ts +0 -9
- package/lib-types/hooks/useForm/useForm.d.ts +0 -5
- package/lib-types/hooks/useForm$/index.d.ts +0 -1
- package/lib-types/hooks/useForm$/useForm$.d.ts +0 -5
- package/lib-types/hooks/useFormStore/index.d.ts +0 -1
- package/lib-types/hooks/useFormStore/useFormStore.d.ts +0 -5
- package/lib-types/hooks/useLiveSignal copy/index.d.ts +0 -1
- package/lib-types/hooks/useLiveSignal copy/useLiveSignal.d.ts +0 -2
- package/lib-types/hooks/usePathSignal/index.d.ts +0 -1
- package/lib-types/hooks/usePathSignal/usePathSignal.d.ts +0 -3
- package/lib-types/hooks/useResolvedQrl/index.d.ts +0 -1
- package/lib-types/hooks/useResolvedQrl/useResolvedQrl.d.ts +0 -2
- package/lib-types/index.d.ts +0 -4
- package/lib-types/root.d.ts +0 -2
- package/lib-types/types/field.d.ts +0 -38
- package/lib-types/types/form.d.ts +0 -11
- package/lib-types/types/index.d.ts +0 -2
- package/lib-types/utils/createInternalSignal/createInternalSignal.d.ts +0 -3
- package/lib-types/utils/createInternalSignal/index.d.ts +0 -1
- package/lib-types/utils/index.d.ts +0 -0
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const v = require("valibot");
|
|
4
|
-
const core = require("@qwik.dev/core");
|
|
5
|
-
function _interopNamespaceDefault(e) {
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const v__namespace = /* @__PURE__ */ _interopNamespaceDefault(v);
|
|
22
|
-
function createId() {
|
|
23
|
-
return Math.random().toString(36).slice(2);
|
|
24
|
-
}
|
|
25
|
-
function batch(fn) {
|
|
26
|
-
return fn();
|
|
27
|
-
}
|
|
28
|
-
function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
29
|
-
if (schema.type === "lazy" || schema.type === "object_with_rest" || schema.type === "record" || schema.type === "tuple_with_rest" || schema.type === "promise") throw new Error(`"${schema.type}" schema is not supported`);
|
|
30
|
-
else if (schema.type === "lazy") initializeFieldStore(internalFieldStore, schema.getter(void 0), initialInput, path);
|
|
31
|
-
else if (schema.type === "exact_optional" || schema.type === "non_nullable" || schema.type === "non_nullish" || schema.type === "non_optional" || schema.type === "nullable" || schema.type === "nullish" || schema.type === "optional" || schema.type === "undefinedable") initializeFieldStore(internalFieldStore, schema.wrapped, initialInput ?? v__namespace.getDefault(schema), path);
|
|
32
|
-
else if (schema.type === "intersect" || schema.type === "union" || schema.type === "variant") for (const schemaOption of schema.options) initializeFieldStore(internalFieldStore, schemaOption, initialInput, path);
|
|
33
|
-
else {
|
|
34
|
-
internalFieldStore.schema = schema;
|
|
35
|
-
internalFieldStore.name = JSON.stringify(path);
|
|
36
|
-
internalFieldStore.elements = [];
|
|
37
|
-
internalFieldStore.errors = core.createSignal(null);
|
|
38
|
-
if (schema.type === "array" || schema.type === "loose_tuple" || schema.type === "strict_tuple" || schema.type === "tuple") {
|
|
39
|
-
if (internalFieldStore.kind && internalFieldStore.kind !== "array") throw new Error(`Store initialized as "${internalFieldStore.kind}" cannot be reinitialized as "array"`);
|
|
40
|
-
internalFieldStore.kind = "array";
|
|
41
|
-
if (internalFieldStore.kind === "array") {
|
|
42
|
-
internalFieldStore.children ?? (internalFieldStore.children = []);
|
|
43
|
-
if (schema.type === "array") {
|
|
44
|
-
if (initialInput) for (let index = 0; index < initialInput.length; index++) {
|
|
45
|
-
internalFieldStore.children[index] = {};
|
|
46
|
-
path.push(index);
|
|
47
|
-
initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
|
|
48
|
-
path.pop();
|
|
49
|
-
}
|
|
50
|
-
} else for (let index = 0; index < schema.items; index++) {
|
|
51
|
-
internalFieldStore.children[index] = {};
|
|
52
|
-
path.push(index);
|
|
53
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput && initialInput[index], path);
|
|
54
|
-
path.pop();
|
|
55
|
-
}
|
|
56
|
-
const initialItems = internalFieldStore.children.map(createId);
|
|
57
|
-
internalFieldStore.initialItems = core.createSignal(initialItems);
|
|
58
|
-
internalFieldStore.startItems = core.createSignal(initialItems);
|
|
59
|
-
internalFieldStore.items = core.createSignal(initialItems);
|
|
60
|
-
internalFieldStore.isTouched = core.createSignal(false);
|
|
61
|
-
internalFieldStore.isDirty = core.createSignal(false);
|
|
62
|
-
}
|
|
63
|
-
} else if (schema.type === "loose_object" || schema.type === "object" || schema.type === "strict_object") {
|
|
64
|
-
if (internalFieldStore.kind && internalFieldStore.kind !== "object") throw new Error(`Store initialized as "${internalFieldStore.kind}" cannot be reinitialized as "object"`);
|
|
65
|
-
internalFieldStore.kind = "object";
|
|
66
|
-
if (internalFieldStore.kind === "object") {
|
|
67
|
-
internalFieldStore.children ?? (internalFieldStore.children = {});
|
|
68
|
-
for (const key in schema.entries) {
|
|
69
|
-
internalFieldStore.children[key] = {};
|
|
70
|
-
path.push(key);
|
|
71
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput && initialInput[key], path);
|
|
72
|
-
path.pop();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
internalFieldStore.kind = "value";
|
|
77
|
-
if (internalFieldStore.kind === "value") {
|
|
78
|
-
internalFieldStore.initialInput = core.createSignal(initialInput);
|
|
79
|
-
internalFieldStore.startInput = core.createSignal(initialInput);
|
|
80
|
-
internalFieldStore.input = core.createSignal(initialInput);
|
|
81
|
-
internalFieldStore.isTouched = core.createSignal(false);
|
|
82
|
-
internalFieldStore.isDirty = core.createSignal(false);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function copyItemState(fromInternalFieldStore, toInternalFieldStore) {
|
|
88
|
-
batch(() => {
|
|
89
|
-
core.untrack(() => {
|
|
90
|
-
if (fromInternalFieldStore.kind === "array" && toInternalFieldStore.kind === "array") {
|
|
91
|
-
const fromItems = fromInternalFieldStore.items.value;
|
|
92
|
-
toInternalFieldStore.isTouched.value = fromInternalFieldStore.isTouched.value;
|
|
93
|
-
toInternalFieldStore.isDirty.value = fromInternalFieldStore.isDirty.value;
|
|
94
|
-
toInternalFieldStore.startItems.value = fromInternalFieldStore.startItems.value;
|
|
95
|
-
toInternalFieldStore.items.value = fromItems;
|
|
96
|
-
let path;
|
|
97
|
-
for (let index = 0; index < fromItems.length; index++) {
|
|
98
|
-
if (!toInternalFieldStore.children[index]) {
|
|
99
|
-
path ?? (path = JSON.parse(toInternalFieldStore.name));
|
|
100
|
-
toInternalFieldStore.children[index] = {};
|
|
101
|
-
path.push(index);
|
|
102
|
-
initializeFieldStore(toInternalFieldStore.children[index], toInternalFieldStore.schema.item, void 0, path);
|
|
103
|
-
path.pop();
|
|
104
|
-
}
|
|
105
|
-
copyItemState(fromInternalFieldStore.children[index], toInternalFieldStore.children[index]);
|
|
106
|
-
}
|
|
107
|
-
} else if (fromInternalFieldStore.kind === "object" && toInternalFieldStore.kind === "object") for (const key in fromInternalFieldStore.children) copyItemState(fromInternalFieldStore.children[key], toInternalFieldStore.children[key]);
|
|
108
|
-
else if (fromInternalFieldStore.kind === "value" && toInternalFieldStore.kind === "value") {
|
|
109
|
-
toInternalFieldStore.isTouched.value = fromInternalFieldStore.isTouched.value;
|
|
110
|
-
toInternalFieldStore.isDirty.value = fromInternalFieldStore.isDirty.value;
|
|
111
|
-
toInternalFieldStore.startInput.value = fromInternalFieldStore.startInput.value;
|
|
112
|
-
toInternalFieldStore.input.value = fromInternalFieldStore.input.value;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function resetItemState(internalFieldStore, initialInput) {
|
|
118
|
-
batch(() => {
|
|
119
|
-
if (internalFieldStore.kind === "array") {
|
|
120
|
-
internalFieldStore.isTouched.value = false;
|
|
121
|
-
internalFieldStore.isDirty.value = false;
|
|
122
|
-
if (initialInput) {
|
|
123
|
-
const newItems = initialInput.map(createId);
|
|
124
|
-
internalFieldStore.startItems.value = newItems;
|
|
125
|
-
internalFieldStore.items.value = newItems;
|
|
126
|
-
for (let index = 0; index < initialInput.length; index++) if (internalFieldStore.children[index]) resetItemState(internalFieldStore.children[index], initialInput[index]);
|
|
127
|
-
} else {
|
|
128
|
-
internalFieldStore.startItems.value = [];
|
|
129
|
-
internalFieldStore.items.value = [];
|
|
130
|
-
}
|
|
131
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) resetItemState(internalFieldStore.children[key], initialInput?.[key]);
|
|
132
|
-
else {
|
|
133
|
-
internalFieldStore.isTouched.value = false;
|
|
134
|
-
internalFieldStore.isDirty.value = false;
|
|
135
|
-
internalFieldStore.startInput.value = initialInput;
|
|
136
|
-
internalFieldStore.input.value = initialInput;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
|
|
141
|
-
batch(() => {
|
|
142
|
-
core.untrack(() => {
|
|
143
|
-
if (firstInternalFieldStore.kind === "array" && secondInternalFieldStore.kind === "array") {
|
|
144
|
-
const firstItems = firstInternalFieldStore.items.value;
|
|
145
|
-
const secondItems = secondInternalFieldStore.items.value;
|
|
146
|
-
const tempIsTouched = firstInternalFieldStore.isTouched.value;
|
|
147
|
-
firstInternalFieldStore.isTouched.value = secondInternalFieldStore.isTouched.value;
|
|
148
|
-
secondInternalFieldStore.isTouched.value = tempIsTouched;
|
|
149
|
-
const tempIsDirty = firstInternalFieldStore.isDirty.value;
|
|
150
|
-
firstInternalFieldStore.isDirty.value = secondInternalFieldStore.isDirty.value;
|
|
151
|
-
secondInternalFieldStore.isDirty.value = tempIsDirty;
|
|
152
|
-
const tempStartItems = firstInternalFieldStore.startItems.value;
|
|
153
|
-
firstInternalFieldStore.startItems.value = secondInternalFieldStore.startItems.value;
|
|
154
|
-
secondInternalFieldStore.startItems.value = tempStartItems;
|
|
155
|
-
firstInternalFieldStore.items.value = secondItems;
|
|
156
|
-
secondInternalFieldStore.items.value = firstItems;
|
|
157
|
-
const maxLength = Math.max(firstItems.length, secondItems.length);
|
|
158
|
-
let firstPath;
|
|
159
|
-
let secondPath;
|
|
160
|
-
for (let index = 0; index < maxLength; index++) {
|
|
161
|
-
if (!firstInternalFieldStore.children[index]) {
|
|
162
|
-
firstPath ?? (firstPath = JSON.parse(firstInternalFieldStore.name));
|
|
163
|
-
firstInternalFieldStore.children[index] = {};
|
|
164
|
-
firstPath.push(index);
|
|
165
|
-
initializeFieldStore(firstInternalFieldStore.children[index], firstInternalFieldStore.schema.item, void 0, firstPath);
|
|
166
|
-
firstPath.pop();
|
|
167
|
-
}
|
|
168
|
-
if (!secondInternalFieldStore.children[index]) {
|
|
169
|
-
secondPath ?? (secondPath = JSON.parse(secondInternalFieldStore.name));
|
|
170
|
-
secondInternalFieldStore.children[index] = {};
|
|
171
|
-
secondPath.push(index);
|
|
172
|
-
initializeFieldStore(secondInternalFieldStore.children[index], secondInternalFieldStore.schema.item, void 0, secondPath);
|
|
173
|
-
secondPath.pop();
|
|
174
|
-
}
|
|
175
|
-
swapItemState(firstInternalFieldStore.children[index], secondInternalFieldStore.children[index]);
|
|
176
|
-
}
|
|
177
|
-
} else if (firstInternalFieldStore.kind === "object" && secondInternalFieldStore.kind === "object") for (const key in firstInternalFieldStore.children) swapItemState(firstInternalFieldStore.children[key], secondInternalFieldStore.children[key]);
|
|
178
|
-
else if (firstInternalFieldStore.kind === "value" && secondInternalFieldStore.kind === "value") {
|
|
179
|
-
const tempIsTouched = firstInternalFieldStore.isTouched.value;
|
|
180
|
-
firstInternalFieldStore.isTouched.value = secondInternalFieldStore.isTouched.value;
|
|
181
|
-
secondInternalFieldStore.isTouched.value = tempIsTouched;
|
|
182
|
-
const tempIsDirty = firstInternalFieldStore.isDirty.value;
|
|
183
|
-
firstInternalFieldStore.isDirty.value = secondInternalFieldStore.isDirty.value;
|
|
184
|
-
secondInternalFieldStore.isDirty.value = tempIsDirty;
|
|
185
|
-
const tempStartInput = firstInternalFieldStore.startInput.value;
|
|
186
|
-
firstInternalFieldStore.startInput.value = secondInternalFieldStore.startInput.value;
|
|
187
|
-
secondInternalFieldStore.startInput.value = tempStartInput;
|
|
188
|
-
const tempInput = firstInternalFieldStore.input.value;
|
|
189
|
-
firstInternalFieldStore.input.value = secondInternalFieldStore.input.value;
|
|
190
|
-
secondInternalFieldStore.input.value = tempInput;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
function getFieldInput(internalFieldStore) {
|
|
196
|
-
if (internalFieldStore.kind === "array") {
|
|
197
|
-
const value = [];
|
|
198
|
-
for (let index = 0; index < internalFieldStore.items.value.length; index++) value[index] = getFieldInput(internalFieldStore.children[index]);
|
|
199
|
-
return value;
|
|
200
|
-
}
|
|
201
|
-
if (internalFieldStore.kind === "object") {
|
|
202
|
-
const value = {};
|
|
203
|
-
for (const key in internalFieldStore.children) value[key] = getFieldInput(internalFieldStore.children[key]);
|
|
204
|
-
return value;
|
|
205
|
-
}
|
|
206
|
-
return internalFieldStore.input.value;
|
|
207
|
-
}
|
|
208
|
-
function getElementInput(element, internalFieldStore) {
|
|
209
|
-
if (element.options && element.multiple) return [
|
|
210
|
-
...element.options
|
|
211
|
-
].filter((option) => option.selected && !option.disabled).map((option) => option.value);
|
|
212
|
-
if (element.type === "checkbox") {
|
|
213
|
-
const options = document.getElementsByName(element.name);
|
|
214
|
-
if (options.length > 1) return [
|
|
215
|
-
...options
|
|
216
|
-
].filter((option) => option.checked).map((option) => option.value);
|
|
217
|
-
return element.checked;
|
|
218
|
-
}
|
|
219
|
-
if (element.type === "radio") {
|
|
220
|
-
const prevValue = core.untrack(() => getFieldInput(internalFieldStore));
|
|
221
|
-
if (element.checked) return [
|
|
222
|
-
...prevValue,
|
|
223
|
-
element.value
|
|
224
|
-
];
|
|
225
|
-
return prevValue.filter((value) => value !== element.value);
|
|
226
|
-
}
|
|
227
|
-
if (element.type === "file") {
|
|
228
|
-
if (element.multiple) return [
|
|
229
|
-
...element.files
|
|
230
|
-
];
|
|
231
|
-
return element.files[0];
|
|
232
|
-
}
|
|
233
|
-
return element.value;
|
|
234
|
-
}
|
|
235
|
-
function getFieldBool(internalFieldStore, type) {
|
|
236
|
-
if (internalFieldStore.kind === "array") {
|
|
237
|
-
if (internalFieldStore[type].value) return true;
|
|
238
|
-
for (let index = 0; index < internalFieldStore.items.value.length; index++) if (getFieldBool(internalFieldStore.children[index], type)) return true;
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
if (internalFieldStore.kind == "object") {
|
|
242
|
-
if (type === "errors" && internalFieldStore[type].value) return true;
|
|
243
|
-
for (const key in internalFieldStore.children) if (getFieldBool(internalFieldStore.children[key], type)) return true;
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
return !!internalFieldStore[type].value;
|
|
247
|
-
}
|
|
248
|
-
function getFieldStore(internalFormStore, path) {
|
|
249
|
-
let internalFieldStore = internalFormStore;
|
|
250
|
-
for (const key of path) internalFieldStore = internalFieldStore.children[key];
|
|
251
|
-
return internalFieldStore;
|
|
252
|
-
}
|
|
253
|
-
function setFieldBool(internalFieldStore, type, bool) {
|
|
254
|
-
batch(() => {
|
|
255
|
-
if (internalFieldStore.kind === "array") {
|
|
256
|
-
internalFieldStore[type].value = bool;
|
|
257
|
-
for (let index = 0; index < core.untrack(() => internalFieldStore.items.value).length; index++) setFieldBool(internalFieldStore.children[index], type, bool);
|
|
258
|
-
} else if (internalFieldStore.kind == "object") for (const key in internalFieldStore.children) setFieldBool(internalFieldStore.children[key], type, bool);
|
|
259
|
-
else internalFieldStore[type].value = bool;
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
function setFieldInput(internalFieldStore, input) {
|
|
263
|
-
batch(() => {
|
|
264
|
-
if (internalFieldStore.kind === "array") {
|
|
265
|
-
const items = core.untrack(() => internalFieldStore.items.value);
|
|
266
|
-
if (input.length < items.length) internalFieldStore.items.value = items.slice(0, input.length);
|
|
267
|
-
else if (input.length > items.length) {
|
|
268
|
-
if (input.length > internalFieldStore.children.length) {
|
|
269
|
-
const path = JSON.parse(internalFieldStore.name);
|
|
270
|
-
for (let index = internalFieldStore.children.length; index < input.length; index++) {
|
|
271
|
-
internalFieldStore.children[index] = {};
|
|
272
|
-
path.push(index);
|
|
273
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, input[index], path);
|
|
274
|
-
path.pop();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
internalFieldStore.items.value = [
|
|
278
|
-
...items,
|
|
279
|
-
...input.slice(items.length).map(createId)
|
|
280
|
-
];
|
|
281
|
-
}
|
|
282
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], input[index]);
|
|
283
|
-
internalFieldStore.isDirty.value = core.untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
284
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
285
|
-
else {
|
|
286
|
-
internalFieldStore.input.value = input;
|
|
287
|
-
const startInput = core.untrack(() => internalFieldStore.startInput.value);
|
|
288
|
-
internalFieldStore.isDirty.value = startInput !== input && (startInput !== void 0 || input !== "" && !Number.isNaN(input));
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
293
|
-
batch(() => {
|
|
294
|
-
if (internalFieldStore.kind === "array") {
|
|
295
|
-
if (initialInput.length > internalFieldStore.children.length) {
|
|
296
|
-
const path = JSON.parse(internalFieldStore.name);
|
|
297
|
-
for (let index = internalFieldStore.children.length; index < initialInput.length; index++) {
|
|
298
|
-
internalFieldStore.children[index] = {};
|
|
299
|
-
path.push(index);
|
|
300
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialInput[index], path);
|
|
301
|
-
path.pop();
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
internalFieldStore.initialItems.value = initialInput.map(createId);
|
|
305
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialInput?.[index]);
|
|
306
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
307
|
-
else internalFieldStore.initialInput.value = initialInput;
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
function walkFieldStore(internalFieldStore, callback) {
|
|
311
|
-
callback(internalFieldStore);
|
|
312
|
-
if (internalFieldStore.kind === "array") for (let index = 0; index < core.untrack(() => internalFieldStore.items.value).length; index++) walkFieldStore(internalFieldStore.children[index], callback);
|
|
313
|
-
else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) walkFieldStore(internalFieldStore.children[key], callback);
|
|
314
|
-
}
|
|
315
|
-
function createFormStore(config, validate) {
|
|
316
|
-
const store = {};
|
|
317
|
-
initializeFieldStore(store, config.schema, config.initialInput, []);
|
|
318
|
-
store.validateOn = config.validateOn ?? "submit";
|
|
319
|
-
store.revalidateOn = config.revalidateOn ?? "input";
|
|
320
|
-
store.validate = validate;
|
|
321
|
-
store.isSubmitting = core.createSignal(false);
|
|
322
|
-
store.isSubmitted = core.createSignal(false);
|
|
323
|
-
store.isValidating = core.createSignal(false);
|
|
324
|
-
return store;
|
|
325
|
-
}
|
|
326
|
-
async function validateFormInput(internalFormStore, config) {
|
|
327
|
-
internalFormStore.validators++;
|
|
328
|
-
internalFormStore.isValidating.value = true;
|
|
329
|
-
const result = await internalFormStore.validate(core.untrack(() => getFieldInput(internalFormStore)));
|
|
330
|
-
let rootErrors;
|
|
331
|
-
let nestedErrors;
|
|
332
|
-
if (result.issues) {
|
|
333
|
-
nestedErrors = {};
|
|
334
|
-
for (const issue of result.issues) if (issue.path) {
|
|
335
|
-
const path = [];
|
|
336
|
-
for (const pathItem of issue.path) {
|
|
337
|
-
const key = pathItem.key;
|
|
338
|
-
const keyType = typeof key;
|
|
339
|
-
const itemType = pathItem.type;
|
|
340
|
-
if (keyType !== "string" && keyType !== "number" || itemType === "map" || itemType === "set") break;
|
|
341
|
-
path.push(key);
|
|
342
|
-
}
|
|
343
|
-
const name = JSON.stringify(path);
|
|
344
|
-
const fieldErrors = nestedErrors[name];
|
|
345
|
-
if (fieldErrors) fieldErrors.push(issue.message);
|
|
346
|
-
else nestedErrors[name] = [
|
|
347
|
-
issue.message
|
|
348
|
-
];
|
|
349
|
-
} else if (rootErrors) rootErrors.push(issue.message);
|
|
350
|
-
else rootErrors = [
|
|
351
|
-
issue.message
|
|
352
|
-
];
|
|
353
|
-
}
|
|
354
|
-
let shouldFocus = config?.shouldFocus ?? false;
|
|
355
|
-
batch(() => {
|
|
356
|
-
walkFieldStore(internalFormStore, (internalFieldStore) => {
|
|
357
|
-
if (internalFieldStore.name === "[]") internalFieldStore.errors.value = rootErrors ?? null;
|
|
358
|
-
else {
|
|
359
|
-
const fieldErrors = nestedErrors?.[internalFieldStore.name] ?? null;
|
|
360
|
-
internalFieldStore.errors.value = fieldErrors;
|
|
361
|
-
if (shouldFocus && fieldErrors) {
|
|
362
|
-
internalFieldStore.elements[0]?.focus();
|
|
363
|
-
shouldFocus = false;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
internalFormStore.validators--;
|
|
368
|
-
internalFormStore.isValidating.value = internalFormStore.validators > 0;
|
|
369
|
-
});
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
function validateIfRequired(internalFormStore, internalFieldStore, validationModes) {
|
|
373
|
-
if (validationModes === (internalFormStore.validateOn === "initial" || (internalFormStore.validateOn === "submit" ? core.untrack(() => internalFormStore.isSubmitted.value) : core.untrack(() => getFieldBool(internalFieldStore, "errors"))) ? internalFormStore.revalidateOn : internalFormStore.validateOn)) validateFormInput(internalFormStore);
|
|
374
|
-
}
|
|
375
|
-
const INTERNAL = "~internal";
|
|
376
|
-
Object.defineProperty(exports, "createSignal", {
|
|
377
|
-
enumerable: true,
|
|
378
|
-
get: () => core.createSignal
|
|
379
|
-
});
|
|
380
|
-
Object.defineProperty(exports, "untrack", {
|
|
381
|
-
enumerable: true,
|
|
382
|
-
get: () => core.untrack
|
|
383
|
-
});
|
|
384
|
-
exports.INTERNAL = INTERNAL;
|
|
385
|
-
exports.batch = batch;
|
|
386
|
-
exports.copyItemState = copyItemState;
|
|
387
|
-
exports.createFormStore = createFormStore;
|
|
388
|
-
exports.createId = createId;
|
|
389
|
-
exports.getElementInput = getElementInput;
|
|
390
|
-
exports.getFieldBool = getFieldBool;
|
|
391
|
-
exports.getFieldInput = getFieldInput;
|
|
392
|
-
exports.getFieldStore = getFieldStore;
|
|
393
|
-
exports.initializeFieldStore = initializeFieldStore;
|
|
394
|
-
exports.resetItemState = resetItemState;
|
|
395
|
-
exports.setFieldBool = setFieldBool;
|
|
396
|
-
exports.setFieldInput = setFieldInput;
|
|
397
|
-
exports.setInitialFieldInput = setInitialFieldInput;
|
|
398
|
-
exports.swapItemState = swapItemState;
|
|
399
|
-
exports.validateFormInput = validateFormInput;
|
|
400
|
-
exports.validateIfRequired = validateIfRequired;
|
|
401
|
-
exports.walkFieldStore = walkFieldStore;
|