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