q2-tecton-elements 1.23.0-alpha.0 → 1.24.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 (236) hide show
  1. package/dist/cjs/action-sheet-4b366e9a.js +84 -0
  2. package/dist/cjs/charting-d02cba1f.js +3127 -0
  3. package/dist/cjs/{index-3518c78c.js → index-e00b4210.js} +33 -7
  4. package/dist/cjs/{installCanvasRenderer-b4d10c92.js → installCanvasRenderer-6c4fbcc9.js} +230 -1130
  5. package/dist/cjs/installLabelLayout-d6b548fe.js +1048 -0
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/cjs/q2-action-sheet.cjs.entry.js +218 -0
  8. package/dist/cjs/q2-badge_2.cjs.entry.js +1 -1
  9. package/dist/cjs/q2-btn_2.cjs.entry.js +2 -2
  10. package/dist/cjs/q2-calendar.cjs.entry.js +1 -1
  11. package/dist/cjs/q2-card.cjs.entry.js +2 -2
  12. package/dist/cjs/q2-carousel-pane.cjs.entry.js +1 -1
  13. package/dist/cjs/q2-carousel.cjs.entry.js +1 -1
  14. package/dist/cjs/q2-chart-area.cjs.entry.js +4569 -0
  15. package/dist/cjs/q2-chart-bar.cjs.entry.js +25 -3133
  16. package/dist/cjs/q2-chart-donut.cjs.entry.js +9 -8
  17. package/dist/cjs/q2-checkbox-group.cjs.entry.js +1 -1
  18. package/dist/cjs/q2-checkbox.cjs.entry.js +2 -2
  19. package/dist/cjs/q2-dropdown-item.cjs.entry.js +1 -1
  20. package/dist/cjs/q2-dropdown.cjs.entry.js +1 -1
  21. package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
  22. package/dist/cjs/q2-icon.cjs.entry.js +1 -1
  23. package/dist/cjs/q2-loading-element.cjs.entry.js +1 -1
  24. package/dist/cjs/q2-loc.cjs.entry.js +1 -1
  25. package/dist/cjs/q2-message.cjs.entry.js +1 -1
  26. package/dist/cjs/q2-month-picker.cjs.entry.js +1 -1
  27. package/dist/cjs/q2-optgroup_2.cjs.entry.js +93 -0
  28. package/dist/cjs/q2-option-list_2.cjs.entry.js +230 -88
  29. package/dist/cjs/q2-pagination.cjs.entry.js +1 -1
  30. package/dist/cjs/q2-pill.cjs.entry.js +57 -18
  31. package/dist/cjs/q2-radio-group.cjs.entry.js +1 -1
  32. package/dist/cjs/q2-radio.cjs.entry.js +1 -1
  33. package/dist/cjs/q2-section.cjs.entry.js +1 -1
  34. package/dist/cjs/q2-select.cjs.entry.js +149 -409
  35. package/dist/cjs/q2-stepper-pane.cjs.entry.js +1 -1
  36. package/dist/cjs/q2-stepper-vertical.cjs.entry.js +1 -1
  37. package/dist/cjs/q2-stepper.cjs.entry.js +1 -1
  38. package/dist/cjs/q2-tab-container.cjs.entry.js +1 -1
  39. package/dist/cjs/q2-tag.cjs.entry.js +21 -6
  40. package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
  41. package/dist/cjs/q2-textarea.cjs.entry.js +1 -1
  42. package/dist/collection/collection-manifest.json +2 -0
  43. package/dist/collection/components/q2-action-sheet/index.js +345 -0
  44. package/dist/collection/components/q2-action-sheet/styles.css +215 -0
  45. package/dist/collection/components/q2-card/index.js +1 -1
  46. package/dist/collection/components/q2-chart-area/index.js +622 -0
  47. package/dist/collection/components/q2-chart-area/styles.css +82 -0
  48. package/dist/collection/components/q2-chart-bar/index.js +4 -4
  49. package/dist/collection/components/q2-chart-bar/styles.css +3 -6
  50. package/dist/collection/components/q2-chart-donut/index.js +1 -1
  51. package/dist/collection/components/q2-checkbox/index.js +2 -2
  52. package/dist/collection/components/q2-checkbox/styles.css +1 -0
  53. package/dist/collection/components/q2-dropdown/index.js +1 -1
  54. package/dist/collection/components/q2-loading/index.js +1 -1
  55. package/dist/collection/components/q2-loading/skeleton/q2-loading-element/styles.css +4 -0
  56. package/dist/collection/components/q2-loading/styles.css +4 -0
  57. package/dist/collection/components/q2-optgroup/styles.css +2 -2
  58. package/dist/collection/components/q2-option/index.js +1 -56
  59. package/dist/collection/components/q2-option/styles.css +7 -0
  60. package/dist/collection/components/q2-option-list/index.js +290 -102
  61. package/dist/collection/components/q2-pill/index.js +79 -18
  62. package/dist/collection/components/q2-pill/styles.css +1 -2
  63. package/dist/collection/components/q2-popover/index.js +21 -5
  64. package/dist/collection/components/q2-popover/styles.css +10 -67
  65. package/dist/collection/components/q2-radio/index.js +2 -2
  66. package/dist/collection/components/q2-select/index.js +197 -427
  67. package/dist/collection/components/q2-select/styles.css +5 -11
  68. package/dist/collection/components/q2-tag/index.js +38 -5
  69. package/dist/collection/utils/action-sheet.js +79 -0
  70. package/dist/collection/utils/index.js +31 -7
  71. package/dist/components/action-sheet.js +81 -0
  72. package/dist/components/charting.js +3113 -0
  73. package/dist/components/index.d.ts +2 -0
  74. package/dist/components/index.js +2 -0
  75. package/dist/components/index10.js +1 -1
  76. package/dist/components/index11.js +42 -353
  77. package/dist/components/index12.js +44 -97
  78. package/dist/components/index13.js +495 -580
  79. package/dist/components/index14.js +137 -0
  80. package/dist/components/index15.js +626 -0
  81. package/dist/components/index5.js +1 -1
  82. package/dist/components/index6.js +1 -1
  83. package/dist/components/index7.js +1 -1
  84. package/dist/components/index8.js +1 -1
  85. package/dist/components/index9.js +3 -3
  86. package/dist/components/installCanvasRenderer.js +188 -1123
  87. package/dist/components/installLabelLayout.js +1042 -0
  88. package/dist/components/q2-action-sheet.d.ts +11 -0
  89. package/dist/components/q2-action-sheet.js +282 -0
  90. package/dist/components/q2-calendar.js +1 -1
  91. package/dist/components/q2-card.js +2 -2
  92. package/dist/components/q2-carousel-pane.js +1 -1
  93. package/dist/components/q2-carousel.js +1 -1
  94. package/dist/components/q2-chart-area.d.ts +11 -0
  95. package/dist/components/q2-chart-area.js +4604 -0
  96. package/dist/components/q2-chart-bar.js +11 -3119
  97. package/dist/components/q2-chart-donut.js +4 -3
  98. package/dist/components/q2-checkbox-group.js +1 -1
  99. package/dist/components/q2-checkbox.js +2 -2
  100. package/dist/components/q2-dropdown.js +2 -2
  101. package/dist/components/q2-editable-field.js +1 -1
  102. package/dist/components/q2-loading-element.js +1 -1
  103. package/dist/components/q2-loc.js +1 -1
  104. package/dist/components/q2-month-picker.js +1 -1
  105. package/dist/components/q2-optgroup.js +1 -70
  106. package/dist/components/q2-option-list.js +1 -1
  107. package/dist/components/q2-option.js +1 -76
  108. package/dist/components/q2-pagination.js +1 -1
  109. package/dist/components/q2-pill.js +62 -21
  110. package/dist/components/q2-popover.js +1 -1
  111. package/dist/components/q2-radio-group.js +1 -1
  112. package/dist/components/q2-radio.js +3 -3
  113. package/dist/components/q2-section.js +1 -1
  114. package/dist/components/q2-select.js +181 -427
  115. package/dist/components/q2-stepper-pane.js +1 -1
  116. package/dist/components/q2-stepper-vertical.js +1 -1
  117. package/dist/components/q2-stepper.js +1 -1
  118. package/dist/components/q2-tab-container.js +1 -1
  119. package/dist/components/q2-tag.js +24 -8
  120. package/dist/components/q2-textarea.js +1 -1
  121. package/dist/esm/action-sheet-a9597b32.js +81 -0
  122. package/dist/esm/charting-2a73ba8e.js +3113 -0
  123. package/dist/esm/{index-9c591682.js → index-ca21e539.js} +32 -8
  124. package/dist/esm/{installCanvasRenderer-0143b52d.js → installCanvasRenderer-4a470516.js} +188 -1123
  125. package/dist/esm/installLabelLayout-d660eaad.js +1042 -0
  126. package/dist/esm/loader.js +1 -1
  127. package/dist/esm/q2-action-sheet.entry.js +214 -0
  128. package/dist/esm/q2-badge_2.entry.js +1 -1
  129. package/dist/esm/q2-btn_2.entry.js +2 -2
  130. package/dist/esm/q2-calendar.entry.js +1 -1
  131. package/dist/esm/q2-card.entry.js +2 -2
  132. package/dist/esm/q2-carousel-pane.entry.js +1 -1
  133. package/dist/esm/q2-carousel.entry.js +1 -1
  134. package/dist/esm/q2-chart-area.entry.js +4565 -0
  135. package/dist/esm/q2-chart-bar.entry.js +11 -3119
  136. package/dist/esm/q2-chart-donut.entry.js +4 -3
  137. package/dist/esm/q2-checkbox-group.entry.js +1 -1
  138. package/dist/esm/q2-checkbox.entry.js +2 -2
  139. package/dist/esm/q2-dropdown-item.entry.js +1 -1
  140. package/dist/esm/q2-dropdown.entry.js +1 -1
  141. package/dist/esm/q2-editable-field.entry.js +1 -1
  142. package/dist/esm/q2-icon.entry.js +1 -1
  143. package/dist/esm/q2-loading-element.entry.js +1 -1
  144. package/dist/esm/q2-loc.entry.js +1 -1
  145. package/dist/esm/q2-message.entry.js +1 -1
  146. package/dist/esm/q2-month-picker.entry.js +1 -1
  147. package/dist/esm/q2-optgroup_2.entry.js +88 -0
  148. package/dist/esm/q2-option-list_2.entry.js +230 -88
  149. package/dist/esm/q2-pagination.entry.js +1 -1
  150. package/dist/esm/q2-pill.entry.js +57 -18
  151. package/dist/esm/q2-radio-group.entry.js +1 -1
  152. package/dist/esm/q2-radio.entry.js +1 -1
  153. package/dist/esm/q2-section.entry.js +1 -1
  154. package/dist/esm/q2-select.entry.js +149 -409
  155. package/dist/esm/q2-stepper-pane.entry.js +1 -1
  156. package/dist/esm/q2-stepper-vertical.entry.js +1 -1
  157. package/dist/esm/q2-stepper.entry.js +1 -1
  158. package/dist/esm/q2-tab-container.entry.js +1 -1
  159. package/dist/esm/q2-tag.entry.js +21 -6
  160. package/dist/esm/q2-tecton-elements.js +1 -1
  161. package/dist/esm/q2-textarea.entry.js +1 -1
  162. package/dist/q2-tecton-elements/{p-db873db2.entry.js → p-0473f4f7.entry.js} +1 -1
  163. package/dist/q2-tecton-elements/{p-520c40f6.entry.js → p-13a1390b.entry.js} +1 -1
  164. package/dist/q2-tecton-elements/{p-9ebb283a.entry.js → p-13deb3ed.entry.js} +1 -1
  165. package/dist/q2-tecton-elements/{p-0ba564b1.entry.js → p-1d854203.entry.js} +1 -1
  166. package/dist/q2-tecton-elements/p-1f71774f.entry.js +1 -0
  167. package/dist/q2-tecton-elements/{p-18cc4758.entry.js → p-256d3fe6.entry.js} +1 -1
  168. package/dist/q2-tecton-elements/{p-9281adaa.entry.js → p-282f0f8c.entry.js} +1 -1
  169. package/dist/q2-tecton-elements/{p-2d2c5af2.entry.js → p-30969629.entry.js} +1 -1
  170. package/dist/q2-tecton-elements/p-30cd888b.entry.js +1 -0
  171. package/dist/q2-tecton-elements/{p-fc134a5d.entry.js → p-37cf9c97.entry.js} +1 -1
  172. package/dist/q2-tecton-elements/{p-fb37e67e.entry.js → p-388349b5.entry.js} +1 -1
  173. package/dist/q2-tecton-elements/p-458b1987.js +1 -0
  174. package/dist/q2-tecton-elements/p-52063431.js +39 -0
  175. package/dist/q2-tecton-elements/p-5589ae0f.entry.js +1 -0
  176. package/dist/q2-tecton-elements/p-619aed74.entry.js +1 -0
  177. package/dist/q2-tecton-elements/{p-4625184b.entry.js → p-63b67260.entry.js} +1 -1
  178. package/dist/q2-tecton-elements/{p-e4dc9ac0.entry.js → p-63e363ad.entry.js} +1 -1
  179. package/dist/q2-tecton-elements/{p-cbd1289a.entry.js → p-6736df05.entry.js} +1 -1
  180. package/dist/q2-tecton-elements/p-72fe10cc.entry.js +1 -0
  181. package/dist/q2-tecton-elements/{p-c4640b55.entry.js → p-75b817c6.entry.js} +1 -1
  182. package/dist/q2-tecton-elements/{p-c3f27fe2.entry.js → p-7a116095.entry.js} +1 -1
  183. package/dist/q2-tecton-elements/p-7c94119b.entry.js +1 -0
  184. package/dist/q2-tecton-elements/p-833398d1.js +1 -0
  185. package/dist/q2-tecton-elements/{p-ce015552.entry.js → p-90572e43.entry.js} +1 -1
  186. package/dist/q2-tecton-elements/p-91153c61.entry.js +1 -0
  187. package/dist/q2-tecton-elements/p-9792de8a.entry.js +1 -0
  188. package/dist/q2-tecton-elements/p-9acfa94e.js +1 -0
  189. package/dist/q2-tecton-elements/p-a1926e65.js +1 -0
  190. package/dist/q2-tecton-elements/{p-ffb48ccc.entry.js → p-b3a8cdc5.entry.js} +1 -1
  191. package/dist/q2-tecton-elements/p-ce3f203c.entry.js +1 -0
  192. package/dist/q2-tecton-elements/{p-041b3a82.entry.js → p-ce91cd9b.entry.js} +1 -1
  193. package/dist/q2-tecton-elements/{p-b8b00394.entry.js → p-cefc9d0b.entry.js} +1 -1
  194. package/dist/q2-tecton-elements/p-d05beeb7.entry.js +1 -0
  195. package/dist/q2-tecton-elements/p-dc7c8371.entry.js +1 -0
  196. package/dist/q2-tecton-elements/{p-16c11d74.entry.js → p-e58581fc.entry.js} +1 -1
  197. package/dist/q2-tecton-elements/{p-f800fd1e.entry.js → p-e886c55b.entry.js} +1 -1
  198. package/dist/q2-tecton-elements/{p-6e6b5b80.entry.js → p-f0ec4d2c.entry.js} +1 -1
  199. package/dist/q2-tecton-elements/{p-97aa8423.entry.js → p-f94e7043.entry.js} +1 -1
  200. package/dist/q2-tecton-elements/{p-c444a60b.entry.js → p-fcb7d191.entry.js} +1 -1
  201. package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
  202. package/dist/test/helpers.js +3 -2
  203. package/dist/types/components/q2-action-sheet/index.d.ts +52 -0
  204. package/dist/types/components/q2-card/index.d.ts +1 -1
  205. package/dist/types/components/q2-chart-area/index.d.ts +40 -0
  206. package/dist/types/components/q2-chart-bar/index.d.ts +2 -2
  207. package/dist/types/components/q2-chart-donut/index.d.ts +1 -1
  208. package/dist/types/components/q2-checkbox/index.d.ts +4 -1
  209. package/dist/types/components/q2-option/index.d.ts +0 -3
  210. package/dist/types/components/q2-option-list/index.d.ts +16 -8
  211. package/dist/types/components/q2-pill/index.d.ts +10 -1
  212. package/dist/types/components/q2-popover/index.d.ts +2 -0
  213. package/dist/types/components/q2-select/index.d.ts +46 -47
  214. package/dist/types/components/q2-tag/index.d.ts +3 -2
  215. package/dist/types/components.d.ts +100 -13
  216. package/dist/types/global.d.ts +10 -1
  217. package/dist/types/utils/action-sheet.d.ts +12 -0
  218. package/dist/types/utils/index.d.ts +3 -1
  219. package/dist/types/workspace/workspace/{_production_release_1.22.x-alpha → Tecton_tecton-production_master}/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +1 -1
  220. package/package.json +3 -2
  221. package/dist/cjs/q2-optgroup.cjs.entry.js +0 -56
  222. package/dist/cjs/q2-option.cjs.entry.js +0 -46
  223. package/dist/esm/q2-optgroup.entry.js +0 -52
  224. package/dist/esm/q2-option.entry.js +0 -42
  225. package/dist/q2-tecton-elements/p-0d8dd75a.entry.js +0 -1
  226. package/dist/q2-tecton-elements/p-0fad9c5a.entry.js +0 -1
  227. package/dist/q2-tecton-elements/p-1f85cced.js +0 -39
  228. package/dist/q2-tecton-elements/p-2c9b1308.entry.js +0 -1
  229. package/dist/q2-tecton-elements/p-5e374fbd.js +0 -1
  230. package/dist/q2-tecton-elements/p-6b52a262.entry.js +0 -1
  231. package/dist/q2-tecton-elements/p-aaf42539.entry.js +0 -1
  232. package/dist/q2-tecton-elements/p-cf41970f.entry.js +0 -1
  233. package/dist/q2-tecton-elements/p-de164483.entry.js +0 -1
  234. package/dist/q2-tecton-elements/p-e6d26f39.entry.js +0 -1
  235. package/dist/q2-tecton-elements/p-f1d06917.entry.js +0 -1
  236. package/dist/q2-tecton-elements/p-f35bf6a3.entry.js +0 -1
