@integry/sdk 4.5.2 → 4.5.4

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 (279) hide show
  1. package/.vscode/launch.json +2 -2
  2. package/THIRD_PARTY_LICENSES +0 -37
  3. package/dist/esm/index.csm.d.ts +12 -2
  4. package/dist/esm/index.csm.js +7262 -1
  5. package/dist/umd/index.umd.d.ts +9 -1
  6. package/dist/umd/index.umd.js +7262 -1
  7. package/jest.config.cjs +10 -0
  8. package/package.json +10 -4
  9. package/src/components/AddTagButton/index.ts +23 -0
  10. package/src/components/BasicSelect/index.ts +114 -0
  11. package/src/components/BasicSelect/styles.module.scss +44 -0
  12. package/src/components/Button/index.ts +94 -0
  13. package/src/components/Button/styles.module.scss +152 -0
  14. package/src/components/CheckboxGroup/Checkbox.ts +104 -0
  15. package/src/components/CheckboxGroup/index.ts +190 -0
  16. package/src/components/CheckboxGroup/styles.module.scss +63 -0
  17. package/src/components/CollapsedMenu/index.ts +101 -0
  18. package/src/components/CollapsedMenu/styles.module.scss +46 -0
  19. package/src/components/ConfigureFieldWrapper/index.ts +85 -0
  20. package/src/components/ConfigureFieldWrapper/styles.module.scss +57 -0
  21. package/src/components/EditableText/index.ts +121 -0
  22. package/src/components/EditableText/styles.module.scss +38 -0
  23. package/src/components/EditableTextArea/index.ts +143 -0
  24. package/src/components/EditableTextArea/styles.module.scss +91 -0
  25. package/src/components/ErrorMessage/index.ts +16 -0
  26. package/src/components/ErrorMessage/styles.module.scss +19 -0
  27. package/src/components/ErrorPage/index.ts +42 -0
  28. package/src/components/ErrorPage/styles.module.scss +26 -0
  29. package/src/components/Footer/index.ts +41 -0
  30. package/src/components/Footer/styles.module.scss +40 -0
  31. package/src/components/HTMLContent/index.tsx +275 -0
  32. package/src/components/HTMLContent/styles.module.scss +3 -0
  33. package/src/components/InfoBox/index.ts +48 -0
  34. package/src/components/InfoBox/styles.module.scss +21 -0
  35. package/src/components/Input/BaseInput/index.ts +170 -0
  36. package/src/components/Input/BaseInput/styles.module.scss +94 -0
  37. package/src/components/Input/DateInput/index.ts +103 -0
  38. package/src/components/Input/DateInput/styles.module.scss +50 -0
  39. package/src/components/Input/Input/index.ts +206 -0
  40. package/src/components/Input/Input/styles.module.scss +14 -0
  41. package/src/components/Input/PasswordInput/index.ts +164 -0
  42. package/src/components/Input/PasswordInput/styles.module.scss +37 -0
  43. package/src/components/Input/index.ts +7 -0
  44. package/src/components/Label/index.ts +61 -0
  45. package/src/components/Label/styles.module.scss +41 -0
  46. package/src/components/LargeLoader/index.ts +25 -0
  47. package/src/components/LargeLoader/styles.module.scss +16 -0
  48. package/src/components/Listbox/ListBoxItem.ts +57 -0
  49. package/src/components/Listbox/index.ts +479 -0
  50. package/src/components/Listbox/styles.module.scss +197 -0
  51. package/src/components/Loader/index.ts +25 -0
  52. package/src/components/Loader/styles.module.scss +16 -0
  53. package/src/components/MediaGallery/MediaGalleryModal.ts +82 -0
  54. package/src/components/MediaGallery/MediaSlider.ts +76 -0
  55. package/src/components/MediaGallery/index.ts +92 -0
  56. package/src/components/MediaGallery/styles.module.scss +156 -0
  57. package/src/components/MediaUpload/index.ts +233 -0
  58. package/src/components/MediaUpload/styles.module.scss +118 -0
  59. package/src/components/Modal/index.ts +87 -0
  60. package/src/components/Modal/styles.module.scss +441 -0
  61. package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +58 -0
  62. package/src/components/MultipurposeField/Dropdown/index.tsx +981 -0
  63. package/src/components/MultipurposeField/Dropdown/styles.module.scss +208 -0
  64. package/src/components/MultipurposeField/TagMenu/index.ts +384 -0
  65. package/src/components/MultipurposeField/TagMenu/styles.module.scss +136 -0
  66. package/src/components/MultipurposeField/TagOptions/index.tsx +83 -0
  67. package/src/components/MultipurposeField/TagOptions/styles.module.scss +95 -0
  68. package/src/components/MultipurposeField/index.tsx +687 -0
  69. package/src/components/MultipurposeField/styles.module.scss +56 -0
  70. package/src/components/NewModal/index.ts +69 -0
  71. package/src/components/NewModal/styles.module.scss +70 -0
  72. package/src/components/OverflowTooltip/index.tsx +59 -0
  73. package/src/components/PopUp/ConfirmationPopUp/index.ts +58 -0
  74. package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +49 -0
  75. package/src/components/PopUp/SuccessPopUp/index.ts +62 -0
  76. package/src/components/PopUp/SuccessPopUp/styles.module.scss +38 -0
  77. package/src/components/RadioGroup/Radio.ts +129 -0
  78. package/src/components/RadioGroup/index.ts +169 -0
  79. package/src/components/RadioGroup/styles.module.scss +81 -0
  80. package/src/components/Search/index.ts +69 -0
  81. package/src/components/Search/styles.module.scss +149 -0
  82. package/src/components/TabBar/Tab.ts +33 -0
  83. package/src/components/TabBar/index.ts +64 -0
  84. package/src/components/TabBar/styles.module.scss +43 -0
  85. package/src/components/Tag/index.ts +29 -0
  86. package/src/components/Tag/styles.module.scss +57 -0
  87. package/src/components/TextArea/index.ts +172 -0
  88. package/src/components/TextArea/styles.module.scss +70 -0
  89. package/src/components/TextContent/index.tsx +128 -0
  90. package/src/components/TextContent/styles.module.scss +6 -0
  91. package/src/components/ThreeDotLoader/index.ts +39 -0
  92. package/src/components/ThreeDotLoader/styles.module.scss +41 -0
  93. package/src/components/TimeInput/index.ts +129 -0
  94. package/src/components/TimeInput/styles.module.scss +16 -0
  95. package/src/components/Toggle/index.ts +34 -0
  96. package/src/components/Toggle/styles.module.scss +56 -0
  97. package/src/components/Toggle-v2/index.ts +40 -0
  98. package/src/components/Toggle-v2/styles.module.scss +86 -0
  99. package/src/components/Tooltip/index.ts +271 -0
  100. package/src/components/Tooltip/styles.module.scss +105 -0
  101. package/src/components/form/ObjectField/index.ts +364 -0
  102. package/src/components/form/ObjectField/styles.module.scss +103 -0
  103. package/src/components/form/index.ts +3 -0
  104. package/src/contexts/AppContext.ts +12 -0
  105. package/src/declaration.d.ts +7 -0
  106. package/src/extensions/HMAC.ts +25 -0
  107. package/src/extensions/IntegryAPIError.ts +19 -0
  108. package/src/features/common/AccountDropdown/index.ts +291 -0
  109. package/src/features/common/AccountDropdown/styles.module.scss +19 -0
  110. package/src/features/common/ActionForm/index.ts +1818 -0
  111. package/src/features/common/ActionForm/styles.module.scss +23 -0
  112. package/src/features/common/AppCard/index.ts +207 -0
  113. package/src/features/common/AppCard/styles.module.scss +117 -0
  114. package/src/features/common/AppCardCompact/index.ts +189 -0
  115. package/src/features/common/AppCardCompact/styles.module.scss +141 -0
  116. package/src/features/common/AuthSelector/index.ts +537 -0
  117. package/src/features/common/AuthSelector/styles.module.scss +161 -0
  118. package/src/features/common/AuthSelectorCompact/index.ts +706 -0
  119. package/src/features/common/AuthSelectorCompact/styles.module.scss +219 -0
  120. package/src/features/common/AuthSelectorDropdown/index.ts +704 -0
  121. package/src/features/common/AuthSelectorDropdown/styles.module.scss +361 -0
  122. package/src/features/common/DynamicField/index.ts +229 -0
  123. package/src/features/common/DynamicField/styles.module.scss +67 -0
  124. package/src/features/common/DynamicTypedField/index.ts +217 -0
  125. package/src/features/common/DynamicTypedField/styles.module.scss +67 -0
  126. package/src/features/common/FunctionForm/index.ts +862 -0
  127. package/src/features/common/FunctionForm/styles.module.scss +163 -0
  128. package/src/features/common/MappingUI/index.ts +649 -0
  129. package/src/features/common/MappingUI/styles.module.scss +121 -0
  130. package/src/features/common/MarketplaceAppCard/index.ts +279 -0
  131. package/src/features/common/MarketplaceAppCard/styles.module.scss +231 -0
  132. package/src/features/common/MarketplaceAppCardCompact/index.ts +283 -0
  133. package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +255 -0
  134. package/src/features/common/NewMappingUI/index.ts +515 -0
  135. package/src/features/common/NewMappingUI/styles.module.scss +113 -0
  136. package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +67 -0
  137. package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +23 -0
  138. package/src/features/common/RequestAppWidget/index.ts +48 -0
  139. package/src/features/common/RequestAppWidget/request-app-form.ts +89 -0
  140. package/src/features/common/RequestAppWidget/styles.module.scss +43 -0
  141. package/src/features/common/SectionField/index.ts +272 -0
  142. package/src/features/common/SectionField/styles.module.scss +67 -0
  143. package/src/features/common/Step/index.ts +827 -0
  144. package/src/features/common/Step/styles.module.scss +12 -0
  145. package/src/features/common/StepNavigation/CollapsedSteps.ts +125 -0
  146. package/src/features/common/StepNavigation/NavItem.ts +111 -0
  147. package/src/features/common/StepNavigation/index.ts +257 -0
  148. package/src/features/common/StepNavigation/styles.module.scss +117 -0
  149. package/src/features/common/Steps/index.ts +1139 -0
  150. package/src/features/common/Steps/styles.module.scss +314 -0
  151. package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +383 -0
  152. package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +367 -0
  153. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +194 -0
  154. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +389 -0
  155. package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +577 -0
  156. package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +83 -0
  157. package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +212 -0
  158. package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +45 -0
  159. package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +1081 -0
  160. package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +452 -0
  161. package/src/features/containers/AppFlowContainer/Authentication/index.ts +610 -0
  162. package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +468 -0
  163. package/src/features/containers/AppFlowContainer/index.ts +114 -0
  164. package/src/features/containers/AppPageContainer/AppPage/index.tsx +262 -0
  165. package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +120 -0
  166. package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +165 -0
  167. package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +81 -0
  168. package/src/features/containers/AppPageContainer/index.tsx +93 -0
  169. package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
  170. package/src/features/containers/AppsForFlows/index.ts +161 -0
  171. package/src/features/containers/AppsForFlows/styles.module.scss +280 -0
  172. package/src/features/containers/AppsForFlowsCompact/index.ts +161 -0
  173. package/src/features/containers/AppsForFlowsCompact/styles.module.scss +279 -0
  174. package/src/features/containers/AuthSetupContainer/AppSelection.ts +73 -0
  175. package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +67 -0
  176. package/src/features/containers/AuthSetupContainer/Footer.ts +32 -0
  177. package/src/features/containers/AuthSetupContainer/Header.ts +39 -0
  178. package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +27 -0
  179. package/src/features/containers/AuthSetupContainer/index.ts +349 -0
  180. package/src/features/containers/AuthSetupContainer/styles.module.scss +229 -0
  181. package/src/features/containers/FlowSetupContainer/index.ts +390 -0
  182. package/src/features/containers/FlowSetupContainer/styles.module.scss +18 -0
  183. package/src/features/containers/MarkeplaceApps/index.ts +574 -0
  184. package/src/features/containers/MarkeplaceApps/styles.module.scss +559 -0
  185. package/src/features/containers/MarketplaceAppsCompact/index.ts +576 -0
  186. package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +546 -0
  187. package/src/features/containers/MarketplaceAppsContainer/index.ts +83 -0
  188. package/src/features/containers/MarketplaceContainer/AppCard/index.ts +91 -0
  189. package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +66 -0
  190. package/src/features/containers/MarketplaceContainer/AppListing/index.ts +34 -0
  191. package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +10 -0
  192. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +132 -0
  193. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +117 -0
  194. package/src/features/containers/MarketplaceContainer/index.ts +242 -0
  195. package/src/features/containers/MarketplaceContainer/styles.module.scss +84 -0
  196. package/src/features/containers/SDKContainer/index.ts +817 -0
  197. package/src/features/containers/SDKContainer/styles.module.scss +266 -0
  198. package/src/features/containers/SDKDebugContainer/index.ts +137 -0
  199. package/src/features/containers/SDKDebugContainer/styles.module.scss +37 -0
  200. package/src/features/containers/SDKFailedContainer/index.ts +117 -0
  201. package/src/features/containers/SDKFailedContainer/styles.module.scss +57 -0
  202. package/src/features/integrations/IntegrationRow/Icons.ts +77 -0
  203. package/src/features/integrations/IntegrationRow/index.ts +129 -0
  204. package/src/features/integrations/IntegrationRow/styles.module.scss +62 -0
  205. package/src/features/integrations/IntegrationsHeader/index.ts +34 -0
  206. package/src/features/integrations/IntegrationsHeader/styles.module.scss +47 -0
  207. package/src/features/integrations/IntegrationsList/index.ts +252 -0
  208. package/src/features/integrations/IntegrationsList/styles.module.scss +67 -0
  209. package/src/features/templates/Template/index.ts +295 -0
  210. package/src/features/templates/Template/styles.module.scss +226 -0
  211. package/src/features/templates/TemplatesView/index.ts +368 -0
  212. package/src/features/templates/TemplatesView/styles.module.scss +71 -0
  213. package/src/features/templates/TemplatesViewCompact/index.ts +364 -0
  214. package/src/features/templates/TemplatesViewCompact/styles.module.scss +141 -0
  215. package/src/hooks/useAutosizeTextArea.ts +22 -0
  216. package/src/hooks/useCustomRef.ts +13 -0
  217. package/src/hooks/useDebounce.ts +17 -0
  218. package/src/hooks/useElementResize.ts +40 -0
  219. package/src/hooks/useEventListener.ts +44 -0
  220. package/src/hooks/useHover.ts +40 -0
  221. package/src/hooks/useOnClickOutside.ts +32 -0
  222. package/src/index.ts +2051 -0
  223. package/src/index.umd.ts +13 -0
  224. package/src/interfaces/index.ts +924 -0
  225. package/src/modules/api/index.ts +1315 -0
  226. package/src/modules/api/responseHandler.ts +38 -0
  227. package/src/modules/event-emitter/index.ts +72 -0
  228. package/src/modules/event-emitter/runners/abstract.ts +21 -0
  229. package/src/modules/event-emitter/runners/default.ts +11 -0
  230. package/src/modules/event-emitter/runners/ntimes.ts +28 -0
  231. package/src/modules/event-emitter/types.ts +34 -0
  232. package/src/store/actionFunctions.ts +1573 -0
  233. package/src/store/index.ts +17 -0
  234. package/src/store/initialState.ts +58 -0
  235. package/src/stories/Button.stories.tsx +83 -0
  236. package/src/stories/Checkbox/Checkbox.stories.tsx +41 -0
  237. package/src/stories/Checkbox/CheckboxGroup.stories.tsx +46 -0
  238. package/src/stories/EditableText.stories.tsx +35 -0
  239. package/src/stories/Input/BaseInput.stories.tsx +48 -0
  240. package/src/stories/Input/DateInput.stories.tsx +28 -0
  241. package/src/stories/Input/Input.stories.tsx +24 -0
  242. package/src/stories/Input/PasswordInput.stories.tsx +26 -0
  243. package/src/stories/Introduction.stories.mdx +211 -0
  244. package/src/stories/Label.stories.tsx +27 -0
  245. package/src/stories/Listbox.stories.tsx +122 -0
  246. package/src/stories/Radio/Radio.stories.tsx +39 -0
  247. package/src/stories/Radio/RadioGroup.stories.tsx +46 -0
  248. package/src/stories/StepNavigation/NavItem.stories.tsx +31 -0
  249. package/src/stories/StepNavigation/StepNavigation.stories.tsx +50 -0
  250. package/src/stories/TabBar.stories.tsx +31 -0
  251. package/src/stories/TextArea.stories.tsx +23 -0
  252. package/src/stories/TimeInput.stories.tsx +37 -0
  253. package/src/stories/Toggle.stories.tsx +33 -0
  254. package/src/stories/assets/code-brackets.svg +1 -0
  255. package/src/stories/assets/colors.svg +1 -0
  256. package/src/stories/assets/comments.svg +1 -0
  257. package/src/stories/assets/direction.svg +1 -0
  258. package/src/stories/assets/flow.svg +1 -0
  259. package/src/stories/assets/plugin.svg +1 -0
  260. package/src/stories/assets/repo.svg +1 -0
  261. package/src/stories/assets/stackalt.svg +1 -0
  262. package/src/types/index.ts +293 -0
  263. package/src/types/store.ts +366 -0
  264. package/src/types/utils.ts +19 -0
  265. package/src/utils/ActivityOutputUtils.ts +163 -0
  266. package/src/utils/common.ts +20 -0
  267. package/src/utils/copyToClipboard.ts +24 -0
  268. package/src/utils/datetime.ts +101 -0
  269. package/src/utils/getUrlParam.ts +11 -0
  270. package/src/utils/isAuthMessage.ts +16 -0
  271. package/src/utils/isBrowser.ts +1 -0
  272. package/src/utils/jsonEncodeDecode.ts +15 -0
  273. package/src/utils/objectUtils.ts +116 -0
  274. package/src/utils/popup.ts +30 -0
  275. package/src/utils/searchJson.ts +51 -0
  276. package/src/utils/stepUtils.ts +45 -0
  277. package/src/utils/truncate.ts +6 -0
  278. package/test/setup.ts +1 -0
  279. package/vitest.config.ts +10 -0
