@watermarkinsights/ripple 3.0.1-0 → 3.0.2-0

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 (224) hide show
  1. package/dist/{ripple/functions-316c1b23.js → cjs/functions-e3f5ae65.js} +188 -2391
  2. package/dist/cjs/global-1e540de6.js +38 -0
  3. package/dist/cjs/http-service-9e8c4dd5.js +57 -0
  4. package/dist/cjs/index-d930307d.js +1392 -0
  5. package/dist/cjs/index.cjs.js +2 -0
  6. package/dist/cjs/interfaces-30a74c1f.js +35 -0
  7. package/dist/cjs/loader.cjs.js +22 -0
  8. package/dist/cjs/priv-chart-popover.cjs.entry.js +89 -0
  9. package/dist/cjs/priv-datepicker.cjs.entry.js +672 -0
  10. package/dist/cjs/priv-navigator-button.cjs.entry.js +29 -0
  11. package/dist/cjs/priv-navigator-item.cjs.entry.js +34 -0
  12. package/dist/cjs/ripple.cjs.js +20 -0
  13. package/dist/cjs/wm-action-menu_2.cjs.entry.js +318 -0
  14. package/dist/cjs/wm-button.cjs.entry.js +152 -0
  15. package/dist/cjs/wm-chart-slice.cjs.entry.js +22 -0
  16. package/dist/cjs/wm-chart.cjs.entry.js +508 -0
  17. package/dist/cjs/wm-datepicker.cjs.entry.js +257 -0
  18. package/dist/cjs/wm-input.cjs.entry.js +110 -0
  19. package/dist/cjs/wm-modal-footer.cjs.entry.js +43 -0
  20. package/dist/cjs/wm-modal-header.cjs.entry.js +45 -0
  21. package/dist/cjs/wm-modal.cjs.entry.js +149 -0
  22. package/dist/cjs/wm-navigator.cjs.entry.js +279 -0
  23. package/dist/cjs/wm-network-uploader.cjs.entry.js +431 -0
  24. package/dist/cjs/wm-option_2.cjs.entry.js +483 -0
  25. package/dist/cjs/wm-pagination.cjs.entry.js +176 -0
  26. package/dist/cjs/wm-search.cjs.entry.js +231 -0
  27. package/dist/cjs/wm-snackbar.cjs.entry.js +160 -0
  28. package/dist/cjs/wm-tab-item_3.cjs.entry.js +316 -0
  29. package/dist/cjs/wm-tag-input.cjs.entry.js +538 -0
  30. package/dist/cjs/wm-timepicker.cjs.entry.js +386 -0
  31. package/dist/cjs/wm-toggletip.cjs.entry.js +128 -0
  32. package/dist/cjs/wm-uploader.cjs.entry.js +342 -0
  33. package/dist/cjs/wm-wrapper.cjs.entry.js +21 -0
  34. package/dist/collection/collection-manifest.json +131 -0
  35. package/dist/{ripple/ripple.css → collection/components/wm-action-menu/wm-action-menu.css} +80 -42
  36. package/dist/collection/components/wm-action-menu/wm-action-menu.js +392 -0
  37. package/dist/collection/components/wm-button/wm-button.css +572 -0
  38. package/dist/collection/components/wm-button/wm-button.js +365 -0
  39. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.css +132 -0
  40. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.js +232 -0
  41. package/dist/collection/components/wm-chart/wm-chart-slice.js +64 -0
  42. package/dist/collection/components/wm-chart/wm-chart.css +337 -0
  43. package/dist/collection/components/wm-chart/wm-chart.js +710 -0
  44. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.css +374 -0
  45. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1003 -0
  46. package/dist/collection/components/wm-datepicker/wm-datepicker.css +211 -0
  47. package/dist/collection/components/wm-datepicker/wm-datepicker.js +439 -0
  48. package/dist/collection/components/wm-input/wm-input.css +220 -0
  49. package/dist/collection/components/wm-input/wm-input.js +302 -0
  50. package/dist/collection/components/wm-menuitem/wm-menuitem.css +118 -0
  51. package/dist/collection/components/wm-menuitem/wm-menuitem.js +411 -0
  52. package/dist/collection/components/wm-modal/wm-modal-footer.css +84 -0
  53. package/dist/collection/components/wm-modal/wm-modal-footer.js +159 -0
  54. package/dist/collection/components/wm-modal/wm-modal-header.css +78 -0
  55. package/dist/collection/components/wm-modal/wm-modal-header.js +109 -0
  56. package/dist/collection/components/wm-modal/wm-modal.css +155 -0
  57. package/dist/collection/components/wm-modal/wm-modal.js +356 -0
  58. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.css +94 -0
  59. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -0
  60. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.css +67 -0
  61. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -0
  62. package/dist/collection/components/wm-navigator/wm-navigator.css +137 -0
  63. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -0
  64. package/dist/collection/components/wm-option/wm-option.css +162 -0
  65. package/dist/collection/components/wm-option/wm-option.js +394 -0
  66. package/dist/collection/components/wm-pagination/wm-pagination.css +217 -0
  67. package/dist/collection/components/wm-pagination/wm-pagination.js +348 -0
  68. package/dist/collection/components/wm-search/wm-search.css +155 -0
  69. package/dist/collection/components/wm-search/wm-search.js +439 -0
  70. package/dist/collection/components/wm-select/wm-select.css +315 -0
  71. package/dist/collection/components/wm-select/wm-select.js +676 -0
  72. package/dist/collection/components/wm-snackbar/wm-snackbar.css +331 -0
  73. package/dist/collection/components/wm-snackbar/wm-snackbar.js +240 -0
  74. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.css +104 -0
  75. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +202 -0
  76. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.css +73 -0
  77. package/dist/{ripple/wm-tab-list.entry.js → collection/components/wm-tabs/wm-tab-list/wm-tab-list.js} +131 -17
  78. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.css +57 -0
  79. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -0
  80. package/dist/collection/components/wm-tag-input/wm-tag-input.css +431 -0
  81. package/dist/collection/components/wm-tag-input/wm-tag-input.js +754 -0
  82. package/dist/collection/components/wm-timepicker/wm-timepicker.css +370 -0
  83. package/dist/collection/components/wm-timepicker/wm-timepicker.js +567 -0
  84. package/dist/collection/components/wm-toggletip/wm-toggletip.css +350 -0
  85. package/dist/collection/components/wm-toggletip/wm-toggletip.js +217 -0
  86. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.css +642 -0
  87. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +753 -0
  88. package/dist/collection/components/wm-uploader/wm-uploader.css +666 -0
  89. package/dist/collection/components/wm-uploader/wm-uploader.js +673 -0
  90. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -0
  91. package/dist/collection/dev/scripts.js +20 -0
  92. package/dist/collection/global/__mocks__/functions.js +5 -0
  93. package/dist/collection/global/functions.js +420 -0
  94. package/dist/{ripple/app-globals-b5693c90.js → collection/global/global.js} +3 -8
  95. package/dist/{ripple/interfaces-50753346.js → collection/global/interfaces.js} +4 -6
  96. package/dist/collection/global/services/__mocks__/http-service.js +130 -0
  97. package/dist/collection/global/services/http-service.js +50 -0
  98. package/dist/collection/lang/lang.js +5 -0
  99. package/dist/collection/lang/piglatin.js +93 -0
  100. package/dist/esm/functions-0deb7f8e.js +6117 -0
  101. package/dist/esm/global-d6b49e98.js +36 -0
  102. package/dist/{ripple → esm}/http-service-5d037e16.js +0 -0
  103. package/dist/esm/index-5a842e48.js +1363 -0
  104. package/dist/esm/index.js +1 -0
  105. package/dist/esm/interfaces-61c6305b.js +32 -0
  106. package/dist/esm/loader.js +18 -0
  107. package/dist/esm/polyfills/core-js.js +11 -0
  108. package/dist/esm/polyfills/css-shim.js +1 -0
  109. package/dist/esm/polyfills/dom.js +79 -0
  110. package/dist/esm/polyfills/es5-html-element.js +1 -0
  111. package/dist/esm/polyfills/index.js +34 -0
  112. package/dist/esm/polyfills/system.js +6 -0
  113. package/dist/{ripple → esm}/priv-chart-popover.entry.js +2 -2
  114. package/dist/{ripple → esm}/priv-datepicker.entry.js +3 -3
  115. package/dist/{ripple → esm}/priv-navigator-button.entry.js +1 -1
  116. package/dist/{ripple → esm}/priv-navigator-item.entry.js +1 -1
  117. package/dist/esm/ripple.js +18 -0
  118. package/dist/{ripple/wm-action-menu.entry.js → esm/wm-action-menu_2.entry.js} +114 -3
  119. package/dist/{ripple → esm}/wm-button.entry.js +3 -3
  120. package/dist/{ripple → esm}/wm-chart-slice.entry.js +1 -1
  121. package/dist/{ripple → esm}/wm-chart.entry.js +2 -2
  122. package/dist/{ripple → esm}/wm-datepicker.entry.js +27 -32
  123. package/dist/{ripple → esm}/wm-input.entry.js +2 -2
  124. package/dist/{ripple → esm}/wm-modal-footer.entry.js +2 -2
  125. package/dist/{ripple → esm}/wm-modal-header.entry.js +2 -2
  126. package/dist/{ripple → esm}/wm-modal.entry.js +2 -2
  127. package/dist/{ripple → esm}/wm-navigator.entry.js +3 -3
  128. package/dist/{ripple → esm}/wm-network-uploader.entry.js +2 -2
  129. package/dist/{ripple/wm-select.entry.js → esm/wm-option_2.entry.js} +119 -3
  130. package/dist/{ripple → esm}/wm-pagination.entry.js +2 -2
  131. package/dist/{ripple → esm}/wm-search.entry.js +2 -2
  132. package/dist/{ripple → esm}/wm-snackbar.entry.js +2 -2
  133. package/dist/esm/wm-tab-item_3.entry.js +310 -0
  134. package/dist/{ripple → esm}/wm-tag-input.entry.js +2 -2
  135. package/dist/{ripple → esm}/wm-timepicker.entry.js +2 -2
  136. package/dist/{ripple → esm}/wm-toggletip.entry.js +2 -2
  137. package/dist/{ripple → esm}/wm-uploader.entry.js +2 -2
  138. package/dist/{ripple → esm}/wm-wrapper.entry.js +1 -1
  139. package/dist/index.cjs.js +1 -0
  140. package/dist/index.js +1 -0
  141. package/dist/loader/cdn.js +3 -0
  142. package/dist/loader/index.cjs.js +3 -0
  143. package/dist/loader/index.d.ts +13 -0
  144. package/dist/loader/index.es2017.js +3 -0
  145. package/dist/loader/index.js +4 -0
  146. package/dist/loader/package.json +10 -0
  147. package/dist/ripple/index.esm.js +0 -1
  148. package/dist/ripple/p-103f8cae.entry.js +1 -0
  149. package/dist/ripple/p-129d94fa.entry.js +1 -0
  150. package/dist/ripple/p-139fe143.entry.js +1 -0
  151. package/dist/ripple/p-16367805.entry.js +1 -0
  152. package/dist/ripple/p-1d334060.entry.js +1 -0
  153. package/dist/ripple/p-2562f330.entry.js +1 -0
  154. package/dist/ripple/p-278b26ef.entry.js +1 -0
  155. package/dist/ripple/p-2c21bb72.entry.js +1 -0
  156. package/dist/ripple/p-2f5fda71.entry.js +1 -0
  157. package/dist/ripple/p-3e6f04d5.entry.js +1 -0
  158. package/dist/ripple/p-7185de7f.entry.js +1 -0
  159. package/dist/ripple/p-770d0798.entry.js +1 -0
  160. package/dist/ripple/p-846b4c5f.entry.js +1 -0
  161. package/dist/ripple/p-888bec42.js +1 -0
  162. package/dist/ripple/p-90779d53.entry.js +1 -0
  163. package/dist/ripple/p-934543f2.js +1 -0
  164. package/dist/ripple/p-9a087fee.entry.js +1 -0
  165. package/dist/ripple/p-a6d6eae7.js +1 -0
  166. package/dist/ripple/p-a942ad10.entry.js +1 -0
  167. package/dist/ripple/p-bfb4652d.entry.js +1 -0
  168. package/dist/ripple/p-c0fe5201.entry.js +1 -0
  169. package/dist/ripple/p-c2e27acc.entry.js +1 -0
  170. package/dist/ripple/p-c2edda64.entry.js +1 -0
  171. package/dist/ripple/p-d1fdcbcf.entry.js +1 -0
  172. package/dist/ripple/p-d40b6afb.entry.js +1 -0
  173. package/dist/ripple/p-da73db1c.entry.js +1 -0
  174. package/dist/ripple/p-e3843249.js +1 -0
  175. package/dist/ripple/p-ea5cd8b8.js +16 -0
  176. package/dist/ripple/p-ed0f43f4.entry.js +1 -0
  177. package/dist/ripple/p-ffafd363.entry.js +1 -0
  178. package/dist/ripple/ripple.esm.js +1 -125
  179. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +43 -0
  180. package/dist/types/components/wm-button/wm-button.d.ts +36 -0
  181. package/dist/types/components/wm-chart/priv-chart-popover/priv-chart-popover.d.ts +23 -0
  182. package/dist/types/components/wm-chart/wm-chart-slice.d.ts +8 -0
  183. package/dist/types/components/wm-chart/wm-chart.d.ts +77 -0
  184. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +75 -0
  185. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +39 -0
  186. package/dist/types/components/wm-input/wm-input.d.ts +30 -0
  187. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +30 -0
  188. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +15 -0
  189. package/dist/types/components/wm-modal/wm-modal-header.d.ts +12 -0
  190. package/dist/types/components/wm-modal/wm-modal.d.ts +34 -0
  191. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -0
  192. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -0
  193. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -0
  194. package/dist/types/components/wm-option/wm-option.d.ts +28 -0
  195. package/dist/types/components/wm-pagination/wm-pagination.d.ts +31 -0
  196. package/dist/types/components/wm-search/wm-search.d.ts +78 -0
  197. package/dist/types/components/wm-select/wm-select.d.ts +63 -0
  198. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +32 -0
  199. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +35 -0
  200. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +50 -0
  201. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -0
  202. package/dist/types/components/wm-tag-input/{wm-tag-input.d.ts~ds312_tagInputMaxTags → wm-tag-input.d.ts} +1 -1
  203. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +59 -0
  204. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +25 -0
  205. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -0
  206. package/dist/types/components/wm-uploader/wm-uploader.d.ts +75 -0
  207. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -0
  208. package/dist/types/{components.d.ts~ds312_tagInputMaxTags → components.d.ts} +0 -0
  209. package/dist/types/global/__mocks__/functions.d.ts +5 -0
  210. package/dist/types/global/global.d.ts +1 -0
  211. package/dist/types/global/interfaces.d.ts +33 -0
  212. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -0
  213. package/dist/types/global/services/http-service.d.ts +4 -0
  214. package/dist/types/lang/lang.d.ts +5 -0
  215. package/dist/types/{stencil-public-runtime.d.ts~ds312_tagInputMaxTags → stencil-public-runtime.d.ts} +190 -182
  216. package/package.json +1 -1
  217. package/dist/ripple/css-shim-bbdf0cc6.js +0 -4
  218. package/dist/ripple/dom-1f98a75f.js +0 -73
  219. package/dist/ripple/index-20b65f86.js +0 -2938
  220. package/dist/ripple/shadow-css-67b66845.js +0 -389
  221. package/dist/ripple/wm-menuitem.entry.js +0 -114
  222. package/dist/ripple/wm-option.entry.js +0 -119
  223. package/dist/ripple/wm-tab-item.entry.js +0 -78
  224. package/dist/ripple/wm-tab-panel.entry.js +0 -38
