@codeleap/form 7.0.0 → 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.
Files changed (54) hide show
  1. package/dist/fields/bool.js +19 -0
  2. package/dist/fields/bool.js.map +1 -0
  3. package/dist/fields/date.js +63 -0
  4. package/dist/fields/date.js.map +1 -0
  5. package/dist/fields/file.js +20 -0
  6. package/dist/fields/file.js.map +1 -0
  7. package/dist/fields/group.js +20 -0
  8. package/dist/fields/group.js.map +1 -0
  9. package/dist/fields/index.d.ts +3 -3
  10. package/dist/fields/index.js +42 -0
  11. package/dist/fields/index.js.map +1 -0
  12. package/dist/fields/list.js +55 -0
  13. package/dist/fields/list.js.map +1 -0
  14. package/dist/fields/number.js +39 -0
  15. package/dist/fields/number.js.map +1 -0
  16. package/dist/fields/selectable.js +26 -0
  17. package/dist/fields/selectable.js.map +1 -0
  18. package/dist/fields/text.js +20 -0
  19. package/dist/fields/text.js.map +1 -0
  20. package/dist/hooks/index.js +8 -0
  21. package/dist/hooks/index.js.map +1 -0
  22. package/dist/hooks/useField.js +27 -0
  23. package/dist/hooks/useField.js.map +1 -0
  24. package/dist/hooks/useValidate.js +58 -0
  25. package/dist/hooks/useValidate.js.map +1 -0
  26. package/dist/index.js +22 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/lib/Field.d.ts +4 -4
  29. package/dist/lib/Field.js +351 -0
  30. package/dist/lib/Field.js.map +1 -0
  31. package/dist/lib/Form.d.ts +2 -2
  32. package/dist/lib/Form.js +201 -0
  33. package/dist/lib/Form.js.map +1 -0
  34. package/dist/lib/factories.js +18 -0
  35. package/dist/lib/factories.js.map +1 -0
  36. package/dist/lib/index.js +21 -0
  37. package/dist/lib/index.js.map +1 -0
  38. package/dist/lib/useFieldBinding.js +51 -0
  39. package/dist/lib/useFieldBinding.js.map +1 -0
  40. package/dist/types/field.js +3 -0
  41. package/dist/types/field.js.map +1 -0
  42. package/dist/types/form.js +3 -0
  43. package/dist/types/form.js.map +1 -0
  44. package/dist/types/globals.js +3 -0
  45. package/dist/types/globals.js.map +1 -0
  46. package/dist/types/index.js +3 -0
  47. package/dist/types/index.js.map +1 -0
  48. package/dist/types/validation.js +3 -0
  49. package/dist/types/validation.js.map +1 -0
  50. package/dist/validators/index.js +18 -0
  51. package/dist/validators/index.js.map +1 -0
  52. package/dist/validators/zod.js +47 -0
  53. package/dist/validators/zod.js.map +1 -0
  54. package/package.json +10 -10
