@codeleap/form 7.0.1 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fields/bool.js +9 -5
- package/dist/fields/bool.js.map +1 -1
- package/dist/fields/date.js +17 -10
- package/dist/fields/date.js.map +1 -1
- package/dist/fields/file.js +9 -5
- package/dist/fields/file.js.map +1 -1
- package/dist/fields/group.js +9 -5
- package/dist/fields/group.js.map +1 -1
- package/dist/fields/index.d.ts +3 -3
- package/dist/fields/index.js +26 -17
- package/dist/fields/index.js.map +1 -1
- package/dist/fields/list.js +8 -3
- package/dist/fields/list.js.map +1 -1
- package/dist/fields/number.js +10 -6
- package/dist/fields/number.js.map +1 -1
- package/dist/fields/selectable.js +10 -6
- package/dist/fields/selectable.js.map +1 -1
- package/dist/fields/text.js +9 -5
- package/dist/fields/text.js.map +1 -1
- package/dist/hooks/index.js +7 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useField.js +6 -3
- package/dist/hooks/useField.js.map +1 -1
- package/dist/hooks/useValidate.js +12 -8
- package/dist/hooks/useValidate.js.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/Field.d.ts +4 -4
- package/dist/lib/Field.js +27 -22
- package/dist/lib/Field.js.map +1 -1
- package/dist/lib/Form.d.ts +2 -2
- package/dist/lib/Form.js +19 -15
- package/dist/lib/Form.js.map +1 -1
- package/dist/lib/factories.js +4 -1
- package/dist/lib/factories.js.map +1 -1
- package/dist/lib/index.js +20 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/useFieldBinding.js +6 -3
- package/dist/lib/useFieldBinding.js.map +1 -1
- package/dist/types/field.js +2 -1
- package/dist/types/form.js +2 -1
- package/dist/types/globals.js +2 -1
- package/dist/types/index.js +2 -1
- package/dist/types/validation.js +2 -1
- package/dist/validators/index.js +17 -1
- package/dist/validators/index.js.map +1 -1
- package/dist/validators/zod.js +9 -5
- package/dist/validators/zod.js.map +1 -1
- package/package.json +1 -1
package/dist/fields/bool.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanField = void 0;
|
|
4
|
+
const Field_1 = require("../lib/Field");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const validators_1 = require("../validators");
|
|
4
7
|
/**
|
|
5
8
|
* Field for boolean values (checkboxes, toggles). `Form.setValues` treats
|
|
6
9
|
* this field specially: it will only set a value when the incoming value is
|
|
7
10
|
* strictly `boolean`, because falsy coercion would prevent setting `false`.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class BooleanField extends Field_1.Field {
|
|
10
13
|
constructor(options) {
|
|
11
|
-
super(Object.assign({ validate: zodValidator(z.boolean()) }, options));
|
|
14
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.boolean()) }, options));
|
|
12
15
|
this._type = "BOOLEAN";
|
|
13
16
|
}
|
|
14
17
|
}
|
|
18
|
+
exports.BooleanField = BooleanField;
|
|
15
19
|
//# sourceMappingURL=bool.js.map
|
package/dist/fields/bool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bool.js","sourceRoot":"","sources":["../../src/fields/bool.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"bool.js","sourceRoot":"","sources":["../../src/fields/bool.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAS5C;;;;GAIG;AACH,MAAa,YAAgD,SAAQ,aAAwB;IAG3F,YAAY,OAAsC;QAChD,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,OAAC,CAAC,OAAO,EAAE,CAAwB,IACvD,OAAO,EACV,CAAA;QANJ,UAAK,GAAG,SAAS,CAAA;IAOjB,CAAC;CACF;AATD,oCASC"}
|
package/dist/fields/date.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
3
|
var t = {};
|
|
3
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -9,19 +10,24 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
10
|
}
|
|
10
11
|
return t;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DateField = void 0;
|
|
18
|
+
const Field_1 = require("../lib/Field");
|
|
19
|
+
const zod_1 = require("zod");
|
|
20
|
+
const validators_1 = require("../validators");
|
|
21
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
16
22
|
function normalizeToDate(val) {
|
|
17
23
|
if (!val)
|
|
18
24
|
return undefined;
|
|
19
25
|
if (val instanceof Date)
|
|
20
26
|
return val;
|
|
21
|
-
if (
|
|
27
|
+
if (dayjs_1.default.isDayjs(val))
|
|
22
28
|
return val.startOf('day').toDate();
|
|
23
29
|
if (typeof val === 'string') {
|
|
24
|
-
const parsed =
|
|
30
|
+
const parsed = (0, dayjs_1.default)(val);
|
|
25
31
|
return parsed.isValid() ? parsed.startOf('day').toDate() : undefined;
|
|
26
32
|
}
|
|
27
33
|
return undefined;
|
|
@@ -34,23 +40,24 @@ function normalizeToDate(val) {
|
|
|
34
40
|
* `undefined`, which fails the `z.date()` check. Bounds are enforced at the
|
|
35
41
|
* start of the day (`startOf('day')`) for dayjs inputs.
|
|
36
42
|
*/
|
|
37
|
-
|
|
43
|
+
class DateField extends Field_1.Field {
|
|
38
44
|
constructor(options) {
|
|
39
45
|
const { minimumDate, maximumDate } = options, rest = __rest(options, ["minimumDate", "maximumDate"]);
|
|
40
|
-
const schema = z.preprocess((val) => {
|
|
46
|
+
const schema = zod_1.z.preprocess((val) => {
|
|
41
47
|
const normalized = normalizeToDate(val);
|
|
42
48
|
if (!normalized || isNaN(normalized.getTime()))
|
|
43
49
|
return undefined;
|
|
44
50
|
return normalized;
|
|
45
|
-
}, z.date()
|
|
51
|
+
}, zod_1.z.date()
|
|
46
52
|
.refine(d => !minimumDate || d >= minimumDate, {
|
|
47
53
|
message: `Date must be on or after ${minimumDate === null || minimumDate === void 0 ? void 0 : minimumDate.toDateString()}`,
|
|
48
54
|
})
|
|
49
55
|
.refine(d => !maximumDate || d <= maximumDate, {
|
|
50
56
|
message: `Date must be on or before ${maximumDate === null || maximumDate === void 0 ? void 0 : maximumDate.toDateString()}`,
|
|
51
57
|
}));
|
|
52
|
-
super(Object.assign({ validate: zodValidator(schema) }, options));
|
|
58
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(schema) }, options));
|
|
53
59
|
this._type = "DATE";
|
|
54
60
|
}
|
|
55
61
|
}
|
|
62
|
+
exports.DateField = DateField;
|
|
56
63
|
//# sourceMappingURL=date.js.map
|
package/dist/fields/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/fields/date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/fields/date.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAC5C,kDAAyB;AAUzB,SAAS,eAAe,CAAC,GAAY;IACnC,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAE1B,IAAI,GAAG,YAAY,IAAI;QAAE,OAAO,GAAG,CAAA;IACnC,IAAI,eAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,OAAO,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B,IAClD,OAAO,EACV,CAAA;QAtBJ,UAAK,GAAG,MAAM,CAAA;IAuBd,CAAC;CACF;AAzBD,8BAyBC"}
|
package/dist/fields/file.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileField = void 0;
|
|
4
|
+
const Field_1 = require("../lib/Field");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const validators_1 = require("../validators");
|
|
4
7
|
/**
|
|
5
8
|
* Field for file uploads. The value type is `any` because the shape of a
|
|
6
9
|
* "file" differs between web (`File` / `FileList`) and React Native (asset
|
|
7
10
|
* descriptor objects). Supply a custom `validate` function to enforce whatever
|
|
8
11
|
* shape your platform produces.
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
class FileField extends Field_1.Field {
|
|
11
14
|
constructor(options) {
|
|
12
|
-
super(Object.assign({ validate: zodValidator(z.any()) }, options));
|
|
15
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.any()) }, options));
|
|
13
16
|
this._type = "FILE";
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
exports.FileField = FileField;
|
|
16
20
|
//# sourceMappingURL=file.js.map
|
package/dist/fields/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/fields/file.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/fields/file.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAO5C;;;;;GAKG;AACH,MAAa,SAA0C,SAAQ,aAAoB;IAGjF,YAAY,OAAmC;QAC7C,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,OAAC,CAAC,GAAG,EAAE,CAAwB,IACnD,OAAO,EACV,CAAA;QANJ,UAAK,GAAG,MAAM,CAAA;IAOd,CAAC;CACF;AATD,8BASC"}
|
package/dist/fields/group.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupField = void 0;
|
|
4
|
+
const Field_1 = require("../lib/Field");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const validators_1 = require("../validators");
|
|
4
7
|
/**
|
|
5
8
|
* Field that represents a selected group or category, stored as a string key.
|
|
6
9
|
* Structurally identical to `TextField` but carries the `"group"` type tag so
|
|
7
10
|
* platform renderers can distinguish it and render a group-picker control
|
|
8
11
|
* instead of a free-text input.
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
class GroupField extends Field_1.Field {
|
|
11
14
|
constructor(options) {
|
|
12
|
-
super(Object.assign({ validate: zodValidator(z.string()) }, options));
|
|
15
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.string()) }, options));
|
|
13
16
|
this._type = "group";
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
exports.GroupField = GroupField;
|
|
16
20
|
//# sourceMappingURL=group.js.map
|
package/dist/fields/group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/fields/group.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/fields/group.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAQ5C;;;;;GAKG;AACH,MAAa,UAA4C,SAAQ,aAAuB;IAGtF,YAAY,OAAoC;QAC9C,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,OAAC,CAAC,MAAM,EAAE,CAAwB,IACtD,OAAO,EACV,CAAA;QANJ,UAAK,GAAG,OAAO,CAAA;IAOf,CAAC;CACF;AATD,gCASC"}
|
package/dist/fields/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const fields: {
|
|
|
23
23
|
text: <A extends {
|
|
24
24
|
name?: string;
|
|
25
25
|
defaultValue?: string | null | undefined;
|
|
26
|
-
state?: import("nanostores").WritableAtom<string> | undefined;
|
|
26
|
+
state?: import("nanostores", { with: { "resolution-mode": "import" } }).WritableAtom<string> | undefined;
|
|
27
27
|
validate?: import("./text").TextValidator<any, any> | undefined;
|
|
28
28
|
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<string, import("./text").TextValidator<any, any>>, "loader">>) | undefined;
|
|
29
29
|
onValueChange?: ((newValue: string) => void) | undefined;
|
|
@@ -46,7 +46,7 @@ export declare const fields: {
|
|
|
46
46
|
boolean: <A extends {
|
|
47
47
|
name?: string;
|
|
48
48
|
defaultValue?: boolean | null | undefined;
|
|
49
|
-
state?: import("nanostores").WritableAtom<boolean> | undefined;
|
|
49
|
+
state?: import("nanostores", { with: { "resolution-mode": "import" } }).WritableAtom<boolean> | undefined;
|
|
50
50
|
validate?: import("./bool").BooleanValidator<any, any> | undefined;
|
|
51
51
|
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<boolean, import("./bool").BooleanValidator<any, any>>, "loader">>) | undefined;
|
|
52
52
|
onValueChange?: ((newValue: boolean) => void) | undefined;
|
|
@@ -54,7 +54,7 @@ export declare const fields: {
|
|
|
54
54
|
selectable: <A extends {
|
|
55
55
|
name?: string;
|
|
56
56
|
defaultValue?: (string | number) | null | undefined;
|
|
57
|
-
state?: import("nanostores").WritableAtom<string | number> | undefined;
|
|
57
|
+
state?: import("nanostores", { with: { "resolution-mode": "import" } }).WritableAtom<string | number> | undefined;
|
|
58
58
|
validate?: import("./selectable").SelectableValidator<string | number, any, any> | undefined;
|
|
59
59
|
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<string | number, import("./selectable").SelectableValidator<string | number, any, any>>, "loader">>) | undefined;
|
|
60
60
|
onValueChange?: ((newValue: string | number) => void) | undefined;
|
package/dist/fields/index.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileField = exports.DateField = exports.SelectableField = exports.BooleanField = exports.NumberField = exports.ListField = exports.TextField = exports.fields = void 0;
|
|
4
|
+
const factories_1 = require("../lib/factories");
|
|
5
|
+
const text_1 = require("./text");
|
|
6
|
+
Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return text_1.TextField; } });
|
|
7
|
+
const list_1 = require("./list");
|
|
8
|
+
Object.defineProperty(exports, "ListField", { enumerable: true, get: function () { return list_1.ListField; } });
|
|
9
|
+
const number_1 = require("./number");
|
|
10
|
+
Object.defineProperty(exports, "NumberField", { enumerable: true, get: function () { return number_1.NumberField; } });
|
|
11
|
+
const bool_1 = require("./bool");
|
|
12
|
+
Object.defineProperty(exports, "BooleanField", { enumerable: true, get: function () { return bool_1.BooleanField; } });
|
|
13
|
+
const selectable_1 = require("./selectable");
|
|
14
|
+
Object.defineProperty(exports, "SelectableField", { enumerable: true, get: function () { return selectable_1.SelectableField; } });
|
|
15
|
+
const date_1 = require("./date");
|
|
16
|
+
Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_1.DateField; } });
|
|
17
|
+
const file_1 = require("./file");
|
|
18
|
+
Object.defineProperty(exports, "FileField", { enumerable: true, get: function () { return file_1.FileField; } });
|
|
9
19
|
/**
|
|
10
20
|
* Convenience namespace that exposes factory functions for every built-in field
|
|
11
21
|
* type. Prefer these over calling constructors directly — they provide better
|
|
@@ -20,14 +30,13 @@ import { FileField } from "./file";
|
|
|
20
30
|
* `fieldFactory`, because `ListField` requires the `item` option's type to be
|
|
21
31
|
* inferred at the call site.
|
|
22
32
|
*/
|
|
23
|
-
|
|
24
|
-
text: fieldFactory(TextField),
|
|
25
|
-
list: listFieldFactory,
|
|
26
|
-
number: fieldFactory(NumberField),
|
|
27
|
-
boolean: fieldFactory(BooleanField),
|
|
28
|
-
selectable: fieldFactory(SelectableField),
|
|
29
|
-
date: fieldFactory(DateField),
|
|
30
|
-
file: fieldFactory(FileField),
|
|
33
|
+
exports.fields = {
|
|
34
|
+
text: (0, factories_1.fieldFactory)(text_1.TextField),
|
|
35
|
+
list: list_1.listFieldFactory,
|
|
36
|
+
number: (0, factories_1.fieldFactory)(number_1.NumberField),
|
|
37
|
+
boolean: (0, factories_1.fieldFactory)(bool_1.BooleanField),
|
|
38
|
+
selectable: (0, factories_1.fieldFactory)(selectable_1.SelectableField),
|
|
39
|
+
date: (0, factories_1.fieldFactory)(date_1.DateField),
|
|
40
|
+
file: (0, factories_1.fieldFactory)(file_1.FileField),
|
|
31
41
|
};
|
|
32
|
-
export { TextField, ListField, NumberField, BooleanField, SelectableField, DateField, FileField, };
|
|
33
42
|
//# sourceMappingURL=index.js.map
|
package/dist/fields/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAC/C,iCAAkC;AAkChC,0FAlCO,gBAAS,OAkCP;AAjCX,iCAAoD;AAkClD,0FAlCO,gBAAS,OAkCP;AAjCX,qCAAsC;AAkCpC,4FAlCO,oBAAW,OAkCP;AAjCb,iCAAqC;AAkCnC,6FAlCO,mBAAY,OAkCP;AAjCd,6CAA8C;AAkC5C,gGAlCO,4BAAe,OAkCP;AAjCjB,iCAAkC;AAkChC,0FAlCO,gBAAS,OAkCP;AAjCX,iCAAkC;AAkChC,0FAlCO,gBAAS,OAkCP;AA/BX;;;;;;;;;;;;;GAaG;AACU,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,IAAA,wBAAY,EAAC,gBAAS,CAAC;IAC7B,IAAI,EAAE,uBAAgB;IACtB,MAAM,EAAE,IAAA,wBAAY,EAAC,oBAAW,CAAC;IACjC,OAAO,EAAE,IAAA,wBAAY,EAAC,mBAAY,CAAC;IACnC,UAAU,EAAE,IAAA,wBAAY,EAAC,4BAAe,CAAC;IACzC,IAAI,EAAE,IAAA,wBAAY,EAAC,gBAAS,CAAC;IAC7B,IAAI,EAAE,IAAA,wBAAY,EAAC,gBAAS,CAAC;CAC9B,CAAA"}
|
package/dist/fields/list.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ListField = void 0;
|
|
4
|
+
exports.listFieldFactory = listFieldFactory;
|
|
5
|
+
const Field_1 = require("../lib/Field");
|
|
2
6
|
/**
|
|
3
7
|
* Field that holds an array of values, each validated by a delegate `item`
|
|
4
8
|
* field. The built-in validator iterates every element through
|
|
@@ -9,7 +13,7 @@ import { Field } from "../lib/Field";
|
|
|
9
13
|
* The `item` field acts as a prototype — it is not mounted independently and
|
|
10
14
|
* does not own its own atom. Do not call `use()` on it directly.
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
class ListField extends Field_1.Field {
|
|
13
17
|
constructor(options) {
|
|
14
18
|
super(Object.assign(Object.assign({}, options), { validate: ((v, form) => {
|
|
15
19
|
var _a, _b, _c;
|
|
@@ -37,6 +41,7 @@ export class ListField extends Field {
|
|
|
37
41
|
this._type = "LIST";
|
|
38
42
|
}
|
|
39
43
|
}
|
|
44
|
+
exports.ListField = ListField;
|
|
40
45
|
/**
|
|
41
46
|
* Convenience factory for `ListField`. Unlike `fieldFactory`-based helpers,
|
|
42
47
|
* `ListField` requires an `item` option whose generic type must be inferred at
|
|
@@ -44,7 +49,7 @@ export class ListField extends Field {
|
|
|
44
49
|
* exists to provide a consistent `fields.list(...)` call signature alongside
|
|
45
50
|
* the other entries in the `fields` namespace.
|
|
46
51
|
*/
|
|
47
|
-
|
|
52
|
+
function listFieldFactory(options) {
|
|
48
53
|
return new ListField(options);
|
|
49
54
|
}
|
|
50
55
|
//# sourceMappingURL=list.js.map
|
package/dist/fields/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/fields/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/fields/list.ts"],"names":[],"mappings":";;;AAkFA,4CAEC;AApFD,wCAAoC;AA6BpC;;;;;;;;;GASG;AACH,MAAa,SAAqC,SAAQ,aAAiD;IAGzG,YAAY,OAA4B;QACtC,KAAK,CAAC,gCACD,OAAO,KACV,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;;gBACrB,IAAI,CAAC,CAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,QAAQ,CAAA;oBAAE,OAAO;wBAClC,OAAO,EAAE,IAAI;qBACd,CAAA;gBAED,MAAM,MAAM,GAAG,EAAE,CAAA;gBAEjB,KAAK,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;oBACtB,MAAM,UAAU,GAAG,MAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,QAAQ,mDAAG,KAAK,CAAC,CAAA;oBAElD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;wBACxB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;oBACzB,CAAC;gBACH,CAAC;gBAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;oBAClB,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,KAAK,EAAE,MAAM;qBACd,CAAA;gBACH,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE,IAAI;iBACd,CAAA;YACH,CAAC,CAAuB,GAC8C,CAAC,CAAA;QA/B3E,UAAK,GAAG,MAAM,CAAA;IAgCd,CAAC;CACF;AAlCD,8BAkCC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAA2B,OAA4B;IACrF,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC"}
|
package/dist/fields/number.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
3
|
var t = {};
|
|
3
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -9,9 +10,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
10
|
}
|
|
10
11
|
return t;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.NumberField = void 0;
|
|
15
|
+
const Field_1 = require("../lib/Field");
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const validators_1 = require("../validators");
|
|
15
18
|
const MAX_VALID_DIGITS = 1000000000000000; // maximum number of digits that the input supports to perform operations
|
|
16
19
|
/**
|
|
17
20
|
* Field for numeric values. Supports both single numbers and arrays of numbers
|
|
@@ -21,15 +24,16 @@ const MAX_VALID_DIGITS = 1000000000000000; // maximum number of digits that the
|
|
|
21
24
|
* supports for arithmetic operations). Values outside the range fail
|
|
22
25
|
* validation.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
class NumberField extends Field_1.Field {
|
|
25
28
|
constructor(options) {
|
|
26
29
|
const { min = 0, max = MAX_VALID_DIGITS, defaultValue } = options, others = __rest(options, ["min", "max", "defaultValue"]);
|
|
27
30
|
const isMultiple = Array.isArray(defaultValue);
|
|
28
|
-
const zScheme = z.number().min(min).max(max);
|
|
29
|
-
super(Object.assign({ validate: zodValidator(isMultiple ? z.array(zScheme) : zScheme), min,
|
|
31
|
+
const zScheme = zod_1.z.number().min(min).max(max);
|
|
32
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(isMultiple ? zod_1.z.array(zScheme) : zScheme), min,
|
|
30
33
|
max,
|
|
31
34
|
defaultValue }, others));
|
|
32
35
|
this._type = "NUMBER";
|
|
33
36
|
}
|
|
34
37
|
}
|
|
38
|
+
exports.NumberField = NumberField;
|
|
35
39
|
//# sourceMappingURL=number.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/fields/number.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/fields/number.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAY5C,MAAM,gBAAgB,GAAG,gBAAgB,CAAA,CAAC,yEAAyE;AAEnH;;;;;;;GAOG;AACH,MAAa,WAA8C,SAAQ,aAAkC;IAGnG,YAAY,OAAqC;QAC/C,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,gBAAgB,EAAE,YAAY,KAAgB,OAAO,EAAlB,MAAM,UAAK,OAAO,EAAtE,8BAA4D,CAAU,CAAA;QAE5E,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAE9C,MAAM,OAAO,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE5C,KAAK,CAAC,gBACJ,QAAQ,EAAE,IAAA,yBAAY,EAAC,UAAU,CAAC,CAAC,CAAC,OAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAwB,EACtF,GAAG;YACH,GAAG;YACH,YAAY,IACT,MAAM,CACsB,CAAC,CAAA;QAfpC,UAAK,GAAG,QAAQ,CAAA;IAgBhB,CAAC;CACF;AAlBD,kCAkBC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectableField = void 0;
|
|
4
|
+
const Field_1 = require("../lib/Field");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const validators_1 = require("../validators");
|
|
4
7
|
/**
|
|
5
8
|
* Field for single or multi-select inputs whose options are a fixed list of
|
|
6
9
|
* string/number keys. `minItems` defaults to `1` (at least one selection
|
|
@@ -9,14 +12,15 @@ import { zodValidator } from "../validators";
|
|
|
9
12
|
* value or an array, so the same field type covers both radio-style and
|
|
10
13
|
* checkbox-style UIs.
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
class SelectableField extends Field_1.Field {
|
|
13
16
|
constructor(options) {
|
|
14
17
|
var _a;
|
|
15
18
|
const { minItems = 1, maxItems = (_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.length } = options;
|
|
16
|
-
const zScheme = z.string().or(z.number());
|
|
17
|
-
super(Object.assign({ validate: zodValidator(z.array(zScheme).min(minItems).max(maxItems).or(zScheme)), minItems,
|
|
19
|
+
const zScheme = zod_1.z.string().or(zod_1.z.number());
|
|
20
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.array(zScheme).min(minItems).max(maxItems).or(zScheme)), minItems,
|
|
18
21
|
maxItems }, options));
|
|
19
22
|
this._type = "SELECTABLE";
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
exports.SelectableField = SelectableField;
|
|
22
26
|
//# sourceMappingURL=selectable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectable.js","sourceRoot":"","sources":["../../src/fields/selectable.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"selectable.js","sourceRoot":"","sources":["../../src/fields/selectable.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAc5C;;;;;;;GAOG;AACH,MAAa,eAA0E,SAAQ,aAAkB;IAG/G,YAAY,OAA4C;;QACtD,MAAM,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,MAAM,EAAE,GAAG,OAAO,CAAA;QAErE,MAAM,OAAO,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAA;QAEzC,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,OAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAwB,EACvG,QAAQ;YACR,QAAQ,IACL,OAAO,EACV,CAAA;QAZJ,UAAK,GAAG,YAAY,CAAA;IAapB,CAAC;CACF;AAfD,0CAeC"}
|
package/dist/fields/text.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextField = void 0;
|
|
4
|
+
const Field_1 = require("../lib/Field");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const validators_1 = require("../validators");
|
|
4
7
|
/**
|
|
5
8
|
* Field for plain string values. Ships with a `z.string()` fallback validator
|
|
6
9
|
* so the field is always valid when no custom `validate` option is provided.
|
|
7
10
|
* Accepts `secure` (password masking) and `multiline` hints that are forwarded
|
|
8
11
|
* as props to the underlying input component.
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
class TextField extends Field_1.Field {
|
|
11
14
|
constructor(options) {
|
|
12
|
-
super(Object.assign({ validate: zodValidator(z.string().optional()) }, options));
|
|
15
|
+
super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.string().optional()) }, options));
|
|
13
16
|
this._type = "TEXT";
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
exports.TextField = TextField;
|
|
16
20
|
//# sourceMappingURL=text.js.map
|
package/dist/fields/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/fields/text.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/fields/text.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,6BAAuB;AAEvB,8CAA4C;AAY5C;;;;;GAKG;AACH,MAAa,SAA0C,SAAQ,aAAuB;IAGpF,YAAY,OAAmC;QAC7C,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAwB,IACjE,OAAO,EACV,CAAA;QANJ,UAAK,GAAG,MAAM,CAAA;IAOd,CAAC;CACF;AATD,8BASC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useValidate = exports.useField = void 0;
|
|
4
|
+
var useField_1 = require("./useField");
|
|
5
|
+
Object.defineProperty(exports, "useField", { enumerable: true, get: function () { return useField_1.useField; } });
|
|
6
|
+
var useValidate_1 = require("./useValidate");
|
|
7
|
+
Object.defineProperty(exports, "useValidate", { enumerable: true, get: function () { return useValidate_1.useValidate; } });
|
|
3
8
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA;AACjB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA"}
|
package/dist/hooks/useField.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useField = useField;
|
|
4
|
+
const react_1 = require("react");
|
|
2
5
|
/**
|
|
3
6
|
* Convenience hook for components that accept an optional `field` prop. When
|
|
4
7
|
* `field` is provided it is used directly; when it is absent (falsy), a
|
|
@@ -12,11 +15,11 @@ import { useMemo } from "react";
|
|
|
12
15
|
* `params` are forwarded to `field.use()` in either branch, so imperative
|
|
13
16
|
* ref bindings work regardless of which field is active.
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
function useField(field, params, defaultField) {
|
|
16
19
|
if (field) {
|
|
17
20
|
return field.use(params === null || params === void 0 ? void 0 : params[0], params === null || params === void 0 ? void 0 : params[1]);
|
|
18
21
|
}
|
|
19
|
-
const tempField = useMemo(() => {
|
|
22
|
+
const tempField = (0, react_1.useMemo)(() => {
|
|
20
23
|
return defaultField();
|
|
21
24
|
}, []);
|
|
22
25
|
return tempField.use(params[0], params === null || params === void 0 ? void 0 : params[1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.js","sourceRoot":"","sources":["../../src/hooks/useField.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useField.js","sourceRoot":"","sources":["../../src/hooks/useField.ts"],"names":[],"mappings":";;AAgBA,4BAUC;AA1BD,iCAA+B;AAG/B;;;;;;;;;;;;GAYG;AACH,SAAgB,QAAQ,CAAkC,KAAQ,EAAE,MAA4B,EAAE,YAAqB;IACrH,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,CAAyB,CAAA;IACpE,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC7B,OAAO,YAAY,EAAE,CAAA;IACvB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,CAAyB,CAAA;AACtE,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useValidate = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const Field_1 = require("../lib/Field");
|
|
3
6
|
/**
|
|
4
7
|
* Standalone validation hook for values managed outside a `Field` instance.
|
|
5
8
|
* Useful when you have a raw state value and a validator function but do not
|
|
@@ -16,18 +19,18 @@ import { ValidationError } from '../lib/Field';
|
|
|
16
19
|
* A {@link ValidationError} thrown by `providedValidate` is caught and
|
|
17
20
|
* normalised; other exceptions propagate.
|
|
18
21
|
*/
|
|
19
|
-
|
|
22
|
+
const useValidate = (value, providedValidate) => {
|
|
20
23
|
var _a, _b, _c, _d;
|
|
21
|
-
const [hasBlurred, setHasBlurred] = useState(false);
|
|
24
|
+
const [hasBlurred, setHasBlurred] = (0, react_1.useState)(false);
|
|
22
25
|
const isUnset = typeof value === 'undefined';
|
|
23
|
-
const startedUnset = useRef(isUnset).current;
|
|
24
|
-
const validate = useCallback((value) => {
|
|
26
|
+
const startedUnset = (0, react_1.useRef)(isUnset).current;
|
|
27
|
+
const validate = (0, react_1.useCallback)((value) => {
|
|
25
28
|
try {
|
|
26
29
|
const result = providedValidate === null || providedValidate === void 0 ? void 0 : providedValidate(value, {});
|
|
27
30
|
return result;
|
|
28
31
|
}
|
|
29
32
|
catch (e) {
|
|
30
|
-
if (e instanceof ValidationError) {
|
|
33
|
+
if (e instanceof Field_1.ValidationError) {
|
|
31
34
|
return {
|
|
32
35
|
isValid: false,
|
|
33
36
|
error: e.data
|
|
@@ -36,7 +39,7 @@ export const useValidate = (value, providedValidate) => {
|
|
|
36
39
|
throw e;
|
|
37
40
|
}
|
|
38
41
|
}, []);
|
|
39
|
-
const onInputBlurred = useCallback(() => {
|
|
42
|
+
const onInputBlurred = (0, react_1.useCallback)(() => {
|
|
40
43
|
setHasBlurred(true);
|
|
41
44
|
}, []);
|
|
42
45
|
const validation = validate(value);
|
|
@@ -51,4 +54,5 @@ export const useValidate = (value, providedValidate) => {
|
|
|
51
54
|
message,
|
|
52
55
|
};
|
|
53
56
|
};
|
|
57
|
+
exports.useValidate = useValidate;
|
|
54
58
|
//# sourceMappingURL=useValidate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useValidate.js","sourceRoot":"","sources":["../../src/hooks/useValidate.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"useValidate.js","sourceRoot":"","sources":["../../src/hooks/useValidate.ts"],"names":[],"mappings":";;;AAAA,iCAAqD;AAErD,wCAA8C;AAE9C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,WAAW,GAAG,CAAsC,KAAQ,EAAE,gBAAmB,EAAE,EAAE;;IAChG,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAEnD,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,WAAW,CAAA;IAE5C,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC,OAAO,CAAA;IAE5C,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAC,KAAQ,EAAE,EAAE;QACxC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,KAAK,EAAE,EAAE,CA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2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fields"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./lib"), exports);
|
|
20
|
+
__exportStar(require("./validators"), exports);
|
|
21
|
+
__exportStar(require("./hooks"), exports);
|
|
6
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,0CAAuB;AACvB,wCAAqB;AACrB,+CAA4B;AAC5B,0CAAuB"}
|
package/dist/lib/Field.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export declare class Field<T, Validate extends Validator<T, any, any>, Result =
|
|
|
90
90
|
*/
|
|
91
91
|
attach(to: FieldState<T>): void;
|
|
92
92
|
setValue(to: T): void;
|
|
93
|
-
useValue(): T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
93
|
+
useValue(): T | import("nanostores", { with: { "resolution-mode": "import" } }).StoreValue<T extends object ? import("nanostores", { with: { "resolution-mode": "import" } }).MapStore<T> : never>;
|
|
94
94
|
resetValue(): void;
|
|
95
95
|
/**
|
|
96
96
|
* Primary React hook for consuming a field inside a component. Subscribes to
|
|
@@ -115,9 +115,9 @@ export declare class Field<T, Validate extends Validator<T, any, any>, Result =
|
|
|
115
115
|
showError: boolean;
|
|
116
116
|
isUnset: boolean;
|
|
117
117
|
validation: ValidationResult<Result, Err>;
|
|
118
|
-
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
118
|
+
value: T | import("nanostores", { with: { "resolution-mode": "import" } }).StoreValue<T extends object ? import("nanostores", { with: { "resolution-mode": "import" } }).MapStore<T> : never>;
|
|
119
119
|
};
|
|
120
|
-
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
120
|
+
value: T | import("nanostores", { with: { "resolution-mode": "import" } }).StoreValue<T extends object ? import("nanostores", { with: { "resolution-mode": "import" } }).MapStore<T> : never>;
|
|
121
121
|
setValue: (to: T) => void;
|
|
122
122
|
changed: boolean;
|
|
123
123
|
representation: any;
|
|
@@ -161,7 +161,7 @@ export declare class Field<T, Validate extends Validator<T, any, any>, Result =
|
|
|
161
161
|
showError: boolean;
|
|
162
162
|
isUnset: boolean;
|
|
163
163
|
validation: ValidationResult<Result, Err>;
|
|
164
|
-
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
164
|
+
value: T | import("nanostores", { with: { "resolution-mode": "import" } }).StoreValue<T extends object ? import("nanostores", { with: { "resolution-mode": "import" } }).MapStore<T> : never>;
|
|
165
165
|
};
|
|
166
166
|
log(level?: string, ...args: any[]): void;
|
|
167
167
|
toInternalValue(v: any): T;
|
package/dist/lib/Field.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = exports.ValidationError = void 0;
|
|
4
|
+
const nanostores_1 = require("nanostores");
|
|
5
|
+
const types_1 = require("@codeleap/types");
|
|
6
|
+
const react_1 = require("@nanostores/react");
|
|
7
|
+
const useFieldBinding_1 = require("./useFieldBinding");
|
|
8
|
+
const react_2 = require("react");
|
|
9
|
+
const logger_1 = require("@codeleap/logger");
|
|
7
10
|
/**
|
|
8
11
|
* Thrown inside a validator function to signal a structured validation failure
|
|
9
12
|
* without propagating as an unhandled exception. The `data` payload is forwarded
|
|
@@ -12,12 +15,13 @@ import { logger } from '@codeleap/logger';
|
|
|
12
15
|
* Throw this instead of returning `{ isValid: false }` when you need to exit
|
|
13
16
|
* validation from a nested helper that cannot easily return a value.
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
class ValidationError extends Error {
|
|
16
19
|
constructor(data) {
|
|
17
20
|
super();
|
|
18
21
|
this.data = data;
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
exports.ValidationError = ValidationError;
|
|
21
25
|
/**
|
|
22
26
|
* Base class for all form fields. Owns the nanostores atom that holds the
|
|
23
27
|
* field's current value, runs synchronous validation on demand, and exposes
|
|
@@ -49,7 +53,7 @@ export class ValidationError extends Error {
|
|
|
49
53
|
* in insertion order. Transformers are global and shared across all field
|
|
50
54
|
* instances via `Field.transformers`.
|
|
51
55
|
*/
|
|
52
|
-
|
|
56
|
+
class Field {
|
|
53
57
|
/**
|
|
54
58
|
* Marks the field's error as visible. Typically called by `Form.validate`
|
|
55
59
|
* when `revealErrors: true` is passed, or imperatively after a failed submit.
|
|
@@ -73,9 +77,9 @@ export class Field {
|
|
|
73
77
|
constructor(options) {
|
|
74
78
|
this.properties = {};
|
|
75
79
|
this.options = options;
|
|
76
|
-
this.ref = createRef();
|
|
80
|
+
this.ref = (0, react_2.createRef)();
|
|
77
81
|
this.loadState();
|
|
78
|
-
this.errorRevealed = atom(false);
|
|
82
|
+
this.errorRevealed = (0, nanostores_1.atom)(false);
|
|
79
83
|
this.setValue = this.setValue.bind(this);
|
|
80
84
|
this.use = this.use.bind(this);
|
|
81
85
|
this.useBinding = this.useBinding.bind(this);
|
|
@@ -115,7 +119,7 @@ export class Field {
|
|
|
115
119
|
return this.state.set(to);
|
|
116
120
|
}
|
|
117
121
|
useValue() {
|
|
118
|
-
const value = useStore(this.state);
|
|
122
|
+
const value = (0, react_1.useStore)(this.state);
|
|
119
123
|
return value;
|
|
120
124
|
}
|
|
121
125
|
resetValue() {
|
|
@@ -150,7 +154,7 @@ export class Field {
|
|
|
150
154
|
};
|
|
151
155
|
}
|
|
152
156
|
useBinding(...args) {
|
|
153
|
-
useFieldBinding(this.ref, ...args);
|
|
157
|
+
(0, useFieldBinding_1.useFieldBinding)(this.ref, ...args);
|
|
154
158
|
}
|
|
155
159
|
changed() {
|
|
156
160
|
return this.state.get() != this.initialValue;
|
|
@@ -160,9 +164,9 @@ export class Field {
|
|
|
160
164
|
var _a, _b, _c;
|
|
161
165
|
let defaultValuePromise = undefined;
|
|
162
166
|
let defaultValue = undefined;
|
|
163
|
-
if (TypeGuards.isFunction(this.options.defaultValue)) {
|
|
167
|
+
if (types_1.TypeGuards.isFunction(this.options.defaultValue)) {
|
|
164
168
|
const v = this.options.defaultValue();
|
|
165
|
-
if (TypeGuards.isPromise(v)) {
|
|
169
|
+
if (types_1.TypeGuards.isPromise(v)) {
|
|
166
170
|
defaultValuePromise = v;
|
|
167
171
|
}
|
|
168
172
|
else {
|
|
@@ -171,14 +175,14 @@ export class Field {
|
|
|
171
175
|
}
|
|
172
176
|
else {
|
|
173
177
|
const v = (_a = this.options) === null || _a === void 0 ? void 0 : _a.defaultValue;
|
|
174
|
-
if (TypeGuards.isPromise(v)) {
|
|
178
|
+
if (types_1.TypeGuards.isPromise(v)) {
|
|
175
179
|
defaultValuePromise = v;
|
|
176
180
|
}
|
|
177
181
|
else {
|
|
178
182
|
defaultValue = v;
|
|
179
183
|
}
|
|
180
184
|
}
|
|
181
|
-
this.state = (_c = (_b = this === null || this === void 0 ? void 0 : this.options) === null || _b === void 0 ? void 0 : _b.state) !== null && _c !== void 0 ? _c : atom(defaultValue);
|
|
185
|
+
this.state = (_c = (_b = this === null || this === void 0 ? void 0 : this.options) === null || _b === void 0 ? void 0 : _b.state) !== null && _c !== void 0 ? _c : (0, nanostores_1.atom)(defaultValue);
|
|
182
186
|
if (!defaultValuePromise) {
|
|
183
187
|
this.initialValue = defaultValue;
|
|
184
188
|
}
|
|
@@ -201,7 +205,7 @@ export class Field {
|
|
|
201
205
|
formatLog(...args) {
|
|
202
206
|
const [firstArgument, ...otherArgs] = args;
|
|
203
207
|
let PREFIX = `(FIELD: ${this.name})`;
|
|
204
|
-
if (TypeGuards.isString(firstArgument)) {
|
|
208
|
+
if (types_1.TypeGuards.isString(firstArgument)) {
|
|
205
209
|
PREFIX += ` ${firstArgument}`;
|
|
206
210
|
}
|
|
207
211
|
else {
|
|
@@ -224,7 +228,7 @@ export class Field {
|
|
|
224
228
|
*/
|
|
225
229
|
validate(value) {
|
|
226
230
|
const validate = this.options.validate;
|
|
227
|
-
const valueToCheck = TypeGuards.isUndefined(value) ? this.state.get() : this.toInternalValue(value);
|
|
231
|
+
const valueToCheck = types_1.TypeGuards.isUndefined(value) ? this.state.get() : this.toInternalValue(value);
|
|
228
232
|
try {
|
|
229
233
|
const result = validate(valueToCheck, {});
|
|
230
234
|
return result;
|
|
@@ -254,9 +258,9 @@ export class Field {
|
|
|
254
258
|
useValidation() {
|
|
255
259
|
var _a, _b;
|
|
256
260
|
const value = this.useValue();
|
|
257
|
-
const revealed = useStore(this.errorRevealed);
|
|
261
|
+
const revealed = (0, react_1.useStore)(this.errorRevealed);
|
|
258
262
|
const isUnset = typeof value === 'undefined';
|
|
259
|
-
const startedUnset = useRef(isUnset).current;
|
|
263
|
+
const startedUnset = (0, react_2.useRef)(isUnset).current;
|
|
260
264
|
const isSet = !isUnset;
|
|
261
265
|
const validation = this.validate(value);
|
|
262
266
|
const isValid = validation.isValid;
|
|
@@ -264,7 +268,7 @@ export class Field {
|
|
|
264
268
|
const hasChanged = this.initialValue != value;
|
|
265
269
|
const message = (_a = validation.readableError) !== null && _a !== void 0 ? _a : (Array.isArray(validation.error) ? (_b = validation.error[0]) === null || _b === void 0 ? void 0 : _b.message : undefined);
|
|
266
270
|
const errorDisplayRequiresBlur = startedUnset;
|
|
267
|
-
const [hasBlurred, setHasBlurred] = useState(false);
|
|
271
|
+
const [hasBlurred, setHasBlurred] = (0, react_2.useState)(false);
|
|
268
272
|
const showError = isInvalid && (errorDisplayRequiresBlur ? revealed || hasBlurred : true);
|
|
269
273
|
return {
|
|
270
274
|
onInputBlurred() {
|
|
@@ -285,7 +289,7 @@ export class Field {
|
|
|
285
289
|
}
|
|
286
290
|
log(level = 'log', ...args) {
|
|
287
291
|
if (Field.enableLogs)
|
|
288
|
-
logger[level](...this.formatLog(...args));
|
|
292
|
+
logger_1.logger[level](...this.formatLog(...args));
|
|
289
293
|
}
|
|
290
294
|
toInternalValue(v) {
|
|
291
295
|
return v;
|
|
@@ -329,6 +333,7 @@ export class Field {
|
|
|
329
333
|
return Field.methodGetPadding(this);
|
|
330
334
|
}
|
|
331
335
|
}
|
|
336
|
+
exports.Field = Field;
|
|
332
337
|
Field.transformers = new Map();
|
|
333
338
|
Field.enableLogs = false;
|
|
334
339
|
Field.getProps = (field) => {
|
package/dist/lib/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../src/lib/Field.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../src/lib/Field.ts"],"names":[],"mappings":";;;AAGA,2CAAsD;AACtD,2CAA+E;AAE/E,6CAA4C;AAC5C,uDAAoD;AACpD,iCAAoD;AACpD,6CAA0C;AAE1C;;;;;;;GAOG;AACH,MAAa,eAAgB,SAA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,CAAC,AAFc,CAEd;AAEM,2BAAqB,GAAG,CAAC,KAAqB,EAAE,UAAe,EAA+B,EAAE;IACrG,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;AAC1D,CAAC,AAF2B,CAE3B;AAEM,oBAAc,GAAG,CAAC,KAAqB,EAAE,SAAc,EAAE,OAA2B,EAAiB,EAAE;IAC5G,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;AACnD,CAAC,AAFoB,CAEpB;AAEM,sBAAgB,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC1D,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;AACrD,CAAC,AAFsB,CAEtB"}
|
package/dist/lib/Form.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ declare class Form<T extends FormDef> {
|
|
|
34
34
|
get isChanged(): boolean;
|
|
35
35
|
changed(): boolean;
|
|
36
36
|
get isValid(): boolean;
|
|
37
|
-
slice<K extends FieldPaths<T>>(field: K): import("nanostores").WritableAtom<unknown>;
|
|
37
|
+
slice<K extends FieldPaths<T>>(field: K): import("nanostores", { with: { "resolution-mode": "import" } }).WritableAtom<unknown>;
|
|
38
38
|
iterFields<V>(cb: (field: FieldTuples<T>, index: number) => V): V[];
|
|
39
39
|
/**
|
|
40
40
|
* Bulk-sets field values from a partial record. Boolean fields require an
|
|
@@ -62,7 +62,7 @@ declare class Form<T extends FormDef> {
|
|
|
62
62
|
* the field key does not exist in this form's shape, making typos a runtime
|
|
63
63
|
* error rather than a silent no-op.
|
|
64
64
|
*/
|
|
65
|
-
register(field: FieldPaths<T>): import("
|
|
65
|
+
register(field: FieldPaths<T>): import("../types").IFieldProps;
|
|
66
66
|
use<Selected>(selector: FormSelector<T, Selected>): Selected;
|
|
67
67
|
useReset(): void;
|
|
68
68
|
useShared<Selected>(selector: FormSelector<T, Selected>): Selected;
|
package/dist/lib/Form.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useForm = useForm;
|
|
4
|
+
exports.form = form;
|
|
5
|
+
const store_1 = require("@codeleap/store");
|
|
6
|
+
const types_1 = require("@codeleap/types");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const hooks_1 = require("@codeleap/hooks");
|
|
5
9
|
function buildState(def) {
|
|
6
10
|
const stateArg = {};
|
|
7
11
|
for (const [name, field] of Object.entries(def)) {
|
|
@@ -37,7 +41,7 @@ class Form {
|
|
|
37
41
|
constructor(id, shape) {
|
|
38
42
|
this.id = id;
|
|
39
43
|
this.fields = shape;
|
|
40
|
-
this.state = globalState(buildState(this.fields));
|
|
44
|
+
this.state = (0, store_1.globalState)(buildState(this.fields));
|
|
41
45
|
this.attachState();
|
|
42
46
|
this.use = this.use.bind(this);
|
|
43
47
|
this.useShared = this.useShared.bind(this);
|
|
@@ -61,7 +65,7 @@ class Form {
|
|
|
61
65
|
return Object.values(res).every((result) => result.isValid);
|
|
62
66
|
}
|
|
63
67
|
slice(field) {
|
|
64
|
-
const fieldSlice = createStateSlice(this.state, (v) => v[field], (value) => {
|
|
68
|
+
const fieldSlice = (0, store_1.createStateSlice)(this.state, (v) => v[field], (value) => {
|
|
65
69
|
return {
|
|
66
70
|
[field]: value
|
|
67
71
|
};
|
|
@@ -86,7 +90,7 @@ class Form {
|
|
|
86
90
|
setValues(values) {
|
|
87
91
|
this.iterFields(([name, field]) => {
|
|
88
92
|
const value = values === null || values === void 0 ? void 0 : values[name];
|
|
89
|
-
if (field._type === 'BOOLEAN' && TypeGuards.isBoolean(value))
|
|
93
|
+
if (field._type === 'BOOLEAN' && types_1.TypeGuards.isBoolean(value))
|
|
90
94
|
field.setValue(value);
|
|
91
95
|
else if (value)
|
|
92
96
|
field.setValue(value);
|
|
@@ -126,7 +130,7 @@ class Form {
|
|
|
126
130
|
return null;
|
|
127
131
|
return [name, field.validate()];
|
|
128
132
|
});
|
|
129
|
-
const resultMap = Object.fromEntries(results.filter((v) => !TypeGuards.isNil(v)));
|
|
133
|
+
const resultMap = Object.fromEntries(results.filter((v) => !types_1.TypeGuards.isNil(v)));
|
|
130
134
|
if (revealErrors) {
|
|
131
135
|
this.iterFields(([_, field]) => {
|
|
132
136
|
field.revealError();
|
|
@@ -151,16 +155,16 @@ class Form {
|
|
|
151
155
|
return value;
|
|
152
156
|
}
|
|
153
157
|
useReset() {
|
|
154
|
-
useUnmount(() => {
|
|
158
|
+
(0, hooks_1.useUnmount)(() => {
|
|
155
159
|
this.resetValues();
|
|
156
160
|
});
|
|
157
161
|
}
|
|
158
162
|
useShared(selector) {
|
|
159
|
-
const [selected, setSelected] = useState(() => selector(this));
|
|
160
|
-
const reselect = useCallback(() => {
|
|
163
|
+
const [selected, setSelected] = (0, react_1.useState)(() => selector(this));
|
|
164
|
+
const reselect = (0, react_1.useCallback)(() => {
|
|
161
165
|
setSelected(selector(this));
|
|
162
166
|
}, [selector]);
|
|
163
|
-
useEffect(() => {
|
|
167
|
+
(0, react_1.useEffect)(() => {
|
|
164
168
|
return this.state.listen((value, previous) => {
|
|
165
169
|
if (value != previous) {
|
|
166
170
|
reselect();
|
|
@@ -179,8 +183,8 @@ class Form {
|
|
|
179
183
|
* Note: `def` is only read on the first render — changing it after mount has
|
|
180
184
|
* no effect.
|
|
181
185
|
*/
|
|
182
|
-
|
|
183
|
-
const form = useMemo(() => {
|
|
186
|
+
function useForm(name, def) {
|
|
187
|
+
const form = (0, react_1.useMemo)(() => {
|
|
184
188
|
return new Form(name, def);
|
|
185
189
|
}, [name]);
|
|
186
190
|
return form;
|
|
@@ -191,7 +195,7 @@ export function useForm(name, def) {
|
|
|
191
195
|
* any individual component. Values are **not** automatically reset on unmount;
|
|
192
196
|
* call `resetValues()` explicitly when needed.
|
|
193
197
|
*/
|
|
194
|
-
|
|
198
|
+
function form(...args) {
|
|
195
199
|
return new Form(...args);
|
|
196
200
|
}
|
|
197
201
|
//# sourceMappingURL=Form.js.map
|
package/dist/lib/Form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/lib/Form.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/lib/Form.ts"],"names":[],"mappings":";;AAwPA,0BAOC;AAQD,oBAEC;AAzQD,2CAA4E;AAC5E,2CAA4C;AAC5C,iCAA0G;AAE1G,2CAA4C;AAK5C,SAAS,UAAU,CAAoB,GAAM;IAC3C,MAAM,QAAQ,GAA4B,EAAE,CAAA;IAE5C,KAAI,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;IAC9B,CAAC;IAED,OAAO,QAAyB,CAAA;AAClC,CAAC;AAOD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,IAAI;IAMR,YAAY,EAAU,EAAE,KAAQ;QAC9B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QAEnB,IAAI,CAAC,KAAK,GAAG,IAAA,mBAAW,EACtB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CACxB,CAAA;QAED,IAAI,CAAC,WAAW,EAAE,CAAA;QAClB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAA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"}
|
package/dist/lib/factories.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldFactory = fieldFactory;
|
|
1
4
|
/**
|
|
2
5
|
* Wraps a `Field` subclass constructor in a factory function, eliminating the
|
|
3
6
|
* need to call `new` at the call site and improving inference of the
|
|
@@ -6,7 +9,7 @@
|
|
|
6
9
|
*
|
|
7
10
|
* All entries in the `fields` namespace are built with this helper.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
function fieldFactory(cls) {
|
|
10
13
|
return (options) => {
|
|
11
14
|
// @ts-expect-error
|
|
12
15
|
return new cls(options !== null && options !== void 0 ? options : {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../src/lib/factories.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../src/lib/factories.tsx"],"names":[],"mappings":";;AAcA,oCAUC;AAlBD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAI1B,GAAM;IACN,OAAO,CAAwC,OAAW,EAAgC,EAAE;QAE1F,mBAAmB;QACnB,OAAO,IAAI,GAAG,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAA;IAC/B,CAAC,CAAA;AACH,CAAC"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Field = void 0;
|
|
18
|
+
__exportStar(require("./Form"), exports);
|
|
19
|
+
var Field_1 = require("./Field");
|
|
20
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return Field_1.Field; } });
|
|
3
21
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,iCAA6B;AAArB,8FAAA,KAAK,OAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,7 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useFieldBinding = useFieldBinding;
|
|
13
|
+
const react_1 = require("react");
|
|
11
14
|
/**
|
|
12
15
|
* Attaches an imperative handle to `ref` via `useImperativeHandle`. Every
|
|
13
16
|
* method in {@link IFieldRef} is given a default implementation that throws
|
|
@@ -19,11 +22,11 @@ import { useImperativeHandle } from "react";
|
|
|
19
22
|
* `deps` is forwarded directly to `useImperativeHandle`; include anything
|
|
20
23
|
* `impl` closes over that can change between renders.
|
|
21
24
|
*/
|
|
22
|
-
|
|
25
|
+
function useFieldBinding(ref, impl, deps = []) {
|
|
23
26
|
const notImplemented = (method) => {
|
|
24
27
|
throw new Error(`ref.${method} not implemented`);
|
|
25
28
|
};
|
|
26
|
-
useImperativeHandle(ref, () => (Object.assign({ blur: () => {
|
|
29
|
+
(0, react_1.useImperativeHandle)(ref, () => (Object.assign({ blur: () => {
|
|
27
30
|
notImplemented('blur');
|
|
28
31
|
}, emit: () => {
|
|
29
32
|
notImplemented('emit');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldBinding.js","sourceRoot":"","sources":["../../src/lib/useFieldBinding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFieldBinding.js","sourceRoot":"","sources":["../../src/lib/useFieldBinding.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,0CAoCC;AAlDD,iCAA2C;AAG3C;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAAI,GAA+C,EAAE,IAA2B,EAAE,OAA6B,EAAE;IAE9I,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE;QACxC,MAAM,IAAI,KAAK,CAAC,OAAO,MAAM,kBAAkB,CAAC,CAAA;IAClD,CAAC,CAAA;IAGD,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAI,EAAE,CAAC,iBAC9B,IAAI,EAAE,GAAG,EAAE;YACT,cAAc,CAAC,MAAM,CAAC,CAAA;QACxB,CAAC,EACD,IAAI,EAAE,GAAG,EAAE;YACT,cAAc,CAAC,MAAM,CAAC,CAAA;QACxB,CAAC,EACD,KAAK,EAAE,GAAG,EAAE;YACV,cAAc,CAAC,OAAO,CAAC,CAAA;QACzB,CAAC;QACD,mBAAmB;QACnB,QAAQ,EAAE,GAAG,EAAE;YACb,cAAc,CAAC,UAAU,CAAC,CAAA;QAC5B,CAAC,EACD,cAAc,EAAE,GAAS,EAAE;YACzB,cAAc,CAAC,gBAAgB,CAAC,CAAA;QAClC,CAAC,CAAA,EACD,SAAS;YACP,cAAc,CAAC,WAAW,CAAC,CAAA;QAC7B,CAAC;QACD,WAAW;YACT,cAAc,CAAC,aAAa,CAAC,CAAA;QAC/B,CAAC;QACD,qBAAqB;YACnB,cAAc,CAAC,uBAAuB,CAAC,CAAA;QACzC,CAAC,IACE,IAAI,EACP,EAAE,IAAI,CAAC,CAAA;AAEX,CAAC"}
|
package/dist/types/field.js
CHANGED
package/dist/types/form.js
CHANGED
package/dist/types/globals.js
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/validation.js
CHANGED
package/dist/validators/index.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zod"), exports);
|
|
2
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB"}
|
package/dist/validators/zod.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodValidator = zodValidator;
|
|
4
|
+
exports.isZodValidationResult = isZodValidationResult;
|
|
5
|
+
const types_1 = require("@codeleap/types");
|
|
2
6
|
/**
|
|
3
7
|
* Adapts a Zod schema into the `Validator` contract expected by `Field` and
|
|
4
8
|
* `useValidate`. Uses `safeParse` internally so Zod errors are captured as
|
|
@@ -7,7 +11,7 @@ import { TypeGuards } from '@codeleap/types';
|
|
|
7
11
|
* The returned function is synchronous — async Zod schemas (`z.promise`,
|
|
8
12
|
* `.parseAsync`) are not supported.
|
|
9
13
|
*/
|
|
10
|
-
|
|
14
|
+
function zodValidator(model) {
|
|
11
15
|
return (value) => {
|
|
12
16
|
var _a;
|
|
13
17
|
const result = model.safeParse(value);
|
|
@@ -28,11 +32,11 @@ const isZodIssue = (val) => {
|
|
|
28
32
|
* distinguish Zod results from results produced by custom validators when
|
|
29
33
|
* handling errors generically.
|
|
30
34
|
*/
|
|
31
|
-
|
|
32
|
-
const isValidABoolean = TypeGuards.isBoolean(val.isValid);
|
|
35
|
+
function isZodValidationResult(val) {
|
|
36
|
+
const isValidABoolean = types_1.TypeGuards.isBoolean(val.isValid);
|
|
33
37
|
if (isValidABoolean) {
|
|
34
38
|
if (!val.isValid) {
|
|
35
|
-
return TypeGuards.isArray(val.error) && val.error.every(isZodIssue);
|
|
39
|
+
return types_1.TypeGuards.isArray(val.error) && val.error.every(isZodIssue);
|
|
36
40
|
}
|
|
37
41
|
else {
|
|
38
42
|
return 'result' in val;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/validators/zod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/validators/zod.ts"],"names":[],"mappings":";;AAcA,oCAUC;AAcD,sDAaC;AAjDD,2CAA4C;AAI5C;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAsB,KAAQ;IACxD,OAAO,CAAC,KAAc,EAA0B,EAAE;;QAChD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAErC,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAA,MAAM,CAAC,KAAK,0CAAE,MAAM;YAC3B,MAAM,EAAE,MAAM,CAAC,IAAI;SACpB,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AAGD,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAmB,EAAE;IAC/C,OAAO,CAAC,MAAM,EAAC,UAAU,EAAC,UAAU,EAAC,MAAM,EAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAA;AAC7E,CAAC,CAAA;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,GAAQ;IAC5C,MAAM,eAAe,GAAG,kBAAU,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEzD,IAAG,eAAe,EAAE,CAAC;QACnB,IAAG,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,OAAO,kBAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QACrE,CAAC;aAAM,CAAC;YACN,OAAO,QAAQ,IAAI,GAAG,CAAA;QACxB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AAEd,CAAC"}
|