@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,1201 +1,1201 @@
1
- import { h, Component, Host, Element, Prop, Listen, State, Event, Watch, forceUpdate, } from "@stencil/core";
2
- import { csvToArray, generateId, shouldOpenUp, intl, debounce, showTooltip, hideTooltip } from "../../global/functions";
3
- export class TagInput {
4
- constructor() {
5
- this.labelPosition = "top";
6
- this.options = ""; // csv
7
- this.selectedTags = ""; // csv
8
- this.addNew = true;
9
- this.characterLimit = 50;
10
- this.tagInputType = "dropdown";
11
- this.uid = this.el.id ? this.el.id : generateId();
12
- this.openUp = false;
13
- this.tooltipVisible = false;
14
- this.tablePosition = { row: 0, column: 1 };
15
- this.isExpanded = false;
16
- this.tagsList = csvToArray(this.selectedTags);
17
- this.optionsList = csvToArray(this.options);
18
- this.charCount = 0;
19
- this.liveRegionMessage = "";
20
- this.tagAreaInstructions = intl.formatMessage({
21
- id: "tagInput.tagAreaInstructions",
22
- defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
23
- });
24
- this.maxTagsReachedMessage = intl.formatMessage({
25
- id: "tagInput.maxTagsReached",
26
- defaultMessage: "No more tags can be added because the limit has been reached.",
27
- });
28
- this.debouncedUpdate = debounce(() => forceUpdate(this.el), 30);
29
- }
30
- get focusedElement() {
31
- return this.el.shadowRoot.activeElement;
32
- }
33
- get listItemEls() {
34
- return Array.from(this.dropdownEl.querySelectorAll("li"));
35
- }
36
- get tagEls() {
37
- return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
38
- }
39
- get nonLockedTagEls() {
40
- return this.tagEls.filter((tag) => !tag.classList.contains("locked"));
41
- }
42
- get optionEls() {
43
- return Array.from(this.dropdownEl.querySelectorAll(".option"));
44
- }
45
- get wmRowEls() {
46
- return Array.from(this.el.querySelectorAll("wm-tag-input-row"));
47
- }
48
- get localRowEls() {
49
- return Array.from(this.el.shadowRoot.querySelectorAll("tr"));
50
- }
51
- get filteredRows() {
52
- return this.wmRowEls.filter((row) => {
53
- const colValues = [row.col1, row.col2, row.col3, row.col4].join("").toLowerCase();
54
- return this.inputEl && this.inputEl.value ? colValues.includes(this.inputEl.value.toLowerCase()) : true;
55
- });
56
- }
57
- get nonLockedTagsList() {
58
- let list = [];
59
- if (this.tagInputType === "table") {
60
- this.tagsList.forEach((id) => {
61
- const correspondingRowEl = this.wmRowEls.filter((row) => id === row.id)[0];
62
- if (!correspondingRowEl.locked) {
63
- list.push(id);
64
- }
65
- });
66
- }
67
- else if (this.tagInputType === "dropdown") {
68
- list = this.tagsList;
69
- }
70
- return list;
71
- }
72
- get tagLimitReached() {
73
- return !!(this.maxTags && this.tagsList.length >= this.maxTags);
74
- }
75
- get noResultsMessage() {
76
- return intl.formatMessage({
77
- id: "tagInput.noResults",
78
- defaultMessage: "No results match your search.",
79
- description: "Message displayed when a user's search returns empty.",
80
- });
81
- }
82
- generateTagAddedMessage(tag) {
83
- return intl.formatMessage({
84
- id: "tagInput.tagAdded",
85
- defaultMessage: "{tagName} added.",
86
- description: "A confirmation for adding a tag.",
87
- }, { tagName: tag });
88
- }
89
- generateTagAlreadyAddedMessage(tag) {
90
- return intl.formatMessage({
91
- id: "tagInput.tagAlreadyAdded",
92
- defaultMessage: "{tagName} has already been added.",
93
- description: "An alert for adding a tag that is already present.",
94
- }, { tagName: tag });
95
- }
96
- generateTagCounterMessage(x, y) {
97
- return intl.formatMessage({
98
- id: "tagInput.tagsAddedCounter",
99
- defaultMessage: "Tags added: {x, number}/{y, number}",
100
- description: "For the user to understand how close they are to the tag limit.",
101
- }, {
102
- x: x,
103
- y: y,
104
- });
105
- }
106
- generateCharacterLimitLabel(characterLimit) {
107
- return intl.formatMessage({
108
- id: "global.characterLimit",
109
- defaultMessage: "{limit, number} characters allowed.",
110
- description: "for screen readers",
111
- }, { limit: characterLimit });
112
- }
113
- componentWillLoad() {
114
- if (!this.placeholder) {
115
- this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
116
- }
117
- if (!this.label) {
118
- console.error("wm-tag-input must have a label property");
119
- }
120
- this.el.focus = function () {
121
- // if present, send focus to the selected tags list
122
- if (this.selectedTags) {
123
- this.shadowRoot.querySelector("ul.tag-area").focus();
124
- }
125
- else {
126
- this.shadowRoot.querySelector("input").focus();
127
- }
128
- };
129
- this.consolidateSelectedTags();
130
- // on resize of component, trigger componentDidRender -> positionInput
131
- const resizeObserver = new ResizeObserver(() => this.debouncedUpdate());
132
- resizeObserver.observe(this.el);
133
- }
134
- componentDidLoad() {
135
- // prevent highlighting of pre-selected tags
136
- this.tagEls.forEach((el) => el.classList.remove("highlight"));
137
- }
138
- componentDidRender() {
139
- this.positionInput();
140
- }
141
- consolidateSelectedTags() {
142
- this.tagsList.forEach((tag) => {
143
- if (!this.includesCaseInsensitive(this.optionsList, tag)) {
144
- this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
145
- }
146
- });
147
- this.optionsList = csvToArray(this.options);
148
- }
149
- createPlaceholderDefault(addNew, hasOptions) {
150
- const addAndSearchPlaceholder = intl.formatMessage({
151
- id: "tagInput.placeholderAddAndSearch",
152
- defaultMessage: "Add or search for a tag",
153
- description: "Placeholder text. Use imperative",
154
- });
155
- const searchPlaceholder = intl.formatMessage({
156
- id: "tagInput.placeholderSearch",
157
- defaultMessage: "Search and select a tag",
158
- description: "Placeholder text. Use imperative",
159
- });
160
- const addPlaceholder = intl.formatMessage({
161
- id: "tagInput.placeholderAdd",
162
- defaultMessage: "Add a new tag",
163
- description: "Placeholder text. Use imperative",
164
- });
165
- let placeholder = "";
166
- if (addNew && hasOptions) {
167
- placeholder = addAndSearchPlaceholder;
168
- }
169
- else if (!addNew && hasOptions) {
170
- placeholder = searchPlaceholder;
171
- }
172
- else if (addNew) {
173
- placeholder = addPlaceholder;
174
- }
175
- return placeholder;
176
- }
177
- reflectSelectedTags(newValue, oldValue) {
178
- const isAddition = newValue.length > oldValue.length;
179
- let changedTag = "";
180
- let selectedTags = this.tagsList;
181
- if (isAddition) {
182
- changedTag = newValue.filter((val) => !oldValue.includes(val))[0];
183
- }
184
- else {
185
- changedTag = oldValue.filter((val) => !newValue.includes(val))[0];
186
- }
187
- // event emitted by type table uses element references instead of strings
188
- if (this.tagInputType === "table") {
189
- changedTag = this.wmRowEls.filter((row) => row.id === changedTag)[0];
190
- selectedTags = this.tagsList.map((id) => this.el.querySelector(`#${id}`));
191
- }
192
- this.selectedTags = this.listToCSV(this.tagsList);
193
- let detail = { value: selectedTags, tagChanged: changedTag };
194
- this.wmTagInputChanged.emit(detail);
195
- }
196
- handleRowUpdate() {
197
- forceUpdate(this.el);
198
- }
199
- closeIfNotElOrChild(ev) {
200
- const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
201
- if (this.tagInputType === "dropdown" && isntElOrChild && this.isExpanded) {
202
- this.closeDropdown();
203
- }
204
- }
205
- // From wm-button
206
- // we need to listen for scroll events during the capture phase because they do not bubble up
207
- // there can be layouts where the main content has 100vh and overflows
208
- // in these cases window will register no scroll events unless we catch on they way down
209
- dismissTooltip() {
210
- if (this.tooltipVisible) {
211
- hideTooltip();
212
- this.tooltipVisible = false;
213
- }
214
- }
215
- handleInputKeyDown(ev) {
216
- if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
217
- this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
218
- }
219
- // prevent keydown triggering on tag area
220
- ev.stopPropagation();
221
- switch (ev.key) {
222
- case "Enter":
223
- case ",":
224
- ev.preventDefault();
225
- this.handleInputEnter();
226
- break;
227
- case "ArrowDown":
228
- ev.preventDefault();
229
- this.handleInputArrowDown();
230
- break;
231
- case "ArrowUp":
232
- ev.preventDefault();
233
- this.handleInputArrowUp();
234
- break;
235
- case "ArrowLeft":
236
- ev.preventDefault();
237
- if (this.tagInputType === "table" && this.tablePosition.row) {
238
- this.moveLeftCell();
239
- }
240
- break;
241
- case "ArrowRight":
242
- ev.preventDefault();
243
- if (this.tagInputType === "table" && this.tablePosition.row) {
244
- this.moveRightCell();
245
- }
246
- break;
247
- case "Escape":
248
- if (this.tagInputType === "dropdown" && this.isExpanded) {
249
- this.closeDropdown();
250
- }
251
- break;
252
- case "ArrowLeft":
253
- case "Backspace":
254
- this.handleInputBackspace();
255
- break;
256
- }
257
- }
258
- handleInputFocus() {
259
- if (this.tagInputType === "dropdown") {
260
- this.openDropdown();
261
- this.clearListItemFocus();
262
- }
263
- // force update needed to apply styled state of field-wrapper el
264
- forceUpdate(this.el);
265
- }
266
- handleInputChanged(value) {
267
- this.charCount = value.length;
268
- if (this.tagInputType === "dropdown") {
269
- this.clearListItemFocus();
270
- if (this.charCount >= this.characterLimit - 5) {
271
- this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
272
- }
273
- if (!this.isExpanded) {
274
- this.openDropdown();
275
- }
276
- }
277
- else if (this.tagInputType === "table") {
278
- this.clearCellFocus();
279
- }
280
- this.announceExistingOptions();
281
- }
282
- handleInputEnter() {
283
- if (this.tagInputType === "dropdown") {
284
- if (this.focusedListItem) {
285
- this.handleListItemClick(this.focusedListItem);
286
- }
287
- else {
288
- this.submitInput(this.addNew, this.inputEl.value.trim());
289
- }
290
- }
291
- else if (this.tagInputType === "table" && this.tablePosition.row > 0) {
292
- this.handleTableRowClick(this.localRowEls[this.tablePosition.row].id);
293
- }
294
- }
295
- submitInput(canAddNew, value) {
296
- const hasNonWhiteSpaceCharacters = value.match(/\S/);
297
- if (canAddNew && hasNonWhiteSpaceCharacters) {
298
- this.addTag(value);
299
- this.optionsList = this.addOption(value);
300
- this.resetInput();
301
- }
302
- }
303
- handleInputArrowDown() {
304
- if (this.tagInputType === "table") {
305
- this.moveDownRow();
306
- }
307
- else if (this.tagInputType === "dropdown" && this.isExpanded) {
308
- this.moveDownListItem();
309
- }
310
- else if (this.tagInputType === "dropdown") {
311
- this.openDropdown();
312
- }
313
- }
314
- handleInputArrowUp() {
315
- if (this.tagInputType === "table") {
316
- this.moveUpRow();
317
- }
318
- else if (this.tagInputType === "dropdown" && this.isExpanded) {
319
- this.moveUpListItem();
320
- }
321
- else if (this.tagInputType === "dropdown") {
322
- this.openDropdown();
323
- }
324
- }
325
- handleInputBackspace() {
326
- if (this.inputEl.value === "" && this.tagsList.length > 0) {
327
- // wait for events to finish firing before redirecting focus
328
- // prevents double input in input area and tag area
329
- window.requestAnimationFrame(() => {
330
- if (this.nonLockedTagsList.length > 0) {
331
- this.tagAreaEl.focus();
332
- this.focusTag(this.tagEls[this.tagEls.length - 1]);
333
- }
334
- });
335
- }
336
- }
337
- handleListItemKeyDown(ev) {
338
- const typedEvTarget = ev.target;
339
- switch (ev.key) {
340
- case "Enter":
341
- case " ":
342
- ev.preventDefault();
343
- typedEvTarget.click();
344
- break;
345
- case "ArrowDown":
346
- ev.preventDefault();
347
- this.moveDownListItem();
348
- break;
349
- case "ArrowUp":
350
- ev.preventDefault();
351
- this.moveUpListItem();
352
- break;
353
- case "Escape":
354
- if (this.focusedElement !== this.inputEl) {
355
- this.inputEl.focus();
356
- }
357
- else if (this.tagInputType === "dropdown") {
358
- this.closeDropdown();
359
- }
360
- break;
361
- }
362
- }
363
- handleListItemClick(item) {
364
- const tag = item.dataset.option.trim() || "";
365
- if (this.includesCaseInsensitive(this.tagsList, tag)) {
366
- this.announce(this.generateTagAlreadyAddedMessage(tag));
367
- }
368
- else {
369
- this.resetInput();
370
- this.addTag(tag);
371
- this.optionsList = this.addOption(tag);
372
- this.focusedListItem = null;
373
- }
374
- }
375
- handleTableRowClick(rowId) {
376
- const referencedRow = this.el.querySelector(`#${rowId}`);
377
- const isLocked = referencedRow.locked;
378
- if (!isLocked) {
379
- if (this.includesCaseInsensitive(this.tagsList, rowId)) {
380
- this.removeTag(rowId);
381
- }
382
- else if (!this.tagLimitReached) {
383
- this.addTag(rowId);
384
- this.resetInput();
385
- }
386
- }
387
- }
388
- handleTagAreaKeyDown(ev) {
389
- switch (ev.key) {
390
- case "ArrowLeft":
391
- case "ArrowUp":
392
- ev.preventDefault();
393
- this.moveLeftTag();
394
- break;
395
- case "ArrowRight":
396
- case "ArrowDown":
397
- ev.preventDefault();
398
- this.moveRightTag();
399
- break;
400
- case "Backspace":
401
- case "Delete":
402
- this.handleTagAreaDelete();
403
- break;
404
- }
405
- }
406
- handleTagAreaDelete() {
407
- const isLocked = this.focusedTag && this.focusedTag.classList.contains("locked");
408
- if (this.focusedTag && this.focusedTag.dataset.tag && !isLocked) {
409
- this.removeTag(this.focusedTag.dataset.tag);
410
- if (this.nonLockedTagsList.length === 0) {
411
- // focus input if no tags are left
412
- this.inputEl.focus();
413
- }
414
- else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
415
- // reassign focus if removing the last tag but there are still tags remaining
416
- this.focusedTag = this.tagEls[this.tagEls.length - 2];
417
- this.focusTag(this.focusedTag);
418
- }
419
- }
420
- }
421
- handleBlur(ev, component) {
422
- const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
423
- this.dismissTooltip();
424
- this.clearCellFocus();
425
- if (isntElOrChild) {
426
- this.fieldWrapperEl.classList.remove("focused");
427
- if (this.tagInputType === "dropdown") {
428
- this.closeDropdown();
429
- }
430
- }
431
- }
432
- handleCellMouseEnter(ev) {
433
- const cell = ev.target;
434
- const isTruncated = cell.scrollWidth > cell.clientWidth;
435
- if (isTruncated) {
436
- // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
437
- showTooltip("bottom", cell, cell.innerText);
438
- this.tooltipVisible = true;
439
- }
440
- }
441
- handleTagAreaFocus() {
442
- if (this.tagInputType === "dropdown") {
443
- this.closeDropdown();
444
- }
445
- this.focusedTag = this.nonLockedTagEls[0];
446
- this.focusTag(this.focusedTag);
447
- }
448
- handleRemoveButtonClick(tag) {
449
- this.moveLeftTag();
450
- this.removeTag(tag);
451
- }
452
- moveDownListItem() {
453
- if (this.listItemEls.length > 0) {
454
- const firstListItem = this.listItemEls[0];
455
- if (!this.focusedListItem) {
456
- this.focusListItem(firstListItem);
457
- }
458
- else if (this.focusedListItem.nextElementSibling) {
459
- this.focusListItem(this.focusedListItem.nextElementSibling);
460
- }
461
- else {
462
- this.focusListItem(firstListItem);
463
- }
464
- }
465
- }
466
- moveUpListItem() {
467
- if (this.listItemEls.length > 0) {
468
- const lastListItem = this.listItemEls[this.listItemEls.length - 1];
469
- if (!this.focusedListItem) {
470
- this.focusListItem(lastListItem);
471
- }
472
- else if (this.focusedListItem.previousElementSibling) {
473
- this.focusListItem(this.focusedListItem.previousElementSibling);
474
- }
475
- else {
476
- this.clearListItemFocus();
477
- }
478
- }
479
- }
480
- moveDownRow() {
481
- if (this.filteredRows.length > 0) {
482
- if (this.tablePosition.row === 0) {
483
- this.tablePosition.row = 1;
484
- }
485
- else if (this.tablePosition.row === this.filteredRows.length) {
486
- this.tablePosition.row = 1;
487
- }
488
- else {
489
- this.tablePosition.row++;
490
- }
491
- // skip locked rows
492
- const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
493
- if (rowToFocus.locked) {
494
- this.moveDownRow();
495
- }
496
- else {
497
- this.focusCell(this.tablePosition);
498
- }
499
- }
500
- }
501
- moveUpRow() {
502
- if (this.filteredRows.length > 0) {
503
- if (this.tablePosition.row === 0) {
504
- this.tablePosition.row = this.filteredRows.length;
505
- }
506
- else if (this.tablePosition.row === 1) {
507
- this.tablePosition.row = 0;
508
- }
509
- else {
510
- this.tablePosition.row--;
511
- }
512
- // skip locked rows
513
- const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
514
- if (rowToFocus && rowToFocus.locked) {
515
- this.moveUpRow();
516
- }
517
- else if (rowToFocus) {
518
- this.focusCell(this.tablePosition);
519
- }
520
- else {
521
- this.clearCellFocus();
522
- }
523
- }
524
- }
525
- moveLeftCell() {
526
- if (this.tablePosition.column != 1) {
527
- this.tablePosition.column--;
528
- this.focusCell(this.tablePosition);
529
- }
530
- }
531
- moveRightCell() {
532
- const numCols = csvToArray(this.colHeaders).length;
533
- if (this.tablePosition.column < numCols) {
534
- this.tablePosition.column++;
535
- this.focusCell(this.tablePosition);
536
- }
537
- }
538
- moveLeftTag() {
539
- const lastTag = this.tagEls[this.tagEls.length - 1];
540
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
541
- this.focusedTag = this.focusedTag.previousElementSibling;
542
- }
543
- else {
544
- this.focusedTag = lastTag;
545
- }
546
- // skip locked tags
547
- if (this.focusedTag.classList.contains("locked") && this.nonLockedTagEls.length > 0) {
548
- this.moveLeftTag();
549
- }
550
- else {
551
- this.focusTag(this.focusedTag);
552
- }
553
- }
554
- moveRightTag() {
555
- const firstTag = this.tagEls[0];
556
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
557
- this.focusedTag = this.focusedTag.nextElementSibling;
558
- }
559
- else {
560
- this.focusedTag = firstTag;
561
- }
562
- // skip locked tags
563
- if (this.focusedTag.classList.contains("locked")) {
564
- this.moveRightTag();
565
- }
566
- else {
567
- this.focusTag(this.focusedTag);
568
- }
569
- }
570
- addOption(option) {
571
- let newOptionsList = this.optionsList;
572
- const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
573
- if (!optionAlreadyExists) {
574
- newOptionsList = newOptionsList.concat(option);
575
- }
576
- return newOptionsList;
577
- }
578
- removeOption(option) {
579
- this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
580
- }
581
- addTag(tag) {
582
- let newTagsList = this.tagsList;
583
- const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
584
- const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
585
- if (!tagAlreadyAdded) {
586
- let textToAnnounce = tag;
587
- if (this.tagInputType === "table") {
588
- const referencedRow = this.el.querySelector(`#${tag}`);
589
- textToAnnounce = referencedRow.col1;
590
- }
591
- this.announce(this.generateTagAddedMessage(textToAnnounce));
592
- this.tagsList = newTagsList.concat(tagExistsAsOption || tag);
593
- // if maxTags has been reached, focus should go to the tagArea
594
- if (this.tagLimitReached) {
595
- this.tagAreaEl.focus();
596
- }
597
- }
598
- }
599
- removeTag(tag) {
600
- let textToAnnounce = tag;
601
- if (this.tagInputType === "table") {
602
- const referencedRow = this.el.querySelector(`#${tag}`);
603
- textToAnnounce = referencedRow.col1;
604
- }
605
- const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: textToAnnounce });
606
- this.announce(tagRemovedMessage);
607
- this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
608
- if (this.tagInputType === "dropdown") {
609
- // if a tag was introduced by the user, also remove it from the dropdown options
610
- const devOptionsList = csvToArray(this.options);
611
- if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
612
- this.removeOption(tag);
613
- }
614
- }
615
- }
616
- focusListItem(item) {
617
- this.focusedListItem = item;
618
- this.inputEl.setAttribute("aria-activedescendant", this.focusedListItem.id);
619
- item.scrollIntoView({ block: "nearest" });
620
- }
621
- focusTag(element) {
622
- if (element.classList.contains("locked")) {
623
- this.focusedTag = null;
624
- this.tagAreaEl.setAttribute("aria-activedescendant", "");
625
- }
626
- else {
627
- this.focusedTag = element;
628
- this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
629
- }
630
- }
631
- focusCell(position) {
632
- this.clearCellFocus(false);
633
- if (position.row) {
634
- const rowToFocus = this.localRowEls[position.row];
635
- const rowCells = rowToFocus.querySelectorAll("td");
636
- const cellToFocus = rowCells[position.column - 1];
637
- const isTruncated = cellToFocus.scrollWidth > cellToFocus.clientWidth;
638
- rowToFocus.classList.add("focused");
639
- cellToFocus.classList.add("focused");
640
- cellToFocus.scrollIntoView({ block: "nearest" });
641
- this.inputEl.setAttribute("aria-activedescendant", cellToFocus.id);
642
- this.dismissTooltip();
643
- if (isTruncated) {
644
- // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
645
- showTooltip("bottom", cellToFocus, cellToFocus.innerText);
646
- this.tooltipVisible = true;
647
- }
648
- }
649
- }
650
- clearTagFocus() {
651
- this.tagAreaEl.setAttribute("aria-activedescendant", "");
652
- this.focusedTag = null;
653
- }
654
- clearCellFocus(resetPosition = true) {
655
- this.inputEl.setAttribute("aria-activedescendant", "");
656
- if (resetPosition) {
657
- this.tablePosition = { row: 0, column: 1 };
658
- }
659
- this.localRowEls.forEach((row) => {
660
- row.classList.remove("focused");
661
- row.querySelectorAll("td").forEach((cell) => {
662
- cell.classList.remove("focused");
663
- });
664
- });
665
- }
666
- openDropdown() {
667
- // given an offset of -2px because the dropdown is transformed downwards to avoid overlapping the focus border
668
- this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight, -2);
669
- this.isExpanded = true;
670
- }
671
- closeDropdown() {
672
- this.clearListItemFocus();
673
- this.isExpanded = false;
674
- }
675
- clearListItemFocus() {
676
- this.focusedListItem = null;
677
- this.inputEl.setAttribute("aria-activedescendant", "");
678
- this.listItemEls.forEach((el) => {
679
- el.classList.remove("focused");
680
- });
681
- }
682
- resetInput() {
683
- this.charCount = 0;
684
- this.inputEl.value = "";
685
- }
686
- announce(message) {
687
- // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
688
- if (this.liveRegionEl.textContent === message) {
689
- message += "\u00A0";
690
- }
691
- this.liveRegionMessage = message;
692
- }
693
- announceExistingOptions() {
694
- // request animation frame to wait for re-rendering of filtered options
695
- window.requestAnimationFrame(() => {
696
- let numResults = 0;
697
- if (this.tagInputType === "dropdown") {
698
- numResults = this.optionEls.length;
699
- }
700
- else if (this.tagInputType === "table") {
701
- numResults = this.filteredRows.length;
702
- }
703
- const existingOptionsMessage = intl.formatMessage({
704
- id: "tagInput.existingOptions",
705
- defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
706
- }, { num: numResults });
707
- if (numResults > 0) {
708
- this.announce(existingOptionsMessage);
709
- }
710
- });
711
- }
712
- announceCharacterLimitWarning(charCount, charLimit) {
713
- const charactersEnteredMessage = intl.formatMessage({
714
- id: "global.charactersEntered",
715
- defaultMessage: "{x, number} of {y, number} characters entered.",
716
- description: "for screen readers",
717
- }, { x: charCount, y: charLimit });
718
- const characterLimitReachedMessage = intl.formatMessage({
719
- id: "global.characterLimitReached",
720
- defaultMessage: "No additional characters will be entered.",
721
- description: "for screen readers",
722
- });
723
- this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
724
- }
725
- positionInput() {
726
- const lastTag = this.tagEls[this.tagEls.length - 1];
727
- // default placement to fall back to when no tags are present, or not enough space is available
728
- this.inputEl.style.position = "static";
729
- this.inputEl.style.width = "100%";
730
- if (lastTag) {
731
- const spaceAvailable = this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right;
732
- // 150px is the minimum width of the input field
733
- if (spaceAvailable >= 150) {
734
- // because the input has right: 0px
735
- // all thats needed to properly place it is setting position: absolute, top, and width
736
- this.inputEl.style.position = "absolute";
737
- this.inputEl.style.top = lastTag.offsetTop.toString() + "px";
738
- this.inputEl.style.width =
739
- (this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right - 8).toString() + "px";
740
- }
741
- }
742
- }
743
- /// Helpers
744
- listToCSV(list) {
745
- return list.join(",");
746
- }
747
- includesCaseInsensitive(list, element) {
748
- const lowercaseList = list.map((str) => str.toLowerCase());
749
- return lowercaseList.includes(element.toLowerCase());
750
- }
751
- filterCaseInsensitive(list, element) {
752
- return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
753
- }
754
- sortCaseInsensitive(list) {
755
- // The vanilla .sort method places words that start with capital letters above others (ASCII order)
756
- // so we need to pass in our own compare function to sort case-insensitive
757
- return list.sort((a, b) => {
758
- a = a.toLowerCase();
759
- b = b.toLowerCase();
760
- return a > b ? 1 : a < b ? -1 : 0;
761
- });
762
- }
763
- /// Renders
764
- renderTags() {
765
- let lockedTags = [];
766
- let unlockedTags = [];
767
- this.tagsList.forEach((tag, idx) => {
768
- const id = `tag${idx + 1}`;
769
- let tagText = "";
770
- let isLocked = false;
771
- if (this.tagInputType === "dropdown") {
772
- tagText = tag;
773
- }
774
- else if (this.tagInputType === "table") {
775
- // display table tags using col1 of the row with the same id
776
- // if one can't be found, display as empty
777
- const referencedRow = this.el.querySelector(`#${tag}`);
778
- tagText = referencedRow ? referencedRow.col1 : "";
779
- isLocked = referencedRow ? referencedRow.locked : false;
780
- }
781
- // make sure locked tags always appear in front of list
782
- const targetList = isLocked ? lockedTags : unlockedTags;
783
- targetList.push(h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""} ${isLocked ? "locked" : ""}`, "data-tag": tag, role: "option" },
784
- tagText,
785
- isLocked ? (h("div", { class: "icon lock" })) : (h("button", { class: "icon remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) }))));
786
- });
787
- return [...lockedTags, ...unlockedTags];
788
- }
789
- renderDropdown() {
790
- return (h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, ref: (el) => (this.dropdownEl = el) },
791
- h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()),
792
- h("ul", { class: "dropdown", id: "dropdown", role: "listbox", "aria-multiselectable": "true", "aria-expanded": this.isExpanded ? "true" : false, "aria-label": this.label, tabindex: -1 },
793
- this.inputEl && this.renderAddNewButton(),
794
- this.renderListItems(this.optionsList))));
795
- }
796
- renderListItems(optionsList) {
797
- optionsList = this.sortCaseInsensitive(optionsList);
798
- // filter by input
799
- if (this.inputEl && this.inputEl.value) {
800
- optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
801
- }
802
- return optionsList.map((option, idx) => {
803
- const id = `option${idx + 1}`;
804
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
805
- const isSelected = this.includesCaseInsensitive(this.tagsList, option);
806
- 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));
807
- });
808
- }
809
- renderAddNewButton() {
810
- const hasNonWhiteSpaceCharacters = this.inputEl.value.match(/\S/);
811
- const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, this.inputEl.value.trim());
812
- if (this.addNew && hasNonWhiteSpaceCharacters && !optionAlreadyExists) {
813
- const id = `add-new-btn`;
814
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
815
- 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()}"`));
816
- }
817
- else
818
- return "";
819
- }
820
- renderHelpText() {
821
- const helpTextHasOptions = intl.formatMessage({
822
- id: "tagInput.helpTextCanSelect",
823
- defaultMessage: "Search and select a tag.",
824
- description: "Placeholder text. Use imperative",
825
- });
826
- const helpTextEditable = intl.formatMessage({
827
- id: "tagInput.helpTextEditable",
828
- defaultMessage: "Press the Enter or Comma key to add a new tag.",
829
- description: "Placeholder text. Use imperative",
830
- });
831
- let helpText = "";
832
- if (this.optionsList.length > 0) {
833
- helpText += helpTextHasOptions;
834
- }
835
- if (this.addNew) {
836
- helpText += " " + helpTextEditable;
837
- }
838
- return helpText;
839
- }
840
- renderTagCounter() {
841
- if (this.maxTags) {
842
- return (h("div", { class: "lower-row" },
843
- h("div", { id: "max-tags" },
844
- this.generateTagCounterMessage(this.tagsList.length, this.maxTags),
845
- this.tagLimitReached && ` - ${this.maxTagsReachedMessage}`)));
846
- }
847
- }
848
- renderTable() {
849
- return (h("div", { class: "table-wrapper", onScroll: () => this.dismissTooltip() },
850
- h("table", { id: "table", role: "grid", class: `${this.colWidths ? "fixed-widths" : ""}`, "aria-label": this.label, "aria-multiselectable": "true" },
851
- this.renderTableHeaders(),
852
- this.filteredRows.length ? this.renderTableRows() : h("div", { class: "no-results" }, this.noResultsMessage))));
853
- }
854
- renderTableHeaders() {
855
- return (h("tr", { class: "headers", role: "row" }, csvToArray(this.colHeaders).map((header, idx) => {
856
- let overflowRule = "wrap";
857
- if (this.colWrap && csvToArray(this.colWrap)[idx]) {
858
- overflowRule = csvToArray(this.colWrap)[idx];
859
- }
860
- return (h("th", { class: `header-cell ${overflowRule}`, role: "columnheader",
861
- // @ts-ignore
862
- width: this.colWidths ? csvToArray(this.colWidths)[idx] : "" }, header));
863
- })));
864
- }
865
- renderTableRows() {
866
- return this.filteredRows.map((row) => {
867
- const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
868
- return (h("tr", { id: row.id, class: `${row.locked ? "locked" : ""} ${isSelected ? "selected" : ""}`, role: "row", onClick: () => this.handleTableRowClick(row.id) }, this.renderTableCells(row)));
869
- });
870
- }
871
- renderTableCells(row) {
872
- const colValues = [row.col1, row.col2, row.col3, row.col4].filter((val) => !!val);
873
- const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
874
- return colValues.map((val, idx) => {
875
- const localId = `${row.id}-col${idx + 1}`;
876
- let overflowRule = "wrap";
877
- if (this.colWrap && csvToArray(this.colWrap)[idx]) {
878
- overflowRule = csvToArray(this.colWrap)[idx];
879
- }
880
- 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() },
881
- val,
882
- h("div", { class: "description", id: `${localId}-description` }, row.locked ? "locked" : "")));
883
- });
884
- }
885
- render() {
886
- return (h(Host, { id: this.uid },
887
- h("div", { class: `wrapper label-${this.labelPosition}` },
888
- h("div", { class: "label-wrapper" },
889
- h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)),
890
- h("div", { class: `field-wrapper ${this.focusedElement ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) },
891
- h("div", { class: "upper-row" },
892
- h("div", { class: "tags-and-input-wrapper" },
893
- 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) => {
894
- this.clearTagFocus();
895
- this.handleBlur(ev, this.el);
896
- }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) }, this.renderTags()),
897
- 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) => {
898
- this.handleBlur(ev, this.el);
899
- }, onFocus: () => this.handleInputFocus(), onKeyDown: (ev) => this.handleInputKeyDown(ev) })),
900
- this.tagInputType === "dropdown" && (h("div", { class: "character-count" },
901
- this.charCount,
902
- "/",
903
- this.characterLimit))),
904
- this.renderTagCounter(),
905
- this.tagInputType === "dropdown" && this.renderDropdown()),
906
- this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""),
907
- h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage),
908
- this.tagInputType === "table" && this.renderTable())));
909
- }
910
- static get is() { return "wm-tag-input"; }
911
- static get encapsulation() { return "shadow"; }
912
- static get originalStyleUrls() { return {
913
- "$": ["wm-tag-input.scss"]
914
- }; }
915
- static get styleUrls() { return {
916
- "$": ["wm-tag-input.css"]
917
- }; }
918
- static get properties() { return {
919
- "label": {
920
- "type": "string",
921
- "mutable": false,
922
- "complexType": {
923
- "original": "string",
924
- "resolved": "string",
925
- "references": {}
926
- },
927
- "required": true,
928
- "optional": false,
929
- "docs": {
930
- "tags": [],
931
- "text": ""
932
- },
933
- "attribute": "label",
934
- "reflect": false
935
- },
936
- "labelPosition": {
937
- "type": "string",
938
- "mutable": false,
939
- "complexType": {
940
- "original": "\"top\" | \"left\" | \"none\"",
941
- "resolved": "\"left\" | \"none\" | \"top\"",
942
- "references": {}
943
- },
944
- "required": false,
945
- "optional": false,
946
- "docs": {
947
- "tags": [],
948
- "text": ""
949
- },
950
- "attribute": "label-position",
951
- "reflect": false,
952
- "defaultValue": "\"top\""
953
- },
954
- "options": {
955
- "type": "string",
956
- "mutable": true,
957
- "complexType": {
958
- "original": "string",
959
- "resolved": "string",
960
- "references": {}
961
- },
962
- "required": false,
963
- "optional": false,
964
- "docs": {
965
- "tags": [],
966
- "text": ""
967
- },
968
- "attribute": "options",
969
- "reflect": false,
970
- "defaultValue": "\"\""
971
- },
972
- "selectedTags": {
973
- "type": "string",
974
- "mutable": true,
975
- "complexType": {
976
- "original": "string",
977
- "resolved": "string",
978
- "references": {}
979
- },
980
- "required": false,
981
- "optional": false,
982
- "docs": {
983
- "tags": [],
984
- "text": ""
985
- },
986
- "attribute": "selected-tags",
987
- "reflect": true,
988
- "defaultValue": "\"\""
989
- },
990
- "info": {
991
- "type": "string",
992
- "mutable": false,
993
- "complexType": {
994
- "original": "string",
995
- "resolved": "string | undefined",
996
- "references": {}
997
- },
998
- "required": false,
999
- "optional": true,
1000
- "docs": {
1001
- "tags": [],
1002
- "text": ""
1003
- },
1004
- "attribute": "info",
1005
- "reflect": false
1006
- },
1007
- "addNew": {
1008
- "type": "boolean",
1009
- "mutable": false,
1010
- "complexType": {
1011
- "original": "boolean",
1012
- "resolved": "boolean",
1013
- "references": {}
1014
- },
1015
- "required": false,
1016
- "optional": false,
1017
- "docs": {
1018
- "tags": [],
1019
- "text": ""
1020
- },
1021
- "attribute": "add-new",
1022
- "reflect": false,
1023
- "defaultValue": "true"
1024
- },
1025
- "placeholder": {
1026
- "type": "string",
1027
- "mutable": true,
1028
- "complexType": {
1029
- "original": "string",
1030
- "resolved": "string | undefined",
1031
- "references": {}
1032
- },
1033
- "required": false,
1034
- "optional": true,
1035
- "docs": {
1036
- "tags": [],
1037
- "text": ""
1038
- },
1039
- "attribute": "placeholder",
1040
- "reflect": false
1041
- },
1042
- "characterLimit": {
1043
- "type": "number",
1044
- "mutable": false,
1045
- "complexType": {
1046
- "original": "number",
1047
- "resolved": "number",
1048
- "references": {}
1049
- },
1050
- "required": false,
1051
- "optional": false,
1052
- "docs": {
1053
- "tags": [],
1054
- "text": ""
1055
- },
1056
- "attribute": "character-limit",
1057
- "reflect": false,
1058
- "defaultValue": "50"
1059
- },
1060
- "maxTags": {
1061
- "type": "number",
1062
- "mutable": false,
1063
- "complexType": {
1064
- "original": "number",
1065
- "resolved": "number | undefined",
1066
- "references": {}
1067
- },
1068
- "required": false,
1069
- "optional": true,
1070
- "docs": {
1071
- "tags": [],
1072
- "text": ""
1073
- },
1074
- "attribute": "max-tags",
1075
- "reflect": false
1076
- },
1077
- "tagInputType": {
1078
- "type": "string",
1079
- "mutable": false,
1080
- "complexType": {
1081
- "original": "\"dropdown\" | \"table\"",
1082
- "resolved": "\"dropdown\" | \"table\"",
1083
- "references": {}
1084
- },
1085
- "required": false,
1086
- "optional": false,
1087
- "docs": {
1088
- "tags": [],
1089
- "text": ""
1090
- },
1091
- "attribute": "tag-input-type",
1092
- "reflect": false,
1093
- "defaultValue": "\"dropdown\""
1094
- },
1095
- "colHeaders": {
1096
- "type": "string",
1097
- "mutable": false,
1098
- "complexType": {
1099
- "original": "string",
1100
- "resolved": "string",
1101
- "references": {}
1102
- },
1103
- "required": true,
1104
- "optional": false,
1105
- "docs": {
1106
- "tags": [],
1107
- "text": ""
1108
- },
1109
- "attribute": "col-headers",
1110
- "reflect": false
1111
- },
1112
- "colWidths": {
1113
- "type": "string",
1114
- "mutable": false,
1115
- "complexType": {
1116
- "original": "string",
1117
- "resolved": "string | undefined",
1118
- "references": {}
1119
- },
1120
- "required": false,
1121
- "optional": true,
1122
- "docs": {
1123
- "tags": [],
1124
- "text": ""
1125
- },
1126
- "attribute": "col-widths",
1127
- "reflect": false
1128
- },
1129
- "colWrap": {
1130
- "type": "string",
1131
- "mutable": false,
1132
- "complexType": {
1133
- "original": "string",
1134
- "resolved": "string | undefined",
1135
- "references": {}
1136
- },
1137
- "required": false,
1138
- "optional": true,
1139
- "docs": {
1140
- "tags": [],
1141
- "text": ""
1142
- },
1143
- "attribute": "col-wrap",
1144
- "reflect": false
1145
- }
1146
- }; }
1147
- static get states() { return {
1148
- "focusedListItem": {},
1149
- "focusedTag": {},
1150
- "tablePosition": {},
1151
- "isExpanded": {},
1152
- "tagsList": {},
1153
- "optionsList": {},
1154
- "charCount": {},
1155
- "liveRegionMessage": {}
1156
- }; }
1157
- static get events() { return [{
1158
- "method": "wmTagInputChanged",
1159
- "name": "wmTagInputChanged",
1160
- "bubbles": true,
1161
- "cancelable": true,
1162
- "composed": true,
1163
- "docs": {
1164
- "tags": [],
1165
- "text": ""
1166
- },
1167
- "complexType": {
1168
- "original": "{\n value: string[] | HTMLWmTagInputRowElement[];\n tagChanged: string | HTMLWmTagInputRowElement;\n }",
1169
- "resolved": "{ value: string[] | HTMLWmTagInputRowElement[]; tagChanged: string | HTMLWmTagInputRowElement; }",
1170
- "references": {
1171
- "HTMLWmTagInputRowElement": {
1172
- "location": "global"
1173
- }
1174
- }
1175
- }
1176
- }]; }
1177
- static get elementRef() { return "el"; }
1178
- static get watchers() { return [{
1179
- "propName": "tagsList",
1180
- "methodName": "reflectSelectedTags"
1181
- }]; }
1182
- static get listeners() { return [{
1183
- "name": "wmTagInputRowUpdated",
1184
- "method": "handleRowUpdate",
1185
- "target": undefined,
1186
- "capture": false,
1187
- "passive": false
1188
- }, {
1189
- "name": "click",
1190
- "method": "closeIfNotElOrChild",
1191
- "target": "document",
1192
- "capture": false,
1193
- "passive": false
1194
- }, {
1195
- "name": "scroll",
1196
- "method": "dismissTooltip",
1197
- "target": "window",
1198
- "capture": true,
1199
- "passive": true
1200
- }]; }
1201
- }
1
+ import { h, Component, Host, Element, Prop, Listen, State, Event, Watch, forceUpdate, } from "@stencil/core";
2
+ import { csvToArray, generateId, shouldOpenUp, intl, debounce, showTooltip, hideTooltip } from "../../global/functions";
3
+ export class TagInput {
4
+ constructor() {
5
+ this.labelPosition = "top";
6
+ this.options = ""; // csv
7
+ this.selectedTags = ""; // csv
8
+ this.addNew = true;
9
+ this.characterLimit = 50;
10
+ this.tagInputType = "dropdown";
11
+ this.uid = this.el.id ? this.el.id : generateId();
12
+ this.openUp = false;
13
+ this.tooltipVisible = false;
14
+ this.tablePosition = { row: 0, column: 1 };
15
+ this.isExpanded = false;
16
+ this.tagsList = csvToArray(this.selectedTags);
17
+ this.optionsList = csvToArray(this.options);
18
+ this.charCount = 0;
19
+ this.liveRegionMessage = "";
20
+ this.tagAreaInstructions = intl.formatMessage({
21
+ id: "tagInput.tagAreaInstructions",
22
+ defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
23
+ });
24
+ this.maxTagsReachedMessage = intl.formatMessage({
25
+ id: "tagInput.maxTagsReached",
26
+ defaultMessage: "No more tags can be added because the limit has been reached.",
27
+ });
28
+ this.debouncedUpdate = debounce(() => forceUpdate(this.el), 30);
29
+ }
30
+ get focusedElement() {
31
+ return this.el.shadowRoot.activeElement;
32
+ }
33
+ get listItemEls() {
34
+ return Array.from(this.dropdownEl.querySelectorAll("li"));
35
+ }
36
+ get tagEls() {
37
+ return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
38
+ }
39
+ get nonLockedTagEls() {
40
+ return this.tagEls.filter((tag) => !tag.classList.contains("locked"));
41
+ }
42
+ get optionEls() {
43
+ return Array.from(this.dropdownEl.querySelectorAll(".option"));
44
+ }
45
+ get wmRowEls() {
46
+ return Array.from(this.el.querySelectorAll("wm-tag-input-row"));
47
+ }
48
+ get localRowEls() {
49
+ return Array.from(this.el.shadowRoot.querySelectorAll("tr"));
50
+ }
51
+ get filteredRows() {
52
+ return this.wmRowEls.filter((row) => {
53
+ const colValues = [row.col1, row.col2, row.col3, row.col4].join("").toLowerCase();
54
+ return this.inputEl && this.inputEl.value ? colValues.includes(this.inputEl.value.toLowerCase()) : true;
55
+ });
56
+ }
57
+ get nonLockedTagsList() {
58
+ let list = [];
59
+ if (this.tagInputType === "table") {
60
+ this.tagsList.forEach((id) => {
61
+ const correspondingRowEl = this.wmRowEls.filter((row) => id === row.id)[0];
62
+ if (!correspondingRowEl.locked) {
63
+ list.push(id);
64
+ }
65
+ });
66
+ }
67
+ else if (this.tagInputType === "dropdown") {
68
+ list = this.tagsList;
69
+ }
70
+ return list;
71
+ }
72
+ get tagLimitReached() {
73
+ return !!(this.maxTags && this.tagsList.length >= this.maxTags);
74
+ }
75
+ get noResultsMessage() {
76
+ return intl.formatMessage({
77
+ id: "tagInput.noResults",
78
+ defaultMessage: "No results match your search.",
79
+ description: "Message displayed when a user's search returns empty.",
80
+ });
81
+ }
82
+ generateTagAddedMessage(tag) {
83
+ return intl.formatMessage({
84
+ id: "tagInput.tagAdded",
85
+ defaultMessage: "{tagName} added.",
86
+ description: "A confirmation for adding a tag.",
87
+ }, { tagName: tag });
88
+ }
89
+ generateTagAlreadyAddedMessage(tag) {
90
+ return intl.formatMessage({
91
+ id: "tagInput.tagAlreadyAdded",
92
+ defaultMessage: "{tagName} has already been added.",
93
+ description: "An alert for adding a tag that is already present.",
94
+ }, { tagName: tag });
95
+ }
96
+ generateTagCounterMessage(x, y) {
97
+ return intl.formatMessage({
98
+ id: "tagInput.tagsAddedCounter",
99
+ defaultMessage: "Tags added: {x, number}/{y, number}",
100
+ description: "For the user to understand how close they are to the tag limit.",
101
+ }, {
102
+ x: x,
103
+ y: y,
104
+ });
105
+ }
106
+ generateCharacterLimitLabel(characterLimit) {
107
+ return intl.formatMessage({
108
+ id: "global.characterLimit",
109
+ defaultMessage: "{limit, number} characters allowed.",
110
+ description: "for screen readers",
111
+ }, { limit: characterLimit });
112
+ }
113
+ componentWillLoad() {
114
+ if (!this.placeholder) {
115
+ this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
116
+ }
117
+ if (!this.label) {
118
+ console.error("wm-tag-input must have a label property");
119
+ }
120
+ this.el.focus = function () {
121
+ // if present, send focus to the selected tags list
122
+ if (this.selectedTags) {
123
+ this.shadowRoot.querySelector("ul.tag-area").focus();
124
+ }
125
+ else {
126
+ this.shadowRoot.querySelector("input").focus();
127
+ }
128
+ };
129
+ this.consolidateSelectedTags();
130
+ // on resize of component, trigger componentDidRender -> positionInput
131
+ const resizeObserver = new ResizeObserver(() => this.debouncedUpdate());
132
+ resizeObserver.observe(this.el);
133
+ }
134
+ componentDidLoad() {
135
+ // prevent highlighting of pre-selected tags
136
+ this.tagEls.forEach((el) => el.classList.remove("highlight"));
137
+ }
138
+ componentDidRender() {
139
+ this.positionInput();
140
+ }
141
+ consolidateSelectedTags() {
142
+ this.tagsList.forEach((tag) => {
143
+ if (!this.includesCaseInsensitive(this.optionsList, tag)) {
144
+ this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
145
+ }
146
+ });
147
+ this.optionsList = csvToArray(this.options);
148
+ }
149
+ createPlaceholderDefault(addNew, hasOptions) {
150
+ const addAndSearchPlaceholder = intl.formatMessage({
151
+ id: "tagInput.placeholderAddAndSearch",
152
+ defaultMessage: "Add or search for a tag",
153
+ description: "Placeholder text. Use imperative",
154
+ });
155
+ const searchPlaceholder = intl.formatMessage({
156
+ id: "tagInput.placeholderSearch",
157
+ defaultMessage: "Search and select a tag",
158
+ description: "Placeholder text. Use imperative",
159
+ });
160
+ const addPlaceholder = intl.formatMessage({
161
+ id: "tagInput.placeholderAdd",
162
+ defaultMessage: "Add a new tag",
163
+ description: "Placeholder text. Use imperative",
164
+ });
165
+ let placeholder = "";
166
+ if (addNew && hasOptions) {
167
+ placeholder = addAndSearchPlaceholder;
168
+ }
169
+ else if (!addNew && hasOptions) {
170
+ placeholder = searchPlaceholder;
171
+ }
172
+ else if (addNew) {
173
+ placeholder = addPlaceholder;
174
+ }
175
+ return placeholder;
176
+ }
177
+ reflectSelectedTags(newValue, oldValue) {
178
+ const isAddition = newValue.length > oldValue.length;
179
+ let changedTag = "";
180
+ let selectedTags = this.tagsList;
181
+ if (isAddition) {
182
+ changedTag = newValue.filter((val) => !oldValue.includes(val))[0];
183
+ }
184
+ else {
185
+ changedTag = oldValue.filter((val) => !newValue.includes(val))[0];
186
+ }
187
+ // event emitted by type table uses element references instead of strings
188
+ if (this.tagInputType === "table") {
189
+ changedTag = this.wmRowEls.filter((row) => row.id === changedTag)[0];
190
+ selectedTags = this.tagsList.map((id) => this.el.querySelector(`#${id}`));
191
+ }
192
+ this.selectedTags = this.listToCSV(this.tagsList);
193
+ let detail = { value: selectedTags, tagChanged: changedTag };
194
+ this.wmTagInputChanged.emit(detail);
195
+ }
196
+ handleRowUpdate() {
197
+ forceUpdate(this.el);
198
+ }
199
+ closeIfNotElOrChild(ev) {
200
+ const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
201
+ if (this.tagInputType === "dropdown" && isntElOrChild && this.isExpanded) {
202
+ this.closeDropdown();
203
+ }
204
+ }
205
+ // From wm-button
206
+ // we need to listen for scroll events during the capture phase because they do not bubble up
207
+ // there can be layouts where the main content has 100vh and overflows
208
+ // in these cases window will register no scroll events unless we catch on they way down
209
+ dismissTooltip() {
210
+ if (this.tooltipVisible) {
211
+ hideTooltip();
212
+ this.tooltipVisible = false;
213
+ }
214
+ }
215
+ handleInputKeyDown(ev) {
216
+ if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
217
+ this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
218
+ }
219
+ // prevent keydown triggering on tag area
220
+ ev.stopPropagation();
221
+ switch (ev.key) {
222
+ case "Enter":
223
+ case ",":
224
+ ev.preventDefault();
225
+ this.handleInputEnter();
226
+ break;
227
+ case "ArrowDown":
228
+ ev.preventDefault();
229
+ this.handleInputArrowDown();
230
+ break;
231
+ case "ArrowUp":
232
+ ev.preventDefault();
233
+ this.handleInputArrowUp();
234
+ break;
235
+ case "ArrowLeft":
236
+ ev.preventDefault();
237
+ if (this.tagInputType === "table" && this.tablePosition.row) {
238
+ this.moveLeftCell();
239
+ }
240
+ break;
241
+ case "ArrowRight":
242
+ ev.preventDefault();
243
+ if (this.tagInputType === "table" && this.tablePosition.row) {
244
+ this.moveRightCell();
245
+ }
246
+ break;
247
+ case "Escape":
248
+ if (this.tagInputType === "dropdown" && this.isExpanded) {
249
+ this.closeDropdown();
250
+ }
251
+ break;
252
+ case "ArrowLeft":
253
+ case "Backspace":
254
+ this.handleInputBackspace();
255
+ break;
256
+ }
257
+ }
258
+ handleInputFocus() {
259
+ if (this.tagInputType === "dropdown") {
260
+ this.openDropdown();
261
+ this.clearListItemFocus();
262
+ }
263
+ // force update needed to apply styled state of field-wrapper el
264
+ forceUpdate(this.el);
265
+ }
266
+ handleInputChanged(value) {
267
+ this.charCount = value.length;
268
+ if (this.tagInputType === "dropdown") {
269
+ this.clearListItemFocus();
270
+ if (this.charCount >= this.characterLimit - 5) {
271
+ this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
272
+ }
273
+ if (!this.isExpanded) {
274
+ this.openDropdown();
275
+ }
276
+ }
277
+ else if (this.tagInputType === "table") {
278
+ this.clearCellFocus();
279
+ }
280
+ this.announceExistingOptions();
281
+ }
282
+ handleInputEnter() {
283
+ if (this.tagInputType === "dropdown") {
284
+ if (this.focusedListItem) {
285
+ this.handleListItemClick(this.focusedListItem);
286
+ }
287
+ else {
288
+ this.submitInput(this.addNew, this.inputEl.value.trim());
289
+ }
290
+ }
291
+ else if (this.tagInputType === "table" && this.tablePosition.row > 0) {
292
+ this.handleTableRowClick(this.localRowEls[this.tablePosition.row].id);
293
+ }
294
+ }
295
+ submitInput(canAddNew, value) {
296
+ const hasNonWhiteSpaceCharacters = value.match(/\S/);
297
+ if (canAddNew && hasNonWhiteSpaceCharacters) {
298
+ this.addTag(value);
299
+ this.optionsList = this.addOption(value);
300
+ this.resetInput();
301
+ }
302
+ }
303
+ handleInputArrowDown() {
304
+ if (this.tagInputType === "table") {
305
+ this.moveDownRow();
306
+ }
307
+ else if (this.tagInputType === "dropdown" && this.isExpanded) {
308
+ this.moveDownListItem();
309
+ }
310
+ else if (this.tagInputType === "dropdown") {
311
+ this.openDropdown();
312
+ }
313
+ }
314
+ handleInputArrowUp() {
315
+ if (this.tagInputType === "table") {
316
+ this.moveUpRow();
317
+ }
318
+ else if (this.tagInputType === "dropdown" && this.isExpanded) {
319
+ this.moveUpListItem();
320
+ }
321
+ else if (this.tagInputType === "dropdown") {
322
+ this.openDropdown();
323
+ }
324
+ }
325
+ handleInputBackspace() {
326
+ if (this.inputEl.value === "" && this.tagsList.length > 0) {
327
+ // wait for events to finish firing before redirecting focus
328
+ // prevents double input in input area and tag area
329
+ window.requestAnimationFrame(() => {
330
+ if (this.nonLockedTagsList.length > 0) {
331
+ this.tagAreaEl.focus();
332
+ this.focusTag(this.tagEls[this.tagEls.length - 1]);
333
+ }
334
+ });
335
+ }
336
+ }
337
+ handleListItemKeyDown(ev) {
338
+ const typedEvTarget = ev.target;
339
+ switch (ev.key) {
340
+ case "Enter":
341
+ case " ":
342
+ ev.preventDefault();
343
+ typedEvTarget.click();
344
+ break;
345
+ case "ArrowDown":
346
+ ev.preventDefault();
347
+ this.moveDownListItem();
348
+ break;
349
+ case "ArrowUp":
350
+ ev.preventDefault();
351
+ this.moveUpListItem();
352
+ break;
353
+ case "Escape":
354
+ if (this.focusedElement !== this.inputEl) {
355
+ this.inputEl.focus();
356
+ }
357
+ else if (this.tagInputType === "dropdown") {
358
+ this.closeDropdown();
359
+ }
360
+ break;
361
+ }
362
+ }
363
+ handleListItemClick(item) {
364
+ const tag = item.dataset.option.trim() || "";
365
+ if (this.includesCaseInsensitive(this.tagsList, tag)) {
366
+ this.announce(this.generateTagAlreadyAddedMessage(tag));
367
+ }
368
+ else {
369
+ this.resetInput();
370
+ this.addTag(tag);
371
+ this.optionsList = this.addOption(tag);
372
+ this.focusedListItem = null;
373
+ }
374
+ }
375
+ handleTableRowClick(rowId) {
376
+ const referencedRow = this.el.querySelector(`#${rowId}`);
377
+ const isLocked = referencedRow.locked;
378
+ if (!isLocked) {
379
+ if (this.includesCaseInsensitive(this.tagsList, rowId)) {
380
+ this.removeTag(rowId);
381
+ }
382
+ else if (!this.tagLimitReached) {
383
+ this.addTag(rowId);
384
+ this.resetInput();
385
+ }
386
+ }
387
+ }
388
+ handleTagAreaKeyDown(ev) {
389
+ switch (ev.key) {
390
+ case "ArrowLeft":
391
+ case "ArrowUp":
392
+ ev.preventDefault();
393
+ this.moveLeftTag();
394
+ break;
395
+ case "ArrowRight":
396
+ case "ArrowDown":
397
+ ev.preventDefault();
398
+ this.moveRightTag();
399
+ break;
400
+ case "Backspace":
401
+ case "Delete":
402
+ this.handleTagAreaDelete();
403
+ break;
404
+ }
405
+ }
406
+ handleTagAreaDelete() {
407
+ const isLocked = this.focusedTag && this.focusedTag.classList.contains("locked");
408
+ if (this.focusedTag && this.focusedTag.dataset.tag && !isLocked) {
409
+ this.removeTag(this.focusedTag.dataset.tag);
410
+ if (this.nonLockedTagsList.length === 0) {
411
+ // focus input if no tags are left
412
+ this.inputEl.focus();
413
+ }
414
+ else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
415
+ // reassign focus if removing the last tag but there are still tags remaining
416
+ this.focusedTag = this.tagEls[this.tagEls.length - 2];
417
+ this.focusTag(this.focusedTag);
418
+ }
419
+ }
420
+ }
421
+ handleBlur(ev, component) {
422
+ const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
423
+ this.dismissTooltip();
424
+ this.clearCellFocus();
425
+ if (isntElOrChild) {
426
+ this.fieldWrapperEl.classList.remove("focused");
427
+ if (this.tagInputType === "dropdown") {
428
+ this.closeDropdown();
429
+ }
430
+ }
431
+ }
432
+ handleCellMouseEnter(ev) {
433
+ const cell = ev.target;
434
+ const isTruncated = cell.scrollWidth > cell.clientWidth;
435
+ if (isTruncated) {
436
+ // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
437
+ showTooltip("bottom", cell, cell.innerText);
438
+ this.tooltipVisible = true;
439
+ }
440
+ }
441
+ handleTagAreaFocus() {
442
+ if (this.tagInputType === "dropdown") {
443
+ this.closeDropdown();
444
+ }
445
+ this.focusedTag = this.nonLockedTagEls[0];
446
+ this.focusTag(this.focusedTag);
447
+ }
448
+ handleRemoveButtonClick(tag) {
449
+ this.moveLeftTag();
450
+ this.removeTag(tag);
451
+ }
452
+ moveDownListItem() {
453
+ if (this.listItemEls.length > 0) {
454
+ const firstListItem = this.listItemEls[0];
455
+ if (!this.focusedListItem) {
456
+ this.focusListItem(firstListItem);
457
+ }
458
+ else if (this.focusedListItem.nextElementSibling) {
459
+ this.focusListItem(this.focusedListItem.nextElementSibling);
460
+ }
461
+ else {
462
+ this.focusListItem(firstListItem);
463
+ }
464
+ }
465
+ }
466
+ moveUpListItem() {
467
+ if (this.listItemEls.length > 0) {
468
+ const lastListItem = this.listItemEls[this.listItemEls.length - 1];
469
+ if (!this.focusedListItem) {
470
+ this.focusListItem(lastListItem);
471
+ }
472
+ else if (this.focusedListItem.previousElementSibling) {
473
+ this.focusListItem(this.focusedListItem.previousElementSibling);
474
+ }
475
+ else {
476
+ this.clearListItemFocus();
477
+ }
478
+ }
479
+ }
480
+ moveDownRow() {
481
+ if (this.filteredRows.length > 0) {
482
+ if (this.tablePosition.row === 0) {
483
+ this.tablePosition.row = 1;
484
+ }
485
+ else if (this.tablePosition.row === this.filteredRows.length) {
486
+ this.tablePosition.row = 1;
487
+ }
488
+ else {
489
+ this.tablePosition.row++;
490
+ }
491
+ // skip locked rows
492
+ const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
493
+ if (rowToFocus.locked) {
494
+ this.moveDownRow();
495
+ }
496
+ else {
497
+ this.focusCell(this.tablePosition);
498
+ }
499
+ }
500
+ }
501
+ moveUpRow() {
502
+ if (this.filteredRows.length > 0) {
503
+ if (this.tablePosition.row === 0) {
504
+ this.tablePosition.row = this.filteredRows.length;
505
+ }
506
+ else if (this.tablePosition.row === 1) {
507
+ this.tablePosition.row = 0;
508
+ }
509
+ else {
510
+ this.tablePosition.row--;
511
+ }
512
+ // skip locked rows
513
+ const rowToFocus = this.wmRowEls[this.tablePosition.row - 1];
514
+ if (rowToFocus && rowToFocus.locked) {
515
+ this.moveUpRow();
516
+ }
517
+ else if (rowToFocus) {
518
+ this.focusCell(this.tablePosition);
519
+ }
520
+ else {
521
+ this.clearCellFocus();
522
+ }
523
+ }
524
+ }
525
+ moveLeftCell() {
526
+ if (this.tablePosition.column != 1) {
527
+ this.tablePosition.column--;
528
+ this.focusCell(this.tablePosition);
529
+ }
530
+ }
531
+ moveRightCell() {
532
+ const numCols = csvToArray(this.colHeaders).length;
533
+ if (this.tablePosition.column < numCols) {
534
+ this.tablePosition.column++;
535
+ this.focusCell(this.tablePosition);
536
+ }
537
+ }
538
+ moveLeftTag() {
539
+ const lastTag = this.tagEls[this.tagEls.length - 1];
540
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
541
+ this.focusedTag = this.focusedTag.previousElementSibling;
542
+ }
543
+ else {
544
+ this.focusedTag = lastTag;
545
+ }
546
+ // skip locked tags
547
+ if (this.focusedTag.classList.contains("locked") && this.nonLockedTagEls.length > 0) {
548
+ this.moveLeftTag();
549
+ }
550
+ else {
551
+ this.focusTag(this.focusedTag);
552
+ }
553
+ }
554
+ moveRightTag() {
555
+ const firstTag = this.tagEls[0];
556
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
557
+ this.focusedTag = this.focusedTag.nextElementSibling;
558
+ }
559
+ else {
560
+ this.focusedTag = firstTag;
561
+ }
562
+ // skip locked tags
563
+ if (this.focusedTag.classList.contains("locked")) {
564
+ this.moveRightTag();
565
+ }
566
+ else {
567
+ this.focusTag(this.focusedTag);
568
+ }
569
+ }
570
+ addOption(option) {
571
+ let newOptionsList = this.optionsList;
572
+ const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
573
+ if (!optionAlreadyExists) {
574
+ newOptionsList = newOptionsList.concat(option);
575
+ }
576
+ return newOptionsList;
577
+ }
578
+ removeOption(option) {
579
+ this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
580
+ }
581
+ addTag(tag) {
582
+ let newTagsList = this.tagsList;
583
+ const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
584
+ const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
585
+ if (!tagAlreadyAdded) {
586
+ let textToAnnounce = tag;
587
+ if (this.tagInputType === "table") {
588
+ const referencedRow = this.el.querySelector(`#${tag}`);
589
+ textToAnnounce = referencedRow.col1;
590
+ }
591
+ this.announce(this.generateTagAddedMessage(textToAnnounce));
592
+ this.tagsList = newTagsList.concat(tagExistsAsOption || tag);
593
+ // if maxTags has been reached, focus should go to the tagArea
594
+ if (this.tagLimitReached) {
595
+ this.tagAreaEl.focus();
596
+ }
597
+ }
598
+ }
599
+ removeTag(tag) {
600
+ let textToAnnounce = tag;
601
+ if (this.tagInputType === "table") {
602
+ const referencedRow = this.el.querySelector(`#${tag}`);
603
+ textToAnnounce = referencedRow.col1;
604
+ }
605
+ const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: textToAnnounce });
606
+ this.announce(tagRemovedMessage);
607
+ this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
608
+ if (this.tagInputType === "dropdown") {
609
+ // if a tag was introduced by the user, also remove it from the dropdown options
610
+ const devOptionsList = csvToArray(this.options);
611
+ if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
612
+ this.removeOption(tag);
613
+ }
614
+ }
615
+ }
616
+ focusListItem(item) {
617
+ this.focusedListItem = item;
618
+ this.inputEl.setAttribute("aria-activedescendant", this.focusedListItem.id);
619
+ item.scrollIntoView({ block: "nearest" });
620
+ }
621
+ focusTag(element) {
622
+ if (element.classList.contains("locked")) {
623
+ this.focusedTag = null;
624
+ this.tagAreaEl.setAttribute("aria-activedescendant", "");
625
+ }
626
+ else {
627
+ this.focusedTag = element;
628
+ this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
629
+ }
630
+ }
631
+ focusCell(position) {
632
+ this.clearCellFocus(false);
633
+ if (position.row) {
634
+ const rowToFocus = this.localRowEls[position.row];
635
+ const rowCells = rowToFocus.querySelectorAll("td");
636
+ const cellToFocus = rowCells[position.column - 1];
637
+ const isTruncated = cellToFocus.scrollWidth > cellToFocus.clientWidth;
638
+ rowToFocus.classList.add("focused");
639
+ cellToFocus.classList.add("focused");
640
+ cellToFocus.scrollIntoView({ block: "nearest" });
641
+ this.inputEl.setAttribute("aria-activedescendant", cellToFocus.id);
642
+ this.dismissTooltip();
643
+ if (isTruncated) {
644
+ // innerText is necessary vs textContent, as innerText ignores sr-only / display: none text
645
+ showTooltip("bottom", cellToFocus, cellToFocus.innerText);
646
+ this.tooltipVisible = true;
647
+ }
648
+ }
649
+ }
650
+ clearTagFocus() {
651
+ this.tagAreaEl.setAttribute("aria-activedescendant", "");
652
+ this.focusedTag = null;
653
+ }
654
+ clearCellFocus(resetPosition = true) {
655
+ this.inputEl.setAttribute("aria-activedescendant", "");
656
+ if (resetPosition) {
657
+ this.tablePosition = { row: 0, column: 1 };
658
+ }
659
+ this.localRowEls.forEach((row) => {
660
+ row.classList.remove("focused");
661
+ row.querySelectorAll("td").forEach((cell) => {
662
+ cell.classList.remove("focused");
663
+ });
664
+ });
665
+ }
666
+ openDropdown() {
667
+ // given an offset of -2px because the dropdown is transformed downwards to avoid overlapping the focus border
668
+ this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight, -2);
669
+ this.isExpanded = true;
670
+ }
671
+ closeDropdown() {
672
+ this.clearListItemFocus();
673
+ this.isExpanded = false;
674
+ }
675
+ clearListItemFocus() {
676
+ this.focusedListItem = null;
677
+ this.inputEl.setAttribute("aria-activedescendant", "");
678
+ this.listItemEls.forEach((el) => {
679
+ el.classList.remove("focused");
680
+ });
681
+ }
682
+ resetInput() {
683
+ this.charCount = 0;
684
+ this.inputEl.value = "";
685
+ }
686
+ announce(message) {
687
+ // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
688
+ if (this.liveRegionEl.textContent === message) {
689
+ message += "\u00A0";
690
+ }
691
+ this.liveRegionMessage = message;
692
+ }
693
+ announceExistingOptions() {
694
+ // request animation frame to wait for re-rendering of filtered options
695
+ window.requestAnimationFrame(() => {
696
+ let numResults = 0;
697
+ if (this.tagInputType === "dropdown") {
698
+ numResults = this.optionEls.length;
699
+ }
700
+ else if (this.tagInputType === "table") {
701
+ numResults = this.filteredRows.length;
702
+ }
703
+ const existingOptionsMessage = intl.formatMessage({
704
+ id: "tagInput.existingOptions",
705
+ defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
706
+ }, { num: numResults });
707
+ if (numResults > 0) {
708
+ this.announce(existingOptionsMessage);
709
+ }
710
+ });
711
+ }
712
+ announceCharacterLimitWarning(charCount, charLimit) {
713
+ const charactersEnteredMessage = intl.formatMessage({
714
+ id: "global.charactersEntered",
715
+ defaultMessage: "{x, number} of {y, number} characters entered.",
716
+ description: "for screen readers",
717
+ }, { x: charCount, y: charLimit });
718
+ const characterLimitReachedMessage = intl.formatMessage({
719
+ id: "global.characterLimitReached",
720
+ defaultMessage: "No additional characters will be entered.",
721
+ description: "for screen readers",
722
+ });
723
+ this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
724
+ }
725
+ positionInput() {
726
+ const lastTag = this.tagEls[this.tagEls.length - 1];
727
+ // default placement to fall back to when no tags are present, or not enough space is available
728
+ this.inputEl.style.position = "static";
729
+ this.inputEl.style.width = "100%";
730
+ if (lastTag) {
731
+ const spaceAvailable = this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right;
732
+ // 150px is the minimum width of the input field
733
+ if (spaceAvailable >= 150) {
734
+ // because the input has right: 0px
735
+ // all thats needed to properly place it is setting position: absolute, top, and width
736
+ this.inputEl.style.position = "absolute";
737
+ this.inputEl.style.top = lastTag.offsetTop.toString() + "px";
738
+ this.inputEl.style.width =
739
+ (this.tagAreaEl.getBoundingClientRect().right - lastTag.getBoundingClientRect().right - 8).toString() + "px";
740
+ }
741
+ }
742
+ }
743
+ /// Helpers
744
+ listToCSV(list) {
745
+ return list.join(",");
746
+ }
747
+ includesCaseInsensitive(list, element) {
748
+ const lowercaseList = list.map((str) => str.toLowerCase());
749
+ return lowercaseList.includes(element.toLowerCase());
750
+ }
751
+ filterCaseInsensitive(list, element) {
752
+ return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
753
+ }
754
+ sortCaseInsensitive(list) {
755
+ // The vanilla .sort method places words that start with capital letters above others (ASCII order)
756
+ // so we need to pass in our own compare function to sort case-insensitive
757
+ return list.sort((a, b) => {
758
+ a = a.toLowerCase();
759
+ b = b.toLowerCase();
760
+ return a > b ? 1 : a < b ? -1 : 0;
761
+ });
762
+ }
763
+ /// Renders
764
+ renderTags() {
765
+ let lockedTags = [];
766
+ let unlockedTags = [];
767
+ this.tagsList.forEach((tag, idx) => {
768
+ const id = `tag${idx + 1}`;
769
+ let tagText = "";
770
+ let isLocked = false;
771
+ if (this.tagInputType === "dropdown") {
772
+ tagText = tag;
773
+ }
774
+ else if (this.tagInputType === "table") {
775
+ // display table tags using col1 of the row with the same id
776
+ // if one can't be found, display as empty
777
+ const referencedRow = this.el.querySelector(`#${tag}`);
778
+ tagText = referencedRow ? referencedRow.col1 : "";
779
+ isLocked = referencedRow ? referencedRow.locked : false;
780
+ }
781
+ // make sure locked tags always appear in front of list
782
+ const targetList = isLocked ? lockedTags : unlockedTags;
783
+ targetList.push(h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""} ${isLocked ? "locked" : ""}`, "data-tag": tag, role: "option" },
784
+ tagText,
785
+ isLocked ? (h("div", { class: "icon lock" })) : (h("button", { class: "icon remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) }))));
786
+ });
787
+ return [...lockedTags, ...unlockedTags];
788
+ }
789
+ renderDropdown() {
790
+ return (h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, ref: (el) => (this.dropdownEl = el) },
791
+ h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()),
792
+ h("ul", { class: "dropdown", id: "dropdown", role: "listbox", "aria-multiselectable": "true", "aria-expanded": this.isExpanded ? "true" : false, "aria-label": this.label, tabindex: -1 },
793
+ this.inputEl && this.renderAddNewButton(),
794
+ this.renderListItems(this.optionsList))));
795
+ }
796
+ renderListItems(optionsList) {
797
+ optionsList = this.sortCaseInsensitive(optionsList);
798
+ // filter by input
799
+ if (this.inputEl && this.inputEl.value) {
800
+ optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
801
+ }
802
+ return optionsList.map((option, idx) => {
803
+ const id = `option${idx + 1}`;
804
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
805
+ const isSelected = this.includesCaseInsensitive(this.tagsList, option);
806
+ 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));
807
+ });
808
+ }
809
+ renderAddNewButton() {
810
+ const hasNonWhiteSpaceCharacters = this.inputEl.value.match(/\S/);
811
+ const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, this.inputEl.value.trim());
812
+ if (this.addNew && hasNonWhiteSpaceCharacters && !optionAlreadyExists) {
813
+ const id = `add-new-btn`;
814
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
815
+ 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()}"`));
816
+ }
817
+ else
818
+ return "";
819
+ }
820
+ renderHelpText() {
821
+ const helpTextHasOptions = intl.formatMessage({
822
+ id: "tagInput.helpTextCanSelect",
823
+ defaultMessage: "Search and select a tag.",
824
+ description: "Placeholder text. Use imperative",
825
+ });
826
+ const helpTextEditable = intl.formatMessage({
827
+ id: "tagInput.helpTextEditable",
828
+ defaultMessage: "Press the Enter or Comma key to add a new tag.",
829
+ description: "Placeholder text. Use imperative",
830
+ });
831
+ let helpText = "";
832
+ if (this.optionsList.length > 0) {
833
+ helpText += helpTextHasOptions;
834
+ }
835
+ if (this.addNew) {
836
+ helpText += " " + helpTextEditable;
837
+ }
838
+ return helpText;
839
+ }
840
+ renderTagCounter() {
841
+ if (this.maxTags) {
842
+ return (h("div", { class: "lower-row" },
843
+ h("div", { id: "max-tags" },
844
+ this.generateTagCounterMessage(this.tagsList.length, this.maxTags),
845
+ this.tagLimitReached && ` - ${this.maxTagsReachedMessage}`)));
846
+ }
847
+ }
848
+ renderTable() {
849
+ return (h("div", { class: "table-wrapper", onScroll: () => this.dismissTooltip() },
850
+ h("table", { id: "table", role: "grid", class: `${this.colWidths ? "fixed-widths" : ""}`, "aria-label": this.label, "aria-multiselectable": "true" },
851
+ this.renderTableHeaders(),
852
+ this.filteredRows.length ? this.renderTableRows() : h("div", { class: "no-results" }, this.noResultsMessage))));
853
+ }
854
+ renderTableHeaders() {
855
+ return (h("tr", { class: "headers", role: "row" }, csvToArray(this.colHeaders).map((header, idx) => {
856
+ let overflowRule = "wrap";
857
+ if (this.colWrap && csvToArray(this.colWrap)[idx]) {
858
+ overflowRule = csvToArray(this.colWrap)[idx];
859
+ }
860
+ return (h("th", { class: `header-cell ${overflowRule}`, role: "columnheader",
861
+ // @ts-ignore
862
+ width: this.colWidths ? csvToArray(this.colWidths)[idx] : "" }, header));
863
+ })));
864
+ }
865
+ renderTableRows() {
866
+ return this.filteredRows.map((row) => {
867
+ const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
868
+ return (h("tr", { id: row.id, class: `${row.locked ? "locked" : ""} ${isSelected ? "selected" : ""}`, role: "row", onClick: () => this.handleTableRowClick(row.id) }, this.renderTableCells(row)));
869
+ });
870
+ }
871
+ renderTableCells(row) {
872
+ const colValues = [row.col1, row.col2, row.col3, row.col4].filter((val) => !!val);
873
+ const isSelected = this.includesCaseInsensitive(this.tagsList, row.id);
874
+ return colValues.map((val, idx) => {
875
+ const localId = `${row.id}-col${idx + 1}`;
876
+ let overflowRule = "wrap";
877
+ if (this.colWrap && csvToArray(this.colWrap)[idx]) {
878
+ overflowRule = csvToArray(this.colWrap)[idx];
879
+ }
880
+ 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() },
881
+ val,
882
+ h("div", { class: "description", id: `${localId}-description` }, row.locked ? "locked" : "")));
883
+ });
884
+ }
885
+ render() {
886
+ return (h(Host, { id: this.uid },
887
+ h("div", { class: `wrapper label-${this.labelPosition}` },
888
+ h("div", { class: "label-wrapper" },
889
+ h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)),
890
+ h("div", { class: `field-wrapper ${this.focusedElement ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) },
891
+ h("div", { class: "upper-row" },
892
+ h("div", { class: "tags-and-input-wrapper" },
893
+ 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) => {
894
+ this.clearTagFocus();
895
+ this.handleBlur(ev, this.el);
896
+ }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) }, this.renderTags()),
897
+ 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) => {
898
+ this.handleBlur(ev, this.el);
899
+ }, onFocus: () => this.handleInputFocus(), onKeyDown: (ev) => this.handleInputKeyDown(ev) })),
900
+ this.tagInputType === "dropdown" && (h("div", { class: "character-count" },
901
+ this.charCount,
902
+ "/",
903
+ this.characterLimit))),
904
+ this.renderTagCounter(),
905
+ this.tagInputType === "dropdown" && this.renderDropdown()),
906
+ this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""),
907
+ h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage),
908
+ this.tagInputType === "table" && this.renderTable())));
909
+ }
910
+ static get is() { return "wm-tag-input"; }
911
+ static get encapsulation() { return "shadow"; }
912
+ static get originalStyleUrls() { return {
913
+ "$": ["wm-tag-input.scss"]
914
+ }; }
915
+ static get styleUrls() { return {
916
+ "$": ["wm-tag-input.css"]
917
+ }; }
918
+ static get properties() { return {
919
+ "label": {
920
+ "type": "string",
921
+ "mutable": false,
922
+ "complexType": {
923
+ "original": "string",
924
+ "resolved": "string",
925
+ "references": {}
926
+ },
927
+ "required": true,
928
+ "optional": false,
929
+ "docs": {
930
+ "tags": [],
931
+ "text": ""
932
+ },
933
+ "attribute": "label",
934
+ "reflect": false
935
+ },
936
+ "labelPosition": {
937
+ "type": "string",
938
+ "mutable": false,
939
+ "complexType": {
940
+ "original": "\"top\" | \"left\" | \"none\"",
941
+ "resolved": "\"left\" | \"none\" | \"top\"",
942
+ "references": {}
943
+ },
944
+ "required": false,
945
+ "optional": false,
946
+ "docs": {
947
+ "tags": [],
948
+ "text": ""
949
+ },
950
+ "attribute": "label-position",
951
+ "reflect": false,
952
+ "defaultValue": "\"top\""
953
+ },
954
+ "options": {
955
+ "type": "string",
956
+ "mutable": true,
957
+ "complexType": {
958
+ "original": "string",
959
+ "resolved": "string",
960
+ "references": {}
961
+ },
962
+ "required": false,
963
+ "optional": false,
964
+ "docs": {
965
+ "tags": [],
966
+ "text": ""
967
+ },
968
+ "attribute": "options",
969
+ "reflect": false,
970
+ "defaultValue": "\"\""
971
+ },
972
+ "selectedTags": {
973
+ "type": "string",
974
+ "mutable": true,
975
+ "complexType": {
976
+ "original": "string",
977
+ "resolved": "string",
978
+ "references": {}
979
+ },
980
+ "required": false,
981
+ "optional": false,
982
+ "docs": {
983
+ "tags": [],
984
+ "text": ""
985
+ },
986
+ "attribute": "selected-tags",
987
+ "reflect": true,
988
+ "defaultValue": "\"\""
989
+ },
990
+ "info": {
991
+ "type": "string",
992
+ "mutable": false,
993
+ "complexType": {
994
+ "original": "string",
995
+ "resolved": "string | undefined",
996
+ "references": {}
997
+ },
998
+ "required": false,
999
+ "optional": true,
1000
+ "docs": {
1001
+ "tags": [],
1002
+ "text": ""
1003
+ },
1004
+ "attribute": "info",
1005
+ "reflect": false
1006
+ },
1007
+ "addNew": {
1008
+ "type": "boolean",
1009
+ "mutable": false,
1010
+ "complexType": {
1011
+ "original": "boolean",
1012
+ "resolved": "boolean",
1013
+ "references": {}
1014
+ },
1015
+ "required": false,
1016
+ "optional": false,
1017
+ "docs": {
1018
+ "tags": [],
1019
+ "text": ""
1020
+ },
1021
+ "attribute": "add-new",
1022
+ "reflect": false,
1023
+ "defaultValue": "true"
1024
+ },
1025
+ "placeholder": {
1026
+ "type": "string",
1027
+ "mutable": true,
1028
+ "complexType": {
1029
+ "original": "string",
1030
+ "resolved": "string | undefined",
1031
+ "references": {}
1032
+ },
1033
+ "required": false,
1034
+ "optional": true,
1035
+ "docs": {
1036
+ "tags": [],
1037
+ "text": ""
1038
+ },
1039
+ "attribute": "placeholder",
1040
+ "reflect": false
1041
+ },
1042
+ "characterLimit": {
1043
+ "type": "number",
1044
+ "mutable": false,
1045
+ "complexType": {
1046
+ "original": "number",
1047
+ "resolved": "number",
1048
+ "references": {}
1049
+ },
1050
+ "required": false,
1051
+ "optional": false,
1052
+ "docs": {
1053
+ "tags": [],
1054
+ "text": ""
1055
+ },
1056
+ "attribute": "character-limit",
1057
+ "reflect": false,
1058
+ "defaultValue": "50"
1059
+ },
1060
+ "maxTags": {
1061
+ "type": "number",
1062
+ "mutable": false,
1063
+ "complexType": {
1064
+ "original": "number",
1065
+ "resolved": "number | undefined",
1066
+ "references": {}
1067
+ },
1068
+ "required": false,
1069
+ "optional": true,
1070
+ "docs": {
1071
+ "tags": [],
1072
+ "text": ""
1073
+ },
1074
+ "attribute": "max-tags",
1075
+ "reflect": false
1076
+ },
1077
+ "tagInputType": {
1078
+ "type": "string",
1079
+ "mutable": false,
1080
+ "complexType": {
1081
+ "original": "\"dropdown\" | \"table\"",
1082
+ "resolved": "\"dropdown\" | \"table\"",
1083
+ "references": {}
1084
+ },
1085
+ "required": false,
1086
+ "optional": false,
1087
+ "docs": {
1088
+ "tags": [],
1089
+ "text": ""
1090
+ },
1091
+ "attribute": "tag-input-type",
1092
+ "reflect": false,
1093
+ "defaultValue": "\"dropdown\""
1094
+ },
1095
+ "colHeaders": {
1096
+ "type": "string",
1097
+ "mutable": false,
1098
+ "complexType": {
1099
+ "original": "string",
1100
+ "resolved": "string",
1101
+ "references": {}
1102
+ },
1103
+ "required": true,
1104
+ "optional": false,
1105
+ "docs": {
1106
+ "tags": [],
1107
+ "text": ""
1108
+ },
1109
+ "attribute": "col-headers",
1110
+ "reflect": false
1111
+ },
1112
+ "colWidths": {
1113
+ "type": "string",
1114
+ "mutable": false,
1115
+ "complexType": {
1116
+ "original": "string",
1117
+ "resolved": "string | undefined",
1118
+ "references": {}
1119
+ },
1120
+ "required": false,
1121
+ "optional": true,
1122
+ "docs": {
1123
+ "tags": [],
1124
+ "text": ""
1125
+ },
1126
+ "attribute": "col-widths",
1127
+ "reflect": false
1128
+ },
1129
+ "colWrap": {
1130
+ "type": "string",
1131
+ "mutable": false,
1132
+ "complexType": {
1133
+ "original": "string",
1134
+ "resolved": "string | undefined",
1135
+ "references": {}
1136
+ },
1137
+ "required": false,
1138
+ "optional": true,
1139
+ "docs": {
1140
+ "tags": [],
1141
+ "text": ""
1142
+ },
1143
+ "attribute": "col-wrap",
1144
+ "reflect": false
1145
+ }
1146
+ }; }
1147
+ static get states() { return {
1148
+ "focusedListItem": {},
1149
+ "focusedTag": {},
1150
+ "tablePosition": {},
1151
+ "isExpanded": {},
1152
+ "tagsList": {},
1153
+ "optionsList": {},
1154
+ "charCount": {},
1155
+ "liveRegionMessage": {}
1156
+ }; }
1157
+ static get events() { return [{
1158
+ "method": "wmTagInputChanged",
1159
+ "name": "wmTagInputChanged",
1160
+ "bubbles": true,
1161
+ "cancelable": true,
1162
+ "composed": true,
1163
+ "docs": {
1164
+ "tags": [],
1165
+ "text": ""
1166
+ },
1167
+ "complexType": {
1168
+ "original": "{\r\n value: string[] | HTMLWmTagInputRowElement[];\r\n tagChanged: string | HTMLWmTagInputRowElement;\r\n }",
1169
+ "resolved": "{ value: string[] | HTMLWmTagInputRowElement[]; tagChanged: string | HTMLWmTagInputRowElement; }",
1170
+ "references": {
1171
+ "HTMLWmTagInputRowElement": {
1172
+ "location": "global"
1173
+ }
1174
+ }
1175
+ }
1176
+ }]; }
1177
+ static get elementRef() { return "el"; }
1178
+ static get watchers() { return [{
1179
+ "propName": "tagsList",
1180
+ "methodName": "reflectSelectedTags"
1181
+ }]; }
1182
+ static get listeners() { return [{
1183
+ "name": "wmTagInputRowUpdated",
1184
+ "method": "handleRowUpdate",
1185
+ "target": undefined,
1186
+ "capture": false,
1187
+ "passive": false
1188
+ }, {
1189
+ "name": "click",
1190
+ "method": "closeIfNotElOrChild",
1191
+ "target": "document",
1192
+ "capture": false,
1193
+ "passive": false
1194
+ }, {
1195
+ "name": "scroll",
1196
+ "method": "dismissTooltip",
1197
+ "target": "window",
1198
+ "capture": true,
1199
+ "passive": true
1200
+ }]; }
1201
+ }