q2-tecton-elements 1.23.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.
- package/dist/cjs/action-sheet-4b366e9a.js +84 -0
- package/dist/cjs/{index-0648c2ec.js → index-e00b4210.js} +28 -5
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/q2-action-sheet.cjs.entry.js +218 -0
- package/dist/cjs/q2-badge_2.cjs.entry.js +1 -1
- package/dist/cjs/q2-btn_2.cjs.entry.js +1 -1
- package/dist/cjs/q2-calendar.cjs.entry.js +1 -1
- package/dist/cjs/q2-card.cjs.entry.js +1 -1
- package/dist/cjs/q2-carousel-pane.cjs.entry.js +1 -1
- package/dist/cjs/q2-carousel.cjs.entry.js +1 -1
- package/dist/cjs/q2-chart-area.cjs.entry.js +1 -1
- package/dist/cjs/q2-chart-bar.cjs.entry.js +1 -1
- package/dist/cjs/q2-chart-donut.cjs.entry.js +1 -1
- package/dist/cjs/q2-checkbox-group.cjs.entry.js +1 -1
- package/dist/cjs/q2-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/q2-dropdown-item.cjs.entry.js +1 -1
- package/dist/cjs/q2-dropdown.cjs.entry.js +1 -1
- package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
- package/dist/cjs/q2-icon.cjs.entry.js +1 -1
- package/dist/cjs/q2-loc.cjs.entry.js +1 -1
- package/dist/cjs/q2-message.cjs.entry.js +1 -1
- package/dist/cjs/q2-month-picker.cjs.entry.js +1 -1
- package/dist/cjs/q2-optgroup_2.cjs.entry.js +93 -0
- package/dist/cjs/q2-option-list_2.cjs.entry.js +226 -86
- package/dist/cjs/q2-pagination.cjs.entry.js +1 -1
- package/dist/cjs/q2-pill.cjs.entry.js +57 -18
- package/dist/cjs/q2-radio-group.cjs.entry.js +1 -1
- package/dist/cjs/q2-radio.cjs.entry.js +1 -1
- package/dist/cjs/q2-section.cjs.entry.js +1 -1
- package/dist/cjs/q2-select.cjs.entry.js +148 -409
- package/dist/cjs/q2-stepper-pane.cjs.entry.js +1 -1
- package/dist/cjs/q2-stepper-vertical.cjs.entry.js +1 -1
- package/dist/cjs/q2-stepper.cjs.entry.js +1 -1
- package/dist/cjs/q2-tab-container.cjs.entry.js +1 -1
- package/dist/cjs/q2-tag.cjs.entry.js +21 -6
- package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
- package/dist/cjs/q2-textarea.cjs.entry.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/q2-action-sheet/index.js +345 -0
- package/dist/collection/components/q2-action-sheet/styles.css +215 -0
- package/dist/collection/components/q2-checkbox/index.js +2 -2
- package/dist/collection/components/q2-dropdown/index.js +1 -1
- package/dist/collection/components/q2-loading/index.js +1 -1
- package/dist/collection/components/q2-optgroup/styles.css +2 -2
- package/dist/collection/components/q2-option/index.js +1 -56
- package/dist/collection/components/q2-option/styles.css +7 -0
- package/dist/collection/components/q2-option-list/index.js +290 -102
- package/dist/collection/components/q2-pill/index.js +79 -18
- package/dist/collection/components/q2-pill/styles.css +1 -2
- package/dist/collection/components/q2-popover/index.js +17 -3
- package/dist/collection/components/q2-popover/styles.css +10 -67
- package/dist/collection/components/q2-radio/index.js +2 -2
- package/dist/collection/components/q2-select/index.js +179 -427
- package/dist/collection/components/q2-select/styles.css +5 -11
- package/dist/collection/components/q2-tag/index.js +38 -5
- package/dist/collection/utils/action-sheet.js +79 -0
- package/dist/collection/utils/index.js +26 -5
- package/dist/components/action-sheet.js +81 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/index10.js +1 -1
- package/dist/components/index11.js +42 -353
- package/dist/components/index12.js +44 -99
- package/dist/components/index13.js +495 -583
- package/dist/components/index14.js +137 -0
- package/dist/components/index15.js +626 -0
- package/dist/components/index5.js +1 -1
- package/dist/components/index6.js +1 -1
- package/dist/components/index7.js +1 -1
- package/dist/components/index8.js +1 -1
- package/dist/components/index9.js +2 -2
- package/dist/components/q2-action-sheet.d.ts +11 -0
- package/dist/components/q2-action-sheet.js +282 -0
- package/dist/components/q2-calendar.js +1 -1
- package/dist/components/q2-card.js +1 -1
- package/dist/components/q2-carousel-pane.js +1 -1
- package/dist/components/q2-carousel.js +1 -1
- package/dist/components/q2-chart-area.js +1 -1
- package/dist/components/q2-chart-bar.js +1 -1
- package/dist/components/q2-chart-donut.js +1 -1
- package/dist/components/q2-checkbox-group.js +1 -1
- package/dist/components/q2-checkbox.js +1 -1
- package/dist/components/q2-dropdown.js +2 -2
- package/dist/components/q2-editable-field.js +1 -1
- package/dist/components/q2-loc.js +1 -1
- package/dist/components/q2-month-picker.js +1 -1
- package/dist/components/q2-optgroup.js +1 -70
- package/dist/components/q2-option-list.js +1 -1
- package/dist/components/q2-option.js +1 -76
- package/dist/components/q2-pagination.js +1 -1
- package/dist/components/q2-pill.js +62 -21
- package/dist/components/q2-popover.js +1 -1
- package/dist/components/q2-radio-group.js +1 -1
- package/dist/components/q2-radio.js +3 -3
- package/dist/components/q2-section.js +1 -1
- package/dist/components/q2-select.js +179 -427
- package/dist/components/q2-stepper-pane.js +1 -1
- package/dist/components/q2-stepper-vertical.js +1 -1
- package/dist/components/q2-stepper.js +1 -1
- package/dist/components/q2-tab-container.js +1 -1
- package/dist/components/q2-tag.js +24 -8
- package/dist/components/q2-textarea.js +1 -1
- package/dist/esm/action-sheet-a9597b32.js +81 -0
- package/dist/esm/{index-501fd22e.js → index-ca21e539.js} +27 -6
- package/dist/esm/loader.js +1 -1
- package/dist/esm/q2-action-sheet.entry.js +214 -0
- package/dist/esm/q2-badge_2.entry.js +1 -1
- package/dist/esm/q2-btn_2.entry.js +1 -1
- package/dist/esm/q2-calendar.entry.js +1 -1
- package/dist/esm/q2-card.entry.js +1 -1
- package/dist/esm/q2-carousel-pane.entry.js +1 -1
- package/dist/esm/q2-carousel.entry.js +1 -1
- package/dist/esm/q2-chart-area.entry.js +1 -1
- package/dist/esm/q2-chart-bar.entry.js +1 -1
- package/dist/esm/q2-chart-donut.entry.js +1 -1
- package/dist/esm/q2-checkbox-group.entry.js +1 -1
- package/dist/esm/q2-checkbox.entry.js +1 -1
- package/dist/esm/q2-dropdown-item.entry.js +1 -1
- package/dist/esm/q2-dropdown.entry.js +1 -1
- package/dist/esm/q2-editable-field.entry.js +1 -1
- package/dist/esm/q2-icon.entry.js +1 -1
- package/dist/esm/q2-loc.entry.js +1 -1
- package/dist/esm/q2-message.entry.js +1 -1
- package/dist/esm/q2-month-picker.entry.js +1 -1
- package/dist/esm/q2-optgroup_2.entry.js +88 -0
- package/dist/esm/q2-option-list_2.entry.js +226 -86
- package/dist/esm/q2-pagination.entry.js +1 -1
- package/dist/esm/q2-pill.entry.js +57 -18
- package/dist/esm/q2-radio-group.entry.js +1 -1
- package/dist/esm/q2-radio.entry.js +1 -1
- package/dist/esm/q2-section.entry.js +1 -1
- package/dist/esm/q2-select.entry.js +148 -409
- package/dist/esm/q2-stepper-pane.entry.js +1 -1
- package/dist/esm/q2-stepper-vertical.entry.js +1 -1
- package/dist/esm/q2-stepper.entry.js +1 -1
- package/dist/esm/q2-tab-container.entry.js +1 -1
- package/dist/esm/q2-tag.entry.js +21 -6
- package/dist/esm/q2-tecton-elements.js +1 -1
- package/dist/esm/q2-textarea.entry.js +1 -1
- package/dist/q2-tecton-elements/{p-3e9a30c4.entry.js → p-0473f4f7.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-5b1aba1a.entry.js → p-13a1390b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-ebd7efa5.entry.js → p-13deb3ed.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-45d61789.entry.js → p-1d854203.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-1f71774f.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-6b7e1ebd.entry.js → p-256d3fe6.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-8dea9a0c.entry.js → p-282f0f8c.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-3603fcdc.entry.js → p-30969629.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-30cd888b.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-3fd5d010.entry.js → p-37cf9c97.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-53be87c8.entry.js → p-388349b5.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-5589ae0f.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-604b22a8.entry.js → p-619aed74.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-d68b5eb3.entry.js → p-63b67260.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-ba73ee1f.entry.js → p-63e363ad.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-d7b27803.entry.js → p-6736df05.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-72fe10cc.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-68ef0786.entry.js → p-75b817c6.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-a2add94e.entry.js → p-7a116095.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-d88e4383.entry.js → p-7c94119b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-24f4571d.entry.js → p-90572e43.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-91153c61.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-70b01387.entry.js → p-9792de8a.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-9acfa94e.js +1 -0
- package/dist/q2-tecton-elements/p-a1926e65.js +1 -0
- package/dist/q2-tecton-elements/{p-d27b2caa.entry.js → p-b3a8cdc5.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-9b101e22.entry.js → p-ce3f203c.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-bf41e71b.entry.js → p-ce91cd9b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-18629cbf.entry.js → p-cefc9d0b.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-d05beeb7.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-6be86940.entry.js → p-dc7c8371.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-acc77332.entry.js → p-e58581fc.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-38a33baa.entry.js → p-e886c55b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-7aa80653.entry.js → p-f94e7043.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-78fac0fa.entry.js → p-fcb7d191.entry.js} +1 -1
- package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
- package/dist/test/helpers.js +3 -2
- package/dist/types/components/q2-action-sheet/index.d.ts +52 -0
- package/dist/types/components/q2-checkbox/index.d.ts +4 -1
- package/dist/types/components/q2-option/index.d.ts +0 -3
- package/dist/types/components/q2-option-list/index.d.ts +16 -8
- package/dist/types/components/q2-pill/index.d.ts +10 -1
- package/dist/types/components/q2-popover/index.d.ts +2 -0
- package/dist/types/components/q2-select/index.d.ts +45 -47
- package/dist/types/components/q2-tag/index.d.ts +3 -2
- package/dist/types/components.d.ts +42 -13
- package/dist/types/global.d.ts +9 -2
- package/dist/types/utils/action-sheet.d.ts +12 -0
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/workspace/workspace/Tecton_tecton-production_master/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +1 -1
- package/package.json +3 -2
- package/dist/cjs/q2-optgroup.cjs.entry.js +0 -56
- package/dist/cjs/q2-option.cjs.entry.js +0 -46
- package/dist/esm/q2-optgroup.entry.js +0 -52
- package/dist/esm/q2-option.entry.js +0 -42
- package/dist/q2-tecton-elements/p-2c20fc43.entry.js +0 -1
- package/dist/q2-tecton-elements/p-3813f51d.entry.js +0 -1
- package/dist/q2-tecton-elements/p-a510290a.js +0 -1
- package/dist/q2-tecton-elements/p-ba76ecfd.entry.js +0 -1
- package/dist/q2-tecton-elements/p-bbdae095.entry.js +0 -1
- package/dist/q2-tecton-elements/p-f1d06917.entry.js +0 -1
- package/dist/q2-tecton-elements/p-f6e868c1.entry.js +0 -1
|
@@ -1,605 +1,517 @@
|
|
|
1
|
-
import { h } from '@stencil/core/internal/client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (
|
|
400
|
-
|
|
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
|
-
|
|
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
|
-
|
|
443
|
-
|
|
393
|
+
adjustActiveOptionAndScroll(numToAdd) {
|
|
394
|
+
this.activeIndex += numToAdd;
|
|
395
|
+
this.setActiveOption();
|
|
396
|
+
this.setFocusedOption();
|
|
397
|
+
this.scrollToActiveOption();
|
|
444
398
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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.noStrings) === 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
|
-
|
|
504
|
-
|
|
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
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
538
|
-
messageContainer.style.setProperty('height', `${height}px`);
|
|
435
|
+
this.updateSingleOptionAttrs();
|
|
539
436
|
}
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
function setPopProperties(target) {
|
|
543
|
-
var _a, _b, _c, _d;
|
|
544
|
-
const { dropdownContainer, popDirection } = target;
|
|
545
|
-
if (dropdownContainer) {
|
|
546
|
-
dropdownContainer.style.maxHeight = null;
|
|
547
|
-
}
|
|
548
|
-
if (popDirection) {
|
|
549
|
-
return (target.privatePopDirection = popDirection);
|
|
550
|
-
}
|
|
551
|
-
const controlElement = target.inputField || target.controlElement;
|
|
552
|
-
const minPopHeight = target.minPopHeight || null;
|
|
553
|
-
// Add sizable so that we can capture the height
|
|
554
|
-
dropdownContainer.classList.add('sizable');
|
|
555
|
-
const dropdownHeight = dropdownContainer.getBoundingClientRect().height;
|
|
556
|
-
dropdownContainer.classList.remove('sizable');
|
|
557
|
-
const { top: topOffset, height } = controlElement.getBoundingClientRect();
|
|
558
|
-
const scrollY = ((_b = (_a = window.Tecton) === null || _a === void 0 ? void 0 : _a.platformDimensions) === null || _b === void 0 ? void 0 : _b.scrollY) || 0;
|
|
559
|
-
const innerHeight = ((_d = (_c = window.Tecton) === null || _c === void 0 ? void 0 : _c.platformDimensions) === null || _d === void 0 ? void 0 : _d.innerHeight) || window.innerHeight;
|
|
560
|
-
const bottomOffset = scrollY + innerHeight - topOffset - height;
|
|
561
|
-
const canShowFullSizeBelow = bottomOffset > dropdownHeight;
|
|
562
|
-
const canShowFullSizeAbove = dropdownHeight <= topOffset;
|
|
563
|
-
// Prefer full size above or below
|
|
564
|
-
if (canShowFullSizeBelow) {
|
|
565
|
-
return (target.privatePopDirection = 'down');
|
|
566
|
-
}
|
|
567
|
-
else if (canShowFullSizeAbove || !minPopHeight) {
|
|
568
|
-
determinePopOffset(target);
|
|
569
|
-
return (target.privatePopDirection = 'up');
|
|
570
|
-
}
|
|
571
|
-
// If full size will not fit and minHeight is set, then make as tall as possible
|
|
572
|
-
const displayBuffer = 5;
|
|
573
|
-
const canShowSmallBelow = bottomOffset >= minPopHeight + displayBuffer;
|
|
574
|
-
if (canShowSmallBelow) {
|
|
575
|
-
const maxBelowHeight = Math.max(bottomOffset - displayBuffer, minPopHeight);
|
|
576
|
-
dropdownContainer.style.maxHeight = `${maxBelowHeight}px`;
|
|
577
|
-
return (target.privatePopDirection = 'down');
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
const maxAboveHeight = Math.max(topOffset, minPopHeight);
|
|
581
|
-
dropdownContainer.style.maxHeight = `${maxAboveHeight}px`;
|
|
582
|
-
determinePopOffset(target);
|
|
583
|
-
return (target.privatePopDirection = 'up');
|
|
584
437
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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") {
|
|
589
504
|
return;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
target.color = undefined;
|
|
602
|
-
}
|
|
603
|
-
};
|
|
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();
|
|
604
516
|
|
|
605
|
-
export {
|
|
517
|
+
export { Q2OptionList as Q, defineCustomElement as d };
|