@mapsindoors/map-template 1.93.2 → 1.94.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 (103) hide show
  1. package/dist/{GoogleMapsMap-982405ad.mjs → GoogleMapsMap-BqYRaFgc.mjs} +51 -62
  2. package/dist/MapboxMap-CUYrfLHY.mjs +34732 -0
  3. package/dist/_commonjsHelpers-ba3f0406.js +21 -0
  4. package/dist/combo-box-item.entry.js +15 -0
  5. package/dist/icon-b8d01d6f.js +24 -0
  6. package/dist/index-7e9696f3.js +1678 -0
  7. package/dist/index.js +1 -0
  8. package/dist/loader.js +18 -0
  9. package/dist/mapsindoors-react.es.js +3 -5
  10. package/dist/mapsindoors-react.umd.js +197 -582
  11. package/dist/mapsindoors-webcomponent.es.js +58512 -75790
  12. package/dist/mi-card_2.entry.js +28 -0
  13. package/dist/mi-chip.entry.js +22 -0
  14. package/dist/mi-column.entry.js +28 -0
  15. package/dist/mi-combo-box.entry.js +416 -0
  16. package/dist/mi-components.js +18 -0
  17. package/dist/mi-data-table.entry.js +302 -0
  18. package/dist/mi-distance_2.entry.js +67 -0
  19. package/dist/mi-dropdown-item.entry.js +15 -0
  20. package/dist/mi-dropdown.entry.js +610 -0
  21. package/dist/mi-floor-selector.entry.js +202 -0
  22. package/dist/mi-keyboard.entry.js +238 -0
  23. package/dist/mi-list-item-category.entry.js +48 -0
  24. package/dist/mi-list-item-location.entry.js +171 -0
  25. package/dist/mi-list.entry.js +56 -0
  26. package/dist/mi-location-booking.entry.js +5193 -0
  27. package/dist/mi-location-info.entry.js +63 -0
  28. package/dist/mi-map-googlemaps.entry.js +750 -0
  29. package/dist/mi-map-mapbox.entry.js +467 -0
  30. package/dist/mi-metric-card.entry.js +48 -0
  31. package/dist/mi-my-position.entry.js +986 -0
  32. package/dist/mi-notification.entry.js +127 -0
  33. package/dist/mi-route-instructions-heading.entry.js +73 -0
  34. package/dist/mi-route-instructions-maneuver-legacy.entry.js +82 -0
  35. package/dist/mi-route-instructions-maneuver.entry.js +82 -0
  36. package/dist/mi-route-instructions-step-legacy.entry.js +308 -0
  37. package/dist/mi-route-instructions-step.entry.js +321 -0
  38. package/dist/mi-route-instructions.entry.js +157 -0
  39. package/dist/mi-scroll-buttons.entry.js +112 -0
  40. package/dist/mi-search.entry.js +376 -0
  41. package/dist/mi-share-sms.entry.js +80 -0
  42. package/dist/mi-step-switcher.entry.js +31 -0
  43. package/dist/mi-tab-panel.entry.js +25 -0
  44. package/dist/mi-tab.entry.js +12 -0
  45. package/dist/mi-tabs.entry.js +47 -0
  46. package/dist/mi-time.entry.js +57 -0
  47. package/dist/mi-variables-9a6c8d4d.js +6 -0
  48. package/dist/polyfills/core-js.js +11 -0
  49. package/dist/polyfills/css-shim.js +1 -0
  50. package/dist/polyfills/dom.js +79 -0
  51. package/dist/polyfills/es5-html-element.js +1 -0
  52. package/dist/polyfills/index.js +34 -0
  53. package/dist/polyfills/system.js +6 -0
  54. package/dist/{reactcomponent-7fbbd9b2.mjs → reactcomponent-DTepe7hB.mjs} +14121 -14626
  55. package/dist/route-travel-mode.enum-7f4ce9c7.js +9 -0
  56. package/dist/sort-order.enum-64ce8998.js +552 -0
  57. package/dist/unit-system.enum-eaefb53e.js +7 -0
  58. package/dist/utils-ae714467.js +61 -0
  59. package/package.json +10 -6
  60. package/dist/MapboxMap-06ef82a3.mjs +0 -37815
  61. package/dist/_commonjsHelpers-ba3f0406-b96e6d6a.mjs +0 -22
  62. package/dist/combo-box-item.entry-d35f3d51.mjs +0 -15
  63. package/dist/icon-b8d01d6f-ddfa2c17.mjs +0 -25
  64. package/dist/mapsindoors-webcomponent.umd.js +0 -3245
  65. package/dist/mi-card_2.entry-fc772c35.mjs +0 -26
  66. package/dist/mi-chip.entry-81c742a1.mjs +0 -19
  67. package/dist/mi-column.entry-3a083282.mjs +0 -21
  68. package/dist/mi-combo-box.entry-cae6401a.mjs +0 -263
  69. package/dist/mi-data-table.entry-d4c3f445.mjs +0 -224
  70. package/dist/mi-distance_2.entry-a33ed69a.mjs +0 -339
  71. package/dist/mi-dropdown-item.entry-974d1e4f.mjs +0 -15
  72. package/dist/mi-dropdown.entry-5317db65.mjs +0 -349
  73. package/dist/mi-floor-selector.entry-185fbd8b.mjs +0 -115
  74. package/dist/mi-keyboard.entry-eaf4b9ef.mjs +0 -3103
  75. package/dist/mi-list-item-category.entry-9c95008c.mjs +0 -39
  76. package/dist/mi-list-item-location.entry-8b41e8f0.mjs +0 -137
  77. package/dist/mi-list.entry-1218d29d.mjs +0 -42
  78. package/dist/mi-location-booking.entry-270aaf5a.mjs +0 -4866
  79. package/dist/mi-location-info.entry-e4f7fd04.mjs +0 -32
  80. package/dist/mi-map-googlemaps.entry-81fa28d2.mjs +0 -467
  81. package/dist/mi-map-mapbox.entry-31821da3.mjs +0 -301
  82. package/dist/mi-metric-card.entry-40407f04.mjs +0 -29
  83. package/dist/mi-my-position.entry-bc48fe6e.mjs +0 -703
  84. package/dist/mi-notification.entry-9a2bc53b.mjs +0 -84
  85. package/dist/mi-route-instructions-heading.entry-e5b1ff04.mjs +0 -75
  86. package/dist/mi-route-instructions-maneuver-legacy.entry-2c3d73ab.mjs +0 -76
  87. package/dist/mi-route-instructions-maneuver.entry-c6f01024.mjs +0 -76
  88. package/dist/mi-route-instructions-step-legacy.entry-80bcf097.mjs +0 -202
  89. package/dist/mi-route-instructions-step.entry-db802e13.mjs +0 -231
  90. package/dist/mi-route-instructions.entry-62416e29.mjs +0 -143
  91. package/dist/mi-scroll-buttons.entry-92b62b21.mjs +0 -83
  92. package/dist/mi-search.entry-87f1e64a.mjs +0 -251
  93. package/dist/mi-share-sms.entry-b6725edb.mjs +0 -56
  94. package/dist/mi-step-switcher.entry-f8f6c040.mjs +0 -27
  95. package/dist/mi-tab-panel.entry-a89213c2.mjs +0 -22
  96. package/dist/mi-tab.entry-a2fb3f8c.mjs +0 -14
  97. package/dist/mi-tabs.entry-cd638ea7.mjs +0 -37
  98. package/dist/mi-time.entry-0b02870d.mjs +0 -46
  99. package/dist/mi-variables-9a6c8d4d-e06eec88.mjs +0 -8
  100. package/dist/route-travel-mode.enum-7f4ce9c7-a9c95a83.mjs +0 -8
  101. package/dist/sort-order.enum-64ce8998-b75ac596.mjs +0 -318
  102. package/dist/unit-system.enum-eaefb53e-0f424da4.mjs +0 -8
  103. package/dist/utils-ae714467-b07fc3be.mjs +0 -37
