@cyclone-ui/state 0.0.12 → 0.0.13

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 (167) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -1
  3. package/dist/base/atoms/atom-with-broadcast.cjs +45 -1
  4. package/dist/base/atoms/atom-with-broadcast.mjs +45 -1
  5. package/dist/base/atoms/atom-with-broadcast.mjs.map +1 -1
  6. package/dist/base/atoms/atom-with-compare.cjs +12 -1
  7. package/dist/base/atoms/atom-with-compare.mjs +12 -1
  8. package/dist/base/atoms/atom-with-compare.mjs.map +1 -1
  9. package/dist/base/atoms/atom-with-debounce.cjs +52 -1
  10. package/dist/base/atoms/atom-with-debounce.mjs +52 -1
  11. package/dist/base/atoms/atom-with-debounce.mjs.map +1 -1
  12. package/dist/base/atoms/atom-with-effect.cjs +123 -1
  13. package/dist/base/atoms/atom-with-effect.mjs +120 -1
  14. package/dist/base/atoms/atom-with-effect.mjs.map +1 -1
  15. package/dist/base/atoms/atom-with-listeners.cjs +36 -1
  16. package/dist/base/atoms/atom-with-listeners.mjs +36 -1
  17. package/dist/base/atoms/atom-with-listeners.mjs.map +1 -1
  18. package/dist/base/atoms/atom-with-pending.cjs +14 -1
  19. package/dist/base/atoms/atom-with-pending.mjs +14 -1
  20. package/dist/base/atoms/atom-with-pending.mjs.map +1 -1
  21. package/dist/base/atoms/atom-with-refresh-and-default.cjs +19 -1
  22. package/dist/base/atoms/atom-with-refresh-and-default.mjs +19 -1
  23. package/dist/base/atoms/atom-with-refresh-and-default.mjs.map +1 -1
  24. package/dist/base/atoms/atom-with-refresh.cjs +13 -1
  25. package/dist/base/atoms/atom-with-refresh.mjs +13 -1
  26. package/dist/base/atoms/atom-with-refresh.mjs.map +1 -1
  27. package/dist/base/atoms/atom-with-toggle.cjs +13 -1
  28. package/dist/base/atoms/atom-with-toggle.mjs +13 -1
  29. package/dist/base/atoms/atom-with-toggle.mjs.map +1 -1
  30. package/dist/base/atoms/atom-with-web-storage.cjs +48 -1
  31. package/dist/base/atoms/atom-with-web-storage.mjs +47 -1
  32. package/dist/base/atoms/atom-with-web-storage.mjs.map +1 -1
  33. package/dist/base/atoms/atom-with-wrapper.cjs +25 -1
  34. package/dist/base/atoms/atom-with-wrapper.mjs +25 -1
  35. package/dist/base/atoms/atom-with-wrapper.mjs.map +1 -1
  36. package/dist/base/atoms/base-atom.cjs +25 -1
  37. package/dist/base/atoms/base-atom.mjs +25 -1
  38. package/dist/base/atoms/base-atom.mjs.map +1 -1
  39. package/dist/base/atoms/index.cjs +24 -1
  40. package/dist/base/atoms/index.mjs +13 -1
  41. package/dist/base/hooks/index.cjs +9 -1
  42. package/dist/base/hooks/index.mjs +6 -1
  43. package/dist/base/hooks/use-atom-effect.cjs +17 -1
  44. package/dist/base/hooks/use-atom-effect.mjs +17 -1
  45. package/dist/base/hooks/use-atom-effect.mjs.map +1 -1
  46. package/dist/base/hooks/use-hydrate-molecule.cjs +17 -1
  47. package/dist/base/hooks/use-hydrate-molecule.mjs +17 -1
  48. package/dist/base/hooks/use-hydrate-molecule.mjs.map +1 -1
  49. package/dist/base/hooks/use-prepare-atoms.cjs +20 -1
  50. package/dist/base/hooks/use-prepare-atoms.mjs +20 -1
  51. package/dist/base/hooks/use-prepare-atoms.mjs.map +1 -1
  52. package/dist/base/hooks/use-sync-molecule.cjs +37 -1
  53. package/dist/base/hooks/use-sync-molecule.mjs +37 -1
  54. package/dist/base/hooks/use-sync-molecule.mjs.map +1 -1
  55. package/dist/base/index.cjs +47 -1
  56. package/dist/base/index.mjs +24 -1
  57. package/dist/base/utilities/create-molecule.cjs +105 -4
  58. package/dist/base/utilities/create-molecule.d.cts.map +1 -1
  59. package/dist/base/utilities/create-molecule.mjs +102 -4
  60. package/dist/base/utilities/create-molecule.mjs.map +1 -1
  61. package/dist/base/utilities/create-web-storage.cjs +55 -1
  62. package/dist/base/utilities/create-web-storage.mjs +55 -1
  63. package/dist/base/utilities/create-web-storage.mjs.map +1 -1
  64. package/dist/base/utilities/debounce.cjs +52 -1
  65. package/dist/base/utilities/debounce.mjs +52 -1
  66. package/dist/base/utilities/debounce.mjs.map +1 -1
  67. package/dist/base/utilities/index.cjs +13 -1
  68. package/dist/base/utilities/index.mjs +6 -1
  69. package/dist/base/utilities/is-atom.cjs +48 -1
  70. package/dist/base/utilities/is-atom.mjs +46 -1
  71. package/dist/base/utilities/is-atom.mjs.map +1 -1
  72. package/dist/base/utilities/set-atom-debug.cjs +24 -1
  73. package/dist/base/utilities/set-atom-debug.mjs +23 -1
  74. package/dist/base/utilities/set-atom-debug.mjs.map +1 -1
  75. package/dist/client/index.cjs +16 -1
  76. package/dist/client/index.mjs +8 -1
  77. package/dist/form/atoms/atom-with-field.cjs +23 -1
  78. package/dist/form/atoms/atom-with-field.mjs +23 -1
  79. package/dist/form/atoms/atom-with-field.mjs.map +1 -1
  80. package/dist/form/atoms/atom-with-messages.cjs +85 -1
  81. package/dist/form/atoms/atom-with-messages.mjs +78 -1
  82. package/dist/form/atoms/atom-with-messages.mjs.map +1 -1
  83. package/dist/form/hooks/index.cjs +7 -1
  84. package/dist/form/hooks/index.mjs +5 -1
  85. package/dist/form/hooks/use-field-actions.cjs +92 -1
  86. package/dist/form/hooks/use-field-actions.mjs +92 -1
  87. package/dist/form/hooks/use-field-actions.mjs.map +1 -1
  88. package/dist/form/hooks/use-field-ref.cjs +16 -1
  89. package/dist/form/hooks/use-field-ref.mjs +16 -1
  90. package/dist/form/hooks/use-field-ref.mjs.map +1 -1
  91. package/dist/form/hooks/use-form-actions.cjs +69 -1
  92. package/dist/form/hooks/use-form-actions.mjs +69 -1
  93. package/dist/form/hooks/use-form-actions.mjs.map +1 -1
  94. package/dist/form/index.cjs +30 -1
  95. package/dist/form/index.mjs +17 -1
  96. package/dist/form/molecules/field-molecule.cjs +154 -1
  97. package/dist/form/molecules/field-molecule.mjs +153 -1
  98. package/dist/form/molecules/field-molecule.mjs.map +1 -1
  99. package/dist/form/molecules/form-molecule.cjs +180 -1
  100. package/dist/form/molecules/form-molecule.mjs +179 -1
  101. package/dist/form/molecules/form-molecule.mjs.map +1 -1
  102. package/dist/form/molecules/index.cjs +7 -1
  103. package/dist/form/molecules/index.mjs +4 -1
  104. package/dist/form/providers/FieldProvider.cjs +103 -4
  105. package/dist/form/providers/FieldProvider.mjs +103 -4
  106. package/dist/form/providers/FieldProvider.mjs.map +1 -1
  107. package/dist/form/providers/FormProvider.cjs +66 -4
  108. package/dist/form/providers/FormProvider.d.cts.map +1 -1
  109. package/dist/form/providers/FormProvider.mjs +66 -4
  110. package/dist/form/providers/FormProvider.mjs.map +1 -1
  111. package/dist/form/providers/index.cjs +5 -1
  112. package/dist/form/providers/index.mjs +4 -1
  113. package/dist/form/types.cjs +13 -1
  114. package/dist/form/types.mjs +13 -1
  115. package/dist/form/types.mjs.map +1 -1
  116. package/dist/form/utilities/abort-error.cjs +15 -1
  117. package/dist/form/utilities/abort-error.mjs +15 -1
  118. package/dist/form/utilities/abort-error.mjs.map +1 -1
  119. package/dist/form/utilities/index.cjs +7 -1
  120. package/dist/form/utilities/index.mjs +5 -1
  121. package/dist/form/utilities/is-validation-results.cjs +9 -1
  122. package/dist/form/utilities/is-validation-results.mjs +9 -1
  123. package/dist/form/utilities/is-validation-results.mjs.map +1 -1
  124. package/dist/form/utilities/validators.cjs +8 -1
  125. package/dist/form/utilities/validators.mjs +8 -1
  126. package/dist/form/utilities/validators.mjs.map +1 -1
  127. package/dist/index.cjs +71 -1
  128. package/dist/index.mjs +34 -1
  129. package/dist/message/components/MessageViewport.cjs +21 -6
  130. package/dist/message/components/MessageViewport.mjs +21 -6
  131. package/dist/message/components/MessageViewport.mjs.map +1 -1
  132. package/dist/message/components/index.cjs +3 -1
  133. package/dist/message/components/index.mjs +3 -1
  134. package/dist/message/hooks/index.cjs +3 -1
  135. package/dist/message/hooks/index.mjs +3 -1
  136. package/dist/message/hooks/use-message-actions.cjs +63 -1
  137. package/dist/message/hooks/use-message-actions.mjs +63 -1
  138. package/dist/message/hooks/use-message-actions.mjs.map +1 -1
  139. package/dist/message/index.cjs +23 -1
  140. package/dist/message/index.mjs +8 -1
  141. package/dist/message/providers/MessageProvider.cjs +16 -1
  142. package/dist/message/providers/MessageProvider.mjs +16 -1
  143. package/dist/message/providers/MessageProvider.mjs.map +1 -1
  144. package/dist/theme/hooks/index.cjs +7 -1
  145. package/dist/theme/hooks/index.mjs +4 -1
  146. package/dist/theme/hooks/use-theme-actions.cjs +21 -1
  147. package/dist/theme/hooks/use-theme-actions.mjs +21 -1
  148. package/dist/theme/hooks/use-theme-actions.mjs.map +1 -1
  149. package/dist/theme/hooks/use-theme-store.cjs +61 -1
  150. package/dist/theme/hooks/use-theme-store.d.cts +2 -2
  151. package/dist/theme/hooks/use-theme-store.d.mts +2 -2
  152. package/dist/theme/hooks/use-theme-store.mjs +59 -1
  153. package/dist/theme/hooks/use-theme-store.mjs.map +1 -1
  154. package/dist/theme/index.cjs +17 -1
  155. package/dist/theme/index.mjs +9 -1
  156. package/dist/theme/molecules/index.cjs +3 -1
  157. package/dist/theme/molecules/index.mjs +3 -1
  158. package/dist/theme/molecules/theme-molecule.cjs +14 -1
  159. package/dist/theme/molecules/theme-molecule.mjs +14 -1
  160. package/dist/theme/molecules/theme-molecule.mjs.map +1 -1
  161. package/dist/theme/providers/ThemeProvider.cjs +30 -5
  162. package/dist/theme/providers/ThemeProvider.mjs +30 -5
  163. package/dist/theme/providers/ThemeProvider.mjs.map +1 -1
  164. package/dist/theme/utilities/theme-helpers.cjs +71 -1
  165. package/dist/theme/utilities/theme-helpers.mjs +70 -1
  166. package/dist/theme/utilities/theme-helpers.mjs.map +1 -1
  167. package/package.json +6 -6
