@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,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useFieldBinding = useFieldBinding;
13
+ const react_1 = require("react");
14
+ /**
15
+ * Attaches an imperative handle to `ref` via `useImperativeHandle`. Every
16
+ * method in {@link IFieldRef} is given a default implementation that throws
17
+ * `"ref.<method> not implemented"`, so callers get a clear error rather than a
18
+ * silent no-op when a method is missing from `impl`.
19
+ *
20
+ * `impl` is a partial override — only supply the methods your component
21
+ * actually supports. Unimplemented methods remain as throwing stubs.
22
+ * `deps` is forwarded directly to `useImperativeHandle`; include anything
23
+ * `impl` closes over that can change between renders.
24
+ */
25
+ function useFieldBinding(ref, impl, deps = []) {
26
+ const notImplemented = (method) => {
27
+ throw new Error(`ref.${method} not implemented`);
28
+ };
29
+ (0, react_1.useImperativeHandle)(ref, () => (Object.assign({ blur: () => {
30
+ notImplemented('blur');
31
+ }, emit: () => {
32
+ notImplemented('emit');
33
+ }, focus: () => {
34
+ notImplemented('focus');
35
+ },
36
+ // @ts-expect-error
37
+ getValue: () => {
38
+ notImplemented('getValue');
39
+ }, scrollIntoView: () => __awaiter(this, void 0, void 0, function* () {
40
+ notImplemented('scrollIntoView');
41
+ }), hideValue() {
42
+ notImplemented('hideValue');
43
+ },
44
+ revealValue() {
45
+ notImplemented('revealValue');
46
+ },
47
+ toggleValueVisibility() {
48
+ notImplemented('toggleValueVisibility');
49
+ } }, impl)), deps);
50
+ }
51
+ //# sourceMappingURL=useFieldBinding.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/types/field.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.js","sourceRoot":"","sources":["../../src/types/form.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/types/validation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
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);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB"}
@@ -0,0 +1,47 @@
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");
6
+ /**
7
+ * Adapts a Zod schema into the `Validator` contract expected by `Field` and
8
+ * `useValidate`. Uses `safeParse` internally so Zod errors are captured as
9
+ * `{ isValid: false, error: ZodIssue[] }` rather than thrown exceptions.
10
+ *
11
+ * The returned function is synchronous — async Zod schemas (`z.promise`,
12
+ * `.parseAsync`) are not supported.
13
+ */
14
+ function zodValidator(model) {
15
+ return (value) => {
16
+ var _a;
17
+ const result = model.safeParse(value);
18
+ return {
19
+ isValid: result.success,
20
+ error: (_a = result.error) === null || _a === void 0 ? void 0 : _a.issues,
21
+ result: result.data
22
+ };
23
+ };
24
+ }
25
+ const isZodIssue = (val) => {
26
+ return ['code', 'expected', 'received', 'path', 'message'].every(x => x in val);
27
+ };
28
+ /**
29
+ * Type guard that narrows a `ValidationResult`-shaped value to one produced by
30
+ * `zodValidator`. A valid result must have `result` present; an invalid result
31
+ * must have `error` as an array of `ZodIssue` objects. Use this to
32
+ * distinguish Zod results from results produced by custom validators when
33
+ * handling errors generically.
34
+ */
35
+ function isZodValidationResult(val) {
36
+ const isValidABoolean = types_1.TypeGuards.isBoolean(val.isValid);
37
+ if (isValidABoolean) {
38
+ if (!val.isValid) {
39
+ return types_1.TypeGuards.isArray(val.error) && val.error.every(isZodIssue);
40
+ }
41
+ else {
42
+ return 'result' in val;
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+ //# sourceMappingURL=zod.js.map
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codeleap/form",
3
- "version": "7.0.0",
4
- "main": "src/index.ts",
3
+ "version": "7.0.2",
4
+ "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -22,10 +22,10 @@
22
22
  "directory": "packages/form"
23
23
  },
24
24
  "devDependencies": {
25
- "@codeleap/config": "7.0.0",
26
- "@codeleap/types": "7.0.0",
27
- "@codeleap/store": "7.0.0",
28
- "@codeleap/hooks": "7.0.0",
25
+ "@codeleap/config": "7.0.1",
26
+ "@codeleap/types": "7.0.1",
27
+ "@codeleap/store": "7.0.1",
28
+ "@codeleap/hooks": "7.0.1",
29
29
  "zod": "4.4.3",
30
30
  "ts-node-dev": "1.1.8"
31
31
  },
@@ -35,10 +35,10 @@
35
35
  "playground": "bun src/test.ts"
36
36
  },
37
37
  "peerDependencies": {
38
- "@codeleap/types": "7.0.0",
39
- "@codeleap/store": "7.0.0",
40
- "@codeleap/logger": "7.0.0",
41
- "@codeleap/hooks": "7.0.0",
38
+ "@codeleap/types": "7.0.1",
39
+ "@codeleap/store": "7.0.1",
40
+ "@codeleap/logger": "7.0.1",
41
+ "@codeleap/hooks": "7.0.1",
42
42
  "zod": "*",
43
43
  "react": "19.1.0",
44
44
  "typescript": "5.5.2"