q2-tecton-elements 1.21.2 → 1.22.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/installCanvasRenderer-b4d10c92.js +38433 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/q2-badge_2.cjs.entry.js +5 -3
- package/dist/cjs/q2-calendar.cjs.entry.js +75 -55
- package/dist/cjs/q2-carousel.cjs.entry.js +3 -3
- package/dist/cjs/q2-chart-bar.cjs.entry.js +4679 -0
- package/dist/cjs/q2-chart-donut.cjs.entry.js +357 -35592
- package/dist/cjs/q2-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
- package/dist/cjs/q2-radio.cjs.entry.js +1 -1
- package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/q2-calendar/index.js +43 -2
- package/dist/collection/components/q2-chart-bar/index.js +466 -0
- package/dist/collection/components/q2-chart-bar/styles.css +85 -0
- package/dist/collection/components/q2-chart-donut/index.js +3 -3
- package/dist/collection/components/q2-checkbox/styles.css +5 -1
- package/dist/collection/components/q2-editable-field/styles.css +1 -1
- package/dist/collection/components/q2-input/formatting/phone.js +2 -2
- package/dist/collection/components/q2-input/index.js +21 -0
- package/dist/collection/components/q2-input/styles.css +2 -2
- package/dist/collection/components/q2-radio/styles.css +1 -1
- package/dist/collection/utils/charting.js +182 -0
- package/dist/components/click-elsewhere.d.ts +11 -0
- package/dist/components/click-elsewhere.js +6 -0
- package/dist/components/index.d.ts +62 -0
- package/dist/components/index.js +42 -0
- package/dist/components/index10.js +84 -0
- package/dist/components/index11.js +383 -0
- package/dist/components/index12.js +125 -0
- package/dist/components/index13.js +602 -0
- package/dist/components/index2.js +100 -0
- package/dist/components/index3.js +90 -0
- package/dist/components/index4.js +62 -0
- package/dist/components/index5.js +146 -0
- package/dist/components/index6.js +145 -0
- package/dist/components/index7.js +2960 -0
- package/dist/components/index8.js +3356 -0
- package/dist/components/index9.js +101 -0
- package/dist/components/installCanvasRenderer.js +38282 -0
- package/dist/components/q2-avatar.d.ts +11 -0
- package/dist/components/q2-avatar.js +6 -0
- package/dist/components/q2-badge.d.ts +11 -0
- package/dist/components/q2-badge.js +6 -0
- package/dist/components/q2-btn.d.ts +11 -0
- package/dist/components/q2-btn.js +6 -0
- package/dist/components/q2-calendar.d.ts +11 -0
- package/dist/components/q2-calendar.js +3755 -0
- package/dist/components/q2-card.d.ts +11 -0
- package/dist/components/q2-card.js +187 -0
- package/dist/components/q2-carousel-pane.d.ts +11 -0
- package/dist/components/q2-carousel-pane.js +97 -0
- package/dist/components/q2-carousel.d.ts +11 -0
- package/dist/components/q2-carousel.js +5379 -0
- package/dist/components/q2-chart-bar.d.ts +11 -0
- package/dist/components/q2-chart-bar.js +4710 -0
- package/dist/components/q2-chart-donut.d.ts +11 -0
- package/dist/components/q2-chart-donut.js +4887 -0
- package/dist/components/q2-checkbox-group.d.ts +11 -0
- package/dist/components/q2-checkbox-group.js +114 -0
- package/dist/components/q2-checkbox.d.ts +11 -0
- package/dist/components/q2-checkbox.js +138 -0
- package/dist/components/q2-dropdown-item.d.ts +11 -0
- package/dist/components/q2-dropdown-item.js +6 -0
- package/dist/components/q2-dropdown.d.ts +11 -0
- package/dist/components/q2-dropdown.js +345 -0
- package/dist/components/q2-editable-field.d.ts +11 -0
- package/dist/components/q2-editable-field.js +220 -0
- package/dist/components/q2-icon.d.ts +11 -0
- package/dist/components/q2-icon.js +6 -0
- package/dist/components/q2-input.d.ts +11 -0
- package/dist/components/q2-input.js +6 -0
- package/dist/components/q2-loading-element.d.ts +11 -0
- package/dist/components/q2-loading-element.js +52 -0
- package/dist/components/q2-loading.d.ts +11 -0
- package/dist/components/q2-loading.js +6 -0
- package/dist/components/q2-loc.d.ts +11 -0
- package/dist/components/q2-loc.js +40 -0
- package/dist/components/q2-message.d.ts +11 -0
- package/dist/components/q2-message.js +6 -0
- package/dist/components/q2-month-picker.d.ts +11 -0
- package/dist/components/q2-month-picker.js +189 -0
- package/dist/components/q2-optgroup.d.ts +11 -0
- package/dist/components/q2-optgroup.js +75 -0
- package/dist/components/q2-option-list.d.ts +11 -0
- package/dist/components/q2-option-list.js +6 -0
- package/dist/components/q2-option.d.ts +11 -0
- package/dist/components/q2-option.js +81 -0
- package/dist/components/q2-pagination.d.ts +11 -0
- package/dist/components/q2-pagination.js +184 -0
- package/dist/components/q2-pill.d.ts +11 -0
- package/dist/components/q2-pill.js +216 -0
- package/dist/components/q2-popover.d.ts +11 -0
- package/dist/components/q2-popover.js +6 -0
- package/dist/components/q2-radio-group.d.ts +11 -0
- package/dist/components/q2-radio-group.js +191 -0
- package/dist/components/q2-radio.d.ts +11 -0
- package/dist/components/q2-radio.js +105 -0
- package/dist/components/q2-section.d.ts +11 -0
- package/dist/components/q2-section.js +218 -0
- package/dist/components/q2-select.d.ts +11 -0
- package/dist/components/q2-select.js +817 -0
- package/dist/components/q2-stepper-pane.d.ts +11 -0
- package/dist/components/q2-stepper-pane.js +92 -0
- package/dist/components/q2-stepper-vertical.d.ts +11 -0
- package/dist/components/q2-stepper-vertical.js +311 -0
- package/dist/components/q2-stepper.d.ts +11 -0
- package/dist/components/q2-stepper.js +252 -0
- package/dist/components/q2-tab-container.d.ts +11 -0
- package/dist/components/q2-tab-container.js +288 -0
- package/dist/components/q2-tab-pane.d.ts +11 -0
- package/dist/components/q2-tab-pane.js +58 -0
- package/dist/components/q2-tag.d.ts +11 -0
- package/dist/components/q2-tag.js +156 -0
- package/dist/components/q2-textarea.d.ts +11 -0
- package/dist/components/q2-textarea.js +265 -0
- package/dist/components/q2-tooltip.d.ts +11 -0
- package/dist/components/q2-tooltip.js +112 -0
- package/dist/components/shapes.js +91 -0
- package/dist/components/tecton-tab-pane.d.ts +11 -0
- package/dist/components/tecton-tab-pane.js +111 -0
- package/dist/esm/installCanvasRenderer-0143b52d.js +38282 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/q2-badge_2.entry.js +5 -3
- package/dist/esm/q2-calendar.entry.js +75 -55
- package/dist/esm/q2-carousel.entry.js +3 -3
- package/dist/esm/q2-chart-bar.entry.js +4675 -0
- package/dist/esm/q2-chart-donut.entry.js +171 -35406
- package/dist/esm/q2-checkbox.entry.js +1 -1
- package/dist/esm/q2-editable-field.entry.js +1 -1
- package/dist/esm/q2-radio.entry.js +1 -1
- package/dist/esm/q2-tecton-elements.js +1 -1
- package/dist/q2-tecton-elements/p-1f85cced.js +39 -0
- package/dist/q2-tecton-elements/{p-89608314.entry.js → p-4625184b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-9772b15f.entry.js → p-520c40f6.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-6b52a262.entry.js +1 -0
- package/dist/q2-tecton-elements/p-c4640b55.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-7e8f43d1.entry.js → p-cf41970f.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-e4dc9ac0.entry.js +1 -0
- package/dist/q2-tecton-elements/p-f35bf6a3.entry.js +1 -0
- package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
- package/dist/types/components/q2-calendar/index.d.ts +3 -0
- package/dist/types/components/q2-chart-bar/index.d.ts +40 -0
- package/dist/types/components/q2-chart-donut/index.d.ts +7 -10
- package/dist/types/components/q2-input/index.d.ts +1 -0
- package/dist/types/components.d.ts +50 -3
- package/dist/types/utils/charting.d.ts +14 -0
- package/package.json +5 -2
- package/dist/q2-tecton-elements/p-0766a694.entry.js +0 -1
- package/dist/q2-tecton-elements/p-5f064e1e.entry.js +0 -39
- package/dist/q2-tecton-elements/p-8d25ec52.entry.js +0 -1
- /package/dist/types/workspace/workspace/{tecton-production_release_1.21.x → Tecton_tecton-production_master}/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +0 -0
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
|
|
2
|
+
import { c as createGuid, s as setPopProperties, h as handleAriaLabel, o as overrideFocus, l as loc, b as isRelatedTargetWithinHost, i as isEventFromElement, r as resizeIframe } from './index13.js';
|
|
3
|
+
import { d as defineCustomElement$7 } from './index2.js';
|
|
4
|
+
import { d as defineCustomElement$6 } from './index4.js';
|
|
5
|
+
import { d as defineCustomElement$5 } from './index5.js';
|
|
6
|
+
import { d as defineCustomElement$4 } from './index7.js';
|
|
7
|
+
import { d as defineCustomElement$3 } from './index8.js';
|
|
8
|
+
import { d as defineCustomElement$2 } from './index9.js';
|
|
9
|
+
|
|
10
|
+
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}.q2-element-dropdown{display:none;position:absolute;background-color:var(--app-white, #ffffff);color:var(--t-text, #4d4d4d);left:0;width:100%;z-index:100;margin-top:1px;box-shadow:var(--app-shadow-1, 0 2px 4px rgba(0, 0, 0, 0.3));height:0;overflow:hidden;opacity:0;visibility:hidden;transition:opacity var(--app-tween-1, 0.2s ease);border-radius:var(--tct-dropdown-border-radius, --t-dropdown-border-radius, 0);--comp-scrollbar-size:var(--tct-scrollbar-size, var(--t-scrollbar-size, var(--app-scale-1x, 5px)));--comp-scrollbar-border-radius:var(--tct-scrollbar-border-radius, var(--t-scrollbar-border-radius, var(--app-border-radius-1, 3px)));--comp-scrollbar-color:var(--tct-scrollbar-color, var(--t-scrollbar-color, var(--t-a11y-gray-color, #747474)));scrollbar-width:thin;scrollbar-color:var(--comp-scrollbar-color) transparent}.q2-element-dropdown::-webkit-scrollbar{width:var(--comp-scrollbar-size);height:var(--comp-scrollbar-size);margin:5px}.q2-element-dropdown::-webkit-scrollbar-thumb{background:var(--comp-scrollbar-color);border-radius:var(--comp-scrollbar-border-radius)}.q2-element-dropdown::-webkit-scrollbar-track{background:transparent;border-radius:var(--comp-scrollbar-border-radius)}.q2-element-dropdown.sizable{display:block;height:auto}.dropdown-open .q2-element-dropdown{display:block;height:auto;overflow:auto;opacity:1;visibility:visible}:host([alignment=right]) .q2-element-dropdown{left:auto;right:0}:host([block]) q2-btn,:host([block]){display:block}:host{display:block;margin-top:var(--tct-select-margin-top, var(--app-scale-4, 30px));margin-bottom:var(--tct-select-margin-bottom, var(--app-scale-4, 30px))}.q2-select-container{position:relative;display:block}.q2-select-input{margin:0;--tct-input-min-height:var(--tct-select-input-min-height, var(--t-select-input-min-height));--tct-input-max-height:var(--tct-select-input-max-height, var(--t-select-input-max-height, 100px))}::slotted([slot=_selected-display]){width:100%;min-height:var(--comp-selected-display-height, 44px)}.custom-display-content{position:absolute;bottom:0;left:calc(var(--tct-scale-2, var(--app-scale-2x, 10px)) + 1px);height:44px;width:calc(100% - 34px - var(--tct-scale-3, var(--app-scale-3x, 15px)));overflow:hidden;cursor:pointer;transition:left var(--tct-tween-2, var(--app-tween-1, 0.2s ease))}.custom-display-content:not([hidden]){display:flex;align-items:center}.is-searchable.is-focused .custom-display-content,.is-searchable .custom-display-content:active{left:calc(var(--tct-scale-3, var(--app-scale-3x, 15px)) + 1px)}.has-error .custom-display-content{width:calc(100% - 68px - var(--tct-scale-3, var(--app-scale-3x, 15px)))}.dropdown-open .q2-select-dropdown{overflow-y:auto;max-height:300px}.multi-select-header{padding:var(--tct-scale-1, var(--app-scale-1x, 5px)) var(--tct-scale-2, var(--app-scale-2x, 10px));position:sticky;top:0;z-index:5;background:var(--app-white)}.show-all-options{margin-right:var(--tct-scale-1, var(--app-scale-1x, 5px));margin-left:var(--tct-scale-2, var(--app-scale-2x, 10px))}.q2-element-dropdown.dropup{bottom:var(--comp-dropup-offset)}";
|
|
11
|
+
|
|
12
|
+
const Q2Select$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.__registerHost();
|
|
16
|
+
this.__attachShadow();
|
|
17
|
+
this.change = createEvent(this, "change", 7);
|
|
18
|
+
this.input = createEvent(this, "input", 7);
|
|
19
|
+
this.scheduledAfterRender = [];
|
|
20
|
+
this.keyStore = {
|
|
21
|
+
queue: [],
|
|
22
|
+
lastPressedAt: new Date(),
|
|
23
|
+
};
|
|
24
|
+
this.guid = createGuid();
|
|
25
|
+
this.onMutationObserved = () => {
|
|
26
|
+
const slotContainer = this.hostElement.querySelector('.custom-display-content');
|
|
27
|
+
const displaySlot = this.hostElement.shadowRoot.querySelector('slot[name="q2-select-display"]');
|
|
28
|
+
const hasCustomDisplay = !!displaySlot
|
|
29
|
+
? displaySlot.assignedNodes().length > 0
|
|
30
|
+
: slotContainer.children.length > 0;
|
|
31
|
+
if (this.hasCustomDisplay !== hasCustomDisplay) {
|
|
32
|
+
this.hasCustomDisplay = hasCustomDisplay;
|
|
33
|
+
}
|
|
34
|
+
if (this.multiple) {
|
|
35
|
+
this.updateMultipleOptionAttrs();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.updateSingleOptionAttrs();
|
|
39
|
+
const activeOption = this.optionElements[this.activeIndex];
|
|
40
|
+
if (!activeOption || activeOption.id !== this.activeOptionId) {
|
|
41
|
+
this.activeIndex = this.getDefaultActiveIndex();
|
|
42
|
+
this.setActiveOption();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.searchAndFocus = keyValue => {
|
|
46
|
+
// pseudo search in non-searchable select
|
|
47
|
+
const reorder = () => {
|
|
48
|
+
this.pivotIndex = this.pivotIndex === undefined ? 0 : (this.activeIndex || 0) + 1;
|
|
49
|
+
const list = this.optionElements.map((element, index) => ({ element, index }));
|
|
50
|
+
return [...list.slice(this.pivotIndex), ...list.slice(0, this.pivotIndex)];
|
|
51
|
+
};
|
|
52
|
+
const buildQueue = () => {
|
|
53
|
+
const now = new Date();
|
|
54
|
+
if (now.getTime() - this.keyStore.lastPressedAt.getTime() > 1000) {
|
|
55
|
+
// empty stored keys if delay > 1s
|
|
56
|
+
this.keyStore.queue = [];
|
|
57
|
+
}
|
|
58
|
+
if (this.keyStore.queue.length !== 1 || this.keyStore.queue[0] !== keyValue) {
|
|
59
|
+
this.keyStore.queue.push(keyValue);
|
|
60
|
+
}
|
|
61
|
+
this.keyStore.lastPressedAt = now;
|
|
62
|
+
};
|
|
63
|
+
const searchIndex = list => {
|
|
64
|
+
return list.find(v => {
|
|
65
|
+
return (!v.element.disabled &&
|
|
66
|
+
v.element.display &&
|
|
67
|
+
v.element.display.replace(/\s/g, '').match(new RegExp(`^${this.keyStore.queue.join('')}`, 'i')));
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const setFocus = ({ element, index }) => {
|
|
71
|
+
if (this.dropdownOpen || this.multiple) {
|
|
72
|
+
// multiple: should open to make sure that which options are selected
|
|
73
|
+
this.openDropdownWithActiveElement(index);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.activeIndex = index;
|
|
77
|
+
this.change.emit({ value: element.value });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
buildQueue();
|
|
81
|
+
const matched = searchIndex(reorder());
|
|
82
|
+
if (matched) {
|
|
83
|
+
setFocus(matched);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/// Event handlers ///
|
|
87
|
+
this.dropdownFocusoutHandler = (event) => {
|
|
88
|
+
const { relatedTarget } = event;
|
|
89
|
+
const isInDropdown = this.dropdownContainer.contains(relatedTarget);
|
|
90
|
+
const isInLightDom = !isInDropdown && this.hostElement.contains(relatedTarget);
|
|
91
|
+
if (isInDropdown || isInLightDom)
|
|
92
|
+
return;
|
|
93
|
+
if (!this.dropdownOpen)
|
|
94
|
+
return;
|
|
95
|
+
this.closeDropdown();
|
|
96
|
+
};
|
|
97
|
+
/* tslint:disable:cyclomatic-complexity */
|
|
98
|
+
this.dropdownKeydownHandler = (event) => {
|
|
99
|
+
event.stopPropagation();
|
|
100
|
+
const { activeIndex, searchable, optionElements, multiSelectHeader } = this;
|
|
101
|
+
const { key, shiftKey } = event;
|
|
102
|
+
if (this.readonly ||
|
|
103
|
+
(multiSelectHeader && multiSelectHeader.contains(event.target) && [' ', 'Enter'].includes(key)))
|
|
104
|
+
return;
|
|
105
|
+
switch (key) {
|
|
106
|
+
case ' ':
|
|
107
|
+
case 'Enter':
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
const newOption = this.hostElement.querySelector(`[option-id="${this.activeOptionId}"]`);
|
|
110
|
+
if (!newOption || newOption.disabled)
|
|
111
|
+
break;
|
|
112
|
+
this.selectOption(newOption, true);
|
|
113
|
+
break;
|
|
114
|
+
case 'ArrowUp':
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
const isFirstOption = activeIndex === 0;
|
|
117
|
+
if (isFirstOption)
|
|
118
|
+
break;
|
|
119
|
+
if (activeIndex !== undefined) {
|
|
120
|
+
const nextIndex = this.getNextVisibleIndex(-1);
|
|
121
|
+
if (nextIndex === -1)
|
|
122
|
+
break;
|
|
123
|
+
this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.setDefaultActiveElement();
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case 'ArrowDown':
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
const isLastOption = activeIndex === optionElements.length - 1;
|
|
132
|
+
if (isLastOption)
|
|
133
|
+
break;
|
|
134
|
+
if (activeIndex !== undefined) {
|
|
135
|
+
const nextIndex = this.getNextVisibleIndex(1);
|
|
136
|
+
if (nextIndex === -1)
|
|
137
|
+
break;
|
|
138
|
+
this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.setDefaultActiveElement();
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case 'Home':
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
this.openDropdownWithActiveElement(0);
|
|
147
|
+
break;
|
|
148
|
+
case 'End':
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
this.openDropdownWithActiveElement(optionElements.length - 1);
|
|
151
|
+
break;
|
|
152
|
+
case 'PageUp':
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
this.openDropdownWithActiveElement(Math.max(activeIndex - 10, 0));
|
|
155
|
+
break;
|
|
156
|
+
case 'PageDown':
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
this.openDropdownWithActiveElement(Math.min(activeIndex + 10, optionElements.length - 1));
|
|
159
|
+
break;
|
|
160
|
+
case 'Tab':
|
|
161
|
+
if (shiftKey)
|
|
162
|
+
break;
|
|
163
|
+
const myOption = this.hostElement.querySelector(`[option-id="${this.activeOptionId}"]`);
|
|
164
|
+
if (!myOption || myOption.disabled)
|
|
165
|
+
return;
|
|
166
|
+
if (myOption.selected)
|
|
167
|
+
return;
|
|
168
|
+
this.selectOption(myOption);
|
|
169
|
+
break;
|
|
170
|
+
case 'Esc':
|
|
171
|
+
case 'Escape':
|
|
172
|
+
this.closeDropdown();
|
|
173
|
+
this.focusInput();
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
if (searchable)
|
|
177
|
+
break;
|
|
178
|
+
if (!key.match(/^[A-Za-z0-9]$/))
|
|
179
|
+
break;
|
|
180
|
+
// search in non-searchable select: alpha-numeric only
|
|
181
|
+
this.searchAndFocus(key);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/* tslint:enable:cyclomatic-complexity */
|
|
186
|
+
this.inputKeydownHandler = (event) => {
|
|
187
|
+
event.stopPropagation();
|
|
188
|
+
const { key } = event;
|
|
189
|
+
const { optionElements, searchable } = this;
|
|
190
|
+
switch (key) {
|
|
191
|
+
case 'ArrowDown':
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
this.openDropdownWithActiveElement(this.getDefaultActiveIndex());
|
|
194
|
+
break;
|
|
195
|
+
case 'ArrowUp':
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
this.openDropdownWithActiveElement(this.getLastEnabledIndex());
|
|
198
|
+
this.setFocusedOption();
|
|
199
|
+
break;
|
|
200
|
+
case 'Home':
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
this.openDropdownWithActiveElement(0);
|
|
203
|
+
break;
|
|
204
|
+
case 'End':
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
this.openDropdownWithActiveElement(optionElements.length - 1);
|
|
207
|
+
break;
|
|
208
|
+
case 'Escape':
|
|
209
|
+
case 'Esc':
|
|
210
|
+
this.closeDropdown();
|
|
211
|
+
break;
|
|
212
|
+
case 'Tab':
|
|
213
|
+
this.closeDropdown();
|
|
214
|
+
break;
|
|
215
|
+
default:
|
|
216
|
+
if (!key.match(/^[A-Za-z0-9]$/))
|
|
217
|
+
break;
|
|
218
|
+
if (searchable) {
|
|
219
|
+
this.openDropdownWithoutActiveElement();
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
// search in non-searchable select: alpha-numeric only
|
|
223
|
+
this.searchAndFocus(key);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
this.inputClickHandler = (event) => {
|
|
227
|
+
event.stopPropagation();
|
|
228
|
+
setPopProperties(this);
|
|
229
|
+
this.toggleDropdown();
|
|
230
|
+
this.focusInput();
|
|
231
|
+
};
|
|
232
|
+
this.inputInputHandler = (event) => {
|
|
233
|
+
event.stopPropagation();
|
|
234
|
+
const inputValue = this.inputField.value;
|
|
235
|
+
const eventValue = event.detail.value;
|
|
236
|
+
const didChangeText = inputValue !== eventValue;
|
|
237
|
+
const shouldClearValue = !!this.value && didChangeText;
|
|
238
|
+
if (shouldClearValue) {
|
|
239
|
+
this.selectOption(null);
|
|
240
|
+
}
|
|
241
|
+
if (!this.dropdownOpen)
|
|
242
|
+
this.openDropdownWithoutActiveElement();
|
|
243
|
+
this.prioritizeSearch = true;
|
|
244
|
+
this.searchText = eventValue;
|
|
245
|
+
this.input.emit({ query: eventValue });
|
|
246
|
+
};
|
|
247
|
+
this.inputFocusHandler = () => {
|
|
248
|
+
this.inputFocused = true;
|
|
249
|
+
};
|
|
250
|
+
this.inputBlurHandler = () => {
|
|
251
|
+
this.inputFocused = false;
|
|
252
|
+
};
|
|
253
|
+
this.inputChangeHandler = (event) => {
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
};
|
|
256
|
+
this.clickedElsewhere = (event) => {
|
|
257
|
+
const target = event.target;
|
|
258
|
+
if (target.localName === 'click-elsewhere') {
|
|
259
|
+
event.stopPropagation();
|
|
260
|
+
if (this.dropdownOpen) {
|
|
261
|
+
this.closeDropdown();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
this.onCustomDisplayClick = (event) => {
|
|
266
|
+
event.stopPropagation();
|
|
267
|
+
this.focusInput();
|
|
268
|
+
this.toggleDropdown();
|
|
269
|
+
};
|
|
270
|
+
this.showSelectedOptions = (event) => {
|
|
271
|
+
event.stopImmediatePropagation();
|
|
272
|
+
this.onlyShowingSelected = true;
|
|
273
|
+
this.optionElements.forEach(optionElement => {
|
|
274
|
+
optionElement._multiSelectHidden = !optionElement.selected;
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
this.showAllOptions = (event) => {
|
|
278
|
+
event.stopPropagation();
|
|
279
|
+
this.onlyShowingSelected = false;
|
|
280
|
+
this.optionElements.forEach(optionElement => {
|
|
281
|
+
optionElement._multiSelectHidden = false;
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
this.label = undefined;
|
|
285
|
+
this.hideLabel = undefined;
|
|
286
|
+
this.value = undefined;
|
|
287
|
+
this.ariaLabel = undefined;
|
|
288
|
+
this.selectedOptions = [];
|
|
289
|
+
this.disabled = false;
|
|
290
|
+
this.readonly = false;
|
|
291
|
+
this.invalid = undefined;
|
|
292
|
+
this.errors = undefined;
|
|
293
|
+
this.multiple = false;
|
|
294
|
+
this.minRows = 3;
|
|
295
|
+
this.popDirection = undefined;
|
|
296
|
+
this.searchable = false;
|
|
297
|
+
this.multilineOptions = false;
|
|
298
|
+
this.optional = false;
|
|
299
|
+
this.dropdownOpen = false;
|
|
300
|
+
this.onlyShowingSelected = false;
|
|
301
|
+
this.activeOptionId = undefined;
|
|
302
|
+
this.searchText = '';
|
|
303
|
+
this.hasCustomDisplay = false;
|
|
304
|
+
this.inputFocused = false;
|
|
305
|
+
this.statusMessage = undefined;
|
|
306
|
+
this.prioritizeSearch = false;
|
|
307
|
+
}
|
|
308
|
+
/// Lifecycle Hooks ///
|
|
309
|
+
componentWillLoad() {
|
|
310
|
+
handleAriaLabel(this);
|
|
311
|
+
}
|
|
312
|
+
componentDidLoad() {
|
|
313
|
+
const observer = new MutationObserver(this.onMutationObserved);
|
|
314
|
+
observer.observe(this.hostElement, { childList: true, subtree: true });
|
|
315
|
+
this.mutationObserver = observer;
|
|
316
|
+
this.onMutationObserved();
|
|
317
|
+
overrideFocus(this.hostElement);
|
|
318
|
+
setTimeout(() => this.checkSelectedDisplay(), 0);
|
|
319
|
+
}
|
|
320
|
+
componentDidRender() {
|
|
321
|
+
setTimeout(() => {
|
|
322
|
+
this.scheduledAfterRender.forEach(fn => fn());
|
|
323
|
+
this.scheduledAfterRender = [];
|
|
324
|
+
}, 25);
|
|
325
|
+
}
|
|
326
|
+
disconnectedCallback() {
|
|
327
|
+
var _a;
|
|
328
|
+
(_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
329
|
+
this.mutationObserver = null;
|
|
330
|
+
}
|
|
331
|
+
/// Getters ///
|
|
332
|
+
get isComponentFocused() {
|
|
333
|
+
return document.activeElement === this.hostElement || !!this.hostElement.querySelector(':focus');
|
|
334
|
+
}
|
|
335
|
+
get isSearchMode() {
|
|
336
|
+
return (this.searchable && this.inputFocused) || this.searchText;
|
|
337
|
+
}
|
|
338
|
+
get badgeValue() {
|
|
339
|
+
if (!this.multiple)
|
|
340
|
+
return;
|
|
341
|
+
const optionsLength = this.selectedOptions.length;
|
|
342
|
+
if (this.dropdownOpen && this.searchable)
|
|
343
|
+
return optionsLength || null;
|
|
344
|
+
else
|
|
345
|
+
return optionsLength > 1 ? `+${optionsLength - 1}` : null;
|
|
346
|
+
}
|
|
347
|
+
get minPopHeight() {
|
|
348
|
+
const { minRows } = this;
|
|
349
|
+
const firstOption = this.hostElement.querySelector('q2-option:not([hidden])');
|
|
350
|
+
const minHeight = firstOption ? window.getComputedStyle(firstOption).minHeight : '44px';
|
|
351
|
+
return minRows * parseInt(minHeight);
|
|
352
|
+
}
|
|
353
|
+
get selectedDisplay() {
|
|
354
|
+
if (this.prioritizeSearch || this.searchText)
|
|
355
|
+
return this.searchText;
|
|
356
|
+
if (this.hasCustomDisplay)
|
|
357
|
+
return '';
|
|
358
|
+
return this.multiple ? this.calculateMultiSelectSelectedDisplay() : this.calculateSingleSelectSelectedDisplay();
|
|
359
|
+
}
|
|
360
|
+
get selectedDisplaySlot() {
|
|
361
|
+
return this.hostElement.querySelector('[slot="_selected-display"]');
|
|
362
|
+
}
|
|
363
|
+
get firstSelectedValue() {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
if (this.multiple)
|
|
366
|
+
return (_b = (_a = this.selectedOptions) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null;
|
|
367
|
+
return this.value;
|
|
368
|
+
}
|
|
369
|
+
get firstSelectedOptionElement() {
|
|
370
|
+
const { firstSelectedValue } = this;
|
|
371
|
+
return firstSelectedValue ? this.optionElements.find(({ value }) => value === firstSelectedValue) : null;
|
|
372
|
+
}
|
|
373
|
+
get optionElements() {
|
|
374
|
+
return Array.from(this.hostElement.querySelectorAll('q2-option'));
|
|
375
|
+
}
|
|
376
|
+
get visibleOptionElements() {
|
|
377
|
+
return Array.from(this.hostElement.querySelectorAll('q2-option:not([_multiselecthidden])'));
|
|
378
|
+
}
|
|
379
|
+
get wrapperClasses() {
|
|
380
|
+
const { errors } = this;
|
|
381
|
+
const classes = ['q2-select-container'];
|
|
382
|
+
if (this.dropdownOpen)
|
|
383
|
+
classes.push('dropdown-open');
|
|
384
|
+
if (Array.isArray(errors) && errors.length > 0)
|
|
385
|
+
classes.push('has-error');
|
|
386
|
+
if (this.inputFocused)
|
|
387
|
+
classes.push('is-focused');
|
|
388
|
+
if (this.searchable)
|
|
389
|
+
classes.push('is-searchable');
|
|
390
|
+
return classes.join(' ');
|
|
391
|
+
}
|
|
392
|
+
/// Watchers ///
|
|
393
|
+
ariaLabelObserver() {
|
|
394
|
+
handleAriaLabel(this);
|
|
395
|
+
}
|
|
396
|
+
valueUpdated() {
|
|
397
|
+
if (this.multiple)
|
|
398
|
+
return;
|
|
399
|
+
this.updateSingleOptionAttrs();
|
|
400
|
+
}
|
|
401
|
+
selectedOptionsUpdated() {
|
|
402
|
+
if (!this.multiple)
|
|
403
|
+
return;
|
|
404
|
+
this.updateMultipleOptionAttrs();
|
|
405
|
+
}
|
|
406
|
+
multilineOptionsChanged(newValue, oldValue) {
|
|
407
|
+
if (newValue === oldValue)
|
|
408
|
+
return;
|
|
409
|
+
this.optionElements.forEach(element => (element.multiline = newValue));
|
|
410
|
+
}
|
|
411
|
+
dropdownOpenChanged(isOpen) {
|
|
412
|
+
this.scheduledAfterRender.push(() => {
|
|
413
|
+
const { multiple, multiSelectHeader, dropdownContainer } = this;
|
|
414
|
+
const height = (isOpen && multiple && (multiSelectHeader === null || multiSelectHeader === void 0 ? void 0 : multiSelectHeader.offsetHeight)) || 0;
|
|
415
|
+
if (height) {
|
|
416
|
+
dropdownContainer.style.setProperty('--comp-multi-select-header-height', `${height}px`);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
dropdownContainer.style.removeProperty('--comp-multi-select-header-height');
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/// Listeners ///
|
|
424
|
+
keydownHandler(event) {
|
|
425
|
+
this.inputKeydownHandler(event);
|
|
426
|
+
}
|
|
427
|
+
onHostElementChange(event) {
|
|
428
|
+
if (this.readonly)
|
|
429
|
+
return;
|
|
430
|
+
if (event.target !== this.hostElement || this.hostElement.onchange)
|
|
431
|
+
return;
|
|
432
|
+
if (this.multiple) {
|
|
433
|
+
this.selectedOptions = event.detail.selectedOptions;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
this.value = event.detail.value;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
onHostElementInput(event) {
|
|
440
|
+
if (!this.searchable || event.target !== this.hostElement || this.hostElement.oninput)
|
|
441
|
+
return;
|
|
442
|
+
const options = this.optionElements;
|
|
443
|
+
const query = this.searchText.trim().toLocaleLowerCase();
|
|
444
|
+
let matchedCount = 0;
|
|
445
|
+
options.forEach(option => {
|
|
446
|
+
var _a;
|
|
447
|
+
if (query === '') {
|
|
448
|
+
option.hidden = false;
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const title = ((_a = option.firstElementChild) === null || _a === void 0 ? void 0 : _a.tagName) === 'Q2-CARD'
|
|
452
|
+
? option.firstElementChild.title
|
|
453
|
+
: null;
|
|
454
|
+
const { display = '', innerText = '' } = option;
|
|
455
|
+
const searchParams = [display, title, innerText];
|
|
456
|
+
const matched = searchParams.some(text => { var _a; return (_a = text === null || text === void 0 ? void 0 : text.toLocaleLowerCase().includes(query)) !== null && _a !== void 0 ? _a : false; });
|
|
457
|
+
option.hidden = !matched;
|
|
458
|
+
if (matched)
|
|
459
|
+
matchedCount++;
|
|
460
|
+
});
|
|
461
|
+
const statusMessageLocString = query
|
|
462
|
+
? 'tecton.element.select.searchable.results'
|
|
463
|
+
: 'tecton.element.select.allOptions';
|
|
464
|
+
const count = query ? matchedCount : options.length;
|
|
465
|
+
this.setStatusMessage(loc(statusMessageLocString, [count]));
|
|
466
|
+
}
|
|
467
|
+
delegateFocus(event) {
|
|
468
|
+
const fromHost = isRelatedTargetWithinHost(event, this.hostElement);
|
|
469
|
+
const prioritizeSearch = (this.prioritizeSearch = fromHost && this.searchable);
|
|
470
|
+
if (prioritizeSearch) {
|
|
471
|
+
this.clearSelectedDisplay();
|
|
472
|
+
}
|
|
473
|
+
else if (isEventFromElement(event, this.hostElement)) {
|
|
474
|
+
this.inputField.shadowRoot.querySelector('.input-field').focus();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
handleFocusout(event) {
|
|
478
|
+
this.prioritizeSearch = !isRelatedTargetWithinHost(event, this.hostElement) && this.searchable;
|
|
479
|
+
}
|
|
480
|
+
clickHandler(event) {
|
|
481
|
+
const selectedOption = event.target.closest('q2-option');
|
|
482
|
+
if (!selectedOption ||
|
|
483
|
+
(selectedOption.hasAttribute('disabled') && selectedOption.getAttribute('disabled') !== 'false'))
|
|
484
|
+
return;
|
|
485
|
+
this.selectOption(selectedOption, true);
|
|
486
|
+
}
|
|
487
|
+
/// Helpers ///
|
|
488
|
+
getDefaultActiveIndex() {
|
|
489
|
+
const firstSelected = this.optionElements.findIndex(element => element.selected && !element.hidden);
|
|
490
|
+
if (firstSelected > -1)
|
|
491
|
+
return firstSelected;
|
|
492
|
+
const firstEnabled = this.optionElements.findIndex(element => !element.hidden);
|
|
493
|
+
if (firstEnabled > -1)
|
|
494
|
+
return firstEnabled;
|
|
495
|
+
else
|
|
496
|
+
return 0;
|
|
497
|
+
}
|
|
498
|
+
getLastEnabledIndex() {
|
|
499
|
+
const enabledIndexes = this.optionElements.reduce((acc, element, index) => {
|
|
500
|
+
if (!element.hidden && !element.disabled)
|
|
501
|
+
acc.push(index);
|
|
502
|
+
return acc;
|
|
503
|
+
}, []);
|
|
504
|
+
return enabledIndexes[enabledIndexes.length - 1];
|
|
505
|
+
}
|
|
506
|
+
setActiveOption() {
|
|
507
|
+
if (!this.dropdownOpen)
|
|
508
|
+
return;
|
|
509
|
+
const activeIndex = this.activeIndex;
|
|
510
|
+
this.optionElements.forEach((element, elementIndex) => {
|
|
511
|
+
if (activeIndex === elementIndex) {
|
|
512
|
+
element.active = true;
|
|
513
|
+
this.activeOptionId = element.optionId;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
element.active = false;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
setFocusedOption() {
|
|
521
|
+
const option = this.optionElements[this.activeIndex];
|
|
522
|
+
if (!option)
|
|
523
|
+
return;
|
|
524
|
+
option.dispatchEvent(new FocusEvent('focus'));
|
|
525
|
+
option.focus();
|
|
526
|
+
}
|
|
527
|
+
calculateMultiSelectSelectedDisplay() {
|
|
528
|
+
var _a;
|
|
529
|
+
const { firstSelectedOptionElement, firstSelectedValue, multilineOptions } = this;
|
|
530
|
+
if (!firstSelectedValue)
|
|
531
|
+
return '';
|
|
532
|
+
if (firstSelectedOptionElement === null || firstSelectedOptionElement === void 0 ? void 0 : firstSelectedOptionElement.display)
|
|
533
|
+
return loc(firstSelectedOptionElement.display);
|
|
534
|
+
if (multilineOptions && this.searchable)
|
|
535
|
+
return this.searchText;
|
|
536
|
+
if (multilineOptions)
|
|
537
|
+
return '';
|
|
538
|
+
return (_a = firstSelectedOptionElement === null || firstSelectedOptionElement === void 0 ? void 0 : firstSelectedOptionElement.value) !== null && _a !== void 0 ? _a : firstSelectedValue;
|
|
539
|
+
}
|
|
540
|
+
calculateSingleSelectSelectedDisplay() {
|
|
541
|
+
const { firstSelectedOptionElement } = this;
|
|
542
|
+
return ((firstSelectedOptionElement === null || firstSelectedOptionElement === void 0 ? void 0 : firstSelectedOptionElement.display) && loc(firstSelectedOptionElement.display)) || this.value || '';
|
|
543
|
+
}
|
|
544
|
+
updateSingleOptionAttrs() {
|
|
545
|
+
const { value, guid, multilineOptions } = this;
|
|
546
|
+
this.optionElements.forEach((element, index) => {
|
|
547
|
+
element.selected = element.value === value;
|
|
548
|
+
element.optionId = `q2-select-${guid}-option-${index}`;
|
|
549
|
+
element.multiline = multilineOptions;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
updateMultipleOptionAttrs() {
|
|
553
|
+
if (this.selectedOptions.length === 0) {
|
|
554
|
+
this.onlyShowingSelected = false;
|
|
555
|
+
}
|
|
556
|
+
const { selectedOptions, onlyShowingSelected, guid, multilineOptions } = this;
|
|
557
|
+
this.optionElements.forEach((element, index) => {
|
|
558
|
+
element.selected = selectedOptions.includes(element.value);
|
|
559
|
+
element._multiSelectHidden = onlyShowingSelected ? !element.selected : false;
|
|
560
|
+
element.optionId = `q2-select-${guid}-option-${index}`;
|
|
561
|
+
element.multiline = multilineOptions;
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
focusSelectedSibling(option) {
|
|
565
|
+
if (!this.onlyShowingSelected)
|
|
566
|
+
return;
|
|
567
|
+
const { visibleOptionElements } = this;
|
|
568
|
+
if (visibleOptionElements.length < 2)
|
|
569
|
+
return;
|
|
570
|
+
const optionIndex = visibleOptionElements.indexOf(option);
|
|
571
|
+
const visibleFocusIndex = optionIndex ? optionIndex - 1 : optionIndex + 1;
|
|
572
|
+
const optionToFocus = visibleOptionElements[visibleFocusIndex];
|
|
573
|
+
const focusIndex = this.optionElements.indexOf(optionToFocus);
|
|
574
|
+
this.activeIndex = focusIndex;
|
|
575
|
+
this.setFocusedOption();
|
|
576
|
+
}
|
|
577
|
+
selectOption(option, focusInputOnClose = false) {
|
|
578
|
+
var _a;
|
|
579
|
+
const value = (_a = option === null || option === void 0 ? void 0 : option.value) !== null && _a !== void 0 ? _a : '';
|
|
580
|
+
if (this.multiple) {
|
|
581
|
+
const isSelected = this.selectedOptions.includes(value);
|
|
582
|
+
if (isSelected) {
|
|
583
|
+
this.focusSelectedSibling(option);
|
|
584
|
+
this.change.emit({
|
|
585
|
+
selectedOptions: this.selectedOptions.filter(selectedValue => selectedValue !== value),
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
else if (value) {
|
|
589
|
+
this.change.emit({ selectedOptions: [...this.selectedOptions, value] });
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
this.change.emit({ value });
|
|
594
|
+
this.closeDropdown();
|
|
595
|
+
if (focusInputOnClose)
|
|
596
|
+
this.focusInput();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
scrollToActiveOption() {
|
|
600
|
+
const activeOption = this.optionElements[this.activeIndex];
|
|
601
|
+
activeOption === null || activeOption === void 0 ? void 0 : activeOption.scrollIntoView({ block: 'nearest' });
|
|
602
|
+
}
|
|
603
|
+
openDropdownWithoutActiveElement() {
|
|
604
|
+
if (this.readonly)
|
|
605
|
+
return;
|
|
606
|
+
this.activeIndex = undefined;
|
|
607
|
+
this.setActiveOption();
|
|
608
|
+
this.dropdownOpen = true;
|
|
609
|
+
this.scheduledAfterRender.push(resizeIframe);
|
|
610
|
+
}
|
|
611
|
+
openDropdownWithActiveElement(activeIndex) {
|
|
612
|
+
if (this.readonly)
|
|
613
|
+
return;
|
|
614
|
+
this.activeIndex = activeIndex;
|
|
615
|
+
this.dropdownOpen = true;
|
|
616
|
+
this.setActiveOption();
|
|
617
|
+
this.scheduledAfterRender.push(() => {
|
|
618
|
+
this.setFocusedOption();
|
|
619
|
+
this.scrollToActiveOption();
|
|
620
|
+
resizeIframe();
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
closeDropdown() {
|
|
624
|
+
this.dropdownOpen = false;
|
|
625
|
+
if (this.searchText) {
|
|
626
|
+
this.searchText = '';
|
|
627
|
+
this.input.emit({ query: '' });
|
|
628
|
+
}
|
|
629
|
+
this.scheduledAfterRender.push(resizeIframe);
|
|
630
|
+
}
|
|
631
|
+
toggleDropdown() {
|
|
632
|
+
if (this.disabled)
|
|
633
|
+
return;
|
|
634
|
+
if (this.dropdownOpen && !this.searchText) {
|
|
635
|
+
this.closeDropdown();
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
this.openDropdownWithoutActiveElement();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
adjustActiveOptionAndScroll(numToAdd) {
|
|
642
|
+
this.activeIndex += numToAdd;
|
|
643
|
+
this.setActiveOption();
|
|
644
|
+
this.setFocusedOption();
|
|
645
|
+
this.scrollToActiveOption();
|
|
646
|
+
}
|
|
647
|
+
setDefaultActiveElement() {
|
|
648
|
+
this.activeIndex = this.getDefaultActiveIndex();
|
|
649
|
+
this.setActiveOption();
|
|
650
|
+
this.setFocusedOption();
|
|
651
|
+
}
|
|
652
|
+
focusInput() {
|
|
653
|
+
var _a;
|
|
654
|
+
(_a = this.inputField) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new FocusEvent('focus'));
|
|
655
|
+
}
|
|
656
|
+
getNextVisibleIndex(direction) {
|
|
657
|
+
let index = this.activeIndex + direction;
|
|
658
|
+
const { optionElements } = this;
|
|
659
|
+
while (index >= 0 && index <= optionElements.length - 1) {
|
|
660
|
+
const { display, visibility } = window.getComputedStyle(optionElements[index]);
|
|
661
|
+
if (display !== 'none' && visibility !== 'hidden') {
|
|
662
|
+
return index;
|
|
663
|
+
}
|
|
664
|
+
index = index + direction;
|
|
665
|
+
}
|
|
666
|
+
return -1;
|
|
667
|
+
}
|
|
668
|
+
setStatusMessage(message) {
|
|
669
|
+
clearTimeout(this.statusMessageTimer);
|
|
670
|
+
this.statusMessage = '';
|
|
671
|
+
this.statusMessageTimer = setTimeout(() => {
|
|
672
|
+
this.statusMessage = message;
|
|
673
|
+
}, 1000);
|
|
674
|
+
}
|
|
675
|
+
clearSelectedDisplay() {
|
|
676
|
+
var _a;
|
|
677
|
+
(_a = this.selectedDisplaySlot) === null || _a === void 0 ? void 0 : _a.remove();
|
|
678
|
+
}
|
|
679
|
+
checkSelectedDisplay() {
|
|
680
|
+
let namedSlot = this.selectedDisplaySlot;
|
|
681
|
+
const { value, multiple, selectedOptions, multilineOptions, firstSelectedOptionElement, prioritizeSearch } = this;
|
|
682
|
+
const hasNoValue = !value && multiple && !selectedOptions.length;
|
|
683
|
+
if (prioritizeSearch || !multilineOptions || hasNoValue)
|
|
684
|
+
return this.clearSelectedDisplay();
|
|
685
|
+
if (!firstSelectedOptionElement || firstSelectedOptionElement.display)
|
|
686
|
+
return this.clearSelectedDisplay();
|
|
687
|
+
// Clone selected option and remove elements with hide-on-select attribute
|
|
688
|
+
const selectionClone = firstSelectedOptionElement.firstElementChild.cloneNode(true);
|
|
689
|
+
selectionClone.querySelectorAll('[hide-on-select]').forEach(element => element.remove());
|
|
690
|
+
if (namedSlot) {
|
|
691
|
+
const height = namedSlot.clientHeight === 0 ? 'auto' : `${namedSlot.clientHeight}px`;
|
|
692
|
+
namedSlot.style.setProperty('--comp-selected-display-height', height);
|
|
693
|
+
if (namedSlot.firstElementChild.outerHTML !== selectionClone.outerHTML) {
|
|
694
|
+
namedSlot.replaceChild(selectionClone, namedSlot.firstElementChild);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
namedSlot = document.createElement('div');
|
|
699
|
+
namedSlot.slot = '_selected-display';
|
|
700
|
+
namedSlot.appendChild(selectionClone);
|
|
701
|
+
this.hostElement.appendChild(namedSlot);
|
|
702
|
+
}
|
|
703
|
+
return namedSlot;
|
|
704
|
+
}
|
|
705
|
+
checkSelectedDisplayHeight() {
|
|
706
|
+
const { selectedDisplaySlot } = this;
|
|
707
|
+
if (!selectedDisplaySlot)
|
|
708
|
+
return;
|
|
709
|
+
selectedDisplaySlot.style.setProperty('--comp-selected-display-height', '44px');
|
|
710
|
+
}
|
|
711
|
+
/// DOM ///
|
|
712
|
+
renderCustomDisplay() {
|
|
713
|
+
const hasSelectedDisplay = this.checkSelectedDisplay();
|
|
714
|
+
if (!hasSelectedDisplay)
|
|
715
|
+
return;
|
|
716
|
+
this.checkSelectedDisplayHeight();
|
|
717
|
+
return (h("slot", { name: "_selected-display", slot: "custom-display" }));
|
|
718
|
+
}
|
|
719
|
+
render() {
|
|
720
|
+
const showAsPseudo = !this.searchable;
|
|
721
|
+
return (h("click-elsewhere", { class: this.wrapperClasses, onChange: this.clickedElsewhere }, h("div", { "aria-live": "polite", "aria-atomic": "true", role: "status", class: "sr" }, this.statusMessage), h("q2-input", { ref: el => (this.inputField = el), class: "q2-select-input", label: (this.label && loc(this.label)) || '', value: this.selectedDisplay, errors: (Array.isArray(this.errors) &&
|
|
722
|
+
this.errors.length > 0 &&
|
|
723
|
+
this.errors.map(error => loc(error))) ||
|
|
724
|
+
(this.invalid && ['tecton.element.select.invalid']) ||
|
|
725
|
+
[], disabled: this.disabled, optional: this.optional, readonly: this.readonly, hideLabel: this.hideLabel, ariaExpanded: `${!!this.dropdownOpen}`, ariaOwns: "dropdown", ariaHaspopup: "listbox", role: this.searchable ? 'combobox' : null, pseudo: showAsPseudo, "test-id": "toggleDropdown", "hide-messages": true, iconRight: "chevron-down", onClick: this.inputClickHandler, onInput: this.inputInputHandler, onKeyDown: this.inputKeydownHandler, onFocus: this.inputFocusHandler, onBlur: this.inputBlurHandler, onChange: this.inputChangeHandler, badgeValue: this.badgeValue, badgeTheme: this.isComponentFocused ? 'primary' : undefined }, this.renderCustomDisplay()), h("div", { class: "custom-display-content", hidden: !this.hasCustomDisplay || !!this.searchText, onClick: this.onCustomDisplayClick }, h("slot", { name: "q2-select-display" })), this.optionsDropdown()));
|
|
726
|
+
}
|
|
727
|
+
optionsDropdown() {
|
|
728
|
+
const dropDirection = this.privatePopDirection === 'up' ? 'dropup' : '';
|
|
729
|
+
return (h("div", { class: `q2-select-dropdown q2-element-dropdown ${dropDirection}`, ref: el => (this.dropdownContainer = el), onKeyDown: this.dropdownKeydownHandler, onFocusout: this.dropdownFocusoutHandler }, this.multiple ? this.visibilityToggle() : '', h("div", { class: "q2-select-options", id: "dropdown", role: "listbox" }, h("slot", null))));
|
|
730
|
+
}
|
|
731
|
+
visibilityToggle() {
|
|
732
|
+
const selectedOptionsCount = this.selectedOptions.length;
|
|
733
|
+
return (h("div", { class: "multi-select-header", ref: el => (this.multiSelectHeader = el) }, loc('tecton.element.select.multiHeader.showing'), h("q2-btn", { class: `show-all-options${this.onlyShowingSelected ? '' : ' selected'}`, badge: true, "aria-selected": !this.onlyShowingSelected || undefined, "test-id": "allOptionsButton", onClick: this.showAllOptions, label: loc('tecton.element.select.multiHeader.allAriaLabel'), "hide-label": true }, loc('tecton.element.select.multiHeader.all')), h("q2-btn", { class: `show-selected-options${this.onlyShowingSelected ? ' selected' : ''}`, "aria-selected": this.onlyShowingSelected || undefined, disabled: this.selectedOptions.length === 0, badge: true, "test-id": "selectedOptionsButton", onClick: this.showSelectedOptions, label: loc('tecton.element.select.multiHeader.selectedAriaLabel', [selectedOptionsCount]), "hide-label": true }, loc('tecton.element.select.multiHeader.selected', [selectedOptionsCount]))));
|
|
734
|
+
}
|
|
735
|
+
get hostElement() { return this; }
|
|
736
|
+
static get watchers() { return {
|
|
737
|
+
"ariaLabel": ["ariaLabelObserver"],
|
|
738
|
+
"value": ["valueUpdated"],
|
|
739
|
+
"selectedOptions": ["selectedOptionsUpdated"],
|
|
740
|
+
"multilineOptions": ["multilineOptionsChanged"],
|
|
741
|
+
"dropdownOpen": ["dropdownOpenChanged"]
|
|
742
|
+
}; }
|
|
743
|
+
static get style() { return stylesCss; }
|
|
744
|
+
}, [1, "q2-select", {
|
|
745
|
+
"label": [1537],
|
|
746
|
+
"hideLabel": [1540, "hide-label"],
|
|
747
|
+
"value": [1025],
|
|
748
|
+
"ariaLabel": [1537, "aria-label"],
|
|
749
|
+
"selectedOptions": [1032, "selected-options"],
|
|
750
|
+
"disabled": [516],
|
|
751
|
+
"readonly": [516],
|
|
752
|
+
"invalid": [516],
|
|
753
|
+
"errors": [16],
|
|
754
|
+
"multiple": [516],
|
|
755
|
+
"minRows": [2, "min-rows"],
|
|
756
|
+
"popDirection": [513, "pop-direction"],
|
|
757
|
+
"searchable": [516],
|
|
758
|
+
"multilineOptions": [516, "multiline-options"],
|
|
759
|
+
"optional": [516],
|
|
760
|
+
"dropdownOpen": [32],
|
|
761
|
+
"onlyShowingSelected": [32],
|
|
762
|
+
"activeOptionId": [32],
|
|
763
|
+
"searchText": [32],
|
|
764
|
+
"hasCustomDisplay": [32],
|
|
765
|
+
"inputFocused": [32],
|
|
766
|
+
"statusMessage": [32],
|
|
767
|
+
"prioritizeSearch": [32]
|
|
768
|
+
}, [[0, "keydown", "keydownHandler"], [0, "change", "onHostElementChange"], [0, "input", "onHostElementInput"], [0, "focus", "delegateFocus"], [0, "focusout", "handleFocusout"], [0, "click", "clickHandler"]]]);
|
|
769
|
+
function defineCustomElement$1() {
|
|
770
|
+
if (typeof customElements === "undefined") {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
const components = ["q2-select", "click-elsewhere", "q2-badge", "q2-btn", "q2-icon", "q2-input", "q2-loading"];
|
|
774
|
+
components.forEach(tagName => { switch (tagName) {
|
|
775
|
+
case "q2-select":
|
|
776
|
+
if (!customElements.get(tagName)) {
|
|
777
|
+
customElements.define(tagName, Q2Select$1);
|
|
778
|
+
}
|
|
779
|
+
break;
|
|
780
|
+
case "click-elsewhere":
|
|
781
|
+
if (!customElements.get(tagName)) {
|
|
782
|
+
defineCustomElement$7();
|
|
783
|
+
}
|
|
784
|
+
break;
|
|
785
|
+
case "q2-badge":
|
|
786
|
+
if (!customElements.get(tagName)) {
|
|
787
|
+
defineCustomElement$6();
|
|
788
|
+
}
|
|
789
|
+
break;
|
|
790
|
+
case "q2-btn":
|
|
791
|
+
if (!customElements.get(tagName)) {
|
|
792
|
+
defineCustomElement$5();
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
case "q2-icon":
|
|
796
|
+
if (!customElements.get(tagName)) {
|
|
797
|
+
defineCustomElement$4();
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
800
|
+
case "q2-input":
|
|
801
|
+
if (!customElements.get(tagName)) {
|
|
802
|
+
defineCustomElement$3();
|
|
803
|
+
}
|
|
804
|
+
break;
|
|
805
|
+
case "q2-loading":
|
|
806
|
+
if (!customElements.get(tagName)) {
|
|
807
|
+
defineCustomElement$2();
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
} });
|
|
811
|
+
}
|
|
812
|
+
defineCustomElement$1();
|
|
813
|
+
|
|
814
|
+
const Q2Select = Q2Select$1;
|
|
815
|
+
const defineCustomElement = defineCustomElement$1;
|
|
816
|
+
|
|
817
|
+
export { Q2Select, defineCustomElement };
|