@@ -1,2 +1,93 @@
1
- import{FieldApi as e}from"../molecules/field-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{RESET as n,useAtomCallback as r}from"jotai/utils";import{useCallback as i}from"react";import{isPromise as a}from"@stryke/type-checks/is-promise";import{upperCaseFirst as o}from"@stryke/string-format/upper-case-first";const s=()=>{let s=e.useMolecule(),c=r(i(async(e,n,r,i)=>{let c=e(s.options);if(c.validate?.[`on${o(i)}`]&&c.validate[`on${o(i)}`].length>0||c.validate?.[`on${o(t.INITIALIZE)}`]&&c.validate[`on${o(t.INITIALIZE)}`].length>0){let l=e(s.previousValue),u=[];c.validate?.[`on${o(i)}`]&&c.validate[`on${o(i)}`].length>0&&u.push(...c.validate[`on${o(i)}`].map(t=>t(r,l,i,e,n))),i!==t.INITIALIZE&&c.validate?.[`on${o(t.INITIALIZE)}`]&&c.validate[`on${o(t.INITIALIZE)}`].length>0&&u.push(...c.validate[`on${o(t.INITIALIZE)}`].map(t=>t(r,l,i,e,n)));let d=[],f=[];for(let e of u)e&&(a(e)?f.push(e):d.push(...e));if(f.length>0){n(s.validating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(s.validating,!1)}n(s.validationResults,e=>({...e,[i]:d}))}},[])),l=r(i(async(e,t)=>{t(s.value,e(s.initialValue)),t(s.options,n)},[])),u=r(i(async(e,t,n,r=!0)=>{r&&e(s.dirty)||n!==e(s.initialValue)&&t(s.initialValue,n)},[])),d=r(i(async(e,t,n,r=!1)=>{if(!e(s.disabled)){!e(s.touched)&&r&&t(s.touched,r);let i=e(s.options),a=e(s.value),o=n;i.parse&&(o=i.parse(n)),i.isEqual(o,a)||t(s.value,o)}},[])),f=r(i(async(e,t)=>{e(s.disabled)||(e(s.touched)||t(s.touched,!0),t(s.focused,!0))},[])),p=r(i(async(e,t)=>{e(s.disabled)||(e(s.touched)||t(s.touched,!0),t(s.focused,!1),t(s.blurred,!0))},[])),m=i(async e=>e?f():p(),[f,p]),h=r(i(async e=>m(!e(s.focused)),[m]));return{mount:r(i(async(e,t,n,r)=>{if(t(s.ref,n),t(s.tabIndex,r??0),!e(s.initialValue)){let n=e(s.options);t(s.initialValue,n.defaultValue??null)}},[])),initialize:u,change:d,focus:f,blur:p,setFocused:m,toggleFocused:h,validate:c,reset:l}};export{s as useFieldActions};
1
+ import { FieldApi } from "../molecules/field-molecule.mjs";
2
+ import { ValidationCause } from "../types.mjs";
3
+ import { RESET, useAtomCallback } from "jotai/utils";
4
+ import { useCallback } from "react";
5
+ import { isPromise } from "@stryke/type-checks/is-promise";
6
+ import { upperCaseFirst } from "@stryke/string-format/upper-case-first";
7
+
8
+ //#region src/form/hooks/use-field-actions.ts
9
+ const useFieldActions = () => {
10
+ const field = FieldApi.useMolecule();
11
+ const validate = useAtomCallback(useCallback(async (get, set, nextValue, cause) => {
12
+ const options = get(field.options);
13
+ if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0 || options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) {
14
+ const previousValue = get(field.previousValue);
15
+ const results = [];
16
+ if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(cause)}`].map((validator) => validator(nextValue, previousValue, cause, get, set)));
17
+ if (cause !== ValidationCause.INITIALIZE && options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].map((validator) => validator(nextValue, previousValue, cause, get, set)));
18
+ const messages = [];
19
+ const promises = [];
20
+ for (const result of results) if (result) {
21
+ if (isPromise(result)) promises.push(result);
22
+ else messages.push(...result);
23
+ }
24
+ if (promises.length > 0) {
25
+ set(field.validating, true);
26
+ for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
27
+ set(field.validating, false);
28
+ }
29
+ set(field.validationResults, (prev) => ({
30
+ ...prev,
31
+ [cause]: messages
32
+ }));
33
+ }
34
+ }, []));
35
+ const reset = useAtomCallback(useCallback(async (get, set) => {
36
+ set(field.value, get(field.initialValue));
37
+ set(field.options, RESET);
38
+ }, []));
39
+ const initialize = useAtomCallback(useCallback(async (get, set, initialValue, skipIfDirty = true) => {
40
+ if (skipIfDirty && get(field.dirty)) return;
41
+ if (initialValue !== get(field.initialValue)) set(field.initialValue, initialValue);
42
+ }, []));
43
+ const change = useAtomCallback(useCallback(async (get, set, nextValue, touch = false) => {
44
+ if (!get(field.disabled)) {
45
+ if (!get(field.touched) && touch) set(field.touched, touch);
46
+ const options = get(field.options);
47
+ const value = get(field.value);
48
+ let nextParsed = nextValue;
49
+ if (options.parse) nextParsed = options.parse(nextValue);
50
+ if (!options.isEqual(nextParsed, value)) set(field.value, nextParsed);
51
+ }
52
+ }, []));
53
+ const focus = useAtomCallback(useCallback(async (get, set) => {
54
+ if (!get(field.disabled)) {
55
+ if (!get(field.touched)) set(field.touched, true);
56
+ set(field.focused, true);
57
+ }
58
+ }, []));
59
+ const blur = useAtomCallback(useCallback(async (get, set) => {
60
+ if (!get(field.disabled)) {
61
+ if (!get(field.touched)) set(field.touched, true);
62
+ set(field.focused, false);
63
+ set(field.blurred, true);
64
+ }
65
+ }, []));
66
+ const setFocused = useCallback(async (focused) => {
67
+ if (focused) return focus();
68
+ return blur();
69
+ }, [focus, blur]);
70
+ const toggleFocused = useAtomCallback(useCallback(async (get) => setFocused(!get(field.focused)), [setFocused]));
71
+ return {
72
+ mount: useAtomCallback(useCallback(async (get, set, ref, tabIndex) => {
73
+ set(field.ref, ref);
74
+ set(field.tabIndex, tabIndex ?? 0);
75
+ if (!get(field.initialValue)) {
76
+ const options = get(field.options);
77
+ set(field.initialValue, options.defaultValue ?? null);
78
+ }
79
+ }, [])),
80
+ initialize,
81
+ change,
82
+ focus,
83
+ blur,
84
+ setFocused,
85
+ toggleFocused,
86
+ validate,
87
+ reset
88
+ };
89
+ };
90
+
91
+ //#endregion
92
+ export { useFieldActions };
2
93
  //# sourceMappingURL=use-field-actions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-field-actions.mjs","names":["useFieldActions","field","FieldApi","validate","useAtomCallback","useCallback","options","get","upperCaseFirst","cause","ValidationCause","previousValue","results","validator","nextValue","set","messages","promises","result","isPromise","prev","reset","RESET","initialize","skipIfDirty","initialValue","change","touch","value","nextParsed","focus","blur","setFocused","focused","toggleFocused","ref","tabIndex"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"use-field-actions.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,16 @@
1
- const e=require("../molecules/field-molecule.cjs");let t=require("react"),n=require("@maskito/react"),r=require("@tamagui/core");const i=i=>{let a=(0,t.useRef)(null),o=e.FieldApi.use().options.get(),s=[a,(0,n.useMaskito)({options:o.mask})];return i&&s.push(i),(0,r.useComposedRefs)(...s)};exports.useFieldRef=i;
1
+ const require_field_molecule = require("../molecules/field-molecule.cjs");
2
+ let react = require("react");
3
+ let _maskito_react = require("@maskito/react");
4
+ let _tamagui_core = require("@tamagui/core");
5
+
6
+ //#region src/form/hooks/use-field-ref.ts
7
+ const useFieldRef = (forwardedRef) => {
8
+ const ref = (0, react.useRef)(null);
9
+ const options = require_field_molecule.FieldApi.use().options.get();
10
+ const refs = [ref, (0, _maskito_react.useMaskito)({ options: options.mask })];
11
+ if (forwardedRef) refs.push(forwardedRef);
12
+ return (0, _tamagui_core.useComposedRefs)(...refs);
13
+ };
14
+
15
+ //#endregion
16
+ exports.useFieldRef = useFieldRef;
@@ -1,2 +1,17 @@
1
- import{FieldApi as e}from"../molecules/field-molecule.mjs";import{useRef as t}from"react";import{useMaskito as n}from"@maskito/react";import{useComposedRefs as r}from"@tamagui/core";const i=i=>{let a=t(null),o=e.use().options.get(),s=[a,n({options:o.mask})];return i&&s.push(i),r(...s)};export{i as useFieldRef};
1
+ import { FieldApi } from "../molecules/field-molecule.mjs";
2
+ import { useRef } from "react";
3
+ import { useMaskito } from "@maskito/react";
4
+ import { useComposedRefs } from "@tamagui/core";
5
+
6
+ //#region src/form/hooks/use-field-ref.ts
7
+ const useFieldRef = (forwardedRef) => {
8
+ const ref = useRef(null);
9
+ const options = FieldApi.use().options.get();
10
+ const refs = [ref, useMaskito({ options: options.mask })];
11
+ if (forwardedRef) refs.push(forwardedRef);
12
+ return useComposedRefs(...refs);
13
+ };
14
+
15
+ //#endregion
16
+ export { useFieldRef };
2
17
  //# sourceMappingURL=use-field-ref.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-field-ref.mjs","names":["useFieldRef","ref","useRef","options","FieldApi","refs","useMaskito","forwardedRef","useComposedRefs"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"use-field-ref.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,69 @@
1
- const e=require("../molecules/form-molecule.cjs"),t=require("../types.cjs");let n=require("jotai/utils"),r=require("react"),i=require("@stryke/type-checks/is-promise"),a=require("@stryke/string-format/upper-case-first");const o=()=>{let o=e.FormApi.useMolecule();return{initializeField:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{},[])),uninitializeField:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{},[])),validate:(0,n.useAtomCallback)((0,r.useCallback)(async(e,n,r,s)=>{let c=e(o.options);if(c.validate?.[`on${(0,a.upperCaseFirst)(s)}`]&&c.validate[`on${(0,a.upperCaseFirst)(s)}`].length>0||c.validate?.[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`]&&c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].length>0){let l=e(o.previousValues),u=[];c.validate?.[`on${(0,a.upperCaseFirst)(s)}`]&&c.validate[`on${(0,a.upperCaseFirst)(s)}`].length>0&&u.push(...c.validate[`on${(0,a.upperCaseFirst)(s)}`].map(t=>t(r,l,s,e,n))),s!==t.ValidationCause.INITIALIZE&&c.validate?.[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`]&&c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].length>0&&u.push(...c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].map(t=>t(r,l,s,e,n)));let d=[],f=[];for(let e of u)e&&((0,i.isPromise)(e)?f.push(e):d.push(...e));if(f.length>0){n(o.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(o.formValidating,!1)}n(o.validationResults,e=>({...e,[s]:d}))}},[])),change:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{let r=e(o.options),i=e(o.values);r.isEqual(n,i)||t(o.values,n)},[])),submit:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t)=>{e(o.canSubmit)?(e(o.submitting)||t(o.submitting,!0),t(o.submitAttempts,e=>e+1),e(o.options),e(o.values),e(o.valid),t(o.submitting,!1)):e(o.invalid)&&e(o.invalid)},[])),reset:(0,r.useCallback)(()=>{},[])}};exports.useFormActions=o;
1
+ const require_form_molecule = require("../molecules/form-molecule.cjs");
2
+ const require_types = require("../types.cjs");
3
+ let jotai_utils = require("jotai/utils");
4
+ let react = require("react");
5
+ let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
6
+ let _stryke_string_format_upper_case_first = require("@stryke/string-format/upper-case-first");
7
+
8
+ //#region src/form/hooks/use-form-actions.ts
9
+ const useFormActions = () => {
10
+ const form = require_form_molecule.FormApi.useMolecule();
11
+ return {
12
+ initializeField: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (_get, _set, _name) => {}, [])),
13
+ uninitializeField: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (_get, _set, _name) => {}, [])),
14
+ validate: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValues, cause) => {
15
+ const options = get(form.options);
16
+ if (options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].length > 0 || options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].length > 0) {
17
+ const previousValues = get(form.previousValues);
18
+ const results = [];
19
+ if (options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].length > 0) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
20
+ if (cause !== require_types.ValidationCause.INITIALIZE && options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].length > 0) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
21
+ const messages = [];
22
+ const promises = [];
23
+ for (const result of results) if (result) {
24
+ if ((0, _stryke_type_checks_is_promise.isPromise)(result)) promises.push(result);
25
+ else messages.push(...result);
26
+ }
27
+ if (promises.length > 0) {
28
+ set(form.formValidating, true);
29
+ for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
30
+ set(form.formValidating, false);
31
+ }
32
+ set(form.validationResults, (prev) => ({
33
+ ...prev,
34
+ [cause]: messages
35
+ }));
36
+ }
37
+ }, [])),
38
+ change: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValues) => {
39
+ const options = get(form.options);
40
+ const values = get(form.values);
41
+ if (!options.isEqual(nextValues, values)) set(form.values, nextValues);
42
+ }, [])),
43
+ submit: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
44
+ if (get(form.canSubmit)) {
45
+ if (!get(form.submitting)) set(form.submitting, true);
46
+ set(form.submitAttempts, (prev) => prev + 1);
47
+ const options = get(form.options);
48
+ try {
49
+ if (get(form.valid)) {
50
+ await options.onSubmit?.({
51
+ get,
52
+ set,
53
+ atoms: form
54
+ });
55
+ set(form.submitted, true);
56
+ }
57
+ } finally {
58
+ set(form.submitting, false);
59
+ }
60
+ } else if (get(form.invalid)) {
61
+ if (get(form.invalid)) {}
62
+ }
63
+ }, [])),
64
+ reset: (0, react.useCallback)(() => {}, [])
65
+ };
66
+ };
67
+
68
+ //#endregion
69
+ exports.useFormActions = useFormActions;
@@ -1,2 +1,70 @@
1
- import{FormApi as e}from"../molecules/form-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{useAtomCallback as n}from"jotai/utils";import{useCallback as r}from"react";import{isPromise as i}from"@stryke/type-checks/is-promise";import{upperCaseFirst as a}from"@stryke/string-format/upper-case-first";const o=()=>{let o=e.useMolecule();return{initializeField:n(r(async(e,t,n)=>{},[])),uninitializeField:n(r(async(e,t,n)=>{},[])),validate:n(r(async(e,n,r,s)=>{let c=e(o.options);if(c.validate?.[`on${a(s)}`]&&c.validate[`on${a(s)}`].length>0||c.validate?.[`on${a(t.INITIALIZE)}`]&&c.validate[`on${a(t.INITIALIZE)}`].length>0){let l=e(o.previousValues),u=[];c.validate?.[`on${a(s)}`]&&c.validate[`on${a(s)}`].length>0&&u.push(...c.validate[`on${a(s)}`].map(t=>t(r,l,s,e,n))),s!==t.INITIALIZE&&c.validate?.[`on${a(t.INITIALIZE)}`]&&c.validate[`on${a(t.INITIALIZE)}`].length>0&&u.push(...c.validate[`on${a(t.INITIALIZE)}`].map(t=>t(r,l,s,e,n)));let d=[],f=[];for(let e of u)e&&(i(e)?f.push(e):d.push(...e));if(f.length>0){n(o.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(o.formValidating,!1)}n(o.validationResults,e=>({...e,[s]:d}))}},[])),change:n(r(async(e,t,n)=>{let r=e(o.options),i=e(o.values);r.isEqual(n,i)||t(o.values,n)},[])),submit:n(r(async(e,t)=>{e(o.canSubmit)?(e(o.submitting)||t(o.submitting,!0),t(o.submitAttempts,e=>e+1),e(o.options),e(o.values),e(o.valid),t(o.submitting,!1)):e(o.invalid)&&e(o.invalid)},[])),reset:r(()=>{},[])}};export{o as useFormActions};
1
+ import { FormApi } from "../molecules/form-molecule.mjs";
2
+ import { ValidationCause } from "../types.mjs";
3
+ import { useAtomCallback } from "jotai/utils";
4
+ import { useCallback } from "react";
5
+ import { isPromise } from "@stryke/type-checks/is-promise";
6
+ import { upperCaseFirst } from "@stryke/string-format/upper-case-first";
7
+
8
+ //#region src/form/hooks/use-form-actions.ts
9
+ const useFormActions = () => {
10
+ const form = FormApi.useMolecule();
11
+ return {
12
+ initializeField: useAtomCallback(useCallback(async (_get, _set, _name) => {}, [])),
13
+ uninitializeField: useAtomCallback(useCallback(async (_get, _set, _name) => {}, [])),
14
+ validate: useAtomCallback(useCallback(async (get, set, nextValues, cause) => {
15
+ const options = get(form.options);
16
+ if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0 || options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) {
17
+ const previousValues = get(form.previousValues);
18
+ const results = [];
19
+ if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(cause)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
20
+ if (cause !== ValidationCause.INITIALIZE && options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
21
+ const messages = [];
22
+ const promises = [];
23
+ for (const result of results) if (result) {
24
+ if (isPromise(result)) promises.push(result);
25
+ else messages.push(...result);
26
+ }
27
+ if (promises.length > 0) {
28
+ set(form.formValidating, true);
29
+ for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
30
+ set(form.formValidating, false);
31
+ }
32
+ set(form.validationResults, (prev) => ({
33
+ ...prev,
34
+ [cause]: messages
35
+ }));
36
+ }
37
+ }, [])),
38
+ change: useAtomCallback(useCallback(async (get, set, nextValues) => {
39
+ const options = get(form.options);
40
+ const values = get(form.values);
41
+ if (!options.isEqual(nextValues, values)) set(form.values, nextValues);
42
+ }, [])),
43
+ submit: useAtomCallback(useCallback(async (get, set) => {
44
+ if (get(form.canSubmit)) {
45
+ if (!get(form.submitting)) set(form.submitting, true);
46
+ set(form.submitAttempts, (prev) => prev + 1);
47
+ const options = get(form.options);
48
+ try {
49
+ if (get(form.valid)) {
50
+ await options.onSubmit?.({
51
+ get,
52
+ set,
53
+ atoms: form
54
+ });
55
+ set(form.submitted, true);
56
+ }
57
+ } finally {
58
+ set(form.submitting, false);
59
+ }
60
+ } else if (get(form.invalid)) {
61
+ if (get(form.invalid)) {}
62
+ }
63
+ }, [])),
64
+ reset: useCallback(() => {}, [])
65
+ };
66
+ };
67
+
68
+ //#endregion
69
+ export { useFormActions };
2
70
  //# sourceMappingURL=use-form-actions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-form-actions.mjs","names":["useFormActions","form","FormApi","useAtomCallback","useCallback","options","get","upperCaseFirst","cause","ValidationCause","previousValues","results","validator","nextValues","set","messages","promises","result","isPromise","prev","values"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"use-form-actions.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,30 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utilities/is-validation-results.cjs"),t=require("./utilities/validators.cjs"),n=require("./molecules/form-molecule.cjs"),r=require("./molecules/field-molecule.cjs"),i=require("./types.cjs"),a=require("./hooks/use-field-actions.cjs"),o=require("./hooks/use-field-ref.cjs"),s=require("./hooks/use-form-actions.cjs");require("./hooks/index.cjs"),require("./molecules/index.cjs");const c=require("./utilities/abort-error.cjs"),l=require("./providers/FieldProvider.cjs"),u=require("./providers/FormProvider.cjs");require("./providers/index.cjs"),require("./utilities/index.cjs"),exports.AbortError=c.AbortError,exports.DEFAULT_FIELD_OPTIONS=r.DEFAULT_FIELD_OPTIONS,exports.DEFAULT_FORM_OPTIONS=n.DEFAULT_FORM_OPTIONS,exports.FieldApi=r.FieldApi,exports.FieldProvider=l.FieldProvider,exports.FormApi=n.FormApi,exports.FormProvider=u.FormProvider,exports.ValidationCause=i.ValidationCause,exports.isValidationResults=e.isValidationResults,exports.requiredValidator=t.requiredValidator,exports.useFieldActions=a.useFieldActions,exports.useFieldRef=o.useFieldRef,exports.useFormActions=s.useFormActions;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_is_validation_results = require("./utilities/is-validation-results.cjs");
3
+ const require_validators = require("./utilities/validators.cjs");
4
+ const require_form_molecule = require("./molecules/form-molecule.cjs");
5
+ const require_field_molecule = require("./molecules/field-molecule.cjs");
6
+ const require_types = require("./types.cjs");
7
+ const require_use_field_actions = require("./hooks/use-field-actions.cjs");
8
+ const require_use_field_ref = require("./hooks/use-field-ref.cjs");
9
+ const require_use_form_actions = require("./hooks/use-form-actions.cjs");
10
+ require("./hooks/index.cjs");
11
+ require("./molecules/index.cjs");
12
+ const require_abort_error = require("./utilities/abort-error.cjs");
13
+ const require_FieldProvider = require("./providers/FieldProvider.cjs");
14
+ const require_FormProvider = require("./providers/FormProvider.cjs");
15
+ require("./providers/index.cjs");
16
+ require("./utilities/index.cjs");
17
+
18
+ exports.AbortError = require_abort_error.AbortError;
19
+ exports.DEFAULT_FIELD_OPTIONS = require_field_molecule.DEFAULT_FIELD_OPTIONS;
20
+ exports.DEFAULT_FORM_OPTIONS = require_form_molecule.DEFAULT_FORM_OPTIONS;
21
+ exports.FieldApi = require_field_molecule.FieldApi;
22
+ exports.FieldProvider = require_FieldProvider.FieldProvider;
23
+ exports.FormApi = require_form_molecule.FormApi;
24
+ exports.FormProvider = require_FormProvider.FormProvider;
25
+ exports.ValidationCause = require_types.ValidationCause;
26
+ exports.isValidationResults = require_is_validation_results.isValidationResults;
27
+ exports.requiredValidator = require_validators.requiredValidator;
28
+ exports.useFieldActions = require_use_field_actions.useFieldActions;
29
+ exports.useFieldRef = require_use_field_ref.useFieldRef;
30
+ exports.useFormActions = require_use_form_actions.useFormActions;
@@ -1 +1,17 @@
1
- import{isValidationResults as e}from"./utilities/is-validation-results.mjs";import{requiredValidator as t}from"./utilities/validators.mjs";import{DEFAULT_FORM_OPTIONS as n,FormApi as r}from"./molecules/form-molecule.mjs";import{DEFAULT_FIELD_OPTIONS as i,FieldApi as a}from"./molecules/field-molecule.mjs";import{ValidationCause as o}from"./types.mjs";import{useFieldActions as s}from"./hooks/use-field-actions.mjs";import{useFieldRef as c}from"./hooks/use-field-ref.mjs";import{useFormActions as l}from"./hooks/use-form-actions.mjs";import"./hooks/index.mjs";import"./molecules/index.mjs";import{AbortError as u}from"./utilities/abort-error.mjs";import{FieldProvider as d}from"./providers/FieldProvider.mjs";import{FormProvider as f}from"./providers/FormProvider.mjs";import"./providers/index.mjs";import"./utilities/index.mjs";export{u as AbortError,i as DEFAULT_FIELD_OPTIONS,n as DEFAULT_FORM_OPTIONS,a as FieldApi,d as FieldProvider,r as FormApi,f as FormProvider,o as ValidationCause,e as isValidationResults,t as requiredValidator,s as useFieldActions,c as useFieldRef,l as useFormActions};
1
+ import { isValidationResults } from "./utilities/is-validation-results.mjs";
2
+ import { requiredValidator } from "./utilities/validators.mjs";
3
+ import { DEFAULT_FORM_OPTIONS, FormApi } from "./molecules/form-molecule.mjs";
4
+ import { DEFAULT_FIELD_OPTIONS, FieldApi } from "./molecules/field-molecule.mjs";
5
+ import { ValidationCause } from "./types.mjs";
6
+ import { useFieldActions } from "./hooks/use-field-actions.mjs";
7
+ import { useFieldRef } from "./hooks/use-field-ref.mjs";
8
+ import { useFormActions } from "./hooks/use-form-actions.mjs";
9
+ import "./hooks/index.mjs";
10
+ import "./molecules/index.mjs";
11
+ import { AbortError } from "./utilities/abort-error.mjs";
12
+ import { FieldProvider } from "./providers/FieldProvider.mjs";
13
+ import { FormProvider } from "./providers/FormProvider.mjs";
14
+ import "./providers/index.mjs";
15
+ import "./utilities/index.mjs";
16
+
17
+ export { AbortError, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldProvider, FormApi, FormProvider, ValidationCause, isValidationResults, requiredValidator, useFieldActions, useFieldRef, useFormActions };
@@ -1 +1,154 @@
1
- const e=require("../../base/utilities/create-molecule.cjs");require("../../base/index.cjs");const t=require("../atoms/atom-with-field.cjs"),n=require("../atoms/atom-with-messages.cjs"),r=require("../utilities/validators.cjs"),i=require("./form-molecule.cjs");let a=require("@stryke/type-checks/is-function"),o=require("jotai/utils"),s=require("@stryke/helpers/is-equal"),c=require("jotai"),l=require("@stryke/type-checks/is-string"),u=require("@stryke/helpers/deep-merge"),ee=require("@stryke/helpers/get-field"),d=require("@stryke/helpers/to-path"),f=require("@stryke/type-checks/is-set"),p=require("jotai-optics");const m={theme:`base`,size:`md`,debounceMs:100,isEqual:s.isEqual,required:!1,disabled:!1,clearable:!1,initialValue:null},h=e.createMoleculeApi(s=>{let h=e.use(i.FormApi.Scope),g=(0,c.atom)(()=>h),_=e.use(i.FormApi.Molecule),v=(0,c.atom)(m),y=(0,c.atom)(e=>{let t=e(_.options),n=e(v),i=(0,u.deepMerge)(t.defaultFieldOptions,n);return(0,u.deepMerge)({validate:{onBlur:i.required?[r.requiredValidator]:[]}},i)},(e,t,n)=>{let r={};r=(0,a.isFunction)(n)?n(e(v)):n===o.RESET?{}:n,t(v,(0,u.deepMerge)(m,r))}),b=`${h}-`,x=(0,d.toPath)(s.startsWith(b)?s.slice(b.length):s.includes(`-`)?s.slice(s.indexOf(`-`)+1):s),S=(0,c.atom)(()=>x),C=(0,c.atom)(e=>e(S).slice(-1)[0]),w=(0,p.focusAtom)(_.focusedFields,e=>e.path(...x)),T=(0,p.focusAtom)(_.requiredFields,e=>e.path(...x)),E=(0,p.focusAtom)(_.disabledFields,e=>e.path(...x)),D=(0,c.atom)(e=>e(T)??e(y).required,(e,t,n)=>{t(T,n)}),O=(0,c.atom)(e=>e(E)??e(y).disabled,(e,t,n)=>{t(E,n)}),k=(0,c.atom)(e=>e(y).clearable),A=(0,p.focusAtom)(_.touchedFields,e=>e.path(...x)),j=(0,p.focusAtom)(_.blurredFields,e=>e.path(...x)),te=(0,p.focusAtom)(_.validatingFields,e=>e.path(...x)),M=(0,p.focusAtom)(_.validationResultsFields,e=>e.path(...x)),ne=(0,p.focusAtom)(_.tabIndexes,e=>e.path(...x)),N=(0,p.focusAtom)(_.refs,e=>e.path(...x)),P=(0,p.focusAtom)(_.initialValues,e=>e.path(...x)),F=(0,p.focusAtom)(_.values,e=>e.path(...x)),I=(0,c.atom)(e=>e(y).isEqual(e(F),e(P))),L=n.atomWithFieldsMessageTypes(M,`danger`),R=n.atomWithFieldsMessageTypes(M,`warning`),z=n.atomWithFieldsMessageTypes(M,`info`),B=n.atomWithFieldsMessageTypes(M,`discovery`),V=n.atomWithFieldsMessageTypes(M,`success`),H=n.atomWithFieldsMessageTypes(M,`positive`),U=n.atomWithFieldsMessageTypes(M,`negative`),W=n.atomWithFieldsMessageList(M,`danger`),G=n.atomWithFieldsMessageList(M,`warning`),K=n.atomWithFieldsMessageList(M,`info`),q=n.atomWithFieldsMessageList(M,`discovery`),J=n.atomWithFieldsMessageList(M,`success`),Y=n.atomWithFieldsMessageList(M,`positive`),X=n.atomWithFieldsMessageList(M,`negative`),Z=(0,c.atom)(e=>e(W).length>0),Q=(0,c.atom)(e=>!e(Z)),re=(0,c.atom)(e=>{let t=e(y),n=e(F),r;return r=t?.format?t.format(n):n,(0,f.isSet)(r)?(0,l.isString)(r)?r:String(r):``}),$=t.atomWithFieldItems(y,F,O),ie=(0,o.splitAtom)($),ae=(0,o.atomWithDefault)(e=>e(y).size??`md`);return{options:y,form:g,name:C,path:S,initialValue:P,previousValue:(0,c.atom)(e=>{let t=e(_.previousValues);return(0,ee.getField)(t,e(S).join(`.`))??null}),value:F,formattedValue:re,focused:w,required:D,disabled:O,clearable:k,touched:A,blurred:j,validating:te,validationResults:M,tabIndex:ne,ref:N,pristine:(0,c.atom)(e=>!e(I)),dirty:I,items:$,itemsAtoms:ie,size:ae,errors:L,warnings:R,info:z,discovery:B,success:V,positive:H,negative:U,dangerMessages:W,warningMessages:G,infoMessages:K,discoveryMessages:q,successMessages:J,positiveMessages:Y,negativeMessages:X,theme:n.atomWithTheme(y,W,G,K,q,J,Y,X),messages:n.atomWithMessages(W,G,K,q,J,Y,X),invalid:Z,valid:Q}},{type:`field`});exports.DEFAULT_FIELD_OPTIONS=m,exports.FieldApi=h;
1
+ const require_create_molecule = require("../../base/utilities/create-molecule.cjs");
2
+ require("../../base/index.cjs");
3
+ const require_atom_with_field = require("../atoms/atom-with-field.cjs");
4
+ const require_atom_with_messages = require("../atoms/atom-with-messages.cjs");
5
+ const require_validators = require("../utilities/validators.cjs");
6
+ const require_form_molecule = require("./form-molecule.cjs");
7
+ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
8
+ let jotai_utils = require("jotai/utils");
9
+ let _stryke_helpers_is_equal = require("@stryke/helpers/is-equal");
10
+ let jotai = require("jotai");
11
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
12
+ let _stryke_helpers_deep_merge = require("@stryke/helpers/deep-merge");
13
+ let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
14
+ let _stryke_helpers_to_path = require("@stryke/helpers/to-path");
15
+ let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
16
+ let jotai_optics = require("jotai-optics");
17
+
18
+ //#region src/form/molecules/field-molecule.ts
19
+ const DEFAULT_FIELD_OPTIONS = {
20
+ theme: "base",
21
+ size: "md",
22
+ debounceMs: 100,
23
+ isEqual: _stryke_helpers_is_equal.isEqual,
24
+ required: false,
25
+ disabled: false,
26
+ clearable: false,
27
+ initialValue: null
28
+ };
29
+ const FieldApi = require_create_molecule.createMoleculeApi((scope) => {
30
+ const formScope = require_create_molecule.use(require_form_molecule.FormApi.Scope);
31
+ const formScopeAtom = (0, jotai.atom)(() => formScope);
32
+ const form = require_create_molecule.use(require_form_molecule.FormApi.Molecule);
33
+ const optionsBaseAtom = (0, jotai.atom)(DEFAULT_FIELD_OPTIONS);
34
+ const optionsAtom = (0, jotai.atom)((get) => {
35
+ const formOptions = get(form.options);
36
+ const options = get(optionsBaseAtom);
37
+ const result = (0, _stryke_helpers_deep_merge.deepMerge)(formOptions.defaultFieldOptions, options);
38
+ return (0, _stryke_helpers_deep_merge.deepMerge)({ validate: { onBlur: result.required ? [require_validators.requiredValidator] : [] } }, result);
39
+ }, (get, set, update) => {
40
+ let nextValue = {};
41
+ if ((0, _stryke_type_checks_is_function.isFunction)(update)) nextValue = update(get(optionsBaseAtom));
42
+ else if (update === jotai_utils.RESET) nextValue = {};
43
+ else nextValue = update;
44
+ set(optionsBaseAtom, (0, _stryke_helpers_deep_merge.deepMerge)(DEFAULT_FIELD_OPTIONS, nextValue));
45
+ });
46
+ const formPrefix = `${formScope}-`;
47
+ const path = (0, _stryke_helpers_to_path.toPath)(scope.startsWith(formPrefix) ? scope.slice(formPrefix.length) : scope.includes("-") ? scope.slice(scope.indexOf("-") + 1) : scope);
48
+ const pathAtom = (0, jotai.atom)(() => path);
49
+ const nameAtom = (0, jotai.atom)((get) => get(pathAtom).slice(-1)[0]);
50
+ const focusedAtom = (0, jotai_optics.focusAtom)(form.focusedFields, (optic) => optic.path(...path));
51
+ const requiredStateAtom = (0, jotai_optics.focusAtom)(form.requiredFields, (optic) => optic.path(...path));
52
+ const disabledStateAtom = (0, jotai_optics.focusAtom)(form.disabledFields, (optic) => optic.path(...path));
53
+ const requiredAtom = (0, jotai.atom)((get) => get(requiredStateAtom) ?? get(optionsAtom).required, (_get, set, update) => {
54
+ set(requiredStateAtom, update);
55
+ });
56
+ const disabledAtom = (0, jotai.atom)((get) => get(disabledStateAtom) ?? get(optionsAtom).disabled, (_get, set, update) => {
57
+ set(disabledStateAtom, update);
58
+ });
59
+ const clearableAtom = (0, jotai.atom)((get) => get(optionsAtom).clearable);
60
+ const touchedAtom = (0, jotai_optics.focusAtom)(form.touchedFields, (optic) => optic.path(...path));
61
+ const blurredAtom = (0, jotai_optics.focusAtom)(form.blurredFields, (optic) => optic.path(...path));
62
+ const validatingAtom = (0, jotai_optics.focusAtom)(form.validatingFields, (optic) => optic.path(...path));
63
+ const validationResultsAtom = (0, jotai_optics.focusAtom)(form.validationResultsFields, (optic) => optic.path(...path));
64
+ const tabIndexAtom = (0, jotai_optics.focusAtom)(form.tabIndexes, (optic) => optic.path(...path));
65
+ const refAtom = (0, jotai_optics.focusAtom)(form.refs, (optic) => optic.path(...path));
66
+ const initialValueAtom = (0, jotai_optics.focusAtom)(form.initialValues, (optic) => optic.path(...path));
67
+ const valueAtom = (0, jotai_optics.focusAtom)(form.values, (optic) => optic.path(...path));
68
+ const dirtyAtom = (0, jotai.atom)((get) => {
69
+ return get(optionsAtom).isEqual(get(valueAtom), get(initialValueAtom));
70
+ });
71
+ const errorsAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "danger");
72
+ const warningsAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "warning");
73
+ const infoAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "info");
74
+ const discoveryAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "discovery");
75
+ const successesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "success");
76
+ const positivesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "positive");
77
+ const negativesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "negative");
78
+ const errorMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "danger");
79
+ const warningMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "warning");
80
+ const infoMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "info");
81
+ const discoveryMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "discovery");
82
+ const successMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "success");
83
+ const positiveMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "positive");
84
+ const negativeMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "negative");
85
+ const invalidAtom = (0, jotai.atom)((get) => {
86
+ return get(errorMessagesAtom).length > 0;
87
+ });
88
+ const validAtom = (0, jotai.atom)((get) => !get(invalidAtom));
89
+ const formattedValueAtom = (0, jotai.atom)((get) => {
90
+ const options = get(optionsAtom);
91
+ const value = get(valueAtom);
92
+ let formattedValue;
93
+ if (options?.format) formattedValue = options.format(value);
94
+ else formattedValue = value;
95
+ if (!(0, _stryke_type_checks_is_set.isSet)(formattedValue)) return "";
96
+ else if ((0, _stryke_type_checks_is_string.isString)(formattedValue)) return formattedValue;
97
+ return String(formattedValue);
98
+ });
99
+ const itemsAtom = require_atom_with_field.atomWithFieldItems(optionsAtom, valueAtom, disabledAtom);
100
+ const itemsAtomsAtom = (0, jotai_utils.splitAtom)(itemsAtom);
101
+ const sizeAtom = (0, jotai_utils.atomWithDefault)((get) => {
102
+ return get(optionsAtom).size ?? "md";
103
+ });
104
+ return {
105
+ options: optionsAtom,
106
+ form: formScopeAtom,
107
+ name: nameAtom,
108
+ path: pathAtom,
109
+ initialValue: initialValueAtom,
110
+ previousValue: (0, jotai.atom)((get) => {
111
+ const previousValues = get(form.previousValues);
112
+ return (0, _stryke_helpers_get_field.getField)(previousValues, get(pathAtom).join(".")) ?? null;
113
+ }),
114
+ value: valueAtom,
115
+ formattedValue: formattedValueAtom,
116
+ focused: focusedAtom,
117
+ required: requiredAtom,
118
+ disabled: disabledAtom,
119
+ clearable: clearableAtom,
120
+ touched: touchedAtom,
121
+ blurred: blurredAtom,
122
+ validating: validatingAtom,
123
+ validationResults: validationResultsAtom,
124
+ tabIndex: tabIndexAtom,
125
+ ref: refAtom,
126
+ pristine: (0, jotai.atom)((get) => !get(dirtyAtom)),
127
+ dirty: dirtyAtom,
128
+ items: itemsAtom,
129
+ itemsAtoms: itemsAtomsAtom,
130
+ size: sizeAtom,
131
+ errors: errorsAtom,
132
+ warnings: warningsAtom,
133
+ info: infoAtom,
134
+ discovery: discoveryAtom,
135
+ success: successesAtom,
136
+ positive: positivesAtom,
137
+ negative: negativesAtom,
138
+ dangerMessages: errorMessagesAtom,
139
+ warningMessages: warningMessagesAtom,
140
+ infoMessages: infoMessagesAtom,
141
+ discoveryMessages: discoveryMessagesAtom,
142
+ successMessages: successMessagesAtom,
143
+ positiveMessages: positiveMessagesAtom,
144
+ negativeMessages: negativeMessagesAtom,
145
+ theme: require_atom_with_messages.atomWithTheme(optionsAtom, errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
146
+ messages: require_atom_with_messages.atomWithMessages(errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
147
+ invalid: invalidAtom,
148
+ valid: validAtom
149
+ };
150
+ }, { type: "field" });
151
+
152
+ //#endregion
153
+ exports.DEFAULT_FIELD_OPTIONS = DEFAULT_FIELD_OPTIONS;
154
+ exports.FieldApi = FieldApi;