@cyclone-ui/state 0.0.30 → 0.0.32

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 (160) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/base/atoms/atom-with-broadcast.cjs +1 -44
  3. package/dist/base/atoms/atom-with-broadcast.mjs +1 -44
  4. package/dist/base/atoms/atom-with-broadcast.mjs.map +1 -1
  5. package/dist/base/atoms/atom-with-compare.cjs +1 -11
  6. package/dist/base/atoms/atom-with-compare.mjs +1 -11
  7. package/dist/base/atoms/atom-with-compare.mjs.map +1 -1
  8. package/dist/base/atoms/atom-with-debounce.cjs +1 -51
  9. package/dist/base/atoms/atom-with-debounce.mjs +1 -51
  10. package/dist/base/atoms/atom-with-debounce.mjs.map +1 -1
  11. package/dist/base/atoms/atom-with-effect.cjs +1 -122
  12. package/dist/base/atoms/atom-with-effect.mjs +1 -119
  13. package/dist/base/atoms/atom-with-effect.mjs.map +1 -1
  14. package/dist/base/atoms/atom-with-listeners.cjs +1 -35
  15. package/dist/base/atoms/atom-with-listeners.mjs +1 -35
  16. package/dist/base/atoms/atom-with-listeners.mjs.map +1 -1
  17. package/dist/base/atoms/atom-with-pending.cjs +1 -13
  18. package/dist/base/atoms/atom-with-pending.mjs +1 -13
  19. package/dist/base/atoms/atom-with-pending.mjs.map +1 -1
  20. package/dist/base/atoms/atom-with-refresh-and-default.cjs +1 -18
  21. package/dist/base/atoms/atom-with-refresh-and-default.mjs +1 -18
  22. package/dist/base/atoms/atom-with-refresh-and-default.mjs.map +1 -1
  23. package/dist/base/atoms/atom-with-refresh.cjs +1 -12
  24. package/dist/base/atoms/atom-with-refresh.mjs +1 -12
  25. package/dist/base/atoms/atom-with-refresh.mjs.map +1 -1
  26. package/dist/base/atoms/atom-with-toggle.cjs +1 -12
  27. package/dist/base/atoms/atom-with-toggle.mjs +1 -12
  28. package/dist/base/atoms/atom-with-toggle.mjs.map +1 -1
  29. package/dist/base/atoms/atom-with-web-storage.cjs +1 -47
  30. package/dist/base/atoms/atom-with-web-storage.mjs +1 -46
  31. package/dist/base/atoms/atom-with-web-storage.mjs.map +1 -1
  32. package/dist/base/atoms/atom-with-wrapper.cjs +1 -24
  33. package/dist/base/atoms/atom-with-wrapper.mjs +1 -24
  34. package/dist/base/atoms/atom-with-wrapper.mjs.map +1 -1
  35. package/dist/base/atoms/base-atom.cjs +1 -24
  36. package/dist/base/atoms/base-atom.mjs +1 -24
  37. package/dist/base/atoms/base-atom.mjs.map +1 -1
  38. package/dist/base/atoms/index.cjs +1 -24
  39. package/dist/base/atoms/index.mjs +1 -13
  40. package/dist/base/hooks/index.cjs +1 -9
  41. package/dist/base/hooks/index.mjs +1 -6
  42. package/dist/base/hooks/use-atom-effect.cjs +1 -16
  43. package/dist/base/hooks/use-atom-effect.mjs +1 -16
  44. package/dist/base/hooks/use-atom-effect.mjs.map +1 -1
  45. package/dist/base/hooks/use-hydrate-molecule.cjs +1 -16
  46. package/dist/base/hooks/use-hydrate-molecule.mjs +1 -16
  47. package/dist/base/hooks/use-hydrate-molecule.mjs.map +1 -1
  48. package/dist/base/hooks/use-prepare-atoms.cjs +1 -19
  49. package/dist/base/hooks/use-prepare-atoms.mjs +1 -19
  50. package/dist/base/hooks/use-prepare-atoms.mjs.map +1 -1
  51. package/dist/base/hooks/use-sync-molecule.cjs +1 -36
  52. package/dist/base/hooks/use-sync-molecule.mjs +1 -36
  53. package/dist/base/hooks/use-sync-molecule.mjs.map +1 -1
  54. package/dist/base/index.cjs +1 -47
  55. package/dist/base/index.mjs +1 -24
  56. package/dist/base/utilities/create-molecule.cjs +1 -104
  57. package/dist/base/utilities/create-molecule.mjs +1 -101
  58. package/dist/base/utilities/create-molecule.mjs.map +1 -1
  59. package/dist/base/utilities/create-web-storage.cjs +1 -54
  60. package/dist/base/utilities/create-web-storage.mjs +1 -54
  61. package/dist/base/utilities/create-web-storage.mjs.map +1 -1
  62. package/dist/base/utilities/debounce.cjs +1 -51
  63. package/dist/base/utilities/debounce.mjs +1 -51
  64. package/dist/base/utilities/debounce.mjs.map +1 -1
  65. package/dist/base/utilities/index.cjs +1 -13
  66. package/dist/base/utilities/index.mjs +1 -6
  67. package/dist/base/utilities/is-atom.cjs +1 -47
  68. package/dist/base/utilities/is-atom.mjs +1 -45
  69. package/dist/base/utilities/is-atom.mjs.map +1 -1
  70. package/dist/base/utilities/set-atom-debug.cjs +1 -23
  71. package/dist/base/utilities/set-atom-debug.mjs +1 -22
  72. package/dist/base/utilities/set-atom-debug.mjs.map +1 -1
  73. package/dist/form/atoms/atom-with-field.cjs +1 -22
  74. package/dist/form/atoms/atom-with-field.mjs +1 -22
  75. package/dist/form/atoms/atom-with-field.mjs.map +1 -1
  76. package/dist/form/atoms/atom-with-messages.cjs +1 -84
  77. package/dist/form/atoms/atom-with-messages.mjs +1 -77
  78. package/dist/form/atoms/atom-with-messages.mjs.map +1 -1
  79. package/dist/form/hooks/index.cjs +1 -7
  80. package/dist/form/hooks/index.mjs +1 -5
  81. package/dist/form/hooks/use-field-actions.cjs +1 -91
  82. package/dist/form/hooks/use-field-actions.mjs +1 -91
  83. package/dist/form/hooks/use-field-actions.mjs.map +1 -1
  84. package/dist/form/hooks/use-field-ref.cjs +1 -15
  85. package/dist/form/hooks/use-field-ref.mjs +1 -15
  86. package/dist/form/hooks/use-field-ref.mjs.map +1 -1
  87. package/dist/form/hooks/use-form-actions.cjs +1 -68
  88. package/dist/form/hooks/use-form-actions.mjs +1 -68
  89. package/dist/form/hooks/use-form-actions.mjs.map +1 -1
  90. package/dist/form/index.cjs +1 -30
  91. package/dist/form/index.mjs +1 -17
  92. package/dist/form/molecules/field-molecule.cjs +1 -156
  93. package/dist/form/molecules/field-molecule.mjs +1 -155
  94. package/dist/form/molecules/field-molecule.mjs.map +1 -1
  95. package/dist/form/molecules/form-molecule.cjs +1 -179
  96. package/dist/form/molecules/form-molecule.mjs +1 -178
  97. package/dist/form/molecules/form-molecule.mjs.map +1 -1
  98. package/dist/form/molecules/index.cjs +1 -7
  99. package/dist/form/molecules/index.mjs +1 -4
  100. package/dist/form/providers/FieldProvider.cjs +1 -102
  101. package/dist/form/providers/FieldProvider.mjs +1 -102
  102. package/dist/form/providers/FieldProvider.mjs.map +1 -1
  103. package/dist/form/providers/FormProvider.cjs +1 -65
  104. package/dist/form/providers/FormProvider.mjs +1 -65
  105. package/dist/form/providers/FormProvider.mjs.map +1 -1
  106. package/dist/form/providers/index.cjs +1 -5
  107. package/dist/form/providers/index.mjs +1 -4
  108. package/dist/form/types.cjs +1 -12
  109. package/dist/form/types.mjs +1 -12
  110. package/dist/form/types.mjs.map +1 -1
  111. package/dist/form/utilities/abort-error.cjs +1 -14
  112. package/dist/form/utilities/abort-error.mjs +1 -14
  113. package/dist/form/utilities/abort-error.mjs.map +1 -1
  114. package/dist/form/utilities/index.cjs +1 -7
  115. package/dist/form/utilities/index.mjs +1 -5
  116. package/dist/form/utilities/is-validation-results.cjs +1 -8
  117. package/dist/form/utilities/is-validation-results.mjs +1 -8
  118. package/dist/form/utilities/is-validation-results.mjs.map +1 -1
  119. package/dist/form/utilities/validators.cjs +1 -7
  120. package/dist/form/utilities/validators.mjs +1 -7
  121. package/dist/form/utilities/validators.mjs.map +1 -1
  122. package/dist/index.cjs +1 -46
  123. package/dist/index.mjs +1 -22
  124. package/dist/message/components/MessageViewport.cjs +1 -20
  125. package/dist/message/components/MessageViewport.mjs +1 -20
  126. package/dist/message/components/MessageViewport.mjs.map +1 -1
  127. package/dist/message/components/index.cjs +1 -3
  128. package/dist/message/components/index.mjs +1 -3
  129. package/dist/message/hooks/index.cjs +1 -3
  130. package/dist/message/hooks/index.mjs +1 -3
  131. package/dist/message/hooks/use-message-actions.cjs +1 -63
  132. package/dist/message/hooks/use-message-actions.mjs +1 -63
  133. package/dist/message/hooks/use-message-actions.mjs.map +1 -1
  134. package/dist/message/index.cjs +1 -23
  135. package/dist/message/index.mjs +1 -8
  136. package/dist/message/providers/MessageProvider.cjs +1 -15
  137. package/dist/message/providers/MessageProvider.mjs +1 -15
  138. package/dist/message/providers/MessageProvider.mjs.map +1 -1
  139. package/dist/theme/hooks/index.cjs +1 -7
  140. package/dist/theme/hooks/index.mjs +1 -4
  141. package/dist/theme/hooks/use-theme-actions.cjs +1 -20
  142. package/dist/theme/hooks/use-theme-actions.mjs +1 -20
  143. package/dist/theme/hooks/use-theme-actions.mjs.map +1 -1
  144. package/dist/theme/hooks/use-theme-store.cjs +1 -60
  145. package/dist/theme/hooks/use-theme-store.mjs +1 -58
  146. package/dist/theme/hooks/use-theme-store.mjs.map +1 -1
  147. package/dist/theme/index.cjs +1 -17
  148. package/dist/theme/index.mjs +1 -9
  149. package/dist/theme/molecules/index.cjs +1 -3
  150. package/dist/theme/molecules/index.mjs +1 -3
  151. package/dist/theme/molecules/theme-molecule.cjs +1 -13
  152. package/dist/theme/molecules/theme-molecule.mjs +1 -13
  153. package/dist/theme/molecules/theme-molecule.mjs.map +1 -1
  154. package/dist/theme/providers/ThemeProvider.cjs +1 -29
  155. package/dist/theme/providers/ThemeProvider.mjs +1 -29
  156. package/dist/theme/providers/ThemeProvider.mjs.map +1 -1
  157. package/dist/theme/utilities/theme-helpers.cjs +1 -70
  158. package/dist/theme/utilities/theme-helpers.mjs +1 -69
  159. package/dist/theme/utilities/theme-helpers.mjs.map +1 -1
  160. package/package.json +3 -3