@@ -1,602 +1,517 @@
1
- import { h } from '@stencil/core/internal/client';
2
-
3
- function createCommonjsModule(fn, basedir, module) {
4
- return module = {
5
- path: basedir,
6
- exports: {},
7
- require: function (path, base) {
8
- return commonjsRequire();
9
- }
10
- }, fn(module, module.exports), module.exports;
11
- }
12
-
13
- function commonjsRequire () {
14
- throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
15
- }
16
-
17
- var smoothscroll = createCommonjsModule(function (module, exports) {
18
- /* smoothscroll v0.4.4 - 2019 - Dustan Kasten, Jeremias Menichelli - MIT License */
19
- (function () {
20
-
21
- // polyfill
22
- function polyfill() {
23
- // aliases
24
- var w = window;
25
- var d = document;
26
-
27
- // return if scroll behavior is supported and polyfill is not forced
28
- if (
29
- 'scrollBehavior' in d.documentElement.style &&
30
- w.__forceSmoothScrollPolyfill__ !== true
31
- ) {
32
- return;
33
- }
34
-
35
- // globals
36
- var Element = w.HTMLElement || w.Element;
37
- var SCROLL_TIME = 468;
38
-
39
- // object gathering original scroll methods
40
- var original = {
41
- scroll: w.scroll || w.scrollTo,
42
- scrollBy: w.scrollBy,
43
- elementScroll: Element.prototype.scroll || scrollElement,
44
- scrollIntoView: Element.prototype.scrollIntoView
45
- };
46
-
47
- // define timing method
48
- var now =
49
- w.performance && w.performance.now
50
- ? w.performance.now.bind(w.performance)
51
- : Date.now;
52
-
53
- /**
54
- * indicates if a the current browser is made by Microsoft
55
- * @method isMicrosoftBrowser
56
- * @param {String} userAgent
57
- * @returns {Boolean}
58
- */
59
- function isMicrosoftBrowser(userAgent) {
60
- var userAgentPatterns = ['MSIE ', 'Trident/', 'Edge/'];
61
-
62
- return new RegExp(userAgentPatterns.join('|')).test(userAgent);
63
- }
64
-
65
- /*
66
- * IE has rounding bug rounding down clientHeight and clientWidth and
67
- * rounding up scrollHeight and scrollWidth causing false positives
68
- * on hasScrollableSpace
69
- */
70
- var ROUNDING_TOLERANCE = isMicrosoftBrowser(w.navigator.userAgent) ? 1 : 0;
71
-
72
- /**
73
- * changes scroll position inside an element
74
- * @method scrollElement
75
- * @param {Number} x
76
- * @param {Number} y
77
- * @returns {undefined}
78
- */
79
- function scrollElement(x, y) {
80
- this.scrollLeft = x;
81
- this.scrollTop = y;
82
- }
83
-
84
- /**
85
- * returns result of applying ease math function to a number
86
- * @method ease
87
- * @param {Number} k
88
- * @returns {Number}
89
- */
90
- function ease(k) {
91
- return 0.5 * (1 - Math.cos(Math.PI * k));
92
- }
93
-
94
- /**
95
- * indicates if a smooth behavior should be applied
96
- * @method shouldBailOut
97
- * @param {Number|Object} firstArg
98
- * @returns {Boolean}
99
- */
100
- function shouldBailOut(firstArg) {
101
- if (
102
- firstArg === null ||
103
- typeof firstArg !== 'object' ||
104
- firstArg.behavior === undefined ||
105
- firstArg.behavior === 'auto' ||
106
- firstArg.behavior === 'instant'
107
- ) {
108
- // first argument is not an object/null
109
- // or behavior is auto, instant or undefined
110
- return true;
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
+ import { o as overrideFocus, n as nextPaint, i as isEventFromElement } from './index15.js';
3
+
4
+ const stylesCss = "*{box-sizing:border-box}*:active{outline:none}*:focus{outline:none;box-shadow:var(--const-double-focus-ring, 0 0 0 2px #ffffff, 0 0 0 4px #33b4ff #06C)}:host{box-shadow:none !important}::-moz-focus-inner{border:none}input,textarea,button{font-family:inherit;font-size:inherit;font-stretch:inherit}:host(.sr),:host(.sr) button{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}.sr,.sr button{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}.hidden{display:none}:host([hidden]){display:none}.invisible{visibility:hidden}:host{position:relative;width:100%;display:block;line-height:var(--tct-option-list-line-height, var(--t-option-list-line-height, var(--app-line-height, 1.428571429em)))}.content{text-align:start}:host([is-sizeable]) .content{display:block;height:auto}";
5
+
6
+ const Q2OptionList = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ this.__registerHost();
10
+ this.__attachShadow();
11
+ this.change = createEvent(this, "change", 7);
12
+ this.popoverState = createEvent(this, "popoverState", 7);
13
+ this.ready = createEvent(this, "ready", 3);
14
+ this.scheduledAfterRender = [];
15
+ /// Event Handlers ///
16
+ /* tslint:disable:cyclomatic-complexity */
17
+ this.externalKeydownHandler = (event) => {
18
+ event.stopPropagation();
19
+ const { activeIndex, customSearch, allOptions } = this;
20
+ const { key } = event;
21
+ let nextIndex;
22
+ switch (key) {
23
+ case ' ':
24
+ if (this.searchString) {
25
+ if (customSearch)
26
+ break;
27
+ this.searchOptions(key, true);
28
+ break;
29
+ }
30
+ this.setDefaultActiveElement();
31
+ break;
32
+ case 'Enter':
33
+ this.setDefaultActiveElement();
34
+ break;
35
+ case 'ArrowUp':
36
+ event.preventDefault();
37
+ this.activeIndex = 0;
38
+ nextIndex = !!this.selectedOptions.length ? this.getDefaultActiveIndex() : this.getNextVisibleIndex(-1);
39
+ if (nextIndex === -1)
40
+ break;
41
+ this.openDropdownWithActiveElement(nextIndex);
42
+ break;
43
+ case 'ArrowDown':
44
+ event.preventDefault();
45
+ this.activeIndex = 0;
46
+ nextIndex = !!this.selectedOptions.length ? this.getDefaultActiveIndex() : this.getNextVisibleIndex(0);
47
+ if (nextIndex === -1)
48
+ break;
49
+ this.openDropdownWithActiveElement(nextIndex);
50
+ break;
51
+ case 'Home':
52
+ event.preventDefault();
53
+ this.openDropdownWithActiveElement(0);
54
+ break;
55
+ case 'End':
56
+ event.preventDefault();
57
+ this.openDropdownWithActiveElement(allOptions.length - 1);
58
+ break;
59
+ case 'PageUp':
60
+ event.preventDefault();
61
+ this.openDropdownWithActiveElement(Math.max((activeIndex || 0) - 10, 0));
62
+ break;
63
+ case 'PageDown':
64
+ event.preventDefault();
65
+ this.openDropdownWithActiveElement(Math.min((activeIndex || 0) + 10, allOptions.length - 1));
66
+ break;
67
+ case 'Tab':
68
+ this.popoverState.emit({ open: false, action: 'close' });
69
+ break;
70
+ case 'Esc':
71
+ case 'Escape':
72
+ if (this.noSelect)
73
+ this.setActiveElement(null);
74
+ this.popoverState.emit({ open: false, action: 'close' });
75
+ break;
76
+ default:
77
+ if (customSearch)
78
+ break;
79
+ if (!key.match(/^[\w]$/))
80
+ break;
81
+ this.searchOptions(key, true);
82
+ break;
111
83
  }
112
-
113
- if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {
114
- // first argument is an object and behavior is smooth
115
- return false;
116
- }
117
-
118
- // throw error when behavior is not supported
119
- throw new TypeError(
120
- 'behavior member of ScrollOptions ' +
121
- firstArg.behavior +
122
- ' is not a valid value for enumeration ScrollBehavior.'
123
- );
124
- }
125
-
126
- /**
127
- * indicates if an element has scrollable space in the provided axis
128
- * @method hasScrollableSpace
129
- * @param {Node} el
130
- * @param {String} axis
131
- * @returns {Boolean}
132
- */
133
- function hasScrollableSpace(el, axis) {
134
- if (axis === 'Y') {
135
- return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;
84
+ };
85
+ this.internalKeydownHandler = (event) => {
86
+ event.stopPropagation();
87
+ const { activeIndex, customSearch, allOptions } = this;
88
+ const { key, shiftKey } = event;
89
+ let newOption;
90
+ switch (key) {
91
+ case ' ':
92
+ if (this.searchString) {
93
+ if (customSearch)
94
+ break;
95
+ this.searchOptions(key, false);
96
+ break;
97
+ }
98
+ event.preventDefault();
99
+ newOption = allOptions.find(element => element.active);
100
+ if (!newOption || newOption.disabled)
101
+ break;
102
+ this.selectOption(newOption);
103
+ break;
104
+ case 'Enter':
105
+ event.preventDefault();
106
+ newOption = allOptions.find(element => element.active);
107
+ if (!newOption || newOption.disabled)
108
+ break;
109
+ this.selectOption(newOption);
110
+ break;
111
+ case 'ArrowUp':
112
+ event.preventDefault();
113
+ const isFirstOptionActive = activeIndex === 0;
114
+ if (isFirstOptionActive)
115
+ break;
116
+ if (activeIndex === undefined) {
117
+ this.setDefaultActiveElement();
118
+ break;
119
+ }
120
+ else {
121
+ const nextIndex = this.getNextVisibleIndex(-1);
122
+ if (nextIndex === -1)
123
+ break;
124
+ this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
125
+ break;
126
+ }
127
+ case 'ArrowDown':
128
+ event.preventDefault();
129
+ const isLastOptionActive = activeIndex === allOptions.length - 1;
130
+ if (isLastOptionActive)
131
+ break;
132
+ if (activeIndex === undefined) {
133
+ this.setDefaultActiveElement();
134
+ break;
135
+ }
136
+ else {
137
+ const nextIndex = this.getNextVisibleIndex(1);
138
+ if (nextIndex === -1)
139
+ break;
140
+ this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
141
+ break;
142
+ }
143
+ case 'Home':
144
+ event.preventDefault();
145
+ this.openDropdownWithActiveElement(0);
146
+ break;
147
+ case 'End':
148
+ event.preventDefault();
149
+ this.openDropdownWithActiveElement(allOptions.length - 1);
150
+ break;
151
+ case 'PageUp':
152
+ event.preventDefault();
153
+ this.openDropdownWithActiveElement(Math.max(activeIndex - 10, 0));
154
+ break;
155
+ case 'PageDown':
156
+ event.preventDefault();
157
+ this.openDropdownWithActiveElement(Math.min(activeIndex + 10, allOptions.length - 1));
158
+ break;
159
+ case 'Tab':
160
+ if (shiftKey)
161
+ break;
162
+ newOption = allOptions.find(element => element.active);
163
+ if (!newOption || newOption.disabled)
164
+ return;
165
+ this.selectOption(newOption);
166
+ break;
167
+ case 'Esc':
168
+ case 'Escape':
169
+ if (this.noSelect)
170
+ this.setActiveElement(null);
171
+ this.popoverState.emit({ open: false, action: 'close' });
172
+ break;
173
+ default:
174
+ if (customSearch)
175
+ break;
176
+ if (!key.match(/^[\w]$/))
177
+ break;
178
+ this.searchOptions(key, false);
179
+ break;
136
180
  }
137
-
138
- if (axis === 'X') {
139
- return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;
181
+ };
182
+ /* tslint:enable:cyclomatic-complexity */
183
+ this.focusoutHandler = (event) => {
184
+ const { relatedTarget } = event;
185
+ const isInDropdown = this.allOptions.includes(relatedTarget);
186
+ const isInLightDom = !isInDropdown && this.hostElement.contains(relatedTarget);
187
+ if (isInDropdown || isInLightDom) {
188
+ event.stopPropagation();
140
189
  }
190
+ };
191
+ this.clickHandler = (event) => {
192
+ const target = event.target;
193
+ const option = target.closest('q2-option');
194
+ this.selectOption(option);
195
+ };
196
+ this.role = 'listbox';
197
+ this.customSearch = undefined;
198
+ this.noSelect = undefined;
199
+ this.align = undefined;
200
+ this.selectedOptions = [];
201
+ this.multiple = undefined;
202
+ this.disabled = undefined;
203
+ this.showSelected = undefined;
204
+ this.type = undefined;
205
+ this.hasOptions = undefined;
206
+ }
207
+ /// LifeCycle Hooks ///
208
+ componentWillLoad() {
209
+ this.hasOptions = !!this.hostElement.querySelectorAll('q2-option').length;
210
+ }
211
+ componentDidLoad() {
212
+ overrideFocus(this.hostElement);
213
+ this.checkOptions();
214
+ this.selectedOptionsUpdated();
215
+ this.ready.emit();
216
+ }
217
+ componentDidRender() {
218
+ this.scheduledAfterRender.forEach(fn => fn());
219
+ this.scheduledAfterRender = [];
220
+ }
221
+ /// Getters ///
222
+ get allContents() {
223
+ const rootSlot = this.getRootSlot(this.hostElement);
224
+ const acceptedTags = ['Q2-OPTGROUP', 'Q2-OPTION'];
225
+ return rootSlot.filter(element => acceptedTags.includes(element.tagName));
226
+ }
227
+ get allOptions() {
228
+ const contents = this.allContents;
229
+ const extractOptions = (elements) => {
230
+ return elements.reduce((acc, element) => {
231
+ if (element.tagName === 'Q2-OPTGROUP') {
232
+ return [...acc, ...extractOptions(Array.from(element.children))];
233
+ }
234
+ else if (element.tagName === 'Q2-OPTION') {
235
+ return [...acc, element];
236
+ }
237
+ else {
238
+ return acc;
239
+ }
240
+ }, []);
241
+ };
242
+ return extractOptions(contents);
243
+ }
244
+ get allVisibleOptions() {
245
+ return this.allOptions.filter(option => !option.hidden && !option._multiSelectHidden && !option.disabled && !option.disabledGroup);
246
+ }
247
+ /// Helpers ///
248
+ async checkOptions() {
249
+ const { type } = this;
250
+ const options = await this.getOptions();
251
+ if (!type)
252
+ return;
253
+ const optionRole = type === 'menu' ? 'menuitem' : 'option';
254
+ options.forEach(option => {
255
+ option.role = optionRole;
256
+ });
257
+ }
258
+ getRootSlot(element) {
259
+ var _a;
260
+ const slot = element.querySelector('slot');
261
+ const assignedElements = (_a = slot === null || slot === void 0 ? void 0 : slot.assignedElements()) !== null && _a !== void 0 ? _a : Array.from(element.children);
262
+ const hasAnotherSlot = !!assignedElements.length && assignedElements[0].tagName === 'SLOT';
263
+ if (hasAnotherSlot) {
264
+ return this.getRootSlot(assignedElements[0]);
141
265
  }
142
-
143
- /**
144
- * indicates if an element has a scrollable overflow property in the axis
145
- * @method canOverflow
146
- * @param {Node} el
147
- * @param {String} axis
148
- * @returns {Boolean}
149
- */
150
- function canOverflow(el, axis) {
151
- var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];
152
-
153
- return overflowValue === 'auto' || overflowValue === 'scroll';
154
- }
155
-
156
- /**
157
- * indicates if an element can be scrolled in either axis
158
- * @method isScrollable
159
- * @param {Node} el
160
- * @param {String} axis
161
- * @returns {Boolean}
162
- */
163
- function isScrollable(el) {
164
- var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');
165
- var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
166
-
167
- return isScrollableY || isScrollableX;
266
+ else {
267
+ return assignedElements;
168
268
  }
169
-
170
- /**
171
- * finds scrollable parent of an element
172
- * @method findScrollableParent
173
- * @param {Node} el
174
- * @returns {Node} el
175
- */
176
- function findScrollableParent(el) {
177
- while (el !== d.body && isScrollable(el) === false) {
178
- el = el.parentNode || el.host;
179
- }
180
-
181
- return el;
269
+ }
270
+ scrollToActiveOption() {
271
+ const activeOption = this.allOptions[this.activeIndex];
272
+ activeOption === null || activeOption === void 0 ? void 0 : activeOption.scrollIntoView({ block: 'nearest' });
273
+ }
274
+ openDropdownWithActiveElement(activeIndex) {
275
+ if (this.disabled)
276
+ return;
277
+ this.activeIndex = activeIndex;
278
+ this.popoverState.emit({ open: true, action: 'open' });
279
+ this.setActiveOption();
280
+ this.setFocusedOption();
281
+ nextPaint(() => {
282
+ this.scrollToActiveOption();
283
+ });
284
+ }
285
+ getDefaultActiveIndex() {
286
+ const { allOptions } = this;
287
+ const firstSelected = allOptions.findIndex(element => element.selected);
288
+ if (firstSelected > -1)
289
+ return firstSelected;
290
+ const firstEnabled = allOptions.findIndex(element => !element.hidden);
291
+ if (firstEnabled > -1)
292
+ return firstEnabled;
293
+ return 0;
294
+ }
295
+ updateSingleOptionAttrs() {
296
+ var _a;
297
+ const { allOptions, selectedOptions } = this;
298
+ const selectedValue = ((_a = selectedOptions[0]) === null || _a === void 0 ? void 0 : _a.value) || undefined;
299
+ allOptions.forEach(element => {
300
+ element.selected = element.value === selectedValue;
301
+ });
302
+ }
303
+ updateMultipleOptionAttrs() {
304
+ const { allOptions, selectedOptions } = this;
305
+ const selectedValues = selectedOptions.map(({ value }) => value);
306
+ allOptions.forEach(element => {
307
+ element.selected = selectedValues.includes(element.value);
308
+ });
309
+ }
310
+ setActiveOption() {
311
+ const activeIndex = this.activeIndex;
312
+ this.allOptions.forEach((element, elementIndex) => {
313
+ element.active = activeIndex === elementIndex;
314
+ });
315
+ }
316
+ setFocusedOption() {
317
+ const option = this.allOptions[this.activeIndex];
318
+ if (!option)
319
+ return;
320
+ const isHostElementVisible = !!this.hostElement.offsetParent;
321
+ if (isHostElementVisible)
322
+ option.focus();
323
+ else
324
+ nextPaint(() => option.focus());
325
+ }
326
+ getNextVisibleIndex(direction) {
327
+ const { allVisibleOptions, allOptions, activeIndex } = this;
328
+ const activeOption = allOptions[activeIndex];
329
+ const visibleActiveOptionIndex = allVisibleOptions.indexOf(activeOption);
330
+ let nextVisibleOptionIndex = visibleActiveOptionIndex + direction;
331
+ if (nextVisibleOptionIndex < 0) {
332
+ nextVisibleOptionIndex = allVisibleOptions.length - 1;
182
333
  }
183
-
184
- /**
185
- * self invoked function that, given a context, steps through scrolling
186
- * @method step
187
- * @param {Object} context
188
- * @returns {undefined}
189
- */
190
- function step(context) {
191
- var time = now();
192
- var value;
193
- var currentX;
194
- var currentY;
195
- var elapsed = (time - context.startTime) / SCROLL_TIME;
196
-
197
- // avoid elapsed times higher than one
198
- elapsed = elapsed > 1 ? 1 : elapsed;
199
-
200
- // apply easing to elapsed time
201
- value = ease(elapsed);
202
-
203
- currentX = context.startX + (context.x - context.startX) * value;
204
- currentY = context.startY + (context.y - context.startY) * value;
205
-
206
- context.method.call(context.scrollable, currentX, currentY);
207
-
208
- // scroll more if we have not reached our destination
209
- if (currentX !== context.x || currentY !== context.y) {
210
- w.requestAnimationFrame(step.bind(w, context));
211
- }
334
+ else if (nextVisibleOptionIndex > allVisibleOptions.length - 1) {
335
+ nextVisibleOptionIndex = 0;
212
336
  }
213
-
214
- /**
215
- * scrolls window or element with a smooth behavior
216
- * @method smoothScroll
217
- * @param {Object|Node} el
218
- * @param {Number} x
219
- * @param {Number} y
220
- * @returns {undefined}
221
- */
222
- function smoothScroll(el, x, y) {
223
- var scrollable;
224
- var startX;
225
- var startY;
226
- var method;
227
- var startTime = now();
228
-
229
- // define scroll context
230
- if (el === d.body) {
231
- scrollable = w;
232
- startX = w.scrollX || w.pageXOffset;
233
- startY = w.scrollY || w.pageYOffset;
234
- method = original.scroll;
235
- } else {
236
- scrollable = el;
237
- startX = el.scrollLeft;
238
- startY = el.scrollTop;
239
- method = scrollElement;
240
- }
241
-
242
- // scroll looping over a frame
243
- step({
244
- scrollable: scrollable,
245
- method: method,
246
- startTime: startTime,
247
- startX: startX,
248
- startY: startY,
249
- x: x,
250
- y: y
251
- });
337
+ const nextVisibleOption = allVisibleOptions[nextVisibleOptionIndex];
338
+ return allOptions.indexOf(nextVisibleOption);
339
+ }
340
+ focusSelectedSibling(option) {
341
+ const { allVisibleOptions, allOptions } = this;
342
+ const hasNoSiblings = allVisibleOptions.length < 2;
343
+ if (hasNoSiblings) {
344
+ this.showSelected = false;
345
+ return;
252
346
  }
253
-
254
- // ORIGINAL METHODS OVERRIDES
255
- // w.scroll and w.scrollTo
256
- w.scroll = w.scrollTo = function() {
257
- // avoid action when no arguments are passed
258
- if (arguments[0] === undefined) {
259
- return;
260
- }
261
-
262
- // avoid smooth behavior if not required
263
- if (shouldBailOut(arguments[0]) === true) {
264
- original.scroll.call(
265
- w,
266
- arguments[0].left !== undefined
267
- ? arguments[0].left
268
- : typeof arguments[0] !== 'object'
269
- ? arguments[0]
270
- : w.scrollX || w.pageXOffset,
271
- // use top prop, second argument if present or fallback to scrollY
272
- arguments[0].top !== undefined
273
- ? arguments[0].top
274
- : arguments[1] !== undefined
275
- ? arguments[1]
276
- : w.scrollY || w.pageYOffset
277
- );
278
-
279
- return;
280
- }
281
-
282
- // LET THE SMOOTHNESS BEGIN!
283
- smoothScroll.call(
284
- w,
285
- d.body,
286
- arguments[0].left !== undefined
287
- ? ~~arguments[0].left
288
- : w.scrollX || w.pageXOffset,
289
- arguments[0].top !== undefined
290
- ? ~~arguments[0].top
291
- : w.scrollY || w.pageYOffset
292
- );
293
- };
294
-
295
- // w.scrollBy
296
- w.scrollBy = function() {
297
- // avoid action when no arguments are passed
298
- if (arguments[0] === undefined) {
299
- return;
300
- }
301
-
302
- // avoid smooth behavior if not required
303
- if (shouldBailOut(arguments[0])) {
304
- original.scrollBy.call(
305
- w,
306
- arguments[0].left !== undefined
307
- ? arguments[0].left
308
- : typeof arguments[0] !== 'object' ? arguments[0] : 0,
309
- arguments[0].top !== undefined
310
- ? arguments[0].top
311
- : arguments[1] !== undefined ? arguments[1] : 0
312
- );
313
-
314
- return;
315
- }
316
-
317
- // LET THE SMOOTHNESS BEGIN!
318
- smoothScroll.call(
319
- w,
320
- d.body,
321
- ~~arguments[0].left + (w.scrollX || w.pageXOffset),
322
- ~~arguments[0].top + (w.scrollY || w.pageYOffset)
323
- );
324
- };
325
-
326
- // Element.prototype.scroll and Element.prototype.scrollTo
327
- Element.prototype.scroll = Element.prototype.scrollTo = function() {
328
- // avoid action when no arguments are passed
329
- if (arguments[0] === undefined) {
330
- return;
331
- }
332
-
333
- // avoid smooth behavior if not required
334
- if (shouldBailOut(arguments[0]) === true) {
335
- // if one number is passed, throw error to match Firefox implementation
336
- if (typeof arguments[0] === 'number' && arguments[1] === undefined) {
337
- throw new SyntaxError('Value could not be converted');
338
- }
339
-
340
- original.elementScroll.call(
341
- this,
342
- // use left prop, first number argument or fallback to scrollLeft
343
- arguments[0].left !== undefined
344
- ? ~~arguments[0].left
345
- : typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft,
346
- // use top prop, second argument or fallback to scrollTop
347
- arguments[0].top !== undefined
348
- ? ~~arguments[0].top
349
- : arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop
350
- );
351
-
352
- return;
353
- }
354
-
355
- var left = arguments[0].left;
356
- var top = arguments[0].top;
357
-
358
- // LET THE SMOOTHNESS BEGIN!
359
- smoothScroll.call(
360
- this,
361
- this,
362
- typeof left === 'undefined' ? this.scrollLeft : ~~left,
363
- typeof top === 'undefined' ? this.scrollTop : ~~top
364
- );
365
- };
366
-
367
- // Element.prototype.scrollBy
368
- Element.prototype.scrollBy = function() {
369
- // avoid action when no arguments are passed
370
- if (arguments[0] === undefined) {
371
- return;
372
- }
373
-
374
- // avoid smooth behavior if not required
375
- if (shouldBailOut(arguments[0]) === true) {
376
- original.elementScroll.call(
377
- this,
378
- arguments[0].left !== undefined
379
- ? ~~arguments[0].left + this.scrollLeft
380
- : ~~arguments[0] + this.scrollLeft,
381
- arguments[0].top !== undefined
382
- ? ~~arguments[0].top + this.scrollTop
383
- : ~~arguments[1] + this.scrollTop
384
- );
385
-
386
- return;
387
- }
388
-
389
- this.scroll({
390
- left: ~~arguments[0].left + this.scrollLeft,
391
- top: ~~arguments[0].top + this.scrollTop,
392
- behavior: arguments[0].behavior
393
- });
347
+ const selectedOptionVisibleIndex = allVisibleOptions.indexOf(option);
348
+ const nextVisibleSiblingIndex = selectedOptionVisibleIndex
349
+ ? selectedOptionVisibleIndex - 1
350
+ : selectedOptionVisibleIndex + 1;
351
+ const nextVisibleSibling = allVisibleOptions[nextVisibleSiblingIndex];
352
+ const nextSiblingIndex = allOptions.indexOf(nextVisibleSibling);
353
+ this.activeIndex = nextSiblingIndex;
354
+ this.setFocusedOption();
355
+ this.scheduledAfterRender.push(() => {
356
+ option._multiSelectHidden = !option.selected;
357
+ });
358
+ }
359
+ selectOption(selectedOption) {
360
+ const { multiple, noSelect, showSelected } = this;
361
+ if (!selectedOption || selectedOption.disabled || selectedOption.disabledGroup)
362
+ return;
363
+ const selectedValue = selectedOption.value;
364
+ const valueObject = {
365
+ value: selectedValue,
366
+ display: selectedOption.display || selectedOption.innerText.trim(),
394
367
  };
395
-
396
- // Element.prototype.scrollIntoView
397
- Element.prototype.scrollIntoView = function() {
398
- // avoid smooth behavior if not required
399
- if (shouldBailOut(arguments[0]) === true) {
400
- original.scrollIntoView.call(
401
- this,
402
- arguments[0] === undefined ? true : arguments[0]
403
- );
404
-
405
- return;
368
+ let values = [];
369
+ if (multiple) {
370
+ const { selectedOptions } = this;
371
+ const isAlreadySelected = selectedOptions.find(option => option.value === selectedValue);
372
+ if (isAlreadySelected) {
373
+ values = selectedOptions.filter(({ value }) => value !== selectedValue);
406
374
  }
407
-
408
- // LET THE SMOOTHNESS BEGIN!
409
- var scrollableParent = findScrollableParent(this);
410
- var parentRects = scrollableParent.getBoundingClientRect();
411
- var clientRects = this.getBoundingClientRect();
412
-
413
- if (scrollableParent !== d.body) {
414
- // reveal element inside parent
415
- smoothScroll.call(
416
- this,
417
- scrollableParent,
418
- scrollableParent.scrollLeft + clientRects.left - parentRects.left,
419
- scrollableParent.scrollTop + clientRects.top - parentRects.top
420
- );
421
-
422
- // reveal parent in viewport unless is fixed
423
- if (w.getComputedStyle(scrollableParent).position !== 'fixed') {
424
- w.scrollBy({
425
- left: parentRects.left,
426
- top: parentRects.top,
427
- behavior: 'smooth'
428
- });
429
- }
430
- } else {
431
- // reveal element in viewport
432
- w.scrollBy({
433
- left: clientRects.left,
434
- top: clientRects.top,
435
- behavior: 'smooth'
436
- });
375
+ else {
376
+ values = [...selectedOptions, valueObject];
437
377
  }
438
- };
378
+ if (showSelected)
379
+ this.focusSelectedSibling(selectedOption);
380
+ }
381
+ else {
382
+ values = [valueObject];
383
+ }
384
+ if (noSelect)
385
+ this.setActiveElement(null);
386
+ else
387
+ this.selectedOptions = values;
388
+ this.change.emit({ value: selectedValue, values });
389
+ if (multiple)
390
+ return;
391
+ this.popoverState.emit({ open: false, action: 'select' });
439
392
  }
440
-
441
- {
442
- // commonjs
443
- module.exports = { polyfill: polyfill };
393
+ adjustActiveOptionAndScroll(numToAdd) {
394
+ this.activeIndex += numToAdd;
395
+ this.setActiveOption();
396
+ this.setFocusedOption();
397
+ this.scrollToActiveOption();
444
398
  }
445
-
446
- }());
447
- });
448
-
449
- function isRelatedTargetWithinHost(event, element) {
450
- return event.relatedTarget !== element && !element.contains(event.relatedTarget);
451
- }
452
- function isEventFromElement(event, element) {
453
- var _a;
454
- return ((_a = event.composedPath) === null || _a === void 0 ? void 0 : _a.call(event)[0]) === element;
455
- }
456
- function overrideFocus(hostElement) {
457
- hostElement.focus = () => hostElement === null || hostElement === void 0 ? void 0 : hostElement.dispatchEvent(new FocusEvent('focus', { bubbles: false }));
458
- }
459
- function addSmoothScrollPolyfill() {
460
- if (!isSafari())
461
- return false;
462
- smoothscroll.polyfill();
463
- return (window.__forceSmoothScrollPolyfill__ = true);
464
- }
465
- function isFirefox() {
466
- const userAgent = navigator.userAgent.toLowerCase();
467
- return userAgent.includes('firefox');
468
- }
469
- function isTouchDevice() {
470
- return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
471
- }
472
- function isSafari() {
473
- const userAgent = navigator.userAgent.toLowerCase();
474
- return userAgent.includes('safari') && !userAgent.includes('chrome');
475
- }
476
- let guid = 1000;
477
- function createGuid() {
478
- return guid++;
479
- }
480
- function nextPaint(fn, execute) {
481
- if (execute)
482
- fn();
483
- else
484
- requestAnimationFrame(() => nextPaint(fn, true));
485
- }
486
- function loc(key, subs) {
487
- var _a, _b, _c;
488
- if (!key)
489
- return '';
490
- if (((_a = window.Tecton) === null || _a === void 0 ? void 0 : _a.noString) === true) {
491
- return key;
492
- }
493
- return (_c = (_b = window === null || window === void 0 ? void 0 : window.TectonElements) === null || _b === void 0 ? void 0 : _b.loc(key, subs)) !== null && _c !== void 0 ? _c : key;
494
- }
495
- function labelDOM(target) {
496
- const { label, hideLabel } = target;
497
- if (!label || hideLabel)
498
- return;
499
- let helpText = '';
500
- if (target.optional) {
501
- helpText = h("span", { class: "optional-tag" }, loc('tecton.element.input.optional'));
399
+ resetTimer() {
400
+ if (this.searchStringTimer) {
401
+ clearTimeout(this.searchStringTimer);
402
+ }
403
+ this.searchStringTimer = window.setTimeout(() => {
404
+ this.searchString = null;
405
+ }, 2000);
502
406
  }
503
- if (target.readonly) {
504
- helpText = h("span", { class: "optional-tag" }, loc('tecton.element.input.readonly'));
407
+ searchOptions(key, shouldSelect) {
408
+ this.resetTimer();
409
+ let searchString = this.searchString ? `${this.searchString}${key}` : key;
410
+ searchString = searchString.replace(/[^\w\s]/gi, '');
411
+ this.searchString = searchString;
412
+ const searchRegEx = new RegExp(`^${searchString}`, 'i');
413
+ const { allOptions } = this;
414
+ const foundIndex = allOptions.findIndex(option => option.value === searchString || option.textContent.trim().match(searchRegEx));
415
+ if (foundIndex === -1)
416
+ return;
417
+ if (shouldSelect)
418
+ this.selectOption(this.allOptions[foundIndex]);
419
+ else
420
+ this.setActiveElement(foundIndex);
505
421
  }
506
- return (h("label", { htmlFor: target.inputId, class: target.readonly ? 'readonly-field' : '' },
507
- loc(target.label),
508
- helpText));
509
- }
510
- function handleAriaLabel(target) {
511
- const { ariaLabel } = target;
512
- if (!ariaLabel)
513
- return;
514
- if ('hideLabel' in target)
515
- target.hideLabel = true;
516
- target.label = loc(ariaLabel);
517
- target.ariaLabel = undefined;
518
- }
519
- function messagesDOM(target) {
520
- const type = target.hasError ? 'danger' : 'info';
521
- return (h("div", { class: "messages-container" },
522
- h("q2-message", { appearance: "minimal", description: true, type: type },
523
- h("ul", { id: target.inputDescribedBy }, target.messages.map(message => (h("li", null, loc(message))))))));
524
- }
525
- function setMessageHeight(target) {
526
- const messageContainer = target.hostElement.shadowRoot.querySelector('.messages-container');
527
- const q2Message = messageContainer.querySelector('q2-message');
528
- nextPaint(() => {
529
- const height = target.showMessages && target.hasFocus ? q2Message.getBoundingClientRect().height : 0;
530
- if (messageContainer.style.getPropertyValue('height') === `${height}px`)
422
+ /// Watchers ///
423
+ showSelectedUpdated(showSelected) {
424
+ if (showSelected && this.selectedOptions.length === 0) {
425
+ this.showSelected = false;
531
426
  return;
532
- if (height === 0) {
533
- q2Message.classList.add('invisible');
534
- messageContainer.style.removeProperty('height');
427
+ }
428
+ this.allOptions.forEach(option => (option._multiSelectHidden = showSelected ? !option.selected : false));
429
+ }
430
+ selectedOptionsUpdated() {
431
+ if (this.multiple) {
432
+ this.updateMultipleOptionAttrs();
535
433
  }
536
434
  else {
537
- q2Message.classList.remove('invisible');
538
- messageContainer.style.setProperty('height', `${height}px`);
435
+ this.updateSingleOptionAttrs();
539
436
  }
540
- });
541
- }
542
- function setPopProperties(target) {
543
- const { dropdownContainer, popDirection } = target;
544
- if (dropdownContainer) {
545
- dropdownContainer.style.maxHeight = null;
546
- }
547
- if (popDirection) {
548
- return (target.privatePopDirection = popDirection);
549
- }
550
- const controlElement = target.inputField || target.controlElement;
551
- const minPopHeight = target.minPopHeight || null;
552
- // Add sizable so that we can capture the height
553
- dropdownContainer.classList.add('sizable');
554
- const dropdownHeight = dropdownContainer.getBoundingClientRect().height;
555
- dropdownContainer.classList.remove('sizable');
556
- const { top: topOffset, height } = controlElement.getBoundingClientRect();
557
- const bottomOffset = window.innerHeight - topOffset - height;
558
- const canShowFullSizeBelow = bottomOffset > dropdownHeight;
559
- const canShowFullSizeAbove = dropdownHeight <= topOffset;
560
- // Prefer full size above or below
561
- if (canShowFullSizeBelow) {
562
- return (target.privatePopDirection = 'down');
563
- }
564
- else if (canShowFullSizeAbove || !minPopHeight) {
565
- determinePopOffset(target);
566
- return (target.privatePopDirection = 'up');
567
- }
568
- // If full size will not fit and minHeight is set, then make as tall as possible
569
- const displayBuffer = 5;
570
- const canShowSmallBelow = bottomOffset >= minPopHeight + displayBuffer;
571
- if (canShowSmallBelow) {
572
- const maxBelowHeight = Math.max(bottomOffset - displayBuffer, minPopHeight);
573
- dropdownContainer.style.maxHeight = `${maxBelowHeight}px`;
574
- return (target.privatePopDirection = 'down');
575
- }
576
- else {
577
- const maxAboveHeight = Math.max(topOffset, minPopHeight);
578
- dropdownContainer.style.maxHeight = `${maxAboveHeight}px`;
579
- determinePopOffset(target);
580
- return (target.privatePopDirection = 'up');
581
437
  }
582
- }
583
- const determinePopOffset = ({ dropdownContainer, inputField }) => {
584
- var _a, _b;
585
- if (!inputField)
438
+ /// Listeners ///
439
+ delegateFocus(event) {
440
+ if (!isEventFromElement(event, this.hostElement))
441
+ return;
442
+ this.popoverState.emit({ open: true, action: 'open' });
443
+ const { activeIndex } = this;
444
+ if (typeof activeIndex === 'number' && activeIndex > -1) {
445
+ this.setActiveOption();
446
+ this.setFocusedOption();
447
+ }
448
+ else {
449
+ this.setDefaultActiveElement();
450
+ }
451
+ }
452
+ handleClick(event) {
453
+ event.stopPropagation();
454
+ }
455
+ /// Public Methods ///
456
+ async setDefaultActiveElement() {
457
+ this.activeIndex = this.getDefaultActiveIndex();
458
+ this.setActiveOption();
459
+ this.setFocusedOption();
460
+ }
461
+ async setActiveElement(index) {
462
+ this.activeIndex = index;
463
+ this.setActiveOption();
464
+ this.setFocusedOption();
465
+ }
466
+ async handleExternalKeydown(event) {
467
+ this.externalKeydownHandler(event);
468
+ }
469
+ async getContents() {
470
+ return this.allContents;
471
+ }
472
+ async getOptions() {
473
+ return this.allOptions;
474
+ }
475
+ /// DOM ///
476
+ render() {
477
+ return (h(Host, null, h("div", { class: "content", ref: el => (this.contentElement = el), onFocusout: this.focusoutHandler }, h("div", { class: "options", role: this.type || 'listbox', onKeyDown: this.internalKeydownHandler, onClick: this.clickHandler }, h("slot", null)))));
478
+ }
479
+ get hostElement() { return this; }
480
+ static get watchers() { return {
481
+ "showSelected": ["showSelectedUpdated"],
482
+ "selectedOptions": ["selectedOptionsUpdated"]
483
+ }; }
484
+ static get style() { return stylesCss; }
485
+ }, [1, "q2-option-list", {
486
+ "role": [513],
487
+ "customSearch": [516, "custom-search"],
488
+ "noSelect": [516, "no-select"],
489
+ "align": [513],
490
+ "selectedOptions": [1040],
491
+ "multiple": [516],
492
+ "disabled": [516],
493
+ "showSelected": [1540, "show-selected"],
494
+ "type": [1],
495
+ "hasOptions": [32],
496
+ "setDefaultActiveElement": [64],
497
+ "setActiveElement": [64],
498
+ "handleExternalKeydown": [64],
499
+ "getContents": [64],
500
+ "getOptions": [64]
501
+ }, [[0, "focus", "delegateFocus"], [0, "click", "handleClick"]]]);
502
+ function defineCustomElement() {
503
+ if (typeof customElements === "undefined") {
586
504
  return;
587
- const inputFieldHeight = (_b = (_a = inputField.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.input-field')) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().height;
588
- dropdownContainer.style.setProperty('--comp-dropup-offset', `${inputFieldHeight}px`);
589
- };
590
- const resizeIframe = () => {
591
- var _a, _b;
592
- return (_b = (_a = window.TectonElements) === null || _a === void 0 ? void 0 : _a.resizeIframe) === null || _b === void 0 ? void 0 : _b.call(_a);
593
- };
594
- // Handling color attribute (deprecated)
595
- const handleColor = (target) => {
596
- if (!target.intent && ['primary', 'secondary'].includes(target.color)) {
597
- target.intent = `workflow-${target.color}`;
598
- target.color = undefined;
599
- }
600
- };
505
+ }
506
+ const components = ["q2-option-list"];
507
+ components.forEach(tagName => { switch (tagName) {
508
+ case "q2-option-list":
509
+ if (!customElements.get(tagName)) {
510
+ customElements.define(tagName, Q2OptionList);
511
+ }
512
+ break;
513
+ } });
514
+ }
515
+ defineCustomElement();
601
516
 
602
- export { isTouchDevice as a, isRelatedTargetWithinHost as b, createGuid as c, addSmoothScrollPolyfill as d, setMessageHeight as e, labelDOM as f, handleColor as g, handleAriaLabel as h, isEventFromElement as i, isFirefox as j, loc as l, messagesDOM as m, nextPaint as n, overrideFocus as o, resizeIframe as r, setPopProperties as s };
517
+ export { Q2OptionList as Q, defineCustomElement as d };