@watermarkinsights/ripple 3.16.0 → 3.17.0-2

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 (267) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{chartFunctions-45d38ae4.js → chartFunctions-0c02a801.js} +425 -421
  3. package/dist/cjs/{functions-23309c38.js → functions-cb39693a.js} +483 -483
  4. package/dist/cjs/{global-5260837d.js → global-4e97582e.js} +62 -62
  5. package/dist/cjs/{http-service-9e8c4dd5.js → http-service-494d81de.js} +49 -49
  6. package/dist/cjs/{interfaces-30a74c1f.js → interfaces-a3338581.js} +29 -29
  7. package/dist/cjs/loader.cjs.js +2 -2
  8. package/dist/cjs/priv-chart-popover.cjs.entry.js +86 -86
  9. package/dist/cjs/priv-datepicker.cjs.entry.js +657 -657
  10. package/dist/cjs/priv-navigator-button.cjs.entry.js +18 -18
  11. package/dist/cjs/priv-navigator-item.cjs.entry.js +23 -23
  12. package/dist/cjs/ripple.cjs.js +2 -2
  13. package/dist/cjs/wm-action-menu_2.cjs.entry.js +329 -329
  14. package/dist/cjs/wm-button.cjs.entry.js +248 -248
  15. package/dist/cjs/wm-chart-slice.cjs.entry.js +13 -13
  16. package/dist/cjs/wm-chart.cjs.entry.js +111 -111
  17. package/dist/cjs/wm-datepicker.cjs.entry.js +265 -265
  18. package/dist/cjs/wm-input.cjs.entry.js +134 -134
  19. package/dist/cjs/wm-modal-footer.cjs.entry.js +33 -33
  20. package/dist/cjs/wm-modal-header.cjs.entry.js +36 -36
  21. package/dist/cjs/wm-modal.cjs.entry.js +163 -163
  22. package/dist/cjs/wm-navigation_3.cjs.entry.js +227 -227
  23. package/dist/cjs/wm-navigator.cjs.entry.js +268 -268
  24. package/dist/cjs/wm-network-uploader.cjs.entry.js +455 -455
  25. package/dist/cjs/wm-option_2.cjs.entry.js +720 -720
  26. package/dist/cjs/wm-pagination.cjs.entry.js +167 -167
  27. package/dist/cjs/wm-progress-indicator_3.cjs.entry.js +139 -131
  28. package/dist/cjs/wm-search.cjs.entry.js +232 -232
  29. package/dist/cjs/wm-snackbar.cjs.entry.js +170 -170
  30. package/dist/cjs/wm-tab-item_3.cjs.entry.js +296 -296
  31. package/dist/cjs/wm-tag-input-row.cjs.entry.js +10 -10
  32. package/dist/cjs/wm-tag-input.cjs.entry.js +884 -884
  33. package/dist/cjs/wm-timepicker.cjs.entry.js +383 -383
  34. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  35. package/dist/cjs/wm-uploader.cjs.entry.js +556 -556
  36. package/dist/cjs/wm-wrapper.cjs.entry.js +12 -12
  37. package/dist/collection/components/charts/priv-chart-popover/priv-chart-popover.js +258 -258
  38. package/dist/collection/components/charts/wm-chart/wm-chart-slice.js +115 -115
  39. package/dist/collection/components/charts/wm-chart/wm-chart.css +81 -84
  40. package/dist/collection/components/charts/wm-chart/wm-chart.js +328 -328
  41. package/dist/collection/components/charts/wm-progress-monitor/wm-progress-indicator.css +81 -84
  42. package/dist/collection/components/charts/wm-progress-monitor/wm-progress-indicator.js +194 -195
  43. package/dist/collection/components/charts/wm-progress-monitor/wm-progress-monitor.css +86 -0
  44. package/dist/collection/components/charts/wm-progress-monitor/wm-progress-monitor.js +117 -88
  45. package/dist/collection/components/charts/wm-progress-monitor/wm-progress-slice.js +111 -111
  46. package/dist/collection/components/wm-action-menu/wm-action-menu.js +442 -442
  47. package/dist/collection/components/wm-button/wm-button.js +545 -545
  48. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1024 -1024
  49. package/dist/collection/components/wm-datepicker/wm-datepicker.js +471 -471
  50. package/dist/collection/components/wm-input/wm-input.js +423 -423
  51. package/dist/collection/components/wm-menuitem/wm-menuitem.js +444 -444
  52. package/dist/collection/components/wm-modal/wm-modal-footer.js +136 -136
  53. package/dist/collection/components/wm-modal/wm-modal-header.js +87 -87
  54. package/dist/collection/components/wm-modal/wm-modal.js +461 -461
  55. package/dist/collection/components/wm-navigation/wm-navigation-hamburger.js +162 -162
  56. package/dist/collection/components/wm-navigation/wm-navigation-item.js +121 -121
  57. package/dist/collection/components/wm-navigation/wm-navigation.js +218 -218
  58. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -97
  59. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -114
  60. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -468
  61. package/dist/collection/components/wm-option/wm-option.js +428 -428
  62. package/dist/collection/components/wm-pagination/wm-pagination.js +368 -368
  63. package/dist/collection/components/wm-search/wm-search.js +480 -480
  64. package/dist/collection/components/wm-select/wm-select.js +1001 -1001
  65. package/dist/collection/components/wm-snackbar/wm-snackbar.js +297 -297
  66. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +216 -216
  67. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.js +330 -330
  68. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -104
  69. package/dist/collection/components/wm-tag-input/wm-tag-input-row/wm-tag-input-row.js +115 -115
  70. package/dist/collection/components/wm-tag-input/wm-tag-input.js +1201 -1201
  71. package/dist/collection/components/wm-timepicker/wm-timepicker.js +583 -583
  72. package/dist/collection/components/wm-toggletip/wm-toggletip.js +241 -241
  73. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +788 -788
  74. package/dist/collection/components/wm-uploader/wm-uploader.js +1000 -1000
  75. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -27
  76. package/dist/collection/dev/scripts.js +20 -20
  77. package/dist/collection/global/__mocks__/functions.js +6 -6
  78. package/dist/collection/global/chartFunctions.js +426 -423
  79. package/dist/collection/global/functions.js +486 -486
  80. package/dist/collection/global/global.js +69 -69
  81. package/dist/collection/global/interfaces.js +49 -49
  82. package/dist/collection/global/services/__mocks__/http-service.js +130 -130
  83. package/dist/collection/global/services/http-service.js +50 -50
  84. package/dist/collection/lang/lang.js +5 -5
  85. package/dist/collection/lang/missing.js +43 -43
  86. package/dist/collection/lang/piglatin.js +93 -93
  87. package/dist/esm/{chartFunctions-4433cafc.js → chartFunctions-fe9af0f8.js} +425 -422
  88. package/dist/esm/{functions-14df5b8c.js → functions-478ab920.js} +483 -483
  89. package/dist/esm/{global-0087a2ea.js → global-32a33c56.js} +62 -62
  90. package/dist/esm/{http-service-5d037e16.js → http-service-3dc3b3e7.js} +49 -49
  91. package/dist/esm/{interfaces-61c6305b.js → interfaces-2b97fab2.js} +29 -29
  92. package/dist/esm/loader.js +2 -2
  93. package/dist/esm/polyfills/core-js.js +0 -0
  94. package/dist/esm/polyfills/dom.js +0 -0
  95. package/dist/esm/polyfills/es5-html-element.js +0 -0
  96. package/dist/esm/polyfills/index.js +0 -0
  97. package/dist/esm/polyfills/system.js +0 -0
  98. package/dist/esm/priv-chart-popover.entry.js +86 -86
  99. package/dist/esm/priv-datepicker.entry.js +657 -657
  100. package/dist/esm/priv-navigator-button.entry.js +18 -18
  101. package/dist/esm/priv-navigator-item.entry.js +23 -23
  102. package/dist/esm/ripple.js +2 -2
  103. package/dist/esm/wm-action-menu_2.entry.js +329 -329
  104. package/dist/esm/wm-button.entry.js +248 -248
  105. package/dist/esm/wm-chart-slice.entry.js +13 -13
  106. package/dist/esm/wm-chart.entry.js +111 -111
  107. package/dist/esm/wm-datepicker.entry.js +265 -265
  108. package/dist/esm/wm-input.entry.js +134 -134
  109. package/dist/esm/wm-modal-footer.entry.js +33 -33
  110. package/dist/esm/wm-modal-header.entry.js +36 -36
  111. package/dist/esm/wm-modal.entry.js +163 -163
  112. package/dist/esm/wm-navigation_3.entry.js +227 -227
  113. package/dist/esm/wm-navigator.entry.js +268 -268
  114. package/dist/esm/wm-network-uploader.entry.js +455 -455
  115. package/dist/esm/wm-option_2.entry.js +720 -720
  116. package/dist/esm/wm-pagination.entry.js +167 -167
  117. package/dist/esm/wm-progress-indicator_3.entry.js +139 -131
  118. package/dist/esm/wm-search.entry.js +232 -232
  119. package/dist/esm/wm-snackbar.entry.js +170 -170
  120. package/dist/esm/wm-tab-item_3.entry.js +296 -296
  121. package/dist/esm/wm-tag-input-row.entry.js +10 -10
  122. package/dist/esm/wm-tag-input.entry.js +884 -884
  123. package/dist/esm/wm-timepicker.entry.js +383 -383
  124. package/dist/esm/wm-toggletip.entry.js +124 -124
  125. package/dist/esm/wm-uploader.entry.js +556 -556
  126. package/dist/esm/wm-wrapper.entry.js +12 -12
  127. package/dist/esm-es5/{chartFunctions-4433cafc.js → chartFunctions-fe9af0f8.js} +1 -1
  128. package/dist/esm-es5/{functions-14df5b8c.js → functions-478ab920.js} +0 -0
  129. package/dist/esm-es5/global-32a33c56.js +1 -0
  130. package/dist/esm-es5/{http-service-5d037e16.js → http-service-3dc3b3e7.js} +0 -0
  131. package/dist/esm-es5/{interfaces-61c6305b.js → interfaces-2b97fab2.js} +0 -0
  132. package/dist/esm-es5/loader.js +1 -1
  133. package/dist/esm-es5/priv-chart-popover.entry.js +1 -1
  134. package/dist/esm-es5/priv-datepicker.entry.js +1 -1
  135. package/dist/esm-es5/ripple.js +1 -1
  136. package/dist/esm-es5/wm-action-menu_2.entry.js +1 -1
  137. package/dist/esm-es5/wm-button.entry.js +1 -1
  138. package/dist/esm-es5/wm-chart.entry.js +1 -1
  139. package/dist/esm-es5/wm-datepicker.entry.js +1 -1
  140. package/dist/esm-es5/wm-input.entry.js +1 -1
  141. package/dist/esm-es5/wm-modal-header.entry.js +1 -1
  142. package/dist/esm-es5/wm-modal.entry.js +1 -1
  143. package/dist/esm-es5/wm-navigation_3.entry.js +1 -1
  144. package/dist/esm-es5/wm-navigator.entry.js +1 -1
  145. package/dist/esm-es5/wm-network-uploader.entry.js +1 -1
  146. package/dist/esm-es5/wm-option_2.entry.js +1 -1
  147. package/dist/esm-es5/wm-pagination.entry.js +1 -1
  148. package/dist/esm-es5/wm-progress-indicator_3.entry.js +1 -1
  149. package/dist/esm-es5/wm-search.entry.js +1 -1
  150. package/dist/esm-es5/wm-snackbar.entry.js +1 -1
  151. package/dist/esm-es5/wm-tab-item_3.entry.js +1 -1
  152. package/dist/esm-es5/wm-tag-input.entry.js +1 -1
  153. package/dist/esm-es5/wm-timepicker.entry.js +1 -1
  154. package/dist/esm-es5/wm-toggletip.entry.js +1 -1
  155. package/dist/esm-es5/wm-uploader.entry.js +1 -1
  156. package/dist/ripple/{p-dfe38d43.system.entry.js → p-054ccfa1.system.entry.js} +1 -1
  157. package/dist/ripple/{p-ff011bf3.entry.js → p-09b2c614.entry.js} +1 -1
  158. package/dist/ripple/{p-d063e3e9.entry.js → p-0dd172c2.entry.js} +1 -1
  159. package/dist/ripple/{p-df2bd836.entry.js → p-10d6335d.entry.js} +1 -1
  160. package/dist/ripple/{p-923527d9.system.entry.js → p-1762bc51.system.entry.js} +1 -1
  161. package/dist/ripple/{p-d530a06f.system.entry.js → p-1a1a6d89.system.entry.js} +1 -1
  162. package/dist/ripple/{p-8707f00a.system.entry.js → p-29792d81.system.entry.js} +1 -1
  163. package/dist/ripple/{p-d24ecc0c.js → p-2b929b10.js} +1 -1
  164. package/dist/ripple/{p-aa0e1f8b.system.entry.js → p-2e6988e6.system.entry.js} +1 -1
  165. package/dist/ripple/{p-811380de.entry.js → p-34d6d1d2.entry.js} +1 -1
  166. package/dist/ripple/{p-85ea8ece.entry.js → p-3597b28b.entry.js} +1 -1
  167. package/dist/ripple/{p-1d61c7bd.system.entry.js → p-3efd31ef.system.entry.js} +1 -1
  168. package/dist/ripple/{p-6f7f1331.system.entry.js → p-3fbf3278.system.entry.js} +1 -1
  169. package/dist/ripple/{p-6b4bc7ed.system.entry.js → p-430183de.system.entry.js} +1 -1
  170. package/dist/ripple/{p-888bec42.js → p-43f1298b.js} +0 -0
  171. package/dist/ripple/{p-b545a4a1.entry.js → p-44da2057.entry.js} +1 -1
  172. package/dist/ripple/p-4a1498f7.system.js +1 -0
  173. package/dist/ripple/p-4f1bf7f5.entry.js +1 -0
  174. package/dist/ripple/{p-32c15757.entry.js → p-5bea2c87.entry.js} +1 -1
  175. package/dist/ripple/{p-0ec5e02c.system.js → p-63190f58.system.js} +0 -0
  176. package/dist/ripple/{p-959aa7ae.system.entry.js → p-695fba1d.system.entry.js} +1 -1
  177. package/dist/ripple/p-791c6577.js +1 -0
  178. package/dist/ripple/{p-2a18f87c.entry.js → p-7a654f2c.entry.js} +1 -1
  179. package/dist/ripple/p-7ce57c62.system.js +1 -0
  180. package/dist/ripple/p-7f621f1c.system.entry.js +1 -0
  181. package/dist/ripple/{p-e3114f71.entry.js → p-87edffcc.entry.js} +1 -1
  182. package/dist/ripple/p-8ee1416a.entry.js +1 -0
  183. package/dist/ripple/{p-47639d21.entry.js → p-9a603f75.entry.js} +1 -1
  184. package/dist/ripple/{p-313b6073.system.js → p-9d02957d.system.js} +0 -0
  185. package/dist/ripple/{p-6c5006d1.entry.js → p-a2663226.entry.js} +1 -1
  186. package/dist/ripple/{p-54fb8d84.entry.js → p-a60407e7.entry.js} +1 -1
  187. package/dist/ripple/{p-05d01f10.system.entry.js → p-b6eb9ed6.system.entry.js} +1 -1
  188. package/dist/ripple/p-bf4bbba3.system.js +1 -0
  189. package/dist/ripple/{p-475e8f32.entry.js → p-c56dc658.entry.js} +1 -1
  190. package/dist/ripple/{p-e62f5770.entry.js → p-c741ddb3.entry.js} +1 -1
  191. package/dist/ripple/{p-9e294a2a.system.entry.js → p-cb22eef3.system.entry.js} +1 -1
  192. package/dist/ripple/{p-fa36e7b3.js → p-cd73566d.js} +0 -0
  193. package/dist/ripple/{p-f48bf28e.system.entry.js → p-d25523dd.system.entry.js} +1 -1
  194. package/dist/ripple/{p-2f9a6860.system.entry.js → p-d872e221.system.entry.js} +1 -1
  195. package/dist/ripple/{p-4325dabd.entry.js → p-d8a12a04.entry.js} +1 -1
  196. package/dist/ripple/{p-31af715e.system.entry.js → p-d9978c48.system.entry.js} +1 -1
  197. package/dist/ripple/p-daec9ed7.system.entry.js +1 -0
  198. package/dist/ripple/{p-ebe7b4fb.entry.js → p-dc7b53bd.entry.js} +1 -1
  199. package/dist/ripple/{p-7d9920ea.system.entry.js → p-df895edb.system.entry.js} +1 -1
  200. package/dist/ripple/{p-5095fe0c.system.entry.js → p-e5a472c8.system.entry.js} +1 -1
  201. package/dist/ripple/{p-671b7adf.entry.js → p-e9b0eccc.entry.js} +1 -1
  202. package/dist/ripple/{p-2d285e1c.system.entry.js → p-ee3b6b4c.system.entry.js} +1 -1
  203. package/dist/ripple/{p-0e3e046c.system.entry.js → p-eea875ce.system.entry.js} +1 -1
  204. package/dist/ripple/{p-5b3a44fe.system.entry.js → p-f0b67d2f.system.entry.js} +1 -1
  205. package/dist/ripple/{p-08b7ec08.system.js → p-f5df5903.system.js} +0 -0
  206. package/dist/ripple/{p-cfea1f6e.entry.js → p-f62d01f9.entry.js} +1 -1
  207. package/dist/ripple/{p-0d0286c5.entry.js → p-f640448f.entry.js} +1 -1
  208. package/dist/ripple/{p-23c428dd.entry.js → p-fbd67b12.entry.js} +1 -1
  209. package/dist/ripple/{p-1a909e18.system.entry.js → p-fccab03d.system.entry.js} +1 -1
  210. package/dist/ripple/{p-a6d6eae7.js → p-fd8070fb.js} +0 -0
  211. package/dist/ripple/ripple.esm.js +1 -1
  212. package/dist/ripple/ripple.js +1 -1
  213. package/dist/types/components/charts/priv-chart-popover/priv-chart-popover.d.ts +27 -27
  214. package/dist/types/components/charts/wm-chart/wm-chart-slice.d.ts +11 -11
  215. package/dist/types/components/charts/wm-chart/wm-chart.d.ts +36 -36
  216. package/dist/types/components/charts/wm-progress-monitor/wm-progress-indicator.d.ts +27 -27
  217. package/dist/types/components/charts/wm-progress-monitor/wm-progress-monitor.d.ts +19 -17
  218. package/dist/types/components/charts/wm-progress-monitor/wm-progress-slice.d.ts +10 -10
  219. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +47 -47
  220. package/dist/types/components/wm-button/wm-button.d.ts +49 -49
  221. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +80 -80
  222. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +41 -41
  223. package/dist/types/components/wm-input/wm-input.d.ts +46 -46
  224. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +34 -34
  225. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +14 -14
  226. package/dist/types/components/wm-modal/wm-modal-header.d.ts +11 -11
  227. package/dist/types/components/wm-modal/wm-modal.d.ts +41 -41
  228. package/dist/types/components/wm-navigation/wm-navigation-hamburger.d.ts +21 -21
  229. package/dist/types/components/wm-navigation/wm-navigation-item.d.ts +13 -13
  230. package/dist/types/components/wm-navigation/wm-navigation.d.ts +28 -28
  231. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -10
  232. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -13
  233. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -61
  234. package/dist/types/components/wm-option/wm-option.d.ts +35 -35
  235. package/dist/types/components/wm-pagination/wm-pagination.d.ts +32 -32
  236. package/dist/types/components/wm-search/wm-search.d.ts +86 -86
  237. package/dist/types/components/wm-select/wm-select.d.ts +94 -94
  238. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +35 -35
  239. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +38 -38
  240. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +53 -53
  241. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -20
  242. package/dist/types/components/wm-tag-input/wm-tag-input-row/wm-tag-input-row.d.ts +11 -11
  243. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts +126 -126
  244. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +61 -61
  245. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +27 -27
  246. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -85
  247. package/dist/types/components/wm-uploader/wm-uploader.d.ts +117 -117
  248. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  249. package/dist/types/components.d.ts +29 -27
  250. package/dist/types/global/__mocks__/functions.d.ts +6 -6
  251. package/dist/types/global/chartFunctions.d.ts +30 -29
  252. package/dist/types/global/functions.d.ts +46 -46
  253. package/dist/types/global/global.d.ts +1 -1
  254. package/dist/types/global/interfaces.d.ts +48 -44
  255. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -6
  256. package/dist/types/global/services/http-service.d.ts +4 -4
  257. package/dist/types/lang/lang.d.ts +5 -5
  258. package/package.json +47 -47
  259. package/dist/esm-es5/global-0087a2ea.js +0 -1
  260. package/dist/ripple/p-09dca516.system.js +0 -1
  261. package/dist/ripple/p-20ad8577.entry.js +0 -1
  262. package/dist/ripple/p-276c88b5.system.entry.js +0 -1
  263. package/dist/ripple/p-4033dc2d.system.entry.js +0 -1
  264. package/dist/ripple/p-437c9944.system.js +0 -1
  265. package/dist/ripple/p-479b5d27.js +0 -1
  266. package/dist/ripple/p-71ac86cb.entry.js +0 -1
  267. package/dist/ripple/p-bbaec20d.system.js +0 -1
