@cyclone-ui/state 0.0.11 → 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 +20 -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 +1,48 @@
1
- let e=require("@stryke/type-checks/is-function"),t=require("@stryke/type-checks/is-plain-object");const n=n=>{try{return(0,t.isPlainObject)(n)&&`read`in n&&(0,e.isFunction)(n.read)}catch{return!1}},r=t=>{try{return n(t)&&`write`in t&&(0,e.isFunction)(t.write)}catch{return!1}},i=e=>{try{return r(e)&&`init`in e}catch{return!1}};exports.isAtom=n,exports.isResetAtom=i,exports.isWritableAtom=r;
1
+ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
2
+ let _stryke_type_checks_is_plain_object = require("@stryke/type-checks/is-plain-object");
3
+
4
+ //#region src/base/utilities/is-atom.ts
5
+ /**
6
+ * Check if the value is a [Jotai](https://jotai.org) `Atom` object
7
+ *
8
+ * @param value - The value to check
9
+ * @returns A boolean indicating whether the value is an `Atom` object
10
+ */
11
+ const isAtom = (value) => {
12
+ try {
13
+ return (0, _stryke_type_checks_is_plain_object.isPlainObject)(value) && "read" in value && (0, _stryke_type_checks_is_function.isFunction)(value.read);
14
+ } catch {
15
+ return false;
16
+ }
17
+ };
18
+ /**
19
+ * Check if the value is a [Jotai](https://jotai.org) `WritableAtom` object
20
+ *
21
+ * @param value - The value to check
22
+ * @returns A boolean indicating whether the value is a `WritableAtom` object
23
+ */
24
+ const isWritableAtom = (value) => {
25
+ try {
26
+ return isAtom(value) && "write" in value && (0, _stryke_type_checks_is_function.isFunction)(value.write);
27
+ } catch {
28
+ return false;
29
+ }
30
+ };
31
+ /**
32
+ * Check if the value is a [Jotai](https://jotai.org) `Atom` object with the ability to reset to it's initial value
33
+ *
34
+ * @param value - The value to check
35
+ * @returns A boolean indicating whether the value is a `Atom` object with the ability to reset to it's initial value
36
+ */
37
+ const isResetAtom = (value) => {
38
+ try {
39
+ return isWritableAtom(value) && "init" in value;
40
+ } catch {
41
+ return false;
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ exports.isAtom = isAtom;
47
+ exports.isResetAtom = isResetAtom;
48
+ exports.isWritableAtom = isWritableAtom;
@@ -1,2 +1,47 @@
1
- import{isFunction as e}from"@stryke/type-checks/is-function";import{isPlainObject as t}from"@stryke/type-checks/is-plain-object";const n=n=>{try{return t(n)&&`read`in n&&e(n.read)}catch{return!1}},r=t=>{try{return n(t)&&`write`in t&&e(t.write)}catch{return!1}},i=e=>{try{return r(e)&&`init`in e}catch{return!1}};export{n as isAtom,i as isResetAtom,r as isWritableAtom};
1
+ import { isFunction } from "@stryke/type-checks/is-function";
2
+ import { isPlainObject } from "@stryke/type-checks/is-plain-object";
3
+
4
+ //#region src/base/utilities/is-atom.ts
5
+ /**
6
+ * Check if the value is a [Jotai](https://jotai.org) `Atom` object
7
+ *
8
+ * @param value - The value to check
9
+ * @returns A boolean indicating whether the value is an `Atom` object
10
+ */
11
+ const isAtom = (value) => {
12
+ try {
13
+ return isPlainObject(value) && "read" in value && isFunction(value.read);
14
+ } catch {
15
+ return false;
16
+ }
17
+ };
18
+ /**
19
+ * Check if the value is a [Jotai](https://jotai.org) `WritableAtom` object
20
+ *
21
+ * @param value - The value to check
22
+ * @returns A boolean indicating whether the value is a `WritableAtom` object
23
+ */
24
+ const isWritableAtom = (value) => {
25
+ try {
26
+ return isAtom(value) && "write" in value && isFunction(value.write);
27
+ } catch {
28
+ return false;
29
+ }
30
+ };
31
+ /**
32
+ * Check if the value is a [Jotai](https://jotai.org) `Atom` object with the ability to reset to it's initial value
33
+ *
34
+ * @param value - The value to check
35
+ * @returns A boolean indicating whether the value is a `Atom` object with the ability to reset to it's initial value
36
+ */
37
+ const isResetAtom = (value) => {
38
+ try {
39
+ return isWritableAtom(value) && "init" in value;
40
+ } catch {
41
+ return false;
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { isAtom, isResetAtom, isWritableAtom };
2
47
  //# sourceMappingURL=is-atom.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-atom.mjs","names":["isAtom","isPlainObject","value","isFunction","isWritableAtom","isResetAtom"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"is-atom.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,24 @@
1
- let e=require("@stryke/env/environment-checks");const t=(t,n)=>{e.isDevelopment&&(t.debugLabel=n)},n=t=>{e.isDevelopment&&(t.debugPrivate=!0)};exports.setAtomDebugLabel=t,exports.setAtomDebugPrivate=n;
1
+ let _stryke_env_environment_checks = require("@stryke/env/environment-checks");
2
+
3
+ //#region src/base/utilities/set-atom-debug.ts
4
+ /**
5
+ * Add a debug label to the Jotai Atom
6
+ *
7
+ * @param atom - The atom to apply the debug label to
8
+ * @param label - The label to apply to the atom
9
+ */
10
+ const setAtomDebugLabel = (atom, label) => {
11
+ if (_stryke_env_environment_checks.isDevelopment) atom.debugLabel = label;
12
+ };
13
+ /**
14
+ * Mark the atom as a *private* or internal
15
+ *
16
+ * @param atom - The atom to mark as private
17
+ */
18
+ const setAtomDebugPrivate = (atom) => {
19
+ if (_stryke_env_environment_checks.isDevelopment) atom.debugPrivate = true;
20
+ };
21
+
22
+ //#endregion
23
+ exports.setAtomDebugLabel = setAtomDebugLabel;
24
+ exports.setAtomDebugPrivate = setAtomDebugPrivate;
@@ -1,2 +1,24 @@
1
- import{isDevelopment as e}from"@stryke/env/environment-checks";const t=(t,n)=>{e&&(t.debugLabel=n)},n=t=>{e&&(t.debugPrivate=!0)};export{t as setAtomDebugLabel,n as setAtomDebugPrivate};
1
+ import { isDevelopment } from "@stryke/env/environment-checks";
2
+
3
+ //#region src/base/utilities/set-atom-debug.ts
4
+ /**
5
+ * Add a debug label to the Jotai Atom
6
+ *
7
+ * @param atom - The atom to apply the debug label to
8
+ * @param label - The label to apply to the atom
9
+ */
10
+ const setAtomDebugLabel = (atom, label) => {
11
+ if (isDevelopment) atom.debugLabel = label;
12
+ };
13
+ /**
14
+ * Mark the atom as a *private* or internal
15
+ *
16
+ * @param atom - The atom to mark as private
17
+ */
18
+ const setAtomDebugPrivate = (atom) => {
19
+ if (isDevelopment) atom.debugPrivate = true;
20
+ };
21
+
22
+ //#endregion
23
+ export { setAtomDebugLabel, setAtomDebugPrivate };
2
24
  //# sourceMappingURL=set-atom-debug.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-atom-debug.mjs","names":["setAtomDebugLabel","isDevelopment","label","setAtomDebugPrivate"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"set-atom-debug.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,16 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../theme/molecules/theme-molecule.cjs"),t=require("../theme/hooks/use-theme-actions.cjs"),n=require("../theme/utilities/theme-helpers.cjs"),r=require("../theme/hooks/use-theme-store.cjs"),i=require("../theme/providers/ThemeProvider.cjs");require("../theme/index.cjs"),exports.ThemeApi=e.ThemeApi,exports.ThemeProvider=i.ThemeProvider,exports.getThemeColorThemeName=n.getThemeColorThemeName,exports.themeColorThemeNameExists=n.themeColorThemeNameExists,exports.useColorThemeName=r.useColorThemeName,exports.useColorThemeNameExists=r.useColorThemeNameExists,exports.useThemeActions=t.useThemeActions,exports.useThemeMode=r.useThemeMode;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_theme_molecule = require("../theme/molecules/theme-molecule.cjs");
3
+ const require_use_theme_actions = require("../theme/hooks/use-theme-actions.cjs");
4
+ const require_theme_helpers = require("../theme/utilities/theme-helpers.cjs");
5
+ const require_use_theme_store = require("../theme/hooks/use-theme-store.cjs");
6
+ const require_ThemeProvider = require("../theme/providers/ThemeProvider.cjs");
7
+ require("../theme/index.cjs");
8
+
9
+ exports.ThemeApi = require_theme_molecule.ThemeApi;
10
+ exports.ThemeProvider = require_ThemeProvider.ThemeProvider;
11
+ exports.getThemeColorThemeName = require_theme_helpers.getThemeColorThemeName;
12
+ exports.themeColorThemeNameExists = require_theme_helpers.themeColorThemeNameExists;
13
+ exports.useColorThemeName = require_use_theme_store.useColorThemeName;
14
+ exports.useColorThemeNameExists = require_use_theme_store.useColorThemeNameExists;
15
+ exports.useThemeActions = require_use_theme_actions.useThemeActions;
16
+ exports.useThemeMode = require_use_theme_store.useThemeMode;
@@ -1 +1,8 @@
1
- import{ThemeApi as e}from"../theme/molecules/theme-molecule.mjs";import{useThemeActions as t}from"../theme/hooks/use-theme-actions.mjs";import{getThemeColorThemeName as n,themeColorThemeNameExists as r}from"../theme/utilities/theme-helpers.mjs";import{useColorThemeName as i,useColorThemeNameExists as a,useThemeMode as o}from"../theme/hooks/use-theme-store.mjs";import{ThemeProvider as s}from"../theme/providers/ThemeProvider.mjs";import"../theme/index.mjs";export{e as ThemeApi,s as ThemeProvider,n as getThemeColorThemeName,r as themeColorThemeNameExists,i as useColorThemeName,a as useColorThemeNameExists,t as useThemeActions,o as useThemeMode};
1
+ import { ThemeApi } from "../theme/molecules/theme-molecule.mjs";
2
+ import { useThemeActions } from "../theme/hooks/use-theme-actions.mjs";
3
+ import { getThemeColorThemeName, themeColorThemeNameExists } from "../theme/utilities/theme-helpers.mjs";
4
+ import { useColorThemeName, useColorThemeNameExists, useThemeMode } from "../theme/hooks/use-theme-store.mjs";
5
+ import { ThemeProvider } from "../theme/providers/ThemeProvider.mjs";
6
+ import "../theme/index.mjs";
7
+
8
+ export { ThemeApi, ThemeProvider, getThemeColorThemeName, themeColorThemeNameExists, useColorThemeName, useColorThemeNameExists, useThemeActions, useThemeMode };
@@ -1 +1,23 @@
1
- let e=require("jotai/utils");require("jotai");const t=(t,n,r)=>(0,e.atomWithDefault)(e=>{let i=e(t),a=e(n),o=e(r);return(i.items??[]).reduce((e,t,n)=>(e.some(e=>e.value===t.value)||e.push({index:n,...t,selected:t.value===a,disabled:!!t.disabled||!!o}),e),[])});exports.atomWithFieldItems=t;
1
+ let jotai_utils = require("jotai/utils");
2
+ let jotai = require("jotai");
3
+
4
+ //#region src/form/atoms/atom-with-field.ts
5
+ const atomWithFieldItems = (optionsAtom, valueAtom, disabledAtom) => {
6
+ return (0, jotai_utils.atomWithDefault)((get) => {
7
+ const options = get(optionsAtom);
8
+ const value = get(valueAtom);
9
+ const disabled = get(disabledAtom);
10
+ return (options.items ?? []).reduce((ret, item, index) => {
11
+ if (!ret.some((existing) => existing.value === item.value)) ret.push({
12
+ index,
13
+ ...item,
14
+ selected: item.value === value,
15
+ disabled: Boolean(item.disabled) || Boolean(disabled)
16
+ });
17
+ return ret;
18
+ }, []);
19
+ });
20
+ };
21
+
22
+ //#endregion
23
+ exports.atomWithFieldItems = atomWithFieldItems;
@@ -1,2 +1,24 @@
1
- import{atomWithDefault as e}from"jotai/utils";import"jotai";const t=(t,n,r)=>e(e=>{let i=e(t),a=e(n),o=e(r);return(i.items??[]).reduce((e,t,n)=>(e.some(e=>e.value===t.value)||e.push({index:n,...t,selected:t.value===a,disabled:!!t.disabled||!!o}),e),[])});export{t as atomWithFieldItems};
1
+ import { atomWithDefault } from "jotai/utils";
2
+ import { atom } from "jotai";
3
+
4
+ //#region src/form/atoms/atom-with-field.ts
5
+ const atomWithFieldItems = (optionsAtom, valueAtom, disabledAtom) => {
6
+ return atomWithDefault((get) => {
7
+ const options = get(optionsAtom);
8
+ const value = get(valueAtom);
9
+ const disabled = get(disabledAtom);
10
+ return (options.items ?? []).reduce((ret, item, index) => {
11
+ if (!ret.some((existing) => existing.value === item.value)) ret.push({
12
+ index,
13
+ ...item,
14
+ selected: item.value === value,
15
+ disabled: Boolean(item.disabled) || Boolean(disabled)
16
+ });
17
+ return ret;
18
+ }, []);
19
+ });
20
+ };
21
+
22
+ //#endregion
23
+ export { atomWithFieldItems };
2
24
  //# sourceMappingURL=atom-with-field.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"atom-with-field.mjs","names":["atomWithFieldItems","atomWithDefault","options","get","optionsAtom","value","valueAtom","disabled","disabledAtom","ret","existing","item"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"atom-with-field.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,85 @@
1
- const e=require("../utilities/is-validation-results.cjs");let t=require("jotai"),n=require("@stryke/type-checks/is-set-object");const r=(e,t)=>{let n=[];return e.initialize&&n.push(...e.initialize.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.change&&n.push(...e.change.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.blur&&n.push(...e.blur.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.server&&n.push(...e.server.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.submit&&n.push(...e.submit.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),n},i=(t,n)=>e.isValidationResults(t)?r(t,n):Object.entries(t).reduce((t,[a,o])=>(t[a]=e.isValidationResults(o)?r(o,n):i(o,n),t),{}),a=(e,n)=>(0,t.atom)(t=>i(t(e),n)),o=(t,i)=>e.isValidationResults(t)?r(t,i):Object.entries(t??{}).reduce((t,[a,s])=>((0,n.isSetObject)(s)&&(e.isValidationResults(s)?t.push(...r(s,i)):t.push(...o(s,i))),t),[]),s=(e,n)=>(0,t.atom)(t=>o(t(e),n)),c=(e,n)=>(0,t.atom)(t=>r(t(e),n)),l=(e,n,r,i,a,o,s)=>(0,t.atom)(t=>{let c=t(e);if(c.length>0)return c;let l=t(n);if(l.length>0)return l;let u=t(r);if(u.length>0)return u;let d=t(i);if(d.length>0)return d;let f=t(a);if(f.length>0)return f;let p=t(o);if(p.length>0)return p;let m=t(s);return m.length>0?m:[]}),u=(e,n,r,i,a,o,s,c)=>(0,t.atom)(t=>{let l=t(e);return t(n).length>0||l.theme?.includes(`danger`)?`danger`:t(r).length>0||l.theme?.includes(`warning`)?`warning`:t(o).length>0||l.theme?.includes(`success`)?`success`:t(i).length>0||l.theme?.includes(`info`)?`info`:t(a).length>0||l.theme?.includes(`discovery`)?`discovery`:t(s).length>0||l.theme?.includes(`positive`)?`positive`:t(c).length>0||l.theme?.includes(`negative`)?`negative`:`base`});exports.atomWithFieldsMessageList=s,exports.atomWithFieldsMessageTypes=a,exports.atomWithMessageTypes=c,exports.atomWithMessages=l,exports.atomWithTheme=u,exports.getFieldsMessageList=o,exports.getFieldsMessageTypes=i,exports.getMessageType=r;
1
+ const require_is_validation_results = require("../utilities/is-validation-results.cjs");
2
+ let jotai = require("jotai");
3
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
4
+
5
+ //#region src/form/atoms/atom-with-messages.ts
6
+ const getMessageType = (validationResults, type) => {
7
+ const messages = [];
8
+ if (validationResults.initialize) messages.push(...validationResults.initialize.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
9
+ if (validationResults.change) messages.push(...validationResults.change.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
10
+ if (validationResults.blur) messages.push(...validationResults.blur.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
11
+ if (validationResults.server) messages.push(...validationResults.server.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
12
+ if (validationResults.submit) messages.push(...validationResults.submit.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
13
+ return messages;
14
+ };
15
+ const getFieldsMessageTypes = (messageMap, type) => {
16
+ if (require_is_validation_results.isValidationResults(messageMap)) return getMessageType(messageMap, type);
17
+ return Object.entries(messageMap).reduce((ret, [field, messages]) => {
18
+ if (!require_is_validation_results.isValidationResults(messages)) ret[field] = getFieldsMessageTypes(messages, type);
19
+ else ret[field] = getMessageType(messages, type);
20
+ return ret;
21
+ }, {});
22
+ };
23
+ const atomWithFieldsMessageTypes = (validationResultsAtom, type) => {
24
+ return (0, jotai.atom)((get) => {
25
+ return getFieldsMessageTypes(get(validationResultsAtom), type);
26
+ });
27
+ };
28
+ const getFieldsMessageList = (messageMap, type) => {
29
+ if (require_is_validation_results.isValidationResults(messageMap)) return getMessageType(messageMap, type);
30
+ return Object.entries(messageMap ?? {}).reduce((ret, [_, messages]) => {
31
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(messages)) {
32
+ if (!require_is_validation_results.isValidationResults(messages)) ret.push(...getFieldsMessageList(messages, type));
33
+ else ret.push(...getMessageType(messages, type));
34
+ }
35
+ return ret;
36
+ }, []);
37
+ };
38
+ const atomWithFieldsMessageList = (validationResultsAtom, type) => {
39
+ return (0, jotai.atom)((get) => {
40
+ return getFieldsMessageList(get(validationResultsAtom), type);
41
+ });
42
+ };
43
+ const atomWithMessageTypes = (validationResultsAtom, type) => {
44
+ return (0, jotai.atom)((get) => {
45
+ return getMessageType(get(validationResultsAtom), type);
46
+ });
47
+ };
48
+ const atomWithMessages = (dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => (0, jotai.atom)((get) => {
49
+ const dangerMessages = get(dangerMessagesAtom);
50
+ if (dangerMessages.length > 0) return dangerMessages;
51
+ const warningMessages = get(warningMessagesAtom);
52
+ if (warningMessages.length > 0) return warningMessages;
53
+ const infoMessages = get(infoMessagesAtom);
54
+ if (infoMessages.length > 0) return infoMessages;
55
+ const discoveryMessages = get(discoveryMessagesAtom);
56
+ if (discoveryMessages.length > 0) return discoveryMessages;
57
+ const successMessages = get(successMessagesAtom);
58
+ if (successMessages.length > 0) return successMessages;
59
+ const positiveMessages = get(positiveMessagesAtom);
60
+ if (positiveMessages.length > 0) return positiveMessages;
61
+ const negativeMessages = get(negativeMessagesAtom);
62
+ if (negativeMessages.length > 0) return negativeMessages;
63
+ return [];
64
+ });
65
+ const atomWithTheme = (optionsAtom, dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => (0, jotai.atom)((get) => {
66
+ const options = get(optionsAtom);
67
+ if (get(dangerMessagesAtom).length > 0 || options.theme?.includes("danger")) return "danger";
68
+ else if (get(warningMessagesAtom).length > 0 || options.theme?.includes("warning")) return "warning";
69
+ else if (get(successMessagesAtom).length > 0 || options.theme?.includes("success")) return "success";
70
+ else if (get(infoMessagesAtom).length > 0 || options.theme?.includes("info")) return "info";
71
+ else if (get(discoveryMessagesAtom).length > 0 || options.theme?.includes("discovery")) return "discovery";
72
+ else if (get(positiveMessagesAtom).length > 0 || options.theme?.includes("positive")) return "positive";
73
+ else if (get(negativeMessagesAtom).length > 0 || options.theme?.includes("negative")) return "negative";
74
+ return "base";
75
+ });
76
+
77
+ //#endregion
78
+ exports.atomWithFieldsMessageList = atomWithFieldsMessageList;
79
+ exports.atomWithFieldsMessageTypes = atomWithFieldsMessageTypes;
80
+ exports.atomWithMessageTypes = atomWithMessageTypes;
81
+ exports.atomWithMessages = atomWithMessages;
82
+ exports.atomWithTheme = atomWithTheme;
83
+ exports.getFieldsMessageList = getFieldsMessageList;
84
+ exports.getFieldsMessageTypes = getFieldsMessageTypes;
85
+ exports.getMessageType = getMessageType;
@@ -1,2 +1,79 @@
1
- import{isValidationResults as e}from"../utilities/is-validation-results.mjs";import{atom as t}from"jotai";import{isSetObject as n}from"@stryke/type-checks/is-set-object";const r=(e,t)=>{let n=[];return e.initialize&&n.push(...e.initialize.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.change&&n.push(...e.change.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.blur&&n.push(...e.blur.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.server&&n.push(...e.server.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),e.submit&&n.push(...e.submit.filter(e=>t===e.type&&(e.message||e.code)&&!n.some(t=>t.message===e.message||t.code===e.code))),n},i=(t,n)=>e(t)?r(t,n):Object.entries(t).reduce((t,[a,o])=>(t[a]=e(o)?r(o,n):i(o,n),t),{}),a=(e,n)=>t(t=>i(t(e),n)),o=(t,i)=>e(t)?r(t,i):Object.entries(t??{}).reduce((t,[a,s])=>(n(s)&&(e(s)?t.push(...r(s,i)):t.push(...o(s,i))),t),[]),s=(e,n)=>t(t=>o(t(e),n)),c=(e,n)=>t(t=>r(t(e),n)),l=(e,n,r,i,a,o,s)=>t(t=>{let c=t(e);if(c.length>0)return c;let l=t(n);if(l.length>0)return l;let u=t(r);if(u.length>0)return u;let d=t(i);if(d.length>0)return d;let f=t(a);if(f.length>0)return f;let p=t(o);if(p.length>0)return p;let m=t(s);return m.length>0?m:[]}),u=(e,n,r,i,a,o,s,c)=>t(t=>{let l=t(e);return t(n).length>0||l.theme?.includes(`danger`)?`danger`:t(r).length>0||l.theme?.includes(`warning`)?`warning`:t(o).length>0||l.theme?.includes(`success`)?`success`:t(i).length>0||l.theme?.includes(`info`)?`info`:t(a).length>0||l.theme?.includes(`discovery`)?`discovery`:t(s).length>0||l.theme?.includes(`positive`)?`positive`:t(c).length>0||l.theme?.includes(`negative`)?`negative`:`base`});export{s as atomWithFieldsMessageList,a as atomWithFieldsMessageTypes,c as atomWithMessageTypes,l as atomWithMessages,u as atomWithTheme,o as getFieldsMessageList,i as getFieldsMessageTypes,r as getMessageType};
1
+ import { isValidationResults } from "../utilities/is-validation-results.mjs";
2
+ import { atom } from "jotai";
3
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
4
+
5
+ //#region src/form/atoms/atom-with-messages.ts
6
+ const getMessageType = (validationResults, type) => {
7
+ const messages = [];
8
+ if (validationResults.initialize) messages.push(...validationResults.initialize.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
9
+ if (validationResults.change) messages.push(...validationResults.change.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
10
+ if (validationResults.blur) messages.push(...validationResults.blur.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
11
+ if (validationResults.server) messages.push(...validationResults.server.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
12
+ if (validationResults.submit) messages.push(...validationResults.submit.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
13
+ return messages;
14
+ };
15
+ const getFieldsMessageTypes = (messageMap, type) => {
16
+ if (isValidationResults(messageMap)) return getMessageType(messageMap, type);
17
+ return Object.entries(messageMap).reduce((ret, [field, messages]) => {
18
+ if (!isValidationResults(messages)) ret[field] = getFieldsMessageTypes(messages, type);
19
+ else ret[field] = getMessageType(messages, type);
20
+ return ret;
21
+ }, {});
22
+ };
23
+ const atomWithFieldsMessageTypes = (validationResultsAtom, type) => {
24
+ return atom((get) => {
25
+ return getFieldsMessageTypes(get(validationResultsAtom), type);
26
+ });
27
+ };
28
+ const getFieldsMessageList = (messageMap, type) => {
29
+ if (isValidationResults(messageMap)) return getMessageType(messageMap, type);
30
+ return Object.entries(messageMap ?? {}).reduce((ret, [_, messages]) => {
31
+ if (isSetObject(messages)) {
32
+ if (!isValidationResults(messages)) ret.push(...getFieldsMessageList(messages, type));
33
+ else ret.push(...getMessageType(messages, type));
34
+ }
35
+ return ret;
36
+ }, []);
37
+ };
38
+ const atomWithFieldsMessageList = (validationResultsAtom, type) => {
39
+ return atom((get) => {
40
+ return getFieldsMessageList(get(validationResultsAtom), type);
41
+ });
42
+ };
43
+ const atomWithMessageTypes = (validationResultsAtom, type) => {
44
+ return atom((get) => {
45
+ return getMessageType(get(validationResultsAtom), type);
46
+ });
47
+ };
48
+ const atomWithMessages = (dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => atom((get) => {
49
+ const dangerMessages = get(dangerMessagesAtom);
50
+ if (dangerMessages.length > 0) return dangerMessages;
51
+ const warningMessages = get(warningMessagesAtom);
52
+ if (warningMessages.length > 0) return warningMessages;
53
+ const infoMessages = get(infoMessagesAtom);
54
+ if (infoMessages.length > 0) return infoMessages;
55
+ const discoveryMessages = get(discoveryMessagesAtom);
56
+ if (discoveryMessages.length > 0) return discoveryMessages;
57
+ const successMessages = get(successMessagesAtom);
58
+ if (successMessages.length > 0) return successMessages;
59
+ const positiveMessages = get(positiveMessagesAtom);
60
+ if (positiveMessages.length > 0) return positiveMessages;
61
+ const negativeMessages = get(negativeMessagesAtom);
62
+ if (negativeMessages.length > 0) return negativeMessages;
63
+ return [];
64
+ });
65
+ const atomWithTheme = (optionsAtom, dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => atom((get) => {
66
+ const options = get(optionsAtom);
67
+ if (get(dangerMessagesAtom).length > 0 || options.theme?.includes("danger")) return "danger";
68
+ else if (get(warningMessagesAtom).length > 0 || options.theme?.includes("warning")) return "warning";
69
+ else if (get(successMessagesAtom).length > 0 || options.theme?.includes("success")) return "success";
70
+ else if (get(infoMessagesAtom).length > 0 || options.theme?.includes("info")) return "info";
71
+ else if (get(discoveryMessagesAtom).length > 0 || options.theme?.includes("discovery")) return "discovery";
72
+ else if (get(positiveMessagesAtom).length > 0 || options.theme?.includes("positive")) return "positive";
73
+ else if (get(negativeMessagesAtom).length > 0 || options.theme?.includes("negative")) return "negative";
74
+ return "base";
75
+ });
76
+
77
+ //#endregion
78
+ export { atomWithFieldsMessageList, atomWithFieldsMessageTypes, atomWithMessageTypes, atomWithMessages, atomWithTheme, getFieldsMessageList, getFieldsMessageTypes, getMessageType };
2
79
  //# sourceMappingURL=atom-with-messages.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"atom-with-messages.mjs","names":["getMessageType","messages","validationResults","type","message","existing","getFieldsMessageTypes","isValidationResults","messageMap","field","ret","atomWithFieldsMessageTypes","atom","get","validationResultsAtom","getFieldsMessageList","_","isSetObject","atomWithFieldsMessageList","atomWithMessageTypes","atomWithMessages","dangerMessages","dangerMessagesAtom","warningMessages","warningMessagesAtom","infoMessages","infoMessagesAtom","discoveryMessages","discoveryMessagesAtom","successMessages","successMessagesAtom","positiveMessages","positiveMessagesAtom","negativeMessages","negativeMessagesAtom","atomWithTheme","options","optionsAtom"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"atom-with-messages.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +1,7 @@
1
- const e=require("./use-field-actions.cjs"),t=require("./use-field-ref.cjs"),n=require("./use-form-actions.cjs");exports.useFieldActions=e.useFieldActions,exports.useFieldRef=t.useFieldRef,exports.useFormActions=n.useFormActions;
1
+ const require_use_field_actions = require("./use-field-actions.cjs");
2
+ const require_use_field_ref = require("./use-field-ref.cjs");
3
+ const require_use_form_actions = require("./use-form-actions.cjs");
4
+
5
+ exports.useFieldActions = require_use_field_actions.useFieldActions;
6
+ exports.useFieldRef = require_use_field_ref.useFieldRef;
7
+ exports.useFormActions = require_use_form_actions.useFormActions;
@@ -1 +1,5 @@
1
- import{useFieldActions as e}from"./use-field-actions.mjs";import{useFieldRef as t}from"./use-field-ref.mjs";import{useFormActions as n}from"./use-form-actions.mjs";export{e as useFieldActions,t as useFieldRef,n as useFormActions};
1
+ import { useFieldActions } from "./use-field-actions.mjs";
2
+ import { useFieldRef } from "./use-field-ref.mjs";
3
+ import { useFormActions } from "./use-form-actions.mjs";
4
+
5
+ export { useFieldActions, useFieldRef, useFormActions };
@@ -1 +1,92 @@
1
- const e=require("../molecules/field-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.FieldApi.useMolecule(),s=(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.previousValue),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.validating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(o.validating,!1)}n(o.validationResults,e=>({...e,[s]:d}))}},[])),c=(0,n.useAtomCallback)((0,r.useCallback)(async(e,t)=>{t(o.value,e(o.initialValue)),t(o.options,n.RESET)},[])),l=(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n,r=!0)=>{r&&e(o.dirty)||n!==e(o.initialValue)&&t(o.initialValue,n)},[])),u=(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n,r=!1)=>{if(!e(o.disabled)){!e(o.touched)&&r&&t(o.touched,r);let i=e(o.options),a=e(o.value),s=n;i.parse&&(s=i.parse(n)),i.isEqual(s,a)||t(o.value,s)}},[])),d=(0,n.useAtomCallback)((0,r.useCallback)(async(e,t)=>{e(o.disabled)||(e(o.touched)||t(o.touched,!0),t(o.focused,!0))},[])),f=(0,n.useAtomCallback)((0,r.useCallback)(async(e,t)=>{e(o.disabled)||(e(o.touched)||t(o.touched,!0),t(o.focused,!1),t(o.blurred,!0))},[])),p=(0,r.useCallback)(async e=>e?d():f(),[d,f]),m=(0,n.useAtomCallback)((0,r.useCallback)(async e=>p(!e(o.focused)),[p]));return{mount:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n,r)=>{if(t(o.ref,n),t(o.tabIndex,r??0),!e(o.initialValue)){let n=e(o.options);t(o.initialValue,n.defaultValue??null)}},[])),initialize:l,change:u,focus:d,blur:f,setFocused:p,toggleFocused:m,validate:s,reset:c}};exports.useFieldActions=o;
1
+ const require_field_molecule = require("../molecules/field-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-field-actions.ts
9
+ const useFieldActions = () => {
10
+ const field = require_field_molecule.FieldApi.useMolecule();
11
+ const validate = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValue, cause) => {
12
+ const options = get(field.options);
13
+ 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) {
14
+ const previousValue = get(field.previousValue);
15
+ const results = [];
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) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].map((validator) => validator(nextValue, previousValue, cause, get, set)));
17
+ 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(nextValue, previousValue, cause, get, set)));
18
+ const messages = [];
19
+ const promises = [];
20
+ for (const result of results) if (result) {
21
+ if ((0, _stryke_type_checks_is_promise.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 = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
36
+ set(field.value, get(field.initialValue));
37
+ set(field.options, jotai_utils.RESET);
38
+ }, []));
39
+ const initialize = (0, jotai_utils.useAtomCallback)((0, react.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 = (0, jotai_utils.useAtomCallback)((0, react.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 = (0, jotai_utils.useAtomCallback)((0, react.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 = (0, jotai_utils.useAtomCallback)((0, react.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 = (0, react.useCallback)(async (focused) => {
67
+ if (focused) return focus();
68
+ return blur();
69
+ }, [focus, blur]);
70
+ const toggleFocused = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get) => setFocused(!get(field.focused)), [setFocused]));
71
+ return {
72
+ mount: (0, jotai_utils.useAtomCallback)((0, react.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
+ exports.useFieldActions = useFieldActions;