@watermarkinsights/ripple 3.3.0-0 → 3.3.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 (176) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{functions-8fb310fe.js → functions-653e695c.js} +442 -442
  3. package/dist/cjs/{global-9bd085c7.js → global-45888f19.js} +65 -65
  4. package/dist/cjs/{http-service-9e8c4dd5.js → http-service-494d81de.js} +49 -49
  5. package/dist/cjs/{interfaces-30a74c1f.js → interfaces-a3338581.js} +29 -29
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/priv-chart-popover.cjs.entry.js +78 -78
  8. package/dist/cjs/priv-datepicker.cjs.entry.js +661 -661
  9. package/dist/cjs/priv-navigator-button.cjs.entry.js +18 -18
  10. package/dist/cjs/priv-navigator-item.cjs.entry.js +23 -23
  11. package/dist/cjs/ripple.cjs.js +2 -2
  12. package/dist/cjs/wm-action-menu_2.cjs.entry.js +340 -313
  13. package/dist/cjs/wm-button.cjs.entry.js +218 -219
  14. package/dist/cjs/wm-chart-slice.cjs.entry.js +13 -13
  15. package/dist/cjs/wm-chart.cjs.entry.js +514 -505
  16. package/dist/cjs/wm-datepicker.cjs.entry.js +256 -256
  17. package/dist/cjs/wm-input.cjs.entry.js +125 -125
  18. package/dist/cjs/wm-modal-footer.cjs.entry.js +31 -31
  19. package/dist/cjs/wm-modal-header.cjs.entry.js +34 -34
  20. package/dist/cjs/wm-modal.cjs.entry.js +161 -161
  21. package/dist/cjs/wm-navigator.cjs.entry.js +268 -268
  22. package/dist/cjs/wm-network-uploader.cjs.entry.js +420 -420
  23. package/dist/cjs/wm-option_2.cjs.entry.js +497 -469
  24. package/dist/cjs/wm-pagination.cjs.entry.js +167 -167
  25. package/dist/cjs/wm-search.cjs.entry.js +231 -231
  26. package/dist/cjs/wm-snackbar.cjs.entry.js +170 -170
  27. package/dist/cjs/wm-tab-item_3.cjs.entry.js +300 -300
  28. package/dist/cjs/wm-tag-input.cjs.entry.js +556 -556
  29. package/dist/cjs/wm-timepicker.cjs.entry.js +386 -381
  30. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  31. package/dist/cjs/wm-uploader.cjs.entry.js +346 -346
  32. package/dist/cjs/wm-wrapper.cjs.entry.js +12 -12
  33. package/dist/collection/components/wm-action-menu/wm-action-menu.js +465 -435
  34. package/dist/collection/components/wm-button/wm-button.js +485 -486
  35. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.js +232 -232
  36. package/dist/collection/components/wm-chart/wm-chart-slice.js +64 -64
  37. package/dist/collection/components/wm-chart/wm-chart.css +13 -0
  38. package/dist/collection/components/wm-chart/wm-chart.js +761 -734
  39. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1003 -1003
  40. package/dist/collection/components/wm-datepicker/wm-datepicker.js +462 -462
  41. package/dist/collection/components/wm-input/wm-input.js +415 -415
  42. package/dist/collection/components/wm-menuitem/wm-menuitem.js +444 -411
  43. package/dist/collection/components/wm-modal/wm-modal-footer.js +141 -141
  44. package/dist/collection/components/wm-modal/wm-modal-header.js +92 -92
  45. package/dist/collection/components/wm-modal/wm-modal.js +459 -459
  46. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -97
  47. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -114
  48. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -468
  49. package/dist/collection/components/wm-option/wm-option.js +422 -394
  50. package/dist/collection/components/wm-pagination/wm-pagination.js +368 -368
  51. package/dist/collection/components/wm-search/wm-search.js +479 -479
  52. package/dist/collection/components/wm-select/wm-select.js +728 -692
  53. package/dist/collection/components/wm-snackbar/wm-snackbar.js +297 -297
  54. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +219 -219
  55. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.js +331 -331
  56. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -104
  57. package/dist/collection/components/wm-tag-input/wm-tag-input.js +787 -787
  58. package/dist/collection/components/wm-timepicker/wm-timepicker.js +598 -587
  59. package/dist/collection/components/wm-toggletip/wm-toggletip.js +241 -241
  60. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +753 -753
  61. package/dist/collection/components/wm-uploader/wm-uploader.js +748 -748
  62. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -27
  63. package/dist/collection/dev/scripts.js +20 -20
  64. package/dist/collection/global/__mocks__/functions.js +6 -5
  65. package/dist/collection/global/functions.js +445 -445
  66. package/dist/collection/global/global.js +72 -72
  67. package/dist/collection/global/interfaces.js +49 -49
  68. package/dist/collection/global/services/__mocks__/http-service.js +130 -130
  69. package/dist/collection/global/services/http-service.js +50 -50
  70. package/dist/collection/lang/lang.js +5 -5
  71. package/dist/collection/lang/piglatin.js +93 -93
  72. package/dist/esm/{functions-c315390d.js → functions-e528c934.js} +442 -442
  73. package/dist/esm/{global-11e6d295.js → global-1e13ed17.js} +65 -65
  74. package/dist/esm/{http-service-5d037e16.js → http-service-3dc3b3e7.js} +49 -49
  75. package/dist/esm/{interfaces-61c6305b.js → interfaces-2b97fab2.js} +29 -29
  76. package/dist/esm/loader.js +2 -2
  77. package/dist/esm/polyfills/core-js.js +0 -0
  78. package/dist/esm/polyfills/dom.js +0 -0
  79. package/dist/esm/polyfills/es5-html-element.js +0 -0
  80. package/dist/esm/polyfills/index.js +0 -0
  81. package/dist/esm/polyfills/system.js +0 -0
  82. package/dist/esm/priv-chart-popover.entry.js +78 -78
  83. package/dist/esm/priv-datepicker.entry.js +661 -661
  84. package/dist/esm/priv-navigator-button.entry.js +18 -18
  85. package/dist/esm/priv-navigator-item.entry.js +23 -23
  86. package/dist/esm/ripple.js +2 -2
  87. package/dist/esm/wm-action-menu_2.entry.js +340 -313
  88. package/dist/esm/wm-button.entry.js +218 -219
  89. package/dist/esm/wm-chart-slice.entry.js +13 -13
  90. package/dist/esm/wm-chart.entry.js +514 -505
  91. package/dist/esm/wm-datepicker.entry.js +256 -256
  92. package/dist/esm/wm-input.entry.js +125 -125
  93. package/dist/esm/wm-modal-footer.entry.js +31 -31
  94. package/dist/esm/wm-modal-header.entry.js +34 -34
  95. package/dist/esm/wm-modal.entry.js +161 -161
  96. package/dist/esm/wm-navigator.entry.js +268 -268
  97. package/dist/esm/wm-network-uploader.entry.js +420 -420
  98. package/dist/esm/wm-option_2.entry.js +497 -469
  99. package/dist/esm/wm-pagination.entry.js +167 -167
  100. package/dist/esm/wm-search.entry.js +231 -231
  101. package/dist/esm/wm-snackbar.entry.js +170 -170
  102. package/dist/esm/wm-tab-item_3.entry.js +300 -300
  103. package/dist/esm/wm-tag-input.entry.js +556 -556
  104. package/dist/esm/wm-timepicker.entry.js +386 -381
  105. package/dist/esm/wm-toggletip.entry.js +124 -124
  106. package/dist/esm/wm-uploader.entry.js +346 -346
  107. package/dist/esm/wm-wrapper.entry.js +12 -12
  108. package/dist/ripple/{p-c5e44367.entry.js → p-092b01f3.entry.js} +1 -1
  109. package/dist/ripple/p-0d138e91.entry.js +1 -0
  110. package/dist/ripple/{p-5ffa983b.entry.js → p-1e0c41a9.entry.js} +1 -1
  111. package/dist/ripple/{p-d5fafa9c.entry.js → p-3003d26d.entry.js} +1 -1
  112. package/dist/ripple/p-301b67a3.entry.js +1 -0
  113. package/dist/ripple/{p-374b4fa6.entry.js → p-33524565.entry.js} +1 -1
  114. package/dist/ripple/{p-73ebc395.js → p-40d42d65.js} +1 -1
  115. package/dist/ripple/{p-888bec42.js → p-43f1298b.js} +0 -0
  116. package/dist/ripple/{p-dea72d46.entry.js → p-4cc71463.entry.js} +1 -1
  117. package/dist/ripple/{p-e60fe2f5.js → p-588b4475.js} +0 -0
  118. package/dist/ripple/p-65e3a656.entry.js +1 -0
  119. package/dist/ripple/p-6b96b3d4.entry.js +1 -0
  120. package/dist/ripple/{p-7bbd123c.entry.js → p-8923b7d0.entry.js} +1 -1
  121. package/dist/ripple/{p-ba9d3069.entry.js → p-8cd1396e.entry.js} +1 -1
  122. package/dist/ripple/{p-e574fb73.entry.js → p-aa973691.entry.js} +1 -1
  123. package/dist/ripple/{p-b4a8c8d3.entry.js → p-b3d5ea85.entry.js} +1 -1
  124. package/dist/ripple/{p-27d5255f.entry.js → p-cd58a15c.entry.js} +1 -1
  125. package/dist/ripple/{p-589f8195.entry.js → p-d613130d.entry.js} +1 -1
  126. package/dist/ripple/{p-2689c3ff.entry.js → p-dc7ba72a.entry.js} +1 -1
  127. package/dist/ripple/{p-41f39509.entry.js → p-dc9c9fda.entry.js} +1 -1
  128. package/dist/ripple/p-df6da757.entry.js +1 -0
  129. package/dist/ripple/{p-36da5d4a.entry.js → p-e9e8334e.entry.js} +1 -1
  130. package/dist/ripple/p-ec9697db.entry.js +1 -0
  131. package/dist/ripple/{p-a6d6eae7.js → p-fd8070fb.js} +0 -0
  132. package/dist/ripple/ripple.esm.js +1 -1
  133. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +48 -46
  134. package/dist/types/components/wm-button/wm-button.d.ts +44 -43
  135. package/dist/types/components/wm-chart/priv-chart-popover/priv-chart-popover.d.ts +23 -23
  136. package/dist/types/components/wm-chart/wm-chart-slice.d.ts +8 -8
  137. package/dist/types/components/wm-chart/wm-chart.d.ts +80 -79
  138. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +75 -75
  139. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +41 -41
  140. package/dist/types/components/wm-input/wm-input.d.ts +45 -45
  141. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +34 -30
  142. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +15 -15
  143. package/dist/types/components/wm-modal/wm-modal-header.d.ts +12 -12
  144. package/dist/types/components/wm-modal/wm-modal.d.ts +41 -41
  145. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -10
  146. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -13
  147. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -61
  148. package/dist/types/components/wm-option/wm-option.d.ts +32 -28
  149. package/dist/types/components/wm-pagination/wm-pagination.d.ts +32 -32
  150. package/dist/types/components/wm-search/wm-search.d.ts +86 -86
  151. package/dist/types/components/wm-select/wm-select.d.ts +67 -64
  152. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +35 -35
  153. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +38 -38
  154. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +53 -53
  155. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -20
  156. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts +91 -91
  157. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +63 -62
  158. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +27 -27
  159. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -85
  160. package/dist/types/components/wm-uploader/wm-uploader.d.ts +80 -80
  161. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  162. package/dist/types/components.d.ts +28 -24
  163. package/dist/types/global/__mocks__/functions.d.ts +6 -5
  164. package/dist/types/global/functions.d.ts +40 -40
  165. package/dist/types/global/global.d.ts +1 -1
  166. package/dist/types/global/interfaces.d.ts +34 -34
  167. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -6
  168. package/dist/types/global/services/http-service.d.ts +4 -4
  169. package/dist/types/lang/lang.d.ts +5 -5
  170. package/package.json +46 -46
  171. package/dist/ripple/p-14b37f79.entry.js +0 -1
  172. package/dist/ripple/p-27c6abf9.entry.js +0 -1
  173. package/dist/ripple/p-336c0ed7.entry.js +0 -1
  174. package/dist/ripple/p-6933edc6.entry.js +0 -1
  175. package/dist/ripple/p-c31c4d52.entry.js +0 -1
  176. package/dist/ripple/p-d079df21.entry.js +0 -1