@@ -1,46 +1,2 @@
1
- import { isFunction } from "@stryke/type-checks/is-function";
2
- import { isPlainObject } from "@stryke/type-checks/is-plain-object";
3
-
4
- // 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
- export { isAtom, isResetAtom, isWritableAtom };
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};
46
2
  //# sourceMappingURL=is-atom.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-atom.mjs","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"is-atom.mjs","names":["isAtom","isPlainObject","value","isFunction","isWritableAtom","isResetAtom"],"sources":[],"mappings":""}
@@ -1,23 +1 @@
1
- let _stryke_env_environment_checks = require("@stryke/env/environment-checks");
2
-
3
- // 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
- exports.setAtomDebugLabel = setAtomDebugLabel;
23
- exports.setAtomDebugPrivate = setAtomDebugPrivate;
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,23 +1,2 @@
1
- import { isDevelopment } from "@stryke/env/environment-checks";
2
-
3
- // 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
- export { setAtomDebugLabel, setAtomDebugPrivate };
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};
23
2
  //# sourceMappingURL=set-atom-debug.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-atom-debug.mjs","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"set-atom-debug.mjs","names":["setAtomDebugLabel","isDevelopment","label","setAtomDebugPrivate"],"sources":[],"mappings":""}
@@ -1,22 +1 @@
1
- let jotai_utils = require("jotai/utils");
2
- let jotai = require("jotai");
3
-
4
- // 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
- exports.atomWithFieldItems = atomWithFieldItems;
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,23 +1,2 @@
1
- import { atomWithDefault } from "jotai/utils";
2
- import { atom } from "jotai";
3
-
4
- // 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
- export { atomWithFieldItems };
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};
23
2
  //# sourceMappingURL=atom-with-field.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"atom-with-field.mjs","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"atom-with-field.mjs","names":["atomWithFieldItems","atomWithDefault","options","get","optionsAtom","value","valueAtom","disabled","disabledAtom","ret","existing","item"],"sources":[],"mappings":""}