@@ -0,0 +1,19 @@
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");
7
+ /**
8
+ * Field for boolean values (checkboxes, toggles). `Form.setValues` treats
9
+ * this field specially: it will only set a value when the incoming value is
10
+ * strictly `boolean`, because falsy coercion would prevent setting `false`.
11
+ */
12
+ class BooleanField extends Field_1.Field {
13
+ constructor(options) {
14
+ super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.boolean()) }, options));
15
+ this._type = "BOOLEAN";
16
+ }
17
+ }
18
+ exports.BooleanField = BooleanField;
19
+ //# sourceMappingURL=bool.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
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"));
22
+ function normalizeToDate(val) {
23
+ if (!val)
24
+ return undefined;
25
+ if (val instanceof Date)
26
+ return val;
27
+ if (dayjs_1.default.isDayjs(val))
28
+ return val.startOf('day').toDate();
29
+ if (typeof val === 'string') {
30
+ const parsed = (0, dayjs_1.default)(val);
31
+ return parsed.isValid() ? parsed.startOf('day').toDate() : undefined;
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Field for `Date` values with optional `minimumDate` / `maximumDate` bounds.
37
+ * The built-in validator normalises the raw input via `dayjs` before running
38
+ * boundary checks, so it transparently accepts `Date` objects, dayjs instances,
39
+ * and ISO date strings. Invalid or unparseable values are normalised to
40
+ * `undefined`, which fails the `z.date()` check. Bounds are enforced at the
41
+ * start of the day (`startOf('day')`) for dayjs inputs.
42
+ */
43
+ class DateField extends Field_1.Field {
44
+ constructor(options) {
45
+ const { minimumDate, maximumDate } = options, rest = __rest(options, ["minimumDate", "maximumDate"]);
46
+ const schema = zod_1.z.preprocess((val) => {
47
+ const normalized = normalizeToDate(val);
48
+ if (!normalized || isNaN(normalized.getTime()))
49
+ return undefined;
50
+ return normalized;
51
+ }, zod_1.z.date()
52
+ .refine(d => !minimumDate || d >= minimumDate, {
53
+ message: `Date must be on or after ${minimumDate === null || minimumDate === void 0 ? void 0 : minimumDate.toDateString()}`,
54
+ })
55
+ .refine(d => !maximumDate || d <= maximumDate, {
56
+ message: `Date must be on or before ${maximumDate === null || maximumDate === void 0 ? void 0 : maximumDate.toDateString()}`,
57
+ }));
58
+ super(Object.assign({ validate: (0, validators_1.zodValidator)(schema) }, options));
59
+ this._type = "DATE";
60
+ }
61
+ }
62
+ exports.DateField = DateField;
63
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
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,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAA;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAA,eAAK,EAAC,GAAG,CAAC,CAAA;QACzB,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IACtE,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAa,SAA0C,SAAQ,aAAqB;IAGlF,YAAY,OAAmC;QAC7C,MAAM,EAAE,WAAW,EAAE,WAAW,KAAc,OAAO,EAAhB,IAAI,UAAK,OAAO,EAA/C,8BAAqC,CAAU,CAAA;QAErD,MAAM,MAAM,GAAG,OAAC,CAAC,UAAU,CAAC,CAAC,GAAY,EAAE,EAAE;YAC3C,MAAM,UAAU,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;YAEvC,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBAAE,OAAO,SAAS,CAAA;YAChE,OAAO,UAAU,CAAA;QACnB,CAAC,EAAE,OAAC,CAAC,IAAI,EAAE;aACR,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,WAAW,IAAI,CAAC,IAAI,WAAW,EAAE;YAC7C,OAAO,EAAE,4BAA4B,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,YAAY,EAAE,EAAE;SACnE,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,WAAW,IAAI,CAAC,IAAI,WAAW,EAAE;YAC7C,OAAO,EAAE,6BAA6B,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,YAAY,EAAE,EAAE;SACpE,CAAC,CACH,CAAA;QAED,KAAK,iBACH,QAAQ,EAAE,IAAA,yBAAY,EAAC,MAAM,CAAwB,IAClD,OAAO,EACV,CAAA;QAtBJ,UAAK,GAAG,MAAM,CAAA;IAuBd,CAAC;CACF;AAzBD,8BAyBC"}
@@ -0,0 +1,20 @@
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");
7
+ /**
8
+ * Field for file uploads. The value type is `any` because the shape of a
9
+ * "file" differs between web (`File` / `FileList`) and React Native (asset
10
+ * descriptor objects). Supply a custom `validate` function to enforce whatever
11
+ * shape your platform produces.
12
+ */
13
+ class FileField extends Field_1.Field {
14
+ constructor(options) {
15
+ super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.any()) }, options));
16
+ this._type = "FILE";
17
+ }
18
+ }
19
+ exports.FileField = FileField;
20
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,20 @@
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");
7
+ /**
8
+ * Field that represents a selected group or category, stored as a string key.
9
+ * Structurally identical to `TextField` but carries the `"group"` type tag so
10
+ * platform renderers can distinguish it and render a group-picker control
11
+ * instead of a free-text input.
12
+ */
13
+ class GroupField extends Field_1.Field {
14
+ constructor(options) {
15
+ super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.string()) }, options));
16
+ this._type = "group";
17
+ }
18
+ }
19
+ exports.GroupField = GroupField;
20
+ //# sourceMappingURL=group.js.map
@@ -0,0 +1 @@
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"}
@@ -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;
@@ -0,0 +1,42 @@
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; } });
19
+ /**
20
+ * Convenience namespace that exposes factory functions for every built-in field
21
+ * type. Prefer these over calling constructors directly — they provide better
22
+ * generic inference for the `validate` option.
23
+ *
24
+ * ```ts
25
+ * const emailField = fields.text({ validate: zodValidator(z.string().email()) })
26
+ * const tagsField = fields.list({ item: fields.text(), defaultValue: [] })
27
+ * ```
28
+ *
29
+ * Note: `fields.list` is the only entry that is not wrapped with
30
+ * `fieldFactory`, because `ListField` requires the `item` option's type to be
31
+ * inferred at the call site.
32
+ */
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),
41
+ };
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,55 @@
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");
6
+ /**
7
+ * Field that holds an array of values, each validated by a delegate `item`
8
+ * field. The built-in validator iterates every element through
9
+ * `options.item.validate` and collects all failures into an error array. The
10
+ * list is considered valid only when every element passes. If `item` has no
11
+ * validator, the list is always valid.
12
+ *
13
+ * The `item` field acts as a prototype — it is not mounted independently and
14
+ * does not own its own atom. Do not call `use()` on it directly.
15
+ */
16
+ class ListField extends Field_1.Field {
17
+ constructor(options) {
18
+ super(Object.assign(Object.assign({}, options), { validate: ((v, form) => {
19
+ var _a, _b, _c;
20
+ if (!((_a = options.item) === null || _a === void 0 ? void 0 : _a.validate))
21
+ return {
22
+ isValid: true
23
+ };
24
+ const errors = [];
25
+ for (const value of v) {
26
+ const validation = (_c = (_b = options.item) === null || _b === void 0 ? void 0 : _b.validate) === null || _c === void 0 ? void 0 : _c.call(_b, value);
27
+ if (!validation.isValid) {
28
+ errors.push(validation);
29
+ }
30
+ }
31
+ if (errors.length) {
32
+ return {
33
+ isValid: false,
34
+ error: errors,
35
+ };
36
+ }
37
+ return {
38
+ isValid: true,
39
+ };
40
+ }) }));
41
+ this._type = "LIST";
42
+ }
43
+ }
44
+ exports.ListField = ListField;
45
+ /**
46
+ * Convenience factory for `ListField`. Unlike `fieldFactory`-based helpers,
47
+ * `ListField` requires an `item` option whose generic type must be inferred at
48
+ * the call site, so it cannot share the same factory wrapper. This function
49
+ * exists to provide a consistent `fields.list(...)` call signature alongside
50
+ * the other entries in the `fields` namespace.
51
+ */
52
+ function listFieldFactory(options) {
53
+ return new ListField(options);
54
+ }
55
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
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");
18
+ const MAX_VALID_DIGITS = 1000000000000000; // maximum number of digits that the input supports to perform operations
19
+ /**
20
+ * Field for numeric values. Supports both single numbers and arrays of numbers
21
+ * (range / multi-handle sliders) — the mode is inferred from whether
22
+ * `defaultValue` is an array. `min` defaults to `0` and `max` defaults to
23
+ * `1_000_000_000_000_000` (the maximum safe integer range the underlying input
24
+ * supports for arithmetic operations). Values outside the range fail
25
+ * validation.
26
+ */
27
+ class NumberField extends Field_1.Field {
28
+ constructor(options) {
29
+ const { min = 0, max = MAX_VALID_DIGITS, defaultValue } = options, others = __rest(options, ["min", "max", "defaultValue"]);
30
+ const isMultiple = Array.isArray(defaultValue);
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,
33
+ max,
34
+ defaultValue }, others));
35
+ this._type = "NUMBER";
36
+ }
37
+ }
38
+ exports.NumberField = NumberField;
39
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,26 @@
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");
7
+ /**
8
+ * Field for single or multi-select inputs whose options are a fixed list of
9
+ * string/number keys. `minItems` defaults to `1` (at least one selection
10
+ * required) and `maxItems` defaults to the length of the provided `options`
11
+ * array (all items selectable). The built-in validator accepts either a single
12
+ * value or an array, so the same field type covers both radio-style and
13
+ * checkbox-style UIs.
14
+ */
15
+ class SelectableField extends Field_1.Field {
16
+ constructor(options) {
17
+ var _a;
18
+ const { minItems = 1, maxItems = (_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.length } = options;
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,
21
+ maxItems }, options));
22
+ this._type = "SELECTABLE";
23
+ }
24
+ }
25
+ exports.SelectableField = SelectableField;
26
+ //# sourceMappingURL=selectable.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,20 @@
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");
7
+ /**
8
+ * Field for plain string values. Ships with a `z.string()` fallback validator
9
+ * so the field is always valid when no custom `validate` option is provided.
10
+ * Accepts `secure` (password masking) and `multiline` hints that are forwarded
11
+ * as props to the underlying input component.
12
+ */
13
+ class TextField extends Field_1.Field {
14
+ constructor(options) {
15
+ super(Object.assign({ validate: (0, validators_1.zodValidator)(zod_1.z.string().optional()) }, options));
16
+ this._type = "TEXT";
17
+ }
18
+ }
19
+ exports.TextField = TextField;
20
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
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; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useField = useField;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Convenience hook for components that accept an optional `field` prop. When
7
+ * `field` is provided it is used directly; when it is absent (falsy), a
8
+ * temporary field created by `defaultField` is memoised for the component's
9
+ * lifetime.
10
+ *
11
+ * This lets components remain uncontrolled by default (using their own
12
+ * internal field) while still accepting external control when a `field` prop
13
+ * is supplied — without conditional hook calls.
14
+ *
15
+ * `params` are forwarded to `field.use()` in either branch, so imperative
16
+ * ref bindings work regardless of which field is active.
17
+ */
18
+ function useField(field, params, defaultField) {
19
+ if (field) {
20
+ return field.use(params === null || params === void 0 ? void 0 : params[0], params === null || params === void 0 ? void 0 : params[1]);
21
+ }
22
+ const tempField = (0, react_1.useMemo)(() => {
23
+ return defaultField();
24
+ }, []);
25
+ return tempField.use(params[0], params === null || params === void 0 ? void 0 : params[1]);
26
+ }
27
+ //# sourceMappingURL=useField.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,58 @@
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");
6
+ /**
7
+ * Standalone validation hook for values managed outside a `Field` instance.
8
+ * Useful when you have a raw state value and a validator function but do not
9
+ * want to create a full `Field` object.
10
+ *
11
+ * Error display follows the same blur policy as `Field.useValidation`: if
12
+ * `value` is `undefined` on the first render (`startedUnset`), the error is
13
+ * hidden until the user has blurred the input. Call the returned
14
+ * `onInputBlurred` handler on the input's blur event to trigger visibility.
15
+ *
16
+ * `message` is resolved from `readableError` first, then from the first
17
+ * element's `.message` when `error` is an array.
18
+ *
19
+ * A {@link ValidationError} thrown by `providedValidate` is caught and
20
+ * normalised; other exceptions propagate.
21
+ */
22
+ const useValidate = (value, providedValidate) => {
23
+ var _a, _b, _c, _d;
24
+ const [hasBlurred, setHasBlurred] = (0, react_1.useState)(false);
25
+ const isUnset = typeof value === 'undefined';
26
+ const startedUnset = (0, react_1.useRef)(isUnset).current;
27
+ const validate = (0, react_1.useCallback)((value) => {
28
+ try {
29
+ const result = providedValidate === null || providedValidate === void 0 ? void 0 : providedValidate(value, {});
30
+ return result;
31
+ }
32
+ catch (e) {
33
+ if (e instanceof Field_1.ValidationError) {
34
+ return {
35
+ isValid: false,
36
+ error: e.data
37
+ };
38
+ }
39
+ throw e;
40
+ }
41
+ }, []);
42
+ const onInputBlurred = (0, react_1.useCallback)(() => {
43
+ setHasBlurred(true);
44
+ }, []);
45
+ const validation = validate(value);
46
+ const isValid = (_a = validation === null || validation === void 0 ? void 0 : validation.isValid) !== null && _a !== void 0 ? _a : true;
47
+ const isInvalid = !isValid;
48
+ const message = (_b = validation === null || validation === void 0 ? void 0 : validation.readableError) !== null && _b !== void 0 ? _b : (_d = (_c = validation === null || validation === void 0 ? void 0 : validation.error) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message;
49
+ const errorDisplayRequiresBlur = startedUnset;
50
+ const showError = isInvalid && (errorDisplayRequiresBlur ? hasBlurred : true);
51
+ return {
52
+ onInputBlurred,
53
+ showError,
54
+ message,
55
+ };
56
+ };
57
+ exports.useValidate = useValidate;
58
+ //# sourceMappingURL=useValidate.js.map
@@ -0,0 +1 @@
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,CAAC,CAAA;YAE5C,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,uBAAe,EAAE,CAAC;gBACjC,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,CAAC,CAAC,IAAI;iBACd,CAAA;YACH,CAAC;YAED,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACtC,aAAa,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAElC,MAAM,OAAO,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,mCAAI,IAAI,CAAA;IAE3C,MAAM,SAAS,GAAG,CAAC,OAAO,CAAA;IAE1B,MAAM,OAAO,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,mCAAI,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,0CAAG,CAAC,CAAC,0CAAE,OAAO,CAAA;IAE5E,MAAM,wBAAwB,GAAG,YAAY,CAAA;IAE7C,MAAM,SAAS,GAAG,SAAS,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAE7E,OAAO;QACL,cAAc;QACd,SAAS;QACT,OAAO;KACR,CAAA;AACH,CAAC,CAAA;AA7CY,QAAA,WAAW,eA6CvB"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
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("./fields"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./lib"), exports);
20
+ __exportStar(require("./validators"), exports);
21
+ __exportStar(require("./hooks"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,0CAAuB;AACvB,wCAAqB;AACrB,+CAA4B;AAC5B,0CAAuB"}
@@ -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;