@@ -0,0 +1,754 @@
1
+ import { h, Component, Host, Element, Prop, Listen, State, Event, Watch } from "@stencil/core";
2
+ import { generateId, shouldOpenUp, intl } from "../../global/functions";
3
+ export class TagInput {
4
+ constructor() {
5
+ this.labelPosition = "top";
6
+ this.options = ""; // csv
7
+ this.selectedTags = ""; // csv
8
+ this.addNew = true;
9
+ this.characterLimit = 50;
10
+ this.uid = this.el.id ? this.el.id : generateId();
11
+ this.openUp = false;
12
+ this.isExpanded = false;
13
+ this.tagsList = this.csvToArray(this.selectedTags);
14
+ this.optionsList = this.csvToArray(this.options);
15
+ this.charCount = 0;
16
+ this.liveRegionMessage = "";
17
+ this.tagAreaInstructions = intl.formatMessage({
18
+ id: "tagInput.tagAreaInstructions",
19
+ defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
20
+ });
21
+ this.maxTagsReachedMessage = intl.formatMessage({
22
+ id: "tagInput.maxTagsReached",
23
+ defaultMessage: "The maximum amount of tags has been reached, no additional tags can be added.",
24
+ });
25
+ }
26
+ get focusedElement() {
27
+ return this.el.shadowRoot.activeElement;
28
+ }
29
+ get listItemEls() {
30
+ return Array.from(this.dropdownEl.querySelectorAll("li"));
31
+ }
32
+ get tagEls() {
33
+ return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
34
+ }
35
+ get optionEls() {
36
+ return Array.from(this.dropdownEl.querySelectorAll(".option"));
37
+ }
38
+ generateTagAddedMessage(tag) {
39
+ return intl.formatMessage({
40
+ id: "tagInput.tagAdded",
41
+ defaultMessage: "{tagName} added.",
42
+ description: "A confirmation for adding a tag.",
43
+ }, { tagName: tag });
44
+ }
45
+ generateTagAlreadyAddedMessage(tag) {
46
+ return intl.formatMessage({
47
+ id: "tagInput.tagAlreadyAdded",
48
+ defaultMessage: "{tagName} has already been added.",
49
+ description: "An alert for adding a tag that is already present.",
50
+ }, { tagName: tag });
51
+ }
52
+ generateTagCounterMessage() {
53
+ return intl.formatMessage({
54
+ id: "tagInput.tagsAddedCounter",
55
+ defaultMessage: "Tags added: {x, number}/{y, number}",
56
+ description: "For the user to understand how close they are to the tag limit.",
57
+ }, {
58
+ x: this.tagsList.length,
59
+ y: this.maxTags,
60
+ });
61
+ }
62
+ componentWillLoad() {
63
+ if (!this.placeholder) {
64
+ this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
65
+ }
66
+ if (!this.label) {
67
+ console.error("wm-tag-input must have a label property");
68
+ }
69
+ this.consolidateSelectedTags();
70
+ }
71
+ componentDidLoad() {
72
+ // prevent highlighting of pre-selected tags
73
+ this.tagEls.forEach((el) => el.classList.remove("highlight"));
74
+ }
75
+ consolidateSelectedTags() {
76
+ this.tagsList.forEach((tag) => {
77
+ if (!this.includesCaseInsensitive(this.optionsList, tag)) {
78
+ this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
79
+ }
80
+ });
81
+ this.optionsList = this.csvToArray(this.options);
82
+ }
83
+ createPlaceholderDefault(addNew, hasOptions) {
84
+ const addAndSearchPlaceholder = intl.formatMessage({
85
+ id: "tagInput.placeholderAddAndSearch",
86
+ defaultMessage: "Add or search for a tag",
87
+ });
88
+ const searchPlaceholder = intl.formatMessage({
89
+ id: "tagInput.placeholderSearch",
90
+ defaultMessage: "Search and select a tag",
91
+ });
92
+ const addPlaceholder = intl.formatMessage({
93
+ id: "tagInput.placeholderAdd",
94
+ defaultMessage: "Add a new tag",
95
+ });
96
+ let placeholder = "";
97
+ if (addNew && hasOptions) {
98
+ placeholder = addAndSearchPlaceholder;
99
+ }
100
+ else if (!addNew && hasOptions) {
101
+ placeholder = searchPlaceholder;
102
+ }
103
+ else if (addNew) {
104
+ placeholder = addPlaceholder;
105
+ }
106
+ return placeholder;
107
+ }
108
+ reflectSelectedTags() {
109
+ this.selectedTags = this.listToCSV(this.tagsList);
110
+ this.wmTagInputChanged.emit({ value: this.tagsList });
111
+ }
112
+ closeIfNotElOrChild(ev) {
113
+ const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
114
+ if (isntElOrChild && this.isExpanded) {
115
+ this.closeDropdown();
116
+ }
117
+ }
118
+ handleInputKeyDown(ev) {
119
+ if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
120
+ this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
121
+ }
122
+ // prevent keydown triggering on tag area
123
+ ev.stopPropagation();
124
+ switch (ev.key) {
125
+ case "Enter":
126
+ case ",":
127
+ ev.preventDefault();
128
+ this.submitInput(this.addNew, this.inputEl.value.trim());
129
+ break;
130
+ case "ArrowDown":
131
+ ev.preventDefault();
132
+ this.handleInputArrowDown();
133
+ break;
134
+ case "ArrowUp":
135
+ ev.preventDefault();
136
+ this.handleInputArrowUp();
137
+ break;
138
+ case "Escape":
139
+ if (this.isExpanded) {
140
+ this.closeDropdown();
141
+ }
142
+ break;
143
+ case "ArrowLeft":
144
+ case "Backspace":
145
+ this.handleInputBackspace();
146
+ break;
147
+ }
148
+ }
149
+ handleInputChanged(value) {
150
+ this.charCount = value.length;
151
+ if (this.charCount >= this.characterLimit - 5) {
152
+ this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
153
+ }
154
+ this.announceExistingOptions();
155
+ if (!this.isExpanded) {
156
+ this.openDropdown();
157
+ }
158
+ }
159
+ submitInput(canAddNew, value) {
160
+ if (canAddNew && value) {
161
+ this.tagsList = this.addTag(value);
162
+ this.optionsList = this.addOption(value);
163
+ this.resetInput();
164
+ // if maxTags has been reached, focus should go to the tagArea instead of the input
165
+ if (this.maxTags && this.tagsList.length >= this.maxTags) {
166
+ this.tagAreaEl.focus();
167
+ }
168
+ }
169
+ }
170
+ handleInputArrowDown() {
171
+ if (this.isExpanded) {
172
+ this.moveDownListItem();
173
+ }
174
+ else {
175
+ this.openDropdown();
176
+ }
177
+ }
178
+ handleInputArrowUp() {
179
+ if (this.isExpanded) {
180
+ this.moveUpListItem();
181
+ }
182
+ else {
183
+ this.openDropdown();
184
+ }
185
+ }
186
+ handleInputBackspace() {
187
+ if (this.inputEl.value === "" && this.tagsList.length > 0) {
188
+ // wait for events to finish firing before redirecting focus
189
+ // prevents double input in input area and tag area
190
+ window.requestAnimationFrame(() => {
191
+ this.tagAreaEl.focus();
192
+ this.focusTag(this.tagEls[this.tagEls.length - 1]);
193
+ });
194
+ }
195
+ }
196
+ handleListItemKeyDown(ev) {
197
+ const typedEvTarget = ev.target;
198
+ switch (ev.key) {
199
+ case "Enter":
200
+ case " ":
201
+ ev.preventDefault();
202
+ typedEvTarget.click();
203
+ break;
204
+ case "ArrowDown":
205
+ ev.preventDefault();
206
+ this.moveDownListItem();
207
+ break;
208
+ case "ArrowUp":
209
+ ev.preventDefault();
210
+ this.moveUpListItem();
211
+ break;
212
+ case "Escape":
213
+ if (this.focusedElement !== this.inputEl) {
214
+ this.inputEl.focus();
215
+ }
216
+ else {
217
+ this.closeDropdown();
218
+ }
219
+ break;
220
+ }
221
+ }
222
+ handleListItemClick(ev) {
223
+ const typedEvTarget = ev.target;
224
+ const tag = typedEvTarget.dataset.option.trim() || "";
225
+ if (this.includesCaseInsensitive(this.tagsList, tag)) {
226
+ this.announce(this.generateTagAlreadyAddedMessage(tag));
227
+ }
228
+ else {
229
+ this.announce(this.generateTagAddedMessage(tag));
230
+ this.resetInput();
231
+ this.tagsList = this.addTag(tag);
232
+ this.optionsList = this.addOption(tag);
233
+ this.focusedListItem = null;
234
+ // if maxTags has been reached, focus should go to the tagArea instead of the input
235
+ const elementToFocus = this.maxTags && this.tagsList.length >= this.maxTags ? this.tagAreaEl : this.inputEl;
236
+ elementToFocus.focus();
237
+ }
238
+ }
239
+ handleTagAreaKeyDown(ev) {
240
+ switch (ev.key) {
241
+ case "ArrowLeft":
242
+ case "ArrowUp":
243
+ ev.preventDefault();
244
+ this.moveLeftTag();
245
+ break;
246
+ case "ArrowRight":
247
+ case "ArrowDown":
248
+ ev.preventDefault();
249
+ this.moveRightTag();
250
+ break;
251
+ case "Backspace":
252
+ case "Delete":
253
+ this.handleTagAreaDelete();
254
+ break;
255
+ }
256
+ }
257
+ handleTagAreaDelete() {
258
+ if (this.focusedTag && this.focusedTag.dataset.tag) {
259
+ this.removeTag(this.focusedTag.dataset.tag);
260
+ if (this.tagsList.length === 0) {
261
+ // focus input if no tags are left
262
+ this.inputEl.focus();
263
+ }
264
+ else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
265
+ // reassign focus if removing the last tag but there are still tags remaining
266
+ this.focusedTag = this.tagEls[this.tagEls.length - 2];
267
+ this.focusTag(this.focusedTag);
268
+ }
269
+ }
270
+ }
271
+ handleBlur(ev, component) {
272
+ const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
273
+ if (isntElOrChild) {
274
+ this.closeDropdown();
275
+ this.fieldWrapperEl.classList.remove("focused");
276
+ }
277
+ }
278
+ handleTagAreaFocus() {
279
+ this.closeDropdown();
280
+ if (!this.focusedTag) {
281
+ this.focusedTag = this.tagEls[0];
282
+ }
283
+ this.focusTag(this.focusedTag);
284
+ }
285
+ handleRemoveButtonClick(tag) {
286
+ this.moveLeftTag();
287
+ this.removeTag(tag);
288
+ }
289
+ moveDownListItem() {
290
+ if (this.listItemEls.length > 0) {
291
+ const firstListItem = this.listItemEls[0];
292
+ if (!this.focusedListItem) {
293
+ this.focusListItem(firstListItem);
294
+ }
295
+ else if (this.focusedListItem.nextElementSibling) {
296
+ this.focusListItem(this.focusedListItem.nextElementSibling);
297
+ }
298
+ else {
299
+ this.focusListItem(firstListItem);
300
+ }
301
+ }
302
+ }
303
+ moveUpListItem() {
304
+ if (this.listItemEls.length > 0) {
305
+ const lastListItem = this.listItemEls[this.listItemEls.length - 1];
306
+ if (!this.focusedListItem) {
307
+ this.focusListItem(lastListItem);
308
+ }
309
+ else if (this.focusedListItem.previousElementSibling) {
310
+ this.focusListItem(this.focusedListItem.previousElementSibling);
311
+ }
312
+ else {
313
+ this.focusedListItem = null;
314
+ this.inputEl.focus();
315
+ }
316
+ }
317
+ }
318
+ moveLeftTag() {
319
+ const lastTag = this.tagEls[this.tagEls.length - 1];
320
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
321
+ this.focusedTag = this.focusedTag.previousElementSibling;
322
+ }
323
+ else {
324
+ this.focusedTag = lastTag;
325
+ }
326
+ this.focusTag(this.focusedTag);
327
+ }
328
+ moveRightTag() {
329
+ const firstTag = this.tagEls[0];
330
+ if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
331
+ this.focusedTag = this.focusedTag.nextElementSibling;
332
+ }
333
+ else {
334
+ this.focusedTag = firstTag;
335
+ }
336
+ this.focusTag(this.focusedTag);
337
+ }
338
+ addOption(option) {
339
+ let newOptionsList = this.optionsList;
340
+ const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
341
+ if (!optionAlreadyExists) {
342
+ newOptionsList = newOptionsList.concat(option);
343
+ }
344
+ return newOptionsList;
345
+ }
346
+ removeOption(option) {
347
+ this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
348
+ }
349
+ addTag(tag) {
350
+ let newTagsList = this.tagsList;
351
+ const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
352
+ const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
353
+ if (!tagAlreadyAdded) {
354
+ this.announce(this.generateTagAddedMessage(tag));
355
+ newTagsList = newTagsList.concat(tagExistsAsOption || tag);
356
+ }
357
+ return newTagsList;
358
+ }
359
+ removeTag(tag) {
360
+ const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: tag });
361
+ this.announce(tagRemovedMessage);
362
+ this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
363
+ const devOptionsList = this.csvToArray(this.options);
364
+ if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
365
+ this.removeOption(tag);
366
+ }
367
+ }
368
+ focusListItem(item) {
369
+ this.focusedListItem = item;
370
+ item.focus();
371
+ }
372
+ focusTag(element) {
373
+ this.focusedTag = element;
374
+ this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
375
+ }
376
+ clearTagFocus() {
377
+ this.tagAreaEl.removeAttribute("aria-activedescendant");
378
+ this.focusedTag = null;
379
+ }
380
+ openDropdown() {
381
+ this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight);
382
+ this.isExpanded = true;
383
+ }
384
+ closeDropdown() {
385
+ this.focusedListItem = null;
386
+ this.isExpanded = false;
387
+ }
388
+ clearListItemFocus() {
389
+ this.focusedListItem = null;
390
+ this.listItemEls.forEach((el) => {
391
+ el.tabIndex = -1;
392
+ el.classList.remove("focused");
393
+ });
394
+ }
395
+ resetInput() {
396
+ this.charCount = 0;
397
+ this.inputEl.value = "";
398
+ }
399
+ announce(message) {
400
+ // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
401
+ if (this.liveRegionEl.textContent === message) {
402
+ message += "\u00A0";
403
+ }
404
+ this.liveRegionMessage = message;
405
+ }
406
+ announceExistingOptions() {
407
+ // request animation frame to wait for re-rendering of filtered options
408
+ window.requestAnimationFrame(() => {
409
+ const existingOptionsMessage = intl.formatMessage({
410
+ id: "tagInput.existingOptions",
411
+ defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
412
+ }, { num: this.optionEls.length });
413
+ if (this.optionEls.length > 0) {
414
+ this.announce(existingOptionsMessage);
415
+ }
416
+ });
417
+ }
418
+ announceCharacterLimitWarning(charCount, charLimit) {
419
+ const charactersEnteredMessage = intl.formatMessage({
420
+ id: "tagInput.charactersEntered",
421
+ defaultMessage: "{x, number} of {y, number} characters entered.",
422
+ }, { x: charCount, y: charLimit });
423
+ const characterLimitReachedMessage = intl.formatMessage({
424
+ id: "tagInput.characterLimitReached",
425
+ defaultMessage: "No additional characters will be entered.",
426
+ });
427
+ this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
428
+ }
429
+ /// Helpers
430
+ listToCSV(list) {
431
+ return list.join(",");
432
+ }
433
+ csvToArray(csv) {
434
+ return csv ? csv.split(/, ?/) : [];
435
+ }
436
+ includesCaseInsensitive(list, element) {
437
+ const lowercaseList = list.map((str) => str.toLowerCase());
438
+ return lowercaseList.includes(element.toLowerCase());
439
+ }
440
+ filterCaseInsensitive(list, element) {
441
+ return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
442
+ }
443
+ sortCaseInsensitive(list) {
444
+ // The vanilla .sort method places words that start with capital letters above others (ASCII order)
445
+ // so we need to pass in our own compare function to sort case-insensitive
446
+ return list.sort((a, b) => {
447
+ a = a.toLowerCase();
448
+ b = b.toLowerCase();
449
+ return a > b ? 1 : a < b ? -1 : 0;
450
+ });
451
+ }
452
+ /// Renders
453
+ renderTags() {
454
+ return this.tagsList.map((tag, idx) => {
455
+ const id = `tag${idx + 1}`;
456
+ return (h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""}`, "data-tag": tag, role: "option" },
457
+ tag,
458
+ h("button", { class: "remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) })));
459
+ });
460
+ }
461
+ renderListItems(optionsList) {
462
+ optionsList = this.sortCaseInsensitive(optionsList);
463
+ // filter by input
464
+ if (this.inputEl && this.inputEl.value) {
465
+ optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
466
+ }
467
+ return optionsList.map((option, idx) => {
468
+ const id = `option${idx + 1}`;
469
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
470
+ const isSelected = this.includesCaseInsensitive(this.tagsList, option);
471
+ return (h("li", { class: `option ${isFocused ? "focused" : ""}`, role: "option", id: id, "data-option": option, tabIndex: isFocused ? 0 : -1, "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) }, option));
472
+ });
473
+ }
474
+ renderAddNewButton() {
475
+ if (this.inputEl.value.length > 0 &&
476
+ this.addNew &&
477
+ !this.includesCaseInsensitive(this.optionsList, this.inputEl.value)) {
478
+ const id = `add-new-btn`;
479
+ const isFocused = this.focusedListItem && this.focusedListItem.id === id;
480
+ return (h("li", { role: "option", class: `add-new-btn ${isFocused ? "focused" : ""}`, id: id, "data-option": this.inputEl.value, onKeyDown: (ev) => this.handleListItemKeyDown(ev), onBlur: (ev) => this.handleBlur(ev, this.el), onClick: (ev) => this.handleListItemClick(ev), tabIndex: isFocused ? 0 : -1 }, `Add "${this.inputEl.value}"`));
481
+ }
482
+ else
483
+ return "";
484
+ }
485
+ renderHelpText() {
486
+ const helpTextHasOptions = intl.formatMessage({
487
+ id: "tagInput.helpTextCanSelect",
488
+ defaultMessage: "Search and select a tag.",
489
+ });
490
+ const helpTextEditable = intl.formatMessage({
491
+ id: "tagInput.helpTextEditable",
492
+ defaultMessage: "Press the Enter or Comma key to add a new tag.",
493
+ });
494
+ let helpText = "";
495
+ if (this.optionsList.length > 0) {
496
+ helpText += helpTextHasOptions;
497
+ }
498
+ if (this.addNew) {
499
+ helpText += " " + helpTextEditable;
500
+ }
501
+ return helpText;
502
+ }
503
+ renderTagCounter() {
504
+ if (this.maxTags) {
505
+ return (h("div", { class: "lower-row" },
506
+ h("div", { id: "max-tags" },
507
+ this.generateTagCounterMessage(),
508
+ this.tagsList.length >= this.maxTags && h("span", { class: "sr-only" }, this.maxTagsReachedMessage))));
509
+ }
510
+ }
511
+ render() {
512
+ const isFocused = this.focusedElement &&
513
+ (this.focusedElement === this.inputEl ||
514
+ this.focusedElement === this.tagAreaEl ||
515
+ this.focusedElement.classList.contains("add-new-btn") ||
516
+ (this.optionsList.length > 0 && this.listItemEls.includes(this.focusedElement)));
517
+ return (h(Host, { id: this.uid },
518
+ h("div", { class: `wrapper label-${this.labelPosition}` },
519
+ h("div", { class: "label-wrapper" },
520
+ h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)),
521
+ h("div", { class: `field-wrapper ${isFocused ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) },
522
+ h("div", { class: "upper-row" },
523
+ h("div", { class: "tags-and-input-wrapper" },
524
+ h("ul", { ref: (el) => (this.tagAreaEl = el), class: "tag-area", role: "listbox", "aria-horizontal": "true", "aria-label": this.tagsList.length > 0 && `${this.label} ${this.tagAreaInstructions}`, tabindex: this.tagsList.length > 0 ? 0 : -1, "aria-describedby": `info max-tags`, onFocus: () => this.handleTagAreaFocus(), onBlur: (ev) => {
525
+ this.clearTagFocus();
526
+ this.handleBlur(ev, this.el);
527
+ }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) },
528
+ this.renderTags(),
529
+ h("div", { class: "input-wrapper", role: "none" },
530
+ h("input", { id: `input${this.uid}`, class: this.maxTags && this.tagsList.length >= this.maxTags ? "hidden" : "", role: "combobox", ref: (el) => (this.inputEl = el), autocomplete: "off", "aria-controls": "dropdown", "aria-describedby": "help-text", "aria-label": this.label, placeholder: this.placeholder, maxLength: this.characterLimit, onInput: () => this.handleInputChanged(this.inputEl.value), onBlur: (ev) => {
531
+ this.handleBlur(ev, this.el);
532
+ }, onFocus: () => {
533
+ this.openDropdown();
534
+ this.clearListItemFocus();
535
+ }, onKeyDown: (ev) => this.handleInputKeyDown(ev) })))),
536
+ h("div", { class: "character-count" },
537
+ this.charCount,
538
+ "/",
539
+ this.characterLimit)),
540
+ this.renderTagCounter(),
541
+ h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}` },
542
+ h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()),
543
+ h("ul", { class: "dropdown", ref: (el) => (this.dropdownEl = el), id: "dropdown", role: "listbox", "aria-multiselectable": "true", "aria-expanded": this.isExpanded ? "true" : false, "aria-label": this.label, tabindex: -1 },
544
+ this.inputEl && this.renderAddNewButton(),
545
+ this.renderListItems(this.optionsList)))),
546
+ this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""),
547
+ h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage))));
548
+ }
549
+ static get is() { return "wm-tag-input"; }
550
+ static get encapsulation() { return "shadow"; }
551
+ static get originalStyleUrls() { return {
552
+ "$": ["wm-tag-input.scss"]
553
+ }; }
554
+ static get styleUrls() { return {
555
+ "$": ["wm-tag-input.css"]
556
+ }; }
557
+ static get properties() { return {
558
+ "label": {
559
+ "type": "string",
560
+ "mutable": false,
561
+ "complexType": {
562
+ "original": "string",
563
+ "resolved": "string",
564
+ "references": {}
565
+ },
566
+ "required": true,
567
+ "optional": false,
568
+ "docs": {
569
+ "tags": [],
570
+ "text": ""
571
+ },
572
+ "attribute": "label",
573
+ "reflect": false
574
+ },
575
+ "labelPosition": {
576
+ "type": "string",
577
+ "mutable": false,
578
+ "complexType": {
579
+ "original": "\"top\" | \"left\" | \"none\"",
580
+ "resolved": "\"left\" | \"none\" | \"top\"",
581
+ "references": {}
582
+ },
583
+ "required": false,
584
+ "optional": false,
585
+ "docs": {
586
+ "tags": [],
587
+ "text": ""
588
+ },
589
+ "attribute": "label-position",
590
+ "reflect": false,
591
+ "defaultValue": "\"top\""
592
+ },
593
+ "options": {
594
+ "type": "string",
595
+ "mutable": true,
596
+ "complexType": {
597
+ "original": "string",
598
+ "resolved": "string",
599
+ "references": {}
600
+ },
601
+ "required": false,
602
+ "optional": false,
603
+ "docs": {
604
+ "tags": [],
605
+ "text": ""
606
+ },
607
+ "attribute": "options",
608
+ "reflect": false,
609
+ "defaultValue": "\"\""
610
+ },
611
+ "selectedTags": {
612
+ "type": "string",
613
+ "mutable": true,
614
+ "complexType": {
615
+ "original": "string",
616
+ "resolved": "string",
617
+ "references": {}
618
+ },
619
+ "required": false,
620
+ "optional": false,
621
+ "docs": {
622
+ "tags": [],
623
+ "text": ""
624
+ },
625
+ "attribute": "selected-tags",
626
+ "reflect": true,
627
+ "defaultValue": "\"\""
628
+ },
629
+ "info": {
630
+ "type": "string",
631
+ "mutable": false,
632
+ "complexType": {
633
+ "original": "string",
634
+ "resolved": "string | undefined",
635
+ "references": {}
636
+ },
637
+ "required": false,
638
+ "optional": true,
639
+ "docs": {
640
+ "tags": [],
641
+ "text": ""
642
+ },
643
+ "attribute": "info",
644
+ "reflect": false
645
+ },
646
+ "addNew": {
647
+ "type": "boolean",
648
+ "mutable": false,
649
+ "complexType": {
650
+ "original": "boolean",
651
+ "resolved": "boolean",
652
+ "references": {}
653
+ },
654
+ "required": false,
655
+ "optional": false,
656
+ "docs": {
657
+ "tags": [],
658
+ "text": ""
659
+ },
660
+ "attribute": "add-new",
661
+ "reflect": false,
662
+ "defaultValue": "true"
663
+ },
664
+ "placeholder": {
665
+ "type": "string",
666
+ "mutable": true,
667
+ "complexType": {
668
+ "original": "string",
669
+ "resolved": "string | undefined",
670
+ "references": {}
671
+ },
672
+ "required": false,
673
+ "optional": true,
674
+ "docs": {
675
+ "tags": [],
676
+ "text": ""
677
+ },
678
+ "attribute": "placeholder",
679
+ "reflect": false
680
+ },
681
+ "characterLimit": {
682
+ "type": "number",
683
+ "mutable": false,
684
+ "complexType": {
685
+ "original": "number",
686
+ "resolved": "number",
687
+ "references": {}
688
+ },
689
+ "required": false,
690
+ "optional": false,
691
+ "docs": {
692
+ "tags": [],
693
+ "text": ""
694
+ },
695
+ "attribute": "character-limit",
696
+ "reflect": false,
697
+ "defaultValue": "50"
698
+ },
699
+ "maxTags": {
700
+ "type": "number",
701
+ "mutable": false,
702
+ "complexType": {
703
+ "original": "number",
704
+ "resolved": "number | undefined",
705
+ "references": {}
706
+ },
707
+ "required": false,
708
+ "optional": true,
709
+ "docs": {
710
+ "tags": [],
711
+ "text": ""
712
+ },
713
+ "attribute": "max-tags",
714
+ "reflect": false
715
+ }
716
+ }; }
717
+ static get states() { return {
718
+ "focusedListItem": {},
719
+ "focusedTag": {},
720
+ "isExpanded": {},
721
+ "tagsList": {},
722
+ "optionsList": {},
723
+ "charCount": {},
724
+ "liveRegionMessage": {}
725
+ }; }
726
+ static get events() { return [{
727
+ "method": "wmTagInputChanged",
728
+ "name": "wmTagInputChanged",
729
+ "bubbles": true,
730
+ "cancelable": true,
731
+ "composed": true,
732
+ "docs": {
733
+ "tags": [],
734
+ "text": ""
735
+ },
736
+ "complexType": {
737
+ "original": "{ value: string[] }",
738
+ "resolved": "{ value: string[]; }",
739
+ "references": {}
740
+ }
741
+ }]; }
742
+ static get elementRef() { return "el"; }
743
+ static get watchers() { return [{
744
+ "propName": "tagsList",
745
+ "methodName": "reflectSelectedTags"
746
+ }]; }
747
+ static get listeners() { return [{
748
+ "name": "click",
749
+ "method": "closeIfNotElOrChild",
750
+ "target": "document",
751
+ "capture": false,
752
+ "passive": false
753
+ }]; }
754
+ }