@@ -0,0 +1,981 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ /* eslint-disable no-use-before-define */
3
+ import { html } from 'htm/preact';
4
+ import {
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useState,
9
+ useRef,
10
+ } from 'preact/hooks';
11
+ import fuzzysort from 'fuzzysort';
12
+ import { createNewSortInstance } from 'fast-sort';
13
+ import { NestedObject } from '@/interfaces';
14
+ import { Label } from '@/components/Label';
15
+ import { Hint } from '@/components/Tooltip';
16
+ import { useOnClickOutside } from '@/hooks/useOnClickOutside';
17
+ import { ThreeDotLoader } from '@/components/ThreeDotLoader';
18
+ import { IntegryAPI } from '@/modules/api';
19
+ import { ErrorMessage } from '@/components/ErrorMessage';
20
+ import useCustomRef from '@/hooks/useCustomRef';
21
+ import { TagButton } from '@/components/AddTagButton';
22
+ import { ListBoxItemProps } from './ListBoxItem';
23
+ import { FieldDropdown, Tabs } from '../TagMenu';
24
+
25
+ import styles from './styles.module.scss';
26
+
27
+ type keyValueMapper = (input: any) => { id: any; value: any }[];
28
+
29
+ interface ListBoxProps {
30
+ title: string;
31
+ description: string;
32
+ items: Omit<ListBoxItemProps, 'onClick'>[];
33
+ value?: string;
34
+ onChange(val: string, stopPropagation?: boolean): void;
35
+ isOpen?: boolean;
36
+ isDynamic?: boolean;
37
+ endpointUrl?: string;
38
+ isSearchable?: boolean;
39
+ placeholder: string | null;
40
+ isRequired?: boolean;
41
+ isHidden?: boolean;
42
+ showStepValidation?: boolean;
43
+ responseMapper?(input: unknown): Omit<ListBoxItemProps, 'onClick'>[];
44
+ apiHandler: IntegryAPI;
45
+ endpointData: string;
46
+ isReadOnly?: boolean;
47
+ isChanged?: boolean;
48
+ tagValue?: string;
49
+ taggedSelect?: boolean;
50
+ skipOptionFetch?: boolean;
51
+ onAddTag?: () => void;
52
+ activityOutputData?: NestedObject;
53
+ sourceFlowData?: NestedObject;
54
+ sourceFlowIntegrataionInvocationUrl?: string;
55
+ isMappable: boolean;
56
+ type: string;
57
+ appName: string;
58
+ fieldId?: string;
59
+ isConfigMode: boolean;
60
+ isEditable: boolean;
61
+ allowTagsInText: boolean;
62
+ labelTags: string[];
63
+ hideTabs?: boolean;
64
+ selectedAuthId?: string;
65
+ disabled?: boolean;
66
+ isMultiSelect?: boolean;
67
+ optionKeyPath?: string;
68
+ valueKeyPath?: string;
69
+ dataSourceBody?: any;
70
+ }
71
+
72
+ const ListBox = (props: ListBoxProps) => {
73
+ const {
74
+ title,
75
+ description,
76
+ items: passedItems = [],
77
+ value = null,
78
+ isOpen = false,
79
+ isDynamic = false,
80
+ endpointData,
81
+ isSearchable = false,
82
+ isRequired = false,
83
+ isHidden = false,
84
+ placeholder,
85
+ onChange = () => null,
86
+ showStepValidation = false,
87
+ responseMapper = (input: { id: string; value: string }[]) => input,
88
+ isReadOnly = false,
89
+ isChanged = false,
90
+ tagValue = '',
91
+ taggedSelect = false,
92
+ skipOptionFetch = false,
93
+ onAddTag,
94
+ activityOutputData = {},
95
+ type,
96
+ appName,
97
+ fieldId = 'dropdown-field',
98
+ isConfigMode = false,
99
+ isMappable = false,
100
+ isEditable = false,
101
+ allowTagsInText = false,
102
+ labelTags = [],
103
+ endpointUrl,
104
+ hideTabs = true,
105
+ sourceFlowData = {},
106
+ sourceFlowIntegrataionInvocationUrl = '',
107
+ selectedAuthId = '',
108
+ disabled = false,
109
+ isMultiSelect = false,
110
+ dataSourceBody = {},
111
+ } = props;
112
+
113
+ const [query, setQuery] = useState<string>('');
114
+
115
+ const [items, setItems] = useState<Omit<ListBoxItemProps, 'onClick'>[]>(
116
+ passedItems,
117
+ );
118
+
119
+ const [highlightedIndex, setHighlightedIndex] = useState<number>(-1);
120
+
121
+ const [filteredItems, setFilteredItems] = useState<
122
+ Omit<ListBoxItemProps, 'onClick'>[]
123
+ >(passedItems);
124
+
125
+ const [loading, setLoading] = useState(
126
+ isDynamic && !passedItems.length && !value && selectedAuthId !== '',
127
+ );
128
+
129
+ const [isDropdownOpen, setIsDropdownOpen] = useState(isOpen);
130
+
131
+ const [tempPlaceholder, setTempPlaceholder] = useState('');
132
+ const [searchValue, setSearchValue] = useState('');
133
+ const [editableTextValue, setEditableTextValue] = useState(value);
134
+ const [isErrorOnLoadingOptions, setIsErrorOnLoadingOptions] = useState(false);
135
+ const [nextPage, setNextPage] = useState('');
136
+
137
+ const [selectedTab, setSelectedTab] = useState('');
138
+
139
+ const [dropdownRef] = useCustomRef<HTMLDivElement>();
140
+ const [dropdownMenuRef] = useCustomRef<HTMLDivElement>();
141
+ const [inputRef] = useCustomRef<HTMLInputElement>();
142
+ const queryRef = useRef(query);
143
+
144
+ useOnClickOutside(dropdownMenuRef, (e) => {
145
+ const clickedElement = e.target as HTMLElement;
146
+ const clickedElementIsDropdownField = document
147
+ .getElementById(fieldId)
148
+ ?.contains(clickedElement);
149
+ setTempPlaceholder('');
150
+
151
+ if (clickedElementIsDropdownField) {
152
+ return;
153
+ }
154
+ if (isDropdownOpen) {
155
+ setIsDropdownOpen(false);
156
+ setHighlightedIndex(-1);
157
+ setSearchValue('');
158
+ }
159
+ });
160
+
161
+ useEffect(() => {
162
+ queryRef.current = query;
163
+ }, [query]);
164
+
165
+ useEffect(() => {
166
+ if (value) {
167
+ if (onChange) onChange(value);
168
+ }
169
+ }, [fieldId]);
170
+
171
+ useEffect(() => {
172
+ if (highlightedIndex > -1 && isDropdownOpen) {
173
+ const item = filteredItems[highlightedIndex];
174
+ if (item) {
175
+ const domEl = document.querySelector(`[data-value="${item.id}"]`);
176
+ domEl?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
177
+ }
178
+ }
179
+ }, [highlightedIndex, isDropdownOpen]);
180
+
181
+ useEffect(() => {
182
+ if (tagValue && tagValue !== query) {
183
+ setQuery(tagValue);
184
+ }
185
+ }, [tagValue]);
186
+
187
+ useEffect(() => {
188
+ if (dropdownRef && dropdownRef.current && isDropdownOpen === true) {
189
+ if (dropdownRef && dropdownRef.current) {
190
+ dropdownRef.current?.addEventListener('keyup', upHandler);
191
+ }
192
+ }
193
+ document.addEventListener('keydown', handleKeyDown);
194
+ // Remove event listeners on cleanup
195
+ return () => {
196
+ if (dropdownRef && dropdownRef.current) {
197
+ dropdownRef.current.removeEventListener('keyup', upHandler);
198
+ }
199
+ document.removeEventListener('keydown', handleKeyDown);
200
+ };
201
+ }, [isDropdownOpen, dropdownRef, highlightedIndex]);
202
+
203
+ useEffect(() => {
204
+ let timer: null | ReturnType<typeof setTimeout> = null;
205
+ if (!Array.isArray(items)) {
206
+ setItems([]);
207
+ }
208
+ const item = items.find((a) => a.id === value);
209
+
210
+ if (!isDropdownOpen && query && !value) {
211
+ setQuery('');
212
+ timer = setTimeout(() => {
213
+ setSortedFilteredItems(items);
214
+ }, 250);
215
+ } else if (!isDropdownOpen && value && item) {
216
+ setQuery(item.value);
217
+ } else if (!isDropdownOpen && tagValue && !skipOptionFetch) {
218
+ setQuery(tagValue);
219
+ }
220
+ return () => {
221
+ if (timer) clearTimeout(timer);
222
+ };
223
+ }, [isDropdownOpen]);
224
+
225
+ useEffect(() => {
226
+ if (query && isSearchable) {
227
+ const filtered = fuzzysort
228
+ .go(query, items, {
229
+ keys: ['value'],
230
+ scoreFn: (keysResult) => {
231
+ const nameResult = keysResult[0];
232
+ const tagsResult = keysResult[1];
233
+ // assign higher score to name result
234
+ const score = Math.max(
235
+ nameResult ? nameResult.score + 100 : -Infinity,
236
+ tagsResult ? tagsResult.score : -Infinity,
237
+ );
238
+ return score;
239
+ },
240
+ })
241
+ .map((el) => el.obj);
242
+ setHighlightedIndex(-1);
243
+ setSortedFilteredItems(filtered);
244
+ if (filtered.length === 1) setHighlightedIndex(0);
245
+ } else if (isDropdownOpen) {
246
+ setHighlightedIndex(-1);
247
+ setSortedFilteredItems(items);
248
+ }
249
+ }, [query]);
250
+
251
+ useEffect(() => {
252
+ const checkboxItems = [
253
+ { id: '1', value: 'Yes' },
254
+ { id: '0', value: 'No' },
255
+ ];
256
+ // eslint-disable-next-line @typescript-eslint/no-shadow
257
+ if (skipOptionFetch && isDynamic) {
258
+ // skip option fetch for dynamic dropdowns only. Static dropdowns should always fetch options
259
+ setLoading(false);
260
+ setFilteredItems([]);
261
+ setItems([]);
262
+ setQuery('');
263
+ if (inputRef.current) {
264
+ inputRef.current.value = '';
265
+ }
266
+ return;
267
+ }
268
+ const { apiHandler } = props;
269
+
270
+ if (isDynamic && sourceFlowIntegrataionInvocationUrl && !disabled) {
271
+ fetchDynamicDataFromSourceFlow();
272
+ } else if (isDynamic && endpointUrl && !disabled) {
273
+ setLoading(true);
274
+ let data;
275
+ try {
276
+ data = JSON.parse(endpointData) || {};
277
+ if (selectedAuthId) {
278
+ data.connected_account_id = selectedAuthId;
279
+ }
280
+ } catch (error) {
281
+ data = '';
282
+ }
283
+ const requestBodyData =
284
+ typeof dataSourceBody === 'object' &&
285
+ Object.keys(dataSourceBody).length > 0
286
+ ? dataSourceBody
287
+ : activityOutputData;
288
+ apiHandler
289
+ .callDynamicDataEndpointWithTags<
290
+ {
291
+ id: string;
292
+ value: string;
293
+ }[]
294
+ >(new URL(endpointUrl), data, requestBodyData)
295
+ .then((res: any) => {
296
+ if (res) {
297
+ setItems(dynamicResponseMapper(res));
298
+ if (res.hasOwnProperty('_cursor') && res._cursor !== null) {
299
+ let tempFilteredItems = dynamicResponseMapper(res);
300
+ setFilteredItems(tempFilteredItems);
301
+ if (tempFilteredItems.length === 1) {
302
+ setEditableTextValue(tempFilteredItems[0].value);
303
+ onChange(tempFilteredItems[0].id, true);
304
+ }
305
+ } else {
306
+ setSortedFilteredItems(dynamicResponseMapper(res));
307
+ }
308
+ // if value was selected before items were loaded, select it again
309
+ if (value && isSearchable) {
310
+ const item = dynamicResponseMapper(res).find(
311
+ (a) => a.id === value,
312
+ );
313
+ if (item) {
314
+ setQuery(item.value);
315
+ } else {
316
+ setQuery('');
317
+ }
318
+ setLoading(false);
319
+ } else {
320
+ setQuery('');
321
+ setLoading(false);
322
+ }
323
+ } else {
324
+ setIsErrorOnLoadingOptions(true);
325
+ setLoading(false);
326
+ }
327
+ });
328
+ } else if (isDynamic && endpointUrl && disabled) {
329
+ setLoading(false);
330
+ } else if (!isDynamic && endpointUrl) {
331
+ // if isDynamic is false, endpointUrl will have JSON data instead of URL
332
+ try {
333
+ const data = JSON.parse(endpointUrl);
334
+ if (type === 'CHECKBOX' && data.length === 1 && data[0].id === '1') {
335
+ setSortedFilteredItems(responseMapper(checkboxItems));
336
+ setItems(responseMapper(checkboxItems));
337
+ setLoading(false);
338
+ } else {
339
+ setItems(responseMapper(data));
340
+ setSortedFilteredItems(responseMapper(data));
341
+ setLoading(false);
342
+ }
343
+ } catch (error) {
344
+ console.error(error);
345
+ }
346
+ } else if (type === 'CHECKBOX') {
347
+ // in case of single checkbox, we need to set the items(Yes/No) and filteredItems(Yes/No)
348
+ setSortedFilteredItems(responseMapper(checkboxItems));
349
+ setItems(responseMapper(checkboxItems));
350
+ setLoading(false);
351
+ }
352
+ }, [endpointData, skipOptionFetch, endpointUrl, selectedAuthId]);
353
+
354
+ const handleKeyDown = (event: KeyboardEvent) => {
355
+ if (event.key === 'Tab') {
356
+ setIsDropdownOpen(false);
357
+ }
358
+ };
359
+
360
+ const dynamicResponseMapper: keyValueMapper = (input) => {
361
+ const keyPath = props.optionKeyPath || 'id';
362
+ const valuePath = props.valueKeyPath || 'value';
363
+ const inputModified = input.hasOwnProperty('output') ? input.output : input;
364
+
365
+ // Check if inputModified is an array, if not, return an empty array
366
+ if (!Array.isArray(inputModified)) {
367
+ return [];
368
+ }
369
+
370
+ if (input.hasOwnProperty('_cursor')) {
371
+ setNextPage(input._cursor);
372
+ }
373
+
374
+ return inputModified.map((item: any) => {
375
+ // Helper function to resolve value based on plain property or tag
376
+ const resolveValue = (path: string): any => {
377
+ // If the path contains template tags, process it
378
+ if (/{([^}]+)}/.test(path)) {
379
+ return path.replace(/{([^}]+)}/g, (_, placeholder) => {
380
+ const keys = placeholder.split('.');
381
+ return (
382
+ keys.reduce((acc: any, key: any) => acc && acc[key], item) || ''
383
+ );
384
+ });
385
+ }
386
+
387
+ // Otherwise, treat it as a plain property path
388
+ const keys = path.split('.');
389
+ return keys.reduce((acc: any, key) => acc && acc[key], item);
390
+ };
391
+
392
+ // Resolve id and value using the helper function
393
+ let id = resolveValue(keyPath);
394
+ let value = resolveValue(valuePath);
395
+
396
+ // Fallback: If 'value' is undefined or an empty string, use 'id' as the value
397
+ if (typeof value === 'undefined' || value === '') {
398
+ value = id;
399
+ }
400
+
401
+ return { id, value };
402
+ });
403
+ };
404
+
405
+ // If released key is our target key then set to false
406
+ const upHandler = useCallback(
407
+ ({ key }: { key: string }): void => {
408
+ switch (key) {
409
+ case 'Enter': // item selected
410
+ onDropdownItemClicked(filteredItems[highlightedIndex]);
411
+ break;
412
+ case 'Escape': // cancel selection
413
+ setIsDropdownOpen(false);
414
+ inputRef.current?.blur();
415
+ break;
416
+ case 'ArrowDown': {
417
+ if (highlightedIndex < 0) {
418
+ setHighlightedIndex(0); // first item
419
+ } else if (highlightedIndex < filteredItems.length - 1) {
420
+ setHighlightedIndex((idx) => idx + 1); // next item
421
+ } else {
422
+ setHighlightedIndex(0); // wrap around
423
+ }
424
+ break;
425
+ }
426
+ case 'ArrowUp': {
427
+ if (highlightedIndex < 0) {
428
+ setHighlightedIndex(filteredItems.length - 1); // last item
429
+ } else if (
430
+ highlightedIndex < filteredItems.length &&
431
+ highlightedIndex > 0
432
+ ) {
433
+ setHighlightedIndex((idx) => idx - 1); // previous item
434
+ } else {
435
+ setHighlightedIndex(filteredItems.length - 1); // wrap around
436
+ }
437
+ break;
438
+ }
439
+ default:
440
+ break;
441
+ }
442
+ },
443
+ [highlightedIndex, filteredItems],
444
+ );
445
+
446
+ const setSortedFilteredItems = (
447
+ data: { id: string; value: string }[],
448
+ ): void => {
449
+ if (type === 'SELECT') {
450
+ // sort A-Z for dropdowns
451
+ const naturalSort = createNewSortInstance({
452
+ comparer: new Intl.Collator(undefined, {
453
+ numeric: true,
454
+ sensitivity: 'base',
455
+ }).compare,
456
+ });
457
+ const sorted = naturalSort(data).asc((item) => item.value);
458
+ setFilteredItems(sorted);
459
+ } else {
460
+ setFilteredItems(data);
461
+ }
462
+ };
463
+
464
+ const toggleDropdown = () => {
465
+ if (!isReadOnly) {
466
+ if (!isDropdownOpen) {
467
+ setQuery('');
468
+ inputRef.current?.focus();
469
+ }
470
+ setIsDropdownOpen((prev) => !prev);
471
+ }
472
+ };
473
+
474
+ const handleMultipurposeOnChange = (option: string) => {
475
+ const textField = inputRef.current;
476
+ let newValue = `${option}`;
477
+
478
+ // if the field is editable only, then EU can only eneter text, no tags and tags menu wont show up, so this function wont be called
479
+ if (textField) {
480
+ const { selectionStart = 0, selectionEnd = 0 } = textField;
481
+ const oldValue = textField.value;
482
+ const textBeforeCursor = oldValue.substring(0, selectionStart || 0);
483
+ const textAfterCursor = oldValue.substring(selectionEnd || 0);
484
+ const insertedText = `${option}`;
485
+ newValue = textBeforeCursor + insertedText + textAfterCursor;
486
+ textField.selectionStart = (selectionStart || 0) + insertedText.length;
487
+ textField.selectionEnd = textField.selectionStart;
488
+ textField.focus();
489
+ }
490
+ if (onChange) onChange(newValue);
491
+ };
492
+ const onDropdownItemClicked = (el: Omit<ListBoxItemProps, 'onClick'>) => {
493
+ setTempPlaceholder('');
494
+ setSearchValue('');
495
+ let fieldVal = el.value;
496
+ if (isMultiSelect) {
497
+ const fieldIds = value ? JSON.parse(value) : [];
498
+ // check if el.id is already selected and then remove it
499
+ if (fieldIds.includes(el.id)) {
500
+ const index = fieldIds.indexOf(el.id);
501
+ fieldIds.splice(index, 1);
502
+ } else {
503
+ fieldIds.push(el.id);
504
+ }
505
+ let index = -1;
506
+ let indexes: number[] = [];
507
+ const selectedValues = fieldIds.map((val: any) => {
508
+ index = items.findIndex((el) => el.id === val);
509
+ indexes.push(index);
510
+ });
511
+ if (indexes.length > 0) {
512
+ fieldVal = indexes.map((i) => items[i].value).join(', ');
513
+ }
514
+ onChange(JSON.stringify(fieldIds));
515
+ setEditableTextValue(JSON.stringify(fieldIds));
516
+ } else {
517
+ onChange(el.id);
518
+ setEditableTextValue(fieldVal);
519
+ }
520
+ setIsDropdownOpen(false);
521
+ if (isSearchable) {
522
+ setQuery(fieldVal); // set the query to the selected value
523
+ inputRef.current?.blur();
524
+ }
525
+ };
526
+
527
+ /* const onTagSelect = (option: string) => {
528
+ if (onChange) onChange(`{${option}}`);
529
+ setIsDropdownOpen(false);
530
+ }; */
531
+
532
+ const onTagSelect = (option: string) => {
533
+ const textField = inputRef.current;
534
+ let newValue = `{${option}}`;
535
+ setTempPlaceholder('');
536
+ // if (!isEditable) {
537
+ if (textField) {
538
+ if (allowTagsInText) {
539
+ // allowTagsInText will be true only if the field is editable
540
+ // if the fields is editable and allowTagsInText, then EU can enter text or select muliple tags within the text
541
+ const { selectionStart = 0, selectionEnd = 0 } = textField;
542
+ const oldValue = textField.value;
543
+ const textBeforeCursor = oldValue.substring(0, selectionStart || 0);
544
+ const textAfterCursor = oldValue.substring(selectionEnd || 0);
545
+ const insertedText = `{${option}}`;
546
+ newValue = textBeforeCursor + insertedText + textAfterCursor;
547
+ textField.selectionStart = (selectionStart || 0) + insertedText.length;
548
+ textField.selectionEnd = textField.selectionStart;
549
+ }
550
+ }
551
+ // if the field is editable and mappable, then EU can enter text or select a tag
552
+ // if the fields in mappable only, then select only one tag
553
+ setIsDropdownOpen(false);
554
+ setSearchValue('');
555
+ setEditableTextValue(newValue);
556
+ if (onChange) onChange(newValue);
557
+ // } else {
558
+ // handleMultipurposeOnChange(newValue);
559
+ // setIsDropdownOpen(false);
560
+ // setSearchValue('');
561
+ // // if the field is editable only, then EU can only eneter text, no tags and tags menu wont show up, so this function wont be called
562
+ // }
563
+ };
564
+
565
+ const getSelectedItem = useMemo(() => {
566
+ let index = -1;
567
+ if (isMultiSelect) {
568
+ const values = value ? JSON.parse(value) : [];
569
+ const indexes: any = [];
570
+ const selectedValues = values.map((val: any) => {
571
+ index = items.findIndex((el) => el.id === val);
572
+ indexes.push(index);
573
+ });
574
+ if (indexes.length > 0 && items.length > 0) {
575
+ return indexes.map((i: number) => items[i].value).join(', ');
576
+ }
577
+ } else {
578
+ try {
579
+ index = items.findIndex((el) => el.id === value);
580
+ } catch (error) {
581
+ index = -1;
582
+ }
583
+ if (isMappable && selectedTab === 'AppFields') {
584
+ return index > -1 ? items[index].value : value;
585
+ }
586
+ }
587
+
588
+ return index > -1 ? items[index].value : '';
589
+ }, [items, value]);
590
+
591
+ const getItemFromText = (
592
+ textValue: string,
593
+ ): {
594
+ id: string;
595
+ value: string;
596
+ } => {
597
+ let tempItem = {
598
+ id: textValue,
599
+ value: textValue,
600
+ };
601
+ let itemFound = false;
602
+ items.forEach((item) => {
603
+ if (item.id === textValue && !itemFound) {
604
+ tempItem = item;
605
+ itemFound = true;
606
+ }
607
+ });
608
+ if (!itemFound) {
609
+ items.forEach((item) => {
610
+ if (item.value === textValue && !itemFound) {
611
+ tempItem = item;
612
+ itemFound = true;
613
+ }
614
+ });
615
+ }
616
+ return tempItem;
617
+ };
618
+
619
+ const updateValue = (e: InputEvent | any) => {
620
+ setTempPlaceholder('');
621
+ if (e.currentTarget instanceof HTMLInputElement) {
622
+ const { value: newValue } = e.currentTarget;
623
+ if (isEditable) {
624
+ const tempItem = getItemFromText(newValue);
625
+ onChange(tempItem.id);
626
+ setEditableTextValue(tempItem.value);
627
+ onSearchChange(e);
628
+ } else {
629
+ onChange(newValue);
630
+ setEditableTextValue(newValue);
631
+ }
632
+ if (newValue !== '' && !isEditable) {
633
+ setSearchValue(newValue.trim());
634
+ } else {
635
+ setSearchValue('');
636
+ }
637
+ }
638
+ };
639
+
640
+ const onInputClicked = (e: InputEvent) => {
641
+ e.stopPropagation();
642
+ if (!isDropdownOpen && !isReadOnly) {
643
+ setQuery('');
644
+ setIsDropdownOpen(true);
645
+ }
646
+ const isTag =
647
+ getSelectedItem?.startsWith('{') && getSelectedItem?.endsWith('}');
648
+
649
+ let itemsToProcess = items;
650
+ if (!Array.isArray(items)) {
651
+ setItems([]);
652
+ itemsToProcess = [];
653
+ }
654
+ const isOption = itemsToProcess.find((el) => el.id === value);
655
+ if (isEditable && !allowTagsInText && isTag) {
656
+ setTempPlaceholder(getSelectedItem || '');
657
+ } else if (isEditable && isOption) {
658
+ setTempPlaceholder(getSelectedItem || '');
659
+ }
660
+ };
661
+
662
+ const onSearchChange = (e: InputEvent) => {
663
+ if (e.currentTarget instanceof HTMLInputElement) {
664
+ setSearchValue(e.currentTarget.value.trim());
665
+ setQuery(e.currentTarget.value.trim());
666
+ }
667
+ };
668
+
669
+ const fetchDynamicDataFromSourceFlow = (
670
+ isRefresh: boolean = false,
671
+ callback?: any,
672
+ ): void => {
673
+ const { apiHandler } = props;
674
+ if (!isRefresh) {
675
+ setLoading(true);
676
+ }
677
+ if (selectedAuthId) {
678
+ apiHandler
679
+ .callSourceFlowIntegrationInvocationUrl<
680
+ {
681
+ id: string;
682
+ value: string;
683
+ }[]
684
+ >(
685
+ new URL(sourceFlowIntegrataionInvocationUrl),
686
+ { authorization_id: selectedAuthId },
687
+ sourceFlowData,
688
+ )
689
+ .then((res) => {
690
+ if (res) {
691
+ setItems(responseMapper(res));
692
+ setSortedFilteredItems(responseMapper(res));
693
+ // if value was selected before items were loaded, select it again
694
+ if (value && isSearchable) {
695
+ const item = responseMapper(res).find((a) => a.id === value);
696
+ if (item && !isRefresh) {
697
+ setQuery(item.value);
698
+ } else {
699
+ setQuery('');
700
+ }
701
+ setLoading(false);
702
+ if (callback) {
703
+ callback();
704
+ }
705
+ } else {
706
+ setQuery('');
707
+ setLoading(false);
708
+ if (callback) {
709
+ callback();
710
+ }
711
+ }
712
+ } else {
713
+ setIsErrorOnLoadingOptions(true);
714
+ }
715
+ });
716
+ }
717
+ };
718
+
719
+ const fetchDynamicData = (
720
+ isRefresh: boolean = false,
721
+ callback?: any,
722
+ loadMore?: boolean,
723
+ params?: any,
724
+ ): void => {
725
+ const { apiHandler } = props;
726
+ if (isDynamic && sourceFlowIntegrataionInvocationUrl) {
727
+ fetchDynamicDataFromSourceFlow(isRefresh, callback);
728
+ } else if (endpointUrl) {
729
+ if (!isRefresh) {
730
+ setLoading(true);
731
+ }
732
+ let data;
733
+ try {
734
+ data = JSON.parse(endpointData);
735
+ } catch (error) {
736
+ data = '';
737
+ }
738
+ apiHandler
739
+ .callDynamicDataEndpoint<
740
+ {
741
+ id: string;
742
+ value: string;
743
+ }[]
744
+ >(new URL(endpointUrl), data, 'POST', params)
745
+ .then((res) => {
746
+ if (res) {
747
+ if (loadMore) {
748
+ setItems([...items, ...dynamicResponseMapper(res)]);
749
+ setFilteredItems([...items, ...dynamicResponseMapper(res)]);
750
+ } else {
751
+ setItems(dynamicResponseMapper(res));
752
+ setSortedFilteredItems(dynamicResponseMapper(res));
753
+ }
754
+ // if value was selected before items were loaded, select it again
755
+ if (value && isSearchable) {
756
+ const item = dynamicResponseMapper(res).find(
757
+ (a) => a.id === value,
758
+ );
759
+ if (item && !isRefresh) {
760
+ setQuery(item.value);
761
+ } else {
762
+ setQuery('');
763
+ }
764
+ setLoading(false);
765
+ if (callback) {
766
+ callback();
767
+ }
768
+ } else {
769
+ setQuery('');
770
+ setLoading(false);
771
+ if (callback) {
772
+ callback();
773
+ }
774
+ }
775
+ } else {
776
+ setIsErrorOnLoadingOptions(true);
777
+ }
778
+ });
779
+ }
780
+ };
781
+ const handleRefreshClick = (callback?: any, nextPage?: string): void => {
782
+ const requestBodyData =
783
+ typeof dataSourceBody === 'object' &&
784
+ Object.keys(dataSourceBody).length > 0
785
+ ? dataSourceBody
786
+ : activityOutputData;
787
+
788
+ // Merge nextPage into requestBodyData if it exists
789
+ const updatedRequestBodyData = nextPage
790
+ ? { ...requestBodyData, _cursor: nextPage }
791
+ : requestBodyData;
792
+ if (nextPage) {
793
+ fetchDynamicData(true, callback, true, updatedRequestBodyData);
794
+ } else {
795
+ setFilteredItems([]);
796
+ fetchDynamicData(true, callback, false, updatedRequestBodyData);
797
+ }
798
+
799
+ if (isSearchable) {
800
+ inputRef.current?.blur();
801
+ }
802
+ };
803
+
804
+ const handleLoadMoreOptions = (callback?: any): void => {
805
+ if (!loading) {
806
+ fetchDynamicData(false, callback, true, { _cursor: nextPage });
807
+ if (isSearchable) {
808
+ inputRef.current?.blur();
809
+ }
810
+ }
811
+ };
812
+
813
+ return html`
814
+ <${Hint} dismissOnClick=${false} position="top" deltaY=${0}>
815
+ <div ref=${dropdownRef} class="${styles.listboxGroupWrapper}">
816
+ <fieldset>
817
+ ${title &&
818
+ html`
819
+ <${Label}
820
+ title=${title}
821
+ description=${description}
822
+ isRequired=${isRequired}
823
+ isHidden=${isHidden}
824
+ labelTag=${labelTags}
825
+ allowRefresh=${false}
826
+ handleRefreshClick=${handleRefreshClick}
827
+ />
828
+ `}
829
+ <div class=${`${styles.listbox} integry-listbox-field`}>
830
+ <div
831
+ class=${`${styles.customSelect} ${
832
+ isDropdownOpen ? styles.open : ''
833
+ }`}
834
+ id="${fieldId}"
835
+ >
836
+ ${isReadOnly &&
837
+ html`<span
838
+ class=${styles.readonlyHint}
839
+ data-hint=${isReadOnly ? `Cannot modify user selection` : ''}
840
+ ></span>`}
841
+ <div
842
+ class=${`${styles.customSelectTrigger} ${
843
+ showStepValidation &&
844
+ !value &&
845
+ isRequired &&
846
+ (!isDropdownOpen || items.length === 0) &&
847
+ styles.error
848
+ } ${(isSearchable || isEditable) && styles.searchable} ${
849
+ isReadOnly ? styles.readonly : ''
850
+ } ${disabled ? styles.disabled : ''}`}
851
+ role="button"
852
+ onclick=${() => !isDropdownOpen && setIsDropdownOpen(true)}
853
+ >
854
+ <span class=${value && styles.selected}>
855
+ ${false
856
+ ? html`<div class=${`${styles.arrow}`}>
857
+ <${ThreeDotLoader} color="#ababab" }><//>
858
+ </div>`
859
+ : html` ${isEditable
860
+ ? html`
861
+ <input
862
+ ref=${inputRef}
863
+ class=${styles.searchInput}
864
+ placeholder=${tempPlaceholder || placeholder}
865
+ value=${getSelectedItem || editableTextValue}
866
+ oninput=${updateValue}
867
+ onfocus=${onInputClicked}
868
+ readonly=${isReadOnly}
869
+ tabindex=${0}
870
+ disabled=${disabled}
871
+ />
872
+ `
873
+ : isDropdownOpen && !isEditable
874
+ ? html`
875
+ <input
876
+ ref=${(r: any) => {
877
+ if (r && isDropdownOpen) {
878
+ r.focus();
879
+ }
880
+ inputRef.current = r;
881
+ }}
882
+ class=${styles.searchInput}
883
+ placeholder=${getSelectedItem || placeholder}
884
+ oninput=${onSearchChange}
885
+ onfocus=${onInputClicked}
886
+ tabindex=${0}
887
+ />
888
+ `
889
+ : html`
890
+ <input
891
+ ref=${(r: any) => {
892
+ if (r && isDropdownOpen) {
893
+ r.focus();
894
+ }
895
+ inputRef.current = r;
896
+ }}
897
+ class=${styles.searchInput}
898
+ placeholder=${getSelectedItem ||
899
+ placeholder ||
900
+ 'Please Select...'}
901
+ value=${value
902
+ ? getSelectedItem !== ''
903
+ ? getSelectedItem
904
+ : null
905
+ : null}
906
+ tabindex=${0}
907
+ onfocus=${onInputClicked}
908
+ disabled=${disabled}
909
+ />
910
+ `}`}
911
+ </span>
912
+
913
+ <div ref=${dropdownRef} style="display: flex;">
914
+ ${taggedSelect &&
915
+ onAddTag &&
916
+ html`
917
+ <${TagButton}
918
+ onClick=${(e: { stopPropagation: () => void }) => {
919
+ e.stopPropagation();
920
+ setIsDropdownOpen(false);
921
+ onAddTag();
922
+ }}
923
+ />
924
+ `}
925
+ </div>
926
+ </div>
927
+ <div>
928
+ ${!false &&
929
+ html`
930
+ <div ref=${dropdownMenuRef}>
931
+ ${isDropdownOpen &&
932
+ html`<${FieldDropdown}
933
+ tags=${activityOutputData}
934
+ onTagClick=${onTagSelect}
935
+ onOptionClick=${onDropdownItemClicked}
936
+ options=${filteredItems}
937
+ defaultTab=${Tabs.Values}
938
+ hideTabs=${!isMappable}
939
+ hideTabs=${hideTabs}
940
+ appName=${appName}
941
+ fieldId=${fieldId}
942
+ searchValue=${searchValue}
943
+ value=${value}
944
+ onTabSelect=${(tab: string) => {
945
+ setSelectedTab(tab);
946
+ setSearchValue('');
947
+ if (!isEditable) {
948
+ updateValue({ currentTarget: { value: '' } });
949
+ if (inputRef.current) {
950
+ inputRef.current.value = '';
951
+ }
952
+ }
953
+ if (inputRef.current) {
954
+ inputRef.current.focus();
955
+ }
956
+ }}
957
+ isMappable=${isMappable}
958
+ isEditable=${isEditable}
959
+ handleRefreshClick=${handleRefreshClick}
960
+ isErrorOnLoadingOptions=${isErrorOnLoadingOptions}
961
+ isMultiSelect=${isMultiSelect}
962
+ loadingOptions=${loading}
963
+ nextPage=${nextPage}
964
+ />`}
965
+ </div>
966
+ `}
967
+ </div>
968
+ </div>
969
+ ${showStepValidation &&
970
+ !value &&
971
+ (!isDropdownOpen || items.length === 0) &&
972
+ isRequired &&
973
+ html` <${ErrorMessage}>Please select an option</${ErrorMessage}>`}
974
+ </div>
975
+ </fieldset>
976
+ </div>
977
+ <//>
978
+ `;
979
+ };
980
+
981
+ export { ListBox, ListBoxProps };