@@ -1,84 +1 @@
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
- // 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
- exports.atomWithFieldsMessageList = atomWithFieldsMessageList;
78
- exports.atomWithFieldsMessageTypes = atomWithFieldsMessageTypes;
79
- exports.atomWithMessageTypes = atomWithMessageTypes;
80
- exports.atomWithMessages = atomWithMessages;
81
- exports.atomWithTheme = atomWithTheme;
82
- exports.getFieldsMessageList = getFieldsMessageList;
83
- exports.getFieldsMessageTypes = getFieldsMessageTypes;
84
- exports.getMessageType = getMessageType;
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,78 +1,2 @@
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
- // 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
- export { atomWithFieldsMessageList, atomWithFieldsMessageTypes, atomWithMessageTypes, atomWithMessages, atomWithTheme, getFieldsMessageList, getFieldsMessageTypes, getMessageType };
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};
78
2
  //# sourceMappingURL=atom-with-messages.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"atom-with-messages.mjs","names":[],"sources":[],"mappings":""}
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,7 +1 @@
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
+ 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,5 +1 @@
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
+ 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,91 +1 @@
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
- // 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
- exports.useFieldActions = useFieldActions;
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,92 +1,2 @@
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
- // 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
- export { useFieldActions };
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};
92
2
  //# sourceMappingURL=use-field-actions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-field-actions.mjs","names":[],"sources":[],"mappings":""}
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,15 +1 @@
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
- // 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
- exports.useFieldRef = useFieldRef;
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,16 +1,2 @@
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
- // 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
- export { useFieldRef };
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};
16
2
  //# sourceMappingURL=use-field-ref.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-field-ref.mjs","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"use-field-ref.mjs","names":["useFieldRef","ref","useRef","options","FieldApi","refs","useMaskito","forwardedRef","useComposedRefs"],"sources":[],"mappings":""}