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