@contember/react-form 1.3.0-alpha.14

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 (141) hide show
  1. package/dist/development/components/FormCheckbox.cjs +68 -0
  2. package/dist/development/components/FormCheckbox.cjs.map +1 -0
  3. package/dist/development/components/FormCheckbox.js +52 -0
  4. package/dist/development/components/FormCheckbox.js.map +1 -0
  5. package/dist/development/components/FormError.cjs +22 -0
  6. package/dist/development/components/FormError.cjs.map +1 -0
  7. package/dist/development/components/FormError.js +22 -0
  8. package/dist/development/components/FormError.js.map +1 -0
  9. package/dist/development/components/FormFieldScope.cjs +15 -0
  10. package/dist/development/components/FormFieldScope.cjs.map +1 -0
  11. package/dist/development/components/FormFieldScope.js +15 -0
  12. package/dist/development/components/FormFieldScope.js.map +1 -0
  13. package/dist/development/components/FormHasManyRelationScope.cjs +15 -0
  14. package/dist/development/components/FormHasManyRelationScope.cjs.map +1 -0
  15. package/dist/development/components/FormHasManyRelationScope.js +15 -0
  16. package/dist/development/components/FormHasManyRelationScope.js.map +1 -0
  17. package/dist/development/components/FormHasOneRelationScope.cjs +15 -0
  18. package/dist/development/components/FormHasOneRelationScope.cjs.map +1 -0
  19. package/dist/development/components/FormHasOneRelationScope.js +15 -0
  20. package/dist/development/components/FormHasOneRelationScope.js.map +1 -0
  21. package/dist/development/components/FormInput.cjs +40 -0
  22. package/dist/development/components/FormInput.cjs.map +1 -0
  23. package/dist/development/components/FormInput.js +40 -0
  24. package/dist/development/components/FormInput.js.map +1 -0
  25. package/dist/development/components/FormLabel.cjs +24 -0
  26. package/dist/development/components/FormLabel.cjs.map +1 -0
  27. package/dist/development/components/FormLabel.js +24 -0
  28. package/dist/development/components/FormLabel.js.map +1 -0
  29. package/dist/development/components/FormRadioInput.cjs +39 -0
  30. package/dist/development/components/FormRadioInput.cjs.map +1 -0
  31. package/dist/development/components/FormRadioInput.js +39 -0
  32. package/dist/development/components/FormRadioInput.js.map +1 -0
  33. package/dist/development/contexts.cjs +14 -0
  34. package/dist/development/contexts.cjs.map +1 -0
  35. package/dist/development/contexts.js +14 -0
  36. package/dist/development/contexts.js.map +1 -0
  37. package/dist/development/hooks/useFormInputValidationHandler.cjs +64 -0
  38. package/dist/development/hooks/useFormInputValidationHandler.cjs.map +1 -0
  39. package/dist/development/hooks/useFormInputValidationHandler.js +48 -0
  40. package/dist/development/hooks/useFormInputValidationHandler.js.map +1 -0
  41. package/dist/development/index.cjs +26 -0
  42. package/dist/development/index.cjs.map +1 -0
  43. package/dist/development/index.js +26 -0
  44. package/dist/development/index.js.map +1 -0
  45. package/dist/development/internal/useFormInputHandler.cjs +98 -0
  46. package/dist/development/internal/useFormInputHandler.cjs.map +1 -0
  47. package/dist/development/internal/useFormInputHandler.js +98 -0
  48. package/dist/development/internal/useFormInputHandler.js.map +1 -0
  49. package/dist/production/components/FormCheckbox.cjs +68 -0
  50. package/dist/production/components/FormCheckbox.cjs.map +1 -0
  51. package/dist/production/components/FormCheckbox.js +52 -0
  52. package/dist/production/components/FormCheckbox.js.map +1 -0
  53. package/dist/production/components/FormError.cjs +22 -0
  54. package/dist/production/components/FormError.cjs.map +1 -0
  55. package/dist/production/components/FormError.js +22 -0
  56. package/dist/production/components/FormError.js.map +1 -0
  57. package/dist/production/components/FormFieldScope.cjs +15 -0
  58. package/dist/production/components/FormFieldScope.cjs.map +1 -0
  59. package/dist/production/components/FormFieldScope.js +15 -0
  60. package/dist/production/components/FormFieldScope.js.map +1 -0
  61. package/dist/production/components/FormHasManyRelationScope.cjs +15 -0
  62. package/dist/production/components/FormHasManyRelationScope.cjs.map +1 -0
  63. package/dist/production/components/FormHasManyRelationScope.js +15 -0
  64. package/dist/production/components/FormHasManyRelationScope.js.map +1 -0
  65. package/dist/production/components/FormHasOneRelationScope.cjs +15 -0
  66. package/dist/production/components/FormHasOneRelationScope.cjs.map +1 -0
  67. package/dist/production/components/FormHasOneRelationScope.js +15 -0
  68. package/dist/production/components/FormHasOneRelationScope.js.map +1 -0
  69. package/dist/production/components/FormInput.cjs +40 -0
  70. package/dist/production/components/FormInput.cjs.map +1 -0
  71. package/dist/production/components/FormInput.js +40 -0
  72. package/dist/production/components/FormInput.js.map +1 -0
  73. package/dist/production/components/FormLabel.cjs +24 -0
  74. package/dist/production/components/FormLabel.cjs.map +1 -0
  75. package/dist/production/components/FormLabel.js +24 -0
  76. package/dist/production/components/FormLabel.js.map +1 -0
  77. package/dist/production/components/FormRadioInput.cjs +39 -0
  78. package/dist/production/components/FormRadioInput.cjs.map +1 -0
  79. package/dist/production/components/FormRadioInput.js +39 -0
  80. package/dist/production/components/FormRadioInput.js.map +1 -0
  81. package/dist/production/contexts.cjs +14 -0
  82. package/dist/production/contexts.cjs.map +1 -0
  83. package/dist/production/contexts.js +14 -0
  84. package/dist/production/contexts.js.map +1 -0
  85. package/dist/production/hooks/useFormInputValidationHandler.cjs +64 -0
  86. package/dist/production/hooks/useFormInputValidationHandler.cjs.map +1 -0
  87. package/dist/production/hooks/useFormInputValidationHandler.js +48 -0
  88. package/dist/production/hooks/useFormInputValidationHandler.js.map +1 -0
  89. package/dist/production/index.cjs +26 -0
  90. package/dist/production/index.cjs.map +1 -0
  91. package/dist/production/index.js +26 -0
  92. package/dist/production/index.js.map +1 -0
  93. package/dist/production/internal/useFormInputHandler.cjs +98 -0
  94. package/dist/production/internal/useFormInputHandler.cjs.map +1 -0
  95. package/dist/production/internal/useFormInputHandler.js +98 -0
  96. package/dist/production/internal/useFormInputHandler.js.map +1 -0
  97. package/dist/types/components/FormCheckbox.d.ts +11 -0
  98. package/dist/types/components/FormCheckbox.d.ts.map +1 -0
  99. package/dist/types/components/FormError.d.ts +7 -0
  100. package/dist/types/components/FormError.d.ts.map +1 -0
  101. package/dist/types/components/FormFieldScope.d.ts +8 -0
  102. package/dist/types/components/FormFieldScope.d.ts.map +1 -0
  103. package/dist/types/components/FormHasManyRelationScope.d.ts +8 -0
  104. package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -0
  105. package/dist/types/components/FormHasOneRelationScope.d.ts +8 -0
  106. package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -0
  107. package/dist/types/components/FormInput.d.ts +10 -0
  108. package/dist/types/components/FormInput.d.ts.map +1 -0
  109. package/dist/types/components/FormLabel.d.ts +5 -0
  110. package/dist/types/components/FormLabel.d.ts.map +1 -0
  111. package/dist/types/components/FormRadioInput.d.ts +11 -0
  112. package/dist/types/components/FormRadioInput.d.ts.map +1 -0
  113. package/dist/types/components/index.d.ts +9 -0
  114. package/dist/types/components/index.d.ts.map +1 -0
  115. package/dist/types/contexts.d.ts +8 -0
  116. package/dist/types/contexts.d.ts.map +1 -0
  117. package/dist/types/hooks/index.d.ts +2 -0
  118. package/dist/types/hooks/index.d.ts.map +1 -0
  119. package/dist/types/hooks/useFormInputValidationHandler.d.ts +8 -0
  120. package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +1 -0
  121. package/dist/types/index.d.ts +4 -0
  122. package/dist/types/index.d.ts.map +1 -0
  123. package/dist/types/internal/useFormInputHandler.d.ts +8 -0
  124. package/dist/types/internal/useFormInputHandler.d.ts.map +1 -0
  125. package/dist/types/tsconfig.tsbuildinfo +1 -0
  126. package/package.json +57 -0
  127. package/src/components/FormCheckbox.tsx +58 -0
  128. package/src/components/FormError.tsx +22 -0
  129. package/src/components/FormFieldScope.tsx +24 -0
  130. package/src/components/FormHasManyRelationScope.tsx +24 -0
  131. package/src/components/FormHasOneRelationScope.tsx +24 -0
  132. package/src/components/FormInput.tsx +46 -0
  133. package/src/components/FormLabel.tsx +22 -0
  134. package/src/components/FormRadioInput.tsx +45 -0
  135. package/src/components/index.ts +8 -0
  136. package/src/contexts.ts +12 -0
  137. package/src/hooks/index.ts +1 -0
  138. package/src/hooks/useFormInputValidationHandler.tsx +47 -0
  139. package/src/index.ts +3 -0
  140. package/src/internal/useFormInputHandler.ts +104 -0
  141. package/src/tsconfig.json +11 -0
