@boomerang-io/carbon-addons-boomerang-react 4.6.10-beta.6 → 4.6.11-beta.1

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 (255) hide show
  1. package/README.md +162 -162
  2. package/dist/cjs/components/AboutPlatform/AboutPlatform.js +50 -50
  3. package/dist/cjs/components/AdvantageSideNav/AdvantageSideNav.js +242 -224
  4. package/dist/cjs/components/AutoSuggest/AutoSuggest.js +101 -101
  5. package/dist/cjs/components/Avatar/Avatar.js +18 -18
  6. package/dist/cjs/components/CheckboxList/CheckboxList.js +34 -34
  7. package/dist/cjs/components/ComboBox/ComboBox.js +103 -103
  8. package/dist/cjs/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
  9. package/dist/cjs/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
  10. package/dist/cjs/components/ComposedModal/ComposedModal.js +80 -80
  11. package/dist/cjs/components/ConfirmModal/ConfirmModal.js +43 -43
  12. package/dist/cjs/components/Creatable/Creatable.js +137 -137
  13. package/dist/cjs/components/DataDrivenInput/DataDrivenInput.js +226 -226
  14. package/dist/cjs/components/DateInput/DateInput.js +35 -35
  15. package/dist/cjs/components/DecisionButtons/DecisionButtons.js +61 -61
  16. package/dist/cjs/components/DelayedRender/DelayedRender.js +17 -17
  17. package/dist/cjs/components/DynamicFormik/DynamicFormik.js +578 -578
  18. package/dist/cjs/components/Error403/Error403.js +13 -13
  19. package/dist/cjs/components/Error403/ForbiddenErrorBackground.js +113 -113
  20. package/dist/cjs/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
  21. package/dist/cjs/components/Error404/Error404.js +13 -13
  22. package/dist/cjs/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
  23. package/dist/cjs/components/Error404/NotFoundErrorBackground.js +129 -129
  24. package/dist/cjs/components/ErrorBoundary/ErrorBoundary.js +32 -32
  25. package/dist/cjs/components/ErrorDragon/ErrorDragon.js +13 -13
  26. package/dist/cjs/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
  27. package/dist/cjs/components/ErrorFullPage/ErrorFullPage.js +10 -10
  28. package/dist/cjs/components/ErrorMessage/ErrorMessage.js +22 -22
  29. package/dist/cjs/components/ErrorPage/ErrorPage.js +11 -11
  30. package/dist/cjs/components/ErrorPageCore/ErrorPageCore.js +15 -15
  31. package/dist/cjs/components/ErrorPageCore/GenericErrorBackground.js +124 -124
  32. package/dist/cjs/components/FeatureHeader/FeatureHeader.js +29 -29
  33. package/dist/cjs/components/FeatureNavTab/FeatureNavTab.js +12 -12
  34. package/dist/cjs/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
  35. package/dist/cjs/components/FeatureSideNav/FeatureSideNav.js +12 -12
  36. package/dist/cjs/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
  37. package/dist/cjs/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
  38. package/dist/cjs/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
  39. package/dist/cjs/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
  40. package/dist/cjs/components/Feedback/Feedback.js +40 -40
  41. package/dist/cjs/components/FlowModal/FlowModal.js +141 -141
  42. package/dist/cjs/components/FlowModal/FlowModalForm.js +12 -12
  43. package/dist/cjs/components/Header/Header.js +168 -182
  44. package/dist/cjs/components/Header/HeaderAppSwitcher.js +102 -94
  45. package/dist/cjs/components/Header/HeaderMenu.js +7 -7
  46. package/dist/cjs/components/Header/HeaderMenuItem.js +52 -52
  47. package/dist/cjs/components/Header/UserRequests.js +29 -29
  48. package/dist/cjs/components/ImageModal/ImageModal.js +17 -17
  49. package/dist/cjs/components/Loading/Loading.js +8 -8
  50. package/dist/cjs/components/MemberBar/MemberBar.js +20 -20
  51. package/dist/cjs/components/Modal/Modal.js +20 -20
  52. package/dist/cjs/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
  53. package/dist/cjs/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
  54. package/dist/cjs/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
  55. package/dist/cjs/components/ModalForm/ModalForm.js +9 -9
  56. package/dist/cjs/components/Notifications/NotificationsContainer.js +22 -22
  57. package/dist/cjs/components/Notifications/ToastNotification.js +21 -21
  58. package/dist/cjs/components/Notifications/notify.js +17 -17
  59. package/dist/cjs/components/PlatformBanner/PlatformBanner.js +8 -8
  60. package/dist/cjs/components/PlatformNotifications/PlatformNotification.js +17 -17
  61. package/dist/cjs/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
  62. package/dist/cjs/components/Portal/Portal.js +14 -14
  63. package/dist/cjs/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
  64. package/dist/cjs/components/PrivacyStatement/PrivacyStatement.js +90 -90
  65. package/dist/cjs/components/ProfileSettings/ProfileSettings.js +124 -124
  66. package/dist/cjs/components/ProtectedRoute/ProtectedRoute.js +13 -13
  67. package/dist/cjs/components/RadioGroup/RadioGroup.js +33 -33
  68. package/dist/cjs/components/RichTextArea/RichTextArea.js +142 -142
  69. package/dist/cjs/components/SignOut/SignOut.js +27 -27
  70. package/dist/cjs/components/SupportCenter/SupportCenter.js +65 -65
  71. package/dist/cjs/components/TextArea/TextArea.js +16 -16
  72. package/dist/cjs/components/TextInput/TextInput.js +13 -13
  73. package/dist/cjs/components/Toggle/Toggle.js +22 -22
  74. package/dist/cjs/components/TooltipHover/TooltipHover.js +39 -39
  75. package/dist/cjs/components/UIShell/UIShell.js +89 -90
  76. package/dist/cjs/config/servicesConfig.js +21 -21
  77. package/dist/cjs/constants/DataDrivenInputTypes.js +74 -74
  78. package/dist/cjs/constants/UserType.js +13 -13
  79. package/dist/cjs/hooks/useHeaderMenu.js +49 -49
  80. package/dist/cjs/hooks/usePortal.js +74 -74
  81. package/dist/cjs/hooks/useWindowSize.js +33 -33
  82. package/dist/cjs/internal/ListBox/ListBox.js +41 -41
  83. package/dist/cjs/internal/ListBox/ListBoxField.js +19 -19
  84. package/dist/cjs/internal/ListBox/ListBoxMenu.js +19 -19
  85. package/dist/cjs/internal/ListBox/ListBoxMenuIcon.js +31 -31
  86. package/dist/cjs/internal/ListBox/ListBoxMenuItem.js +38 -38
  87. package/dist/cjs/internal/ListBox/ListBoxSelection.js +64 -64
  88. package/dist/cjs/internal/ListBox/index.js +10 -10
  89. package/dist/cjs/internal/keyboard/keys.js +16 -16
  90. package/dist/cjs/internal/keyboard/match.js +67 -67
  91. package/dist/cjs/internal/settings.js +5 -5
  92. package/dist/cjs/tools/accessibility.js +13 -13
  93. package/dist/cjs/tools/createPropAdapter.js +44 -44
  94. package/dist/cjs/tools/isUrl.js +39 -39
  95. package/dist/cjs/tools/setupGetInstanceId.js +20 -20
  96. package/dist/cjs/tools/useSetState.js +12 -12
  97. package/dist/cjs/tools/yupAst/astGenerator.js +212 -212
  98. package/dist/cjs/tools/yupAst/customValidators.js +17 -17
  99. package/dist/esm/components/AboutPlatform/AboutPlatform.js +50 -50
  100. package/dist/esm/components/AdvantageSideNav/AdvantageSideNav.js +244 -226
  101. package/dist/esm/components/AutoSuggest/AutoSuggest.js +101 -101
  102. package/dist/esm/components/Avatar/Avatar.js +18 -18
  103. package/dist/esm/components/CheckboxList/CheckboxList.js +34 -34
  104. package/dist/esm/components/ComboBox/ComboBox.js +103 -103
  105. package/dist/esm/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
  106. package/dist/esm/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
  107. package/dist/esm/components/ComposedModal/ComposedModal.js +80 -80
  108. package/dist/esm/components/ConfirmModal/ConfirmModal.js +43 -43
  109. package/dist/esm/components/Creatable/Creatable.js +137 -137
  110. package/dist/esm/components/DataDrivenInput/DataDrivenInput.js +226 -226
  111. package/dist/esm/components/DateInput/DateInput.js +35 -35
  112. package/dist/esm/components/DecisionButtons/DecisionButtons.js +61 -61
  113. package/dist/esm/components/DelayedRender/DelayedRender.js +17 -17
  114. package/dist/esm/components/DynamicFormik/DynamicFormik.js +578 -578
  115. package/dist/esm/components/Error403/Error403.js +13 -13
  116. package/dist/esm/components/Error403/ForbiddenErrorBackground.js +113 -113
  117. package/dist/esm/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
  118. package/dist/esm/components/Error404/Error404.js +13 -13
  119. package/dist/esm/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
  120. package/dist/esm/components/Error404/NotFoundErrorBackground.js +129 -129
  121. package/dist/esm/components/ErrorBoundary/ErrorBoundary.js +32 -32
  122. package/dist/esm/components/ErrorDragon/ErrorDragon.js +13 -13
  123. package/dist/esm/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
  124. package/dist/esm/components/ErrorFullPage/ErrorFullPage.js +10 -10
  125. package/dist/esm/components/ErrorMessage/ErrorMessage.js +22 -22
  126. package/dist/esm/components/ErrorPage/ErrorPage.js +11 -11
  127. package/dist/esm/components/ErrorPageCore/ErrorPageCore.js +15 -15
  128. package/dist/esm/components/ErrorPageCore/GenericErrorBackground.js +124 -124
  129. package/dist/esm/components/FeatureHeader/FeatureHeader.js +29 -29
  130. package/dist/esm/components/FeatureNavTab/FeatureNavTab.js +12 -12
  131. package/dist/esm/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
  132. package/dist/esm/components/FeatureSideNav/FeatureSideNav.js +12 -12
  133. package/dist/esm/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
  134. package/dist/esm/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
  135. package/dist/esm/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
  136. package/dist/esm/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
  137. package/dist/esm/components/Feedback/Feedback.js +40 -40
  138. package/dist/esm/components/FlowModal/FlowModal.js +141 -141
  139. package/dist/esm/components/FlowModal/FlowModalForm.js +12 -12
  140. package/dist/esm/components/Header/Header.js +168 -182
  141. package/dist/esm/components/Header/HeaderAppSwitcher.js +102 -94
  142. package/dist/esm/components/Header/HeaderMenu.js +7 -7
  143. package/dist/esm/components/Header/HeaderMenuItem.js +52 -52
  144. package/dist/esm/components/Header/UserRequests.js +29 -29
  145. package/dist/esm/components/ImageModal/ImageModal.js +17 -17
  146. package/dist/esm/components/Loading/Loading.js +8 -8
  147. package/dist/esm/components/MemberBar/MemberBar.js +20 -20
  148. package/dist/esm/components/Modal/Modal.js +20 -20
  149. package/dist/esm/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
  150. package/dist/esm/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
  151. package/dist/esm/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
  152. package/dist/esm/components/ModalForm/ModalForm.js +9 -9
  153. package/dist/esm/components/Notifications/NotificationsContainer.js +22 -22
  154. package/dist/esm/components/Notifications/ToastNotification.js +21 -21
  155. package/dist/esm/components/Notifications/notify.js +17 -17
  156. package/dist/esm/components/PlatformBanner/PlatformBanner.js +8 -8
  157. package/dist/esm/components/PlatformNotifications/PlatformNotification.js +17 -17
  158. package/dist/esm/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
  159. package/dist/esm/components/Portal/Portal.js +14 -14
  160. package/dist/esm/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
  161. package/dist/esm/components/PrivacyStatement/PrivacyStatement.js +90 -90
  162. package/dist/esm/components/ProfileSettings/ProfileSettings.js +124 -124
  163. package/dist/esm/components/ProtectedRoute/ProtectedRoute.js +13 -13
  164. package/dist/esm/components/RadioGroup/RadioGroup.js +33 -33
  165. package/dist/esm/components/RichTextArea/RichTextArea.js +142 -142
  166. package/dist/esm/components/SignOut/SignOut.js +27 -27
  167. package/dist/esm/components/SupportCenter/SupportCenter.js +65 -65
  168. package/dist/esm/components/TextArea/TextArea.js +16 -16
  169. package/dist/esm/components/TextInput/TextInput.js +13 -13
  170. package/dist/esm/components/Toggle/Toggle.js +22 -22
  171. package/dist/esm/components/TooltipHover/TooltipHover.js +39 -39
  172. package/dist/esm/components/UIShell/UIShell.js +89 -90
  173. package/dist/esm/config/servicesConfig.js +21 -21
  174. package/dist/esm/constants/DataDrivenInputTypes.js +74 -74
  175. package/dist/esm/constants/UserType.js +13 -13
  176. package/dist/esm/hooks/useHeaderMenu.js +49 -49
  177. package/dist/esm/hooks/usePortal.js +74 -74
  178. package/dist/esm/hooks/useWindowSize.js +33 -33
  179. package/dist/esm/internal/ListBox/ListBox.js +41 -41
  180. package/dist/esm/internal/ListBox/ListBoxField.js +19 -19
  181. package/dist/esm/internal/ListBox/ListBoxMenu.js +19 -19
  182. package/dist/esm/internal/ListBox/ListBoxMenuIcon.js +31 -31
  183. package/dist/esm/internal/ListBox/ListBoxMenuItem.js +38 -38
  184. package/dist/esm/internal/ListBox/ListBoxSelection.js +64 -64
  185. package/dist/esm/internal/ListBox/index.js +10 -10
  186. package/dist/esm/internal/keyboard/keys.js +16 -16
  187. package/dist/esm/internal/keyboard/match.js +67 -67
  188. package/dist/esm/internal/settings.js +5 -5
  189. package/dist/esm/tools/accessibility.js +13 -13
  190. package/dist/esm/tools/createPropAdapter.js +44 -44
  191. package/dist/esm/tools/isUrl.js +39 -39
  192. package/dist/esm/tools/setupGetInstanceId.js +20 -20
  193. package/dist/esm/tools/useSetState.js +12 -12
  194. package/dist/esm/tools/yupAst/astGenerator.js +212 -212
  195. package/dist/esm/tools/yupAst/customValidators.js +17 -17
  196. package/dist/types/index.d.ts +1309 -1407
  197. package/package.json +167 -167
  198. package/scss/components/AboutPlatform/_aboutPlatform.scss +139 -139
  199. package/scss/components/AdvantageSideNav/_advantageSideNav.scss +267 -261
  200. package/scss/components/AutoSuggest/_autoSuggest.scss +62 -62
  201. package/scss/components/Avatar/_avatar.scss +32 -32
  202. package/scss/components/CheckboxList/_checkboxList.scss +26 -26
  203. package/scss/components/ComboBox/_combobox.scss +23 -23
  204. package/scss/components/ComboBoxMultiSelect/_comboBoxMultiSelect.scss +53 -53
  205. package/scss/components/ConfirmModal/_confirmModal.scss +12 -12
  206. package/scss/components/Creatable/_creatable.scss +48 -48
  207. package/scss/components/DateInput/_dateInput.scss +36 -36
  208. package/scss/components/DecisionButtons/_decisionButtons.scss +132 -132
  209. package/scss/components/DynamicFormik/_dynamicFormik.scss +17 -17
  210. package/scss/components/ErrorBoundary/_errorBoundary.scss +12 -12
  211. package/scss/components/ErrorDragon/_errorDragon.scss +55 -55
  212. package/scss/components/ErrorMessage/_errorMessage.scss +43 -43
  213. package/scss/components/ErrorPage/_errorPage.scss +66 -66
  214. package/scss/components/ErrorPageCore/_errorPageCore.scss +73 -73
  215. package/scss/components/FeatureHeader/_featureHeader.scss +67 -67
  216. package/scss/components/FeatureNavTab/_featureNavTab.scss +27 -27
  217. package/scss/components/FeatureSideNav/_featureSideNav.scss +76 -76
  218. package/scss/components/FeatureSideNavLink/_featureSideNavLink.scss +49 -49
  219. package/scss/components/Feedback/_feedback.scss +46 -46
  220. package/scss/components/Header/_header.scss +179 -179
  221. package/scss/components/Header/_headerAppSwitcher.scss +117 -117
  222. package/scss/components/Header/_headerMenu.scss +30 -30
  223. package/scss/components/Header/_headerMenuItem.scss +65 -65
  224. package/scss/components/Header/_userRequests.scss +36 -36
  225. package/scss/components/ImageModal/_imageModal.scss +51 -51
  226. package/scss/components/MemberBar/_memberBar.scss +99 -99
  227. package/scss/components/Modal/_modal.scss +163 -163
  228. package/scss/components/ModalConfirmEdit/_modalConfirmEdit.scss +113 -113
  229. package/scss/components/Notifications/_notifications.scss +57 -57
  230. package/scss/components/PlatformBanner/_platformBanner.scss +30 -30
  231. package/scss/components/PlatformNotifications/_platformNotifications.scss +230 -230
  232. package/scss/components/PrivacyRedirect/_privacyRedirect.scss +43 -43
  233. package/scss/components/PrivacyStatement/_privacyStatement.scss +137 -137
  234. package/scss/components/ProfileSettings/_profileSettings.scss +117 -117
  235. package/scss/components/ProtectedRoute/_protectedRoute.scss +32 -32
  236. package/scss/components/RadioGroup/_radioGroup.scss +46 -46
  237. package/scss/components/RichTextArea/_richTextArea.scss +82 -82
  238. package/scss/components/SignOut/_signOut.scss +51 -51
  239. package/scss/components/SupportCenter/_supportCenter.scss +16 -16
  240. package/scss/components/TextArea/_textArea.scss +19 -19
  241. package/scss/components/TextInput/_textInput.scss +26 -26
  242. package/scss/components/Toggle/_toggle.scss +80 -80
  243. package/scss/components/TooltipHover/_tooltip.scss +48 -48
  244. package/scss/global/_config.scss +14 -14
  245. package/scss/global/_tippy.scss +49 -49
  246. package/scss/global/index.scss +402 -401
  247. package/scss/global/themes/_boomerang.scss +184 -184
  248. package/scss/global/themes/_default.scss +79 -79
  249. package/scss/global/themes/_shell-tokens.scss +42 -42
  250. package/scss/global/utils/_animations.scss +15 -15
  251. package/scss/global/utils/_mixins.scss +67 -67
  252. package/scss/global/utils/index.scss +10 -10
  253. package/dist/cjs/components/Header/HeaderTeamSwitcher.js +0 -324
  254. package/dist/esm/components/Header/HeaderTeamSwitcher.js +0 -315
  255. package/scss/components/Header/_headerTeamSwitcher.scss +0 -195
