@goodie-forms/core 1.2.6-alpha → 1.3.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 +61 -0
- package/dist/field/FieldPath.d.ts.map +1 -1
- package/dist/field/Reconcile.d.ts +4 -1
- package/dist/field/Reconcile.d.ts.map +1 -1
- package/dist/form/FormController.d.ts.map +1 -1
- package/dist/form/FormField.d.ts.map +1 -1
- package/dist/index.js +179 -181
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
- package/src/field/FieldPath.ts +1 -0
- package/src/field/Reconcile.ts +10 -5
- package/src/form/FormController.ts +8 -13
- package/src/form/FormField.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodie-forms/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/iGoodie/goodie-forms"
|
|
7
|
+
},
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Taha Anılcan Metinyurt",
|
|
10
|
+
"email": "igoodie@programmer.net",
|
|
11
|
+
"url": "https://github.com/iGoodie"
|
|
12
|
+
},
|
|
13
|
+
"license": "CC BY-SA 4.0",
|
|
4
14
|
"type": "module",
|
|
5
15
|
"main": "dist/index.js",
|
|
6
16
|
"types": "dist/index.d.ts",
|
package/src/field/FieldPath.ts
CHANGED
package/src/field/Reconcile.ts
CHANGED
|
@@ -73,24 +73,29 @@ export namespace Reconcile {
|
|
|
73
73
|
export function arrayDiff<T>(
|
|
74
74
|
prev: readonly T[],
|
|
75
75
|
next: readonly T[],
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
opts?: {
|
|
77
|
+
equals?: (a: T, b: T) => boolean;
|
|
78
|
+
include?: (a: T) => boolean;
|
|
79
|
+
},
|
|
78
80
|
) {
|
|
79
81
|
const added: T[] = [];
|
|
80
82
|
const removed: T[] = [];
|
|
81
83
|
const unchanged: T[] = [];
|
|
82
84
|
|
|
85
|
+
const equals = (a: T, b: T) => (opts?.equals ? opts.equals(a, b) : a === b);
|
|
86
|
+
const include = (a: T) => (opts?.include ? opts.include(a) : true);
|
|
87
|
+
|
|
83
88
|
for (const n of next) {
|
|
84
89
|
if (prev.some((p) => equals(p, n))) {
|
|
85
|
-
if (
|
|
90
|
+
if (include(n)) unchanged.push(n);
|
|
86
91
|
} else {
|
|
87
|
-
if (
|
|
92
|
+
if (include(n)) added.push(n);
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
for (const p of prev) {
|
|
92
97
|
if (!next.some((n) => equals(p, n))) {
|
|
93
|
-
if (
|
|
98
|
+
if (include(p)) removed.push(p);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -116,8 +116,7 @@ export class FormController<TOutput extends object> {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
get isValid() {
|
|
119
|
-
|
|
120
|
-
return this._issues.length === 0;
|
|
119
|
+
return this.isValidating || this._issues.length === 0;
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
get isValidating() {
|
|
@@ -273,11 +272,9 @@ export class FormController<TOutput extends object> {
|
|
|
273
272
|
_result: StandardSchemaV1.Result<TOutput>,
|
|
274
273
|
path: TPath,
|
|
275
274
|
) {
|
|
276
|
-
const diff = Reconcile.arrayDiff(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
Reconcile.deepEqual,
|
|
280
|
-
(issue) => {
|
|
275
|
+
const diff = Reconcile.arrayDiff(this._issues, _result.issues ?? [], {
|
|
276
|
+
equals: Reconcile.deepEqual,
|
|
277
|
+
include: (issue) => {
|
|
281
278
|
if (issue.path == null) return false;
|
|
282
279
|
const issuePath = FieldPath.normalize(issue.path);
|
|
283
280
|
return (
|
|
@@ -285,7 +282,7 @@ export class FormController<TOutput extends object> {
|
|
|
285
282
|
FieldPath.isDescendant(path, issuePath)
|
|
286
283
|
);
|
|
287
284
|
},
|
|
288
|
-
);
|
|
285
|
+
});
|
|
289
286
|
|
|
290
287
|
removeBy(this._issues, (issue) => diff.removed.includes(issue));
|
|
291
288
|
|
|
@@ -314,11 +311,9 @@ export class FormController<TOutput extends object> {
|
|
|
314
311
|
}
|
|
315
312
|
|
|
316
313
|
// Append non-registered issues too
|
|
317
|
-
const diff = Reconcile.arrayDiff(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
Reconcile.deepEqual,
|
|
321
|
-
);
|
|
314
|
+
const diff = Reconcile.arrayDiff(this._issues, result.issues ?? [], {
|
|
315
|
+
equals: Reconcile.deepEqual,
|
|
316
|
+
});
|
|
322
317
|
diff.added.forEach((issue) => this._issues.push(issue));
|
|
323
318
|
|
|
324
319
|
this.setValidating(false);
|
package/src/form/FormField.ts
CHANGED
|
@@ -182,6 +182,9 @@ export class FormField<TOutput extends object, TValue> {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// TODO: impl
|
|
186
|
+
// private modifyInitialData() {}
|
|
187
|
+
|
|
185
188
|
setValue(value: TValue, opts?: Parameters<typeof this.modifyData>[1]) {
|
|
186
189
|
return this.modifyData((data) => {
|
|
187
190
|
FieldPath.setValue(data as TOutput, this.path, value as never);
|