@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,25 @@
1
+ import { html } from 'htm/preact';
2
+
3
+ import styles from './styles.module.scss';
4
+
5
+ const LargeLoader = () => html`
6
+ <svg
7
+ class=${styles.loader}
8
+ width="26"
9
+ height="25"
10
+ viewBox="0 0 26 25"
11
+ fill="none"
12
+ xmlns="http://www.w3.org/2000/svg"
13
+ >
14
+ <path
15
+ d="M15.7173 0.29892C13.1175 -0.280085 10.4006 -0.0135017 7.96294 1.0598C5.52524 2.13311 3.49412 3.95702 2.16568 6.26562C0.837246 8.57421 0.280965 11.2468 0.57794 13.8937C0.874915 16.5406 2.00962 19.0235 3.81662 20.9803C5.62362 22.9371 8.00843 24.2656 10.6234 24.772C13.2383 25.2784 15.9466 24.9363 18.3535 23.7956C20.7604 22.6548 22.74 20.7751 24.0036 18.4304C25.2673 16.0857 25.749 13.3987 25.3785 10.7611L24.1406 10.935C24.4741 13.3088 24.0406 15.7272 22.9033 17.8374C21.766 19.9476 19.9844 21.6393 17.8182 22.666C15.652 23.6927 13.2145 24.0006 10.861 23.5448C8.50758 23.089 6.36125 21.8934 4.73495 20.1323C3.10866 18.3711 2.08742 16.1366 1.82015 13.7543C1.55287 11.3721 2.05352 8.96679 3.24911 6.88905C4.44471 4.81132 6.27272 3.1698 8.46665 2.20382C10.6606 1.23785 13.1057 0.997923 15.4456 1.51903L15.7173 0.29892Z"
16
+ fill="#EFEFEF"
17
+ />
18
+ <path
19
+ d="M25.3833 10.7959C25.0346 8.26181 23.9168 5.8957 22.1808 4.01695C20.4449 2.13819 18.1743 0.83725 15.6756 0.289715L15.4081 1.51074C17.6569 2.00353 19.7004 3.17437 21.2628 4.86525C22.8251 6.55613 23.8311 8.68563 24.145 10.9663L25.3833 10.7959Z"
20
+ fill="#C4C4C4"
21
+ />
22
+ </svg>
23
+ `;
24
+
25
+ export { LargeLoader };
@@ -0,0 +1,16 @@
1
+ .loader {
2
+ animation-name: ckw;
3
+ animation-duration: 1s;
4
+ animation-iteration-count: infinite;
5
+ animation-timing-function: linear;
6
+ transform-origin: 50% 50%;
7
+ }
8
+
9
+ @keyframes ckw {
10
+ 0% {
11
+ transform: rotate(0deg);
12
+ }
13
+ 100% {
14
+ transform: rotate(360deg);
15
+ }
16
+ }
@@ -0,0 +1,57 @@
1
+ import { html } from 'htm/preact';
2
+ import { useRef } from 'preact/hooks';
3
+
4
+ import styles from './styles.module.scss';
5
+
6
+ interface ListBoxItemProps {
7
+ value: string;
8
+ id: string;
9
+ isSelected?: boolean;
10
+ isHighlighted?: boolean;
11
+ onClick(): void;
12
+ }
13
+
14
+ const ListBoxItem = (props: ListBoxItemProps) => {
15
+ const { id, value, isSelected, isHighlighted = false, onClick } = props;
16
+ const listItemRef = useRef<HTMLSpanElement>();
17
+
18
+ const isContentOverflowing = (): boolean => {
19
+ if (listItemRef.current) {
20
+ return (listItemRef.current.clientWidth < listItemRef.current.scrollWidth);
21
+ }
22
+ return false;
23
+ };
24
+
25
+ return html`
26
+ <span
27
+ class=${`${styles.listboxItem} ${isSelected ? styles.selected : ''} ${
28
+ isHighlighted ? styles.highlighted : ''
29
+ }`}
30
+ data-value=${id}
31
+ onclick=${onClick}
32
+ ref=${listItemRef}
33
+ data-hint=${`${isContentOverflowing() ? value : ''}`}
34
+ >
35
+ ${false && isSelected &&
36
+ html`
37
+ <svg
38
+ width="7"
39
+ height="7"
40
+ viewBox="0 0 7 7"
41
+ fill="none"
42
+ xmlns="http://www.w3.org/2000/svg"
43
+ stroke="#333"
44
+ >
45
+ <path
46
+ d="M6.33333 1.5L2.83522 5.5L1 3.40148"
47
+ stroke-width="1.2"
48
+ stroke-linecap="round"
49
+ />
50
+ </svg>
51
+ `}
52
+ ${value}
53
+ </span>
54
+ `;
55
+ };
56
+
57
+ export { ListBoxItem, ListBoxItemProps };
@@ -0,0 +1,479 @@
1
+ /* eslint-disable no-use-before-define */
2
+ import { html } from 'htm/preact';
3
+ import { useCallback, useEffect, useMemo, useState } from 'preact/hooks';
4
+ import fuzzysort from 'fuzzysort';
5
+ import { createNewSortInstance } from 'fast-sort';
6
+ import { Label } from '@/components/Label';
7
+ import { Hint } from '@/components/Tooltip';
8
+ import { useOnClickOutside } from '@/hooks/useOnClickOutside';
9
+ import { ThreeDotLoader } from '@/components/ThreeDotLoader';
10
+ import { IntegryAPI } from '@/modules/api';
11
+ import { ErrorMessage } from '@/components/ErrorMessage';
12
+ import useCustomRef from '@/hooks/useCustomRef';
13
+ import { ListBoxItem, ListBoxItemProps } from './ListBoxItem';
14
+
15
+ import styles from './styles.module.scss';
16
+
17
+ interface ListBoxProps {
18
+ title: string;
19
+ description: string;
20
+ items: Omit<ListBoxItemProps, 'onClick'>[];
21
+ value?: string;
22
+ onChange(val: string): void;
23
+ isOpen?: boolean;
24
+ isDynamic?: boolean;
25
+ endpointUrl?: string;
26
+ isSearchable?: boolean;
27
+ placeholder: string | null;
28
+ isRequired?: boolean;
29
+ showStepValidation?: boolean;
30
+ responseMapper?(input: unknown): Omit<ListBoxItemProps, 'onClick'>[];
31
+ apiHandler: IntegryAPI;
32
+ endpointData: string;
33
+ isReadOnly?: boolean;
34
+ isChanged?: boolean;
35
+ isEditable?: boolean;
36
+ }
37
+
38
+ const ListBox = (props: ListBoxProps) => {
39
+ const {
40
+ title,
41
+ description,
42
+ items: passedItems = [],
43
+ value = null,
44
+ isOpen = false,
45
+ isDynamic = false,
46
+ endpointData,
47
+ isSearchable = false,
48
+ isRequired = false,
49
+ placeholder,
50
+ onChange = () => null,
51
+ showStepValidation = false,
52
+ responseMapper = (input: { id: string; value: string }[]) => input,
53
+ isReadOnly = false,
54
+ isChanged = false,
55
+ endpointUrl,
56
+ isEditable = false,
57
+ } = props;
58
+
59
+ const [query, setQuery] = useState<string>('');
60
+ const [editableTextValue, setEditableTextValue] = useState<string>('');
61
+
62
+ const [items, setItems] = useState<Omit<ListBoxItemProps, 'onClick'>[]>(
63
+ passedItems,
64
+ );
65
+
66
+ const [highlightedIndex, setHighlightedIndex] = useState<number>(-1);
67
+
68
+ const [filteredItems, setFilteredItems] = useState<
69
+ Omit<ListBoxItemProps, 'onClick'>[]
70
+ >(passedItems);
71
+
72
+ const [loading, setLoading] = useState(
73
+ isDynamic && !passedItems.length && !value,
74
+ );
75
+
76
+ const [isDropdownOpen, setIsDropdownOpen] = useState(isOpen);
77
+
78
+ const [dropdownRef] = useCustomRef<HTMLDivElement>();
79
+ const [inputRef] = useCustomRef<HTMLInputElement>();
80
+
81
+ useOnClickOutside(dropdownRef, () => {
82
+ if (isDropdownOpen) {
83
+ setIsDropdownOpen(false);
84
+ setHighlightedIndex(-1);
85
+ }
86
+ });
87
+
88
+ useEffect(() => {
89
+ if (highlightedIndex > -1 && isDropdownOpen) {
90
+ const item = filteredItems[highlightedIndex];
91
+ if (item) {
92
+ const domEl = document.querySelector(`[data-value="${item.value}"]`);
93
+ domEl?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
94
+ }
95
+ }
96
+ }, [highlightedIndex, isDropdownOpen]);
97
+
98
+ useEffect(() => {
99
+ if (dropdownRef && dropdownRef.current && isDropdownOpen === true) {
100
+ if (dropdownRef && dropdownRef.current) {
101
+ dropdownRef.current?.addEventListener('keyup', upHandler);
102
+ }
103
+ }
104
+ // Remove event listeners on cleanup
105
+ return () => {
106
+ if (dropdownRef && dropdownRef.current) {
107
+ dropdownRef.current.removeEventListener('keyup', upHandler);
108
+ }
109
+ };
110
+ }, [isDropdownOpen, dropdownRef, highlightedIndex]);
111
+
112
+ useEffect(() => {
113
+ let timer: null | ReturnType<typeof setTimeout> = null;
114
+ const item = items.find((a) => a.id === value);
115
+
116
+ if (!isDropdownOpen && query && !value) {
117
+ setQuery('');
118
+ timer = setTimeout(() => {
119
+ setSortedFilteredItems(items);
120
+ }, 250);
121
+ } else if (!isDropdownOpen && value && item) {
122
+ setQuery(item.value);
123
+ }
124
+ return () => {
125
+ if (timer) clearTimeout(timer);
126
+ };
127
+ }, [isDropdownOpen]);
128
+
129
+ useEffect(() => {
130
+ if (query && isSearchable) {
131
+ const filtered = fuzzysort
132
+ .go(query, items, {
133
+ keys: ['value'],
134
+ scoreFn: (keysResult) => {
135
+ const nameResult = keysResult[0];
136
+ const tagsResult = keysResult[1];
137
+ // assign higher score to name result
138
+ const score = Math.max(
139
+ nameResult ? nameResult.score + 100 : -Infinity,
140
+ tagsResult ? tagsResult.score : -Infinity,
141
+ );
142
+ return score;
143
+ },
144
+ })
145
+ .map((el) => el.obj);
146
+ setHighlightedIndex(-1);
147
+ setSortedFilteredItems(filtered);
148
+ if (filtered.length === 1) setHighlightedIndex(0);
149
+ } else if (isDropdownOpen) {
150
+ setHighlightedIndex(-1);
151
+ setSortedFilteredItems(items);
152
+ }
153
+ }, [query]);
154
+
155
+ useEffect(() => {
156
+ // eslint-disable-next-line @typescript-eslint/no-shadow
157
+ const { isDynamic, endpointUrl } = props;
158
+ if (isDynamic && endpointUrl) {
159
+ fetchDynamicData();
160
+ } else if (!isDynamic && endpointUrl) {
161
+ // if isDynamic is false, endpointUrl will have JSON data instead of URL
162
+ try {
163
+ const data = JSON.parse(endpointUrl);
164
+ setItems(responseMapper(data));
165
+ setFilteredItems(responseMapper(data));
166
+ setLoading(false);
167
+ } catch (error) {
168
+ console.error(error);
169
+ }
170
+ }
171
+ }, [endpointData]);
172
+
173
+ const fetchDynamicData = (): void => {
174
+ const { apiHandler } = props;
175
+ if (endpointUrl) {
176
+ setLoading(true);
177
+ let data;
178
+ try {
179
+ data = JSON.parse(endpointData);
180
+ } catch (error) {
181
+ data = '';
182
+ }
183
+ apiHandler
184
+ .callDynamicDataEndpoint<
185
+ {
186
+ id: string;
187
+ value: string;
188
+ }[]
189
+ >(new URL(endpointUrl), data)
190
+ .then((res) => {
191
+ if (res) {
192
+ setItems(responseMapper(res));
193
+ setSortedFilteredItems(responseMapper(res));
194
+ // if value was selected before items were loaded, select it again
195
+ if (value && isSearchable) {
196
+ const item = responseMapper(res).find((a) => a.id === value);
197
+ if (item) {
198
+ setQuery(item.value);
199
+ } else {
200
+ setQuery('');
201
+ }
202
+ setLoading(false);
203
+ } else {
204
+ setQuery('');
205
+ setLoading(false);
206
+ }
207
+ }
208
+ });
209
+ }
210
+ };
211
+
212
+ const setSortedFilteredItems = (data: { id: string, value: string }[]): void => {
213
+ const naturalSort = createNewSortInstance({
214
+ comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare,
215
+ });
216
+ const sorted = naturalSort(data).asc(item => item.value);
217
+ setFilteredItems(sorted);
218
+ };
219
+
220
+ // If released key is our target key then set to false
221
+ const upHandler = useCallback(
222
+ ({ key }: { key: string }): void => {
223
+ switch (key) {
224
+ case 'Enter': // item selected
225
+ onDropdownItemClicked(filteredItems[highlightedIndex]);
226
+ break;
227
+ case 'Escape': // cancel selection
228
+ setIsDropdownOpen(false);
229
+ inputRef.current?.blur();
230
+ break;
231
+ case 'ArrowDown': {
232
+ if (highlightedIndex < 0) {
233
+ setHighlightedIndex(0); // first item
234
+ } else if (highlightedIndex < filteredItems.length - 1) {
235
+ setHighlightedIndex((idx) => idx + 1); // next item
236
+ } else {
237
+ setHighlightedIndex(0); // wrap around
238
+ }
239
+ break;
240
+ }
241
+ case 'ArrowUp': {
242
+ if (highlightedIndex < 0) {
243
+ setHighlightedIndex(filteredItems.length - 1); // last item
244
+ } else if (
245
+ highlightedIndex < filteredItems.length &&
246
+ highlightedIndex > 0
247
+ ) {
248
+ setHighlightedIndex((idx) => idx - 1); // previous item
249
+ } else {
250
+ setHighlightedIndex(filteredItems.length - 1); // wrap around
251
+ }
252
+ break;
253
+ }
254
+ default:
255
+ break;
256
+ }
257
+ },
258
+ [highlightedIndex, filteredItems],
259
+ );
260
+
261
+ const toggleDropdown = () => {
262
+ if (!isReadOnly) {
263
+ if (!isDropdownOpen) {
264
+ setQuery('');
265
+ inputRef.current?.focus();
266
+ }
267
+ setIsDropdownOpen((prev) => !prev);
268
+ }
269
+ };
270
+
271
+ const onDropdownItemClicked = (el: Omit<ListBoxItemProps, 'onClick'>) => {
272
+ onChange(el.id);
273
+ setIsDropdownOpen(false);
274
+ if (isEditable) {
275
+ setEditableTextValue(el.value);
276
+ setQuery('');
277
+ inputRef.current?.blur();
278
+ }
279
+ if (isSearchable) {
280
+ setQuery(el.value);
281
+ inputRef.current?.blur();
282
+ }
283
+ };
284
+
285
+ const onInputClicked = (e: InputEvent) => {
286
+ e.stopPropagation();
287
+ if (!isDropdownOpen && !isReadOnly) {
288
+ setQuery('');
289
+ setIsDropdownOpen(true);
290
+ }
291
+ };
292
+
293
+ const getSelectedItem = useMemo(() => {
294
+ const index = items.findIndex((el) => el.id === value);
295
+ return index > -1 ? items[index].value : 'Please Select...';
296
+ }, [items, value]);
297
+
298
+ const getItemFromText = (textValue: string): ({
299
+ id: string;
300
+ value: string;
301
+ }) => {
302
+ let tempItem = {
303
+ id: textValue,
304
+ value: textValue,
305
+ };
306
+ let itemFound = false;
307
+ items.forEach((item) => {
308
+ if (item.id === textValue && !itemFound) {
309
+ tempItem = item;
310
+ itemFound = true;
311
+ }
312
+ });
313
+ if (!itemFound) {
314
+ items.forEach((item) => {
315
+ if (item.value === textValue && !itemFound) {
316
+ tempItem = item;
317
+ itemFound = true;
318
+ }
319
+ });
320
+ }
321
+ return tempItem;
322
+ }
323
+
324
+ const updateValue = (e: InputEvent) => {
325
+ if (e.currentTarget instanceof HTMLInputElement) {
326
+ const { value: newValue } = e.currentTarget;
327
+
328
+ if (isEditable) {
329
+ const tempItem = getItemFromText(newValue);
330
+ onChange(tempItem.id);
331
+ setEditableTextValue(tempItem.value);
332
+ setQuery(tempItem.value.trim());
333
+ } else if(newValue !== '') {
334
+ setQuery(newValue.trim());
335
+ }
336
+ }
337
+ };
338
+
339
+ const handleRefreshClick = (): void => {
340
+ fetchDynamicData();
341
+ onChange('');
342
+ setIsDropdownOpen(false);
343
+ if (isSearchable) {
344
+ setQuery('');
345
+ inputRef.current?.blur();
346
+ }
347
+ }
348
+
349
+ return html`
350
+ <${Hint} dismissOnClick=${false} position="top" deltaY=${0}>
351
+ <div ref=${dropdownRef} class="${styles.listboxGroupWrapper}">
352
+ <fieldset>
353
+ ${title &&
354
+ html`
355
+ <${Label}
356
+ title=${title}
357
+ description=${description}
358
+ isRequired=${isRequired}
359
+ labelTag=${isReadOnly && isChanged ? 'Changed' : ''}
360
+ allowRefresh=${isDynamic && endpointUrl}
361
+ handleRefreshClick=${handleRefreshClick}
362
+ />
363
+ `}
364
+ <div class=${styles.listbox}>
365
+ <div
366
+ class=${`${styles.customSelect} ${
367
+ isDropdownOpen ? styles.open : ''
368
+ }`}
369
+ >
370
+ ${isReadOnly &&
371
+ html`<span
372
+ class=${styles.readonlyHint}
373
+ data-hint=${isReadOnly ? `Cannot modify user selection` : ''}
374
+ ></span>`}
375
+ <div
376
+ class=${`${styles.customSelectTrigger} ${
377
+ showStepValidation &&
378
+ !value &&
379
+ isRequired &&
380
+ !isDropdownOpen &&
381
+ styles.error
382
+ } ${isSearchable && styles.searchable} ${
383
+ isReadOnly ? styles.readonly : ''
384
+ }`}
385
+ role="button"
386
+ tabindex=${0}
387
+ onclick=${toggleDropdown}
388
+ >
389
+ <span class=${value && styles.selected}>
390
+ ${loading
391
+ ? html`Loading`
392
+ : html` ${isSearchable || isEditable
393
+ ? html`
394
+ <input
395
+ ref=${inputRef}
396
+ class=${styles.searchInput}
397
+ placeholder=${placeholder ||
398
+ (isEditable ? 'Please select or enter value...' : 'Please Select or Search...')}
399
+ value=${isEditable ? editableTextValue : query}
400
+ oninput=${updateValue}
401
+ onclick=${onInputClicked}
402
+ readonly=${isReadOnly}
403
+ />
404
+ `
405
+ : html`
406
+ ${items.length > 0
407
+ ? html`
408
+ ${value
409
+ ? html`${getSelectedItem}`
410
+ : html`${placeholder || 'Please Select...'}`}
411
+ `
412
+ : html`No options`}
413
+ `}`}
414
+ </span>
415
+
416
+ <div ref=${dropdownRef} style="display: flex;">
417
+ ${loading
418
+ ? html`<${ThreeDotLoader} color="#ababab"><//>`
419
+ : html`
420
+ <div
421
+ class=${`${styles.arrow} ${
422
+ isDropdownOpen ? styles.close : ''
423
+ } ${isReadOnly ? styles.readonly : ''}`}
424
+ >
425
+ <svg
426
+ width="12"
427
+ height="8"
428
+ viewBox="0 0 12 8"
429
+ fill="none"
430
+ xmlns="http://www.w3.org/2000/svg"
431
+ >
432
+ <path
433
+ d="M11 1.5L6 6.5L1 1.5"
434
+ stroke="#999999"
435
+ stroke-width="2"
436
+ stroke-linecap="round"
437
+ />
438
+ </svg>
439
+ </div>
440
+ `}
441
+ </div>
442
+ </div>
443
+ <div class=${styles.customOptions}>
444
+ ${items.length > 0 &&
445
+ !loading &&
446
+ html`
447
+ ${filteredItems.map(
448
+ (el, idx) => html`
449
+ <${ListBoxItem}
450
+ key=${el.id}
451
+ id=${el.id}
452
+ value=${el.value}
453
+ isHighlighted=${highlightedIndex === idx}
454
+ isSelected=${value === el.id}
455
+ onClick=${() => onDropdownItemClicked(el)}
456
+ ><//>
457
+ `,
458
+ )}
459
+ `}
460
+ ${isSearchable &&
461
+ query &&
462
+ !filteredItems.length &&
463
+ !loading &&
464
+ html`<div class=${styles.noResults}>No results found</div>`}
465
+ </div>
466
+ </div>
467
+ ${showStepValidation &&
468
+ !value &&
469
+ !isDropdownOpen &&
470
+ isRequired &&
471
+ html` <${ErrorMessage}>Please select an option</${ErrorMessage}>`}
472
+ </div>
473
+ </fieldset>
474
+ </div>
475
+ <//>
476
+ `;
477
+ };
478
+
479
+ export { ListBox, ListBoxProps };