@@ -1,891 +1,891 @@
1
1
  import { r as registerInstance, c as createEvent, f as forceUpdate, h, H as Host, g as getElement } from './index-17c79cc6.js';
2
- import { g as generateId, p as csvToArray, i as intl, d as debounce, q as hideTooltip, r as showTooltip, l as shouldOpenUp } from './functions-14df5b8c.js';
2
+ import { g as generateId, p as csvToArray, i as intl, d as debounce, q as hideTooltip, r as showTooltip, l as shouldOpenUp } from './functions-478ab920.js';
3
3
 
4
4
  const wmTagInputCss = ":host,wm-tag-input{font-family:inherit;width:100%;display:block}:host *,wm-tag-input *{-webkit-box-sizing:border-box;box-sizing:border-box;font-size:14px}:host .wrapper,wm-tag-input .wrapper{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;font-size:0.875rem}:host .wrapper .label,wm-tag-input .wrapper .label{display:block;line-height:normal;font-weight:600;white-space:nowrap;margin-bottom:0.25rem}:host .wrapper .label .required,wm-tag-input .wrapper .label .required{color:#c0392b}:host .wrapper.label-left,wm-tag-input .wrapper.label-left{-ms-flex-direction:row;flex-direction:row}:host .wrapper.label-left .label-wrapper,wm-tag-input .wrapper.label-left .label-wrapper{line-height:2.5rem}:host .wrapper.label-left .label-wrapper .label,wm-tag-input .wrapper.label-left .label-wrapper .label{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;min-height:2.5rem;white-space:normal;margin-bottom:0;margin-right:0.75rem}:host .wrapper.label-none label,wm-tag-input .wrapper.label-none label{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;border:0 !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;white-space:nowrap !important;margin:-1px !important}:host .wrapper.invalid .label,wm-tag-input .wrapper.invalid .label{color:#c0392b}:host .wrapper.invalid .label:after,wm-tag-input .wrapper.invalid .label:after{display:inline-block;font:normal normal normal 24px/1 \"Material Design Icons\";font-size:inherit;text-rendering:auto;line-height:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:\"\\f026\";margin-left:0.3125rem}[dir=RTL] :host .wrapper.invalid .label:after,[dir=RTL] wm-tag-input .wrapper.invalid .label:after{margin-left:0;margin-right:0.3125rem}:host .wrapper.rtl.label-left .label,wm-tag-input .wrapper.rtl.label-left .label{margin-right:0;margin-left:0.75rem}:host .wrapper,wm-tag-input .wrapper{width:100%;height:100%;position:relative}:host .field-wrapper,wm-tag-input .field-wrapper{position:relative;width:100%;border:1px solid #4a4a4a;-webkit-border-radius:3px;-moz-border-radius:3px;-ms-border-radius:3px;border-radius:3px}:host .field-wrapper.focused,wm-tag-input .field-wrapper.focused{-webkit-box-shadow:0 0 0 1px #20cbd4;-moz-box-shadow:0 0 0 1px #20cbd4;box-shadow:0 0 0 1px #20cbd4;outline:none;border-color:#20cbd4}:host .character-count,wm-tag-input .character-count{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;min-width:5rem;background-color:rgba(74, 74, 74, 0.05);font-size:0.875rem;font-weight:500;-ms-flex-item-align:stretch;align-self:stretch}:host .tags-and-input-wrapper,wm-tag-input .tags-and-input-wrapper{position:relative;width:100%;padding:0.5rem 0.25rem 0.5rem 0;margin-bottom:-0.5rem}:host .upper-row,wm-tag-input .upper-row{width:100%;display:-ms-flexbox;display:flex;-ms-flex:1;flex:1;-ms-flex-pack:justify;justify-content:space-between}:host .upper-row:before,wm-tag-input .upper-row:before{-ms-flex-item-align:start;align-self:flex-start;display:inline-block;font:normal normal normal 24px/1 \"Material Design Icons\";font-size:inherit;text-rendering:auto;line-height:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:\"\\f349\";color:#b5b5b5;padding:0.75rem 0.5rem 0.75rem 0.75rem}:host .lower-row,wm-tag-input .lower-row{width:100%;min-height:1.875rem}:host #max-tags,wm-tag-input #max-tags{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;min-height:1.875rem;background-color:#e6e6e6;padding:0.5rem 1rem;color:#4a4a4a;font-size:0.875rem;border-top:1px solid rgba(35, 35, 35, 0.6);border-radius:0 0 3px 3px}:host .tag-area,wm-tag-input .tag-area{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;margin:0;padding:0}:host .tag-area:focus,wm-tag-input .tag-area:focus{outline:none}:host .tag-area [role=option],wm-tag-input .tag-area [role=option]{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-align:center;align-items:center;height:1.75rem;list-style:none;color:#4a4a4a;background-color:rgba(3, 0, 0, 0.1);padding:0.5rem 0.625rem;margin-bottom:0.5rem;margin-right:0.25rem;margin-left:0.25rem;-webkit-transition:background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);transition:background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);white-space:pre}:host .tag-area [role=option].highlight,wm-tag-input .tag-area [role=option].highlight{-webkit-animation:fadeIn 1s;animation:fadeIn 1s}@-webkit-keyframes fadeIn{0%{background-color:rgba(3, 0, 0, 0.1)}50%{background-color:#c8dfcc}100%{background-color:rgba(3, 0, 0, 0.1)}}@keyframes fadeIn{0%{background-color:rgba(3, 0, 0, 0.1)}50%{background-color:#c8dfcc}100%{background-color:rgba(3, 0, 0, 0.1)}}:host .tag-area [role=option].focused,wm-tag-input .tag-area [role=option].focused{background-color:#d1d1d1}:host .tag-area [role=option].locked,wm-tag-input .tag-area [role=option].locked{background-color:#6b6b6b;color:white}:host .tag-area [role=option] .icon,wm-tag-input .tag-area [role=option] .icon{display:-ms-inline-flexbox;display:inline-flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;height:1.25rem;width:1.25rem;padding:0;margin-left:0.5rem}:host .tag-area [role=option] .icon.remove-btn,wm-tag-input .tag-area [role=option] .icon.remove-btn{border:1px solid #575195;color:#575195;border-radius:50%;cursor:pointer;-webkit-transition:background-color 500ms cubic-bezier(0.4, 0, 0.2, 1), color 500ms cubic-bezier(0.4, 0, 0.2, 1);transition:background-color 500ms cubic-bezier(0.4, 0, 0.2, 1), color 500ms cubic-bezier(0.4, 0, 0.2, 1)}:host .tag-area [role=option] .icon.remove-btn:hover,wm-tag-input .tag-area [role=option] .icon.remove-btn:hover{color:white;background-color:#575195}:host .tag-area [role=option] .icon.remove-btn:before,wm-tag-input .tag-area [role=option] .icon.remove-btn:before{display:inline-block;font:normal normal normal 24px/1 \"Material Design Icons\";font-size:inherit;text-rendering:auto;line-height:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:\"\\f156\"}:host .tag-area [role=option] .icon.lock,wm-tag-input .tag-area [role=option] .icon.lock{color:white}:host .tag-area [role=option] .icon.lock:before,wm-tag-input .tag-area [role=option] .icon.lock:before{display:inline-block;font:normal normal normal 24px/1 \"Material Design Icons\";font-size:inherit;text-rendering:auto;line-height:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:\"\\f341\"}:host input,wm-tag-input input{font-family:inherit;border:none;height:1.75rem;padding:0;margin-bottom:0.5rem;margin-right:0.25rem;padding-left:0.5rem;right:0px}:host input.hidden,wm-tag-input input.hidden{display:none}:host input:focus,wm-tag-input input:focus{outline:none}:host .dropdown-wrapper,wm-tag-input .dropdown-wrapper{margin:0;padding:0;-webkit-box-shadow:0 4px 15px 0 rgba(0, 0, 0, 0.2);-moz-box-shadow:0 4px 15px 0 rgba(0, 0, 0, 0.2);box-shadow:0 4px 15px 0 rgba(0, 0, 0, 0.2);-ms-transition:transform 0.25s ease;-webkit-transition:transform 0.25s ease;-moz-transition:transform 0.25s ease;-webkit-transition:-webkit-transform 0.25s ease;transition:-webkit-transform 0.25s ease;transition:transform 0.25s ease;transition:transform 0.25s ease, -webkit-transform 0.25s ease;-ms-transform:scale(1, 0);-webkit-transform:scale(1, 0);-moz-transform:scale(1, 0);transform:scale(1, 0);-ms-transform-origin:center top;-webkit-transform-origin:center top;-moz-transform-origin:center top;transform-origin:center top;-webkit-border-radius:3px;-moz-border-radius:3px;-ms-border-radius:3px;border-radius:3px;position:absolute;top:calc(100% + 2px);right:0;background:#fff;z-index:100;width:100%;font-size:0.875rem}:host .dropdown-wrapper .dropdown,wm-tag-input .dropdown-wrapper .dropdown{-webkit-overflow-scrolling:touch;overflow:auto;max-height:12.5rem;margin:0;padding:0}:host .dropdown-wrapper.open,wm-tag-input .dropdown-wrapper.open{-ms-transform:scale(1, 1);-webkit-transform:scale(1, 1);-moz-transform:scale(1, 1);transform:scale(1, 1)}:host .dropdown-wrapper.upwards,wm-tag-input .dropdown-wrapper.upwards{top:unset;bottom:calc(100% + 2px);-ms-transform-origin:center bottom;-webkit-transform-origin:center bottom;-moz-transform-origin:center bottom;transform-origin:center bottom}:host .dropdown-wrapper li,:host .dropdown-wrapper div,wm-tag-input .dropdown-wrapper li,wm-tag-input .dropdown-wrapper div{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;padding:0 1rem;background:#fff;list-style:none;height:2.6875rem;white-space:pre}:host .dropdown-wrapper li[role=option],:host .dropdown-wrapper li.add-new-btn,:host .dropdown-wrapper div[role=option],:host .dropdown-wrapper div.add-new-btn,wm-tag-input .dropdown-wrapper li[role=option],wm-tag-input .dropdown-wrapper li.add-new-btn,wm-tag-input .dropdown-wrapper div[role=option],wm-tag-input .dropdown-wrapper div.add-new-btn{cursor:pointer;color:#575195;font-weight:bold;width:100%;border:none}:host .dropdown-wrapper li[role=option][aria-selected=true],:host .dropdown-wrapper li.add-new-btn[aria-selected=true],:host .dropdown-wrapper div[role=option][aria-selected=true],:host .dropdown-wrapper div.add-new-btn[aria-selected=true],wm-tag-input .dropdown-wrapper li[role=option][aria-selected=true],wm-tag-input .dropdown-wrapper li.add-new-btn[aria-selected=true],wm-tag-input .dropdown-wrapper div[role=option][aria-selected=true],wm-tag-input .dropdown-wrapper div.add-new-btn[aria-selected=true]{color:#6b6b6b;font-style:italic;font-weight:normal;cursor:unset}:host .dropdown-wrapper li[role=option]:hover:not([aria-selected=true]),:host .dropdown-wrapper li[role=option].focused,:host .dropdown-wrapper li.add-new-btn:hover:not([aria-selected=true]),:host .dropdown-wrapper li.add-new-btn.focused,:host .dropdown-wrapper div[role=option]:hover:not([aria-selected=true]),:host .dropdown-wrapper div[role=option].focused,:host .dropdown-wrapper div.add-new-btn:hover:not([aria-selected=true]),:host .dropdown-wrapper div.add-new-btn.focused,wm-tag-input .dropdown-wrapper li[role=option]:hover:not([aria-selected=true]),wm-tag-input .dropdown-wrapper li[role=option].focused,wm-tag-input .dropdown-wrapper li.add-new-btn:hover:not([aria-selected=true]),wm-tag-input .dropdown-wrapper li.add-new-btn.focused,wm-tag-input .dropdown-wrapper div[role=option]:hover:not([aria-selected=true]),wm-tag-input .dropdown-wrapper div[role=option].focused,wm-tag-input .dropdown-wrapper div.add-new-btn:hover:not([aria-selected=true]),wm-tag-input .dropdown-wrapper div.add-new-btn.focused{outline:none;background:#f4f4f4}:host .dropdown-wrapper li.help-text,:host .dropdown-wrapper div.help-text,wm-tag-input .dropdown-wrapper li.help-text,wm-tag-input .dropdown-wrapper div.help-text{color:#4a4a4a;min-height:2.6875rem;padding-top:0.25rem;padding-bottom:0.25rem;white-space:normal}:host .dropdown-wrapper li:not(:last-child),:host .dropdown-wrapper div:not(:last-child),wm-tag-input .dropdown-wrapper li:not(:last-child),wm-tag-input .dropdown-wrapper div:not(:last-child){border-bottom:2px solid rgba(46, 27, 70, 0.05)}:host .info-text,wm-tag-input .info-text{font-style:italic;margin-top:0.25rem}:host .table-wrapper,wm-tag-input .table-wrapper{min-height:10rem;overflow:auto;margin-top:1.5rem}:host .table-wrapper #table,wm-tag-input .table-wrapper #table{width:100%;border-spacing:0px}:host .table-wrapper #table.fixed-widths,wm-tag-input .table-wrapper #table.fixed-widths{table-layout:fixed}:host .table-wrapper #table .headers,wm-tag-input .table-wrapper #table .headers{height:2.5rem;background-color:#eeedf4}:host .table-wrapper #table .headers th,wm-tag-input .table-wrapper #table .headers th{text-align:left;font-size:0.75rem;font-weight:700;text-transform:uppercase;padding:0 1.5rem}:host .table-wrapper tr.locked td:first-child:before,wm-tag-input .table-wrapper tr.locked td:first-child:before{display:inline-block;font:normal normal normal 24px/1 \"Material Design Icons\";font-size:inherit;text-rendering:auto;line-height:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:\"\\f33e\";margin-right:0.5rem;color:#4a4a4a}:host .table-wrapper tr:nth-child(even),wm-tag-input .table-wrapper tr:nth-child(even){background-color:#fafafa}:host .table-wrapper tr.selected,wm-tag-input .table-wrapper tr.selected{background-color:rgba(25, 161, 169, 0.2);-webkit-box-shadow:inset 0 0 0 1px #19a1a9;box-shadow:inset 0 0 0 1px #19a1a9;font-weight:500}:host .table-wrapper tr.focused,:host .table-wrapper tr:hover,wm-tag-input .table-wrapper tr.focused,wm-tag-input .table-wrapper tr:hover{background-color:#e9e7ec;-webkit-box-shadow:none;box-shadow:none}:host .table-wrapper td,wm-tag-input .table-wrapper td{height:3.75rem;vertical-align:middle;padding:0 1.5rem;cursor:pointer}:host .table-wrapper td.trunc,wm-tag-input .table-wrapper td.trunc{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .table-wrapper td.focused,wm-tag-input .table-wrapper td.focused{-webkit-box-shadow:inset 0 2px 2px 0 rgba(244, 243, 246, 0.2), inset 0 2px 2px 0 rgba(0, 0, 0, 0.1), inset 0 0 4px 3px #61279e;box-shadow:inset 0 2px 2px 0 rgba(244, 243, 246, 0.2), inset 0 2px 2px 0 rgba(0, 0, 0, 0.1), inset 0 0 4px 3px #61279e}:host .table-wrapper td .description,wm-tag-input .table-wrapper td .description{display:none}:host .no-results,wm-tag-input .no-results{padding:1.25rem 1.5rem}:host .sr-only,wm-tag-input .sr-only{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;border:0 !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;white-space:nowrap !important;margin:-1px !important}";