@@ -0,0 +1,14 @@
1
+ import { createContext } from "@contember/react-utils";
2
+ const FormFieldIdContext_ = createContext("FormFieldIdContext", void 0);
3
+ const FormFieldIdContext = FormFieldIdContext_[0];
4
+ const useFormFieldId = FormFieldIdContext_[1];
5
+ const FormErrorContext_ = createContext("FormErrorContext", void 0);
6
+ const FormErrorContext = FormErrorContext_[0];
7
+ const useFormError = FormErrorContext_[1];
8
+ export {
9
+ FormErrorContext,
10
+ FormFieldIdContext,
11
+ useFormError,
12
+ useFormFieldId
13
+ };
14
+ //# sourceMappingURL=contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.js","sources":["../../src/contexts.ts"],"sourcesContent":["import { createContext } from '@contember/react-utils'\nimport { ErrorAccessor } from '@contember/react-binding'\n\nconst FormFieldIdContext_ = createContext<string | undefined>('FormFieldIdContext', undefined)\n/** @internal */\nexport const FormFieldIdContext = FormFieldIdContext_[0]\nexport const useFormFieldId = FormFieldIdContext_[1]\n\nconst FormErrorContext_ = createContext<ErrorAccessor.Error[] | undefined>('FormErrorContext', undefined)\n/** @internal */\nexport const FormErrorContext = FormErrorContext_[0]\nexport const useFormError = FormErrorContext_[1]\n"],"names":[],"mappings":";AAGA,MAAM,sBAAsB,cAAkC,sBAAsB,MAAS;AAEhF,MAAA,qBAAqB,oBAAoB,CAAC;AAC1C,MAAA,iBAAiB,oBAAoB,CAAC;AAEnD,MAAM,oBAAoB,cAAiD,oBAAoB,MAAS;AAE3F,MAAA,mBAAmB,kBAAkB,CAAC;AACtC,MAAA,eAAe,kBAAkB,CAAC;"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const reactBinding = require("@contember/react-binding");
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
22
+ const useFormInputValidationHandler = (field) => {
23
+ const accessorGetter = field.getAccessor;
24
+ const validationMessage = React.useRef();
25
+ const [focus, setFocus] = React__namespace.useState(false);
26
+ const inputRef = React__namespace.useRef(null);
27
+ reactBinding.useEntityBeforePersist(React.useCallback(() => {
28
+ if (validationMessage.current) {
29
+ accessorGetter().addError(validationMessage.current);
30
+ }
31
+ }, [accessorGetter]));
32
+ React.useEffect(() => {
33
+ if (!inputRef.current) {
34
+ return;
35
+ }
36
+ const input = inputRef.current;
37
+ const valid = input.validity?.valid;
38
+ const message = valid ? void 0 : input?.validationMessage;
39
+ if (message !== validationMessage.current) {
40
+ validationMessage.current = message;
41
+ if (!message || !focus) {
42
+ accessorGetter().clearErrors();
43
+ }
44
+ if (!focus && message) {
45
+ accessorGetter().addError(message);
46
+ }
47
+ }
48
+ });
49
+ return {
50
+ ref: inputRef,
51
+ onFocus: React.useCallback(() => {
52
+ setFocus(true);
53
+ }, []),
54
+ onBlur: React.useCallback(() => {
55
+ setFocus(false);
56
+ accessorGetter().clearErrors();
57
+ if (validationMessage.current) {
58
+ accessorGetter().addError(validationMessage.current);
59
+ }
60
+ }, [accessorGetter])
61
+ };
62
+ };
63
+ exports.useFormInputValidationHandler = useFormInputValidationHandler;
64
+ //# sourceMappingURL=useFormInputValidationHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormInputValidationHandler.cjs","sources":["../../../src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>()\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tif (message !== validationMessage.current) {\n\t\t\tvalidationMessage.current = message\n\t\t\tif (!message || !focus) {\n\t\t\t\taccessorGetter().clearErrors()\n\t\t\t}\n\t\t\tif (!focus && message) {\n\t\t\t\taccessorGetter().addError(message)\n\t\t\t}\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n"],"names":["useRef","React","useEntityBeforePersist","useCallback","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoBA,MAAAA;AAC1B,QAAM,CAAC,OAAO,QAAQ,IAAIC,iBAAM,SAAS,KAAK;AACxC,QAAA,WAAWA,iBAAM,OAAyB,IAAI;AACpDC,eAAA,uBAAuBC,kBAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AACf,uBAAE,SAAS,kBAAkB,OAAO;AAAA,IACpD;AAAA,EAAA,GACE,CAAC,cAAc,CAAC,CAAC;AAEpBC,QAAAA,UAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AACA,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AACxB,UAAA,UAAU,QAAQ,SAAY,OAAO;AACvC,QAAA,YAAY,kBAAkB,SAAS;AAC1C,wBAAkB,UAAU;AACxB,UAAA,CAAC,WAAW,CAAC,OAAO;AACvB,uBAAA,EAAiB;MAClB;AACI,UAAA,CAAC,SAAS,SAAS;AACP,uBAAA,EAAE,SAAS,OAAO;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,CACA;AAEM,SAAA;AAAA,IACN,KAAK;AAAA,IACL,SAASD,kBAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,IACL,QAAQA,kBAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB;AACjB,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IAAA,GACE,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;;"}
@@ -0,0 +1,48 @@
1
+ import * as React from "react";
2
+ import { useRef, useCallback, useEffect } from "react";
3
+ import { useEntityBeforePersist } from "@contember/react-binding";
4
+ const useFormInputValidationHandler = (field) => {
5
+ const accessorGetter = field.getAccessor;
6
+ const validationMessage = useRef();
7
+ const [focus, setFocus] = React.useState(false);
8
+ const inputRef = React.useRef(null);
9
+ useEntityBeforePersist(useCallback(() => {
10
+ if (validationMessage.current) {
11
+ accessorGetter().addError(validationMessage.current);
12
+ }
13
+ }, [accessorGetter]));
14
+ useEffect(() => {
15
+ if (!inputRef.current) {
16
+ return;
17
+ }
18
+ const input = inputRef.current;
19
+ const valid = input.validity?.valid;
20
+ const message = valid ? void 0 : input?.validationMessage;
21
+ if (message !== validationMessage.current) {
22
+ validationMessage.current = message;
23
+ if (!message || !focus) {
24
+ accessorGetter().clearErrors();
25
+ }
26
+ if (!focus && message) {
27
+ accessorGetter().addError(message);
28
+ }
29
+ }
30
+ });
31
+ return {
32
+ ref: inputRef,
33
+ onFocus: useCallback(() => {
34
+ setFocus(true);
35
+ }, []),
36
+ onBlur: useCallback(() => {
37
+ setFocus(false);
38
+ accessorGetter().clearErrors();
39
+ if (validationMessage.current) {
40
+ accessorGetter().addError(validationMessage.current);
41
+ }
42
+ }, [accessorGetter])
43
+ };
44
+ };
45
+ export {
46
+ useFormInputValidationHandler
47
+ };
48
+ //# sourceMappingURL=useFormInputValidationHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormInputValidationHandler.js","sources":["../../../src/hooks/useFormInputValidationHandler.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'\n\nexport const useFormInputValidationHandler = (field: FieldAccessor<any>) => {\n\tconst accessorGetter = field.getAccessor\n\tconst validationMessage = useRef<string>()\n\tconst [focus, setFocus] = React.useState(false)\n\tconst inputRef = React.useRef<HTMLInputElement>(null)\n\tuseEntityBeforePersist(useCallback(() => {\n\t\tif (validationMessage.current) {\n\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t}\n\t}, [accessorGetter]))\n\n\tuseEffect(() => {\n\t\tif (!inputRef.current) {\n\t\t\treturn\n\t\t}\n\t\tconst input = inputRef.current\n\t\tconst valid = input.validity?.valid\n\t\tconst message = valid ? undefined : input?.validationMessage\n\t\tif (message !== validationMessage.current) {\n\t\t\tvalidationMessage.current = message\n\t\t\tif (!message || !focus) {\n\t\t\t\taccessorGetter().clearErrors()\n\t\t\t}\n\t\t\tif (!focus && message) {\n\t\t\t\taccessorGetter().addError(message)\n\t\t\t}\n\t\t}\n\t})\n\n\treturn {\n\t\tref: inputRef,\n\t\tonFocus: useCallback(() => {\n\t\t\tsetFocus(true)\n\t\t}, []),\n\t\tonBlur: useCallback(() => {\n\t\t\tsetFocus(false)\n\t\t\taccessorGetter().clearErrors()\n\t\t\tif (validationMessage.current) {\n\t\t\t\taccessorGetter().addError(validationMessage.current)\n\t\t\t}\n\t\t}, [accessorGetter]),\n\t}\n}\n"],"names":[],"mappings":";;;AAIa,MAAA,gCAAgC,CAAC,UAA8B;AAC3E,QAAM,iBAAiB,MAAM;AAC7B,QAAM,oBAAoB;AAC1B,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AACxC,QAAA,WAAW,MAAM,OAAyB,IAAI;AACpD,yBAAuB,YAAY,MAAM;AACxC,QAAI,kBAAkB,SAAS;AACf,uBAAE,SAAS,kBAAkB,OAAO;AAAA,IACpD;AAAA,EAAA,GACE,CAAC,cAAc,CAAC,CAAC;AAEpB,YAAU,MAAM;AACX,QAAA,CAAC,SAAS,SAAS;AACtB;AAAA,IACD;AACA,UAAM,QAAQ,SAAS;AACjB,UAAA,QAAQ,MAAM,UAAU;AACxB,UAAA,UAAU,QAAQ,SAAY,OAAO;AACvC,QAAA,YAAY,kBAAkB,SAAS;AAC1C,wBAAkB,UAAU;AACxB,UAAA,CAAC,WAAW,CAAC,OAAO;AACvB,uBAAA,EAAiB;MAClB;AACI,UAAA,CAAC,SAAS,SAAS;AACP,uBAAA,EAAE,SAAS,OAAO;AAAA,MAClC;AAAA,IACD;AAAA,EAAA,CACA;AAEM,SAAA;AAAA,IACN,KAAK;AAAA,IACL,SAAS,YAAY,MAAM;AAC1B,eAAS,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,IACL,QAAQ,YAAY,MAAM;AACzB,eAAS,KAAK;AACd,qBAAA,EAAiB;AACjB,UAAI,kBAAkB,SAAS;AACf,yBAAE,SAAS,kBAAkB,OAAO;AAAA,MACpD;AAAA,IAAA,GACE,CAAC,cAAc,CAAC;AAAA,EAAA;AAErB;"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const contexts = require("./contexts.cjs");
4
+ const FormError = require("./components/FormError.cjs");
5
+ const FormCheckbox = require("./components/FormCheckbox.cjs");
6
+ const FormFieldScope = require("./components/FormFieldScope.cjs");
7
+ const FormHasOneRelationScope = require("./components/FormHasOneRelationScope.cjs");
8
+ const FormHasManyRelationScope = require("./components/FormHasManyRelationScope.cjs");
9
+ const FormInput = require("./components/FormInput.cjs");
10
+ const FormLabel = require("./components/FormLabel.cjs");
11
+ const FormRadioInput = require("./components/FormRadioInput.cjs");
12
+ const useFormInputValidationHandler = require("./hooks/useFormInputValidationHandler.cjs");
13
+ exports.FormErrorContext = contexts.FormErrorContext;
14
+ exports.FormFieldIdContext = contexts.FormFieldIdContext;
15
+ exports.useFormError = contexts.useFormError;
16
+ exports.useFormFieldId = contexts.useFormFieldId;
17
+ exports.FormError = FormError.FormError;
18
+ exports.FormCheckbox = FormCheckbox.FormCheckbox;
19
+ exports.FormFieldScope = FormFieldScope.FormFieldScope;
20
+ exports.FormHasOneRelationScope = FormHasOneRelationScope.FormHasOneRelationScope;
21
+ exports.FormHasManyRelationScope = FormHasManyRelationScope.FormHasManyRelationScope;
22
+ exports.FormInput = FormInput.FormInput;
23
+ exports.FormLabel = FormLabel.FormLabel;
24
+ exports.FormRadioInput = FormRadioInput.FormRadioInput;
25
+ exports.useFormInputValidationHandler = useFormInputValidationHandler.useFormInputValidationHandler;
26
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,26 @@
1
+ import { FormErrorContext, FormFieldIdContext, useFormError, useFormFieldId } from "./contexts.js";
2
+ import { FormError } from "./components/FormError.js";
3
+ import { FormCheckbox } from "./components/FormCheckbox.js";
4
+ import { FormFieldScope } from "./components/FormFieldScope.js";
5
+ import { FormHasOneRelationScope } from "./components/FormHasOneRelationScope.js";
6
+ import { FormHasManyRelationScope } from "./components/FormHasManyRelationScope.js";
7
+ import { FormInput } from "./components/FormInput.js";
8
+ import { FormLabel } from "./components/FormLabel.js";
9
+ import { FormRadioInput } from "./components/FormRadioInput.js";
10
+ import { useFormInputValidationHandler } from "./hooks/useFormInputValidationHandler.js";
11
+ export {
12
+ FormCheckbox,
13
+ FormError,
14
+ FormErrorContext,
15
+ FormFieldIdContext,
16
+ FormFieldScope,
17
+ FormHasManyRelationScope,
18
+ FormHasOneRelationScope,
19
+ FormInput,
20
+ FormLabel,
21
+ FormRadioInput,
22
+ useFormError,
23
+ useFormFieldId,
24
+ useFormInputValidationHandler
25
+ };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const useFormInputHandler = (field) => {
5
+ return React.useMemo(() => {
6
+ const schema = field.schema;
7
+ const columnType = schema.type;
8
+ const handlerFactory = ColumnTypeHandlerFactories[columnType];
9
+ if (!handlerFactory) {
10
+ throw new Error(`Column type ${columnType} is not supported yet`);
11
+ }
12
+ return handlerFactory(schema, field.getAccessor);
13
+ }, [field.getAccessor, field.schema]);
14
+ };
15
+ const ColumnTypeHandlerFactories = {
16
+ Integer: () => ({
17
+ parseValue: (value) => {
18
+ if (value === "") {
19
+ return null;
20
+ }
21
+ const parsed = parseInt(value, 10);
22
+ return isNaN(parsed) ? null : parsed;
23
+ },
24
+ formatValue: (value) => {
25
+ return value === null ? "" : value.toString(10);
26
+ },
27
+ defaultInputProps: {
28
+ type: "number"
29
+ }
30
+ }),
31
+ Double: () => ({
32
+ parseValue: (value) => {
33
+ if (value === "") {
34
+ return null;
35
+ }
36
+ const parsed = parseFloat(value);
37
+ return isNaN(parsed) ? null : parsed;
38
+ },
39
+ formatValue: (value) => {
40
+ return value === null ? "" : value.toString(10);
41
+ },
42
+ defaultInputProps: {
43
+ type: "number"
44
+ }
45
+ }),
46
+ String: (schema, field) => ({
47
+ parseValue: (value) => {
48
+ if (value === "" && schema.nullable && field().valueOnServer === null) {
49
+ return null;
50
+ }
51
+ return value;
52
+ },
53
+ formatValue: (value) => value ?? ""
54
+ }),
55
+ Date: () => ({
56
+ parseValue: (value) => {
57
+ if (value === "") {
58
+ return null;
59
+ }
60
+ const parsed = Date.parse(value);
61
+ return isNaN(parsed) ? null : new Date(parsed);
62
+ },
63
+ formatValue: (value) => {
64
+ const parsed = value ? Date.parse(value) : null;
65
+ return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().split("T")[0];
66
+ },
67
+ defaultInputProps: {
68
+ type: "date"
69
+ }
70
+ }),
71
+ DateTime: () => ({
72
+ parseValue: (value) => {
73
+ if (value === "") {
74
+ return null;
75
+ }
76
+ const parsed = Date.parse(value);
77
+ return isNaN(parsed) ? null : new Date(parsed);
78
+ },
79
+ formatValue: (value) => {
80
+ const parsed = value ? Date.parse(value) : null;
81
+ return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().substring(0, 16);
82
+ },
83
+ defaultInputProps: {
84
+ type: "datetime-local"
85
+ }
86
+ }),
87
+ Bool: () => {
88
+ throw new Error("Boolean column type is not supported yet");
89
+ },
90
+ Enum: () => {
91
+ throw new Error("Enum column type is not supported yet");
92
+ },
93
+ Uuid: () => {
94
+ throw new Error("UUID column type is not supported yet");
95
+ }
96
+ };
97
+ exports.useFormInputHandler = useFormInputHandler;
98
+ //# sourceMappingURL=useFormInputHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormInputHandler.cjs","sources":["../../../src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nexport const useFormInputHandler = (field: FieldAccessor) => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType]\n\t\tif (!handlerFactory) {\n\t\t\tthrow new Error(`Column type ${columnType} is not supported yet`)\n\t\t}\n\t\treturn handlerFactory(schema, field.getAccessor)\n\t}, [field.getAccessor, field.schema])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => {\n\tparseValue: (value: string) => any\n\tformatValue: (value: any) => string\n\tdefaultInputProps?: React.InputHTMLAttributes<HTMLInputElement>\n}\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory> = {\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tString: (schema, field) => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => value ?? '',\n\t}),\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : new Date(parsed)\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : new Date(parsed)\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().substring(0, 16)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tBool: () => {\n\t\tthrow new Error('Boolean column type is not supported yet')\n\t},\n\tEnum: () => {\n\t\tthrow new Error('Enum column type is not supported yet')\n\t},\n\tUuid: () => {\n\t\tthrow new Error('UUID column type is not supported yet')\n\t},\n}\n"],"names":["useMemo"],"mappings":"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"}
@@ -0,0 +1,98 @@
1
+ import { useMemo } from "react";
2
+ const useFormInputHandler = (field) => {
3
+ return useMemo(() => {
4
+ const schema = field.schema;
5
+ const columnType = schema.type;
6
+ const handlerFactory = ColumnTypeHandlerFactories[columnType];
7
+ if (!handlerFactory) {
8
+ throw new Error(`Column type ${columnType} is not supported yet`);
9
+ }
10
+ return handlerFactory(schema, field.getAccessor);
11
+ }, [field.getAccessor, field.schema]);
12
+ };
13
+ const ColumnTypeHandlerFactories = {
14
+ Integer: () => ({
15
+ parseValue: (value) => {
16
+ if (value === "") {
17
+ return null;
18
+ }
19
+ const parsed = parseInt(value, 10);
20
+ return isNaN(parsed) ? null : parsed;
21
+ },
22
+ formatValue: (value) => {
23
+ return value === null ? "" : value.toString(10);
24
+ },
25
+ defaultInputProps: {
26
+ type: "number"
27
+ }
28
+ }),
29
+ Double: () => ({
30
+ parseValue: (value) => {
31
+ if (value === "") {
32
+ return null;
33
+ }
34
+ const parsed = parseFloat(value);
35
+ return isNaN(parsed) ? null : parsed;
36
+ },
37
+ formatValue: (value) => {
38
+ return value === null ? "" : value.toString(10);
39
+ },
40
+ defaultInputProps: {
41
+ type: "number"
42
+ }
43
+ }),
44
+ String: (schema, field) => ({
45
+ parseValue: (value) => {
46
+ if (value === "" && schema.nullable && field().valueOnServer === null) {
47
+ return null;
48
+ }
49
+ return value;
50
+ },
51
+ formatValue: (value) => value ?? ""
52
+ }),
53
+ Date: () => ({
54
+ parseValue: (value) => {
55
+ if (value === "") {
56
+ return null;
57
+ }
58
+ const parsed = Date.parse(value);
59
+ return isNaN(parsed) ? null : new Date(parsed);
60
+ },
61
+ formatValue: (value) => {
62
+ const parsed = value ? Date.parse(value) : null;
63
+ return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().split("T")[0];
64
+ },
65
+ defaultInputProps: {
66
+ type: "date"
67
+ }
68
+ }),
69
+ DateTime: () => ({
70
+ parseValue: (value) => {
71
+ if (value === "") {
72
+ return null;
73
+ }
74
+ const parsed = Date.parse(value);
75
+ return isNaN(parsed) ? null : new Date(parsed);
76
+ },
77
+ formatValue: (value) => {
78
+ const parsed = value ? Date.parse(value) : null;
79
+ return !parsed || isNaN(parsed) ? "" : new Date(parsed).toISOString().substring(0, 16);
80
+ },
81
+ defaultInputProps: {
82
+ type: "datetime-local"
83
+ }
84
+ }),
85
+ Bool: () => {
86
+ throw new Error("Boolean column type is not supported yet");
87
+ },
88
+ Enum: () => {
89
+ throw new Error("Enum column type is not supported yet");
90
+ },
91
+ Uuid: () => {
92
+ throw new Error("UUID column type is not supported yet");
93
+ }
94
+ };
95
+ export {
96
+ useFormInputHandler
97
+ };
98
+ //# sourceMappingURL=useFormInputHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormInputHandler.js","sources":["../../../src/internal/useFormInputHandler.ts"],"sourcesContent":["import { FieldAccessor, SchemaColumn, SchemaKnownColumnType } from '@contember/react-binding'\nimport * as React from 'react'\nimport { useMemo } from 'react'\n\nexport const useFormInputHandler = (field: FieldAccessor) => {\n\treturn useMemo(() => {\n\t\tconst schema = field.schema\n\t\tconst columnType = schema.type\n\t\tconst handlerFactory = ColumnTypeHandlerFactories[columnType as SchemaKnownColumnType]\n\t\tif (!handlerFactory) {\n\t\t\tthrow new Error(`Column type ${columnType} is not supported yet`)\n\t\t}\n\t\treturn handlerFactory(schema, field.getAccessor)\n\t}, [field.getAccessor, field.schema])\n}\n\ntype ColumnTypeHandlerFactory = (column: SchemaColumn, getAccessor: FieldAccessor.GetFieldAccessor) => {\n\tparseValue: (value: string) => any\n\tformatValue: (value: any) => string\n\tdefaultInputProps?: React.InputHTMLAttributes<HTMLInputElement>\n}\n\nconst ColumnTypeHandlerFactories: Record<SchemaKnownColumnType, ColumnTypeHandlerFactory> = {\n\tInteger: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseInt(value, 10)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tDouble: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = parseFloat(value)\n\t\t\treturn isNaN(parsed) ? null : parsed\n\t\t},\n\t\tformatValue: (value: number | null) => {\n\t\t\treturn value === null ? '' : value.toString(10)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'number',\n\t\t},\n\t}),\n\tString: (schema, field) => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '' && schema.nullable && field().valueOnServer === null) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn value\n\t\t},\n\t\tformatValue: (value: string | null) => value ?? '',\n\t}),\n\tDate: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : new Date(parsed)\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().split('T')[0]\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'date',\n\t\t},\n\t}),\n\tDateTime: () => ({\n\t\tparseValue: (value: string) => {\n\t\t\tif (value === '') {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tconst parsed = Date.parse(value)\n\t\t\treturn isNaN(parsed) ? null : new Date(parsed)\n\t\t},\n\t\tformatValue: (value: string | null) => {\n\t\t\tconst parsed = value ? Date.parse(value) : null\n\t\t\treturn !parsed || isNaN(parsed) ? '' : new Date(parsed).toISOString().substring(0, 16)\n\t\t},\n\t\tdefaultInputProps: {\n\t\t\ttype: 'datetime-local',\n\t\t},\n\t}),\n\tBool: () => {\n\t\tthrow new Error('Boolean column type is not supported yet')\n\t},\n\tEnum: () => {\n\t\tthrow new Error('Enum column type is not supported yet')\n\t},\n\tUuid: () => {\n\t\tthrow new Error('UUID column type is not supported yet')\n\t},\n}\n"],"names":[],"mappings":";AAIa,MAAA,sBAAsB,CAAC,UAAyB;AAC5D,SAAO,QAAQ,MAAM;AACpB,UAAM,SAAS,MAAM;AACrB,UAAM,aAAa,OAAO;AACpB,UAAA,iBAAiB,2BAA2B,UAAmC;AACrF,QAAI,CAAC,gBAAgB;AACpB,YAAM,IAAI,MAAM,eAAe,UAAU,uBAAuB;AAAA,IACjE;AACO,WAAA,eAAe,QAAQ,MAAM,WAAW;AAAA,KAC7C,CAAC,MAAM,aAAa,MAAM,MAAM,CAAC;AACrC;AAQA,MAAM,6BAAsF;AAAA,EAC3F,SAAS,OAAO;AAAA,IACf,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACV,eAAA;AAAA,MACR;AACM,YAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,aAAA,MAAM,MAAM,IAAI,OAAO;AAAA,IAC/B;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,UAAU,OAAO,KAAK,MAAM,SAAS,EAAE;AAAA,IAC/C;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IACP;AAAA,EAAA;AAAA,EAED,QAAQ,OAAO;AAAA,IACd,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACV,eAAA;AAAA,MACR;AACM,YAAA,SAAS,WAAW,KAAK;AACxB,aAAA,MAAM,MAAM,IAAI,OAAO;AAAA,IAC/B;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,aAAO,UAAU,OAAO,KAAK,MAAM,SAAS,EAAE;AAAA,IAC/C;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IACP;AAAA,EAAA;AAAA,EAED,QAAQ,CAAC,QAAQ,WAAW;AAAA,IAC3B,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,MAAM,OAAO,YAAY,MAAM,EAAE,kBAAkB,MAAM;AAC/D,eAAA;AAAA,MACR;AACO,aAAA;AAAA,IACR;AAAA,IACA,aAAa,CAAC,UAAyB,SAAS;AAAA,EAAA;AAAA,EAEjD,MAAM,OAAO;AAAA,IACZ,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACV,eAAA;AAAA,MACR;AACM,YAAA,SAAS,KAAK,MAAM,KAAK;AAC/B,aAAO,MAAM,MAAM,IAAI,OAAO,IAAI,KAAK,MAAM;AAAA,IAC9C;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,YAAM,SAAS,QAAQ,KAAK,MAAM,KAAK,IAAI;AAC3C,aAAO,CAAC,UAAU,MAAM,MAAM,IAAI,KAAK,IAAI,KAAK,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,IACnF;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IACP;AAAA,EAAA;AAAA,EAED,UAAU,OAAO;AAAA,IAChB,YAAY,CAAC,UAAkB;AAC9B,UAAI,UAAU,IAAI;AACV,eAAA;AAAA,MACR;AACM,YAAA,SAAS,KAAK,MAAM,KAAK;AAC/B,aAAO,MAAM,MAAM,IAAI,OAAO,IAAI,KAAK,MAAM;AAAA,IAC9C;AAAA,IACA,aAAa,CAAC,UAAyB;AACtC,YAAM,SAAS,QAAQ,KAAK,MAAM,KAAK,IAAI;AAC3C,aAAO,CAAC,UAAU,MAAM,MAAM,IAAI,KAAK,IAAI,KAAK,MAAM,EAAE,YAAc,EAAA,UAAU,GAAG,EAAE;AAAA,IACtF;AAAA,IACA,mBAAmB;AAAA,MAClB,MAAM;AAAA,IACP;AAAA,EAAA;AAAA,EAED,MAAM,MAAM;AACL,UAAA,IAAI,MAAM,0CAA0C;AAAA,EAC3D;AAAA,EACA,MAAM,MAAM;AACL,UAAA,IAAI,MAAM,uCAAuC;AAAA,EACxD;AAAA,EACA,MAAM,MAAM;AACL,UAAA,IAAI,MAAM,uCAAuC;AAAA,EACxD;AACD;"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const reactBinding = require("@contember/react-binding");
6
+ const contexts = require("../contexts.cjs");
7
+ const utilities = require("@contember/utilities");
8
+ const reactSlot = require("@radix-ui/react-slot");
9
+ const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
10
+ function _interopNamespaceDefault(e) {
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== "default") {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
+ const SlotInput = reactSlot.Slot;
28
+ const FormCheckbox = reactBinding.Component(({ field, isNonbearing, defaultValue, ...props }) => {
29
+ const id = contexts.useFormFieldId();
30
+ const accessor = reactBinding.useField(field);
31
+ const value = accessor.value;
32
+ const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
33
+ const accessorGetter = accessor.getAccessor;
34
+ const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
35
+ const [checkboxRef, setCheckboxRef] = React__namespace.useState(null);
36
+ React.useEffect(() => {
37
+ if (!checkboxRef) {
38
+ return;
39
+ }
40
+ ref.current = checkboxRef;
41
+ if (value === null) {
42
+ checkboxRef.indeterminate = true;
43
+ }
44
+ }, [checkboxRef, ref, value]);
45
+ return /* @__PURE__ */ jsxRuntime.jsx(
46
+ SlotInput,
47
+ {
48
+ ref: setCheckboxRef,
49
+ type: "checkbox",
50
+ checked: accessor.value === true,
51
+ "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
52
+ "data-invalid": utilities.dataAttribute(errors.length > 0),
53
+ id: `${id}-input`,
54
+ onFocus,
55
+ onBlur,
56
+ onChange: React.useCallback((e) => {
57
+ accessorGetter().updateValue(e.target.checked);
58
+ }, [accessorGetter]),
59
+ ...props
60
+ }
61
+ );
62
+ }, ({ field, isNonbearing, defaultValue }, env) => {
63
+ const node = reactBinding.TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
64
+ const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
65
+ return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
66
+ });
67
+ exports.FormCheckbox = FormCheckbox;
68
+ //# sourceMappingURL=FormCheckbox.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormCheckbox.cjs","sources":["../../../src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useField } from '@contember/react-binding'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<boolean>(field)\n\tconst value = accessor.value\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\t(ref as any).current = checkboxRef\n\t\tif (value === null) {\n\t\t\tcheckboxRef.indeterminate = true\n\t\t}\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t\t<SlotInput\n\t\t\t\tref={setCheckboxRef}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\tchecked={accessor.value === true}\n\t\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t\tid={`${id}-input`}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t\t}, [accessorGetter])}\n\t\t\t\t{...props}\n\t\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":["Slot","Component","useFormFieldId","useField","useFormError","useFormInputValidationHandler","React","useEffect","jsx","dataAttribute","useCallback","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,YAAYA,UAAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,KAAKC,SAAAA;AACL,QAAA,WAAWC,sBAAkB,KAAK;AACxC,QAAM,QAAQ,SAAS;AACvB,QAAM,SAASC,SAAAA,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAIC,iBAAM,SAAkC,IAAI;AAElFC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACC,QAAY,UAAU;AACvB,QAAI,UAAU,MAAM;AACnB,kBAAY,gBAAgB;AAAA,IAC7B;AAAA,EACE,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG1B,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK;AAAA,MACL,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAcC,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,IAAI,GAAG,EAAE;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGR,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAOC,wCAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQH,2BAAAA,IAAAI,aAAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;;"}
@@ -0,0 +1,52 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { useEffect, useCallback } from "react";
4
+ import { Component, useField, TreeNodeEnvironmentFactory, Field } from "@contember/react-binding";
5
+ import { useFormFieldId, useFormError } from "../contexts.js";
6
+ import { dataAttribute } from "@contember/utilities";
7
+ import { Slot } from "@radix-ui/react-slot";
8
+ import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
9
+ const SlotInput = Slot;
10
+ const FormCheckbox = Component(({ field, isNonbearing, defaultValue, ...props }) => {
11
+ const id = useFormFieldId();
12
+ const accessor = useField(field);
13
+ const value = accessor.value;
14
+ const errors = useFormError() ?? accessor.errors?.errors ?? [];
15
+ const accessorGetter = accessor.getAccessor;
16
+ const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
17
+ const [checkboxRef, setCheckboxRef] = React.useState(null);
18
+ useEffect(() => {
19
+ if (!checkboxRef) {
20
+ return;
21
+ }
22
+ ref.current = checkboxRef;
23
+ if (value === null) {
24
+ checkboxRef.indeterminate = true;
25
+ }
26
+ }, [checkboxRef, ref, value]);
27
+ return /* @__PURE__ */ jsx(
28
+ SlotInput,
29
+ {
30
+ ref: setCheckboxRef,
31
+ type: "checkbox",
32
+ checked: accessor.value === true,
33
+ "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
34
+ "data-invalid": dataAttribute(errors.length > 0),
35
+ id: `${id}-input`,
36
+ onFocus,
37
+ onBlur,
38
+ onChange: useCallback((e) => {
39
+ accessorGetter().updateValue(e.target.checked);
40
+ }, [accessorGetter]),
41
+ ...props
42
+ }
43
+ );
44
+ }, ({ field, isNonbearing, defaultValue }, env) => {
45
+ const node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
46
+ const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
47
+ return /* @__PURE__ */ jsx(Field, { field, isNonbearing, defaultValue: resolvedDefaultValue });
48
+ });
49
+ export {
50
+ FormCheckbox
51
+ };
52
+ //# sourceMappingURL=FormCheckbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormCheckbox.js","sources":["../../../src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useField } from '@contember/react-binding'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst id = useFormFieldId()\n\tconst accessor = useField<boolean>(field)\n\tconst value = accessor.value\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\t(ref as any).current = checkboxRef\n\t\tif (value === null) {\n\t\t\tcheckboxRef.indeterminate = true\n\t\t}\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t\t<SlotInput\n\t\t\t\tref={setCheckboxRef}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\tchecked={accessor.value === true}\n\t\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t\tid={`${id}-input`}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t\t}, [accessorGetter])}\n\t\t\t\t{...props}\n\t\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":[],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AASL,MAAA,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,KAAK;AACL,QAAA,WAAW,SAAkB,KAAK;AACxC,QAAM,QAAQ,SAAS;AACvB,QAAM,SAAS,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAkC,IAAI;AAElF,YAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACC,QAAY,UAAU;AACvB,QAAI,UAAU,MAAM;AACnB,kBAAY,gBAAgB;AAAA,IAC7B;AAAA,EACE,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG1B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK;AAAA,MACL,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAc,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,IAAI,GAAG,EAAE;AAAA,MACT;AAAA,MACA;AAAA,MACA,UAAU,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGR,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const contexts = require("../contexts.cjs");
5
+ const reactBinding = require("@contember/react-binding");
6
+ const FormError = ({ children, formatter }) => {
7
+ const errors = contexts.useFormError();
8
+ const id = contexts.useFormFieldId();
9
+ const formatted = React.useMemo(() => formatter(errors ?? []), [errors, formatter]);
10
+ if (errors === void 0 || id === void 0) {
11
+ throw new reactBinding.BindingError("FormError must be used inside a FormField");
12
+ }
13
+ return formatted.map((it, index) => {
14
+ return React.cloneElement(children, {
15
+ key: index,
16
+ ...{ id: `${id}-error-${index}` },
17
+ children: it
18
+ });
19
+ });
20
+ };
21
+ exports.FormError = FormError;
22
+ //# sourceMappingURL=FormError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormError.cjs","sources":["../../../src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst errors = useFormError()\n\tconst id = useFormFieldId()\n\tconst formatted = useMemo(() => formatter(errors ?? []), [errors, formatter])\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...{ id: `${id}-error-${index}` },\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":["useFormError","useFormFieldId","useMemo","BindingError","cloneElement"],"mappings":";;;;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,SAASA,SAAAA;AACf,QAAM,KAAKC,SAAAA;AACL,QAAA,YAAYC,cAAQ,MAAM,UAAU,UAAU,CAAE,CAAA,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxE,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AACA,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAOC,MAAAA,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAG,EAAE,IAAI,GAAG,EAAE,UAAU,KAAK,GAAG;AAAA,MAChC,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;;"}
@@ -0,0 +1,22 @@
1
+ import { useMemo, cloneElement } from "react";
2
+ import { useFormError, useFormFieldId } from "../contexts.js";
3
+ import { BindingError } from "@contember/react-binding";
4
+ const FormError = ({ children, formatter }) => {
5
+ const errors = useFormError();
6
+ const id = useFormFieldId();
7
+ const formatted = useMemo(() => formatter(errors ?? []), [errors, formatter]);
8
+ if (errors === void 0 || id === void 0) {
9
+ throw new BindingError("FormError must be used inside a FormField");
10
+ }
11
+ return formatted.map((it, index) => {
12
+ return cloneElement(children, {
13
+ key: index,
14
+ ...{ id: `${id}-error-${index}` },
15
+ children: it
16
+ });
17
+ });
18
+ };
19
+ export {
20
+ FormError
21
+ };
22
+ //# sourceMappingURL=FormError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormError.js","sources":["../../../src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormError, useFormFieldId } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst errors = useFormError()\n\tconst id = useFormFieldId()\n\tconst formatted = useMemo(() => formatter(errors ?? []), [errors, formatter])\n\tif (errors === undefined || id === undefined) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...{ id: `${id}-error-${index}` },\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,SAAS;AACf,QAAM,KAAK;AACL,QAAA,YAAY,QAAQ,MAAM,UAAU,UAAU,CAAE,CAAA,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxE,MAAA,WAAW,UAAa,OAAO,QAAW;AACvC,UAAA,IAAI,aAAa,2CAA2C;AAAA,EACnE;AACA,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAO,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAG,EAAE,IAAI,GAAG,EAAE,UAAU,KAAK,GAAG;AAAA,MAChC,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;"}