@@ -0,0 +1,610 @@
1
+ import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-7e9696f3.js';
2
+ import { S as SortOrder, f as fuzzysort } from './sort-order.enum-64ce8998.js';
3
+ import './_commonjsHelpers-ba3f0406.js';
4
+
5
+ /**
6
+ * Performs function composition in LTR (Left To Right) direction.
7
+ *
8
+ * @example
9
+ * const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
10
+ *
11
+ * const getInitials = pipe(
12
+ * normalizeWhiteSpaces,
13
+ * name => name.split(' ').map(name => name.charAt(0)),
14
+ * initials => initials.join('').toLocaleUpperCase()
15
+ * );
16
+ *
17
+ * getInitials('Vitor Luiz Cavalcanti');
18
+ * //=> "VLC"
19
+ *
20
+ * @param {Function} fn - An arity N function. Its result is the argument of next one.
21
+ * @param {...Function[]} fns - Functions of arity 1. Each one's result is next's argument.
22
+ * @returns {Function}
23
+ */
24
+ function pipe(fn) {
25
+ var fns = [].slice.call(arguments, 1);
26
+ return function () {
27
+ return fns.reduce(function (x, fn) { return fn(x); }, fn.apply(null, arguments));
28
+ };
29
+ }
30
+
31
+ /**
32
+ * If `String.prototype.normalize` is supported it normalizes diacritics by
33
+ * replacing them with "clean" character from received text.
34
+ * @example
35
+ * normalizeDiacritics('Olá, você aí');
36
+ * //=> 'Ola, voce ai'
37
+ * @param {string} text - A `string` value.
38
+ * @returns {string}
39
+ */
40
+ var normalizeDiacritics = function (text) {
41
+ return !!String.prototype.normalize
42
+ ? text.normalize('NFKD').replace(/[\u0300-\u036F]/g, '')
43
+ : text;
44
+ };
45
+
46
+ /**
47
+ * Resolves a value to an array, if it isn't already an array.
48
+ * @template T
49
+ * @param {T | readonly T[]} value
50
+ * @returns {readonly T[]}
51
+ */
52
+ var resolveToArray = function (value) {
53
+ return Array.isArray(value) ? value : [value];
54
+ };
55
+
56
+ /**
57
+ * Normalize all white-space characters and remove trailing ones received text.
58
+ * @example
59
+ * normalizeWhiteSpaces(' What exactly is it? ');
60
+ * //=> "What exactly is it?"
61
+ *
62
+ * normalizeWhiteSpaces('Hi, how is \r\n everything \t?');
63
+ * //=> 'Hi, how is everything ?'
64
+ *
65
+ * normalizeWhiteSpaces`It is ${temperature}\n degree\r outside. `
66
+ * //=> 'It is 25 degree outside.'
67
+ * @param {TemplateStringsArray | string} partsOrText
68
+ * @param {unknown[]} values
69
+ * @returns {string}
70
+ */
71
+ function normalizeWhiteSpaces(partsOrText) {
72
+ var values = [];
73
+ for (var _i = 1; _i < arguments.length; _i++) {
74
+ values[_i - 1] = arguments[_i];
75
+ }
76
+ return resolveToArray(partsOrText)
77
+ .reduce(function (text, part, index) { return text + values[index - 1] + part; })
78
+ .replace(/\s+/g, ' ')
79
+ .trim();
80
+ }
81
+
82
+ /**
83
+ * Resolve one or multiple texts into a single one.
84
+ * @param {string | readonly string[]} values - A `string` or an array of `string` values.
85
+ * @returns {string}
86
+ */
87
+ var resolveToText = function (values) {
88
+ return Array.isArray(values) ? values.join(' ') : values;
89
+ };
90
+ /**
91
+ * Transforms a text to lower case.
92
+ * @param {string} text - A `string` value.
93
+ * @returns {string}
94
+ */
95
+ var transformToLowerCase = function (text) { return text.toLocaleLowerCase(); };
96
+ /**
97
+ * Resolve received texts (when receives an `Array`) by normalizing its
98
+ * white-spaces and its diacritics and transforming to lower-case.
99
+ * @example
100
+ * normalizeText(' so there\'s a Way to NORMALIZE ');
101
+ * //=> "so there\'s a way to normalize"
102
+ *
103
+ * normalizeText(['Olá\r\n', 'como está a senhorita?']);
104
+ * //=> "ola como esta a senhorita?"
105
+ * @param {string | readonly string[]} values - A `string` or an array of `string` values.
106
+ * @returns {string}
107
+ */
108
+ var normalizeText = /*#__PURE__*/ pipe(resolveToText, normalizeDiacritics, normalizeWhiteSpaces, transformToLowerCase);
109
+
110
+ const dropdownCss = ".mi-input[type=text],.mi-input[type=search],.mi-input[type=number],.mi-input[type=password],.mi-input[type=tel]{font-size:1rem;padding:8px;border-style:solid;border-width:1px;border-color:#8d98aa;border-radius:4px}.mi-input[type=text],.mi-input[type=search],.mi-input[type=number],.mi-input[type=password],.mi-input[type=range],.mi-input[type=tel]{display:block}.mi-input[type=radio],.mi-input[type=checkbox]{margin:0px;transform:scale(1.2, 1.2)}.mi-input[type=search]{padding-left:32px;background:url(\"data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 22' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14.6267 8.43836C14.6267 11.8561 11.8561 14.6267 8.43836 14.6267C5.02062 14.6267 2.25 11.8561 2.25 8.43836C2.25 5.02062 5.02062 2.25 8.43836 2.25C11.8561 2.25 14.6267 5.02062 14.6267 8.43836Z' stroke='%23aeb9cb' stroke-width='2.5'/%3E%3Crect x='15.0979' y='14.1614' width='7.34678' height='1.32449' rx='0.662244' transform='rotate(45 15.0979 14.1614)' fill='%23aeb9cb' stroke='%23aeb9cb'/%3E%3Crect x='13.7847' y='13.2916' width='1.05276' height='0.697347' transform='rotate(45 13.7847 13.2916)' stroke='%23aeb9cb' stroke-width='0.697346'/%3E%3C/svg%3E%0A\") no-repeat scroll 8px center, white}.mi-input:disabled{opacity:0.48;cursor:not-allowed}.mi-label{font-style:normal;display:block;font-size:1rem;font-weight:500;color:#1e2025}.mi-label>*{margin-top:4px}.mi-label>input[type=radio],.mi-label>input[type=checkbox],.mi-label>label.mi-toggle-btn{margin-right:8px}mi-dropdown-item{display:none}:host{display:inline-block;position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;user-select:none;font-family:Figtree, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}:host(.open) .button::after{border-top-color:transparent;border-bottom-color:#1f2937;margin-top:-8px}:host(.open) section{display:flex}:host(.open) svg.arrow{transform:rotate(180deg)}.button{display:flex;justify-content:flex-start;align-items:center;height:100%;width:100%;font-family:inherit;background:linear-gradient(#f9fafb, #f3f4f6);padding:0;padding-left:16px;padding-right:16px;border-radius:4px;border-width:1px;border-style:solid;border-color:#d1d5db;color:#1c1917;font-size:1rem;font-weight:500;line-height:1rem;gap:8px}.button__left-icon{height:20px;width:20px}.button svg{margin-left:auto}.button__label{padding-top:12px;padding-bottom:12px;display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.button__label--from-inner-html{display:grid;grid-auto-flow:column;grid-template-columns:24px 1fr;gap:8px;place-items:center}.button:disabled{opacity:0.72;cursor:not-allowed}.content{padding-top:12px;padding-bottom:12px;margin-top:12px;margin-bottom:12px;border-radius:8px;color:#1c1917;font-size:1rem;font-weight:500;background-color:#fcfcfc;box-shadow:0px 2px 2px rgba(0, 0, 0, 0.2), 0px 4px 4px rgba(0, 0, 0, 0.18), 0px 8px 8px rgba(0, 0, 0, 0.16);min-width:320px;max-width:480px;max-height:580px;display:none;flex-direction:column;position:fixed;z-index:10000}.content .filter{margin-bottom:16px;padding-left:8px;padding-right:8px;display:flex;position:relative}.content .filter__input{width:100%}.content .filter__clear{width:20px;height:20px;padding:0;border-width:0;display:flex;align-items:center;justify-content:center;position:absolute;right:14px;top:50%;transform:translateY(-50%);background-color:#1f2937;border-radius:50%}.content .filter__clear:focus{outline:0}.content .filter__clear--hidden{opacity:0;pointer-events:none}.content .filter__clear svg{fill:#fcfcfc;width:10px;height:10px}.content .options{margin-bottom:16px;padding-left:16px;padding-right:16px}.content .options__item{padding:0;color:#3b82f6;font-size:0.75rem;font-weight:500;font-family:inherit;background-color:transparent;border:transparent}.content .options__item:hover{text-decoration:underline}.content .options__item:first-child{margin-right:16px}.content .options__item:disabled{color:rgba(48, 113, 217, 0.72);cursor:not-allowed;text-decoration:none}.content .list{padding:0;margin:0;list-style:none;overflow-y:auto}.content .list__item{cursor:pointer}.content .list__item--disabled{opacity:0.72}.content .list__item--highlighted{background-color:#f3f4f6}.empty-page{display:flex;align-items:left;flex-direction:column;margin-left:16px;margin-bottom:12px}.empty-page>*{margin:0}.empty-page__header{font-size:1rem;font-weight:400;color:#374151}.label{display:flex;flex-direction:row;align-items:center;padding-left:16px;padding-right:16px;padding-top:8px;padding-bottom:8px}.label__item{display:inline-block;margin-top:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.label__item--from-inner-html{display:grid;grid-auto-flow:column;grid-template-columns:24px 1fr;gap:8px;place-items:center}.label__checkbox{margin-right:12px}.label__checkbox--hidden{display:none}";
111
+
112
+ var KeyCode;
113
+ (function (KeyCode) {
114
+ KeyCode["ArrowDown"] = "ArrowDown";
115
+ KeyCode["ArrowUp"] = "ArrowUp";
116
+ KeyCode["Enter"] = "Enter";
117
+ KeyCode["Esc"] = "Escape";
118
+ })(KeyCode || (KeyCode = {}));
119
+ const Dropdown = class {
120
+ constructor(hostRef) {
121
+ registerInstance(this, hostRef);
122
+ this.change = createEvent(this, "change", 3);
123
+ this.cleared = createEvent(this, "cleared", 7);
124
+ /**
125
+ * Sets the disabled state of the select buttons in the filterable version of the component.
126
+ */
127
+ this.isFilterSelectionDisabled = false;
128
+ /**
129
+ * Flag to control the visibility of the clear button for filterable components.
130
+ */
131
+ this.isClearButtonVisible = false;
132
+ /**
133
+ * Flag to control the mouseover event on the items. The event is disabled when using the arrow keys to navigate the list.
134
+ */
135
+ this.isMouseOverEventDisabled = false;
136
+ this.currentItemIndex = 0;
137
+ this.selectedItemIndex = 0;
138
+ this.highlightedItemClassName = 'list__item--highlighted';
139
+ this.open = false;
140
+ this.items = [];
141
+ this.itemsOrder = undefined;
142
+ this.label = undefined;
143
+ this.filterable = false;
144
+ this.placeholder = 'Type to filter...';
145
+ this.multiple = false;
146
+ this.selected = [];
147
+ this.noResultsMessage = 'No results found';
148
+ this.iconSrc = undefined;
149
+ this.iconAlt = undefined;
150
+ this.dropdownAlignment = 'left';
151
+ this.currentItems = [];
152
+ this.disabled = false;
153
+ }
154
+ /**
155
+ * Watcher for items property.
156
+ */
157
+ onItemsChanged(items) {
158
+ if (items.some(item => item.tagName.toLowerCase() !== 'mi-dropdown-item')) {
159
+ throw new Error('Items contains unknown element(s).');
160
+ }
161
+ if (Object.values(SortOrder).includes(this.itemsOrder)) {
162
+ items = this.getSortedItems(items);
163
+ }
164
+ this.currentItems = [...items];
165
+ this.filter();
166
+ if (!this.multiple) {
167
+ const selectedItemIndex = this.currentItems.findIndex(item => item.selected);
168
+ this.currentItemIndex = selectedItemIndex > -1 ? selectedItemIndex : 0;
169
+ this.selectedItemIndex = this.currentItemIndex;
170
+ }
171
+ this.items.forEach((item, itemIndex) => {
172
+ item.dataset.index = itemIndex.toString();
173
+ item.dataset.excludefromall = `${item.excludefromall}`;
174
+ });
175
+ this.selectFirstMiDropdownItem();
176
+ }
177
+ /**
178
+ * Watcher for currentItems property.
179
+ */
180
+ onCurrentItemsChange() {
181
+ this.isFilterSelectionDisabled = this.currentItems.length === 0;
182
+ }
183
+ /**
184
+ * Keyboard event listener.
185
+ * When the Tab key is pressed, the focus is set to the filter input field (If present).
186
+ *
187
+ * @param {KeyboardEvent} event
188
+ * @returns {void}
189
+ */
190
+ handleKeyDown(event) {
191
+ var _a;
192
+ if (event.key === 'Tab' && this.open) {
193
+ (_a = this.filterElement) === null || _a === void 0 ? void 0 : _a.focus();
194
+ event.preventDefault();
195
+ }
196
+ }
197
+ /**
198
+ * Outside the dropdown listener. It will close the dropdown when a click is outside a dropdown and dropdown list.
199
+ *
200
+ * @param {Event} event
201
+ */
202
+ checkForClickOutside(event) {
203
+ if (!this.hostElement.contains(event.target)) {
204
+ this.open = false;
205
+ }
206
+ }
207
+ /**
208
+ * Mousemove event handler.
209
+ * When the mouse is moved the mouseover event handler is enabled.
210
+ */
211
+ mouseMoveEventHandler() {
212
+ this.isMouseOverEventDisabled = false;
213
+ }
214
+ /**
215
+ * Scroll event handler.
216
+ * The dropdown is closed when the scroll event is trigget outside the dropdown.
217
+ */
218
+ scrollEventHandler(event) {
219
+ const target = event.target;
220
+ if (!target || !this.hostElement.contains(target)) {
221
+ this.open = false;
222
+ }
223
+ }
224
+ /**
225
+ * Resize event handler.
226
+ * Recalculate the position of the dropdown when the window is resized.
227
+ */
228
+ resizeEventHandler() {
229
+ this.calculateDropDownPosition();
230
+ }
231
+ /**
232
+ * Lifecycle method called when the component is loaded in the DOM.
233
+ */
234
+ componentDidLoad() {
235
+ this.createMiDropdownItemsFromDocument();
236
+ this.selectFirstMiDropdownItem();
237
+ this.enableKeyboardNavigationEvents();
238
+ const filterElementObserver = new IntersectionObserver((entries) => {
239
+ entries.forEach(entry => {
240
+ if (entry.isIntersecting === true) {
241
+ this.filterElement.focus();
242
+ }
243
+ });
244
+ });
245
+ if (this.filterElement !== undefined) {
246
+ filterElementObserver.observe(this.filterElement);
247
+ this.filterElement.addEventListener('keydown', (event) => {
248
+ if (event.key === KeyCode.ArrowDown || event.key === KeyCode.ArrowUp) {
249
+ event.preventDefault();
250
+ }
251
+ });
252
+ }
253
+ }
254
+ /**
255
+ * Lifecycle method called when the component is updated.
256
+ */
257
+ componentDidRender() {
258
+ this.calculateDropDownPosition();
259
+ if (!this.multiple) {
260
+ // Makes sure that an item is always highlighted when the content window is open.
261
+ this.highlightItem(this.currentItemIndex, true);
262
+ }
263
+ }
264
+ /**
265
+ * Gets all mi-dropdown-item elements for the mi-dropdown items property.
266
+ */
267
+ createMiDropdownItemsFromDocument() {
268
+ const items = this.items && this.items.length > 0 ? this.items : this.hostElement.querySelectorAll('mi-dropdown-item');
269
+ if (items.length > 0) {
270
+ this.items = Array.from(items);
271
+ }
272
+ }
273
+ /**
274
+ * Set the first mi-dropdown-item as the textual content of the button.
275
+ */
276
+ selectFirstMiDropdownItem() {
277
+ var _a;
278
+ if (!this.multiple) {
279
+ const selectedIndex = (_a = this.items) === null || _a === void 0 ? void 0 : _a.findIndex((item) => { return item.selected; });
280
+ this.selected = [this.items[selectedIndex > -1 ? selectedIndex : 0]];
281
+ }
282
+ }
283
+ /**
284
+ * Enables cycling through the items in the content window using arrow up/down keys.
285
+ */
286
+ enableKeyboardNavigationEvents() {
287
+ this.hostElement.addEventListener('keydown', event => {
288
+ if (this.open === false && event.key === KeyCode.ArrowDown) {
289
+ this.isMouseOverEventDisabled = true;
290
+ this.toggleContentWindow();
291
+ event.preventDefault();
292
+ return;
293
+ }
294
+ if (this.open === true && !this.multiple) {
295
+ switch (event.key) {
296
+ case KeyCode.ArrowDown:
297
+ this.isMouseOverEventDisabled = true;
298
+ this.currentItemIndex = (this.currentItemIndex + 1) % this.currentItems.length;
299
+ this.highlightItem(this.currentItemIndex, true);
300
+ event.preventDefault();
301
+ break;
302
+ case KeyCode.ArrowUp:
303
+ this.isMouseOverEventDisabled = true;
304
+ this.currentItemIndex = ((this.currentItemIndex + this.currentItems.length) - 1) % this.currentItems.length;
305
+ this.highlightItem(this.currentItemIndex, true);
306
+ event.preventDefault();
307
+ break;
308
+ case KeyCode.Enter:
309
+ if (this.hostElement.shadowRoot.activeElement === this.clearButtonElement) {
310
+ // When the clear button is focused and Enter is pressed, don't select the
311
+ // currently highlighted item or close the content window.
312
+ return;
313
+ }
314
+ if (this.currentItems[this.currentItemIndex] !== undefined) {
315
+ this.onSelect(this.currentItems[this.currentItemIndex]);
316
+ }
317
+ event.preventDefault();
318
+ break;
319
+ }
320
+ }
321
+ // This case must be applied to all types of the dropdown component.
322
+ if (event.key === KeyCode.Esc) {
323
+ if (!this.multiple) {
324
+ this.currentItemIndex = this.selectedItemIndex;
325
+ this.highlightItem(this.currentItemIndex);
326
+ }
327
+ this.toggleContentWindow();
328
+ this.clearFilter();
329
+ }
330
+ });
331
+ }
332
+ /**
333
+ * Updates the currently highlighted item in the markup.
334
+ *
335
+ * @param {number} itemIndex
336
+ */
337
+ highlightItem(itemIndex, scrollIntoView = false) {
338
+ var _a, _b;
339
+ const items = this.hostElement.shadowRoot.querySelectorAll('.list__item');
340
+ items.forEach(item => {
341
+ item.classList.remove(this.highlightedItemClassName);
342
+ });
343
+ (_a = items[itemIndex]) === null || _a === void 0 ? void 0 : _a.classList.add(this.highlightedItemClassName);
344
+ if (scrollIntoView) {
345
+ (_b = items[itemIndex]) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ block: 'nearest', inline: 'nearest' });
346
+ }
347
+ }
348
+ /**
349
+ * Get sorted items.
350
+ * The sorting order is defined by the itemsOrder attribute.
351
+ *
352
+ * @param {HTMLMiDropdownItemElement[]} items
353
+ * @returns {HTMLMiDropdownItemElement[]}
354
+ */
355
+ getSortedItems(items) {
356
+ if (this.itemsOrder === SortOrder.Asc) {
357
+ // Ascending order
358
+ items.sort((a, b) => (a.text || a.innerText)
359
+ .trimStart()
360
+ .toLowerCase()
361
+ .localeCompare((b.text || b.innerText).trimStart().toLowerCase(), undefined, { numeric: true }));
362
+ }
363
+ else {
364
+ // Descending order
365
+ items.sort((b, a) => (a.text || a.innerText)
366
+ .trimStart()
367
+ .toLowerCase()
368
+ .localeCompare((b.text || b.innerText).trimStart().toLowerCase(), undefined, { numeric: true }));
369
+ }
370
+ return items;
371
+ }
372
+ /**
373
+ * Update and emit list of selected items.
374
+ */
375
+ onChangedHandler() {
376
+ this.selected = [...this.items.filter(item => item.selected)];
377
+ this.change.emit(this.selected);
378
+ }
379
+ /**
380
+ * Toggle visibility of content window.
381
+ */
382
+ toggleContentWindow() {
383
+ this.open = !this.open;
384
+ }
385
+ /**
386
+ * Check all checkboxes.
387
+ */
388
+ selectAll() {
389
+ const items = Array.from(this.currentItems);
390
+ for (const item of items) {
391
+ item.selected = (`${item.dataset.excludefromall}` === 'true' || item.disabled) ? false : true;
392
+ }
393
+ this.onChangedHandler();
394
+ }
395
+ /**
396
+ * Uncheck all checkboxes.
397
+ */
398
+ selectNone() {
399
+ const items = Array.from(this.currentItems);
400
+ for (const item of items) {
401
+ item.selected = false;
402
+ }
403
+ this.onChangedHandler();
404
+ }
405
+ /**
406
+ * Select or toggle selection of item.
407
+ *
408
+ * @param {HTMLMiDropdownItemElement} item
409
+ */
410
+ onSelect(item) {
411
+ if (!this.multiple) {
412
+ this.open = false;
413
+ const items = Array.from(this.items);
414
+ items.forEach((item) => { item.selected = false; });
415
+ this.clearFilter();
416
+ }
417
+ item.selected = !item.selected;
418
+ this.currentItemIndex = Number(item.dataset.index);
419
+ this.selectedItemIndex = this.currentItemIndex;
420
+ this.onChangedHandler();
421
+ }
422
+ /**
423
+ * Highlights the item that the cursor is hovering in the content window.
424
+ *
425
+ * @param {number} filteredItemsIndex
426
+ */
427
+ onMouseOver(filteredItemsIndex) {
428
+ if (!this.isMouseOverEventDisabled && !this.multiple) {
429
+ this.highlightItem(filteredItemsIndex);
430
+ this.currentItemIndex = filteredItemsIndex;
431
+ }
432
+ }
433
+ /**
434
+ * Filter items based on the input query.
435
+ */
436
+ filter() {
437
+ if (this.filterElement) {
438
+ const inputQuery = this.filterElement.value;
439
+ // Normalize text by trimming whitespace, converting to lowercase, and removing diacritics.
440
+ // This ensures consistent matching/comparison of dropdown items.
441
+ const miDropdownItemTexts = this.items.map(item => (normalizeText(item.text) || normalizeText(item.innerText)));
442
+ const numberOfItemsDisplayed = this.currentItems.length;
443
+ if (inputQuery === '') {
444
+ this.currentItemIndex = this.selectedItemIndex;
445
+ this.isClearButtonVisible = false;
446
+ this.currentItems = [...this.items];
447
+ return;
448
+ }
449
+ else {
450
+ this.isClearButtonVisible = true;
451
+ }
452
+ const searchResultsOptions = {
453
+ limit: 50,
454
+ allowTypo: false,
455
+ threshold: -10000
456
+ };
457
+ // Normalize text by trimming whitespace, converting to lowercase, and removing diacritics.
458
+ // This ensures consistent matching/comparison of dropdown items.
459
+ const fuzzyResults = fuzzysort.go(normalizeText(inputQuery), miDropdownItemTexts, searchResultsOptions);
460
+ const filteredItems = fuzzyResults.map(result => this.items.find(item => (normalizeText(item.text) || normalizeText(item.innerText)) === normalizeText(result.target)));
461
+ this.currentItems = filteredItems;
462
+ if (numberOfItemsDisplayed !== this.currentItems.length) {
463
+ this.currentItemIndex = 0;
464
+ }
465
+ }
466
+ }
467
+ /**
468
+ * Clear filter.
469
+ */
470
+ clearFilter() {
471
+ if (this.filterElement) {
472
+ this.filterElement.value = '';
473
+ this.filterElement.focus();
474
+ this.currentItems = this.items;
475
+ this.cleared.emit();
476
+ }
477
+ this.isClearButtonVisible = false;
478
+ }
479
+ /**
480
+ * Render the dropdown component.
481
+ *
482
+ * @returns {JSX.Element}
483
+ */
484
+ render() {
485
+ const filter = this.filterable ? this.renderFiltering() : null;
486
+ const multiple = this.multiple ? this.renderMultipleOptions() : null;
487
+ const leftSideIcon = this.iconSrc ? this.renderLeftSideIcon() : null;
488
+ const listOfItems = (h("ul", { class: "list" }, this.currentItems.map((item, index) => this.renderListItem(item, index, (multiple ? true : false)))));
489
+ return (h(Host, { class: { 'open': this.open } }, h("button", { part: "button", class: "button", disabled: this.disabled || this.items.length === 0, onClick: () => this.toggleContentWindow() }, leftSideIcon, this.renderButtonLabel(), h("svg", { class: "arrow", part: "icon-down-arrow", width: "12", height: "6", viewBox: "0 0 18 10", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M9.37165 9.58706C9.17303 9.80775 8.82697 9.80775 8.62835 9.58706L0.751035 0.834484C0.46145 0.512722 0.689796 7.73699e-08 1.12268 1.25924e-07L16.8773 1.89302e-06C17.3102 1.94157e-06 17.5386 0.512723 17.249 0.834484L9.37165 9.58706Z" }))), h("section", { ref: (el) => this.listElement = el, part: "dropdown-container", class: "content", "tab-index": "1" }, filter, multiple, this.currentItems.length === 0 ? this.renderNoResultsTemplate() : listOfItems)));
490
+ }
491
+ /**
492
+ * Helper function to render markup when no items are available to be displayed in the content window.
493
+ *
494
+ * @returns {JSX.Element}
495
+ */
496
+ renderNoResultsTemplate() {
497
+ const noResultsTemplate = (h("div", { class: "empty-page" }, h("p", { class: "empty-page__header" }, this.noResultsMessage)));
498
+ return noResultsTemplate;
499
+ }
500
+ /**
501
+ * Helper function to render the button label.
502
+ *
503
+ * @returns {JSX.Element}
504
+ */
505
+ renderButtonLabel() {
506
+ var _a, _b, _c, _d, _e;
507
+ const label = (_a = this.label) !== null && _a !== void 0 ? _a : (_c = (_b = this.selected) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.text;
508
+ if (label > '') {
509
+ return (h("div", { part: "button-label", class: "button__label" }, label));
510
+ }
511
+ else if ((_e = (_d = this.selected) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.innerHTML) {
512
+ return (h("div", { part: "button-label", class: "button__label button__label--from-inner-html", innerHTML: this.selected[0].innerHTML }));
513
+ }
514
+ else {
515
+ return (h("div", { part: "button-label", class: "button__label" }));
516
+ }
517
+ }
518
+ /**
519
+ * Helper function to render an icon when an image source is provided.
520
+ *
521
+ * @returns {JSX.Element}
522
+ */
523
+ renderLeftSideIcon() {
524
+ return (h("img", { part: "button-icon", class: "button__left-icon", src: this.iconSrc, alt: this.iconAlt ? this.iconAlt : '' }));
525
+ }
526
+ /**
527
+ * Helper function for rendering the filtering UI.
528
+ *
529
+ * @returns {JSX.Element}
530
+ */
531
+ renderFiltering() {
532
+ return (h("div", { class: "filter" }, h("input", { type: "text", class: "mi-input filter__input", placeholder: this.placeholder, ref: (el) => this.filterElement = el, onInput: () => { this.filter(); }, tabIndex: this.open ? 0 : -1 }), h("button", { ref: (el) => this.clearButtonElement = el, tabindex: this.isClearButtonVisible ? 0 : -1, type: "button", onClick: () => this.clearFilter(), class: `filter__clear ${this.isClearButtonVisible === false ? 'filter__clear--hidden' : ''}`, "aria-label": "Clear" }, h("svg", { viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z" })))));
533
+ }
534
+ /**
535
+ * Helper function for rendering the multi select options.
536
+ *
537
+ * @returns {JSX.Element}
538
+ */
539
+ renderMultipleOptions() {
540
+ return (h("div", { class: "options" }, h("button", { class: "options__item", disabled: this.isFilterSelectionDisabled, onClick: () => this.selectAll() }, "Select all"), h("button", { class: "options__item", disabled: this.isFilterSelectionDisabled, onClick: () => this.selectNone() }, "Select none")));
541
+ }
542
+ /**
543
+ * Helper function for rendering list item.
544
+ *
545
+ * @param {HTMLMiDropdownItemElement} item
546
+ * @param {number} index
547
+ * @param {boolean} showCheckBox
548
+ * @returns {JSX.Element}
549
+ */
550
+ renderListItem(item, index, showCheckBox) {
551
+ let itemText;
552
+ const itemTooltipInfo = (item.getAttribute('title') || item.text || item.innerText);
553
+ if (item.innerText.length > 0) {
554
+ itemText = h("div", { class: "label__item label__item--from-inner-html", innerHTML: item.innerHTML });
555
+ }
556
+ else {
557
+ itemText = h("div", { class: "label__item", innerHTML: item.text });
558
+ }
559
+ return (h("li", { class: { 'list__item': true, 'list__item--disabled': item.disabled }, title: itemTooltipInfo, onMouseOver: () => { this.onMouseOver(index); } }, h("label", { class: "mi-label label", tabindex: "-1" }, h("input", { class: { 'label__checkbox': true, 'label__checkbox--hidden': !showCheckBox, 'mi-input': true }, type: "checkbox", value: index, checked: item.selected, disabled: item.disabled, "data-excludefromall": item.excludefromall, onChange: () => this.onSelect(item) }), itemText)));
560
+ }
561
+ /**
562
+ * Function for calculating the position of the dropdown list element.
563
+ */
564
+ calculateDropDownPosition() {
565
+ this.listElement.style.bottom = null;
566
+ this.listElement.style.left = null;
567
+ this.listElement.style.right = null;
568
+ this.listElement.style.top = null;
569
+ this.listElement.style.maxHeight = null;
570
+ this.listElement.style.minWidth = null;
571
+ const { clientWidth, clientHeight } = document.documentElement;
572
+ const hostElementRect = this.hostElement.getBoundingClientRect();
573
+ const listElementRect = this.listElement.getBoundingClientRect();
574
+ const availableSpaceBelowComponent = clientHeight - hostElementRect.bottom;
575
+ const availableSpaceAboveComponent = hostElementRect.top;
576
+ const MAX_HEIGHT = 580;
577
+ const MARGIN = 12;
578
+ if (clientWidth <= listElementRect.width || (hostElementRect.right - listElementRect.width < 0 && listElementRect.right > clientWidth)) {
579
+ this.listElement.style.right = `${MARGIN}px`;
580
+ this.listElement.style.left = `${MARGIN}px`;
581
+ this.listElement.style.minWidth = 'unset';
582
+ }
583
+ else if (listElementRect.right > clientWidth || this.dropdownAlignment === 'right') {
584
+ this.listElement.style.left = 'unset';
585
+ this.listElement.style.right = `${clientWidth - hostElementRect.right}px`;
586
+ }
587
+ else {
588
+ this.listElement.style.left = `${hostElementRect.left}px`;
589
+ this.listElement.style.right = 'unset';
590
+ }
591
+ if (availableSpaceAboveComponent > availableSpaceBelowComponent) {
592
+ this.listElement.style.maxHeight = `${Math.min(availableSpaceAboveComponent, MAX_HEIGHT)}px`;
593
+ this.listElement.style.top = 'unset';
594
+ this.listElement.style.bottom = `${clientHeight - hostElementRect.top}px`;
595
+ }
596
+ else {
597
+ this.listElement.style.top = `${hostElementRect.bottom}px`;
598
+ this.listElement.style.bottom = 'unset';
599
+ this.listElement.style.maxHeight = `${Math.min(availableSpaceBelowComponent - (MARGIN * 2), MAX_HEIGHT)}px`;
600
+ }
601
+ }
602
+ get hostElement() { return getElement(this); }
603
+ static get watchers() { return {
604
+ "items": ["onItemsChanged"],
605
+ "currentItems": ["onCurrentItemsChange"]
606
+ }; }
607
+ };
608
+ Dropdown.style = dropdownCss;
609
+
610
+ export { Dropdown as mi_dropdown };