5
5
 
6
- const TagInput = class {
7
- constructor(hostRef) {
8
- registerInstance(this, hostRef);
9
- this.wmTagInputChanged = createEvent(this, "wmTagInputChanged", 7);
10
- this.labelPosition = "top";
11
- this.options = ""; // csv
12
- this.selectedTags = ""; // csv
13
- this.addNew = true;
14
- this.characterLimit = 50;
15
- this.tagInputType = "dropdown";
16
- this.uid = this.el.id ? this.el.id : generateId();
17
- this.openUp = false;
18
- this.tooltipVisible = false;
19
- this.tablePosition = { row: 0, column: 1 };
20
- this.isExpanded = false;
21
- this.tagsList = csvToArray(this.selectedTags);
22
- this.optionsList = csvToArray(this.options);
23
- this.charCount = 0;
24
- this.liveRegionMessage = "";
25
- this.tagAreaInstructions = intl.formatMessage({
26
- id: "tagInput.tagAreaInstructions",
27
- defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
28
- });
29
- this.maxTagsReachedMessage = intl.formatMessage({
30
- id: "tagInput.maxTagsReached",
31
- defaultMessage: "No more tags can be added because the limit has been reached.",
32
- });
33
- this.debouncedUpdate = debounce(() => forceUpdate(this.el), 30);
34
- }
35
- get focusedElement() {
36
- return this.el.shadowRoot.activeElement;
37
- }
38
- get listItemEls() {
39
- return Array.from(this.dropdownEl.querySelectorAll("li"));
40
- }
41
- get tagEls() {
42
- return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
43
- }
44
- get nonLockedTagEls() {
45
- return this.tagEls.filter((tag) => !tag.classList.contains("locked"));
46
- }
47
- get optionEls() {
48
- return Array.from(this.dropdownEl.querySelectorAll(".option"));
49
- }
50
- get wmRowEls() {
51
- return Array.from(this.el.querySelectorAll("wm-tag-input-row"));
52
- }
53
- get localRowEls() {
54
- return Array.from(this.el.shadowRoot.querySelectorAll("tr"));
55
- }
56
- get filteredRows() {
57
- return this.wmRowEls.filter((row) => {
58
- const colValues = [row.col1, row.col2, row.col3, row.col4].join("").toLowerCase();
59
- return this.inputEl && this.inputEl.value ? colValues.includes(this.inputEl.value.toLowerCase()) : true;
60
- });
61
- }
62
- get nonLockedTagsList() {
63
- let list = [];
64
- if (this.tagInputType === "table") {
65
- this.tagsList.forEach((id) => {
66
- const correspondingRowEl = this.wmRowEls.filter((row) => id === row.id)[0];
67
- if (!correspondingRowEl.locked) {
68
- list.push(id);
69
- }
70
- });
71
- }
72
- else if (this.tagInputType === "dropdown") {
73
- list = this.tagsList;
74
- }
75
- return list;
76
- }
77
- get tagLimitReached() {
78
- return !!(this.maxTags && this.tagsList.length >= this.maxTags);
79
- }
80
- get noResultsMessage() {
81
- return intl.formatMessage({
82
- id: "tagInput.noResults",
83
- defaultMessage: "No results match your search.",
84
- description: "Message displayed when a user's search returns empty.",
85
- });
86
- }
87
- generateTagAddedMessage(tag) {
88
- return intl.formatMessage({
89
- id: "tagInput.tagAdded",
90
- defaultMessage: "{tagName} added.",
91
- description: "A confirmation for adding a tag.",
92
- }, { tagName: tag });
93
- }
94
- generateTagAlreadyAddedMessage(tag) {
95
- return intl.formatMessage({
96
- id: "tagInput.tagAlreadyAdded",
97
- defaultMessage: "{tagName} has already been added.",
98
- description: "An alert for adding a tag that is already present.",
99
- }, { tagName: tag });
100
- }
101
- generateTagCounterMessage(x, y) {
102
- return intl.formatMessage({
103
- id: "tagInput.tagsAddedCounter",
104
- defaultMessage: "Tags added: {x, number}/{y, number}",
105
- description: "For the user to understand how close they are to the tag limit.",
106
- }, {
107
- x: x,
108
- y: y,
109
- });
110
- }
111
- generateCharacterLimitLabel(characterLimit) {
112
- return intl.formatMessage({
113
- id: "global.characterLimit",
114
- defaultMessage: "{limit, number} characters allowed.",
115
- description: "for screen readers",
116
- }, { limit: characterLimit });
117
- }
118
- componentWillLoad() {
119
- if (!this.placeholder) {
120
- this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
121
- }
122
- if (!this.label) {
123
- console.error("wm-tag-input must have a label property");
124
- }
125
- this.el.focus = function () {
126
- // if present, send focus to the selected tags list
127
- if (this.selectedTags) {
128
- this.shadowRoot.querySelector("ul.tag-area").focus();
129
- }
130
- else {
131
- this.shadowRoot.querySelector("input").focus();
132
- }
133
- };
134
- this.consolidateSelectedTags();
135
- // on resize of component, trigger componentDidRender -> positionInput
136
- const resizeObserver = new ResizeObserver(() => this.debouncedUpdate());
137
- resizeObserver.observe(this.el);
138
- }
139
- componentDidLoad() {
140
- // prevent highlighting of pre-selected tags
141
- this.tagEls.forEach((el) => el.classList.remove("highlight"));
142
- }
143
- componentDidRender() {
144
- this.positionInput();
145
- }
146
- consolidateSelectedTags() {
147
- this.tagsList.forEach((tag) => {
148
- if (!this.includesCaseInsensitive(this.optionsList, tag)) {
149
- this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
150
- }
151
- });
152
- this.optionsList = csvToArray(this.options);
153
- }
154
- createPlaceholderDefault(addNew, hasOptions) {
155
- const addAndSearchPlaceholder = intl.formatMessage({
156
- id: "tagInput.placeholderAddAndSearch",
157
- defaultMessage: "Add or search for a tag",
158
- description: "Placeholder text. Use imperative",
159
- });
160
- const searchPlaceholder = intl.formatMessage({
161
- id: "tagInput.placeholderSearch",
162
- defaultMessage: "Search and select a tag",
163
- description: "Placeholder text. Use imperative",
164
- });
165
- const addPlaceholder = intl.formatMessage({
166
- id: "tagInput.placeholderAdd",
167
- defaultMessage: "Add a new tag",
168
- description: "Placeholder text. Use imperative",
169
- });
170
- let placeholder = "";
171
- if (addNew && hasOptions) {
172
- placeholder = addAndSearchPlaceholder;
173
- }
174
- else if (!addNew && hasOptions) {
175
- placeholder = searchPlaceholder;
176
- }
177
- else if (addNew) {
178
- placeholder = addPlaceholder;
179
- }
180
- return placeholder;
181
- }
182
- reflectSelectedTags(newValue, oldValue) {
183
- const isAddition = newValue.length > oldValue.length;
184
- let changedTag = "";
185
- let selectedTags = this.tagsList;
186
- if (isAddition) {
187
- changedTag = newValue.filter((val) => !oldValue.includes(val))[0];
188
- }
189
- else {
190
- changedTag = oldValue.filter((val) => !newValue.includes(val))[0];
191
- }
192
- // event emitted by type table uses element references instead of strings
193
- if (this.tagInputType === "table") {
194
- changedTag = this.wmRowEls.filter((row) => row.id === changedTag)[0];
195
- selectedTags = this.tagsList.map((id) => this.el.querySelector(`#${id}`));
196
- }
197
- this.selectedTags = this.listToCSV(this.tagsList);
198
- let detail = { value: selectedTags, tagChanged: changedTag };
199
- this.wmTagInputChanged.emit(detail);
200
- }
201
- handleRowUpdate() {
202
- forceUpdate(this.el);
203
- }
204
- closeIfNotElOrChild(ev) {
205
- const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
206
- if (this.tagInputType === "dropdown" && isntElOrChild && this.isExpanded) {
207
- this.closeDropdown();
208
- }
209
- }
210
- // From wm-button
211
- // we need to listen for scroll events during the capture phase because they do not bubble up
212
- // there can be layouts where the main content has 100vh and overflows
213
- // in these cases window will register no scroll events unless we catch on they way down
214
- dismissTooltip() {
215
- if (this.tooltipVisible) {
216
- hideTooltip();
217
- this.tooltipVisible = false;
218
- }
219
- }
220
- handleInputKeyDown(ev) {
221
- if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
222
- this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
223
- }
224
- // prevent keydown triggering on tag area
225
- ev.stopPropagation();
226
- switch (ev.key) {
227
- case "Enter":
228
- case ",":
229
- ev.preventDefault();
230
- this.handleInputEnter();
231
- break;
232
- case "ArrowDown":
233
- ev.preventDefault();
234
- this.handleInputArrowDown();
235
- break;
236
- case "ArrowUp":
237
- ev.preventDefault();
238
- this.handleInputArrowUp();
239
- break;
240
- case "ArrowLeft":
241
- ev.preventDefault();
242
- if (this.tagInputType === "table" && this.tablePosition.row) {
243
- this.moveLeftCell();
244
- }
245
- break;
246
- case "ArrowRight":
247
- ev.preventDefault();
248
- if (this.tagInputType === "table" && this.tablePosition.row) {
249
- this.moveRightCell();
250
- }
251
- break;
252
- case "Escape":
253
- if (this.tagInputType === "dropdown" && this.isExpanded) {
254
- this.closeDropdown();
255
- }
256
- break;
257
- case "ArrowLeft":
258
- case "Backspace":
259
- this.handleInputBackspace();
260
- break;
261
- }
262
- }
263
- handleInputFocus() {
264
- if (this.tagInputType === "dropdown") {
265
- this.openDropdown();
266
- this.clearListItemFocus();
267
- }
268
- // force update needed to apply styled state of field-wrapper el
269
- forceUpdate(this.el);
270
- }
271
- handleInputChanged(value) {
272
- this.charCount = value.length;
273
- if (this.tagInputType === "dropdown") {
274
- this.clearListItemFocus();
275
- if (this.charCount >= this.characterLimit - 5) {
276
- this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
277
- }
278
- if (!this.isExpanded) {
279
- this.openDropdown();
280
- }
281
- }
282
- else if (this.tagInputType === "table") {
283
- this.clearCellFocus();
284
- }
285
- this.announceExistingOptions();
286
- }
287
- handleInputEnter() {
288
- if (this.tagInputType === "dropdown") {
289
- if (this.focusedListItem) {
290
- this.handleListItemClick(this.focusedListItem);
291
- }
292
- else {
293
- this.submitInput(this.addNew, this.inputEl.value.trim());
294
- }
295
- }
296
- else if (this.tagInputType === "table" && this.tablePosition.row > 0) {
297
- this.handleTableRowClick(this.localRowEls[this.tablePosition.row].id);
298
- }
299
- }
300
- submitInput(canAddNew, value) {
301
- const hasNonWhiteSpaceCharacters = value.match(/\S/);
302
- if (canAddNew && hasNonWhiteSpaceCharacters) {
303
- this.addTag(value);
304
- this.optionsList = this.addOption(value);
305
- this.resetInput();
306
- }
307
- }
308
- handleInputArrowDown() {
309
- if (this.tagInputType === "table") {
310
- this.moveDownRow();
311
- }
312
- else if (this.tagInputType === "dropdown" && this.isExpanded) {
313
- this.moveDownListItem();
314
- }
315
- else if (this.tagInputType === "dropdown") {
316
- this.openDropdown();
317
- }
318
- }
319
- handleInputArrowUp() {
320
- if (this.tagInputType === "table") {
321
- this.moveUpRow();
322
- }
323
- else if (this.tagInputType === "dropdown" && this.isExpanded) {
324
- this.moveUpListItem();
325
- }
326
- else if (this.tagInputType === "dropdown") {
327
- this.openDropdown();
328
- }
329
- }
330
- handleInputBackspace() {
331
- if (this.inputEl.value === "" && this.tagsList.length > 0) {
332
- // wait for events to finish firing before redirecting focus
333
- // prevents double input in input area and tag area
334
- window.requestAnimationFrame(() => {
335
- if (this.nonLockedTagsList.length > 0) {
336
- this.tagAreaEl.focus();
337
- this.focusTag(this.tagEls[this.tagEls.length - 1]);
338
- }
339
- });
340
- }
341
- }
342
- handleListItemKeyDown(ev) {
343
- const typedEvTarget = ev.target;
344
- switch (ev.key) {
345
- case "Enter":
346
- case " ":
347
- ev.preventDefault();
348
- typedEvTarget.click();
349
- break;
350
- case "ArrowDown":
351
- ev.preventDefault();
352
- this.moveDownListItem();
353
- break;
354
- case "ArrowUp":
355
- ev.preventDefault();
356
- this.moveUpListItem();
357
- break;
358
- case "Escape":
359
- if (this.focusedElement !== this.inputEl) {
360
- this.inputEl.focus();
361
- }
362
- else if (this.tagInputType === "dropdown") {
363
- this.closeDropdown();
364
- }
365
- break;
366
- }
367
- }
368
- handleListItemClick(item) {
369
- const tag = item.dataset.option.trim() || "";
370
- if (this.includesCaseInsensitive(this.tagsList, tag)) {
371
- this.announce(this.generateTagAlreadyAddedMessage(tag));
372
- }
373
- else {
374
- this.resetInput();
375
- this.addTag(tag);
376
- this.optionsList = this.addOption(tag);
377
- this.focusedListItem = null;
378
- }
379
- }
380
- handleTableRowClick(rowId) {
381
- const referencedRow = this.el.querySelector(`#${rowId}`);
382
- const isLocked = referencedRow.locked;
383
- if (!isLocked) {
384
- if (this.includesCaseInsensitive(this.tagsList, rowId)) {
385
- this.removeTag(rowId);
386
- }
387
- else if (!this.tagLimitReached) {
388
- this.addTag(rowId);
389
- this.resetInput();
390
- }
391
- }
392
- }
393
- handleTagAreaKeyDown(ev) {
394
- switch (ev.key) {
395
- case "ArrowLeft":
396
- case "ArrowUp":
397
- ev.preventDefault();
398
- this.moveLeftTag();
399
- break;
400
- case "ArrowRight":
401
- case "ArrowDown":
402
- ev.preventDefault();
403
- this.moveRightTag();
404
- break;
405
- case "Backspace":
406
- case "Delete":
407
- this.handleTagAreaDelete();
408
- break;
409
- }
410
- }
411
- handleTagAreaDelete() {
412
- const isLocked = this.focusedTag && this.focusedTag.classList.contains("locked");
413
- if (this.focusedTag && this.focusedTag.dataset.tag && !isLocked) {
414
- this.removeTag(this.focusedTag.dataset.tag);
415
- if (this.nonLockedTagsList.length === 0) {
416
- // focus input if no tags are left
417
- this.inputEl.focus();
418
- }
419
- else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
420
- // reassign focus if removing the last tag but there are still tags remaining
421
- this.focusedTag = this.tagEls[this.tagEls.length - 2];
422
- this.focusTag(this.focusedTag);
423
- }
424
- }
425
- }
426
- handleBlur(ev, component) {
427
- const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
428
- this.dismissTooltip();
429
- this.clearCellFocus();
430
- if (isntElOrChild) {
431
- this.fieldWrapperEl.classList.remove("focused");
432
- if (this.tagInputType === "dropdown") {
433
- this.closeDropdown();
434
- }
435
- }
436
- }
437
- handleCellMouseEnter(ev) {
438
- const cell = ev.target;
439
- const isTruncated = cell.scrollWidth > cell.clientWidth;
440
- if (isTruncated) {
441
- // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
442
- showTooltip("bottom", cell, cell.innerText);
443
- this.tooltipVisible = true;
444
- }
445
- }
446
- handleTagAreaFocus() {
447
- if (this.tagInputType === "dropdown") {
448
- this.closeDropdown();
449
- }
450
- this.focusedTag = this.nonLockedTagEls[0];
451
- this.focusTag(this.focusedTag);
452
- }
453
- handleRemoveButtonClick(tag) {
454
- this.moveLeftTag();
455
- this.removeTag(tag);
456
- }
457
- moveDownListItem() {
458
- if (this.listItemEls.length > 0) {
459
- const firstListItem = this.listItemEls[0];
460
- if (!this.focusedListItem) {
461
- this.focusListItem(firstListItem);
462
- }
463
- else if (this.focusedListItem.nextElementSibling) {
464
- this.focusListItem(this.focusedListItem.nextElementSibling);
465
- }
466
- else {
467
- this.focusListItem(firstListItem);
468
- }
469
- }
470
- }
471
- moveUpListItem() {
472
- if (this.listItemEls.length > 0) {
473
- const lastListItem = this.listItemEls[this.listItemEls.length - 1];
474
- if (!this.focusedListItem) {
475
- this.focusListItem(lastListItem);
476
- }
477
- else if (this.focusedListItem.previousElementSibling) {
478
- this.focusListItem(this.focusedListItem.previousElementSibling);
479
- }
480
- else {
481
- this.clearListItemFocus();
482
- }
483
- }
484
- }
485
- moveDownRow() {
486
- if (this.filteredRows.length > 0) {
487
- if (this.tablePosition.row === 0) {
488
- this.tablePosition.row = 1;
489
- }
490
- else if (this.tablePosition.row === this.filteredRows.length) {
491
- this.tablePosition.row = 1;
492
- }
493
- else {
494
- this.tablePosition.row++;
495
- }
496
- // skip locked rows
497
- const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
498
- if (rowToFocus.locked) {
499
- this.moveDownRow();
500
- }
501
- else {
502
- this.focusCell(this.tablePosition);
503
- }
504
- }
505
- }
506
- moveUpRow() {
507
- if (this.filteredRows.length > 0) {
508
- if (this.tablePosition.row === 0) {
509
- this.tablePosition.row = this.filteredRows.length;
510
- }
511
- else if (this.tablePosition.row === 1) {
512
- this.tablePosition.row = 0;
513
- }
514
- else {
515
- this.tablePosition.row--;
516
- }
517
- // skip locked rows
518
- const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
519
- if (rowToFocus && rowToFocus.locked) {
520
- this.moveUpRow();
521
- }
522
- else if (rowToFocus) {
523
- this.focusCell(this.tablePosition);
524
- }
525
- else {
526
- this.clearCellFocus();
527
- }
528
- }
529
- }
530
- moveLeftCell() {
531
- if (this.tablePosition.column != 1) {
532
- this.tablePosition.column--;
533
- this.focusCell(this.tablePosition);
534
- }
535
- }
536
- moveRightCell() {
537
- const numCols = csvToArray(this.colHeaders).length;
538
- if (this.tablePosition.column < numCols) {
539
- this.tablePosition.column++;
540
- this.focusCell(this.tablePosition);
541
- }
542
- }
543
- moveLeftTag() {
544
- const lastTag = this.tagEls[this.tagEls.length - 1];
545
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
546
- this.focusedTag = this.focusedTag.previousElementSibling;
547
- }
548
- else {
549
- this.focusedTag = lastTag;
550
- }
551
- // skip locked tags
552
- if (this.focusedTag.classList.contains("locked") && this.nonLockedTagEls.length > 0) {
553
- this.moveLeftTag();
554
- }
555
- else {
556
- this.focusTag(this.focusedTag);
557
- }
558
- }
559
- moveRightTag() {
560
- const firstTag = this.tagEls[0];
561
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
562
- this.focusedTag = this.focusedTag.nextElementSibling;
563
- }
564
- else {
565
- this.focusedTag = firstTag;
566
- }
567
- // skip locked tags
568
- if (this.focusedTag.classList.contains("locked")) {
569
- this.moveRightTag();
570
- }
571
- else {
572
- this.focusTag(this.focusedTag);
573
- }
574
- }
575
- addOption(option) {
576
- let newOptionsList = this.optionsList;
577
- const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
578
- if (!optionAlreadyExists) {
579
- newOptionsList = newOptionsList.concat(option);
580
- }
581
- return newOptionsList;
582
- }
583
- removeOption(option) {
584
- this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
585
- }
586
- addTag(tag) {
587
- let newTagsList = this.tagsList;
588
- const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
589
- const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
590
- if (!tagAlreadyAdded) {
591
- let textToAnnounce = tag;
592
- if (this.tagInputType === "table") {
593
- const referencedRow = this.el.querySelector(`#${tag}`);
594
- textToAnnounce = referencedRow.col1;
595
- }
596
- this.announce(this.generateTagAddedMessage(textToAnnounce));
597
- this.tagsList = newTagsList.concat(tagExistsAsOption || tag);
598
- // if maxTags has been reached, focus should go to the tagArea
599
- if (this.tagLimitReached) {
600
- this.tagAreaEl.focus();
601
- }
602
- }
603
- }
604
- removeTag(tag) {
605
- let textToAnnounce = tag;
606
- if (this.tagInputType === "table") {
607
- const referencedRow = this.el.querySelector(`#${tag}`);
608
- textToAnnounce = referencedRow.col1;
609
- }
610
- const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: textToAnnounce });
611
- this.announce(tagRemovedMessage);
612
- this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
613
- if (this.tagInputType === "dropdown") {
614
- // if a tag was introduced by the user, also remove it from the dropdown options
615
- const devOptionsList = csvToArray(this.options);
616
- if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
617
- this.removeOption(tag);
618
- }
619
- }
620
- }
621
- focusListItem(item) {
622
- this.focusedListItem = item;
623
- this.inputEl.setAttribute("aria-activedescendant", this.focusedListItem.id);
624
- item.scrollIntoView({ block: "nearest" });
625
- }
626
- focusTag(element) {
627
- if (element.classList.contains("locked")) {
628
- this.focusedTag = null;
629
- this.tagAreaEl.setAttribute("aria-activedescendant", "");
630
- }
631
- else {
632
- this.focusedTag = element;
633
- this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
634
- }
635
- }
636
- focusCell(position) {
637
- this.clearCellFocus(false);
638
- if (position.row) {
639
- const rowToFocus = this.localRowEls[position.row];
640
- const rowCells = rowToFocus.querySelectorAll("td");
641
- const cellToFocus = rowCells[position.column - 1];
642
- const isTruncated = cellToFocus.scrollWidth > cellToFocus.clientWidth;
643
- rowToFocus.classList.add("focused");
644
- cellToFocus.classList.add("focused");
645
- cellToFocus.scrollIntoView({ block: "nearest" });
646
- this.inputEl.setAttribute("aria-activedescendant", cellToFocus.id);
647
- this.dismissTooltip();
648
- if (isTruncated) {
649
- // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
650
- showTooltip("bottom", cellToFocus, cellToFocus.innerText);
651
- this.tooltipVisible = true;
652
- }
653
- }
654
- }
655
- clearTagFocus() {
656
- this.tagAreaEl.setAttribute("aria-activedescendant", "");
657
- this.focusedTag = null;
658
- }
659
- clearCellFocus(resetPosition = true) {
660
- this.inputEl.setAttribute("aria-activedescendant", "");
661
- if (resetPosition) {
662
- this.tablePosition = { row: 0, column: 1 };
663
- }
664
- this.localRowEls.forEach((row) => {
665
- row.classList.remove("focused");
666
- row.querySelectorAll("td").forEach((cell) => {
667
- cell.classList.remove("focused");
668
- });
669
- });
670
- }
671
- openDropdown() {
672
- // given an offset of -2px because the dropdown is transformed downwards to avoid overlapping the focus border
673
- this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight, -2);
674
- this.isExpanded = true;
675
- }
676
- closeDropdown() {
677
- this.clearListItemFocus();
678
- this.isExpanded = false;
679
- }
680
- clearListItemFocus() {
681
- this.focusedListItem = null;
682
- this.inputEl.setAttribute("aria-activedescendant", "");
683
- this.listItemEls.forEach((el) => {
684
- el.classList.remove("focused");
685
- });
686
- }
687
- resetInput() {
688
- this.charCount = 0;
689
- this.inputEl.value = "";
690
- }
691
- announce(message) {
692
- // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
693
- if (this.liveRegionEl.textContent === message) {
694
- message += "\u00A0";
695
- }
696
- this.liveRegionMessage = message;
697
- }
698
- announceExistingOptions() {
699
- // request animation frame to wait for re-rendering of filtered options
700
- window.requestAnimationFrame(() => {
701
- let numResults = 0;
702
- if (this.tagInputType === "dropdown") {
703
- numResults = this.optionEls.length;
704
- }
705
- else if (this.tagInputType === "table") {
706
- numResults = this.filteredRows.length;
707
- }
708
- const existingOptionsMessage = intl.formatMessage({
709
- id: "tagInput.existingOptions",
710
- defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
711
- }, { num: numResults });
712
- if (numResults > 0) {
713
- this.announce(existingOptionsMessage);
714
- }
715
- });
716
- }
717
- announceCharacterLimitWarning(charCount, charLimit) {
718
- const charactersEnteredMessage = intl.formatMessage({
719
- id: "global.charactersEntered",
720
- defaultMessage: "{x, number} of {y, number} characters entered.",
721
- description: "for screen readers",
722
- }, { x: charCount, y: charLimit });
723
- const characterLimitReachedMessage = intl.formatMessage({
724
- id: "global.characterLimitReached",
725
- defaultMessage: "No additional characters will be entered.",
726
- description: "for screen readers",
727
- });
728
- this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
729
- }
730
- positionInput() {
731
- const lastTag = this.tagEls[this.tagEls.length - 1];
732
- // default placement to fall back to when no tags are present, or not enough space is available
733
- this.inputEl.style.position = "static";
734
- this.inputEl.style.width = "100%";
735
- if (lastTag) {
736
- const spaceAvailable = this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right;
737
- // 150px is the minimum width of the input field
738
- if (spaceAvailable >= 150) {
739
- // because the input has right: 0px
740
- // all thats needed to properly place it is setting position: absolute, top, and width
741
- this.inputEl.style.position = "absolute";
742
- this.inputEl.style.top = lastTag.offsetTop.toString() + "px";
743
- this.inputEl.style.width =
744
- (this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right - 8).toString() + "px";
745
- }
746
- }
747
- }
748
- /// Helpers
749
- listToCSV(list) {
750
- return list.join(",");
751
- }
752
- includesCaseInsensitive(list, element) {
753
- const lowercaseList = list.map((str) => str.toLowerCase());
754
- return lowercaseList.includes(element.toLowerCase());
755
- }
756
- filterCaseInsensitive(list, element) {
757
- return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
758
- }
759
- sortCaseInsensitive(list) {
760
- // The vanilla .sort method places words that start with capital letters above others (ASCII order)
761
- // so we need to pass in our own compare function to sort case-insensitive
762
- return list.sort((a, b) => {
763
- a = a.toLowerCase();
764
- b = b.toLowerCase();
765
- return a > b ? 1 : a < b ? -1 : 0;
766
- });
767
- }
768
- /// Renders
769
- renderTags() {
770
- let lockedTags = [];
771
- let unlockedTags = [];
772
- this.tagsList.forEach((tag, idx) => {
773
- const id = `tag${idx + 1}`;
774
- let tagText = "";
775
- let isLocked = false;
776
- if (this.tagInputType === "dropdown") {
777
- tagText = tag;
778
- }
779
- else if (this.tagInputType === "table") {
780
- // display table tags using col1 of the row with the same id
781
- // if one can't be found, display as empty
782
- const referencedRow = this.el.querySelector(`#${tag}`);
783
- tagText = referencedRow ? referencedRow.col1 : "";
784
- isLocked = referencedRow ? referencedRow.locked : false;
785
- }
786
- // make sure locked tags always appear in front of list
787
- const targetList = isLocked ? lockedTags : unlockedTags;
788
- targetList.push(h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""} ${isLocked ? "locked" : ""}`, "data-tag": tag, role: "option" }, tagText, isLocked ? (h("div", { class: "icon lock" })) : (h("button", { class: "icon remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) }))));
789
- });
790
- return [...lockedTags, ...unlockedTags];
791
- }
792
- renderDropdown() {
793
- return (h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, ref: (el) => (this.dropdownEl = el) }, h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()), h("ul", { class: "dropdown", id: "dropdown", role: "listbox", "aria-multiselectable": "true", "aria-expanded": this.isExpanded ? "true" : false, "aria-label": this.label, tabindex: -1 }, this.inputEl && this.renderAddNewButton(), this.renderListItems(this.optionsList))));
794
- }
795
- renderListItems(optionsList) {
796
- optionsList = this.sortCaseInsensitive(optionsList);
797
- // filter by input
798
- if (this.inputEl && this.inputEl.value) {
799
- optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
800
- }
801
- return optionsList.map((option, idx) => {
802
- const id = `option${idx + 1}`;
803
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
804
- const isSelected = this.includesCaseInsensitive(this.tagsList, option);
805
- return (h("li", { class: `option ${isFocused ? "focused" : ""}`, role: "option", id: id, "data-option": option, "aria-selected": isSelected ? "true" : "false", "aria-disabled": isSelected ? "true" : "false", onKeyDown: (ev) => this.handleListItemKeyDown(ev), onBlur: (ev) => this.handleBlur(ev, this.el), onClick: (ev) => this.handleListItemClick(ev.target) }, option));
806
- });
807
- }
808
- renderAddNewButton() {
809
- const hasNonWhiteSpaceCharacters = this.inputEl.value.match(/\S/);
810
- const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, this.inputEl.value.trim());
811
- if (this.addNew && hasNonWhiteSpaceCharacters && !optionAlreadyExists) {
812
- const id = `add-new-btn`;
813
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
814
- return (h("li", { role: "option", class: `add-new-btn ${isFocused ? "focused" : ""}`, id: id, "data-option": this.inputEl.value, onKeyDown: (ev) => this.handleListItemKeyDown(ev), onBlur: (ev) => this.handleBlur(ev, this.el), onClick: (ev) => this.handleListItemClick(ev.target), tabIndex: isFocused ? 0 : -1 }, `Add "${this.inputEl.value.trim()}"`));
815
- }
816
- else
817
- return "";
818
- }
819
- renderHelpText() {
820
- const helpTextHasOptions = intl.formatMessage({
821
- id: "tagInput.helpTextCanSelect",
822
- defaultMessage: "Search and select a tag.",
823
- description: "Placeholder text. Use imperative",
824
- });
825
- const helpTextEditable = intl.formatMessage({
826
- id: "tagInput.helpTextEditable",
827
- defaultMessage: "Press the Enter or Comma key to add a new tag.",
828
- description: "Placeholder text. Use imperative",
829
- });
830
- let helpText = "";
831
- if (this.optionsList.length > 0) {
832
- helpText += helpTextHasOptions;
833
- }
834
- if (this.addNew) {
835
- helpText += " " + helpTextEditable;
836
- }
837
- return helpText;
838
- }
839
- renderTagCounter() {
840
- if (this.maxTags) {
841
- return (h("div", { class: "lower-row" }, h("div", { id: "max-tags" }, this.generateTagCounterMessage(this.tagsList.length, this.maxTags), this.tagLimitReached && ` - ${this.maxTagsReachedMessage}`)));
842
- }
843
- }
844
- renderTable() {
845
- return (h("div", { class: "table-wrapper", onScroll: () => this.dismissTooltip() }, h("table", { id: "table", role: "grid", class: `${this.colWidths ? "fixed-widths" : ""}`, "aria-label": this.label, "aria-multiselectable": "true" }, this.renderTableHeaders(), this.filteredRows.length ? this.renderTableRows() : h("div", { class: "no-results" }, this.noResultsMessage))));
846
- }
847
- renderTableHeaders() {
848
- return (h("tr", { class: "headers", role: "row" }, csvToArray(this.colHeaders).map((header, idx) => {
849
- let overflowRule = "wrap";
850
- if (this.colWrap && csvToArray(this.colWrap)[idx]) {
851
- overflowRule = csvToArray(this.colWrap)[idx];
852
- }
853
- return (h("th", { class: `header-cell ${overflowRule}`, role: "columnheader",
854
- // @ts-ignore
855
- width: this.colWidths ? csvToArray(this.colWidths)[idx] : "" }, header));
856
- })));
857
- }
858
- renderTableRows() {
859
- return this.filteredRows.map((row) => {
860
- const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
861
- return (h("tr", { id: row.id, class: `${row.locked ? "locked" : ""} ${isSelected ? "selected" : ""}`, role: "row", onClick: () => this.handleTableRowClick(row.id) }, this.renderTableCells(row)));
862
- });
863
- }
864
- renderTableCells(row) {
865
- const colValues = [row.col1, row.col2, row.col3, row.col4].filter((val) => !!val);
866
- const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
867
- return colValues.map((val, idx) => {
868
- const localId = `${row.id}-col${idx + 1}`;
869
- let overflowRule = "wrap";
870
- if (this.colWrap && csvToArray(this.colWrap)[idx]) {
871
- overflowRule = csvToArray(this.colWrap)[idx];
872
- }
873
- return (h("td", { id: localId, role: "gridcell", class: overflowRule, "aria-describedby": `${localId}-description`, "aria-selected": isSelected.toString(), onMouseEnter: (ev) => this.handleCellMouseEnter(ev), onMouseLeave: () => this.dismissTooltip() }, val, h("div", { class: "description", id: `${localId}-description` }, row.locked ? "locked" : "")));
874
- });
875
- }
876
- render() {
877
- return (h(Host, { id: this.uid }, h("div", { class: `wrapper label-${this.labelPosition}` }, h("div", { class: "label-wrapper" }, h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)), h("div", { class: `field-wrapper ${this.focusedElement ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) }, h("div", { class: "upper-row" }, h("div", { class: "tags-and-input-wrapper" }, h("ul", { ref: (el) => (this.tagAreaEl = el), class: "tag-area", role: "listbox", "aria-activedescendant": "", "aria-orientation": "horizontal", "aria-label": `${this.label} ${this.tagsList.length > 0 ? this.tagAreaInstructions : ""}`, tabindex: this.nonLockedTagsList.length > 0 ? 0 : -1, "aria-describedby": `info max-tags`, onFocus: () => this.handleTagAreaFocus(), onBlur: (ev) => {
878
- this.clearTagFocus();
879
- this.handleBlur(ev, this.el);
880
- }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) }, this.renderTags()), h("input", { id: `input${this.uid}`, class: this.tagLimitReached ? "hidden" : "", role: "combobox", ref: (el) => (this.inputEl = el), autocomplete: "off", "aria-controls": this.tagInputType, "aria-describedby": "help-text", "aria-label": `${this.label} ${this.generateCharacterLimitLabel(this.characterLimit)}`, "aria-expanded": this.tagInputType === "dropdown" ? this.isExpanded.toString() : null, placeholder: this.placeholder, maxLength: this.tagInputType === "dropdown" ? this.characterLimit : undefined, onInput: () => this.handleInputChanged(this.inputEl.value), onBlur: (ev) => {
881
- this.handleBlur(ev, this.el);
882
- }, onFocus: () => this.handleInputFocus(), onKeyDown: (ev) => this.handleInputKeyDown(ev) })), this.tagInputType === "dropdown" && (h("div", { class: "character-count" }, this.charCount, "/", this.characterLimit))), this.renderTagCounter(), this.tagInputType === "dropdown" && this.renderDropdown()), this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""), h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage), this.tagInputType === "table" && this.renderTable())));
883
- }
884
- get el() { return getElement(this); }
885
- static get watchers() { return {
886
- "tagsList": ["reflectSelectedTags"]
887
- }; }
888
- };
6
+ const TagInput = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ this.wmTagInputChanged = createEvent(this, "wmTagInputChanged", 7);
10
+ this.labelPosition = "top";
11
+ this.options = ""; // csv
12
+ this.selectedTags = ""; // csv
13
+ this.addNew = true;
14
+ this.characterLimit = 50;
15
+ this.tagInputType = "dropdown";
16
+ this.uid = this.el.id ? this.el.id : generateId();
17
+ this.openUp = false;
18
+ this.tooltipVisible = false;
19
+ this.tablePosition = { row: 0, column: 1 };
20
+ this.isExpanded = false;
21
+ this.tagsList = csvToArray(this.selectedTags);
22
+ this.optionsList = csvToArray(this.options);
23
+ this.charCount = 0;
24
+ this.liveRegionMessage = "";
25
+ this.tagAreaInstructions = intl.formatMessage({
26
+ id: "tagInput.tagAreaInstructions",
27
+ defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
28
+ });
29
+ this.maxTagsReachedMessage = intl.formatMessage({
30
+ id: "tagInput.maxTagsReached",
31
+ defaultMessage: "No more tags can be added because the limit has been reached.",
32
+ });
33
+ this.debouncedUpdate = debounce(() => forceUpdate(this.el), 30);
34
+ }
35
+ get focusedElement() {
36
+ return this.el.shadowRoot.activeElement;
37
+ }
38
+ get listItemEls() {
39
+ return Array.from(this.dropdownEl.querySelectorAll("li"));
40
+ }
41
+ get tagEls() {
42
+ return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
43
+ }
44
+ get nonLockedTagEls() {
45
+ return this.tagEls.filter((tag) => !tag.classList.contains("locked"));
46
+ }
47
+ get optionEls() {
48
+ return Array.from(this.dropdownEl.querySelectorAll(".option"));
49
+ }
50
+ get wmRowEls() {
51
+ return Array.from(this.el.querySelectorAll("wm-tag-input-row"));
52
+ }
53
+ get localRowEls() {
54
+ return Array.from(this.el.shadowRoot.querySelectorAll("tr"));
55
+ }
56
+ get filteredRows() {
57
+ return this.wmRowEls.filter((row) => {
58
+ const colValues = [row.col1, row.col2, row.col3, row.col4].join("").toLowerCase();
59
+ return this.inputEl && this.inputEl.value ? colValues.includes(this.inputEl.value.toLowerCase()) : true;
60
+ });
61
+ }
62
+ get nonLockedTagsList() {
63
+ let list = [];
64
+ if (this.tagInputType === "table") {
65
+ this.tagsList.forEach((id) => {
66
+ const correspondingRowEl = this.wmRowEls.filter((row) => id === row.id)[0];
67
+ if (!correspondingRowEl.locked) {
68
+ list.push(id);
69
+ }
70
+ });
71
+ }
72
+ else if (this.tagInputType === "dropdown") {
73
+ list = this.tagsList;
74
+ }
75
+ return list;
76
+ }
77
+ get tagLimitReached() {
78
+ return !!(this.maxTags && this.tagsList.length >= this.maxTags);
79
+ }
80
+ get noResultsMessage() {
81
+ return intl.formatMessage({
82
+ id: "tagInput.noResults",
83
+ defaultMessage: "No results match your search.",
84
+ description: "Message displayed when a user's search returns empty.",
85
+ });
86
+ }
87
+ generateTagAddedMessage(tag) {
88
+ return intl.formatMessage({
89
+ id: "tagInput.tagAdded",
90
+ defaultMessage: "{tagName} added.",
91
+ description: "A confirmation for adding a tag.",
92
+ }, { tagName: tag });
93
+ }
94
+ generateTagAlreadyAddedMessage(tag) {
95
+ return intl.formatMessage({
96
+ id: "tagInput.tagAlreadyAdded",
97
+ defaultMessage: "{tagName} has already been added.",
98
+ description: "An alert for adding a tag that is already present.",
99
+ }, { tagName: tag });
100
+ }
101
+ generateTagCounterMessage(x, y) {
102
+ return intl.formatMessage({
103
+ id: "tagInput.tagsAddedCounter",
104
+ defaultMessage: "Tags added: {x, number}/{y, number}",
105
+ description: "For the user to understand how close they are to the tag limit.",
106
+ }, {
107
+ x: x,
108
+ y: y,
109
+ });
110
+ }
111
+ generateCharacterLimitLabel(characterLimit) {
112
+ return intl.formatMessage({
113
+ id: "global.characterLimit",
114
+ defaultMessage: "{limit, number} characters allowed.",
115
+ description: "for screen readers",
116
+ }, { limit: characterLimit });
117
+ }
118
+ componentWillLoad() {
119
+ if (!this.placeholder) {
120
+ this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
121
+ }
122
+ if (!this.label) {
123
+ console.error("wm-tag-input must have a label property");
124
+ }
125
+ this.el.focus = function () {
126
+ // if present, send focus to the selected tags list
127
+ if (this.selectedTags) {
128
+ this.shadowRoot.querySelector("ul.tag-area").focus();
129
+ }
130
+ else {
131
+ this.shadowRoot.querySelector("input").focus();
132
+ }
133
+ };
134
+ this.consolidateSelectedTags();
135
+ // on resize of component, trigger componentDidRender -> positionInput
136
+ const resizeObserver = new ResizeObserver(() => this.debouncedUpdate());
137
+ resizeObserver.observe(this.el);
138
+ }
139
+ componentDidLoad() {
140
+ // prevent highlighting of pre-selected tags
141
+ this.tagEls.forEach((el) => el.classList.remove("highlight"));
142
+ }
143
+ componentDidRender() {
144
+ this.positionInput();
145
+ }
146
+ consolidateSelectedTags() {
147
+ this.tagsList.forEach((tag) => {
148
+ if (!this.includesCaseInsensitive(this.optionsList, tag)) {
149
+ this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
150
+ }
151
+ });
152
+ this.optionsList = csvToArray(this.options);
153
+ }
154
+ createPlaceholderDefault(addNew, hasOptions) {
155
+ const addAndSearchPlaceholder = intl.formatMessage({
156
+ id: "tagInput.placeholderAddAndSearch",
157
+ defaultMessage: "Add or search for a tag",
158
+ description: "Placeholder text. Use imperative",
159
+ });
160
+ const searchPlaceholder = intl.formatMessage({
161
+ id: "tagInput.placeholderSearch",
162
+ defaultMessage: "Search and select a tag",
163
+ description: "Placeholder text. Use imperative",
164
+ });
165
+ const addPlaceholder = intl.formatMessage({
166
+ id: "tagInput.placeholderAdd",
167
+ defaultMessage: "Add a new tag",
168
+ description: "Placeholder text. Use imperative",
169
+ });
170
+ let placeholder = "";
171
+ if (addNew && hasOptions) {
172
+ placeholder = addAndSearchPlaceholder;
173
+ }
174
+ else if (!addNew && hasOptions) {
175
+ placeholder = searchPlaceholder;
176
+ }
177
+ else if (addNew) {
178
+ placeholder = addPlaceholder;
179
+ }
180
+ return placeholder;
181
+ }
182
+ reflectSelectedTags(newValue, oldValue) {
183
+ const isAddition = newValue.length > oldValue.length;
184
+ let changedTag = "";
185
+ let selectedTags = this.tagsList;
186
+ if (isAddition) {
187
+ changedTag = newValue.filter((val) => !oldValue.includes(val))[0];
188
+ }
189
+ else {
190
+ changedTag = oldValue.filter((val) => !newValue.includes(val))[0];
191
+ }
192
+ // event emitted by type table uses element references instead of strings
193
+ if (this.tagInputType === "table") {
194
+ changedTag = this.wmRowEls.filter((row) => row.id === changedTag)[0];
195
+ selectedTags = this.tagsList.map((id) => this.el.querySelector(`#${id}`));
196
+ }
197
+ this.selectedTags = this.listToCSV(this.tagsList);
198
+ let detail = { value: selectedTags, tagChanged: changedTag };
199
+ this.wmTagInputChanged.emit(detail);
200
+ }
201
+ handleRowUpdate() {
202
+ forceUpdate(this.el);
203
+ }
204
+ closeIfNotElOrChild(ev) {
205
+ const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
206
+ if (this.tagInputType === "dropdown" && isntElOrChild && this.isExpanded) {
207
+ this.closeDropdown();
208
+ }
209
+ }
210
+ // From wm-button
211
+ // we need to listen for scroll events during the capture phase because they do not bubble up
212
+ // there can be layouts where the main content has 100vh and overflows
213
+ // in these cases window will register no scroll events unless we catch on they way down
214
+ dismissTooltip() {
215
+ if (this.tooltipVisible) {
216
+ hideTooltip();
217
+ this.tooltipVisible = false;
218
+ }
219
+ }
220
+ handleInputKeyDown(ev) {
221
+ if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
222
+ this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
223
+ }
224
+ // prevent keydown triggering on tag area
225
+ ev.stopPropagation();
226
+ switch (ev.key) {
227
+ case "Enter":
228
+ case ",":
229
+ ev.preventDefault();
230
+ this.handleInputEnter();
231
+ break;
232
+ case "ArrowDown":
233
+ ev.preventDefault();
234
+ this.handleInputArrowDown();
235
+ break;
236
+ case "ArrowUp":
237
+ ev.preventDefault();
238
+ this.handleInputArrowUp();
239
+ break;
240
+ case "ArrowLeft":
241
+ ev.preventDefault();
242
+ if (this.tagInputType === "table" && this.tablePosition.row) {
243
+ this.moveLeftCell();
244
+ }
245
+ break;
246
+ case "ArrowRight":
247
+ ev.preventDefault();
248
+ if (this.tagInputType === "table" && this.tablePosition.row) {
249
+ this.moveRightCell();
250
+ }
251
+ break;
252
+ case "Escape":
253
+ if (this.tagInputType === "dropdown" && this.isExpanded) {
254
+ this.closeDropdown();
255
+ }
256
+ break;
257
+ case "ArrowLeft":
258
+ case "Backspace":
259
+ this.handleInputBackspace();
260
+ break;
261
+ }
262
+ }
263
+ handleInputFocus() {
264
+ if (this.tagInputType === "dropdown") {
265
+ this.openDropdown();
266
+ this.clearListItemFocus();
267
+ }
268
+ // force update needed to apply styled state of field-wrapper el
269
+ forceUpdate(this.el);
270
+ }
271
+ handleInputChanged(value) {
272
+ this.charCount = value.length;
273
+ if (this.tagInputType === "dropdown") {
274
+ this.clearListItemFocus();
275
+ if (this.charCount >= this.characterLimit - 5) {
276
+ this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
277
+ }
278
+ if (!this.isExpanded) {
279
+ this.openDropdown();
280
+ }
281
+ }
282
+ else if (this.tagInputType === "table") {
283
+ this.clearCellFocus();
284
+ }
285
+ this.announceExistingOptions();
286
+ }
287
+ handleInputEnter() {
288
+ if (this.tagInputType === "dropdown") {
289
+ if (this.focusedListItem) {
290
+ this.handleListItemClick(this.focusedListItem);
291
+ }
292
+ else {
293
+ this.submitInput(this.addNew, this.inputEl.value.trim());
294
+ }
295
+ }
296
+ else if (this.tagInputType === "table" && this.tablePosition.row > 0) {
297
+ this.handleTableRowClick(this.localRowEls[this.tablePosition.row].id);
298
+ }
299
+ }
300
+ submitInput(canAddNew, value) {
301
+ const hasNonWhiteSpaceCharacters = value.match(/\S/);
302
+ if (canAddNew && hasNonWhiteSpaceCharacters) {
303
+ this.addTag(value);
304
+ this.optionsList = this.addOption(value);
305
+ this.resetInput();
306
+ }
307
+ }
308
+ handleInputArrowDown() {
309
+ if (this.tagInputType === "table") {
310
+ this.moveDownRow();
311
+ }
312
+ else if (this.tagInputType === "dropdown" && this.isExpanded) {
313
+ this.moveDownListItem();
314
+ }
315
+ else if (this.tagInputType === "dropdown") {
316
+ this.openDropdown();
317
+ }
318
+ }
319
+ handleInputArrowUp() {
320
+ if (this.tagInputType === "table") {
321
+ this.moveUpRow();
322
+ }
323
+ else if (this.tagInputType === "dropdown" && this.isExpanded) {
324
+ this.moveUpListItem();
325
+ }
326
+ else if (this.tagInputType === "dropdown") {
327
+ this.openDropdown();
328
+ }
329
+ }
330
+ handleInputBackspace() {
331
+ if (this.inputEl.value === "" && this.tagsList.length > 0) {
332
+ // wait for events to finish firing before redirecting focus
333
+ // prevents double input in input area and tag area
334
+ window.requestAnimationFrame(() => {
335
+ if (this.nonLockedTagsList.length > 0) {
336
+ this.tagAreaEl.focus();
337
+ this.focusTag(this.tagEls[this.tagEls.length - 1]);
338
+ }
339
+ });
340
+ }
341
+ }
342
+ handleListItemKeyDown(ev) {
343
+ const typedEvTarget = ev.target;
344
+ switch (ev.key) {
345
+ case "Enter":
346
+ case " ":
347
+ ev.preventDefault();
348
+ typedEvTarget.click();
349
+ break;
350
+ case "ArrowDown":
351
+ ev.preventDefault();
352
+ this.moveDownListItem();
353
+ break;
354
+ case "ArrowUp":
355
+ ev.preventDefault();
356
+ this.moveUpListItem();
357
+ break;
358
+ case "Escape":
359
+ if (this.focusedElement !== this.inputEl) {
360
+ this.inputEl.focus();
361
+ }
362
+ else if (this.tagInputType === "dropdown") {
363
+ this.closeDropdown();
364
+ }
365
+ break;
366
+ }
367
+ }
368
+ handleListItemClick(item) {
369
+ const tag = item.dataset.option.trim() || "";
370
+ if (this.includesCaseInsensitive(this.tagsList, tag)) {
371
+ this.announce(this.generateTagAlreadyAddedMessage(tag));
372
+ }
373
+ else {
374
+ this.resetInput();
375
+ this.addTag(tag);
376
+ this.optionsList = this.addOption(tag);
377
+ this.focusedListItem = null;
378
+ }
379
+ }
380
+ handleTableRowClick(rowId) {
381
+ const referencedRow = this.el.querySelector(`#${rowId}`);
382
+ const isLocked = referencedRow.locked;
383
+ if (!isLocked) {
384
+ if (this.includesCaseInsensitive(this.tagsList, rowId)) {
385
+ this.removeTag(rowId);
386
+ }
387
+ else if (!this.tagLimitReached) {
388
+ this.addTag(rowId);
389
+ this.resetInput();
390
+ }
391
+ }
392
+ }
393
+ handleTagAreaKeyDown(ev) {
394
+ switch (ev.key) {
395
+ case "ArrowLeft":
396
+ case "ArrowUp":
397
+ ev.preventDefault();
398
+ this.moveLeftTag();
399
+ break;
400
+ case "ArrowRight":
401
+ case "ArrowDown":
402
+ ev.preventDefault();
403
+ this.moveRightTag();
404
+ break;
405
+ case "Backspace":
406
+ case "Delete":
407
+ this.handleTagAreaDelete();
408
+ break;
409
+ }
410
+ }
411
+ handleTagAreaDelete() {
412
+ const isLocked = this.focusedTag && this.focusedTag.classList.contains("locked");
413
+ if (this.focusedTag && this.focusedTag.dataset.tag && !isLocked) {
414
+ this.removeTag(this.focusedTag.dataset.tag);
415
+ if (this.nonLockedTagsList.length === 0) {
416
+ // focus input if no tags are left
417
+ this.inputEl.focus();
418
+ }
419
+ else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
420
+ // reassign focus if removing the last tag but there are still tags remaining
421
+ this.focusedTag = this.tagEls[this.tagEls.length - 2];
422
+ this.focusTag(this.focusedTag);
423
+ }
424
+ }
425
+ }
426
+ handleBlur(ev, component) {
427
+ const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
428
+ this.dismissTooltip();
429
+ this.clearCellFocus();
430
+ if (isntElOrChild) {
431
+ this.fieldWrapperEl.classList.remove("focused");
432
+ if (this.tagInputType === "dropdown") {
433
+ this.closeDropdown();
434
+ }
435
+ }
436
+ }
437
+ handleCellMouseEnter(ev) {
438
+ const cell = ev.target;
439
+ const isTruncated = cell.scrollWidth > cell.clientWidth;
440
+ if (isTruncated) {
441
+ // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
442
+ showTooltip("bottom", cell, cell.innerText);
443
+ this.tooltipVisible = true;
444
+ }
445
+ }
446
+ handleTagAreaFocus() {
447
+ if (this.tagInputType === "dropdown") {
448
+ this.closeDropdown();
449
+ }
450
+ this.focusedTag = this.nonLockedTagEls[0];
451
+ this.focusTag(this.focusedTag);
452
+ }
453
+ handleRemoveButtonClick(tag) {
454
+ this.moveLeftTag();
455
+ this.removeTag(tag);
456
+ }
457
+ moveDownListItem() {
458
+ if (this.listItemEls.length > 0) {
459
+ const firstListItem = this.listItemEls[0];
460
+ if (!this.focusedListItem) {
461
+ this.focusListItem(firstListItem);
462
+ }
463
+ else if (this.focusedListItem.nextElementSibling) {
464
+ this.focusListItem(this.focusedListItem.nextElementSibling);
465
+ }
466
+ else {
467
+ this.focusListItem(firstListItem);
468
+ }
469
+ }
470
+ }
471
+ moveUpListItem() {
472
+ if (this.listItemEls.length > 0) {
473
+ const lastListItem = this.listItemEls[this.listItemEls.length - 1];
474
+ if (!this.focusedListItem) {
475
+ this.focusListItem(lastListItem);
476
+ }
477
+ else if (this.focusedListItem.previousElementSibling) {
478
+ this.focusListItem(this.focusedListItem.previousElementSibling);
479
+ }
480
+ else {
481
+ this.clearListItemFocus();
482
+ }
483
+ }
484
+ }
485
+ moveDownRow() {
486
+ if (this.filteredRows.length > 0) {
487
+ if (this.tablePosition.row === 0) {
488
+ this.tablePosition.row = 1;
489
+ }
490
+ else if (this.tablePosition.row === this.filteredRows.length) {
491
+ this.tablePosition.row = 1;
492
+ }
493
+ else {
494
+ this.tablePosition.row++;
495
+ }
496
+ // skip locked rows
497
+ const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
498
+ if (rowToFocus.locked) {
499
+ this.moveDownRow();
500
+ }
501
+ else {
502
+ this.focusCell(this.tablePosition);
503
+ }
504
+ }
505
+ }
506
+ moveUpRow() {
507
+ if (this.filteredRows.length > 0) {
508
+ if (this.tablePosition.row === 0) {
509
+ this.tablePosition.row = this.filteredRows.length;
510
+ }
511
+ else if (this.tablePosition.row === 1) {
512
+ this.tablePosition.row = 0;
513
+ }
514
+ else {
515
+ this.tablePosition.row--;
516
+ }
517
+ // skip locked rows
518
+ const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
519
+ if (rowToFocus && rowToFocus.locked) {
520
+ this.moveUpRow();
521
+ }
522
+ else if (rowToFocus) {
523
+ this.focusCell(this.tablePosition);
524
+ }
525
+ else {
526
+ this.clearCellFocus();
527
+ }
528
+ }
529
+ }
530
+ moveLeftCell() {
531
+ if (this.tablePosition.column != 1) {
532
+ this.tablePosition.column--;
533
+ this.focusCell(this.tablePosition);
534
+ }
535
+ }
536
+ moveRightCell() {
537
+ const numCols = csvToArray(this.colHeaders).length;
538
+ if (this.tablePosition.column < numCols) {
539
+ this.tablePosition.column++;
540
+ this.focusCell(this.tablePosition);
541
+ }
542
+ }
543
+ moveLeftTag() {
544
+ const lastTag = this.tagEls[this.tagEls.length - 1];
545
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
546
+ this.focusedTag = this.focusedTag.previousElementSibling;
547
+ }
548
+ else {
549
+ this.focusedTag = lastTag;
550
+ }
551
+ // skip locked tags
552
+ if (this.focusedTag.classList.contains("locked") && this.nonLockedTagEls.length > 0) {
553
+ this.moveLeftTag();
554
+ }
555
+ else {
556
+ this.focusTag(this.focusedTag);
557
+ }
558
+ }
559
+ moveRightTag() {
560
+ const firstTag = this.tagEls[0];
561
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
562
+ this.focusedTag = this.focusedTag.nextElementSibling;
563
+ }
564
+ else {
565
+ this.focusedTag = firstTag;
566
+ }
567
+ // skip locked tags
568
+ if (this.focusedTag.classList.contains("locked")) {
569
+ this.moveRightTag();
570
+ }
571
+ else {
572
+ this.focusTag(this.focusedTag);
573
+ }
574
+ }
575
+ addOption(option) {
576
+ let newOptionsList = this.optionsList;
577
+ const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
578
+ if (!optionAlreadyExists) {
579
+ newOptionsList = newOptionsList.concat(option);
580
+ }
581
+ return newOptionsList;
582
+ }
583
+ removeOption(option) {
584
+ this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
585
+ }
586
+ addTag(tag) {
587
+ let newTagsList = this.tagsList;
588
+ const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
589
+ const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
590
+ if (!tagAlreadyAdded) {
591
+ let textToAnnounce = tag;
592
+ if (this.tagInputType === "table") {
593
+ const referencedRow = this.el.querySelector(`#${tag}`);
594
+ textToAnnounce = referencedRow.col1;
595
+ }
596
+ this.announce(this.generateTagAddedMessage(textToAnnounce));
597
+ this.tagsList = newTagsList.concat(tagExistsAsOption || tag);
598
+ // if maxTags has been reached, focus should go to the tagArea
599
+ if (this.tagLimitReached) {
600
+ this.tagAreaEl.focus();
601
+ }
602
+ }
603
+ }
604
+ removeTag(tag) {
605
+ let textToAnnounce = tag;
606
+ if (this.tagInputType === "table") {
607
+ const referencedRow = this.el.querySelector(`#${tag}`);
608
+ textToAnnounce = referencedRow.col1;
609
+ }
610
+ const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: textToAnnounce });
611
+ this.announce(tagRemovedMessage);
612
+ this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
613
+ if (this.tagInputType === "dropdown") {
614
+ // if a tag was introduced by the user, also remove it from the dropdown options
615
+ const devOptionsList = csvToArray(this.options);
616
+ if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
617
+ this.removeOption(tag);
618
+ }
619
+ }
620
+ }
621
+ focusListItem(item) {
622
+ this.focusedListItem = item;
623
+ this.inputEl.setAttribute("aria-activedescendant", this.focusedListItem.id);
624
+ item.scrollIntoView({ block: "nearest" });
625
+ }
626
+ focusTag(element) {
627
+ if (element.classList.contains("locked")) {
628
+ this.focusedTag = null;
629
+ this.tagAreaEl.setAttribute("aria-activedescendant", "");
630
+ }
631
+ else {
632
+ this.focusedTag = element;
633
+ this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
634
+ }
635
+ }
636
+ focusCell(position) {
637
+ this.clearCellFocus(false);
638
+ if (position.row) {
639
+ const rowToFocus = this.localRowEls[position.row];
640
+ const rowCells = rowToFocus.querySelectorAll("td");
641
+ const cellToFocus = rowCells[position.column - 1];
642
+ const isTruncated = cellToFocus.scrollWidth > cellToFocus.clientWidth;
643
+ rowToFocus.classList.add("focused");
644
+ cellToFocus.classList.add("focused");
645
+ cellToFocus.scrollIntoView({ block: "nearest" });
646
+ this.inputEl.setAttribute("aria-activedescendant", cellToFocus.id);
647
+ this.dismissTooltip();
648
+ if (isTruncated) {
649
+ // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
650
+ showTooltip("bottom", cellToFocus, cellToFocus.innerText);
651
+ this.tooltipVisible = true;
652
+ }
653
+ }
654
+ }
655
+ clearTagFocus() {
656
+ this.tagAreaEl.setAttribute("aria-activedescendant", "");
657
+ this.focusedTag = null;
658
+ }
659
+ clearCellFocus(resetPosition = true) {
660
+ this.inputEl.setAttribute("aria-activedescendant", "");
661
+ if (resetPosition) {
662
+ this.tablePosition = { row: 0, column: 1 };
663
+ }
664
+ this.localRowEls.forEach((row) => {
665
+ row.classList.remove("focused");
666
+ row.querySelectorAll("td").forEach((cell) => {
667
+ cell.classList.remove("focused");
668
+ });
669
+ });
670
+ }
671
+ openDropdown() {
672
+ // given an offset of -2px because the dropdown is transformed downwards to avoid overlapping the focus border
673
+ this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight, -2);
674
+ this.isExpanded = true;
675
+ }
676
+ closeDropdown() {
677
+ this.clearListItemFocus();
678
+ this.isExpanded = false;
679
+ }
680
+ clearListItemFocus() {
681
+ this.focusedListItem = null;
682
+ this.inputEl.setAttribute("aria-activedescendant", "");
683
+ this.listItemEls.forEach((el) => {
684
+ el.classList.remove("focused");
685
+ });
686
+ }
687
+ resetInput() {
688
+ this.charCount = 0;
689
+ this.inputEl.value = "";
690
+ }
691
+ announce(message) {
692
+ // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
693
+ if (this.liveRegionEl.textContent === message) {
694
+ message += "\u00A0";
695
+ }
696
+ this.liveRegionMessage = message;
697
+ }
698
+ announceExistingOptions() {
699
+ // request animation frame to wait for re-rendering of filtered options
700
+ window.requestAnimationFrame(() => {
701
+ let numResults = 0;
702
+ if (this.tagInputType === "dropdown") {
703
+ numResults = this.optionEls.length;
704
+ }
705
+ else if (this.tagInputType === "table") {
706
+ numResults = this.filteredRows.length;
707
+ }
708
+ const existingOptionsMessage = intl.formatMessage({
709
+ id: "tagInput.existingOptions",
710
+ defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
711
+ }, { num: numResults });
712
+ if (numResults > 0) {
713
+ this.announce(existingOptionsMessage);
714
+ }
715
+ });
716
+ }
717
+ announceCharacterLimitWarning(charCount, charLimit) {
718
+ const charactersEnteredMessage = intl.formatMessage({
719
+ id: "global.charactersEntered",
720
+ defaultMessage: "{x, number} of {y, number} characters entered.",
721
+ description: "for screen readers",
722
+ }, { x: charCount, y: charLimit });
723
+ const characterLimitReachedMessage = intl.formatMessage({
724
+ id: "global.characterLimitReached",
725
+ defaultMessage: "No additional characters will be entered.",
726
+ description: "for screen readers",
727
+ });
728
+ this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
729
+ }
730
+ positionInput() {
731
+ const lastTag = this.tagEls[this.tagEls.length - 1];
732
+ // default placement to fall back to when no tags are present, or not enough space is available
733
+ this.inputEl.style.position = "static";
734
+ this.inputEl.style.width = "100%";
735
+ if (lastTag) {
736
+ const spaceAvailable = this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right;
737
+ // 150px is the minimum width of the input field
738
+ if (spaceAvailable >= 150) {
739
+ // because the input has right: 0px
740
+ // all thats needed to properly place it is setting position: absolute, top, and width
741
+ this.inputEl.style.position = "absolute";
742
+ this.inputEl.style.top = lastTag.offsetTop.toString() + "px";
743
+ this.inputEl.style.width =
744
+ (this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right - 8).toString() + "px";
745
+ }
746
+ }
747
+ }
748
+ /// Helpers
749
+ listToCSV(list) {
750
+ return list.join(",");
751
+ }
752
+ includesCaseInsensitive(list, element) {
753
+ const lowercaseList = list.map((str) => str.toLowerCase());
754
+ return lowercaseList.includes(element.toLowerCase());
755
+ }
756
+ filterCaseInsensitive(list, element) {
757
+ return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
758
+ }
759
+ sortCaseInsensitive(list) {
760
+ // The vanilla .sort method places words that start with capital letters above others (ASCII order)
761
+ // so we need to pass in our own compare function to sort case-insensitive
762
+ return list.sort((a, b) => {
763
+ a = a.toLowerCase();
764
+ b = b.toLowerCase();
765
+ return a > b ? 1 : a < b ? -1 : 0;
766
+ });
767
+ }
768
+ /// Renders
769
+ renderTags() {
770
+ let lockedTags = [];
771
+ let unlockedTags = [];
772
+ this.tagsList.forEach((tag, idx) => {
773
+ const id = `tag${idx + 1}`;
774
+ let tagText = "";
775
+ let isLocked = false;
776
+ if (this.tagInputType === "dropdown") {
777
+ tagText = tag;
778
+ }
779
+ else if (this.tagInputType === "table") {
780
+ // display table tags using col1 of the row with the same id
781
+ // if one can't be found, display as empty
782
+ const referencedRow = this.el.querySelector(`#${tag}`);
783
+ tagText = referencedRow ? referencedRow.col1 : "";
784
+ isLocked = referencedRow ? referencedRow.locked : false;
785
+ }
786
+ // make sure locked tags always appear in front of list
787
+ const targetList = isLocked ? lockedTags : unlockedTags;
788
+ targetList.push(h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""} ${isLocked ? "locked" : ""}`, "data-tag": tag, role: "option" }, tagText, isLocked ? (h("div", { class: "icon lock" })) : (h("button", { class: "icon remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) }))));
789
+ });
790
+ return [...lockedTags, ...unlockedTags];
791
+ }
792
+ renderDropdown() {
793
+ return (h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, ref: (el) => (this.dropdownEl = el) }, h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()), h("ul", { class: "dropdown", id: "dropdown", role: "listbox", "aria-multiselectable": "true", "aria-expanded": this.isExpanded ? "true" : false, "aria-label": this.label, tabindex: -1 }, this.inputEl && this.renderAddNewButton(), this.renderListItems(this.optionsList))));
794
+ }
795
+ renderListItems(optionsList) {
796
+ optionsList = this.sortCaseInsensitive(optionsList);
797
+ // filter by input
798
+ if (this.inputEl && this.inputEl.value) {
799
+ optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
800
+ }
801
+ return optionsList.map((option, idx) => {
802
+ const id = `option${idx + 1}`;
803
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
804
+ const isSelected = this.includesCaseInsensitive(this.tagsList, option);
805
+ return (h("li", { class: `option ${isFocused ? "focused" : ""}`, role: "option", id: id, "data-option": option, "aria-selected": isSelected ? "true" : "false", "aria-disabled": isSelected ? "true" : "false", onKeyDown: (ev) => this.handleListItemKeyDown(ev), onBlur: (ev) => this.handleBlur(ev, this.el), onClick: (ev) => this.handleListItemClick(ev.target) }, option));
806
+ });
807
+ }
808
+ renderAddNewButton() {
809
+ const hasNonWhiteSpaceCharacters = this.inputEl.value.match(/\S/);
810
+ const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, this.inputEl.value.trim());
811
+ if (this.addNew && hasNonWhiteSpaceCharacters && !optionAlreadyExists) {
812
+ const id = `add-new-btn`;
813
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
814
+ return (h("li", { role: "option", class: `add-new-btn ${isFocused ? "focused" : ""}`, id: id, "data-option": this.inputEl.value, onKeyDown: (ev) => this.handleListItemKeyDown(ev), onBlur: (ev) => this.handleBlur(ev, this.el), onClick: (ev) => this.handleListItemClick(ev.target), tabIndex: isFocused ? 0 : -1 }, `Add "${this.inputEl.value.trim()}"`));
815
+ }
816
+ else
817
+ return "";
818
+ }
819
+ renderHelpText() {
820
+ const helpTextHasOptions = intl.formatMessage({
821
+ id: "tagInput.helpTextCanSelect",
822
+ defaultMessage: "Search and select a tag.",
823
+ description: "Placeholder text. Use imperative",
824
+ });
825
+ const helpTextEditable = intl.formatMessage({
826
+ id: "tagInput.helpTextEditable",
827
+ defaultMessage: "Press the Enter or Comma key to add a new tag.",
828
+ description: "Placeholder text. Use imperative",
829
+ });
830
+ let helpText = "";
831
+ if (this.optionsList.length > 0) {
832
+ helpText += helpTextHasOptions;
833
+ }
834
+ if (this.addNew) {
835
+ helpText += " " + helpTextEditable;
836
+ }
837
+ return helpText;
838
+ }
839
+ renderTagCounter() {
840
+ if (this.maxTags) {
841
+ return (h("div", { class: "lower-row" }, h("div", { id: "max-tags" }, this.generateTagCounterMessage(this.tagsList.length, this.maxTags), this.tagLimitReached && ` - ${this.maxTagsReachedMessage}`)));
842
+ }
843
+ }
844
+ renderTable() {
845
+ return (h("div", { class: "table-wrapper", onScroll: () => this.dismissTooltip() }, h("table", { id: "table", role: "grid", class: `${this.colWidths ? "fixed-widths" : ""}`, "aria-label": this.label, "aria-multiselectable": "true" }, this.renderTableHeaders(), this.filteredRows.length ? this.renderTableRows() : h("div", { class: "no-results" }, this.noResultsMessage))));
846
+ }
847
+ renderTableHeaders() {
848
+ return (h("tr", { class: "headers", role: "row" }, csvToArray(this.colHeaders).map((header, idx) => {
849
+ let overflowRule = "wrap";
850
+ if (this.colWrap && csvToArray(this.colWrap)[idx]) {
851
+ overflowRule = csvToArray(this.colWrap)[idx];
852
+ }
853
+ return (h("th", { class: `header-cell ${overflowRule}`, role: "columnheader",
854
+ // @ts-ignore
855
+ width: this.colWidths ? csvToArray(this.colWidths)[idx] : "" }, header));
856
+ })));
857
+ }
858
+ renderTableRows() {
859
+ return this.filteredRows.map((row) => {
860
+ const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
861
+ return (h("tr", { id: row.id, class: `${row.locked ? "locked" : ""} ${isSelected ? "selected" : ""}`, role: "row", onClick: () => this.handleTableRowClick(row.id) }, this.renderTableCells(row)));
862
+ });
863
+ }
864
+ renderTableCells(row) {
865
+ const colValues = [row.col1, row.col2, row.col3, row.col4].filter((val) => !!val);
866
+ const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
867
+ return colValues.map((val, idx) => {
868
+ const localId = `${row.id}-col${idx + 1}`;
869
+ let overflowRule = "wrap";
870
+ if (this.colWrap && csvToArray(this.colWrap)[idx]) {
871
+ overflowRule = csvToArray(this.colWrap)[idx];
872
+ }
873
+ return (h("td", { id: localId, role: "gridcell", class: overflowRule, "aria-describedby": `${localId}-description`, "aria-selected": isSelected.toString(), onMouseEnter: (ev) => this.handleCellMouseEnter(ev), onMouseLeave: () => this.dismissTooltip() }, val, h("div", { class: "description", id: `${localId}-description` }, row.locked ? "locked" : "")));
874
+ });
875
+ }
876
+ render() {
877
+ return (h(Host, { id: this.uid }, h("div", { class: `wrapper label-${this.labelPosition}` }, h("div", { class: "label-wrapper" }, h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)), h("div", { class: `field-wrapper ${this.focusedElement ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) }, h("div", { class: "upper-row" }, h("div", { class: "tags-and-input-wrapper" }, h("ul", { ref: (el) => (this.tagAreaEl = el), class: "tag-area", role: "listbox", "aria-activedescendant": "", "aria-orientation": "horizontal", "aria-label": `${this.label} ${this.tagsList.length > 0 ? this.tagAreaInstructions : ""}`, tabindex: this.nonLockedTagsList.length > 0 ? 0 : -1, "aria-describedby": `info max-tags`, onFocus: () => this.handleTagAreaFocus(), onBlur: (ev) => {
878
+ this.clearTagFocus();
879
+ this.handleBlur(ev, this.el);
880
+ }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) }, this.renderTags()), h("input", { id: `input${this.uid}`, class: this.tagLimitReached ? "hidden" : "", role: "combobox", ref: (el) => (this.inputEl = el), autocomplete: "off", "aria-controls": this.tagInputType, "aria-describedby": "help-text", "aria-label": `${this.label} ${this.generateCharacterLimitLabel(this.characterLimit)}`, "aria-expanded": this.tagInputType === "dropdown" ? this.isExpanded.toString() : null, placeholder: this.placeholder, maxLength: this.tagInputType === "dropdown" ? this.characterLimit : undefined, onInput: () => this.handleInputChanged(this.inputEl.value), onBlur: (ev) => {
881
+ this.handleBlur(ev, this.el);
882
+ }, onFocus: () => this.handleInputFocus(), onKeyDown: (ev) => this.handleInputKeyDown(ev) })), this.tagInputType === "dropdown" && (h("div", { class: "character-count" }, this.charCount, "/", this.characterLimit))), this.renderTagCounter(), this.tagInputType === "dropdown" && this.renderDropdown()), this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""), h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage), this.tagInputType === "table" && this.renderTable())));
883
+ }
884
+ get el() { return getElement(this); }
885
+ static get watchers() { return {
886
+ "tagsList": ["reflectSelectedTags"]
887
+ }; }
888
+ };
889
889
  TagInput.style = wmTagInputCss;
890
890
 
891
891
  export { TagInput as wm_tag_input };