@watermarkinsights/ripple 3.0.1 → 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 (81) hide show
  1. package/dist/cjs/{global-ccb9500c.js → global-1e540de6.js} +1 -1
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/priv-datepicker.cjs.entry.js +1 -1
  4. package/dist/cjs/ripple.cjs.js +2 -2
  5. package/dist/cjs/wm-datepicker.cjs.entry.js +25 -30
  6. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.css +9 -0
  7. package/dist/collection/components/wm-datepicker/wm-datepicker.js +26 -32
  8. package/dist/esm/{global-4f914bb2.js → global-d6b49e98.js} +1 -1
  9. package/dist/esm/loader.js +2 -2
  10. package/dist/esm/priv-datepicker.entry.js +1 -1
  11. package/dist/esm/ripple.js +2 -2
  12. package/dist/esm/wm-datepicker.entry.js +25 -30
  13. package/dist/ripple/p-129d94fa.entry.js +1 -0
  14. package/dist/ripple/{p-454ad552.entry.js → p-c0fe5201.entry.js} +1 -1
  15. package/dist/ripple/{p-69a73e86.js → p-e3843249.js} +1 -1
  16. package/dist/ripple/ripple.esm.js +1 -1
  17. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +3 -3
  18. package/package.json +1 -1
  19. package/dist/cjs/app-globals-a07327ae.js +0 -47
  20. package/dist/cjs/css-shim-a7379e2b.js +0 -6
  21. package/dist/cjs/dom-3e7d9c3b.js +0 -75
  22. package/dist/cjs/functions-65513c61.js +0 -8360
  23. package/dist/cjs/global-06317e3f.js +0 -36
  24. package/dist/cjs/global-f6930bb0.js +0 -38
  25. package/dist/cjs/index-8dea8c13.js +0 -2976
  26. package/dist/cjs/shadow-css-09555044.js +0 -391
  27. package/dist/esm/app-globals-f62991a4.js +0 -45
  28. package/dist/esm/css-shim-bbdf0cc6.js +0 -4
  29. package/dist/esm/dom-1f98a75f.js +0 -73
  30. package/dist/esm/functions-316c1b23.js +0 -8340
  31. package/dist/esm/global-03372f70.js +0 -34
  32. package/dist/esm/global-fedbc323.js +0 -36
  33. package/dist/esm/index-e34aa595.js +0 -2938
  34. package/dist/esm/shadow-css-67b66845.js +0 -389
  35. package/dist/ripple/app-globals-b5693c90.js +0 -45
  36. package/dist/ripple/app-globals-d72c2d3c.js +0 -45
  37. package/dist/ripple/app-globals-f62991a4.js +0 -45
  38. package/dist/ripple/css-shim-bbdf0cc6.js +0 -4
  39. package/dist/ripple/dom-1f98a75f.js +0 -73
  40. package/dist/ripple/functions-316c1b23.js +0 -8340
  41. package/dist/ripple/http-service-5d037e16.js +0 -52
  42. package/dist/ripple/index-20b65f86.js +0 -2938
  43. package/dist/ripple/index-e34aa595.js +0 -2938
  44. package/dist/ripple/interfaces-50753346.js +0 -51
  45. package/dist/ripple/p-0c2498f4.js +0 -1
  46. package/dist/ripple/p-42ca2e15.entry.js +0 -1
  47. package/dist/ripple/p-e91befe3.js +0 -1
  48. package/dist/ripple/priv-chart-popover.entry.js +0 -85
  49. package/dist/ripple/priv-datepicker.entry.js +0 -668
  50. package/dist/ripple/priv-navigator-button.entry.js +0 -25
  51. package/dist/ripple/priv-navigator-item.entry.js +0 -30
  52. package/dist/ripple/ripple.css +0 -84
  53. package/dist/ripple/shadow-css-67b66845.js +0 -389
  54. package/dist/ripple/wm-action-menu.entry.js +0 -202
  55. package/dist/ripple/wm-button.entry.js +0 -148
  56. package/dist/ripple/wm-chart-slice.entry.js +0 -18
  57. package/dist/ripple/wm-chart.entry.js +0 -504
  58. package/dist/ripple/wm-datepicker.entry.js +0 -258
  59. package/dist/ripple/wm-input.entry.js +0 -106
  60. package/dist/ripple/wm-menuitem.entry.js +0 -114
  61. package/dist/ripple/wm-modal-footer.entry.js +0 -39
  62. package/dist/ripple/wm-modal-header.entry.js +0 -41
  63. package/dist/ripple/wm-modal.entry.js +0 -145
  64. package/dist/ripple/wm-navigator.entry.js +0 -275
  65. package/dist/ripple/wm-network-uploader.entry.js +0 -427
  66. package/dist/ripple/wm-option.entry.js +0 -119
  67. package/dist/ripple/wm-pagination.entry.js +0 -172
  68. package/dist/ripple/wm-search.entry.js +0 -227
  69. package/dist/ripple/wm-select.entry.js +0 -362
  70. package/dist/ripple/wm-snackbar.entry.js +0 -156
  71. package/dist/ripple/wm-tab-item.entry.js +0 -78
  72. package/dist/ripple/wm-tab-list.entry.js +0 -201
  73. package/dist/ripple/wm-tab-panel.entry.js +0 -38
  74. package/dist/ripple/wm-tag-input.entry.js +0 -534
  75. package/dist/ripple/wm-timepicker.entry.js +0 -382
  76. package/dist/ripple/wm-toggletip.entry.js +0 -124
  77. package/dist/ripple/wm-uploader.entry.js +0 -338
  78. package/dist/ripple/wm-wrapper.entry.js +0 -17
  79. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts~ds312_tagInputMaxTags +0 -87
  80. package/dist/types/components.d.ts~ds312_tagInputMaxTags +0 -879
  81. package/dist/types/stencil-public-runtime.d.ts~ds312_tagInputMaxTags +0 -1555
