@formisch/solid 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dev.js +125 -95
- package/dist/dev.jsx +130 -95
- package/dist/index.d.ts +477 -160
- package/dist/index.js +125 -95
- package/dist/index.jsx +130 -95
- package/package.json +1 -1
package/dist/dev.jsx
CHANGED
|
@@ -23,11 +23,13 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
|
|
|
23
23
|
else {
|
|
24
24
|
internalFieldStore.schema = schema;
|
|
25
25
|
internalFieldStore.name = JSON.stringify(path);
|
|
26
|
+
internalFieldStore.path = path;
|
|
26
27
|
const initialElements = [];
|
|
27
28
|
internalFieldStore.initialElements = initialElements;
|
|
28
29
|
internalFieldStore.elements = initialElements;
|
|
29
30
|
internalFieldStore.errors = /* @__PURE__ */ createSignal(null);
|
|
30
31
|
internalFieldStore.isTouched = /* @__PURE__ */ createSignal(false);
|
|
32
|
+
internalFieldStore.isEdited = /* @__PURE__ */ createSignal(false);
|
|
31
33
|
internalFieldStore.isDirty = /* @__PURE__ */ createSignal(false);
|
|
32
34
|
if (schema.type === "array" || schema.type === "loose_tuple" || schema.type === "strict_tuple" || schema.type === "tuple") {
|
|
33
35
|
if (internalFieldStore.kind && internalFieldStore.kind !== "array") throw new Error(`Store initialized as "${internalFieldStore.kind}" cannot be reinitialized as "array"`);
|
|
@@ -37,16 +39,13 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
|
|
|
37
39
|
if (schema.type === "array") {
|
|
38
40
|
if (initialInput) for (let index = 0; index < initialInput.length; index++) {
|
|
39
41
|
internalFieldStore.children[index] = {};
|
|
40
|
-
|
|
41
|
-
initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
|
|
42
|
-
path.pop();
|
|
42
|
+
initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], [...path, index]);
|
|
43
43
|
}
|
|
44
44
|
} else for (let index = 0; index < schema.items.length; index++) {
|
|
45
45
|
internalFieldStore.children[index] = {};
|
|
46
|
-
|
|
47
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
48
|
-
path.pop();
|
|
46
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], [...path, index]);
|
|
49
47
|
}
|
|
48
|
+
internalFieldStore.isNullish = nullish;
|
|
50
49
|
const arrayInput = nullish && initialInput == null ? initialInput : true;
|
|
51
50
|
internalFieldStore.initialInput = /* @__PURE__ */ createSignal(arrayInput);
|
|
52
51
|
internalFieldStore.startInput = /* @__PURE__ */ createSignal(arrayInput);
|
|
@@ -63,10 +62,9 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
|
|
|
63
62
|
internalFieldStore.children ??= {};
|
|
64
63
|
for (const key in schema.entries) {
|
|
65
64
|
internalFieldStore.children[key] ??= {};
|
|
66
|
-
|
|
67
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
68
|
-
path.pop();
|
|
65
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], [...path, key]);
|
|
69
66
|
}
|
|
67
|
+
internalFieldStore.isNullish = nullish;
|
|
70
68
|
const objectInput = nullish && initialInput == null ? initialInput : true;
|
|
71
69
|
internalFieldStore.initialInput = /* @__PURE__ */ createSignal(objectInput);
|
|
72
70
|
internalFieldStore.startInput = /* @__PURE__ */ createSignal(objectInput);
|
|
@@ -91,19 +89,16 @@ function copyItemState(fromInternalFieldStore, toInternalFieldStore) {
|
|
|
91
89
|
toInternalFieldStore.startInput.value = fromInternalFieldStore.startInput.value;
|
|
92
90
|
toInternalFieldStore.input.value = fromInternalFieldStore.input.value;
|
|
93
91
|
toInternalFieldStore.isTouched.value = fromInternalFieldStore.isTouched.value;
|
|
92
|
+
toInternalFieldStore.isEdited.value = fromInternalFieldStore.isEdited.value;
|
|
94
93
|
toInternalFieldStore.isDirty.value = fromInternalFieldStore.isDirty.value;
|
|
95
94
|
if (fromInternalFieldStore.kind === "array" && toInternalFieldStore.kind === "array") {
|
|
96
95
|
const fromItems = fromInternalFieldStore.items.value;
|
|
97
96
|
toInternalFieldStore.startItems.value = fromInternalFieldStore.startItems.value;
|
|
98
97
|
toInternalFieldStore.items.value = fromItems;
|
|
99
|
-
let path;
|
|
100
98
|
for (let index = 0; index < fromItems.length; index++) {
|
|
101
99
|
if (!toInternalFieldStore.children[index]) {
|
|
102
|
-
path ??= JSON.parse(toInternalFieldStore.name);
|
|
103
100
|
toInternalFieldStore.children[index] = {};
|
|
104
|
-
|
|
105
|
-
initializeFieldStore(toInternalFieldStore.children[index], toInternalFieldStore.schema.item, void 0, path);
|
|
106
|
-
path.pop();
|
|
101
|
+
initializeFieldStore(toInternalFieldStore.children[index], toInternalFieldStore.schema.item, void 0, [...toInternalFieldStore.path, index]);
|
|
107
102
|
}
|
|
108
103
|
copyItemState(fromInternalFieldStore.children[index], toInternalFieldStore.children[index]);
|
|
109
104
|
}
|
|
@@ -118,30 +113,32 @@ function resetItemState(internalFieldStore, input, keepStart = false) {
|
|
|
118
113
|
internalFieldStore.elements = elements;
|
|
119
114
|
internalFieldStore.errors.value = null;
|
|
120
115
|
internalFieldStore.isTouched.value = false;
|
|
116
|
+
internalFieldStore.isEdited.value = false;
|
|
121
117
|
internalFieldStore.isDirty.value = false;
|
|
122
118
|
if (internalFieldStore.kind === "array" || internalFieldStore.kind === "object") {
|
|
123
|
-
const objectInput = input == null ? input : true;
|
|
119
|
+
const objectInput = internalFieldStore.isNullish && input == null ? input : true;
|
|
124
120
|
if (!keepStart) internalFieldStore.startInput.value = objectInput;
|
|
125
121
|
internalFieldStore.input.value = objectInput;
|
|
126
|
-
if (internalFieldStore.kind === "array")
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
122
|
+
if (internalFieldStore.kind === "array") {
|
|
123
|
+
const isTuple = internalFieldStore.schema.type !== "array";
|
|
124
|
+
if (input || isTuple) {
|
|
125
|
+
const length = isTuple ? internalFieldStore.children.length : input.length;
|
|
126
|
+
const newItems = Array.from({ length }, createId);
|
|
127
|
+
if (!keepStart) internalFieldStore.startItems.value = newItems;
|
|
128
|
+
internalFieldStore.items.value = newItems;
|
|
129
|
+
for (let index = 0; index < length; index++) {
|
|
130
|
+
const itemInput = input?.[index];
|
|
131
|
+
if (internalFieldStore.children[index]) resetItemState(internalFieldStore.children[index], itemInput, keepStart);
|
|
132
|
+
else {
|
|
133
|
+
internalFieldStore.children[index] = {};
|
|
134
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, itemInput, [...internalFieldStore.path, index]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
if (!keepStart) internalFieldStore.startItems.value = [];
|
|
139
|
+
internalFieldStore.items.value = [];
|
|
139
140
|
}
|
|
140
|
-
} else
|
|
141
|
-
if (!keepStart) internalFieldStore.startItems.value = [];
|
|
142
|
-
internalFieldStore.items.value = [];
|
|
143
|
-
}
|
|
144
|
-
else for (const key in internalFieldStore.children) resetItemState(internalFieldStore.children[key], input?.[key], keepStart);
|
|
141
|
+
} else for (const key in internalFieldStore.children) resetItemState(internalFieldStore.children[key], input?.[key], keepStart);
|
|
145
142
|
} else {
|
|
146
143
|
if (!keepStart) internalFieldStore.startInput.value = input;
|
|
147
144
|
internalFieldStore.input.value = input;
|
|
@@ -166,6 +163,9 @@ function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
|
|
|
166
163
|
const tempIsTouched = firstInternalFieldStore.isTouched.value;
|
|
167
164
|
firstInternalFieldStore.isTouched.value = secondInternalFieldStore.isTouched.value;
|
|
168
165
|
secondInternalFieldStore.isTouched.value = tempIsTouched;
|
|
166
|
+
const tempIsEdited = firstInternalFieldStore.isEdited.value;
|
|
167
|
+
firstInternalFieldStore.isEdited.value = secondInternalFieldStore.isEdited.value;
|
|
168
|
+
secondInternalFieldStore.isEdited.value = tempIsEdited;
|
|
169
169
|
const tempIsDirty = firstInternalFieldStore.isDirty.value;
|
|
170
170
|
firstInternalFieldStore.isDirty.value = secondInternalFieldStore.isDirty.value;
|
|
171
171
|
secondInternalFieldStore.isDirty.value = tempIsDirty;
|
|
@@ -178,22 +178,14 @@ function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
|
|
|
178
178
|
firstInternalFieldStore.items.value = secondItems;
|
|
179
179
|
secondInternalFieldStore.items.value = firstItems;
|
|
180
180
|
const maxLength = Math.max(firstItems.length, secondItems.length);
|
|
181
|
-
let firstPath;
|
|
182
|
-
let secondPath;
|
|
183
181
|
for (let index = 0; index < maxLength; index++) {
|
|
184
182
|
if (!firstInternalFieldStore.children[index]) {
|
|
185
|
-
firstPath ??= JSON.parse(firstInternalFieldStore.name);
|
|
186
183
|
firstInternalFieldStore.children[index] = {};
|
|
187
|
-
|
|
188
|
-
initializeFieldStore(firstInternalFieldStore.children[index], firstInternalFieldStore.schema.item, void 0, firstPath);
|
|
189
|
-
firstPath.pop();
|
|
184
|
+
initializeFieldStore(firstInternalFieldStore.children[index], firstInternalFieldStore.schema.item, void 0, [...firstInternalFieldStore.path, index]);
|
|
190
185
|
}
|
|
191
186
|
if (!secondInternalFieldStore.children[index]) {
|
|
192
|
-
secondPath ??= JSON.parse(secondInternalFieldStore.name);
|
|
193
187
|
secondInternalFieldStore.children[index] = {};
|
|
194
|
-
|
|
195
|
-
initializeFieldStore(secondInternalFieldStore.children[index], secondInternalFieldStore.schema.item, void 0, secondPath);
|
|
196
|
-
secondPath.pop();
|
|
188
|
+
initializeFieldStore(secondInternalFieldStore.children[index], secondInternalFieldStore.schema.item, void 0, [...secondInternalFieldStore.path, index]);
|
|
197
189
|
}
|
|
198
190
|
swapItemState(firstInternalFieldStore.children[index], secondInternalFieldStore.children[index]);
|
|
199
191
|
}
|
|
@@ -208,20 +200,20 @@ function focusFieldElement(internalFieldStore) {
|
|
|
208
200
|
}
|
|
209
201
|
return false;
|
|
210
202
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (internalFieldStore[type].value) return true;
|
|
203
|
+
function walkFieldStore(internalFieldStore, callback) {
|
|
204
|
+
if (callback(internalFieldStore)) return true;
|
|
214
205
|
if (internalFieldStore.kind === "array") {
|
|
215
|
-
for (let index = 0; index < internalFieldStore.items.value.length; index++) if (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (internalFieldStore.kind == "object") {
|
|
219
|
-
for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
|
|
220
|
-
return false;
|
|
206
|
+
for (let index = 0; index < internalFieldStore.items.value.length; index++) if (walkFieldStore(internalFieldStore.children[index], callback)) return true;
|
|
207
|
+
} else if (internalFieldStore.kind === "object") {
|
|
208
|
+
for (const key in internalFieldStore.children) if (walkFieldStore(internalFieldStore.children[key], callback)) return true;
|
|
221
209
|
}
|
|
222
210
|
return false;
|
|
223
211
|
}
|
|
224
212
|
// @__NO_SIDE_EFFECTS__
|
|
213
|
+
function getFieldBool(internalFieldStore, type) {
|
|
214
|
+
return walkFieldStore(internalFieldStore, (internalFieldStore$1) => Boolean(internalFieldStore$1[type].value));
|
|
215
|
+
}
|
|
216
|
+
// @__NO_SIDE_EFFECTS__
|
|
225
217
|
function getDirtyFieldInput(internalFieldStore, dirtyOnly = true) {
|
|
226
218
|
if (dirtyOnly && !/* @__PURE__ */ getFieldBool(internalFieldStore, "isDirty")) return;
|
|
227
219
|
if (internalFieldStore.kind === "array") {
|
|
@@ -291,26 +283,26 @@ function getFieldStore(internalFormStore, path) {
|
|
|
291
283
|
}
|
|
292
284
|
function setFieldBool(internalFieldStore, type, bool) {
|
|
293
285
|
batch(() => {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
286
|
+
untrack(() => {
|
|
287
|
+
walkFieldStore(internalFieldStore, (internalFieldStore$1) => {
|
|
288
|
+
internalFieldStore$1[type].value = bool;
|
|
289
|
+
});
|
|
290
|
+
});
|
|
297
291
|
});
|
|
298
292
|
}
|
|
299
293
|
function setNestedInput(internalFieldStore, input) {
|
|
300
294
|
internalFieldStore.isTouched.value = true;
|
|
295
|
+
internalFieldStore.isEdited.value = true;
|
|
301
296
|
if (internalFieldStore.kind === "array") {
|
|
302
297
|
const arrayInput = input ?? [];
|
|
303
298
|
const items = internalFieldStore.items.value;
|
|
304
299
|
const length = internalFieldStore.schema.type === "array" ? arrayInput.length : internalFieldStore.children.length;
|
|
305
300
|
if (length < items.length) internalFieldStore.items.value = items.slice(0, length);
|
|
306
301
|
else if (length > items.length) {
|
|
307
|
-
const path = JSON.parse(internalFieldStore.name);
|
|
308
302
|
for (let index = items.length; index < length; index++) if (internalFieldStore.children[index]) resetItemState(internalFieldStore.children[index], arrayInput[index], true);
|
|
309
303
|
else {
|
|
310
304
|
internalFieldStore.children[index] = {};
|
|
311
|
-
|
|
312
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
313
|
-
path.pop();
|
|
305
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], [...internalFieldStore.path, index]);
|
|
314
306
|
}
|
|
315
307
|
internalFieldStore.items.value = [...items, ...Array.from({ length: length - items.length }, createId)];
|
|
316
308
|
}
|
|
@@ -345,14 +337,9 @@ function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
|
345
337
|
internalFieldStore.initialInput.value = initialInput == null ? initialInput : true;
|
|
346
338
|
const initialArrayInput = initialInput ?? [];
|
|
347
339
|
const length = internalFieldStore.schema.type === "array" ? initialArrayInput.length : internalFieldStore.children.length;
|
|
348
|
-
if (length > internalFieldStore.children.length) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
internalFieldStore.children[index] = {};
|
|
352
|
-
path.push(index);
|
|
353
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
354
|
-
path.pop();
|
|
355
|
-
}
|
|
340
|
+
if (length > internalFieldStore.children.length) for (let index = internalFieldStore.children.length; index < length; index++) {
|
|
341
|
+
internalFieldStore.children[index] = {};
|
|
342
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], [...internalFieldStore.path, index]);
|
|
356
343
|
}
|
|
357
344
|
internalFieldStore.initialItems.value = Array.from({ length }, createId);
|
|
358
345
|
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
@@ -362,11 +349,6 @@ function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
|
362
349
|
} else internalFieldStore.initialInput.value = initialInput;
|
|
363
350
|
});
|
|
364
351
|
}
|
|
365
|
-
function walkFieldStore(internalFieldStore, callback) {
|
|
366
|
-
callback(internalFieldStore);
|
|
367
|
-
if (internalFieldStore.kind === "array") for (let index = 0; index < untrack(() => internalFieldStore.items.value).length; index++) walkFieldStore(internalFieldStore.children[index], callback);
|
|
368
|
-
else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) walkFieldStore(internalFieldStore.children[key], callback);
|
|
369
|
-
}
|
|
370
352
|
function createFormStore(config, parse) {
|
|
371
353
|
const store = {};
|
|
372
354
|
initializeFieldStore(store, config.schema, config.initialInput, []);
|
|
@@ -406,13 +388,15 @@ async function validateFormInput(internalFormStore, config) {
|
|
|
406
388
|
}
|
|
407
389
|
let shouldFocus = config?.shouldFocus ?? false;
|
|
408
390
|
batch(() => {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
391
|
+
untrack(() => {
|
|
392
|
+
walkFieldStore(internalFormStore, (internalFieldStore) => {
|
|
393
|
+
if (internalFieldStore.path.length === 0) internalFieldStore.errors.value = rootErrors ?? null;
|
|
394
|
+
else {
|
|
395
|
+
const fieldErrors = nestedErrors?.[internalFieldStore.name] ?? null;
|
|
396
|
+
internalFieldStore.errors.value = fieldErrors;
|
|
397
|
+
if (shouldFocus && fieldErrors && focusFieldElement(internalFieldStore)) shouldFocus = false;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
416
400
|
});
|
|
417
401
|
internalFormStore.validators--;
|
|
418
402
|
internalFormStore.isValidating.value = internalFormStore.validators > 0;
|
|
@@ -436,15 +420,26 @@ function focus(form, config) {
|
|
|
436
420
|
focusFieldElement(getFieldStore(form[INTERNAL], config.path));
|
|
437
421
|
}
|
|
438
422
|
// @__NO_SIDE_EFFECTS__
|
|
439
|
-
function
|
|
440
|
-
|
|
441
|
-
walkFieldStore(form[INTERNAL], (internalFieldStore) => {
|
|
442
|
-
|
|
423
|
+
function getDeepErrorEntries(form, config) {
|
|
424
|
+
const entries = [];
|
|
425
|
+
walkFieldStore(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], (internalFieldStore) => {
|
|
426
|
+
const errors = internalFieldStore.errors.value;
|
|
427
|
+
if (errors) entries.push({
|
|
428
|
+
path: internalFieldStore.path,
|
|
429
|
+
errors
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
return entries;
|
|
433
|
+
}
|
|
434
|
+
// @__NO_SIDE_EFFECTS__
|
|
435
|
+
function getDeepErrors(form, config) {
|
|
436
|
+
let deepErrors = null;
|
|
437
|
+
walkFieldStore(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], (internalFieldStore) => {
|
|
443
438
|
const errors = internalFieldStore.errors.value;
|
|
444
|
-
if (errors) if (
|
|
445
|
-
else
|
|
439
|
+
if (errors) if (deepErrors) deepErrors.push(...errors);
|
|
440
|
+
else deepErrors = [...errors];
|
|
446
441
|
});
|
|
447
|
-
return
|
|
442
|
+
return deepErrors;
|
|
448
443
|
}
|
|
449
444
|
// @__NO_SIDE_EFFECTS__
|
|
450
445
|
function getDirtyInput(form, config) {
|
|
@@ -452,9 +447,8 @@ function getDirtyInput(form, config) {
|
|
|
452
447
|
}
|
|
453
448
|
// @__NO_SIDE_EFFECTS__
|
|
454
449
|
function getDirtyPaths(form, config) {
|
|
455
|
-
config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL];
|
|
456
450
|
const paths = [];
|
|
457
|
-
config?.path
|
|
451
|
+
config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL];
|
|
458
452
|
return paths;
|
|
459
453
|
}
|
|
460
454
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -498,25 +492,38 @@ function insert(form, config) {
|
|
|
498
492
|
internalArrayStore.items.value = newItems;
|
|
499
493
|
for (let index = items.length; index > insertIndex; index--) {
|
|
500
494
|
if (!internalArrayStore.children[index]) {
|
|
501
|
-
const path = JSON.parse(internalArrayStore.name);
|
|
502
495
|
internalArrayStore.children[index] = {};
|
|
503
|
-
|
|
504
|
-
initializeFieldStore(internalArrayStore.children[index], internalArrayStore.schema.item, void 0, path);
|
|
496
|
+
initializeFieldStore(internalArrayStore.children[index], internalArrayStore.schema.item, void 0, [...internalArrayStore.path, index]);
|
|
505
497
|
}
|
|
506
498
|
copyItemState(internalArrayStore.children[index - 1], internalArrayStore.children[index]);
|
|
507
499
|
}
|
|
508
500
|
if (!internalArrayStore.children[insertIndex]) {
|
|
509
|
-
const path = JSON.parse(internalArrayStore.name);
|
|
510
501
|
internalArrayStore.children[insertIndex] = {};
|
|
511
|
-
|
|
512
|
-
initializeFieldStore(internalArrayStore.children[insertIndex], internalArrayStore.schema.item, config.initialInput, path);
|
|
502
|
+
initializeFieldStore(internalArrayStore.children[insertIndex], internalArrayStore.schema.item, config.initialInput, [...internalArrayStore.path, insertIndex]);
|
|
513
503
|
} else resetItemState(internalArrayStore.children[insertIndex], config.initialInput);
|
|
514
504
|
internalArrayStore.input.value = true;
|
|
515
505
|
internalArrayStore.isTouched.value = true;
|
|
506
|
+
internalArrayStore.isEdited.value = true;
|
|
516
507
|
internalArrayStore.isDirty.value = true;
|
|
517
508
|
validateIfRequired(internalFormStore, internalArrayStore, "input");
|
|
518
509
|
});
|
|
519
510
|
}
|
|
511
|
+
// @__NO_SIDE_EFFECTS__
|
|
512
|
+
function isDirty(form, config) {
|
|
513
|
+
return getFieldBool(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], "isDirty");
|
|
514
|
+
}
|
|
515
|
+
// @__NO_SIDE_EFFECTS__
|
|
516
|
+
function isEdited(form, config) {
|
|
517
|
+
return getFieldBool(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], "isEdited");
|
|
518
|
+
}
|
|
519
|
+
// @__NO_SIDE_EFFECTS__
|
|
520
|
+
function isTouched(form, config) {
|
|
521
|
+
return getFieldBool(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], "isTouched");
|
|
522
|
+
}
|
|
523
|
+
// @__NO_SIDE_EFFECTS__
|
|
524
|
+
function isValid(form, config) {
|
|
525
|
+
return !getFieldBool(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL], "errors");
|
|
526
|
+
}
|
|
520
527
|
function move(form, config) {
|
|
521
528
|
const internalFormStore = form[INTERNAL];
|
|
522
529
|
const internalArrayStore = getFieldStore(internalFormStore, config.path);
|
|
@@ -532,6 +539,7 @@ function move(form, config) {
|
|
|
532
539
|
else for (let index = config.from; index > config.to; index--) copyItemState(internalArrayStore.children[index - 1], internalArrayStore.children[index]);
|
|
533
540
|
copyItemState(tempInternalFieldStore, internalArrayStore.children[config.to]);
|
|
534
541
|
internalArrayStore.isTouched.value = true;
|
|
542
|
+
internalArrayStore.isEdited.value = true;
|
|
535
543
|
internalArrayStore.isDirty.value = internalArrayStore.startItems.value.join() !== newItems.join();
|
|
536
544
|
validateIfRequired(internalFormStore, internalArrayStore, "input");
|
|
537
545
|
});
|
|
@@ -564,6 +572,7 @@ function remove(form, config) {
|
|
|
564
572
|
internalArrayStore.items.value = newItems;
|
|
565
573
|
for (let index = config.at; index < items.length - 1; index++) copyItemState(internalArrayStore.children[index + 1], internalArrayStore.children[index]);
|
|
566
574
|
internalArrayStore.isTouched.value = true;
|
|
575
|
+
internalArrayStore.isEdited.value = true;
|
|
567
576
|
internalArrayStore.isDirty.value = internalArrayStore.startItems.value.join() !== newItems.join();
|
|
568
577
|
validateIfRequired(internalFormStore, internalArrayStore, "input");
|
|
569
578
|
});
|
|
@@ -578,6 +587,7 @@ function replace(form, config) {
|
|
|
578
587
|
internalArrayStore.items.value = newItems;
|
|
579
588
|
resetItemState(internalArrayStore.children[config.at], config.initialInput);
|
|
580
589
|
internalArrayStore.isTouched.value = true;
|
|
590
|
+
internalArrayStore.isEdited.value = true;
|
|
581
591
|
internalArrayStore.isDirty.value = true;
|
|
582
592
|
validateIfRequired(internalFormStore, internalArrayStore, "input");
|
|
583
593
|
});
|
|
@@ -592,6 +602,7 @@ function reset(form, config) {
|
|
|
592
602
|
internalFieldStore$1.elements = internalFieldStore$1.initialElements;
|
|
593
603
|
if (!config?.keepErrors) internalFieldStore$1.errors.value = null;
|
|
594
604
|
if (!config?.keepTouched) internalFieldStore$1.isTouched.value = false;
|
|
605
|
+
if (!config?.keepEdited) internalFieldStore$1.isEdited.value = false;
|
|
595
606
|
internalFieldStore$1.startInput.value = internalFieldStore$1.initialInput.value;
|
|
596
607
|
if (!config?.keepInput) internalFieldStore$1.input.value = internalFieldStore$1.initialInput.value;
|
|
597
608
|
if (internalFieldStore$1.kind === "array") {
|
|
@@ -638,6 +649,7 @@ function swap(form, config) {
|
|
|
638
649
|
internalArrayStore.items.value = newItems;
|
|
639
650
|
swapItemState(internalArrayStore.children[config.at], internalArrayStore.children[config.and]);
|
|
640
651
|
internalArrayStore.isTouched.value = true;
|
|
652
|
+
internalArrayStore.isEdited.value = true;
|
|
641
653
|
internalArrayStore.isDirty.value = internalArrayStore.startItems.value.join() !== newItems.join();
|
|
642
654
|
validateIfRequired(internalFormStore, internalArrayStore, "input");
|
|
643
655
|
});
|
|
@@ -658,6 +670,9 @@ function createForm(config) {
|
|
|
658
670
|
const getIsTouched = createMemo(
|
|
659
671
|
() => getFieldBool(internalFormStore, "isTouched")
|
|
660
672
|
);
|
|
673
|
+
const getIsEdited = createMemo(
|
|
674
|
+
() => getFieldBool(internalFormStore, "isEdited")
|
|
675
|
+
);
|
|
661
676
|
const getIsDirty = createMemo(
|
|
662
677
|
() => getFieldBool(internalFormStore, "isDirty")
|
|
663
678
|
);
|
|
@@ -678,6 +693,9 @@ function createForm(config) {
|
|
|
678
693
|
get isTouched() {
|
|
679
694
|
return getIsTouched();
|
|
680
695
|
},
|
|
696
|
+
get isEdited() {
|
|
697
|
+
return getIsEdited();
|
|
698
|
+
},
|
|
681
699
|
get isDirty() {
|
|
682
700
|
return getIsDirty();
|
|
683
701
|
},
|
|
@@ -717,6 +735,9 @@ function useField(form, config) {
|
|
|
717
735
|
const getIsTouched = createMemo2(
|
|
718
736
|
() => getFieldBool(getInternalFieldStore(), "isTouched")
|
|
719
737
|
);
|
|
738
|
+
const getIsEdited = createMemo2(
|
|
739
|
+
() => getFieldBool(getInternalFieldStore(), "isEdited")
|
|
740
|
+
);
|
|
720
741
|
const getIsDirty = createMemo2(
|
|
721
742
|
() => getFieldBool(getInternalFieldStore(), "isDirty")
|
|
722
743
|
);
|
|
@@ -736,6 +757,9 @@ function useField(form, config) {
|
|
|
736
757
|
get isTouched() {
|
|
737
758
|
return getIsTouched();
|
|
738
759
|
},
|
|
760
|
+
get isEdited() {
|
|
761
|
+
return getIsEdited();
|
|
762
|
+
},
|
|
739
763
|
get isDirty() {
|
|
740
764
|
return getIsDirty();
|
|
741
765
|
},
|
|
@@ -817,6 +841,9 @@ function useFieldArray(form, config) {
|
|
|
817
841
|
const getIsTouched = createMemo3(
|
|
818
842
|
() => getFieldBool(getInternalFieldStore(), "isTouched")
|
|
819
843
|
);
|
|
844
|
+
const getIsEdited = createMemo3(
|
|
845
|
+
() => getFieldBool(getInternalFieldStore(), "isEdited")
|
|
846
|
+
);
|
|
820
847
|
const getIsDirty = createMemo3(
|
|
821
848
|
() => getFieldBool(getInternalFieldStore(), "isDirty")
|
|
822
849
|
);
|
|
@@ -836,6 +863,9 @@ function useFieldArray(form, config) {
|
|
|
836
863
|
get isTouched() {
|
|
837
864
|
return getIsTouched();
|
|
838
865
|
},
|
|
866
|
+
get isEdited() {
|
|
867
|
+
return getIsEdited();
|
|
868
|
+
},
|
|
839
869
|
get isDirty() {
|
|
840
870
|
return getIsDirty();
|
|
841
871
|
},
|
|
@@ -885,13 +915,18 @@ export {
|
|
|
885
915
|
Form,
|
|
886
916
|
createForm,
|
|
887
917
|
focus,
|
|
888
|
-
|
|
918
|
+
getDeepErrorEntries,
|
|
919
|
+
getDeepErrors,
|
|
889
920
|
getDirtyInput,
|
|
890
921
|
getDirtyPaths,
|
|
891
922
|
getErrors,
|
|
892
923
|
getInput,
|
|
893
924
|
handleSubmit,
|
|
894
925
|
insert,
|
|
926
|
+
isDirty,
|
|
927
|
+
isEdited,
|
|
928
|
+
isTouched,
|
|
929
|
+
isValid,
|
|
895
930
|
move,
|
|
896
931
|
pickDirty,
|
|
897
932
|
remove,
|