@@ -1,435 +1,465 @@
1
- import { h, Component, Element, Listen, Prop, State, Event, Host } from "@stencil/core";
2
- import { generateId, getTextDir, shouldOpenUp, shouldShiftRight } from "../../global/functions";
3
- export class ActionMenu {
4
- constructor() {
5
- this.openUp = false;
6
- this.isExpanded = false;
7
- this.actionMenuType = null;
8
- this.buttonType = null; // deprecated in favor of actionMenuType
9
- this.disabled = false;
10
- this.keysSoFar = "";
11
- this.searchIndex = 0;
12
- this.keyClear = null;
13
- }
14
- get horizontalPosition() {
15
- return !!this.el && !!this.itemsEl && shouldShiftRight(this.el, this.itemsEl) ? "right" : "left";
16
- }
17
- get childItems() {
18
- return Array.from(this.el.querySelectorAll("wm-menuitem"));
19
- }
20
- get tempActionMenuType() {
21
- // uses of this getter should be replaced with this.actionMenuType when buttonType is fully phased out
22
- // don't forget to reset this.actionMenuTypes's default value to icon
23
- return this.actionMenuType || this.buttonType || "icon";
24
- }
25
- handleClickedItem() {
26
- this.close();
27
- }
28
- handleKeyUp(ev) {
29
- this.moveUp(ev.target);
30
- }
31
- handleKeyDown(ev) {
32
- this.moveDown(ev.detail);
33
- }
34
- handleHomeKey() {
35
- this.focusFirstItem();
36
- }
37
- handleEndKey() {
38
- this.focusLastItem();
39
- }
40
- handleTabKey() {
41
- if (this.isExpanded) {
42
- this.close();
43
- }
44
- }
45
- handleEscKey() {
46
- this.close();
47
- this.wmButtonEl.focus();
48
- }
49
- blurHandler(ev) {
50
- const isElOrChild = ev.target === this.el || this.el.contains(ev.target);
51
- if (!isElOrChild && this.isExpanded) {
52
- this.close();
53
- }
54
- }
55
- handleKey(ev) {
56
- switch (ev.key) {
57
- case "ArrowDown":
58
- if (!this.isExpanded) {
59
- ev.preventDefault();
60
- this.open();
61
- window.requestAnimationFrame(() => this.focusFirstItem());
62
- }
63
- break;
64
- case "ArrowUp":
65
- if (!this.isExpanded) {
66
- ev.preventDefault();
67
- this.open();
68
- window.requestAnimationFrame(() => this.focusLastItem());
69
- }
70
- break;
71
- }
72
- }
73
- componentWillLoad() {
74
- this.uid = this.el.id ? this.el.id : generateId();
75
- this.el.focus = function () {
76
- if (!this.disabled) {
77
- const button = this.shadowRoot.querySelector("wm-button");
78
- button && button.focus();
79
- }
80
- };
81
- if (this.buttonType) {
82
- console.warn("wm-action-menu: button-type has been deprecated as of v3.1.0. Please use action-menu-type instead.");
83
- }
84
- }
85
- componentDidLoad() {
86
- if (this.childItems.length === 0) {
87
- console.error("wm-action-menu should have wm-menuitem elements as children");
88
- }
89
- else {
90
- this.focusFirstItem();
91
- }
92
- if (this.tempActionMenuType !== "icon" && !this.buttonText) {
93
- console.error("wm-action-menu should have a valid button-text property when button-type is set to 'text' or 'selector'");
94
- }
95
- if (this.tempActionMenuType === "icon" && !this.tooltip) {
96
- console.error("wm-action-menu should have a valid tooltip when button-type is set to 'icon'");
97
- }
98
- this.wmActionMenuLoaded.emit();
99
- this.menuLoaded.emit(); // deprecated
100
- }
101
- moveUp(el) {
102
- const index = this.childItems.indexOf(el);
103
- if (index === 0) {
104
- this.focusLastItem();
105
- }
106
- else {
107
- this.focusItem(this.childItems[index - 1]);
108
- }
109
- }
110
- moveDown(el) {
111
- const index = this.childItems.indexOf(el);
112
- if (index === this.childItems.length - 1) {
113
- this.focusFirstItem();
114
- }
115
- else {
116
- this.focusItem(this.childItems[index + 1]);
117
- }
118
- }
119
- open() {
120
- if (!this.disabled) {
121
- this.openUp = shouldOpenUp(this.el, this.itemsEl);
122
- // action menu usually is on the right side of the screen,
123
- // so dropdown opens to the left (is anchored on the right corner)
124
- // if there is not enough space on the left and enough on the right though,
125
- // it will open on the right side
126
- this.isExpanded = true;
127
- this.itemsEl.classList.remove("hidden");
128
- window.requestAnimationFrame(() => this.focusFirstItem());
129
- }
130
- }
131
- close() {
132
- this.isExpanded = false;
133
- this.childItems.forEach((i) => (i.focused = false));
134
- window.setTimeout(() => {
135
- this.itemsEl.classList.add("hidden");
136
- }, 150);
137
- window.setTimeout(() => {
138
- // if dev omits to assign focus after an action is triggered,
139
- // the component brings the focus back on the button
140
- // Focus will only be lost (and go to the body) once the menuitem
141
- // is not visible anymore, so we need to wait for the transition to
142
- // finish and the hidden class to be applied.
143
- // also checking if focus stayed on the menuitem
144
- if (document.activeElement.tagName === "BODY" || document.activeElement.tagName === "WM-MENUITEM") {
145
- this.wmButtonEl.focus();
146
- }
147
- }, 250);
148
- }
149
- focusItem(item) {
150
- this.childItems.map((i) => (i.focused = i === item));
151
- item.focus && item.focus();
152
- }
153
- focusFirstItem() {
154
- this.focusItem(this.childItems[0]);
155
- }
156
- focusLastItem() {
157
- this.focusItem(this.childItems[this.childItems.length - 1]);
158
- }
159
- findAndFocusItem(ev) {
160
- const character = ev.detail.toUpperCase();
161
- this.focusFirstItem();
162
- if (!this.keysSoFar) {
163
- for (var i = 0; i < this.childItems.length; i++) {
164
- if (this.childItems[i] === document.activeElement) {
165
- this.searchIndex = i;
166
- }
167
- }
168
- }
169
- this.keysSoFar += character;
170
- this.clearKeysSoFarAfterDelay();
171
- var nextMatch = this.findMatchInRange(this.childItems, this.searchIndex + 1, this.childItems.length);
172
- if (!nextMatch) {
173
- nextMatch = this.findMatchInRange(this.childItems, 0, this.searchIndex);
174
- }
175
- if (nextMatch) {
176
- this.focusItem(nextMatch);
177
- }
178
- }
179
- clearKeysSoFarAfterDelay() {
180
- if (this.keyClear) {
181
- window.clearTimeout(this.keyClear);
182
- this.keyClear = null;
183
- }
184
- this.keyClear = window.setTimeout(function () {
185
- this.keysSoFar = "";
186
- this.keyClear = null;
187
- }.bind(this), 500);
188
- }
189
- findMatchInRange(list, startIndex, endIndex) {
190
- // Find the first item starting with the keysSoFar substring, searching in
191
- // the specified range of items
192
- for (var n = startIndex; n < endIndex; n++) {
193
- var label = list[n].innerText;
194
- if (label && label.toUpperCase().indexOf(this.keysSoFar) === 0) {
195
- return list[n];
196
- }
197
- }
198
- return null;
199
- }
200
- render() {
201
- return (h(Host, null,
202
- h("div", { class: getTextDir() },
203
- h("wm-button", { "button-type": `${this.tempActionMenuType}only`, tooltip: this.tooltip, "label-for-identical-buttons": this.labelForIdenticalButtons, icon: this.tempActionMenuType === "icon" ? "f1d9" : "", id: `menubtn-${this.uid}`, onClick: () => (this.isExpanded ? this.close() : this.open()), disabled: this.disabled, ref: (el) => (this.wmButtonEl = el), "tooltip-position": this.tooltipPosition || this.horizontalPosition, "aria-haspopup": "true", "aria-expanded": this.isExpanded ? "true" : "false", "aria-controls": `menu-${this.uid}` }, this.buttonText),
204
- h("div", { class: `dropdown ${this.openUp ? "open-up" : ""} ${this.horizontalPosition} ${this.isExpanded ? "open" : ""} hidden`, id: `menu-${this.uid}`, tabindex: -1, role: "menu", ref: (el) => (this.itemsEl = el) },
205
- h("slot", null)))));
206
- }
207
- static get is() { return "wm-action-menu"; }
208
- static get encapsulation() { return "shadow"; }
209
- static get originalStyleUrls() { return {
210
- "$": ["wm-action-menu.scss"]
211
- }; }
212
- static get styleUrls() { return {
213
- "$": ["wm-action-menu.css"]
214
- }; }
215
- static get properties() { return {
216
- "tooltipPosition": {
217
- "type": "string",
218
- "mutable": false,
219
- "complexType": {
220
- "original": "| \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"bottom-left\"\n | \"bottom-right\"\n | \"top-right\"\n | \"top-left\"",
221
- "resolved": "\"bottom\" | \"bottom-left\" | \"bottom-right\" | \"left\" | \"right\" | \"top\" | \"top-left\" | \"top-right\" | undefined",
222
- "references": {}
223
- },
224
- "required": false,
225
- "optional": true,
226
- "docs": {
227
- "tags": [],
228
- "text": ""
229
- },
230
- "attribute": "tooltip-position",
231
- "reflect": false
232
- },
233
- "actionMenuType": {
234
- "type": "string",
235
- "mutable": false,
236
- "complexType": {
237
- "original": "\"icon\" | \"text\" | \"selector\" | null",
238
- "resolved": "\"icon\" | \"selector\" | \"text\" | null",
239
- "references": {}
240
- },
241
- "required": false,
242
- "optional": false,
243
- "docs": {
244
- "tags": [],
245
- "text": ""
246
- },
247
- "attribute": "action-menu-type",
248
- "reflect": false,
249
- "defaultValue": "null"
250
- },
251
- "buttonType": {
252
- "type": "string",
253
- "mutable": false,
254
- "complexType": {
255
- "original": "\"icon\" | \"text\" | \"selector\" | null",
256
- "resolved": "\"icon\" | \"selector\" | \"text\" | null",
257
- "references": {}
258
- },
259
- "required": false,
260
- "optional": false,
261
- "docs": {
262
- "tags": [],
263
- "text": ""
264
- },
265
- "attribute": "button-type",
266
- "reflect": false,
267
- "defaultValue": "null"
268
- },
269
- "buttonText": {
270
- "type": "string",
271
- "mutable": false,
272
- "complexType": {
273
- "original": "string",
274
- "resolved": "string | undefined",
275
- "references": {}
276
- },
277
- "required": false,
278
- "optional": true,
279
- "docs": {
280
- "tags": [],
281
- "text": ""
282
- },
283
- "attribute": "button-text",
284
- "reflect": false
285
- },
286
- "disabled": {
287
- "type": "boolean",
288
- "mutable": false,
289
- "complexType": {
290
- "original": "boolean",
291
- "resolved": "boolean",
292
- "references": {}
293
- },
294
- "required": false,
295
- "optional": false,
296
- "docs": {
297
- "tags": [],
298
- "text": ""
299
- },
300
- "attribute": "disabled",
301
- "reflect": true,
302
- "defaultValue": "false"
303
- },
304
- "tooltip": {
305
- "type": "string",
306
- "mutable": false,
307
- "complexType": {
308
- "original": "string",
309
- "resolved": "string | undefined",
310
- "references": {}
311
- },
312
- "required": false,
313
- "optional": true,
314
- "docs": {
315
- "tags": [],
316
- "text": ""
317
- },
318
- "attribute": "tooltip",
319
- "reflect": false
320
- },
321
- "labelForIdenticalButtons": {
322
- "type": "string",
323
- "mutable": false,
324
- "complexType": {
325
- "original": "string",
326
- "resolved": "string | undefined",
327
- "references": {}
328
- },
329
- "required": false,
330
- "optional": true,
331
- "docs": {
332
- "tags": [],
333
- "text": ""
334
- },
335
- "attribute": "label-for-identical-buttons",
336
- "reflect": false
337
- }
338
- }; }
339
- static get states() { return {
340
- "isExpanded": {}
341
- }; }
342
- static get events() { return [{
343
- "method": "wmActionMenuLoaded",
344
- "name": "wmActionMenuLoaded",
345
- "bubbles": true,
346
- "cancelable": true,
347
- "composed": true,
348
- "docs": {
349
- "tags": [],
350
- "text": ""
351
- },
352
- "complexType": {
353
- "original": "any",
354
- "resolved": "any",
355
- "references": {}
356
- }
357
- }, {
358
- "method": "menuLoaded",
359
- "name": "menuLoaded",
360
- "bubbles": true,
361
- "cancelable": true,
362
- "composed": true,
363
- "docs": {
364
- "tags": [],
365
- "text": ""
366
- },
367
- "complexType": {
368
- "original": "any",
369
- "resolved": "any",
370
- "references": {}
371
- }
372
- }]; }
373
- static get elementRef() { return "el"; }
374
- static get listeners() { return [{
375
- "name": "wmMenuitemClicked",
376
- "method": "handleClickedItem",
377
- "target": undefined,
378
- "capture": false,
379
- "passive": false
380
- }, {
381
- "name": "wmKeyUpPressed",
382
- "method": "handleKeyUp",
383
- "target": undefined,
384
- "capture": false,
385
- "passive": false
386
- }, {
387
- "name": "wmKeyDownPressed",
388
- "method": "handleKeyDown",
389
- "target": undefined,
390
- "capture": false,
391
- "passive": false
392
- }, {
393
- "name": "wmHomeKeyPressed",
394
- "method": "handleHomeKey",
395
- "target": undefined,
396
- "capture": false,
397
- "passive": false
398
- }, {
399
- "name": "wmEndKeyPressed",
400
- "method": "handleEndKey",
401
- "target": undefined,
402
- "capture": false,
403
- "passive": false
404
- }, {
405
- "name": "wmTabKeyPressed",
406
- "method": "handleTabKey",
407
- "target": undefined,
408
- "capture": false,
409
- "passive": false
410
- }, {
411
- "name": "wmEscKeyPressed",
412
- "method": "handleEscKey",
413
- "target": undefined,
414
- "capture": false,
415
- "passive": false
416
- }, {
417
- "name": "click",
418
- "method": "blurHandler",
419
- "target": "document",
420
- "capture": false,
421
- "passive": false
422
- }, {
423
- "name": "keydown",
424
- "method": "handleKey",
425
- "target": undefined,
426
- "capture": false,
427
- "passive": false
428
- }, {
429
- "name": "wmLetterPressed",
430
- "method": "findAndFocusItem",
431
- "target": undefined,
432
- "capture": false,
433
- "passive": false
434
- }]; }
435
- }
1
+ import { h, Component, Element, Listen, Prop, State, Event, Host } from "@stencil/core";
2
+ import { generateId, getTextDir, shouldOpenUp, shouldShiftRight } from "../../global/functions";
3
+ export class ActionMenu {
4
+ constructor() {
5
+ this.openUp = false;
6
+ this.isExpanded = false;
7
+ this.actionMenuType = null;
8
+ this.buttonType = null; // deprecated in favor of actionMenuType
9
+ this.disabled = false;
10
+ this.keysSoFar = "";
11
+ this.searchIndex = 0;
12
+ this.keyClear = null;
13
+ }
14
+ get horizontalPosition() {
15
+ return !!this.el && !!this.itemsEl && shouldShiftRight(this.el, this.itemsEl) ? "right" : "left";
16
+ }
17
+ get childItems() {
18
+ return Array.from(this.el.querySelectorAll("wm-menuitem"));
19
+ }
20
+ get tempActionMenuType() {
21
+ // uses of this getter should be replaced with this.actionMenuType when buttonType is fully phased out
22
+ // don't forget to reset this.actionMenuTypes's default value to icon
23
+ return this.actionMenuType || this.buttonType || "icon";
24
+ }
25
+ handleClickedItem() {
26
+ this.close();
27
+ }
28
+ handleKeyUp(ev) {
29
+ this.moveUp(ev.target);
30
+ }
31
+ handleKeyDown(ev) {
32
+ this.moveDown(ev.detail);
33
+ }
34
+ handleHomeKey() {
35
+ this.focusFirstItem();
36
+ }
37
+ handleEndKey() {
38
+ this.focusLastItem();
39
+ }
40
+ handleTabKey() {
41
+ if (this.isExpanded) {
42
+ this.close();
43
+ }
44
+ }
45
+ handleEscKey() {
46
+ this.close();
47
+ this.wmButtonEl.focus();
48
+ }
49
+ handleClick(ev) {
50
+ const isElOrChild = ev.target === this.el || this.el.contains(ev.target);
51
+ if (!isElOrChild && this.isExpanded) {
52
+ this.close();
53
+ }
54
+ }
55
+ handleKey(ev) {
56
+ switch (ev.key) {
57
+ case "ArrowDown":
58
+ if (!this.isExpanded) {
59
+ ev.preventDefault();
60
+ this.open();
61
+ window.requestAnimationFrame(() => this.focusFirstItem());
62
+ }
63
+ break;
64
+ case "ArrowUp":
65
+ if (!this.isExpanded) {
66
+ ev.preventDefault();
67
+ this.open();
68
+ window.requestAnimationFrame(() => this.focusLastItem());
69
+ }
70
+ break;
71
+ }
72
+ }
73
+ handleMenuitemBlur(ev) {
74
+ const toElOrChild = ev.detail.relatedTarget === this.el || this.el.contains(ev.detail.relatedTarget);
75
+ // if the Menuitem is blurred to something other than the component, emit a blur event with the appropriate relatedTarget
76
+ // keeps our component's blur events accurate, and closes when focusing browser address bar
77
+ if (!toElOrChild) {
78
+ const event = new CustomEvent("blur");
79
+ // @ts-ignore
80
+ event.relatedTarget = ev.detail.relatedTarget;
81
+ this.el.dispatchEvent(event);
82
+ }
83
+ }
84
+ handleButtonBlur(ev) {
85
+ const toElOrChild = ev.relatedTarget === this.el || this.el.contains(ev.relatedTarget);
86
+ if (toElOrChild) {
87
+ // do not emit a blur event when opening the dropdown and focusing the Menuitems
88
+ ev.stopPropagation();
89
+ }
90
+ }
91
+ componentWillLoad() {
92
+ this.uid = this.el.id ? this.el.id : generateId();
93
+ this.el.focus = function () {
94
+ if (!this.disabled) {
95
+ const button = this.shadowRoot.querySelector("wm-button");
96
+ button && button.focus();
97
+ }
98
+ };
99
+ if (this.buttonType) {
100
+ console.warn("wm-action-menu: button-type has been deprecated as of v3.1.0. Please use action-menu-type instead.");
101
+ }
102
+ }
103
+ componentDidLoad() {
104
+ if (this.childItems.length === 0) {
105
+ console.error("wm-action-menu should have wm-menuitem elements as children");
106
+ }
107
+ else {
108
+ this.focusFirstItem();
109
+ }
110
+ if (this.tempActionMenuType !== "icon" && !this.buttonText) {
111
+ console.error("wm-action-menu should have a valid button-text property when button-type is set to 'text' or 'selector'");
112
+ }
113
+ if (this.tempActionMenuType === "icon" && !this.tooltip) {
114
+ console.error("wm-action-menu should have a valid tooltip when button-type is set to 'icon'");
115
+ }
116
+ this.wmActionMenuLoaded.emit();
117
+ this.menuLoaded.emit(); // deprecated
118
+ }
119
+ moveUp(el) {
120
+ const index = this.childItems.indexOf(el);
121
+ if (index === 0) {
122
+ this.focusLastItem();
123
+ }
124
+ else {
125
+ this.focusItem(this.childItems[index - 1]);
126
+ }
127
+ }
128
+ moveDown(el) {
129
+ const index = this.childItems.indexOf(el);
130
+ if (index === this.childItems.length - 1) {
131
+ this.focusFirstItem();
132
+ }
133
+ else {
134
+ this.focusItem(this.childItems[index + 1]);
135
+ }
136
+ }
137
+ open() {
138
+ if (!this.disabled) {
139
+ this.openUp = shouldOpenUp(this.el, this.itemsEl);
140
+ // action menu usually is on the right side of the screen,
141
+ // so dropdown opens to the left (is anchored on the right corner)
142
+ // if there is not enough space on the left and enough on the right though,
143
+ // it will open on the right side
144
+ this.isExpanded = true;
145
+ this.itemsEl.classList.remove("hidden");
146
+ window.requestAnimationFrame(() => this.focusFirstItem());
147
+ }
148
+ }
149
+ close() {
150
+ this.isExpanded = false;
151
+ this.childItems.forEach((i) => (i.focused = false));
152
+ window.setTimeout(() => {
153
+ this.itemsEl.classList.add("hidden");
154
+ }, 150);
155
+ window.setTimeout(() => {
156
+ // if dev omits to assign focus after an action is triggered,
157
+ // the component brings the focus back on the button
158
+ // Focus will only be lost (and go to the body) once the menuitem
159
+ // is not visible anymore, so we need to wait for the transition to
160
+ // finish and the hidden class to be applied.
161
+ // also checking if focus stayed on the menuitem
162
+ if (document.activeElement.tagName === "BODY" || document.activeElement.tagName === "WM-MENUITEM") {
163
+ this.wmButtonEl.focus();
164
+ }
165
+ }, 250);
166
+ }
167
+ focusItem(item) {
168
+ this.childItems.map((i) => (i.focused = i === item));
169
+ item.focus && item.focus();
170
+ }
171
+ focusFirstItem() {
172
+ this.focusItem(this.childItems[0]);
173
+ }
174
+ focusLastItem() {
175
+ this.focusItem(this.childItems[this.childItems.length - 1]);
176
+ }
177
+ findAndFocusItem(ev) {
178
+ const character = ev.detail.toUpperCase();
179
+ this.focusFirstItem();
180
+ if (!this.keysSoFar) {
181
+ for (var i = 0; i < this.childItems.length; i++) {
182
+ if (this.childItems[i] === document.activeElement) {
183
+ this.searchIndex = i;
184
+ }
185
+ }
186
+ }
187
+ this.keysSoFar += character;
188
+ this.clearKeysSoFarAfterDelay();
189
+ var nextMatch = this.findMatchInRange(this.childItems, this.searchIndex + 1, this.childItems.length);
190
+ if (!nextMatch) {
191
+ nextMatch = this.findMatchInRange(this.childItems, 0, this.searchIndex);
192
+ }
193
+ if (nextMatch) {
194
+ this.focusItem(nextMatch);
195
+ }
196
+ }
197
+ clearKeysSoFarAfterDelay() {
198
+ if (this.keyClear) {
199
+ window.clearTimeout(this.keyClear);
200
+ this.keyClear = null;
201
+ }
202
+ this.keyClear = window.setTimeout(function () {
203
+ this.keysSoFar = "";
204
+ this.keyClear = null;
205
+ }.bind(this), 500);
206
+ }
207
+ findMatchInRange(list, startIndex, endIndex) {
208
+ // Find the first item starting with the keysSoFar substring, searching in
209
+ // the specified range of items
210
+ for (var n = startIndex; n < endIndex; n++) {
211
+ var label = list[n].innerText;
212
+ if (label && label.toUpperCase().indexOf(this.keysSoFar) === 0) {
213
+ return list[n];
214
+ }
215
+ }
216
+ return null;
217
+ }
218
+ render() {
219
+ return (h(Host, null,
220
+ h("div", { class: getTextDir() },
221
+ h("wm-button", { "button-type": `${this.tempActionMenuType}only`, tooltip: this.tooltip, "label-for-identical-buttons": this.labelForIdenticalButtons, icon: this.tempActionMenuType === "icon" ? "f1d9" : "", id: `menubtn-${this.uid}`, onClick: () => (this.isExpanded ? this.close() : this.open()), onBlur: (ev) => this.handleButtonBlur(ev), disabled: this.disabled, ref: (el) => (this.wmButtonEl = el), "tooltip-position": this.tooltipPosition || this.horizontalPosition, "aria-haspopup": "true", "aria-expanded": this.isExpanded ? "true" : "false", "aria-controls": `menu-${this.uid}` }, this.buttonText),
222
+ h("div", { class: `dropdown ${this.openUp ? "open-up" : ""} ${this.horizontalPosition} ${this.isExpanded ? "open" : ""} hidden`, id: `menu-${this.uid}`, tabindex: -1, role: "menu", ref: (el) => (this.itemsEl = el) },
223
+ h("slot", null)))));
224
+ }
225
+ static get is() { return "wm-action-menu"; }
226
+ static get encapsulation() { return "shadow"; }
227
+ static get originalStyleUrls() { return {
228
+ "$": ["wm-action-menu.scss"]
229
+ }; }
230
+ static get styleUrls() { return {
231
+ "$": ["wm-action-menu.css"]
232
+ }; }
233
+ static get properties() { return {
234
+ "tooltipPosition": {
235
+ "type": "string",
236
+ "mutable": false,
237
+ "complexType": {
238
+ "original": "| \"top\"\r\n | \"bottom\"\r\n | \"left\"\r\n | \"right\"\r\n | \"bottom-left\"\r\n | \"bottom-right\"\r\n | \"top-right\"\r\n | \"top-left\"",
239
+ "resolved": "\"bottom\" | \"bottom-left\" | \"bottom-right\" | \"left\" | \"right\" | \"top\" | \"top-left\" | \"top-right\" | undefined",
240
+ "references": {}
241
+ },
242
+ "required": false,
243
+ "optional": true,
244
+ "docs": {
245
+ "tags": [],
246
+ "text": ""
247
+ },
248
+ "attribute": "tooltip-position",
249
+ "reflect": false
250
+ },
251
+ "actionMenuType": {
252
+ "type": "string",
253
+ "mutable": false,
254
+ "complexType": {
255
+ "original": "\"icon\" | \"text\" | \"selector\" | null",
256
+ "resolved": "\"icon\" | \"selector\" | \"text\" | null",
257
+ "references": {}
258
+ },
259
+ "required": false,
260
+ "optional": false,
261
+ "docs": {
262
+ "tags": [],
263
+ "text": ""
264
+ },
265
+ "attribute": "action-menu-type",
266
+ "reflect": false,
267
+ "defaultValue": "null"
268
+ },
269
+ "buttonType": {
270
+ "type": "string",
271
+ "mutable": false,
272
+ "complexType": {
273
+ "original": "\"icon\" | \"text\" | \"selector\" | null",
274
+ "resolved": "\"icon\" | \"selector\" | \"text\" | null",
275
+ "references": {}
276
+ },
277
+ "required": false,
278
+ "optional": false,
279
+ "docs": {
280
+ "tags": [],
281
+ "text": ""
282
+ },
283
+ "attribute": "button-type",
284
+ "reflect": false,
285
+ "defaultValue": "null"
286
+ },
287
+ "buttonText": {
288
+ "type": "string",
289
+ "mutable": false,
290
+ "complexType": {
291
+ "original": "string",
292
+ "resolved": "string | undefined",
293
+ "references": {}
294
+ },
295
+ "required": false,
296
+ "optional": true,
297
+ "docs": {
298
+ "tags": [],
299
+ "text": ""
300
+ },
301
+ "attribute": "button-text",
302
+ "reflect": false
303
+ },
304
+ "disabled": {
305
+ "type": "boolean",
306
+ "mutable": false,
307
+ "complexType": {
308
+ "original": "boolean",
309
+ "resolved": "boolean",
310
+ "references": {}
311
+ },
312
+ "required": false,
313
+ "optional": false,
314
+ "docs": {
315
+ "tags": [],
316
+ "text": ""
317
+ },
318
+ "attribute": "disabled",
319
+ "reflect": true,
320
+ "defaultValue": "false"
321
+ },
322
+ "tooltip": {
323
+ "type": "string",
324
+ "mutable": false,
325
+ "complexType": {
326
+ "original": "string",
327
+ "resolved": "string | undefined",
328
+ "references": {}
329
+ },
330
+ "required": false,
331
+ "optional": true,
332
+ "docs": {
333
+ "tags": [],
334
+ "text": ""
335
+ },
336
+ "attribute": "tooltip",
337
+ "reflect": false
338
+ },
339
+ "labelForIdenticalButtons": {
340
+ "type": "string",
341
+ "mutable": false,
342
+ "complexType": {
343
+ "original": "string",
344
+ "resolved": "string | undefined",
345
+ "references": {}
346
+ },
347
+ "required": false,
348
+ "optional": true,
349
+ "docs": {
350
+ "tags": [],
351
+ "text": ""
352
+ },
353
+ "attribute": "label-for-identical-buttons",
354
+ "reflect": false
355
+ }
356
+ }; }
357
+ static get states() { return {
358
+ "isExpanded": {}
359
+ }; }
360
+ static get events() { return [{
361
+ "method": "wmActionMenuLoaded",
362
+ "name": "wmActionMenuLoaded",
363
+ "bubbles": true,
364
+ "cancelable": true,
365
+ "composed": true,
366
+ "docs": {
367
+ "tags": [],
368
+ "text": ""
369
+ },
370
+ "complexType": {
371
+ "original": "any",
372
+ "resolved": "any",
373
+ "references": {}
374
+ }
375
+ }, {
376
+ "method": "menuLoaded",
377
+ "name": "menuLoaded",
378
+ "bubbles": true,
379
+ "cancelable": true,
380
+ "composed": true,
381
+ "docs": {
382
+ "tags": [],
383
+ "text": ""
384
+ },
385
+ "complexType": {
386
+ "original": "any",
387
+ "resolved": "any",
388
+ "references": {}
389
+ }
390
+ }]; }
391
+ static get elementRef() { return "el"; }
392
+ static get listeners() { return [{
393
+ "name": "wmMenuitemClicked",
394
+ "method": "handleClickedItem",
395
+ "target": undefined,
396
+ "capture": false,
397
+ "passive": false
398
+ }, {
399
+ "name": "wmKeyUpPressed",
400
+ "method": "handleKeyUp",
401
+ "target": undefined,
402
+ "capture": false,
403
+ "passive": false
404
+ }, {
405
+ "name": "wmKeyDownPressed",
406
+ "method": "handleKeyDown",
407
+ "target": undefined,
408
+ "capture": false,
409
+ "passive": false
410
+ }, {
411
+ "name": "wmHomeKeyPressed",
412
+ "method": "handleHomeKey",
413
+ "target": undefined,
414
+ "capture": false,
415
+ "passive": false
416
+ }, {
417
+ "name": "wmEndKeyPressed",
418
+ "method": "handleEndKey",
419
+ "target": undefined,
420
+ "capture": false,
421
+ "passive": false
422
+ }, {
423
+ "name": "wmTabKeyPressed",
424
+ "method": "handleTabKey",
425
+ "target": undefined,
426
+ "capture": false,
427
+ "passive": false
428
+ }, {
429
+ "name": "wmEscKeyPressed",
430
+ "method": "handleEscKey",
431
+ "target": undefined,
432
+ "capture": false,
433
+ "passive": false
434
+ }, {
435
+ "name": "click",
436
+ "method": "handleClick",
437
+ "target": "document",
438
+ "capture": false,
439
+ "passive": false
440
+ }, {
441
+ "name": "keydown",
442
+ "method": "handleKey",
443
+ "target": undefined,
444
+ "capture": false,
445
+ "passive": false
446
+ }, {
447
+ "name": "wmMenuitemBlurred",
448
+ "method": "handleMenuitemBlur",
449
+ "target": undefined,
450
+ "capture": false,
451
+ "passive": false
452
+ }, {
453
+ "name": "blur",
454
+ "method": "close",
455
+ "target": undefined,
456
+ "capture": false,
457
+ "passive": false
458
+ }, {
459
+ "name": "wmLetterPressed",
460
+ "method": "findAndFocusItem",
461
+ "target": undefined,
462
+ "capture": false,
463
+ "passive": false
464
+ }]; }
465
+ }