@@ -9,584 +9,584 @@ import { transformAll } from '../../tools/yupAst/astGenerator.js';
9
9
  import { prefix } from '../../internal/settings.js';
10
10
  import { TEXT_INPUT_TYPES, TEXT_AREA_TYPES, TEXT_EDITOR_TYPES, ARRAY_INPUT_TYPES, CHECKBOX_TYPES, INPUT_GROUPS, CREATABLE_TYPES, DATE_TYPES, MULTI_SELECT_TYPES, RADIO_TYPES, SELECT_TYPES, BOOLEAN_TYPES, INPUT_TYPES_ARRAY } from '../../constants/DataDrivenInputTypes.js';
11
11
 
12
- /*
13
- IBM Confidential
14
- 694970X, 69497O0
15
- © Copyright IBM Corp. 2022, 2024
16
- */
17
- /**
18
- *
19
- * @param {string} value - value to test for valid property syntax
20
- */
21
- function isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound }) {
22
- // Look property pattern and capture group for the property itself
23
- let match = value.match(customPropertySyntaxPattern);
24
- // if the first matched group is truthy, then a property has been entered
25
- // Empty properties are not valid
26
- if (Array.isArray(match) && match.length === propsSyntaxFound) {
27
- return true;
28
- }
29
- else {
30
- return false;
31
- }
32
- }
33
- function validateUrlWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
34
- return function () {
35
- return this.transform(function (value, originalValue) {
36
- const propsSyntaxFound = value.match(customPropertyStartsWithPattern)?.length ?? 0;
37
- if ((isUrl(value) && !Boolean(propsSyntaxFound)) ||
38
- isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound })) {
39
- return value;
40
- }
41
- return false;
42
- });
43
- };
44
- }
45
- function validateEmailWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
46
- return function () {
47
- return this.transform(function (value, originalValue) {
48
- // Simple pattern for emails
49
- const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
50
- const propsSyntaxFound = value.match(customPropertyStartsWithPattern)?.length ?? 0;
51
- if ((isValidEmail && !Boolean(propsSyntaxFound)) ||
52
- isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound })) {
53
- return value;
54
- }
55
- return false;
56
- });
57
- };
58
- }
59
- function registerCustomPropertyMethods(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
60
- const validateUrl = validateUrlWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern);
61
- const validateEmail = validateEmailWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern);
62
- yup.addMethod(yup.string, "urlWithCustomProperty", validateUrl);
63
- yup.addMethod(yup.string, "emailWithCustomProperty", validateEmail);
64
- }
65
- function getGoverningSelectKeysMap({ governingKey, governingJsonKey, governingKeys, inputs, }) {
66
- if (Boolean(governingKey) && governingKey !== governingJsonKey)
67
- governingKeys.unshift(governingKey);
68
- const governingInput = inputs.find((input) => input.key === governingKey) ?? {};
69
- /** Continue recursion if the governing select has a governingKey */
70
- if (Boolean(governingInput.governingKey)) {
71
- return getGoverningSelectKeysMap({
72
- governingKey: governingInput.governingKey,
73
- governingJsonKey,
74
- governingKeys,
75
- inputs,
76
- });
77
- }
78
- else {
79
- return governingKeys;
80
- }
81
- }
82
- function getGoverningSelectDeepOptions({ formikValues, governingInputJsonObject, governingKeys, input, inputs, }) {
83
- const nextKey = governingKeys.shift();
84
- if (nextKey) {
85
- const nextKeyInput = inputs.find((input) => input.key === nextKey) ?? {};
86
- const nextInputJsonObject = governingInputJsonObject[nextKey].find((jsonElement) => jsonElement[nextKeyInput.jsonKey] === formikValues[nextKey]);
87
- return getGoverningSelectDeepOptions({
88
- formikValues,
89
- governingInputJsonObject: nextInputJsonObject,
90
- governingKeys,
91
- input,
92
- inputs,
93
- });
94
- }
95
- else {
96
- return governingInputJsonObject[input.key].map((option) => ({
97
- label: option[input.jsonLabel],
98
- value: option[input.jsonKey],
99
- }));
100
- }
101
- }
102
- async function handleGoverningSelectChange({ formikProps, input, inputs, isInputBeingChanged, selectedItem, }) {
103
- const { key, value } = input;
104
- const inputsGovernedByCurrentOne = inputs.filter((formikInput) => formikInput.governingKey === key);
105
- if (selectedItem?.value !== value) {
106
- /** Erase value of governed inputs */
107
- if (inputsGovernedByCurrentOne.length) {
108
- await inputsGovernedByCurrentOne.forEach(async (input) => {
109
- await handleGoverningSelectChange({ formikProps, input, inputs, isInputBeingChanged: false, selectedItem: null });
110
- });
111
- }
112
- // only the top governing select should display warnings if changed and reset touched status for governed ones
113
- await formikProps.setFieldTouched(`['${key}']`, isInputBeingChanged);
114
- formikProps.setFieldValue(`['${key}']`, selectedItem ? selectedItem.value : "");
115
- formikProps.setFieldValue(`['${key}-keyLabel']`, selectedItem ? selectedItem.label : "");
116
- }
117
- }
118
- function generateYupAst({ inputs, allowCustomPropertySyntax, customPropertySyntaxPattern, customPropertyStartsWithPattern, useCSVforArrays, }) {
119
- if (allowCustomPropertySyntax) {
120
- registerCustomPropertyMethods(customPropertySyntaxPattern, customPropertyStartsWithPattern);
121
- }
122
- let yupShape = {};
123
- inputs.forEach((input) => {
124
- let yupValidationArray = [];
125
- const inputType = input.type ?? "";
126
- if (!INPUT_TYPES_ARRAY.includes(inputType)) {
127
- return;
128
- }
129
- if (inputType === DATE_TYPES.DATE) {
130
- yupValidationArray.push(["yup.date", "Enter a valid date"]);
131
- }
132
- if (inputType === TEXT_AREA_TYPES.TEXT_AREA ||
133
- inputType === TEXT_INPUT_TYPES.EMAIL ||
134
- inputType === TEXT_INPUT_TYPES.PASSWORD ||
135
- inputType === TEXT_INPUT_TYPES.SECURED ||
136
- inputType === TEXT_INPUT_TYPES.TEL ||
137
- inputType === TEXT_INPUT_TYPES.TEXT ||
138
- inputType === TEXT_INPUT_TYPES.TIME ||
139
- inputType === TEXT_INPUT_TYPES.URL ||
140
- inputType === RADIO_TYPES.RADIO ||
141
- inputType === SELECT_TYPES.SELECT ||
142
- inputType?.startsWith(TEXT_EDITOR_TYPES.TEXT_EDITOR)) {
143
- yupValidationArray.push(["yup.string"]);
144
- // if (
145
- // allowCustomPropertySyntax &&
146
- // inputType !== TEXT_INPUT_TYPES.EMAIL &&
147
- // inputType !== TEXT_INPUT_TYPES.URL &&
148
- // inputType !== TEXT_INPUT_TYPES.SECURED &&
149
- // inputType !== TEXT_INPUT_TYPES.PASSWORD
150
- // )
151
- // yupValidationArray.push(
152
- // ['yup.customProperty'],
153
- // ['yup.typeError', 'Enter valid syntax for a property']
154
- // );
155
- // Create a customValidator for each input b/c regex deserialization
156
- // does not work currently
157
- const { pattern } = input;
158
- if (typeof pattern === "string") {
159
- addCustomValidator(`${input.key}-matches`, yup.string().test(`${input.key}-matches`, input.patternInvalidText || `Enter a value that matches pattern: ${input.pattern}`, (value) => {
160
- if (!input.required && !Boolean(value)) {
161
- return true;
162
- }
163
- else
164
- return new RegExp(pattern).test(value);
165
- }));
166
- yupValidationArray.push([`${input.key}-matches`]);
167
- }
168
- //TODO: figure out how to update serialization in yup-ast so we can use the native "matches" validator
169
- // if (input.pattern) {
170
- // yupValidationArray.push([
171
- // 'yup.matches',
172
- // new RegExp(input.pattern),
173
- // {
174
- // message: `Enter a value that matches pattern ${input.pattern}`,
175
- // excludeEmptyString: true,
176
- // },
177
- // ]);
178
- // }
179
- if (inputType === TEXT_INPUT_TYPES.EMAIL) {
180
- if (allowCustomPropertySyntax)
181
- yupValidationArray.push(["yup.emailWithCustomProperty"], ["yup.typeError", "Enter a valid email"]);
182
- else
183
- yupValidationArray.push(["yup.email", "Enter a valid email"]);
184
- }
185
- if (inputType === TEXT_INPUT_TYPES.URL) {
186
- if (allowCustomPropertySyntax)
187
- yupValidationArray.push(["yup.urlWithCustomProperty"], ["yup.typeError", "Enter a valid URL"]);
188
- else
189
- yupValidationArray.push(["yup.url", "Enter a valid URL"]);
190
- }
191
- }
192
- if (inputType === TEXT_INPUT_TYPES.NUMBER) {
193
- yupValidationArray.push(["yup.number", "Enter a number"]);
194
- }
195
- if (inputType === BOOLEAN_TYPES.BOOLEAN) {
196
- yupValidationArray.push(["yup.boolean"]);
197
- }
198
- if (inputType === MULTI_SELECT_TYPES.MULTI_SELECT ||
199
- inputType === CREATABLE_TYPES.CREATABLE_SINGLE ||
200
- inputType === CREATABLE_TYPES.CREATABLE_SINGLE_NON_DELETABLE ||
201
- inputType === CREATABLE_TYPES.CREATABLE_PAIR ||
202
- inputType === CREATABLE_TYPES.CREATABLE_PAIR_NON_DELETABLE ||
203
- inputType === CHECKBOX_TYPES.CHECKBOX) {
204
- if (useCSVforArrays) {
205
- yupValidationArray.push(["yup.string"]);
206
- const { pattern } = input;
207
- if (pattern === typeof "string") {
208
- addCustomValidator(`${input.key}-matches`, yup.string().test(`${input.key}-matches`, input.patternInvalidText || `Enter values that matches pattern: ${input.pattern}`, (csv) => {
209
- const regexTester = new RegExp(pattern);
210
- return csv?.split(",").every((val) => regexTester.test(val)) ?? false;
211
- }));
212
- yupValidationArray.push([`${input.key}-matches`]);
213
- }
214
- }
215
- else {
216
- yupValidationArray.push(["yup.array"]);
217
- const { pattern } = input;
218
- if (typeof pattern === "string") {
219
- addCustomValidator(`${input.key}-matches`, yup.array().test(`${input.key}-matches`, input.patternInvalidText || `Enter values that matches pattern: ${pattern}`, (values) => {
220
- const regexTester = new RegExp(pattern);
221
- return values?.every((val) => regexTester.test(val)) ?? false;
222
- }));
223
- yupValidationArray.push([`${input.key}-matches`]);
224
- }
225
- }
226
- }
227
- if (Object.values(TEXT_INPUT_TYPES).includes(inputType) ||
228
- inputType === TEXT_AREA_TYPES.TEXT_AREA ||
229
- inputType === TEXT_EDITOR_TYPES.TEXT_EDITOR) {
230
- if (inputType === TEXT_INPUT_TYPES.NUMBER) {
231
- if (input.min) {
232
- yupValidationArray.push(["yup.min", input.min, `Enter value greater than ${input.min}`]);
233
- }
234
- if (input.max) {
235
- yupValidationArray.push(["yup.max", input.max, `Enter value less than ${input.max}`]);
236
- }
237
- }
238
- else {
239
- if (input.min) {
240
- yupValidationArray.push(["yup.min", input.min, `Enter at least ${input.min} characters`]);
241
- }
242
- if (input.max) {
243
- yupValidationArray.push(["yup.max", input.max, `Enter at most ${input.max} characters`]);
244
- }
245
- }
246
- }
247
- if (Array.isArray(input.invalidValues)) {
248
- yupValidationArray.push(["yup.notOneOf", input.invalidValues, `Enter an allowed value`]);
249
- }
250
- if (input.required) {
251
- if (inputType === BOOLEAN_TYPES.BOOLEAN) {
252
- yupValidationArray.push(["yup.oneOf", [true], "Toggle must be checked"]);
253
- }
254
- else {
255
- yupValidationArray.push(["yup.required", `Enter a value for ${input.label}`]);
256
- }
257
- }
258
- if (yupValidationArray.length > 0) {
259
- yupShape[input.key] = yupValidationArray;
260
- }
261
- });
262
- return [["yup.object"], ["yup.shape", yupShape]];
263
- }
264
- function generateYupSchema({ inputs, allowCustomPropertySyntax, customPropertySyntaxPattern, customPropertyStartsWithPattern, useCSVforArrays, validationSchemaExtension, }) {
265
- let validationSchema = transformAll(generateYupAst({
266
- inputs,
267
- allowCustomPropertySyntax,
268
- customPropertySyntaxPattern,
269
- customPropertyStartsWithPattern,
270
- useCSVforArrays,
271
- }));
272
- if (validationSchemaExtension) {
273
- validationSchema = validationSchema.concat(validationSchemaExtension);
274
- }
275
- return validationSchema;
276
- }
277
- /**
278
- * Get initial values of each input in array of inputs
279
- */
280
- const determineInitialValues = (inputs, useCSVforArrays) => {
281
- const values = {};
282
- inputs.forEach((input) => {
283
- let value = "";
284
- let valueToCheck = input.value || input.defaultValue;
285
- const isArrayInput = !useCSVforArrays && Object.values(ARRAY_INPUT_TYPES).includes(input.type);
286
- if (isArrayInput) {
287
- valueToCheck = input.value || input.defaultValue || input.values || input.defaultValues;
288
- }
289
- if (valueToCheck) {
290
- switch (valueToCheck) {
291
- case "false": {
292
- value = false;
293
- break;
294
- }
295
- case "true": {
296
- value = true;
297
- break;
298
- }
299
- default: {
300
- value = valueToCheck;
301
- }
302
- }
303
- }
304
- values[input.key] = value;
305
- });
306
- return values;
307
- };
308
- /**
309
- * Check if an input X needs to be conditionally rendered
310
- * If it does, then find an input Y in the same section that has key equal to the input X's requiredForKey
311
- * If input Y has a value that is present in input X's requiredValueOf array, then render X
312
- */
313
- const conditionallyRenderInput = (input, values) => {
314
- if (!input.conditionallyRender) {
315
- return true;
316
- }
317
- if (input.requiredForKey && input.requiredValueOf) {
318
- /**
319
- * Check which input in this section has the key equal to requiredForKey and get its value
320
- */
321
- const requiredForKeyInputValue = values[input.requiredForKey];
322
- const valuesInputIsRenderedFor = input.requiredValueOf;
323
- /**
324
- * If the value of the input this input is required for is an array loop through those values to find a matching one
325
- * by going through all of configured values for the input - the "requiredValueOf" of property
326
- * Check for the value and the string of the value bc of how the services work. "true" and "false" are strings not boolean values
327
- */
328
- if (Array.isArray(requiredForKeyInputValue)) {
329
- for (let requiredForValue of valuesInputIsRenderedFor) {
330
- for (let singleRequiredForKeyInputValue of requiredForKeyInputValue) {
331
- if (requiredForValue === singleRequiredForKeyInputValue ||
332
- requiredForValue === String(singleRequiredForKeyInputValue)) {
333
- return true;
334
- }
335
- }
336
- }
337
- }
338
- else {
339
- for (let requiredForValue of valuesInputIsRenderedFor) {
340
- if (requiredForValue === requiredForKeyInputValue || requiredForValue === String(requiredForKeyInputValue)) {
341
- return true;
342
- }
343
- }
344
- }
345
- }
346
- else {
347
- return false;
348
- }
349
- };
350
- /**
351
- * Map of the input groups to specifc props to be passed
352
- */
353
- const TYPE_PROPS = {
354
- [INPUT_GROUPS.CHECKBOX]: (formikProps, { key }, inputs, useCSVforArrays) => ({
355
- onChange: (value, id, event, selectedItems) => {
356
- if (useCSVforArrays) {
357
- formikProps.setFieldValue(`['${key}']`, selectedItems?.join() ?? "");
358
- }
359
- else {
360
- formikProps.setFieldValue(`['${key}']`, selectedItems);
361
- }
362
- },
363
- }),
364
- [INPUT_GROUPS.CREATABLE]: (formikProps, { key }, inputs, useCSVforArrays) => ({
365
- onChange: (createdItems) => {
366
- formikProps.setFieldTouched(`['${key}']`, true);
367
- if (useCSVforArrays) {
368
- formikProps.setFieldValue(`['${key}']`, createdItems?.join() ?? "");
369
- }
370
- else {
371
- formikProps.setFieldValue(`['${key}']`, createdItems);
372
- }
373
- },
374
- onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
375
- }),
376
- [INPUT_GROUPS.DATE]: (formikProps, { key, type }) => type === DATE_TYPES.DATE_RANGE
377
- ? {
378
- onChange: (dateArray) => formikProps.setFieldValue(`['${key}']`, dateArray?.map((date) => date.toISOString())),
379
- }
380
- : {
381
- onChange: formikProps.handleChange,
382
- onCalendarChange: (dateArray) => formikProps.setFieldValue(`['${key}']`, dateArray[0]?.toISOString()),
383
- },
384
- [INPUT_GROUPS.MULTI_SELECT]: (formikProps, { key }, inputs, useCSVforArrays) => ({
385
- onChange: async ({ selectedItems }) => {
386
- await formikProps.setFieldTouched(`['${key}']`, true);
387
- if (useCSVforArrays) {
388
- formikProps.setFieldValue(`['${key}']`, selectedItems ? selectedItems.map((item) => item && item.value).join() : "");
389
- }
390
- else {
391
- formikProps.setFieldValue(`['${key}']`, selectedItems.map((item) => item && item.value));
392
- }
393
- },
394
- onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
395
- }),
396
- [INPUT_GROUPS.RADIO]: (formikProps, { key }) => ({
397
- onChange: (value) => formikProps.setFieldValue(`['${key}']`, value),
398
- }),
399
- [INPUT_GROUPS.SELECT]: (formikProps, input, inputs) => {
400
- const { key, value } = input;
401
- let typeProps = {
402
- onChange: async ({ selectedItem }) => {
403
- if (selectedItem.value !== value) {
404
- await formikProps.setFieldTouched(`['${key}']`, true);
405
- formikProps.setFieldValue(`['${key}']`, selectedItem ? selectedItem.value : "");
406
- }
407
- },
408
- onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
409
- };
410
- /**
411
- * Start Governing Selects logic if input contains governingJsonKey
412
- */
413
- if (Boolean(input.governingJsonKey)) {
414
- const { governingJsonKey, governingKey, jsonKey, jsonLabel } = input;
415
- const governingJsonInput = inputs.find((input) => input.key === governingJsonKey);
416
- /** Check if governingJson with all governing selects data exists as an array */
417
- if (governingJsonInput && Array.isArray(governingJsonInput.governingJson)) {
418
- const { governingJson } = governingJsonInput;
419
- let governingOptions = [];
420
- let governingDisabled = false;
421
- /**
422
- * Select "governingOptions"
423
- * If current select is the top level governing select, just get the top level options from the json
424
- */
425
- if (key === governingJsonKey) {
426
- governingOptions = governingJson.map((option) => ({
427
- label: option[jsonLabel],
428
- value: option[jsonKey],
429
- }));
430
- }
431
- else {
432
- /** Check if the select that governs this one has a value and disable if it doesn't */
433
- const governingSelectValue = formikProps.values[governingKey];
434
- if (Boolean(governingSelectValue)) {
435
- let governingKeys = getGoverningSelectKeysMap({
436
- governingKey,
437
- governingJsonKey,
438
- governingKeys: [],
439
- inputs,
440
- });
441
- governingOptions = getGoverningSelectDeepOptions({
442
- formikValues: formikProps.values,
443
- governingInputJsonObject: governingJson.find((jsonElement) => jsonElement[governingJsonInput.jsonKey] === formikProps.values[governingJsonKey]),
444
- governingKeys: [...governingKeys],
445
- input,
446
- inputs,
447
- });
448
- }
449
- else {
450
- governingDisabled = true;
451
- }
452
- }
453
- typeProps = {
454
- ...typeProps,
455
- onChange: ({ selectedItem }) => handleGoverningSelectChange({ formikProps, input, inputs, selectedItem, isInputBeingChanged: true }),
456
- governingOptions,
457
- governingDisabled,
458
- };
459
- }
460
- }
461
- return typeProps;
462
- },
463
- [INPUT_GROUPS.TEXT_AREA]: (formikProps) => ({
464
- onChange: formikProps.handleChange,
465
- }),
466
- [INPUT_GROUPS.TEXT_EDITOR]: (formikProps) => ({
467
- onChange: formikProps.handleChange,
468
- }),
469
- [INPUT_GROUPS.TEXT_INPUT]: (formikProps) => ({
470
- onChange: formikProps.handleChange,
471
- }),
472
- [INPUT_GROUPS.BOOLEAN]: (formikProps, { key }) => ({
473
- onChange: (value) => {
474
- formikProps.setFieldTouched(`['${key}']`, true, true);
475
- formikProps.setFieldValue(`['${key}']`, value);
476
- },
477
- }),
478
- };
479
- function determineTypeProps(type, otherProps) {
480
- const { checkboxListProps, creatableProps, dateProps, multiSelectProps, radioProps, selectProps, textAreaProps, textEditorProps, textInputProps, toggleProps, } = otherProps;
481
- if (Object.values(CHECKBOX_TYPES).includes(type)) {
482
- return {
483
- typeProps: TYPE_PROPS[INPUT_GROUPS.CHECKBOX],
484
- additionalTypeProps: checkboxListProps,
485
- };
486
- }
487
- if (Object.values(CREATABLE_TYPES).includes(type)) {
488
- return {
489
- typeProps: TYPE_PROPS[INPUT_GROUPS.CREATABLE],
490
- additionalTypeProps: creatableProps,
491
- };
492
- }
493
- if (Object.values(DATE_TYPES).includes(type)) {
494
- return {
495
- typeProps: TYPE_PROPS[INPUT_GROUPS.DATE],
496
- additionalTypeProps: dateProps,
497
- };
498
- }
499
- if (Object.values(MULTI_SELECT_TYPES).includes(type)) {
500
- return {
501
- typeProps: TYPE_PROPS[INPUT_GROUPS.MULTI_SELECT],
502
- additionalTypeProps: multiSelectProps,
503
- };
504
- }
505
- if (Object.values(RADIO_TYPES).includes(type)) {
506
- return {
507
- typeProps: TYPE_PROPS[INPUT_GROUPS.RADIO],
508
- additionalTypeProps: radioProps,
509
- };
510
- }
511
- if (Object.values(SELECT_TYPES).includes(type)) {
512
- return {
513
- typeProps: TYPE_PROPS[INPUT_GROUPS.SELECT],
514
- additionalTypeProps: selectProps,
515
- };
516
- }
517
- if (Object.values(TEXT_AREA_TYPES).includes(type)) {
518
- return {
519
- typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_AREA],
520
- additionalTypeProps: textAreaProps,
521
- };
522
- }
523
- if (type.startsWith(TEXT_EDITOR_TYPES.TEXT_EDITOR)) {
524
- return {
525
- typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_EDITOR],
526
- additionalTypeProps: textEditorProps,
527
- };
528
- }
529
- if (Object.values(TEXT_INPUT_TYPES).includes(type)) {
530
- return {
531
- typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_INPUT],
532
- additionalTypeProps: textInputProps,
533
- };
534
- }
535
- if (Object.values(BOOLEAN_TYPES).includes(type)) {
536
- return {
537
- typeProps: TYPE_PROPS[INPUT_GROUPS.BOOLEAN],
538
- additionalTypeProps: toggleProps,
539
- };
540
- }
541
- return { typeProps: () => { }, additionalTypeProps: () => { } };
542
- }
543
- DynamicFormik.defaultProps = {
544
- checkboxListProps: (...args) => ({}),
545
- creatableProps: (...args) => ({}),
546
- dateProps: (...args) => ({}),
547
- multiSelectProps: (...args) => ({}),
548
- radioProps: (...args) => ({}),
549
- selectProps: (...args) => ({}),
550
- textAreaProps: (...args) => ({}),
551
- textEditorProps: (...args) => ({}),
552
- textInputProps: (...args) => ({}),
553
- toggleProps: (...args) => ({}),
554
- };
555
- function DynamicFormik({ additionalInitialValues = {}, allowCustomPropertySyntax = false, customPropertySyntaxPattern = /\$\{p:([a-zA-Z0-9_.-]+)\}|\$\(([a-zA-Z0-9_.-\s]+)\)/g, customPropertyStartsWithPattern = /\$\{|\$\(/g, children, dataDrivenInputProps, inputProps, initialValues, inputs, onSubmit, useCSVforArrays = false, validationSchema, validationSchemaExtension, ...otherProps }) {
556
- return (React.createElement(Formik, { initialValues: (Boolean(initialValues) && initialValues) || {
557
- ...determineInitialValues(inputs, useCSVforArrays),
558
- ...additionalInitialValues,
559
- }, validationSchema: validationSchema ||
560
- generateYupSchema({
561
- inputs,
562
- allowCustomPropertySyntax,
563
- customPropertySyntaxPattern,
564
- customPropertyStartsWithPattern,
565
- useCSVforArrays,
566
- validationSchemaExtension,
567
- }), onSubmit: (values, actions) => {
568
- if (onSubmit)
569
- onSubmit(values, actions);
570
- }, ...otherProps }, (formikProps) => {
571
- const { values, touched, errors, handleBlur } = formikProps;
572
- const finalInputs = inputs.filter((input) => conditionallyRenderInput(input, values));
573
- const dataDrivenInputs = finalInputs.map((input) => {
574
- const { key, type, value, // eslint-disable-line
575
- ...otherInputsProps } = input;
576
- const inputValue = values[key] !== undefined &&
577
- values[key] !== null &&
578
- (Object.values(TEXT_INPUT_TYPES).includes(type) ||
579
- type === TEXT_AREA_TYPES.TEXT_AREA ||
580
- type === TEXT_EDITOR_TYPES.TEXT_EDITOR)
581
- ? values[key].toString()
582
- : values[key];
583
- const invalidText = get(errors, key);
584
- const invalid = invalidText && get(touched, key);
585
- const { typeProps = () => { }, additionalTypeProps = () => { } } = determineTypeProps(type, otherProps);
586
- return (React.createElement(DataDrivenInput, { key: key, customComponent: input.customComponent, formikProps: formikProps, id: `['${key}']`, invalid: invalid, invalidText: invalidText, name: `['${key}']`, onBlur: handleBlur, type: type, value: inputValue, ...typeProps(formikProps, input, finalInputs, useCSVforArrays), ...otherInputsProps, ...inputProps, ...additionalTypeProps({ formikProps, input }), ...dataDrivenInputProps }));
587
- });
588
- return (React.createElement("div", { className: `${prefix}--bmrg-dynamic-formik` }, children({ inputs: dataDrivenInputs, formikProps })));
589
- }));
12
+ /*
13
+ IBM Confidential
14
+ 694970X, 69497O0
15
+ © Copyright IBM Corp. 2022, 2024
16
+ */
17
+ /**
18
+ *
19
+ * @param {string} value - value to test for valid property syntax
20
+ */
21
+ function isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound }) {
22
+ // Look property pattern and capture group for the property itself
23
+ let match = value.match(customPropertySyntaxPattern);
24
+ // if the first matched group is truthy, then a property has been entered
25
+ // Empty properties are not valid
26
+ if (Array.isArray(match) && match.length === propsSyntaxFound) {
27
+ return true;
28
+ }
29
+ else {
30
+ return false;
31
+ }
32
+ }
33
+ function validateUrlWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
34
+ return function () {
35
+ return this.transform(function (value, originalValue) {
36
+ const propsSyntaxFound = value.match(customPropertyStartsWithPattern)?.length ?? 0;
37
+ if ((isUrl(value) && !Boolean(propsSyntaxFound)) ||
38
+ isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound })) {
39
+ return value;
40
+ }
41
+ return false;
42
+ });
43
+ };
44
+ }
45
+ function validateEmailWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
46
+ return function () {
47
+ return this.transform(function (value, originalValue) {
48
+ // Simple pattern for emails
49
+ const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
50
+ const propsSyntaxFound = value.match(customPropertyStartsWithPattern)?.length ?? 0;
51
+ if ((isValidEmail && !Boolean(propsSyntaxFound)) ||
52
+ isPropertySyntaxValid({ value, customPropertySyntaxPattern, propsSyntaxFound })) {
53
+ return value;
54
+ }
55
+ return false;
56
+ });
57
+ };
58
+ }
59
+ function registerCustomPropertyMethods(customPropertySyntaxPattern, customPropertyStartsWithPattern) {
60
+ const validateUrl = validateUrlWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern);
61
+ const validateEmail = validateEmailWithProperties(customPropertySyntaxPattern, customPropertyStartsWithPattern);
62
+ yup.addMethod(yup.string, "urlWithCustomProperty", validateUrl);
63
+ yup.addMethod(yup.string, "emailWithCustomProperty", validateEmail);
64
+ }
65
+ function getGoverningSelectKeysMap({ governingKey, governingJsonKey, governingKeys, inputs, }) {
66
+ if (Boolean(governingKey) && governingKey !== governingJsonKey)
67
+ governingKeys.unshift(governingKey);
68
+ const governingInput = inputs.find((input) => input.key === governingKey) ?? {};
69
+ /** Continue recursion if the governing select has a governingKey */
70
+ if (Boolean(governingInput.governingKey)) {
71
+ return getGoverningSelectKeysMap({
72
+ governingKey: governingInput.governingKey,
73
+ governingJsonKey,
74
+ governingKeys,
75
+ inputs,
76
+ });
77
+ }
78
+ else {
79
+ return governingKeys;
80
+ }
81
+ }
82
+ function getGoverningSelectDeepOptions({ formikValues, governingInputJsonObject, governingKeys, input, inputs, }) {
83
+ const nextKey = governingKeys.shift();
84
+ if (nextKey) {
85
+ const nextKeyInput = inputs.find((input) => input.key === nextKey) ?? {};
86
+ const nextInputJsonObject = governingInputJsonObject[nextKey].find((jsonElement) => jsonElement[nextKeyInput.jsonKey] === formikValues[nextKey]);
87
+ return getGoverningSelectDeepOptions({
88
+ formikValues,
89
+ governingInputJsonObject: nextInputJsonObject,
90
+ governingKeys,
91
+ input,
92
+ inputs,
93
+ });
94
+ }
95
+ else {
96
+ return governingInputJsonObject[input.key].map((option) => ({
97
+ label: option[input.jsonLabel],
98
+ value: option[input.jsonKey],
99
+ }));
100
+ }
101
+ }
102
+ async function handleGoverningSelectChange({ formikProps, input, inputs, isInputBeingChanged, selectedItem, }) {
103
+ const { key, value } = input;
104
+ const inputsGovernedByCurrentOne = inputs.filter((formikInput) => formikInput.governingKey === key);
105
+ if (selectedItem?.value !== value) {
106
+ /** Erase value of governed inputs */
107
+ if (inputsGovernedByCurrentOne.length) {
108
+ await inputsGovernedByCurrentOne.forEach(async (input) => {
109
+ await handleGoverningSelectChange({ formikProps, input, inputs, isInputBeingChanged: false, selectedItem: null });
110
+ });
111
+ }
112
+ // only the top governing select should display warnings if changed and reset touched status for governed ones
113
+ await formikProps.setFieldTouched(`['${key}']`, isInputBeingChanged);
114
+ formikProps.setFieldValue(`['${key}']`, selectedItem ? selectedItem.value : "");
115
+ formikProps.setFieldValue(`['${key}-keyLabel']`, selectedItem ? selectedItem.label : "");
116
+ }
117
+ }
118
+ function generateYupAst({ inputs, allowCustomPropertySyntax, customPropertySyntaxPattern, customPropertyStartsWithPattern, useCSVforArrays, }) {
119
+ if (allowCustomPropertySyntax) {
120
+ registerCustomPropertyMethods(customPropertySyntaxPattern, customPropertyStartsWithPattern);
121
+ }
122
+ let yupShape = {};
123
+ inputs.forEach((input) => {
124
+ let yupValidationArray = [];
125
+ const inputType = input.type ?? "";
126
+ if (!INPUT_TYPES_ARRAY.includes(inputType)) {
127
+ return;
128
+ }
129
+ if (inputType === DATE_TYPES.DATE) {
130
+ yupValidationArray.push(["yup.date", "Enter a valid date"]);
131
+ }
132
+ if (inputType === TEXT_AREA_TYPES.TEXT_AREA ||
133
+ inputType === TEXT_INPUT_TYPES.EMAIL ||
134
+ inputType === TEXT_INPUT_TYPES.PASSWORD ||
135
+ inputType === TEXT_INPUT_TYPES.SECURED ||
136
+ inputType === TEXT_INPUT_TYPES.TEL ||
137
+ inputType === TEXT_INPUT_TYPES.TEXT ||
138
+ inputType === TEXT_INPUT_TYPES.TIME ||
139
+ inputType === TEXT_INPUT_TYPES.URL ||
140
+ inputType === RADIO_TYPES.RADIO ||
141
+ inputType === SELECT_TYPES.SELECT ||
142
+ inputType?.startsWith(TEXT_EDITOR_TYPES.TEXT_EDITOR)) {
143
+ yupValidationArray.push(["yup.string"]);
144
+ // if (
145
+ // allowCustomPropertySyntax &&
146
+ // inputType !== TEXT_INPUT_TYPES.EMAIL &&
147
+ // inputType !== TEXT_INPUT_TYPES.URL &&
148
+ // inputType !== TEXT_INPUT_TYPES.SECURED &&
149
+ // inputType !== TEXT_INPUT_TYPES.PASSWORD
150
+ // )
151
+ // yupValidationArray.push(
152
+ // ['yup.customProperty'],
153
+ // ['yup.typeError', 'Enter valid syntax for a property']
154
+ // );
155
+ // Create a customValidator for each input b/c regex deserialization
156
+ // does not work currently
157
+ const { pattern } = input;
158
+ if (typeof pattern === "string") {
159
+ addCustomValidator(`${input.key}-matches`, yup.string().test(`${input.key}-matches`, input.patternInvalidText || `Enter a value that matches pattern: ${input.pattern}`, (value) => {
160
+ if (!input.required && !Boolean(value)) {
161
+ return true;
162
+ }
163
+ else
164
+ return new RegExp(pattern).test(value);
165
+ }));
166
+ yupValidationArray.push([`${input.key}-matches`]);
167
+ }
168
+ //TODO: figure out how to update serialization in yup-ast so we can use the native "matches" validator
169
+ // if (input.pattern) {
170
+ // yupValidationArray.push([
171
+ // 'yup.matches',
172
+ // new RegExp(input.pattern),
173
+ // {
174
+ // message: `Enter a value that matches pattern ${input.pattern}`,
175
+ // excludeEmptyString: true,
176
+ // },
177
+ // ]);
178
+ // }
179
+ if (inputType === TEXT_INPUT_TYPES.EMAIL) {
180
+ if (allowCustomPropertySyntax)
181
+ yupValidationArray.push(["yup.emailWithCustomProperty"], ["yup.typeError", "Enter a valid email"]);
182
+ else
183
+ yupValidationArray.push(["yup.email", "Enter a valid email"]);
184
+ }
185
+ if (inputType === TEXT_INPUT_TYPES.URL) {
186
+ if (allowCustomPropertySyntax)
187
+ yupValidationArray.push(["yup.urlWithCustomProperty"], ["yup.typeError", "Enter a valid URL"]);
188
+ else
189
+ yupValidationArray.push(["yup.url", "Enter a valid URL"]);
190
+ }
191
+ }
192
+ if (inputType === TEXT_INPUT_TYPES.NUMBER) {
193
+ yupValidationArray.push(["yup.number", "Enter a number"]);
194
+ }
195
+ if (inputType === BOOLEAN_TYPES.BOOLEAN) {
196
+ yupValidationArray.push(["yup.boolean"]);
197
+ }
198
+ if (inputType === MULTI_SELECT_TYPES.MULTI_SELECT ||
199
+ inputType === CREATABLE_TYPES.CREATABLE_SINGLE ||
200
+ inputType === CREATABLE_TYPES.CREATABLE_SINGLE_NON_DELETABLE ||
201
+ inputType === CREATABLE_TYPES.CREATABLE_PAIR ||
202
+ inputType === CREATABLE_TYPES.CREATABLE_PAIR_NON_DELETABLE ||
203
+ inputType === CHECKBOX_TYPES.CHECKBOX) {
204
+ if (useCSVforArrays) {
205
+ yupValidationArray.push(["yup.string"]);
206
+ const { pattern } = input;
207
+ if (pattern === typeof "string") {
208
+ addCustomValidator(`${input.key}-matches`, yup.string().test(`${input.key}-matches`, input.patternInvalidText || `Enter values that matches pattern: ${input.pattern}`, (csv) => {
209
+ const regexTester = new RegExp(pattern);
210
+ return csv?.split(",").every((val) => regexTester.test(val)) ?? false;
211
+ }));
212
+ yupValidationArray.push([`${input.key}-matches`]);
213
+ }
214
+ }
215
+ else {
216
+ yupValidationArray.push(["yup.array"]);
217
+ const { pattern } = input;
218
+ if (typeof pattern === "string") {
219
+ addCustomValidator(`${input.key}-matches`, yup.array().test(`${input.key}-matches`, input.patternInvalidText || `Enter values that matches pattern: ${pattern}`, (values) => {
220
+ const regexTester = new RegExp(pattern);
221
+ return values?.every((val) => regexTester.test(val)) ?? false;
222
+ }));
223
+ yupValidationArray.push([`${input.key}-matches`]);
224
+ }
225
+ }
226
+ }
227
+ if (Object.values(TEXT_INPUT_TYPES).includes(inputType) ||
228
+ inputType === TEXT_AREA_TYPES.TEXT_AREA ||
229
+ inputType === TEXT_EDITOR_TYPES.TEXT_EDITOR) {
230
+ if (inputType === TEXT_INPUT_TYPES.NUMBER) {
231
+ if (input.min) {
232
+ yupValidationArray.push(["yup.min", input.min, `Enter value greater than ${input.min}`]);
233
+ }
234
+ if (input.max) {
235
+ yupValidationArray.push(["yup.max", input.max, `Enter value less than ${input.max}`]);
236
+ }
237
+ }
238
+ else {
239
+ if (input.min) {
240
+ yupValidationArray.push(["yup.min", input.min, `Enter at least ${input.min} characters`]);
241
+ }
242
+ if (input.max) {
243
+ yupValidationArray.push(["yup.max", input.max, `Enter at most ${input.max} characters`]);
244
+ }
245
+ }
246
+ }
247
+ if (Array.isArray(input.invalidValues)) {
248
+ yupValidationArray.push(["yup.notOneOf", input.invalidValues, `Enter an allowed value`]);
249
+ }
250
+ if (input.required) {
251
+ if (inputType === BOOLEAN_TYPES.BOOLEAN) {
252
+ yupValidationArray.push(["yup.oneOf", [true], "Toggle must be checked"]);
253
+ }
254
+ else {
255
+ yupValidationArray.push(["yup.required", `Enter a value for ${input.label}`]);
256
+ }
257
+ }
258
+ if (yupValidationArray.length > 0) {
259
+ yupShape[input.key] = yupValidationArray;
260
+ }
261
+ });
262
+ return [["yup.object"], ["yup.shape", yupShape]];
263
+ }
264
+ function generateYupSchema({ inputs, allowCustomPropertySyntax, customPropertySyntaxPattern, customPropertyStartsWithPattern, useCSVforArrays, validationSchemaExtension, }) {
265
+ let validationSchema = transformAll(generateYupAst({
266
+ inputs,
267
+ allowCustomPropertySyntax,
268
+ customPropertySyntaxPattern,
269
+ customPropertyStartsWithPattern,
270
+ useCSVforArrays,
271
+ }));
272
+ if (validationSchemaExtension) {
273
+ validationSchema = validationSchema.concat(validationSchemaExtension);
274
+ }
275
+ return validationSchema;
276
+ }
277
+ /**
278
+ * Get initial values of each input in array of inputs
279
+ */
280
+ const determineInitialValues = (inputs, useCSVforArrays) => {
281
+ const values = {};
282
+ inputs.forEach((input) => {
283
+ let value = "";
284
+ let valueToCheck = input.value || input.defaultValue;
285
+ const isArrayInput = !useCSVforArrays && Object.values(ARRAY_INPUT_TYPES).includes(input.type);
286
+ if (isArrayInput) {
287
+ valueToCheck = input.value || input.defaultValue || input.values || input.defaultValues;
288
+ }
289
+ if (valueToCheck) {
290
+ switch (valueToCheck) {
291
+ case "false": {
292
+ value = false;
293
+ break;
294
+ }
295
+ case "true": {
296
+ value = true;
297
+ break;
298
+ }
299
+ default: {
300
+ value = valueToCheck;
301
+ }
302
+ }
303
+ }
304
+ values[input.key] = value;
305
+ });
306
+ return values;
307
+ };
308
+ /**
309
+ * Check if an input X needs to be conditionally rendered
310
+ * If it does, then find an input Y in the same section that has key equal to the input X's requiredForKey
311
+ * If input Y has a value that is present in input X's requiredValueOf array, then render X
312
+ */
313
+ const conditionallyRenderInput = (input, values) => {
314
+ if (!input.conditionallyRender) {
315
+ return true;
316
+ }
317
+ if (input.requiredForKey && input.requiredValueOf) {
318
+ /**
319
+ * Check which input in this section has the key equal to requiredForKey and get its value
320
+ */
321
+ const requiredForKeyInputValue = values[input.requiredForKey];
322
+ const valuesInputIsRenderedFor = input.requiredValueOf;
323
+ /**
324
+ * If the value of the input this input is required for is an array loop through those values to find a matching one
325
+ * by going through all of configured values for the input - the "requiredValueOf" of property
326
+ * Check for the value and the string of the value bc of how the services work. "true" and "false" are strings not boolean values
327
+ */
328
+ if (Array.isArray(requiredForKeyInputValue)) {
329
+ for (let requiredForValue of valuesInputIsRenderedFor) {
330
+ for (let singleRequiredForKeyInputValue of requiredForKeyInputValue) {
331
+ if (requiredForValue === singleRequiredForKeyInputValue ||
332
+ requiredForValue === String(singleRequiredForKeyInputValue)) {
333
+ return true;
334
+ }
335
+ }
336
+ }
337
+ }
338
+ else {
339
+ for (let requiredForValue of valuesInputIsRenderedFor) {
340
+ if (requiredForValue === requiredForKeyInputValue || requiredForValue === String(requiredForKeyInputValue)) {
341
+ return true;
342
+ }
343
+ }
344
+ }
345
+ }
346
+ else {
347
+ return false;
348
+ }
349
+ };
350
+ /**
351
+ * Map of the input groups to specifc props to be passed
352
+ */
353
+ const TYPE_PROPS = {
354
+ [INPUT_GROUPS.CHECKBOX]: (formikProps, { key }, inputs, useCSVforArrays) => ({
355
+ onChange: (value, id, event, selectedItems) => {
356
+ if (useCSVforArrays) {
357
+ formikProps.setFieldValue(`['${key}']`, selectedItems?.join() ?? "");
358
+ }
359
+ else {
360
+ formikProps.setFieldValue(`['${key}']`, selectedItems);
361
+ }
362
+ },
363
+ }),
364
+ [INPUT_GROUPS.CREATABLE]: (formikProps, { key }, inputs, useCSVforArrays) => ({
365
+ onChange: (createdItems) => {
366
+ formikProps.setFieldTouched(`['${key}']`, true);
367
+ if (useCSVforArrays) {
368
+ formikProps.setFieldValue(`['${key}']`, createdItems?.join() ?? "");
369
+ }
370
+ else {
371
+ formikProps.setFieldValue(`['${key}']`, createdItems);
372
+ }
373
+ },
374
+ onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
375
+ }),
376
+ [INPUT_GROUPS.DATE]: (formikProps, { key, type }) => type === DATE_TYPES.DATE_RANGE
377
+ ? {
378
+ onChange: (dateArray) => formikProps.setFieldValue(`['${key}']`, dateArray?.map((date) => date.toISOString())),
379
+ }
380
+ : {
381
+ onChange: formikProps.handleChange,
382
+ onCalendarChange: (dateArray) => formikProps.setFieldValue(`['${key}']`, dateArray[0]?.toISOString()),
383
+ },
384
+ [INPUT_GROUPS.MULTI_SELECT]: (formikProps, { key }, inputs, useCSVforArrays) => ({
385
+ onChange: async ({ selectedItems }) => {
386
+ await formikProps.setFieldTouched(`['${key}']`, true);
387
+ if (useCSVforArrays) {
388
+ formikProps.setFieldValue(`['${key}']`, selectedItems ? selectedItems.map((item) => item && item.value).join() : "");
389
+ }
390
+ else {
391
+ formikProps.setFieldValue(`['${key}']`, selectedItems.map((item) => item && item.value));
392
+ }
393
+ },
394
+ onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
395
+ }),
396
+ [INPUT_GROUPS.RADIO]: (formikProps, { key }) => ({
397
+ onChange: (value) => formikProps.setFieldValue(`['${key}']`, value),
398
+ }),
399
+ [INPUT_GROUPS.SELECT]: (formikProps, input, inputs) => {
400
+ const { key, value } = input;
401
+ let typeProps = {
402
+ onChange: async ({ selectedItem }) => {
403
+ if (selectedItem.value !== value) {
404
+ await formikProps.setFieldTouched(`['${key}']`, true);
405
+ formikProps.setFieldValue(`['${key}']`, selectedItem ? selectedItem.value : "");
406
+ }
407
+ },
408
+ onInputBlur: () => formikProps.setFieldTouched(`['${key}']`, true, true),
409
+ };
410
+ /**
411
+ * Start Governing Selects logic if input contains governingJsonKey
412
+ */
413
+ if (Boolean(input.governingJsonKey)) {
414
+ const { governingJsonKey, governingKey, jsonKey, jsonLabel } = input;
415
+ const governingJsonInput = inputs.find((input) => input.key === governingJsonKey);
416
+ /** Check if governingJson with all governing selects data exists as an array */
417
+ if (governingJsonInput && Array.isArray(governingJsonInput.governingJson)) {
418
+ const { governingJson } = governingJsonInput;
419
+ let governingOptions = [];
420
+ let governingDisabled = false;
421
+ /**
422
+ * Select "governingOptions"
423
+ * If current select is the top level governing select, just get the top level options from the json
424
+ */
425
+ if (key === governingJsonKey) {
426
+ governingOptions = governingJson.map((option) => ({
427
+ label: option[jsonLabel],
428
+ value: option[jsonKey],
429
+ }));
430
+ }
431
+ else {
432
+ /** Check if the select that governs this one has a value and disable if it doesn't */
433
+ const governingSelectValue = formikProps.values[governingKey];
434
+ if (Boolean(governingSelectValue)) {
435
+ let governingKeys = getGoverningSelectKeysMap({
436
+ governingKey,
437
+ governingJsonKey,
438
+ governingKeys: [],
439
+ inputs,
440
+ });
441
+ governingOptions = getGoverningSelectDeepOptions({
442
+ formikValues: formikProps.values,
443
+ governingInputJsonObject: governingJson.find((jsonElement) => jsonElement[governingJsonInput.jsonKey] === formikProps.values[governingJsonKey]),
444
+ governingKeys: [...governingKeys],
445
+ input,
446
+ inputs,
447
+ });
448
+ }
449
+ else {
450
+ governingDisabled = true;
451
+ }
452
+ }
453
+ typeProps = {
454
+ ...typeProps,
455
+ onChange: ({ selectedItem }) => handleGoverningSelectChange({ formikProps, input, inputs, selectedItem, isInputBeingChanged: true }),
456
+ governingOptions,
457
+ governingDisabled,
458
+ };
459
+ }
460
+ }
461
+ return typeProps;
462
+ },
463
+ [INPUT_GROUPS.TEXT_AREA]: (formikProps) => ({
464
+ onChange: formikProps.handleChange,
465
+ }),
466
+ [INPUT_GROUPS.TEXT_EDITOR]: (formikProps) => ({
467
+ onChange: formikProps.handleChange,
468
+ }),
469
+ [INPUT_GROUPS.TEXT_INPUT]: (formikProps) => ({
470
+ onChange: formikProps.handleChange,
471
+ }),
472
+ [INPUT_GROUPS.BOOLEAN]: (formikProps, { key }) => ({
473
+ onChange: (value) => {
474
+ formikProps.setFieldTouched(`['${key}']`, true, true);
475
+ formikProps.setFieldValue(`['${key}']`, value);
476
+ },
477
+ }),
478
+ };
479
+ function determineTypeProps(type, otherProps) {
480
+ const { checkboxListProps, creatableProps, dateProps, multiSelectProps, radioProps, selectProps, textAreaProps, textEditorProps, textInputProps, toggleProps, } = otherProps;
481
+ if (Object.values(CHECKBOX_TYPES).includes(type)) {
482
+ return {
483
+ typeProps: TYPE_PROPS[INPUT_GROUPS.CHECKBOX],
484
+ additionalTypeProps: checkboxListProps,
485
+ };
486
+ }
487
+ if (Object.values(CREATABLE_TYPES).includes(type)) {
488
+ return {
489
+ typeProps: TYPE_PROPS[INPUT_GROUPS.CREATABLE],
490
+ additionalTypeProps: creatableProps,
491
+ };
492
+ }
493
+ if (Object.values(DATE_TYPES).includes(type)) {
494
+ return {
495
+ typeProps: TYPE_PROPS[INPUT_GROUPS.DATE],
496
+ additionalTypeProps: dateProps,
497
+ };
498
+ }
499
+ if (Object.values(MULTI_SELECT_TYPES).includes(type)) {
500
+ return {
501
+ typeProps: TYPE_PROPS[INPUT_GROUPS.MULTI_SELECT],
502
+ additionalTypeProps: multiSelectProps,
503
+ };
504
+ }
505
+ if (Object.values(RADIO_TYPES).includes(type)) {
506
+ return {
507
+ typeProps: TYPE_PROPS[INPUT_GROUPS.RADIO],
508
+ additionalTypeProps: radioProps,
509
+ };
510
+ }
511
+ if (Object.values(SELECT_TYPES).includes(type)) {
512
+ return {
513
+ typeProps: TYPE_PROPS[INPUT_GROUPS.SELECT],
514
+ additionalTypeProps: selectProps,
515
+ };
516
+ }
517
+ if (Object.values(TEXT_AREA_TYPES).includes(type)) {
518
+ return {
519
+ typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_AREA],
520
+ additionalTypeProps: textAreaProps,
521
+ };
522
+ }
523
+ if (type.startsWith(TEXT_EDITOR_TYPES.TEXT_EDITOR)) {
524
+ return {
525
+ typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_EDITOR],
526
+ additionalTypeProps: textEditorProps,
527
+ };
528
+ }
529
+ if (Object.values(TEXT_INPUT_TYPES).includes(type)) {
530
+ return {
531
+ typeProps: TYPE_PROPS[INPUT_GROUPS.TEXT_INPUT],
532
+ additionalTypeProps: textInputProps,
533
+ };
534
+ }
535
+ if (Object.values(BOOLEAN_TYPES).includes(type)) {
536
+ return {
537
+ typeProps: TYPE_PROPS[INPUT_GROUPS.BOOLEAN],
538
+ additionalTypeProps: toggleProps,
539
+ };
540
+ }
541
+ return { typeProps: () => { }, additionalTypeProps: () => { } };
542
+ }
543
+ DynamicFormik.defaultProps = {
544
+ checkboxListProps: (...args) => ({}),
545
+ creatableProps: (...args) => ({}),
546
+ dateProps: (...args) => ({}),
547
+ multiSelectProps: (...args) => ({}),
548
+ radioProps: (...args) => ({}),
549
+ selectProps: (...args) => ({}),
550
+ textAreaProps: (...args) => ({}),
551
+ textEditorProps: (...args) => ({}),
552
+ textInputProps: (...args) => ({}),
553
+ toggleProps: (...args) => ({}),
554
+ };
555
+ function DynamicFormik({ additionalInitialValues = {}, allowCustomPropertySyntax = false, customPropertySyntaxPattern = /\$\{p:([a-zA-Z0-9_.-]+)\}|\$\(([a-zA-Z0-9_.-\s]+)\)/g, customPropertyStartsWithPattern = /\$\{|\$\(/g, children, dataDrivenInputProps, inputProps, initialValues, inputs, onSubmit, useCSVforArrays = false, validationSchema, validationSchemaExtension, ...otherProps }) {
556
+ return (React.createElement(Formik, { initialValues: (Boolean(initialValues) && initialValues) || {
557
+ ...determineInitialValues(inputs, useCSVforArrays),
558
+ ...additionalInitialValues,
559
+ }, validationSchema: validationSchema ||
560
+ generateYupSchema({
561
+ inputs,
562
+ allowCustomPropertySyntax,
563
+ customPropertySyntaxPattern,
564
+ customPropertyStartsWithPattern,
565
+ useCSVforArrays,
566
+ validationSchemaExtension,
567
+ }), onSubmit: (values, actions) => {
568
+ if (onSubmit)
569
+ onSubmit(values, actions);
570
+ }, ...otherProps }, (formikProps) => {
571
+ const { values, touched, errors, handleBlur } = formikProps;
572
+ const finalInputs = inputs.filter((input) => conditionallyRenderInput(input, values));
573
+ const dataDrivenInputs = finalInputs.map((input) => {
574
+ const { key, type, value, // eslint-disable-line
575
+ ...otherInputsProps } = input;
576
+ const inputValue = values[key] !== undefined &&
577
+ values[key] !== null &&
578
+ (Object.values(TEXT_INPUT_TYPES).includes(type) ||
579
+ type === TEXT_AREA_TYPES.TEXT_AREA ||
580
+ type === TEXT_EDITOR_TYPES.TEXT_EDITOR)
581
+ ? values[key].toString()
582
+ : values[key];
583
+ const invalidText = get(errors, key);
584
+ const invalid = invalidText && get(touched, key);
585
+ const { typeProps = () => { }, additionalTypeProps = () => { } } = determineTypeProps(type, otherProps);
586
+ return (React.createElement(DataDrivenInput, { key: key, customComponent: input.customComponent, formikProps: formikProps, id: `['${key}']`, invalid: invalid, invalidText: invalidText, name: `['${key}']`, onBlur: handleBlur, type: type, value: inputValue, ...typeProps(formikProps, input, finalInputs, useCSVforArrays), ...otherInputsProps, ...inputProps, ...additionalTypeProps({ formikProps, input }), ...dataDrivenInputProps }));
587
+ });
588
+ return (React.createElement("div", { className: `${prefix}--bmrg-dynamic-formik` }, children({ inputs: dataDrivenInputs, formikProps })));
589
+ }));
590
590
  }
591
591
 
592
592
  export { DynamicFormik as default };