@@ -1,534 +0,0 @@
1
- import { r as registerInstance, e as createEvent, h, f as Host, g as getElement } from './index-e34aa595.js';
2
- import { g as generateId, i as intl, a as shouldOpenUp } from './functions-316c1b23.js';
3
-
4
- const wmTagInputCss = "@charset \"UTF-8\";:host,wm-tag-input{font-family:inherit;width:100%}:host *,wm-tag-input *{box-sizing:border-box;font-size:14px}:host .wrapper,wm-tag-input .wrapper{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;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{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:flex;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;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:\"\";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%;position:relative}:host .field-wrapper,wm-tag-input .field-wrapper{position:relative;min-height:2.5rem;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:flex;align-items:center;justify-content:center;min-width:5rem;background-color:rgba(74, 74, 74, 0.05);font-size:0.875rem;font-weight:500;align-self:stretch}:host .tags-and-input-wrapper,wm-tag-input .tags-and-input-wrapper{width:100%;padding:0.5rem 0.25rem;margin-bottom:-0.5rem}:host .upper-row,wm-tag-input .upper-row{width:100%;display:flex;flex:1;justify-content:space-between;align-items:center}:host .lower-row,wm-tag-input .lower-row{width:100%;border-radius:0 0 3px 3px}:host #max-tags,wm-tag-input #max-tags{display:flex;align-items:center;height:1.875rem;background-color:#6b6b6b;padding:0.5rem 1rem;color:white;font-size:0.875rem}:host .tag-area,wm-tag-input .tag-area{display:flex;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:inline-flex;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;transition:background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1)}:host .tag-area [role=option].highlight,wm-tag-input .tag-area [role=option].highlight{animation:fadeIn 1s}@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] .remove-btn,wm-tag-input .tag-area [role=option] .remove-btn{display:inline-flex;justify-content:center;align-items:center;height:1.25rem;width:1.25rem;border:1px solid #575195;color:#575195;border-radius:50%;padding:0;margin-left:0.5rem;cursor:pointer;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] .remove-btn:hover,wm-tag-input .tag-area [role=option] .remove-btn:hover{color:white;background-color:#575195}:host .tag-area [role=option] .remove-btn:before,wm-tag-input .tag-area [role=option] .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:\"\"}:host .input-wrapper,wm-tag-input .input-wrapper{flex:1 0 150px}:host .input-wrapper input,wm-tag-input .input-wrapper input{font-family:inherit;border:none;height:1.75rem;padding:0;margin-bottom:0.5rem;margin-right:0.25rem;margin-left:0.25rem;width:100%}:host .input-wrapper input.hidden,wm-tag-input .input-wrapper input.hidden{display:none}:host .input-wrapper input:focus,wm-tag-input .input-wrapper 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;transition: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:flex;align-items:center;padding:0 1rem;background:#fff;list-style:none;height:2.6875rem}: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}: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 .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;clip-path:inset(50%) !important;white-space:nowrap !important;margin:-1px !important}";
5
-
6
- const TagInput = class {
7
- constructor(hostRef) {
8
- registerInstance(this, hostRef);
9
- this.wmTagInputChanged = createEvent(this, "wmTagInputChanged", 7);
10
- this.labelPosition = "top";
11
- this.options = ""; // csv
12
- this.selectedTags = ""; // csv
13
- this.addNew = true;
14
- this.characterLimit = 50;
15
- this.uid = this.el.id ? this.el.id : generateId();
16
- this.openUp = false;
17
- this.isExpanded = false;
18
- this.tagsList = this.csvToArray(this.selectedTags);
19
- this.optionsList = this.csvToArray(this.options);
20
- this.charCount = 0;
21
- this.liveRegionMessage = "";
22
- this.tagAreaInstructions = intl.formatMessage({
23
- id: "tagInput.tagAreaInstructions",
24
- defaultMessage: "tag selection. Press Backspace or Delete to remove a tag.",
25
- });
26
- this.maxTagsReachedMessage = intl.formatMessage({
27
- id: "tagInput.maxTagsReached",
28
- defaultMessage: "The maximum amount of tags has been reached, no additional tags can be added.",
29
- });
30
- }
31
- get focusedElement() {
32
- return this.el.shadowRoot.activeElement;
33
- }
34
- get listItemEls() {
35
- return Array.from(this.dropdownEl.querySelectorAll("li"));
36
- }
37
- get tagEls() {
38
- return Array.from(this.tagAreaEl.querySelectorAll(".tag"));
39
- }
40
- get optionEls() {
41
- return Array.from(this.dropdownEl.querySelectorAll(".option"));
42
- }
43
- generateTagAddedMessage(tag) {
44
- return intl.formatMessage({
45
- id: "tagInput.tagAdded",
46
- defaultMessage: "{tagName} added.",
47
- description: "A confirmation for adding a tag.",
48
- }, { tagName: tag });
49
- }
50
- generateTagAlreadyAddedMessage(tag) {
51
- return intl.formatMessage({
52
- id: "tagInput.tagAlreadyAdded",
53
- defaultMessage: "{tagName} has already been added.",
54
- description: "An alert for adding a tag that is already present.",
55
- }, { tagName: tag });
56
- }
57
- generateTagCounterMessage() {
58
- return intl.formatMessage({
59
- id: "tagInput.tagsAddedCounter",
60
- defaultMessage: "Tags added: {x, number}/{y, number}",
61
- description: "For the user to understand how close they are to the tag limit.",
62
- }, {
63
- x: this.tagsList.length,
64
- y: this.maxTags,
65
- });
66
- }
67
- componentWillLoad() {
68
- if (!this.placeholder) {
69
- this.placeholder = this.createPlaceholderDefault(this.addNew, !!this.options);
70
- }
71
- if (!this.label) {
72
- console.error("wm-tag-input must have a label property");
73
- }
74
- this.consolidateSelectedTags();
75
- }
76
- componentDidLoad() {
77
- // prevent highlighting of pre-selected tags
78
- this.tagEls.forEach((el) => el.classList.remove("highlight"));
79
- }
80
- consolidateSelectedTags() {
81
- this.tagsList.forEach((tag) => {
82
- if (!this.includesCaseInsensitive(this.optionsList, tag)) {
83
- this.options += `${this.options.length > 0 ? "," : ""}${tag}`;
84
- }
85
- });
86
- this.optionsList = this.csvToArray(this.options);
87
- }
88
- createPlaceholderDefault(addNew, hasOptions) {
89
- const addAndSearchPlaceholder = intl.formatMessage({
90
- id: "tagInput.placeholderAddAndSearch",
91
- defaultMessage: "Add or search for a tag",
92
- });
93
- const searchPlaceholder = intl.formatMessage({
94
- id: "tagInput.placeholderSearch",
95
- defaultMessage: "Search and select a tag",
96
- });
97
- const addPlaceholder = intl.formatMessage({
98
- id: "tagInput.placeholderAdd",
99
- defaultMessage: "Add a new tag",
100
- });
101
- let placeholder = "";
102
- if (addNew && hasOptions) {
103
- placeholder = addAndSearchPlaceholder;
104
- }
105
- else if (!addNew && hasOptions) {
106
- placeholder = searchPlaceholder;
107
- }
108
- else if (addNew) {
109
- placeholder = addPlaceholder;
110
- }
111
- return placeholder;
112
- }
113
- reflectSelectedTags() {
114
- this.selectedTags = this.listToCSV(this.tagsList);
115
- this.wmTagInputChanged.emit({ value: this.tagsList });
116
- }
117
- closeIfNotElOrChild(ev) {
118
- const isntElOrChild = ev.target !== this.el && !this.el.shadowRoot.contains(ev.target);
119
- if (isntElOrChild && this.isExpanded) {
120
- this.closeDropdown();
121
- }
122
- }
123
- handleInputKeyDown(ev) {
124
- if (/^.$/.test(ev.key) && this.inputEl.value.length >= this.characterLimit) {
125
- this.announceCharacterLimitWarning(this.inputEl.value.length, this.characterLimit);
126
- }
127
- // prevent keydown triggering on tag area
128
- ev.stopPropagation();
129
- switch (ev.key) {
130
- case "Enter":
131
- case ",":
132
- ev.preventDefault();
133
- this.submitInput(this.addNew, this.inputEl.value.trim());
134
- break;
135
- case "ArrowDown":
136
- ev.preventDefault();
137
- this.handleInputArrowDown();
138
- break;
139
- case "ArrowUp":
140
- ev.preventDefault();
141
- this.handleInputArrowUp();
142
- break;
143
- case "Escape":
144
- if (this.isExpanded) {
145
- this.closeDropdown();
146
- }
147
- break;
148
- case "ArrowLeft":
149
- case "Backspace":
150
- this.handleInputBackspace();
151
- break;
152
- }
153
- }
154
- handleInputChanged(value) {
155
- this.charCount = value.length;
156
- if (this.charCount >= this.characterLimit - 5) {
157
- this.announceCharacterLimitWarning(this.charCount, this.characterLimit);
158
- }
159
- this.announceExistingOptions();
160
- if (!this.isExpanded) {
161
- this.openDropdown();
162
- }
163
- }
164
- submitInput(canAddNew, value) {
165
- if (canAddNew && value) {
166
- this.tagsList = this.addTag(value);
167
- this.optionsList = this.addOption(value);
168
- this.resetInput();
169
- // if maxTags has been reached, focus should go to the tagArea instead of the input
170
- if (this.maxTags && this.tagsList.length >= this.maxTags) {
171
- this.tagAreaEl.focus();
172
- }
173
- }
174
- }
175
- handleInputArrowDown() {
176
- if (this.isExpanded) {
177
- this.moveDownListItem();
178
- }
179
- else {
180
- this.openDropdown();
181
- }
182
- }
183
- handleInputArrowUp() {
184
- if (this.isExpanded) {
185
- this.moveUpListItem();
186
- }
187
- else {
188
- this.openDropdown();
189
- }
190
- }
191
- handleInputBackspace() {
192
- if (this.inputEl.value === "" && this.tagsList.length > 0) {
193
- // wait for events to finish firing before redirecting focus
194
- // prevents double input in input area and tag area
195
- window.requestAnimationFrame(() => {
196
- this.tagAreaEl.focus();
197
- this.focusTag(this.tagEls[this.tagEls.length - 1]);
198
- });
199
- }
200
- }
201
- handleListItemKeyDown(ev) {
202
- const typedEvTarget = ev.target;
203
- switch (ev.key) {
204
- case "Enter":
205
- case " ":
206
- ev.preventDefault();
207
- typedEvTarget.click();
208
- break;
209
- case "ArrowDown":
210
- ev.preventDefault();
211
- this.moveDownListItem();
212
- break;
213
- case "ArrowUp":
214
- ev.preventDefault();
215
- this.moveUpListItem();
216
- break;
217
- case "Escape":
218
- if (this.focusedElement !== this.inputEl) {
219
- this.inputEl.focus();
220
- }
221
- else {
222
- this.closeDropdown();
223
- }
224
- break;
225
- }
226
- }
227
- handleListItemClick(ev) {
228
- const typedEvTarget = ev.target;
229
- const tag = typedEvTarget.dataset.option.trim() || "";
230
- if (this.includesCaseInsensitive(this.tagsList, tag)) {
231
- this.announce(this.generateTagAlreadyAddedMessage(tag));
232
- }
233
- else {
234
- this.announce(this.generateTagAddedMessage(tag));
235
- this.resetInput();
236
- this.tagsList = this.addTag(tag);
237
- this.optionsList = this.addOption(tag);
238
- this.focusedListItem = null;
239
- // if maxTags has been reached, focus should go to the tagArea instead of the input
240
- const elementToFocus = this.maxTags && this.tagsList.length >= this.maxTags ? this.tagAreaEl : this.inputEl;
241
- elementToFocus.focus();
242
- }
243
- }
244
- handleTagAreaKeyDown(ev) {
245
- switch (ev.key) {
246
- case "ArrowLeft":
247
- case "ArrowUp":
248
- ev.preventDefault();
249
- this.moveLeftTag();
250
- break;
251
- case "ArrowRight":
252
- case "ArrowDown":
253
- ev.preventDefault();
254
- this.moveRightTag();
255
- break;
256
- case "Backspace":
257
- case "Delete":
258
- this.handleTagAreaDelete();
259
- break;
260
- }
261
- }
262
- handleTagAreaDelete() {
263
- if (this.focusedTag && this.focusedTag.dataset.tag) {
264
- this.removeTag(this.focusedTag.dataset.tag);
265
- if (this.tagsList.length === 0) {
266
- // focus input if no tags are left
267
- this.inputEl.focus();
268
- }
269
- else if (this.focusedTag === this.tagEls[this.tagEls.length - 1]) {
270
- // reassign focus if removing the last tag but there are still tags remaining
271
- this.focusedTag = this.tagEls[this.tagEls.length - 2];
272
- this.focusTag(this.focusedTag);
273
- }
274
- }
275
- }
276
- handleBlur(ev, component) {
277
- const isntElOrChild = ev.relatedTarget !== component && !this.el.shadowRoot.contains(ev.relatedTarget);
278
- if (isntElOrChild) {
279
- this.closeDropdown();
280
- this.fieldWrapperEl.classList.remove("focused");
281
- }
282
- }
283
- handleTagAreaFocus() {
284
- this.closeDropdown();
285
- if (!this.focusedTag) {
286
- this.focusedTag = this.tagEls[0];
287
- }
288
- this.focusTag(this.focusedTag);
289
- }
290
- handleRemoveButtonClick(tag) {
291
- this.moveLeftTag();
292
- this.removeTag(tag);
293
- }
294
- moveDownListItem() {
295
- if (this.listItemEls.length > 0) {
296
- const firstListItem = this.listItemEls[0];
297
- if (!this.focusedListItem) {
298
- this.focusListItem(firstListItem);
299
- }
300
- else if (this.focusedListItem.nextElementSibling) {
301
- this.focusListItem(this.focusedListItem.nextElementSibling);
302
- }
303
- else {
304
- this.focusListItem(firstListItem);
305
- }
306
- }
307
- }
308
- moveUpListItem() {
309
- if (this.listItemEls.length > 0) {
310
- const lastListItem = this.listItemEls[this.listItemEls.length - 1];
311
- if (!this.focusedListItem) {
312
- this.focusListItem(lastListItem);
313
- }
314
- else if (this.focusedListItem.previousElementSibling) {
315
- this.focusListItem(this.focusedListItem.previousElementSibling);
316
- }
317
- else {
318
- this.focusedListItem = null;
319
- this.inputEl.focus();
320
- }
321
- }
322
- }
323
- moveLeftTag() {
324
- const lastTag = this.tagEls[this.tagEls.length - 1];
325
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.previousElementSibling)) {
326
- this.focusedTag = this.focusedTag.previousElementSibling;
327
- }
328
- else {
329
- this.focusedTag = lastTag;
330
- }
331
- this.focusTag(this.focusedTag);
332
- }
333
- moveRightTag() {
334
- const firstTag = this.tagEls[0];
335
- if (this.focusedTag && this.tagEls.includes(this.focusedTag.nextElementSibling)) {
336
- this.focusedTag = this.focusedTag.nextElementSibling;
337
- }
338
- else {
339
- this.focusedTag = firstTag;
340
- }
341
- this.focusTag(this.focusedTag);
342
- }
343
- addOption(option) {
344
- let newOptionsList = this.optionsList;
345
- const optionAlreadyExists = this.includesCaseInsensitive(this.optionsList, option);
346
- if (!optionAlreadyExists) {
347
- newOptionsList = newOptionsList.concat(option);
348
- }
349
- return newOptionsList;
350
- }
351
- removeOption(option) {
352
- this.optionsList = this.filterCaseInsensitive(this.optionsList, option);
353
- }
354
- addTag(tag) {
355
- let newTagsList = this.tagsList;
356
- const tagAlreadyAdded = this.includesCaseInsensitive(this.tagsList, tag);
357
- const tagExistsAsOption = this.optionsList.filter((x) => x.toLowerCase() === tag.toLowerCase())[0];
358
- if (!tagAlreadyAdded) {
359
- this.announce(this.generateTagAddedMessage(tag));
360
- newTagsList = newTagsList.concat(tagExistsAsOption || tag);
361
- }
362
- return newTagsList;
363
- }
364
- removeTag(tag) {
365
- const tagRemovedMessage = intl.formatMessage({ id: "tagInput.tagRemoved", defaultMessage: "{tag} removed" }, { tag: tag });
366
- this.announce(tagRemovedMessage);
367
- this.tagsList = this.filterCaseInsensitive(this.tagsList, tag);
368
- const devOptionsList = this.csvToArray(this.options);
369
- if (this.includesCaseInsensitive(this.optionsList, tag) && !this.includesCaseInsensitive(devOptionsList, tag)) {
370
- this.removeOption(tag);
371
- }
372
- }
373
- focusListItem(item) {
374
- this.focusedListItem = item;
375
- item.focus();
376
- }
377
- focusTag(element) {
378
- this.focusedTag = element;
379
- this.tagAreaEl.setAttribute("aria-activedescendant", this.focusedTag.id);
380
- }
381
- clearTagFocus() {
382
- this.tagAreaEl.removeAttribute("aria-activedescendant");
383
- this.focusedTag = null;
384
- }
385
- openDropdown() {
386
- this.openUp = shouldOpenUp(this.el, this.dropdownEl, this.el.clientHeight);
387
- this.isExpanded = true;
388
- }
389
- closeDropdown() {
390
- this.focusedListItem = null;
391
- this.isExpanded = false;
392
- }
393
- clearListItemFocus() {
394
- this.focusedListItem = null;
395
- this.listItemEls.forEach((el) => {
396
- el.tabIndex = -1;
397
- el.classList.remove("focused");
398
- });
399
- }
400
- resetInput() {
401
- this.charCount = 0;
402
- this.inputEl.value = "";
403
- }
404
- announce(message) {
405
- // \u00A0 is a non-breaking space character, which causes the message to be read as a new one
406
- if (this.liveRegionEl.textContent === message) {
407
- message += "\u00A0";
408
- }
409
- this.liveRegionMessage = message;
410
- }
411
- announceExistingOptions() {
412
- // request animation frame to wait for re-rendering of filtered options
413
- window.requestAnimationFrame(() => {
414
- const existingOptionsMessage = intl.formatMessage({
415
- id: "tagInput.existingOptions",
416
- defaultMessage: "{num, plural, one {1 existing option.} other {# existing options.}}",
417
- }, { num: this.optionEls.length });
418
- if (this.optionEls.length > 0) {
419
- this.announce(existingOptionsMessage);
420
- }
421
- });
422
- }
423
- announceCharacterLimitWarning(charCount, charLimit) {
424
- const charactersEnteredMessage = intl.formatMessage({
425
- id: "tagInput.charactersEntered",
426
- defaultMessage: "{x, number} of {y, number} characters entered.",
427
- }, { x: charCount, y: charLimit });
428
- const characterLimitReachedMessage = intl.formatMessage({
429
- id: "tagInput.characterLimitReached",
430
- defaultMessage: "No additional characters will be entered.",
431
- });
432
- this.announce(`${charactersEnteredMessage}${charCount >= charLimit ? " " + characterLimitReachedMessage : ""}`);
433
- }
434
- /// Helpers
435
- listToCSV(list) {
436
- return list.join(",");
437
- }
438
- csvToArray(csv) {
439
- return csv ? csv.split(/, ?/) : [];
440
- }
441
- includesCaseInsensitive(list, element) {
442
- const lowercaseList = list.map((str) => str.toLowerCase());
443
- return lowercaseList.includes(element.toLowerCase());
444
- }
445
- filterCaseInsensitive(list, element) {
446
- return list.filter((x) => x.toLowerCase() !== element.toLowerCase());
447
- }
448
- sortCaseInsensitive(list) {
449
- // The vanilla .sort method places words that start with capital letters above others (ASCII order)
450
- // so we need to pass in our own compare function to sort case-insensitive
451
- return list.sort((a, b) => {
452
- a = a.toLowerCase();
453
- b = b.toLowerCase();
454
- return a > b ? 1 : a < b ? -1 : 0;
455
- });
456
- }
457
- /// Renders
458
- renderTags() {
459
- return this.tagsList.map((tag, idx) => {
460
- const id = `tag${idx + 1}`;
461
- return (h("li", { id: id, class: `tag highlight ${this.focusedTag && this.focusedTag.id === id ? "focused" : ""}`, "data-tag": tag, role: "option" }, tag, h("button", { class: "remove-btn", tabIndex: -1, onClick: () => this.handleRemoveButtonClick(tag) })));
462
- });
463
- }
464
- renderListItems(optionsList) {
465
- optionsList = this.sortCaseInsensitive(optionsList);
466
- // filter by input
467
- if (this.inputEl && this.inputEl.value) {
468
- optionsList = this.optionsList.filter((option) => option.toLowerCase().includes(this.inputEl.value.toLowerCase()));
469
- }
470
- return optionsList.map((option, idx) => {
471
- const id = `option${idx + 1}`;
472
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
473
- const isSelected = this.includesCaseInsensitive(this.tagsList, option);
474
- 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));
475
- });
476
- }
477
- renderAddNewButton() {
478
- if (this.inputEl.value.length > 0 &&
479
- this.addNew &&
480
- !this.includesCaseInsensitive(this.optionsList, this.inputEl.value)) {
481
- const id = `add-new-btn`;
482
- const isFocused = this.focusedListItem && this.focusedListItem.id === id;
483
- 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}"`));
484
- }
485
- else
486
- return "";
487
- }
488
- renderHelpText() {
489
- const helpTextHasOptions = intl.formatMessage({
490
- id: "tagInput.helpTextCanSelect",
491
- defaultMessage: "Search and select a tag.",
492
- });
493
- const helpTextEditable = intl.formatMessage({
494
- id: "tagInput.helpTextEditable",
495
- defaultMessage: "Press the Enter or Comma key to add a new tag.",
496
- });
497
- let helpText = "";
498
- if (this.optionsList.length > 0) {
499
- helpText += helpTextHasOptions;
500
- }
501
- if (this.addNew) {
502
- helpText += " " + helpTextEditable;
503
- }
504
- return helpText;
505
- }
506
- renderTagCounter() {
507
- if (this.maxTags) {
508
- return (h("div", { class: "lower-row" }, h("div", { id: "max-tags" }, this.generateTagCounterMessage(), 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 }, h("div", { class: `wrapper label-${this.labelPosition}` }, h("div", { class: "label-wrapper" }, h("label", { class: "label", htmlFor: `input${this.uid}` }, this.label)), h("div", { class: `field-wrapper ${isFocused ? "focused" : ""}`, ref: (el) => (this.fieldWrapperEl = el) }, h("div", { class: "upper-row" }, h("div", { class: "tags-and-input-wrapper" }, h("ul", { ref: (el) => (this.tagAreaEl = el), class: "tag-area", role: "listbox", "aria-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) => {
518
- this.clearTagFocus();
519
- this.handleBlur(ev, this.el);
520
- }, onKeyDown: (ev) => this.handleTagAreaKeyDown(ev) }, this.renderTags(), h("div", { class: "input-wrapper", role: "none" }, 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) => {
521
- this.handleBlur(ev, this.el);
522
- }, onFocus: () => {
523
- this.openDropdown();
524
- this.clearListItemFocus();
525
- }, onKeyDown: (ev) => this.handleInputKeyDown(ev) })))), h("div", { class: "character-count" }, this.charCount, "/", this.characterLimit)), this.renderTagCounter(), h("div", { class: `dropdown-wrapper ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}` }, h("div", { id: "help-text", class: "help-text" }, this.renderHelpText()), 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 }, this.inputEl && this.renderAddNewButton(), this.renderListItems(this.optionsList)))), this.info ? (h("div", { id: "info", class: "info-text" }, this.info)) : (""), h("div", { class: "sr-only", "aria-live": "assertive", ref: (el) => (this.liveRegionEl = el), "aria-atomic": "true" }, this.liveRegionMessage))));
526
- }
527
- get el() { return getElement(this); }
528
- static get watchers() { return {
529
- "tagsList": ["reflectSelectedTags"]
530
- }; }
531
- };
532
- TagInput.style = wmTagInputCss;
533
-
534
- export { TagInput as wm_tag_input };