tyrell-components 1.0.0-RC13 → 1.0.0-RC15
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/README.md +10 -2
- package/css/tyrell-theme.css +192 -180
- package/css/tyrell.css +23 -0
- package/dist/tyrell-colors-static.css +1 -316
- package/dist/tyrell-theme.css +1 -1454
- package/dist/tyrell.css +1 -1371
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +20 -10
- package/lib/base/ty-component.js +196 -319
- package/lib/components/button.d.ts +3 -17
- package/lib/components/button.js +261 -295
- package/lib/components/calendar-month.d.ts +4 -50
- package/lib/components/calendar-month.js +443 -582
- package/lib/components/calendar-navigation.d.ts +3 -48
- package/lib/components/calendar-navigation.js +239 -362
- package/lib/components/calendar.d.ts +8 -83
- package/lib/components/calendar.js +616 -829
- package/lib/components/checkbox.d.ts +5 -72
- package/lib/components/checkbox.js +273 -416
- package/lib/components/copy.d.ts +4 -57
- package/lib/components/copy.js +280 -397
- package/lib/components/date-picker.d.ts +21 -163
- package/lib/components/date-picker.js +1143 -1674
- package/lib/components/file-upload.d.ts +9 -15
- package/lib/components/file-upload.js +404 -426
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +8 -108
- package/lib/components/input.js +593 -784
- package/lib/components/modal.d.ts +17 -26
- package/lib/components/modal.js +340 -484
- package/lib/components/option.d.ts +2 -9
- package/lib/components/option.js +168 -216
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +249 -380
- package/lib/components/radio.d.ts +5 -25
- package/lib/components/radio.js +407 -461
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +69 -103
- package/lib/components/scroll-container.d.ts +2 -12
- package/lib/components/scroll-container.js +293 -338
- package/lib/components/select.d.ts +87 -159
- package/lib/components/select.js +1609 -2090
- package/lib/components/selected-tags.d.ts +5 -48
- package/lib/components/selected-tags.js +188 -276
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +1 -12
- package/lib/components/switch.js +214 -247
- package/lib/components/tab.d.ts +1 -6
- package/lib/components/tab.js +62 -69
- package/lib/components/tabs.d.ts +6 -63
- package/lib/components/tabs.js +545 -777
- package/lib/components/tag.d.ts +3 -37
- package/lib/components/tag.js +236 -335
- package/lib/components/textarea.d.ts +7 -87
- package/lib/components/textarea.js +457 -627
- package/lib/components/tooltip.d.ts +3 -11
- package/lib/components/tooltip.js +307 -443
- package/lib/components/wizard.d.ts +6 -54
- package/lib/components/wizard.js +405 -618
- package/lib/icons/fontawesome/brands.d.ts +0 -1
- package/lib/icons/fontawesome/brands.js +0 -8
- package/lib/icons/fontawesome/regular.d.ts +0 -1
- package/lib/icons/fontawesome/regular.js +0 -8
- package/lib/icons/fontawesome/solid.d.ts +0 -1
- package/lib/icons/fontawesome/solid.js +0 -8
- package/lib/icons/heroicons/micro.d.ts +0 -1
- package/lib/icons/heroicons/micro.js +392 -400
- package/lib/icons/heroicons/mini.d.ts +0 -1
- package/lib/icons/heroicons/mini.js +382 -390
- package/lib/icons/heroicons/outline.d.ts +0 -1
- package/lib/icons/heroicons/outline.js +337 -345
- package/lib/icons/heroicons/solid.d.ts +0 -1
- package/lib/icons/heroicons/solid.js +407 -415
- package/lib/icons/lucide.d.ts +0 -1
- package/lib/icons/lucide.js +24479 -26351
- package/lib/icons/material/filled.d.ts +0 -1
- package/lib/icons/material/filled.js +9653 -9663
- package/lib/icons/material/outlined.d.ts +0 -1
- package/lib/icons/material/outlined.js +10271 -10281
- package/lib/icons/material/round.d.ts +0 -1
- package/lib/icons/material/round.js +10495 -10505
- package/lib/icons/material/sharp.d.ts +0 -1
- package/lib/icons/material/sharp.js +9905 -9915
- package/lib/icons/material/two-tone.d.ts +0 -1
- package/lib/icons/material/two-tone.js +12792 -12802
- package/lib/index.d.ts +0 -1
- package/lib/index.js +21 -41
- package/lib/styles/button.d.ts +2 -20
- package/lib/styles/button.js +202 -404
- package/lib/styles/calendar-month.d.ts +1 -5
- package/lib/styles/calendar-month.js +127 -244
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +64 -104
- package/lib/styles/calendar.d.ts +1 -2
- package/lib/styles/calendar.js +9 -22
- package/lib/styles/checkbox.d.ts +0 -1
- package/lib/styles/checkbox.js +45 -94
- package/lib/styles/copy.d.ts +0 -1
- package/lib/styles/copy.js +67 -106
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +1 -5
- package/lib/styles/date-picker.js +261 -335
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.d.ts +1 -2
- package/lib/styles/file-upload.js +143 -188
- package/lib/styles/icon.d.ts +2 -6
- package/lib/styles/icon.js +92 -170
- package/lib/styles/input.d.ts +1 -6
- package/lib/styles/input.js +125 -290
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +71 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +49 -64
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +42 -77
- package/lib/styles/radio.d.ts +0 -1
- package/lib/styles/radio.js +69 -110
- package/lib/styles/resize-observer.d.ts +1 -2
- package/lib/styles/resize-observer.js +2 -12
- package/lib/styles/scroll-container.d.ts +1 -2
- package/lib/styles/scroll-container.js +100 -149
- package/lib/styles/select-base.d.ts +0 -1
- package/lib/styles/select-base.js +597 -785
- package/lib/styles/select.d.ts +1 -2
- package/lib/styles/select.js +140 -236
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +22 -33
- package/lib/styles/switch.d.ts +0 -1
- package/lib/styles/switch.js +34 -73
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +22 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +190 -222
- package/lib/styles/tag.d.ts +1 -5
- package/lib/styles/tag.js +136 -218
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +210 -319
- package/lib/styles/tooltip.d.ts +0 -1
- package/lib/styles/tooltip.js +3 -13
- package/lib/styles/wizard.d.ts +5 -21
- package/lib/styles/wizard.js +170 -306
- package/lib/types/common.d.ts +2 -2
- package/lib/types/common.js +6 -17
- package/lib/utils/calendar-utils.d.ts +4 -21
- package/lib/utils/calendar-utils.js +100 -273
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +0 -1
- package/lib/utils/flavor-sheet.js +14 -37
- package/lib/utils/icon-registry.d.ts +0 -2
- package/lib/utils/icon-registry.js +137 -243
- package/lib/utils/icons.d.ts +0 -1
- package/lib/utils/icons.js +0 -9
- package/lib/utils/loader-registry.d.ts +0 -1
- package/lib/utils/loader-registry.js +3 -35
- package/lib/utils/locale.d.ts +2 -23
- package/lib/utils/locale.js +34 -120
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -3
- package/lib/utils/number-format.js +54 -110
- package/lib/utils/positioning.d.ts +50 -7
- package/lib/utils/positioning.js +224 -234
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +0 -1
- package/lib/utils/property-manager.js +126 -196
- package/lib/utils/resize-observer.d.ts +0 -1
- package/lib/utils/resize-observer.js +23 -59
- package/lib/utils/scroll-lock.d.ts +4 -11
- package/lib/utils/scroll-lock.js +65 -172
- package/lib/utils/styles.d.ts +0 -1
- package/lib/utils/styles.js +17 -41
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +4 -4
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/file-upload.d.ts.map +0 -1
- package/lib/components/file-upload.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/radio.d.ts.map +0 -1
- package/lib/components/radio.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/select.d.ts.map +0 -1
- package/lib/components/select.js.map +0 -1
- package/lib/components/selected-tags.d.ts.map +0 -1
- package/lib/components/selected-tags.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/switch.d.ts.map +0 -1
- package/lib/components/switch.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/checkbox.d.ts.map +0 -1
- package/lib/styles/checkbox.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/custom-scrollbar.d.ts.map +0 -1
- package/lib/styles/custom-scrollbar.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/file-upload.d.ts.map +0 -1
- package/lib/styles/file-upload.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -8
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -849
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/radio.d.ts.map +0 -1
- package/lib/styles/radio.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/select-base.d.ts.map +0 -1
- package/lib/styles/select-base.js.map +0 -1
- package/lib/styles/select.d.ts.map +0 -1
- package/lib/styles/select.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/switch.d.ts.map +0 -1
- package/lib/styles/switch.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/custom-scrollbar.d.ts.map +0 -1
- package/lib/utils/custom-scrollbar.js.map +0 -1
- package/lib/utils/flavor-sheet.d.ts.map +0 -1
- package/lib/utils/flavor-sheet.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/icons.d.ts.map +0 -1
- package/lib/utils/icons.js.map +0 -1
- package/lib/utils/loader-registry.d.ts.map +0 -1
- package/lib/utils/loader-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/mobile.d.ts.map +0 -1
- package/lib/utils/mobile.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -58
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
package/lib/components/select.js
CHANGED
|
@@ -1,2115 +1,1634 @@
|
|
|
1
|
-
|
|
2
|
-
* TySelect Web Component
|
|
3
|
-
*
|
|
4
|
-
* The select control — replaces ty-dropdown and ty-multiselect.
|
|
5
|
-
*
|
|
6
|
-
* Cardinality (native <select> semantics):
|
|
7
|
-
* - default: SINGLE select — scalar value, picking an option closes the popup
|
|
8
|
-
* - `multiple`: multi select — comma value / repeated FormData entries,
|
|
9
|
-
* options toggle and the popup stays open
|
|
10
|
-
*
|
|
11
|
-
* Skins:
|
|
12
|
-
* - default: form FIELD — full width, --ty-input-* tokens, matches ty-input;
|
|
13
|
-
* shows the selected label(s) inline
|
|
14
|
-
* - `compact`: content-hugging trigger for toolbars/filter bars; single shows
|
|
15
|
-
* the selected label, multiple shows placeholder + count badge (pair with
|
|
16
|
-
* <ty-selected-options>)
|
|
17
|
-
* - slot="trigger": consumer skin — replaces field/compact chrome entirely,
|
|
18
|
-
* behavior/ARIA/form participation unchanged
|
|
19
|
-
*
|
|
20
|
-
* - ty-option children (ty-tag also accepted)
|
|
21
|
-
* - Desktop popup with smart positioning, mobile full-screen modal
|
|
22
|
-
* - Search / external-search / debounce, keyboard navigation
|
|
23
|
-
* - Form association: single submits one entry, multiple submits repeated
|
|
24
|
-
* `name=` entries (HTMX-ready)
|
|
25
|
-
* - change event detail: { value, values, items: [{value, label, flavor}], action, item }
|
|
26
|
-
* (`value` is a scalar for single, array for multiple)
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```html
|
|
30
|
-
* <!-- Single select, field skin -->
|
|
31
|
-
* <ty-select label="Robot" name="robot">
|
|
32
|
-
* <ty-option value="bobo">Bobo Robot</ty-option>
|
|
33
|
-
* <ty-option value="eywa">EYWA Dataset Example</ty-option>
|
|
34
|
-
* </ty-select>
|
|
35
|
-
*
|
|
36
|
-
* <!-- Multi select, compact skin + out-of-band chips -->
|
|
37
|
-
* <ty-select multiple compact label="Robots" name="robots" id="robots">...</ty-select>
|
|
38
|
-
* <ty-selected-options for="robots"></ty-selected-options>
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
1
|
+
import { DEFAULT_SIZE } from "../types/common.js";
|
|
41
2
|
import { ensureStyles } from "../utils/styles.js";
|
|
42
3
|
import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
|
|
43
4
|
import { selectBaseStyles, selectCustomFlavorCss } from "../styles/select-base.js";
|
|
44
5
|
import { selectStyles } from "../styles/select.js";
|
|
45
6
|
import { getLoaderSvg } from "../utils/loader-registry.js";
|
|
46
7
|
import { lockScroll, unlockScroll } from "../utils/scroll-lock.js";
|
|
47
|
-
import { computeAnchoredPosition } from "../utils/positioning.js";
|
|
8
|
+
import { computeAnchoredPosition, placementToAnchored } from "../utils/positioning.js";
|
|
48
9
|
import { isMobileTouch } from "../utils/mobile.js";
|
|
49
10
|
import { TyComponent } from "../base/ty-component.js";
|
|
50
11
|
import { CustomScrollbar, isCustomScrollbarEnabled, } from "../utils/custom-scrollbar.js";
|
|
51
|
-
// ============================================================================
|
|
52
|
-
// Element Hash Utility (for consistent scroll lock IDs)
|
|
53
|
-
// ============================================================================
|
|
54
|
-
/**
|
|
55
|
-
* Counter for generating unique element IDs
|
|
56
|
-
*/
|
|
57
12
|
let elementIdCounter = 0;
|
|
58
|
-
/**
|
|
59
|
-
* WeakMap to store consistent element hashes
|
|
60
|
-
* Automatically garbage collects when element is destroyed
|
|
61
|
-
*/
|
|
62
13
|
const elementIds = new WeakMap();
|
|
63
|
-
/**
|
|
64
|
-
* Get a consistent unique ID for an element
|
|
65
|
-
* Returns the same ID for the same element across multiple calls
|
|
66
|
-
*
|
|
67
|
-
* @param element - The element to hash
|
|
68
|
-
* @returns A consistent numeric hash for the element
|
|
69
|
-
*/
|
|
70
14
|
function getElementHash(element) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
// ============================================================================
|
|
79
|
-
// SVG Icons
|
|
80
|
-
// ============================================================================
|
|
15
|
+
let id = elementIds.get(element);
|
|
16
|
+
if (id === undefined) {
|
|
17
|
+
id = ++elementIdCounter;
|
|
18
|
+
elementIds.set(element, id);
|
|
19
|
+
}
|
|
20
|
+
return id;
|
|
21
|
+
}
|
|
81
22
|
import { REQUIRED_ICON_SVG } from "../utils/icons.js";
|
|
82
|
-
|
|
83
|
-
* Chevron down icon SVG
|
|
84
|
-
*/
|
|
23
|
+
const SEARCH_AUTO_THRESHOLD = 7;
|
|
85
24
|
const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
|
|
86
|
-
|
|
25
|
+
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
87
26
|
</svg>`;
|
|
88
|
-
/**
|
|
89
|
-
* 'auto' searchable mode: option count above which the search row appears.
|
|
90
|
-
* Short lists scan faster than they search — native <select> has no search.
|
|
91
|
-
*/
|
|
92
|
-
const SEARCH_AUTO_THRESHOLD = 7;
|
|
93
|
-
/**
|
|
94
|
-
* create-transform="slug": lowercase, spaces → '_', strip anything else
|
|
95
|
-
* non-alphanumeric, collapse/trim stray underscores.
|
|
96
|
-
*/
|
|
97
27
|
function slugify(text) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Search (magnifier) icon SVG — popup search input adornment (from Lucide)
|
|
108
|
-
*/
|
|
28
|
+
return text
|
|
29
|
+
.trim()
|
|
30
|
+
.toLowerCase()
|
|
31
|
+
.replace(/\s+/g, "_")
|
|
32
|
+
.replace(/[^a-z0-9_]/g, "")
|
|
33
|
+
.replace(/_+/g, "_")
|
|
34
|
+
.replace(/^_|_$/g, "");
|
|
35
|
+
}
|
|
109
36
|
const SEARCH_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
110
|
-
|
|
37
|
+
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
|
|
111
38
|
</svg>`;
|
|
112
|
-
/**
|
|
113
|
-
* Clear (X) icon SVG — .select-clear button, shown in the trigger's fallback
|
|
114
|
-
* chrome (default/compact skins) when clearable and something is selected.
|
|
115
|
-
*/
|
|
116
39
|
const CLEAR_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
117
|
-
|
|
118
|
-
|
|
40
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
41
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
119
42
|
</svg>`;
|
|
120
|
-
/**
|
|
121
|
-
* Ty Select Component
|
|
122
|
-
*/
|
|
123
43
|
export class TySelect extends TyComponent {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
<span class="dropdown-loading-spinner"></span>
|
|
1565
|
-
<span class="dropdown-loading-text">Searching…</span>
|
|
1566
|
-
</slot>
|
|
1567
|
-
</div>
|
|
1568
|
-
</div>
|
|
1569
|
-
</div>
|
|
1570
|
-
|
|
1571
|
-
</div>
|
|
1572
|
-
</div>
|
|
1573
|
-
</dialog>
|
|
1574
|
-
</div>
|
|
1575
|
-
</div>
|
|
1576
|
-
`;
|
|
1577
|
-
// Setup event listeners ONCE
|
|
1578
|
-
this.setupMobileEventListeners();
|
|
1579
|
-
}
|
|
1580
|
-
// Always update placeholder visibility
|
|
1581
|
-
this.updateSelectionDisplay();
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Setup event listeners for mobile mode
|
|
1585
|
-
* Using <dialog> element - backdrop clicks handled natively
|
|
1586
|
-
*/
|
|
1587
|
-
setupMobileEventListeners() {
|
|
1588
|
-
const shadow = this.shadowRoot;
|
|
1589
|
-
const stub = shadow.querySelector(".select-stub");
|
|
1590
|
-
const optionsSlot = shadow.querySelector("#options-slot");
|
|
1591
|
-
const searchInput = shadow.querySelector(".mobile-search-input");
|
|
1592
|
-
const closeButton = shadow.querySelector(".mobile-close-button");
|
|
1593
|
-
const dialog = shadow.querySelector(".mobile-dialog");
|
|
1594
|
-
if (stub) {
|
|
1595
|
-
stub.addEventListener("click", (e) => this.handleMobileStubClick(e));
|
|
1596
|
-
stub.addEventListener("keydown", (e) => this.handleMobileStubKeydown(e));
|
|
1597
|
-
}
|
|
1598
|
-
const clearBtn = shadow.querySelector(".select-clear");
|
|
1599
|
-
clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
|
|
1600
|
-
this.setupTriggerSlot();
|
|
1601
|
-
// Add tag click handler to slot
|
|
1602
|
-
if (optionsSlot) {
|
|
1603
|
-
optionsSlot.addEventListener("click", (e) => this.handleMobileTagClick(e));
|
|
1604
|
-
}
|
|
1605
|
-
// Add search input handlers (if searchable)
|
|
1606
|
-
if (searchInput) {
|
|
1607
|
-
searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
|
|
1608
|
-
}
|
|
1609
|
-
// Close button click
|
|
1610
|
-
if (closeButton) {
|
|
1611
|
-
closeButton.addEventListener("click", () => this.closeMobileModal());
|
|
1612
|
-
}
|
|
1613
|
-
// Backdrop click to close (native dialog behavior)
|
|
1614
|
-
if (dialog) {
|
|
1615
|
-
dialog.addEventListener("click", (e) => {
|
|
1616
|
-
// Only close if clicking directly on the dialog element (backdrop)
|
|
1617
|
-
// Not if clicking on its children (dialog-content)
|
|
1618
|
-
if (e.target === dialog) {
|
|
1619
|
-
this.closeMobileModal();
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
// Also handle Escape key via cancel event
|
|
1623
|
-
dialog.addEventListener("cancel", (e) => {
|
|
1624
|
-
e.preventDefault(); // Prevent default to handle it our way
|
|
1625
|
-
this.closeMobileModal();
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
* Handle mobile stub click - open modal
|
|
1631
|
-
*/
|
|
1632
|
-
handleMobileStubClick(e) {
|
|
1633
|
-
e.preventDefault();
|
|
1634
|
-
e.stopPropagation();
|
|
1635
|
-
if (this._disabled || this._readonly) {
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
this.openMobileModal();
|
|
1639
|
-
}
|
|
1640
|
-
/** Keyboard-open the (closed) mobile stub — see handleStubKeydown for why this is needed. */
|
|
1641
|
-
handleMobileStubKeydown(e) {
|
|
1642
|
-
if (this._disabled || this._readonly || this._state.open)
|
|
1643
|
-
return;
|
|
1644
|
-
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
1645
|
-
e.preventDefault();
|
|
1646
|
-
this.openMobileModal();
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Handle mobile tag click - select and potentially close
|
|
1651
|
-
*/
|
|
1652
|
-
handleMobileTagClick(e) {
|
|
1653
|
-
// Use the same tag click handler as desktop
|
|
1654
|
-
// It already handles mobile mode for auto-close
|
|
1655
|
-
this.handleTagClick(e);
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* Update mobile options section state (count, empty state)
|
|
1659
|
-
*/
|
|
1660
|
-
updateMobileSelectedState() {
|
|
1661
|
-
if (this._state.mode !== "mobile")
|
|
1662
|
-
return;
|
|
1663
|
-
const shadow = this.shadowRoot;
|
|
1664
|
-
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1665
|
-
if (availableSection) {
|
|
1666
|
-
// Count *visible* options — options hidden by search filtering count as 0
|
|
1667
|
-
const visibleAvailable = this.getTagElements().filter((tag) => !tag.hasAttribute("hidden")).length;
|
|
1668
|
-
availableSection.setAttribute("data-empty", String(visibleAvailable === 0));
|
|
1669
|
-
// Update available header count
|
|
1670
|
-
const availableTitleSpan = shadow.querySelector(".mobile-available-section .section-title");
|
|
1671
|
-
if (availableTitleSpan) {
|
|
1672
|
-
availableTitleSpan.textContent = `${this._availableLabel} (${visibleAvailable})`;
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
/**
|
|
1677
|
-
* Update selection display: count badge next to the placeholder
|
|
1678
|
-
*/
|
|
1679
|
-
/**
|
|
1680
|
-
* Should the popup show a search row? external-search always (the input is
|
|
1681
|
-
* the mechanism); searchable always/never wins otherwise; 'auto' shows it
|
|
1682
|
-
* only when the option list is long enough to need filtering.
|
|
1683
|
-
*/
|
|
1684
|
-
shouldShowSearch() {
|
|
1685
|
-
if (this._externalSearch)
|
|
1686
|
-
return true;
|
|
1687
|
-
// allow-create's only input mechanism IS the search box.
|
|
1688
|
-
if (this._allowCreate)
|
|
1689
|
-
return true;
|
|
1690
|
-
if (this._searchable === "always")
|
|
1691
|
-
return true;
|
|
1692
|
-
if (this._searchable === "never")
|
|
1693
|
-
return false;
|
|
1694
|
-
return this.getTagElements().length > SEARCH_AUTO_THRESHOLD;
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* Toggle the search row (desktop header / mobile input) per shouldShowSearch.
|
|
1698
|
-
*/
|
|
1699
|
-
updateSearchVisibility() {
|
|
1700
|
-
const shadow = this.shadowRoot;
|
|
1701
|
-
if (!shadow)
|
|
1702
|
-
return;
|
|
1703
|
-
const show = this.shouldShowSearch();
|
|
1704
|
-
const header = shadow.querySelector(".dropdown-header");
|
|
1705
|
-
if (header)
|
|
1706
|
-
header.hidden = !show;
|
|
1707
|
-
// Mobile keeps its header (label + close button); only the input+icon hide
|
|
1708
|
-
const mobileInput = shadow.querySelector(".mobile-search-input");
|
|
1709
|
-
if (mobileInput)
|
|
1710
|
-
mobileInput.hidden = !show;
|
|
1711
|
-
const mobileIcon = shadow.querySelector(".mobile-header-content .dropdown-search-icon");
|
|
1712
|
-
if (mobileIcon)
|
|
1713
|
-
mobileIcon.hidden = !show;
|
|
1714
|
-
}
|
|
1715
|
-
/**
|
|
1716
|
-
* Selection summary appropriate to cardinality × skin:
|
|
1717
|
-
* - single (field or compact): the selected OPTION itself — cloned into
|
|
1718
|
-
* slot="selected" so rich HTML options display intact (dropdown parity);
|
|
1719
|
-
* placeholder when empty
|
|
1720
|
-
* - multiple + field: joined labels (ellipsis via CSS), or placeholder
|
|
1721
|
-
* - multiple + compact: placeholder + count badge
|
|
1722
|
-
*/
|
|
1723
|
-
updateSelectionDisplay() {
|
|
1724
|
-
const shadow = this.shadowRoot;
|
|
1725
|
-
const stub = shadow.querySelector(".select-stub");
|
|
1726
|
-
if (!stub)
|
|
1727
|
-
return;
|
|
1728
|
-
// Selection comes from STATE, not from scanning option elements —
|
|
1729
|
-
// external search replaces the option children, and the selection must
|
|
1730
|
-
// survive even when the current results don't include the selected value.
|
|
1731
|
-
const values = this._state.selectedValues;
|
|
1732
|
-
const count = values.length;
|
|
1733
|
-
stub.classList.toggle("has-selection", count > 0);
|
|
1734
|
-
stub.classList.toggle("compact", this._compact);
|
|
1735
|
-
const badge = stub.querySelector(".select-count");
|
|
1736
|
-
if (badge) {
|
|
1737
|
-
badge.textContent = String(count);
|
|
1738
|
-
badge.hidden = count === 0 || !this._multiple || !this._compact;
|
|
1739
|
-
}
|
|
1740
|
-
const clearBtn = stub.querySelector(".select-clear");
|
|
1741
|
-
if (clearBtn) {
|
|
1742
|
-
clearBtn.hidden = !(count > 0 && this._clearable && !this._disabled && !this._readonly);
|
|
1743
|
-
}
|
|
1744
|
-
// Single select: project the selected option into the stub as a clone
|
|
1745
|
-
// (rich HTML content survives — same mechanism as ty-dropdown).
|
|
1746
|
-
const wantClone = !this._multiple && count > 0 ? values[0] : null;
|
|
1747
|
-
this.syncSelectedClone(wantClone);
|
|
1748
|
-
stub.classList.toggle("has-clone", wantClone !== null);
|
|
1749
|
-
const textEl = stub.querySelector(".dropdown-placeholder");
|
|
1750
|
-
if (textEl) {
|
|
1751
|
-
// The clone replaces the text display entirely in single mode
|
|
1752
|
-
textEl.hidden = wantClone !== null;
|
|
1753
|
-
const showLabels = count > 0 && this._multiple && !this._compact;
|
|
1754
|
-
if (showLabels) {
|
|
1755
|
-
textEl.textContent = this.getSelectedItems(values)
|
|
1756
|
-
.map((i) => i.label)
|
|
1757
|
-
.join(", ");
|
|
1758
|
-
textEl.classList.remove("placeholder-shown");
|
|
1759
|
-
}
|
|
1760
|
-
else {
|
|
1761
|
-
textEl.textContent = this._placeholder;
|
|
1762
|
-
textEl.classList.add("placeholder-shown");
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
/**
|
|
1767
|
-
* Keep exactly one display clone (slot="selected", marked `cloned`) in our
|
|
1768
|
-
* light DOM matching the given value — or none. The clone never counts as
|
|
1769
|
-
* an option (getTagElements filters [cloned]) and ty-option's own
|
|
1770
|
-
* :host([cloned]) styling strips its list-row chrome.
|
|
1771
|
-
*/
|
|
1772
|
-
syncSelectedClone(value) {
|
|
1773
|
-
const existing = this.querySelector(':scope > [cloned][slot="selected"]');
|
|
1774
|
-
if (existing?.getAttribute("value") === value) {
|
|
1775
|
-
this._selectedClone = existing;
|
|
1776
|
-
return; // already right
|
|
1777
|
-
}
|
|
1778
|
-
existing?.remove();
|
|
1779
|
-
if (value === null) {
|
|
1780
|
-
this._selectedClone = null;
|
|
1781
|
-
return;
|
|
1782
|
-
}
|
|
1783
|
-
const option = this.getTagElements().find((el) => this.getTagData(el).value === value);
|
|
1784
|
-
if (option) {
|
|
1785
|
-
const clone = option.cloneNode(true);
|
|
1786
|
-
clone.removeAttribute("selected"); // no tick/selected styling in the stub
|
|
1787
|
-
clone.setAttribute("slot", "selected");
|
|
1788
|
-
clone.setAttribute("cloned", "true");
|
|
1789
|
-
this.appendChild(clone);
|
|
1790
|
-
this._selectedClone = clone;
|
|
1791
|
-
}
|
|
1792
|
-
else if (this._selectedClone?.getAttribute("value") === value) {
|
|
1793
|
-
// The option list no longer contains the selection (external search
|
|
1794
|
-
// swapped the children — possibly wiping our clone with them). Restore
|
|
1795
|
-
// the saved display clone so the selection stays visible.
|
|
1796
|
-
const restored = this._selectedClone.cloneNode(true);
|
|
1797
|
-
this.appendChild(restored);
|
|
1798
|
-
this._selectedClone = restored;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
// ============================================================================
|
|
1802
|
-
// PUBLIC API - Getters/Setters
|
|
1803
|
-
// ============================================================================
|
|
1804
|
-
/**
|
|
1805
|
-
* Deselect a value programmatically WITH a change event.
|
|
1806
|
-
* Used by out-of-band chip displays (ty-selected-options) so dismissing a chip
|
|
1807
|
-
* fires change like any in-popup interaction (HTMX hx-trigger="change" etc.).
|
|
1808
|
-
*/
|
|
1809
|
-
deselectValue(value) {
|
|
1810
|
-
const current = this.getSelectedValues();
|
|
1811
|
-
if (!current.includes(value))
|
|
1812
|
-
return;
|
|
1813
|
-
this.updateComponentValue(current.filter((v) => v !== value), true, "remove", value);
|
|
1814
|
-
}
|
|
1815
|
-
/**
|
|
1816
|
-
* Clear the entire selection programmatically WITH a change event
|
|
1817
|
-
* (action: 'clear'). No-op if nothing is selected. Exists so slot="trigger"
|
|
1818
|
-
* consumers (custom chrome, built-in clear UI hidden by design) can wire
|
|
1819
|
-
* their own clear icon's click handler to it.
|
|
1820
|
-
*/
|
|
1821
|
-
clear() {
|
|
1822
|
-
this.updateComponentValue([], true, "clear", null);
|
|
1823
|
-
}
|
|
1824
|
-
get value() {
|
|
1825
|
-
// Always read from DOM - tags with 'selected' attribute are source of truth
|
|
1826
|
-
return this.getSelectedValues().join(",");
|
|
1827
|
-
}
|
|
1828
|
-
set value(val) {
|
|
1829
|
-
this.setProperty("value", val);
|
|
1830
|
-
}
|
|
1831
|
-
get name() {
|
|
1832
|
-
return this.getProperty("name");
|
|
1833
|
-
}
|
|
1834
|
-
set name(val) {
|
|
1835
|
-
this.setProperty("name", val);
|
|
1836
|
-
}
|
|
1837
|
-
get multiple() {
|
|
1838
|
-
return this.getProperty("multiple");
|
|
1839
|
-
}
|
|
1840
|
-
set multiple(value) {
|
|
1841
|
-
this.setProperty("multiple", value);
|
|
1842
|
-
}
|
|
1843
|
-
get compact() {
|
|
1844
|
-
return this.getProperty("compact");
|
|
1845
|
-
}
|
|
1846
|
-
set compact(value) {
|
|
1847
|
-
this.setProperty("compact", value);
|
|
1848
|
-
}
|
|
1849
|
-
get placeholder() {
|
|
1850
|
-
return this.getProperty("placeholder");
|
|
1851
|
-
}
|
|
1852
|
-
set placeholder(val) {
|
|
1853
|
-
this.setProperty("placeholder", val);
|
|
1854
|
-
}
|
|
1855
|
-
get label() {
|
|
1856
|
-
return this.getProperty("label");
|
|
1857
|
-
}
|
|
1858
|
-
set label(val) {
|
|
1859
|
-
this.setProperty("label", val);
|
|
1860
|
-
}
|
|
1861
|
-
get disabled() {
|
|
1862
|
-
return this.getProperty("disabled");
|
|
1863
|
-
}
|
|
1864
|
-
set disabled(value) {
|
|
1865
|
-
this.setProperty("disabled", value);
|
|
1866
|
-
}
|
|
1867
|
-
get loading() {
|
|
1868
|
-
return this.getProperty("loading");
|
|
1869
|
-
}
|
|
1870
|
-
set loading(value) {
|
|
1871
|
-
this.setProperty("loading", value);
|
|
1872
|
-
}
|
|
1873
|
-
get readonly() {
|
|
1874
|
-
return this.getProperty("readonly");
|
|
1875
|
-
}
|
|
1876
|
-
set readonly(value) {
|
|
1877
|
-
this.setProperty("readonly", value);
|
|
1878
|
-
}
|
|
1879
|
-
get clearable() {
|
|
1880
|
-
return this.getProperty("clearable");
|
|
1881
|
-
}
|
|
1882
|
-
set clearable(value) {
|
|
1883
|
-
this.setProperty("clearable", value);
|
|
1884
|
-
}
|
|
1885
|
-
get required() {
|
|
1886
|
-
return this.getProperty("required");
|
|
1887
|
-
}
|
|
1888
|
-
set required(value) {
|
|
1889
|
-
this.setProperty("required", value);
|
|
1890
|
-
}
|
|
1891
|
-
get searchable() {
|
|
1892
|
-
return this.getProperty("searchable");
|
|
1893
|
-
}
|
|
1894
|
-
set searchable(value) {
|
|
1895
|
-
this.setProperty("searchable", value);
|
|
1896
|
-
}
|
|
1897
|
-
get externalSearch() {
|
|
1898
|
-
return this.getProperty("externalSearch");
|
|
1899
|
-
}
|
|
1900
|
-
set externalSearch(value) {
|
|
1901
|
-
this.setProperty("externalSearch", value);
|
|
1902
|
-
}
|
|
1903
|
-
get debounce() {
|
|
1904
|
-
return this.getProperty("debounce");
|
|
1905
|
-
}
|
|
1906
|
-
set debounce(value) {
|
|
1907
|
-
const numValue = typeof value === "string" ? parseInt(value, 10) : value;
|
|
1908
|
-
this.setProperty("debounce", numValue);
|
|
1909
|
-
}
|
|
1910
|
-
get size() {
|
|
1911
|
-
return this.getProperty("size");
|
|
1912
|
-
}
|
|
1913
|
-
set size(value) {
|
|
1914
|
-
this.setProperty("size", value);
|
|
1915
|
-
}
|
|
1916
|
-
get align() {
|
|
1917
|
-
return this.getProperty("align");
|
|
1918
|
-
}
|
|
1919
|
-
set align(value) {
|
|
1920
|
-
this.setProperty("align", value);
|
|
1921
|
-
}
|
|
1922
|
-
get flavor() {
|
|
1923
|
-
return this.getProperty("flavor");
|
|
1924
|
-
}
|
|
1925
|
-
set flavor(value) {
|
|
1926
|
-
this.setProperty("flavor", value);
|
|
1927
|
-
}
|
|
1928
|
-
get form() {
|
|
1929
|
-
return this._internals.form;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
// ============================================================================
|
|
1933
|
-
// PROPERTY CONFIGURATION - Declarative property lifecycle
|
|
1934
|
-
// ============================================================================
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
this._name = "";
|
|
47
|
+
this._multiple = false;
|
|
48
|
+
this._compact = false;
|
|
49
|
+
this._placeholder = "Select...";
|
|
50
|
+
this._label = "";
|
|
51
|
+
this._disabled = false;
|
|
52
|
+
this._readonly = false;
|
|
53
|
+
this._required = false;
|
|
54
|
+
this._clearable = true;
|
|
55
|
+
this._externalSearch = false;
|
|
56
|
+
this._allowCreate = false;
|
|
57
|
+
this._createTransform = "none";
|
|
58
|
+
this._notSearchable = false;
|
|
59
|
+
this._loading = false;
|
|
60
|
+
this._scrollLockId = null;
|
|
61
|
+
this._size = DEFAULT_SIZE;
|
|
62
|
+
this._availableLabel = "Available";
|
|
63
|
+
this._selectedLabel = "Selected";
|
|
64
|
+
this._noOptionsMessage = "No options available";
|
|
65
|
+
this._state = {
|
|
66
|
+
open: false,
|
|
67
|
+
search: "",
|
|
68
|
+
highlightedIndex: -1,
|
|
69
|
+
filteredTags: [],
|
|
70
|
+
selectedValues: [],
|
|
71
|
+
mode: "desktop",
|
|
72
|
+
};
|
|
73
|
+
this._stubClickHandler = null;
|
|
74
|
+
this._tagClickHandler = null;
|
|
75
|
+
this._searchInputHandler = null;
|
|
76
|
+
this._blockSearchClick = null;
|
|
77
|
+
this._keyboardHandler = null;
|
|
78
|
+
this._debounce = 0;
|
|
79
|
+
this._searchDebounceTimer = null;
|
|
80
|
+
this._optionsScrollbar = null;
|
|
81
|
+
this._childObserver = null;
|
|
82
|
+
this._selectedClone = null;
|
|
83
|
+
this._customFlavorSheet = null;
|
|
84
|
+
const shadow = this.shadowRoot;
|
|
85
|
+
ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
|
|
86
|
+
ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
|
|
87
|
+
}
|
|
88
|
+
onConnect() {
|
|
89
|
+
const shadow = this.shadowRoot;
|
|
90
|
+
const dialogs = shadow.querySelectorAll("dialog");
|
|
91
|
+
dialogs.forEach((dialog) => {
|
|
92
|
+
if (dialog.open) {
|
|
93
|
+
console.warn("⚠️ Found open dialog on connect, closing it");
|
|
94
|
+
dialog.close();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.render();
|
|
98
|
+
this.initializeState();
|
|
99
|
+
this._childObserver = new MutationObserver(() => {
|
|
100
|
+
this.ensureOptionRoles();
|
|
101
|
+
if (this._state.selectedValues.length > 0) {
|
|
102
|
+
this.syncSelectedTags(this._state.selectedValues);
|
|
103
|
+
}
|
|
104
|
+
this.updateSearchVisibility();
|
|
105
|
+
this.updateSelectionDisplay();
|
|
106
|
+
this.updateMobileSelectedState();
|
|
107
|
+
});
|
|
108
|
+
this._childObserver.observe(this, { childList: true });
|
|
109
|
+
this.ensureOptionRoles();
|
|
110
|
+
this._syncCustomFlavor();
|
|
111
|
+
}
|
|
112
|
+
_syncCustomFlavor() {
|
|
113
|
+
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getProperty("flavor"), ({ base }) => selectCustomFlavorCss(base));
|
|
114
|
+
}
|
|
115
|
+
onDisconnect() {
|
|
116
|
+
const shadow = this.shadowRoot;
|
|
117
|
+
const dialogs = shadow.querySelectorAll("dialog");
|
|
118
|
+
dialogs.forEach((dialog) => {
|
|
119
|
+
if (dialog.open) {
|
|
120
|
+
dialog.close();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (this._keyboardHandler) {
|
|
124
|
+
document.removeEventListener("keydown", this._keyboardHandler);
|
|
125
|
+
this._keyboardHandler = null;
|
|
126
|
+
}
|
|
127
|
+
if (this._searchDebounceTimer !== null) {
|
|
128
|
+
clearTimeout(this._searchDebounceTimer);
|
|
129
|
+
this._searchDebounceTimer = null;
|
|
130
|
+
}
|
|
131
|
+
this._destroyOptionsScrollbar();
|
|
132
|
+
if (this._childObserver) {
|
|
133
|
+
this._childObserver.disconnect();
|
|
134
|
+
this._childObserver = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
onPropertiesChanged(changes) {
|
|
138
|
+
for (const { name, newValue } of changes) {
|
|
139
|
+
switch (name) {
|
|
140
|
+
case "value":
|
|
141
|
+
const selectedValues = this.parseValue(newValue);
|
|
142
|
+
this._state.selectedValues = selectedValues;
|
|
143
|
+
if (this.isConnected && this.shadowRoot) {
|
|
144
|
+
this.syncSelectedTags(selectedValues);
|
|
145
|
+
this.updateSelectionDisplay();
|
|
146
|
+
this.updateMobileSelectedState();
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case "name":
|
|
150
|
+
this._name = newValue || "";
|
|
151
|
+
break;
|
|
152
|
+
case "flavor":
|
|
153
|
+
this._syncCustomFlavor();
|
|
154
|
+
break;
|
|
155
|
+
case "multiple":
|
|
156
|
+
this._multiple = newValue;
|
|
157
|
+
if (!newValue && this._state.selectedValues.length > 1) {
|
|
158
|
+
this.updateComponentValue([this._state.selectedValues[0]], false, "set", null);
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
case "compact":
|
|
162
|
+
this._compact = newValue;
|
|
163
|
+
break;
|
|
164
|
+
case "placeholder":
|
|
165
|
+
this._placeholder = newValue || "Select...";
|
|
166
|
+
if (this.isConnected && this.shadowRoot)
|
|
167
|
+
this.updateSelectionDisplay();
|
|
168
|
+
break;
|
|
169
|
+
case "label":
|
|
170
|
+
this._label = newValue || "";
|
|
171
|
+
break;
|
|
172
|
+
case "disabled":
|
|
173
|
+
this._disabled = newValue;
|
|
174
|
+
break;
|
|
175
|
+
case "readonly":
|
|
176
|
+
this._readonly = newValue;
|
|
177
|
+
break;
|
|
178
|
+
case "required":
|
|
179
|
+
this._required = newValue;
|
|
180
|
+
break;
|
|
181
|
+
case "clearable":
|
|
182
|
+
this._clearable = newValue;
|
|
183
|
+
if (this.isConnected && this.shadowRoot)
|
|
184
|
+
this.updateSelectionDisplay();
|
|
185
|
+
break;
|
|
186
|
+
case "externalSearch":
|
|
187
|
+
this._externalSearch = newValue;
|
|
188
|
+
break;
|
|
189
|
+
case "notSearchable":
|
|
190
|
+
this._notSearchable = newValue;
|
|
191
|
+
if (this.isConnected && this.shadowRoot)
|
|
192
|
+
this.updateSearchVisibility();
|
|
193
|
+
break;
|
|
194
|
+
case "allowCreate":
|
|
195
|
+
this._allowCreate = newValue;
|
|
196
|
+
if (this.isConnected && this.shadowRoot)
|
|
197
|
+
this.updateSearchVisibility();
|
|
198
|
+
break;
|
|
199
|
+
case "createTransform":
|
|
200
|
+
this._createTransform = newValue;
|
|
201
|
+
break;
|
|
202
|
+
case "size":
|
|
203
|
+
this._size = newValue;
|
|
204
|
+
break;
|
|
205
|
+
case "debounce":
|
|
206
|
+
this._debounce = newValue;
|
|
207
|
+
break;
|
|
208
|
+
case "available-label":
|
|
209
|
+
this._availableLabel = newValue || "Available";
|
|
210
|
+
break;
|
|
211
|
+
case "selected-label":
|
|
212
|
+
this._selectedLabel = newValue || "Selected";
|
|
213
|
+
break;
|
|
214
|
+
case "no-options-message":
|
|
215
|
+
this._noOptionsMessage = newValue || "No options available";
|
|
216
|
+
break;
|
|
217
|
+
case "loading":
|
|
218
|
+
this._loading = newValue;
|
|
219
|
+
this.applyLoadingState();
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
applyLoadingState() {
|
|
225
|
+
const shadow = this.shadowRoot;
|
|
226
|
+
if (!shadow)
|
|
227
|
+
return;
|
|
228
|
+
const svg = this._loading ? getLoaderSvg() : null;
|
|
229
|
+
shadow.querySelectorAll(".dropdown-options-wrapper").forEach((wrapper) => {
|
|
230
|
+
wrapper.classList.toggle("loading", this._loading);
|
|
231
|
+
if (this._loading) {
|
|
232
|
+
wrapper.setAttribute("aria-busy", "true");
|
|
233
|
+
const spinner = wrapper.querySelector(".dropdown-loading-spinner");
|
|
234
|
+
if (spinner && svg)
|
|
235
|
+
spinner.innerHTML = svg;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
wrapper.removeAttribute("aria-busy");
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
getFormValue() {
|
|
243
|
+
const selectedValues = this._state.selectedValues;
|
|
244
|
+
if (this._name && selectedValues.length > 0) {
|
|
245
|
+
if (!this._multiple)
|
|
246
|
+
return selectedValues[0];
|
|
247
|
+
const formData = new FormData();
|
|
248
|
+
selectedValues.forEach((value) => {
|
|
249
|
+
formData.append(this._name, value);
|
|
250
|
+
});
|
|
251
|
+
return formData;
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
parseValue(value) {
|
|
256
|
+
if (!value || typeof value !== "string" || value.trim() === "")
|
|
257
|
+
return [];
|
|
258
|
+
return value
|
|
259
|
+
.split(",")
|
|
260
|
+
.map((v) => v.trim())
|
|
261
|
+
.filter((v) => v !== "");
|
|
262
|
+
}
|
|
263
|
+
initializeState() {
|
|
264
|
+
const initialValue = this.getProperty("value") || "";
|
|
265
|
+
if (initialValue) {
|
|
266
|
+
const selectedValues = this.parseValue(initialValue);
|
|
267
|
+
this._state.selectedValues = selectedValues;
|
|
268
|
+
this.syncSelectedTags(selectedValues);
|
|
269
|
+
this.updateSelectionDisplay();
|
|
270
|
+
this.updateMobileSelectedState();
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
this.resolveDeclarativeSelection();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
resolveDeclarativeSelection() {
|
|
277
|
+
if (this.getAttribute("value") || this._state.selectedValues.length > 0) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const preSelectedTags = this.getTagElements()
|
|
281
|
+
.filter((tag) => tag.hasAttribute("selected"))
|
|
282
|
+
.map((tag) => this.getTagData(tag).value);
|
|
283
|
+
if (preSelectedTags.length > 0) {
|
|
284
|
+
this.updateComponentValue(preSelectedTags, false);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (document.readyState === "loading") {
|
|
288
|
+
document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
|
|
289
|
+
this.resolveDeclarativeSelection(); }, { once: true });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
getTagElements() {
|
|
293
|
+
return Array.from(this.querySelectorAll("ty-option:not([cloned]), ty-tag:not([cloned])"));
|
|
294
|
+
}
|
|
295
|
+
getTagData(element) {
|
|
296
|
+
const value = element.value ||
|
|
297
|
+
element.getAttribute("value") ||
|
|
298
|
+
element.textContent ||
|
|
299
|
+
"";
|
|
300
|
+
const text = element.getAttribute("label") || element.textContent || "";
|
|
301
|
+
return { value, text, element };
|
|
302
|
+
}
|
|
303
|
+
selectTag(tag) {
|
|
304
|
+
tag.setAttribute("selected", "");
|
|
305
|
+
}
|
|
306
|
+
deselectTag(tag) {
|
|
307
|
+
tag.removeAttribute("selected");
|
|
308
|
+
}
|
|
309
|
+
getSelectedValues() {
|
|
310
|
+
return [...this._state.selectedValues];
|
|
311
|
+
}
|
|
312
|
+
syncSelectedTags(selectedValues) {
|
|
313
|
+
const selectedSet = new Set(selectedValues);
|
|
314
|
+
const tags = this.getTagElements();
|
|
315
|
+
tags.forEach((tag) => {
|
|
316
|
+
const tagValue = this.getTagData(tag).value;
|
|
317
|
+
const shouldBeSelected = selectedSet.has(tagValue);
|
|
318
|
+
const isSelected = tag.hasAttribute("selected");
|
|
319
|
+
if (shouldBeSelected && !isSelected) {
|
|
320
|
+
this.selectTag(tag);
|
|
321
|
+
}
|
|
322
|
+
else if (!shouldBeSelected && isSelected) {
|
|
323
|
+
this.deselectTag(tag);
|
|
324
|
+
}
|
|
325
|
+
tag.setAttribute("aria-selected", String(shouldBeSelected));
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
ensureOptionRoles() {
|
|
329
|
+
this.getTagElements().forEach((tag) => {
|
|
330
|
+
if (!tag.hasAttribute("role"))
|
|
331
|
+
tag.setAttribute("role", "option");
|
|
332
|
+
if (!tag.hasAttribute("aria-selected"))
|
|
333
|
+
tag.setAttribute("aria-selected", "false");
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
updateComponentValue(newValues, dispatchChange = false, action = "set", item = null) {
|
|
337
|
+
const oldValues = this.getSelectedValues();
|
|
338
|
+
const valueStr = newValues.join(",");
|
|
339
|
+
if (JSON.stringify(newValues.sort()) !== JSON.stringify(oldValues.sort())) {
|
|
340
|
+
this.setProperty("value", valueStr);
|
|
341
|
+
this.updateValidity();
|
|
342
|
+
if (dispatchChange) {
|
|
343
|
+
this.dispatchChangeEvent({
|
|
344
|
+
value: this._multiple ? [...newValues] : (newValues[0] ?? null),
|
|
345
|
+
values: newValues,
|
|
346
|
+
items: this.getSelectedItems(newValues),
|
|
347
|
+
action,
|
|
348
|
+
item,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
getSelectedItems(values) {
|
|
354
|
+
const byValue = new Map(this.getTagElements().map((el) => [this.getTagData(el).value, el]));
|
|
355
|
+
return values.map((value) => {
|
|
356
|
+
const el = byValue.get(value);
|
|
357
|
+
return {
|
|
358
|
+
value,
|
|
359
|
+
label: el?.getAttribute("label") || el?.textContent?.trim() || value,
|
|
360
|
+
flavor: el?.getAttribute("flavor") ?? null,
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
calculatePosition() {
|
|
365
|
+
const shadow = this.shadowRoot;
|
|
366
|
+
const stub = shadow.querySelector(".select-stub");
|
|
367
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
368
|
+
if (!stub || !dialog)
|
|
369
|
+
return;
|
|
370
|
+
const stubRect = stub.getBoundingClientRect();
|
|
371
|
+
const MAX_POPUP_ESTIMATE = 440;
|
|
372
|
+
const dialogRect = dialog.getBoundingClientRect();
|
|
373
|
+
const estimatedHeight = Math.min(dialogRect.height || 200, MAX_POPUP_ESTIMATE);
|
|
374
|
+
const wrapPadding = 20;
|
|
375
|
+
const cssWidth = parseFloat(getComputedStyle(this).getPropertyValue("--ty-select-popup-width"));
|
|
376
|
+
const popupWidth = !isNaN(cssWidth)
|
|
377
|
+
? cssWidth
|
|
378
|
+
: Math.max(stubRect.width, 320);
|
|
379
|
+
const requested = this.getProperty("placement");
|
|
380
|
+
const anchored = requested
|
|
381
|
+
? placementToAnchored(requested)
|
|
382
|
+
: {
|
|
383
|
+
side: "auto",
|
|
384
|
+
align: this.getProperty("align"),
|
|
385
|
+
};
|
|
386
|
+
const pos = computeAnchoredPosition({
|
|
387
|
+
anchorRect: stubRect,
|
|
388
|
+
popupWidth,
|
|
389
|
+
popupHeight: estimatedHeight,
|
|
390
|
+
align: anchored.align,
|
|
391
|
+
side: anchored.side,
|
|
392
|
+
gap: 8,
|
|
393
|
+
});
|
|
394
|
+
const positionBelow = pos.below;
|
|
395
|
+
const x = pos.x - wrapPadding;
|
|
396
|
+
const y = (positionBelow ? pos.topY : pos.bottomY) - wrapPadding;
|
|
397
|
+
const width = popupWidth + wrapPadding + wrapPadding;
|
|
398
|
+
this.style.setProperty("--dropdown-x", `${x}px`);
|
|
399
|
+
this.style.setProperty("--dropdown-y", `${y}px`);
|
|
400
|
+
this.style.setProperty("--dropdown-width", `${width}px`);
|
|
401
|
+
this.style.setProperty("--dropdown-offset-x", "0px");
|
|
402
|
+
this.style.setProperty("--dropdown-offset-y", "0px");
|
|
403
|
+
this.style.setProperty("--dropdown-padding", `${wrapPadding}px`);
|
|
404
|
+
if (positionBelow) {
|
|
405
|
+
dialog.classList.add("position-below");
|
|
406
|
+
dialog.classList.remove("position-above");
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
dialog.classList.add("position-above");
|
|
410
|
+
dialog.classList.remove("position-below");
|
|
411
|
+
}
|
|
412
|
+
this.style.setProperty("--dropdown-direction", positionBelow ? "below" : "above");
|
|
413
|
+
}
|
|
414
|
+
_setupOptionsScrollbar() {
|
|
415
|
+
if (!isCustomScrollbarEnabled())
|
|
416
|
+
return;
|
|
417
|
+
const shadow = this.shadowRoot;
|
|
418
|
+
const optionsDiv = shadow.querySelector(".dropdown-options");
|
|
419
|
+
const optionsWrapper = shadow.querySelector(".dropdown-options-wrapper");
|
|
420
|
+
if (!optionsDiv || !optionsWrapper)
|
|
421
|
+
return;
|
|
422
|
+
this._destroyOptionsScrollbar();
|
|
423
|
+
optionsDiv.classList.add("ty-custom-scroll");
|
|
424
|
+
this._optionsScrollbar = new CustomScrollbar(optionsDiv, {
|
|
425
|
+
vertical: true,
|
|
426
|
+
});
|
|
427
|
+
if (this._optionsScrollbar.trackY) {
|
|
428
|
+
optionsWrapper.appendChild(this._optionsScrollbar.trackY);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
_destroyOptionsScrollbar() {
|
|
432
|
+
if (this._optionsScrollbar) {
|
|
433
|
+
this._optionsScrollbar.trackY?.remove();
|
|
434
|
+
this._optionsScrollbar.destroy();
|
|
435
|
+
this._optionsScrollbar = null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
openDropdown() {
|
|
439
|
+
const shadow = this.shadowRoot;
|
|
440
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
441
|
+
if (!dialog)
|
|
442
|
+
return;
|
|
443
|
+
const stubEl = shadow.querySelector(".select-stub");
|
|
444
|
+
if (stubEl)
|
|
445
|
+
stubEl.setAttribute("aria-expanded", "true");
|
|
446
|
+
const lockId = `select-${this.id || "anon"}-${getElementHash(this)}`;
|
|
447
|
+
this._scrollLockId = lockId;
|
|
448
|
+
lockScroll(lockId);
|
|
449
|
+
dialog.showModal();
|
|
450
|
+
this.calculatePosition();
|
|
451
|
+
dialog.classList.add("open");
|
|
452
|
+
this._state.open = true;
|
|
453
|
+
const chevron = shadow.querySelector(".dropdown-chevron");
|
|
454
|
+
if (chevron)
|
|
455
|
+
chevron.classList.add("open");
|
|
456
|
+
const searchChevron = shadow.querySelector(".dropdown-search-chevron");
|
|
457
|
+
if (searchChevron)
|
|
458
|
+
searchChevron.classList.add("open");
|
|
459
|
+
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
460
|
+
this._state.filteredTags = tags;
|
|
461
|
+
this._state.highlightedIndex = -1;
|
|
462
|
+
this.updateOptionsVisibility(true);
|
|
463
|
+
this._setupOptionsScrollbar();
|
|
464
|
+
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
465
|
+
if (searchInput && this.shouldShowSearch()) {
|
|
466
|
+
setTimeout(() => searchInput.focus(), 100);
|
|
467
|
+
}
|
|
468
|
+
this.fireOpenEvent();
|
|
469
|
+
}
|
|
470
|
+
closeDropdown() {
|
|
471
|
+
const shadow = this.shadowRoot;
|
|
472
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
473
|
+
if (!dialog)
|
|
474
|
+
return;
|
|
475
|
+
const stubEl = shadow.querySelector(".select-stub");
|
|
476
|
+
if (stubEl)
|
|
477
|
+
stubEl.setAttribute("aria-expanded", "false");
|
|
478
|
+
this._destroyOptionsScrollbar();
|
|
479
|
+
dialog.classList.remove("open");
|
|
480
|
+
dialog.classList.remove("position-above");
|
|
481
|
+
dialog.classList.remove("position-below");
|
|
482
|
+
dialog.close();
|
|
483
|
+
if (this._scrollLockId) {
|
|
484
|
+
unlockScroll(this._scrollLockId);
|
|
485
|
+
this._scrollLockId = null;
|
|
486
|
+
}
|
|
487
|
+
this._state.open = false;
|
|
488
|
+
this._state.highlightedIndex = -1;
|
|
489
|
+
const chevron = shadow.querySelector(".dropdown-chevron");
|
|
490
|
+
if (chevron)
|
|
491
|
+
chevron.classList.remove("open");
|
|
492
|
+
const searchChevron = shadow.querySelector(".dropdown-search-chevron");
|
|
493
|
+
if (searchChevron)
|
|
494
|
+
searchChevron.classList.remove("open");
|
|
495
|
+
const hadQuery = this._state.search !== "";
|
|
496
|
+
this._state.search = "";
|
|
497
|
+
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
498
|
+
if (searchInput) {
|
|
499
|
+
searchInput.value = "";
|
|
500
|
+
}
|
|
501
|
+
if (this._externalSearch) {
|
|
502
|
+
if (hadQuery) {
|
|
503
|
+
if (this._searchDebounceTimer !== null) {
|
|
504
|
+
clearTimeout(this._searchDebounceTimer);
|
|
505
|
+
this._searchDebounceTimer = null;
|
|
506
|
+
}
|
|
507
|
+
this.fireSearchEvent("");
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
512
|
+
this._state.filteredTags = allTags;
|
|
513
|
+
this.updateTagVisibility(allTags, allTags);
|
|
514
|
+
this.clearHighlights(allTags);
|
|
515
|
+
}
|
|
516
|
+
this.fireCloseEvent();
|
|
517
|
+
}
|
|
518
|
+
openMobileModal() {
|
|
519
|
+
const shadow = this.shadowRoot;
|
|
520
|
+
const dialog = shadow.querySelector(".mobile-dialog");
|
|
521
|
+
if (!dialog)
|
|
522
|
+
return;
|
|
523
|
+
const stubEl = shadow.querySelector(".select-stub");
|
|
524
|
+
if (stubEl)
|
|
525
|
+
stubEl.setAttribute("aria-expanded", "true");
|
|
526
|
+
const lockId = `select-${this.id || "anon"}-${getElementHash(this)}`;
|
|
527
|
+
this._scrollLockId = lockId;
|
|
528
|
+
lockScroll(lockId);
|
|
529
|
+
dialog.showModal();
|
|
530
|
+
dialog.getBoundingClientRect();
|
|
531
|
+
dialog.classList.add("open");
|
|
532
|
+
this._state.open = true;
|
|
533
|
+
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
534
|
+
this._state.filteredTags = tags;
|
|
535
|
+
this.updateTagVisibility(tags, tags);
|
|
536
|
+
requestAnimationFrame(() => {
|
|
537
|
+
this.updateMobileSelectedState();
|
|
538
|
+
});
|
|
539
|
+
this.fireOpenEvent();
|
|
540
|
+
}
|
|
541
|
+
closeMobileModal() {
|
|
542
|
+
const shadow = this.shadowRoot;
|
|
543
|
+
const dialog = shadow.querySelector(".mobile-dialog");
|
|
544
|
+
if (!dialog)
|
|
545
|
+
return;
|
|
546
|
+
const stubEl = shadow.querySelector(".select-stub");
|
|
547
|
+
if (stubEl)
|
|
548
|
+
stubEl.setAttribute("aria-expanded", "false");
|
|
549
|
+
dialog.classList.remove("open");
|
|
550
|
+
dialog.close();
|
|
551
|
+
if (this._scrollLockId) {
|
|
552
|
+
unlockScroll(this._scrollLockId);
|
|
553
|
+
this._scrollLockId = null;
|
|
554
|
+
}
|
|
555
|
+
this._state.open = false;
|
|
556
|
+
this._state.highlightedIndex = -1;
|
|
557
|
+
const hadQuery = this._state.search !== "";
|
|
558
|
+
this._state.search = "";
|
|
559
|
+
const searchInput = shadow.querySelector(".mobile-search-input");
|
|
560
|
+
if (searchInput) {
|
|
561
|
+
searchInput.value = "";
|
|
562
|
+
}
|
|
563
|
+
if (this._externalSearch) {
|
|
564
|
+
if (hadQuery) {
|
|
565
|
+
if (this._searchDebounceTimer !== null) {
|
|
566
|
+
clearTimeout(this._searchDebounceTimer);
|
|
567
|
+
this._searchDebounceTimer = null;
|
|
568
|
+
}
|
|
569
|
+
this.fireSearchEvent("");
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
const allTags = this.getTagElements();
|
|
574
|
+
allTags.forEach((el) => el.removeAttribute("hidden"));
|
|
575
|
+
}
|
|
576
|
+
this.fireCloseEvent();
|
|
577
|
+
}
|
|
578
|
+
handleStubClick(e) {
|
|
579
|
+
e.preventDefault();
|
|
580
|
+
e.stopPropagation();
|
|
581
|
+
if (this._disabled || this._readonly) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
this.openDropdown();
|
|
585
|
+
}
|
|
586
|
+
handleClearClick(e) {
|
|
587
|
+
e.preventDefault();
|
|
588
|
+
e.stopPropagation();
|
|
589
|
+
if (this._disabled || this._readonly) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
this.clear();
|
|
593
|
+
}
|
|
594
|
+
handleStubKeydown(e) {
|
|
595
|
+
if (this._disabled || this._readonly || this._state.open)
|
|
596
|
+
return;
|
|
597
|
+
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
598
|
+
e.preventDefault();
|
|
599
|
+
this.openDropdown();
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
handleTagClick(e) {
|
|
603
|
+
const target = e.target;
|
|
604
|
+
const tag = target.closest("ty-option, ty-tag");
|
|
605
|
+
if (!tag || tag.hasAttribute("disabled"))
|
|
606
|
+
return;
|
|
607
|
+
e.preventDefault();
|
|
608
|
+
e.stopPropagation();
|
|
609
|
+
this.selectByTag(tag);
|
|
610
|
+
}
|
|
611
|
+
selectByTag(tag) {
|
|
612
|
+
const tagValue = this.getTagData(tag).value;
|
|
613
|
+
const currentValues = this.getSelectedValues();
|
|
614
|
+
if (!this._multiple) {
|
|
615
|
+
this.updateComponentValue([tagValue], true, "set", tagValue);
|
|
616
|
+
if (this._state.mode === "mobile") {
|
|
617
|
+
this.closeMobileModal();
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
this.closeDropdown();
|
|
621
|
+
}
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (currentValues.includes(tagValue)) {
|
|
625
|
+
const newValues = currentValues.filter((v) => v !== tagValue);
|
|
626
|
+
this.updateComponentValue(newValues, true, "remove", tagValue);
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
this.updateComponentValue([...currentValues, tagValue], true, "add", tagValue);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
tryCreateFromSearch() {
|
|
633
|
+
if (!this._allowCreate)
|
|
634
|
+
return false;
|
|
635
|
+
const query = (this._state.search || "").trim();
|
|
636
|
+
if (!query)
|
|
637
|
+
return false;
|
|
638
|
+
const queryLower = query.toLowerCase();
|
|
639
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
640
|
+
const existing = allTags.find((t) => t.value.toLowerCase() === queryLower ||
|
|
641
|
+
t.text.toLowerCase() === queryLower);
|
|
642
|
+
if (existing) {
|
|
643
|
+
this.selectByTag(existing.element);
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
const rawLabel = query;
|
|
647
|
+
const defaultValue = this._createTransform === "slug" ? slugify(rawLabel) : rawLabel;
|
|
648
|
+
if (!defaultValue)
|
|
649
|
+
return true;
|
|
650
|
+
const detail = { value: defaultValue, label: rawLabel };
|
|
651
|
+
const event = new CustomEvent("create", {
|
|
652
|
+
detail,
|
|
653
|
+
bubbles: true,
|
|
654
|
+
composed: true,
|
|
655
|
+
cancelable: true,
|
|
656
|
+
});
|
|
657
|
+
this.dispatchEvent(event);
|
|
658
|
+
if (event.defaultPrevented)
|
|
659
|
+
return true;
|
|
660
|
+
const finalValue = detail.value;
|
|
661
|
+
const option = document.createElement("ty-option");
|
|
662
|
+
option.setAttribute("value", finalValue);
|
|
663
|
+
option.textContent = rawLabel;
|
|
664
|
+
this.appendChild(option);
|
|
665
|
+
if (!this._multiple) {
|
|
666
|
+
this.updateComponentValue([finalValue], true, "create", finalValue);
|
|
667
|
+
if (this._state.mode === "mobile") {
|
|
668
|
+
this.closeMobileModal();
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
this.closeDropdown();
|
|
672
|
+
}
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
const currentValues = this.getSelectedValues();
|
|
676
|
+
this.updateComponentValue([...currentValues, finalValue], true, "create", finalValue);
|
|
677
|
+
this.clearSearchAfterCreate();
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
clearSearchAfterCreate() {
|
|
681
|
+
this._state.search = "";
|
|
682
|
+
this._state.highlightedIndex = -1;
|
|
683
|
+
const shadow = this.shadowRoot;
|
|
684
|
+
if (!shadow)
|
|
685
|
+
return;
|
|
686
|
+
const desktopInput = shadow.querySelector(".dropdown-search-input");
|
|
687
|
+
const mobileInput = shadow.querySelector(".mobile-search-input");
|
|
688
|
+
if (desktopInput)
|
|
689
|
+
desktopInput.value = "";
|
|
690
|
+
if (mobileInput)
|
|
691
|
+
mobileInput.value = "";
|
|
692
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
693
|
+
this._state.filteredTags = allTags;
|
|
694
|
+
this.updateTagVisibility(allTags, allTags);
|
|
695
|
+
this.updateOptionsVisibility(true);
|
|
696
|
+
this.clearHighlights(allTags);
|
|
697
|
+
this.updateMobileSelectedState();
|
|
698
|
+
(desktopInput ?? mobileInput)?.focus();
|
|
699
|
+
}
|
|
700
|
+
blockSearchClick(e) {
|
|
701
|
+
e.stopPropagation();
|
|
702
|
+
e.preventDefault();
|
|
703
|
+
}
|
|
704
|
+
handleSearchInput(e) {
|
|
705
|
+
if (this._state.mode === "mobile")
|
|
706
|
+
this.expandMobileSection("available");
|
|
707
|
+
const target = e.target;
|
|
708
|
+
const query = target.value;
|
|
709
|
+
this._state.search = query;
|
|
710
|
+
if (this._externalSearch) {
|
|
711
|
+
this.dispatchSearchEvent(query);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
715
|
+
const filtered = this.filterTags(allTags, query);
|
|
716
|
+
this._state.filteredTags = filtered;
|
|
717
|
+
this._state.highlightedIndex = -1;
|
|
718
|
+
this.updateTagVisibility(filtered, allTags);
|
|
719
|
+
this.updateOptionsVisibility(filtered.length > 0);
|
|
720
|
+
this.updateMobileSelectedState();
|
|
721
|
+
this.clearHighlights(allTags);
|
|
722
|
+
}
|
|
723
|
+
handleKeyboard(e) {
|
|
724
|
+
if (!this._state.open)
|
|
725
|
+
return;
|
|
726
|
+
const shadow = this.shadowRoot;
|
|
727
|
+
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
728
|
+
const target = e.target;
|
|
729
|
+
const shouldHandle = target === searchInput || document.activeElement !== searchInput;
|
|
730
|
+
if (!shouldHandle)
|
|
731
|
+
return;
|
|
732
|
+
const filteredTags = this._state.filteredTags;
|
|
733
|
+
const tagsCount = filteredTags.length;
|
|
734
|
+
const currentHighlightedIndex = this._state.highlightedIndex;
|
|
735
|
+
switch (e.key) {
|
|
736
|
+
case "Escape":
|
|
737
|
+
e.preventDefault();
|
|
738
|
+
e.stopPropagation();
|
|
739
|
+
if (this._state.mode === "mobile") {
|
|
740
|
+
this.closeMobileModal();
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
this.closeDropdown();
|
|
744
|
+
}
|
|
745
|
+
break;
|
|
746
|
+
case "Enter":
|
|
747
|
+
e.preventDefault();
|
|
748
|
+
e.stopPropagation();
|
|
749
|
+
if (currentHighlightedIndex >= 0 &&
|
|
750
|
+
currentHighlightedIndex < tagsCount) {
|
|
751
|
+
this.selectByTag(filteredTags[currentHighlightedIndex].element);
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
this.tryCreateFromSearch();
|
|
755
|
+
}
|
|
756
|
+
break;
|
|
757
|
+
case "ArrowUp":
|
|
758
|
+
e.preventDefault();
|
|
759
|
+
e.stopPropagation();
|
|
760
|
+
const newIndexUp = this.nextEnabledTagIndex(filteredTags, currentHighlightedIndex, -1);
|
|
761
|
+
this._state.highlightedIndex = newIndexUp;
|
|
762
|
+
this.highlightTag(filteredTags, newIndexUp);
|
|
763
|
+
break;
|
|
764
|
+
case "ArrowDown":
|
|
765
|
+
e.preventDefault();
|
|
766
|
+
e.stopPropagation();
|
|
767
|
+
const newIndexDown = this.nextEnabledTagIndex(filteredTags, currentHighlightedIndex, 1);
|
|
768
|
+
this._state.highlightedIndex = newIndexDown;
|
|
769
|
+
this.highlightTag(filteredTags, newIndexDown);
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
nextEnabledTagIndex(tags, fromIndex, direction) {
|
|
774
|
+
const count = tags.length;
|
|
775
|
+
if (count === 0)
|
|
776
|
+
return -1;
|
|
777
|
+
let index = fromIndex === -1
|
|
778
|
+
? (direction === 1 ? 0 : count - 1)
|
|
779
|
+
: (fromIndex + direction + count) % count;
|
|
780
|
+
for (let i = 0; i < count; i++) {
|
|
781
|
+
if (!tags[index].element.hasAttribute("disabled"))
|
|
782
|
+
return index;
|
|
783
|
+
index = (index + direction + count) % count;
|
|
784
|
+
}
|
|
785
|
+
return -1;
|
|
786
|
+
}
|
|
787
|
+
filterTags(tags, query) {
|
|
788
|
+
if (!query || query.trim() === "") {
|
|
789
|
+
return tags;
|
|
790
|
+
}
|
|
791
|
+
const searchLower = query.toLowerCase();
|
|
792
|
+
return tags.filter(({ text }) => text.toLowerCase().includes(searchLower));
|
|
793
|
+
}
|
|
794
|
+
updateTagVisibility(filteredTags, allTags) {
|
|
795
|
+
const visibleValues = new Set(filteredTags.map((tag) => tag.value));
|
|
796
|
+
allTags.forEach(({ value, element }) => {
|
|
797
|
+
if (visibleValues.has(value)) {
|
|
798
|
+
element.removeAttribute("hidden");
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
element.setAttribute("hidden", "");
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
updateOptionsVisibility(hasOptions) {
|
|
806
|
+
const shadow = this.shadowRoot;
|
|
807
|
+
const options = shadow.querySelector(".dropdown-options");
|
|
808
|
+
if (options) {
|
|
809
|
+
options.style.display = hasOptions ? "" : "none";
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
clearHighlights(tags) {
|
|
813
|
+
tags.forEach(({ element }) => {
|
|
814
|
+
element.removeAttribute("highlighted");
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
highlightTag(tags, index) {
|
|
818
|
+
this.clearHighlights(tags);
|
|
819
|
+
if (index >= 0 && index < tags.length) {
|
|
820
|
+
const { element } = tags[index];
|
|
821
|
+
element.setAttribute("highlighted", "");
|
|
822
|
+
element.scrollIntoView({
|
|
823
|
+
behavior: "smooth",
|
|
824
|
+
block: "nearest",
|
|
825
|
+
inline: "nearest",
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
dispatchSearchEvent(query) {
|
|
830
|
+
if (this._searchDebounceTimer !== null) {
|
|
831
|
+
clearTimeout(this._searchDebounceTimer);
|
|
832
|
+
this._searchDebounceTimer = null;
|
|
833
|
+
}
|
|
834
|
+
if (this._debounce > 0) {
|
|
835
|
+
this._searchDebounceTimer = window.setTimeout(() => {
|
|
836
|
+
this.fireSearchEvent(query);
|
|
837
|
+
this._searchDebounceTimer = null;
|
|
838
|
+
}, this._debounce);
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
this.fireSearchEvent(query);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
fireSearchEvent(query) {
|
|
845
|
+
this.dispatchEvent(new CustomEvent("search", {
|
|
846
|
+
detail: {
|
|
847
|
+
query,
|
|
848
|
+
element: this,
|
|
849
|
+
},
|
|
850
|
+
bubbles: true,
|
|
851
|
+
composed: true,
|
|
852
|
+
}));
|
|
853
|
+
}
|
|
854
|
+
fireOpenEvent() {
|
|
855
|
+
this.dispatchEvent(new CustomEvent("open", {
|
|
856
|
+
detail: { mode: this._state.mode, element: this },
|
|
857
|
+
}));
|
|
858
|
+
if (this._externalSearch) {
|
|
859
|
+
this.fireSearchEvent("");
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
fireCloseEvent() {
|
|
863
|
+
this.dispatchEvent(new CustomEvent("close", {
|
|
864
|
+
detail: { mode: this._state.mode, element: this },
|
|
865
|
+
}));
|
|
866
|
+
}
|
|
867
|
+
dispatchChangeEvent(detail) {
|
|
868
|
+
this.dispatchEvent(new CustomEvent("change", {
|
|
869
|
+
detail,
|
|
870
|
+
bubbles: true,
|
|
871
|
+
cancelable: true,
|
|
872
|
+
}));
|
|
873
|
+
}
|
|
874
|
+
render() {
|
|
875
|
+
this._state.mode = isMobileTouch() ? "mobile" : "desktop";
|
|
876
|
+
if (this._state.mode === "mobile") {
|
|
877
|
+
this.renderMobile();
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
this.renderDesktop();
|
|
881
|
+
}
|
|
882
|
+
this.updateSearchVisibility();
|
|
883
|
+
this.applyLoadingState();
|
|
884
|
+
this.updateValidity();
|
|
885
|
+
}
|
|
886
|
+
updateValidity() {
|
|
887
|
+
if (this.disabled) {
|
|
888
|
+
this._internals.setValidity({});
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (this.required && this.getSelectedValues().length === 0) {
|
|
892
|
+
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
893
|
+
this._internals.setValidity({ valueMissing: true }, "Please select a value", stub ?? undefined);
|
|
894
|
+
}
|
|
895
|
+
else {
|
|
896
|
+
this._internals.setValidity({});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
setupTriggerSlot() {
|
|
900
|
+
const shadow = this.shadowRoot;
|
|
901
|
+
const stub = shadow.querySelector(".select-stub");
|
|
902
|
+
const slot = shadow.querySelector('slot[name="trigger"]');
|
|
903
|
+
if (!stub || !slot)
|
|
904
|
+
return;
|
|
905
|
+
const sync = () => {
|
|
906
|
+
const hasTrigger = slot.assignedElements().length > 0;
|
|
907
|
+
stub.classList.toggle("custom-trigger", hasTrigger);
|
|
908
|
+
this.toggleAttribute("has-trigger", hasTrigger);
|
|
909
|
+
};
|
|
910
|
+
slot.addEventListener("slotchange", sync);
|
|
911
|
+
sync();
|
|
912
|
+
}
|
|
913
|
+
setupEventListeners() {
|
|
914
|
+
const shadow = this.shadowRoot;
|
|
915
|
+
const stub = shadow.querySelector(".select-stub");
|
|
916
|
+
const optionsSlot = shadow.querySelector("#options-slot");
|
|
917
|
+
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
918
|
+
if (stub) {
|
|
919
|
+
this._stubClickHandler = this.handleStubClick.bind(this);
|
|
920
|
+
stub.addEventListener("click", this._stubClickHandler);
|
|
921
|
+
stub.addEventListener("keydown", this.handleStubKeydown.bind(this));
|
|
922
|
+
}
|
|
923
|
+
const clearBtn = shadow.querySelector(".select-clear");
|
|
924
|
+
clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
|
|
925
|
+
this.setupTriggerSlot();
|
|
926
|
+
if (optionsSlot) {
|
|
927
|
+
this._tagClickHandler = this.handleTagClick.bind(this);
|
|
928
|
+
optionsSlot.addEventListener("click", this._tagClickHandler);
|
|
929
|
+
}
|
|
930
|
+
if (searchInput) {
|
|
931
|
+
this._searchInputHandler = this.handleSearchInput.bind(this);
|
|
932
|
+
this._blockSearchClick = this.blockSearchClick.bind(this);
|
|
933
|
+
searchInput.addEventListener("input", this._searchInputHandler);
|
|
934
|
+
searchInput.addEventListener("click", this._blockSearchClick);
|
|
935
|
+
}
|
|
936
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
937
|
+
if (dialog) {
|
|
938
|
+
dialog.addEventListener("click", (e) => {
|
|
939
|
+
if (e.target === dialog) {
|
|
940
|
+
this.closeDropdown();
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
945
|
+
document.addEventListener("keydown", this._keyboardHandler);
|
|
946
|
+
}
|
|
947
|
+
buildStubClasses() {
|
|
948
|
+
const classes = [];
|
|
949
|
+
if (this._disabled)
|
|
950
|
+
classes.push("disabled");
|
|
951
|
+
if (this._compact)
|
|
952
|
+
classes.push("compact");
|
|
953
|
+
return classes.join(" ");
|
|
954
|
+
}
|
|
955
|
+
renderDesktop() {
|
|
956
|
+
const shadow = this.shadowRoot;
|
|
957
|
+
if (!shadow.querySelector(".select-container")) {
|
|
958
|
+
const stubClasses = this.buildStubClasses();
|
|
959
|
+
const listboxId = `select-listbox-${getElementHash(this)}`;
|
|
960
|
+
const labelId = `select-label-${getElementHash(this)}`;
|
|
961
|
+
const labelHtml = this._label
|
|
962
|
+
? `
|
|
963
|
+
<label class="ty-field-label" id="${labelId}">
|
|
964
|
+
${this._label}
|
|
965
|
+
${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
|
|
966
|
+
</label>
|
|
967
|
+
`
|
|
968
|
+
: "";
|
|
969
|
+
const searchPlaceholder = "Search...";
|
|
970
|
+
shadow.innerHTML = `
|
|
971
|
+
<div class="select-container dropdown-mode-desktop">
|
|
972
|
+
${labelHtml}
|
|
973
|
+
<div class="dropdown-wrapper">
|
|
974
|
+
<div class="dropdown-stub select-stub ${stubClasses}"
|
|
975
|
+
role="combobox"
|
|
976
|
+
aria-haspopup="listbox"
|
|
977
|
+
aria-expanded="false"
|
|
978
|
+
aria-controls="${listboxId}"
|
|
979
|
+
${this._label ? `aria-labelledby="${labelId}"` : ""}
|
|
980
|
+
tabindex="${this._disabled ? "-1" : "0"}"
|
|
981
|
+
${this._disabled ? 'disabled aria-disabled="true"' : ""}>
|
|
982
|
+
<slot name="trigger">
|
|
983
|
+
<slot name="start"></slot>
|
|
984
|
+
<slot name="selected"></slot>
|
|
985
|
+
<span class="dropdown-placeholder">${this._placeholder}</span>
|
|
986
|
+
<span class="select-count" hidden></span>
|
|
987
|
+
<slot name="end"></slot>
|
|
988
|
+
<button class="select-clear" type="button" aria-label="Clear selection" hidden>
|
|
989
|
+
${CLEAR_ICON_SVG}
|
|
990
|
+
</button>
|
|
991
|
+
<div class="dropdown-chevron">
|
|
992
|
+
${CHEVRON_DOWN_SVG}
|
|
993
|
+
</div>
|
|
994
|
+
</slot>
|
|
995
|
+
</div>
|
|
996
|
+
<dialog class="dropdown-dialog">
|
|
997
|
+
<div class="dropdown-header">
|
|
998
|
+
<div class="dropdown-search-icon" aria-hidden="true">
|
|
999
|
+
${SEARCH_ICON_SVG}
|
|
1000
|
+
</div>
|
|
1001
|
+
<input
|
|
1002
|
+
class="dropdown-search-input"
|
|
1003
|
+
type="text"
|
|
1004
|
+
placeholder="${searchPlaceholder}"
|
|
1005
|
+
${this._disabled ? "disabled" : ""}
|
|
1006
|
+
/>
|
|
1007
|
+
<div class="dropdown-search-chevron">
|
|
1008
|
+
${CHEVRON_DOWN_SVG}
|
|
1009
|
+
</div>
|
|
1010
|
+
</div>
|
|
1011
|
+
<div class="dropdown-options-wrapper">
|
|
1012
|
+
<div class="dropdown-options" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
|
|
1013
|
+
<slot id="options-slot"></slot>
|
|
1014
|
+
</div>
|
|
1015
|
+
<div class="dropdown-loading" aria-hidden="true">
|
|
1016
|
+
<slot name="loading">
|
|
1017
|
+
<span class="dropdown-loading-spinner"></span>
|
|
1018
|
+
<span class="dropdown-loading-text">Searching…</span>
|
|
1019
|
+
</slot>
|
|
1020
|
+
</div>
|
|
1021
|
+
</div>
|
|
1022
|
+
</dialog>
|
|
1023
|
+
</div>
|
|
1024
|
+
</div>
|
|
1025
|
+
`;
|
|
1026
|
+
this.setupEventListeners();
|
|
1027
|
+
}
|
|
1028
|
+
this.updateSelectionDisplay();
|
|
1029
|
+
}
|
|
1030
|
+
renderMobile() {
|
|
1031
|
+
const shadow = this.shadowRoot;
|
|
1032
|
+
if (!shadow.querySelector(".select-container")) {
|
|
1033
|
+
const stubClasses = this.buildStubClasses();
|
|
1034
|
+
const listboxId = `select-listbox-${getElementHash(this)}`;
|
|
1035
|
+
const labelId = `select-label-${getElementHash(this)}`;
|
|
1036
|
+
const labelHtml = this._label
|
|
1037
|
+
? `
|
|
1038
|
+
<label class="ty-field-label" id="${labelId}">
|
|
1039
|
+
${this._label}
|
|
1040
|
+
${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
|
|
1041
|
+
</label>
|
|
1042
|
+
`
|
|
1043
|
+
: "";
|
|
1044
|
+
const closeButtonSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1045
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
1046
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
1047
|
+
</svg>`;
|
|
1048
|
+
const searchPlaceholder = this._label
|
|
1049
|
+
? `Search ${this._label}...`
|
|
1050
|
+
: "Search...";
|
|
1051
|
+
const searchHeaderHtml = `
|
|
1052
|
+
<div class="mobile-search-header">
|
|
1053
|
+
${this._label ? `<span class="mobile-header-label">${this._label}</span>` : ""}
|
|
1054
|
+
<div class="mobile-header-content">
|
|
1055
|
+
<div class="dropdown-search-icon" aria-hidden="true">
|
|
1056
|
+
${SEARCH_ICON_SVG}
|
|
1057
|
+
</div>
|
|
1058
|
+
<input
|
|
1059
|
+
class="mobile-search-input"
|
|
1060
|
+
type="text"
|
|
1061
|
+
placeholder="${searchPlaceholder}"
|
|
1062
|
+
autofocus
|
|
1063
|
+
${this._disabled ? "disabled" : ""}
|
|
1064
|
+
/>
|
|
1065
|
+
<button class="mobile-close-button" type="button" aria-label="Close">
|
|
1066
|
+
${closeButtonSvg}
|
|
1067
|
+
</button>
|
|
1068
|
+
</div>
|
|
1069
|
+
</div>
|
|
1070
|
+
`;
|
|
1071
|
+
shadow.innerHTML = `
|
|
1072
|
+
<div class="select-container dropdown-mode-mobile">
|
|
1073
|
+
${labelHtml}
|
|
1074
|
+
<div class="dropdown-wrapper">
|
|
1075
|
+
<div class="dropdown-stub select-stub ${stubClasses}"
|
|
1076
|
+
role="combobox"
|
|
1077
|
+
aria-haspopup="listbox"
|
|
1078
|
+
aria-expanded="false"
|
|
1079
|
+
aria-controls="${listboxId}"
|
|
1080
|
+
${this._label ? `aria-labelledby="${labelId}"` : ""}
|
|
1081
|
+
tabindex="${this._disabled ? "-1" : "0"}"
|
|
1082
|
+
${this._disabled ? 'disabled aria-disabled="true"' : ""}>
|
|
1083
|
+
<slot name="trigger">
|
|
1084
|
+
<slot name="start"></slot>
|
|
1085
|
+
<slot name="selected"></slot>
|
|
1086
|
+
<span class="dropdown-placeholder">${this._placeholder}</span>
|
|
1087
|
+
<span class="select-count" hidden></span>
|
|
1088
|
+
<slot name="end"></slot>
|
|
1089
|
+
<button class="select-clear" type="button" aria-label="Clear selection" hidden>
|
|
1090
|
+
${CLEAR_ICON_SVG}
|
|
1091
|
+
</button>
|
|
1092
|
+
<div class="dropdown-chevron">
|
|
1093
|
+
${CHEVRON_DOWN_SVG}
|
|
1094
|
+
</div>
|
|
1095
|
+
</slot>
|
|
1096
|
+
</div>
|
|
1097
|
+
<dialog class="mobile-dialog">
|
|
1098
|
+
<div class="mobile-dialog-content">
|
|
1099
|
+
<!-- HEADER (matches dropdown.ts) -->
|
|
1100
|
+
${searchHeaderHtml}
|
|
1101
|
+
<!-- BODY: options list with toggleable selected state -->
|
|
1102
|
+
<div class="mobile-body" data-expanded="available">
|
|
1103
|
+
<!-- SELECTED STRIP (pinned above the list, collapses when empty) -->
|
|
1104
|
+
<div class="mobile-selected-section" data-empty="true">
|
|
1105
|
+
<button class="section-header" type="button" data-section="selected" aria-expanded="false">
|
|
1106
|
+
<span class="section-title">${this._selectedLabel} <span class="section-count">(0)</span></span>
|
|
1107
|
+
${CHEVRON_DOWN_SVG}
|
|
1108
|
+
</button>
|
|
1109
|
+
<div class="section-content mobile-selected-chips"></div>
|
|
1110
|
+
</div>
|
|
1111
|
+
<!-- AVAILABLE LIST (always visible, takes remaining space) -->
|
|
1112
|
+
<div class="mobile-available-section" data-empty="false">
|
|
1113
|
+
<button class="section-header" type="button" data-section="available" aria-expanded="true">
|
|
1114
|
+
<span class="section-title">${this._availableLabel}</span>
|
|
1115
|
+
${CHEVRON_DOWN_SVG}
|
|
1116
|
+
</button>
|
|
1117
|
+
<div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
|
|
1118
|
+
<slot id="options-slot"></slot>
|
|
1119
|
+
<div class="empty-state">${this._noOptionsMessage}</div>
|
|
1120
|
+
<div class="dropdown-loading" aria-hidden="true">
|
|
1121
|
+
<slot name="loading">
|
|
1122
|
+
<span class="dropdown-loading-spinner"></span>
|
|
1123
|
+
<span class="dropdown-loading-text">Searching…</span>
|
|
1124
|
+
</slot>
|
|
1125
|
+
</div>
|
|
1126
|
+
</div>
|
|
1127
|
+
</div>
|
|
1128
|
+
</div>
|
|
1129
|
+
</div>
|
|
1130
|
+
</dialog>
|
|
1131
|
+
</div>
|
|
1132
|
+
</div>
|
|
1133
|
+
`;
|
|
1134
|
+
this.setupMobileEventListeners();
|
|
1135
|
+
}
|
|
1136
|
+
this.updateSelectionDisplay();
|
|
1137
|
+
}
|
|
1138
|
+
setupMobileEventListeners() {
|
|
1139
|
+
if (!this._keyboardHandler) {
|
|
1140
|
+
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
1141
|
+
document.addEventListener("keydown", this._keyboardHandler);
|
|
1142
|
+
}
|
|
1143
|
+
const shadow = this.shadowRoot;
|
|
1144
|
+
const stub = shadow.querySelector(".select-stub");
|
|
1145
|
+
const optionsSlot = shadow.querySelector("#options-slot");
|
|
1146
|
+
const searchInput = shadow.querySelector(".mobile-search-input");
|
|
1147
|
+
const closeButton = shadow.querySelector(".mobile-close-button");
|
|
1148
|
+
const dialog = shadow.querySelector(".mobile-dialog");
|
|
1149
|
+
if (stub) {
|
|
1150
|
+
stub.addEventListener("click", (e) => this.handleMobileStubClick(e));
|
|
1151
|
+
stub.addEventListener("keydown", (e) => this.handleMobileStubKeydown(e));
|
|
1152
|
+
}
|
|
1153
|
+
const clearBtn = shadow.querySelector(".select-clear");
|
|
1154
|
+
clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
|
|
1155
|
+
this.setupTriggerSlot();
|
|
1156
|
+
if (optionsSlot) {
|
|
1157
|
+
optionsSlot.addEventListener("click", (e) => this.handleMobileTagClick(e));
|
|
1158
|
+
}
|
|
1159
|
+
if (searchInput) {
|
|
1160
|
+
searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
|
|
1161
|
+
}
|
|
1162
|
+
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
1163
|
+
header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
|
|
1164
|
+
});
|
|
1165
|
+
if (closeButton) {
|
|
1166
|
+
closeButton.addEventListener("click", () => this.closeMobileModal());
|
|
1167
|
+
}
|
|
1168
|
+
if (dialog) {
|
|
1169
|
+
dialog.addEventListener("click", (e) => {
|
|
1170
|
+
if (e.target === dialog) {
|
|
1171
|
+
this.closeMobileModal();
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
dialog.addEventListener("cancel", (e) => {
|
|
1175
|
+
e.preventDefault();
|
|
1176
|
+
this.closeMobileModal();
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
handleMobileStubClick(e) {
|
|
1181
|
+
e.preventDefault();
|
|
1182
|
+
e.stopPropagation();
|
|
1183
|
+
if (this._disabled || this._readonly) {
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
this.openMobileModal();
|
|
1187
|
+
}
|
|
1188
|
+
handleMobileStubKeydown(e) {
|
|
1189
|
+
if (this._disabled || this._readonly || this._state.open)
|
|
1190
|
+
return;
|
|
1191
|
+
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
1192
|
+
e.preventDefault();
|
|
1193
|
+
this.openMobileModal();
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
handleMobileTagClick(e) {
|
|
1197
|
+
this.handleTagClick(e);
|
|
1198
|
+
}
|
|
1199
|
+
updateMobileSelectedState() {
|
|
1200
|
+
if (this._state.mode !== "mobile")
|
|
1201
|
+
return;
|
|
1202
|
+
const shadow = this.shadowRoot;
|
|
1203
|
+
this.renderMobileSelectedChips();
|
|
1204
|
+
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1205
|
+
if (availableSection) {
|
|
1206
|
+
const visibleAvailable = this.getTagElements().filter((tag) => !tag.hasAttribute("hidden") && !tag.hasAttribute("selected")).length;
|
|
1207
|
+
availableSection.setAttribute("data-empty", String(visibleAvailable === 0));
|
|
1208
|
+
const availableTitleSpan = shadow.querySelector(".mobile-available-section .section-title");
|
|
1209
|
+
if (availableTitleSpan) {
|
|
1210
|
+
availableTitleSpan.textContent = `${this._availableLabel} (${visibleAvailable})`;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
expandMobileSection(section) {
|
|
1215
|
+
const shadow = this.shadowRoot;
|
|
1216
|
+
const body = shadow?.querySelector(".mobile-body");
|
|
1217
|
+
if (!body)
|
|
1218
|
+
return;
|
|
1219
|
+
if (section === "selected" && this._state.selectedValues.length === 0)
|
|
1220
|
+
return;
|
|
1221
|
+
body.dataset.expanded = section;
|
|
1222
|
+
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
1223
|
+
const owns = header.dataset.section === section;
|
|
1224
|
+
header.setAttribute("aria-expanded", String(owns));
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
renderMobileSelectedChips() {
|
|
1228
|
+
const shadow = this.shadowRoot;
|
|
1229
|
+
const section = shadow.querySelector(".mobile-selected-section");
|
|
1230
|
+
const host = shadow.querySelector(".mobile-selected-chips");
|
|
1231
|
+
if (!section || !host)
|
|
1232
|
+
return;
|
|
1233
|
+
const selected = this._state.selectedValues;
|
|
1234
|
+
section.setAttribute("data-empty", String(selected.length === 0));
|
|
1235
|
+
const count = section.querySelector(".section-count");
|
|
1236
|
+
if (count)
|
|
1237
|
+
count.textContent = `(${selected.length})`;
|
|
1238
|
+
if (selected.length === 0)
|
|
1239
|
+
this.expandMobileSection("available");
|
|
1240
|
+
const labelFor = (value) => {
|
|
1241
|
+
const option = this.getTagElements().find((tag) => this.getTagData(tag).value === value);
|
|
1242
|
+
return option ? this.getTagData(option).text : value;
|
|
1243
|
+
};
|
|
1244
|
+
host.textContent = "";
|
|
1245
|
+
for (const value of selected) {
|
|
1246
|
+
const chip = document.createElement("button");
|
|
1247
|
+
chip.type = "button";
|
|
1248
|
+
chip.className = "mobile-selected-chip";
|
|
1249
|
+
chip.dataset.value = value;
|
|
1250
|
+
chip.setAttribute("aria-label", `Remove ${labelFor(value)}`);
|
|
1251
|
+
chip.innerHTML = `<span class="chip-label"></span>${CLEAR_ICON_SVG}`;
|
|
1252
|
+
chip.querySelector(".chip-label").textContent = labelFor(value);
|
|
1253
|
+
chip.addEventListener("click", (e) => {
|
|
1254
|
+
e.preventDefault();
|
|
1255
|
+
e.stopPropagation();
|
|
1256
|
+
this.deselectValue(value);
|
|
1257
|
+
});
|
|
1258
|
+
host.appendChild(chip);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
shouldShowSearch() {
|
|
1262
|
+
if (this._externalSearch)
|
|
1263
|
+
return true;
|
|
1264
|
+
if (this._allowCreate)
|
|
1265
|
+
return true;
|
|
1266
|
+
if (this._notSearchable)
|
|
1267
|
+
return false;
|
|
1268
|
+
return this.getTagElements().length > SEARCH_AUTO_THRESHOLD;
|
|
1269
|
+
}
|
|
1270
|
+
updateSearchVisibility() {
|
|
1271
|
+
const shadow = this.shadowRoot;
|
|
1272
|
+
if (!shadow)
|
|
1273
|
+
return;
|
|
1274
|
+
const show = this.shouldShowSearch();
|
|
1275
|
+
const header = shadow.querySelector(".dropdown-header");
|
|
1276
|
+
if (header)
|
|
1277
|
+
header.hidden = !show;
|
|
1278
|
+
const mobileInput = shadow.querySelector(".mobile-search-input");
|
|
1279
|
+
if (mobileInput)
|
|
1280
|
+
mobileInput.hidden = !show;
|
|
1281
|
+
const mobileIcon = shadow.querySelector(".mobile-header-content .dropdown-search-icon");
|
|
1282
|
+
if (mobileIcon)
|
|
1283
|
+
mobileIcon.hidden = !show;
|
|
1284
|
+
}
|
|
1285
|
+
updateSelectionDisplay() {
|
|
1286
|
+
const shadow = this.shadowRoot;
|
|
1287
|
+
const stub = shadow.querySelector(".select-stub");
|
|
1288
|
+
if (!stub)
|
|
1289
|
+
return;
|
|
1290
|
+
const values = this._state.selectedValues;
|
|
1291
|
+
const count = values.length;
|
|
1292
|
+
stub.classList.toggle("has-selection", count > 0);
|
|
1293
|
+
stub.classList.toggle("compact", this._compact);
|
|
1294
|
+
const badge = stub.querySelector(".select-count");
|
|
1295
|
+
if (badge) {
|
|
1296
|
+
badge.textContent = String(count);
|
|
1297
|
+
badge.hidden = count === 0 || !this._multiple || !this._compact;
|
|
1298
|
+
}
|
|
1299
|
+
const clearBtn = stub.querySelector(".select-clear");
|
|
1300
|
+
if (clearBtn) {
|
|
1301
|
+
clearBtn.hidden = !(count > 0 && this._clearable && !this._disabled && !this._readonly);
|
|
1302
|
+
}
|
|
1303
|
+
const wantClone = !this._multiple && count > 0 ? values[0] : null;
|
|
1304
|
+
this.syncSelectedClone(wantClone);
|
|
1305
|
+
const hasClone = this._selectedClone !== null;
|
|
1306
|
+
stub.classList.toggle("has-clone", hasClone);
|
|
1307
|
+
const textEl = stub.querySelector(".dropdown-placeholder");
|
|
1308
|
+
if (textEl) {
|
|
1309
|
+
textEl.hidden = hasClone;
|
|
1310
|
+
const showLabels = count > 0 && this._multiple && !this._compact;
|
|
1311
|
+
if (showLabels) {
|
|
1312
|
+
textEl.textContent = this.getSelectedItems(values)
|
|
1313
|
+
.map((i) => i.label)
|
|
1314
|
+
.join(", ");
|
|
1315
|
+
textEl.classList.remove("placeholder-shown");
|
|
1316
|
+
}
|
|
1317
|
+
else if (wantClone !== null) {
|
|
1318
|
+
textEl.textContent = values.join(", ");
|
|
1319
|
+
textEl.classList.remove("placeholder-shown");
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
textEl.textContent = this._placeholder;
|
|
1323
|
+
textEl.classList.add("placeholder-shown");
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
syncSelectedClone(value) {
|
|
1328
|
+
const existing = this.querySelector(':scope > [cloned][slot="selected"]');
|
|
1329
|
+
if (existing?.getAttribute("value") === value) {
|
|
1330
|
+
const stale = value !== null &&
|
|
1331
|
+
existing.childNodes.length === 0 &&
|
|
1332
|
+
(this.getTagElements().find((el) => this.getTagData(el).value === value)?.childNodes.length ?? 0) > 0;
|
|
1333
|
+
if (!stale) {
|
|
1334
|
+
this._selectedClone = existing;
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
existing?.remove();
|
|
1339
|
+
if (value === null) {
|
|
1340
|
+
this._selectedClone = null;
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
const option = this.getTagElements().find((el) => this.getTagData(el).value === value);
|
|
1344
|
+
if (option) {
|
|
1345
|
+
const clone = option.cloneNode(true);
|
|
1346
|
+
clone.removeAttribute("selected");
|
|
1347
|
+
clone.setAttribute("slot", "selected");
|
|
1348
|
+
clone.setAttribute("cloned", "true");
|
|
1349
|
+
this.appendChild(clone);
|
|
1350
|
+
this._selectedClone = clone;
|
|
1351
|
+
if (option.childNodes.length === 0 && document.readyState === "loading") {
|
|
1352
|
+
document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
|
|
1353
|
+
this.updateSelectionDisplay(); }, { once: true });
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
else if (this._selectedClone?.getAttribute("value") === value) {
|
|
1357
|
+
const restored = this._selectedClone.cloneNode(true);
|
|
1358
|
+
this.appendChild(restored);
|
|
1359
|
+
this._selectedClone = restored;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
deselectValue(value) {
|
|
1363
|
+
const current = this.getSelectedValues();
|
|
1364
|
+
if (!current.includes(value))
|
|
1365
|
+
return;
|
|
1366
|
+
this.updateComponentValue(current.filter((v) => v !== value), true, "remove", value);
|
|
1367
|
+
}
|
|
1368
|
+
clear() {
|
|
1369
|
+
this.updateComponentValue([], true, "clear", null);
|
|
1370
|
+
}
|
|
1371
|
+
get value() {
|
|
1372
|
+
return this.getSelectedValues().join(",");
|
|
1373
|
+
}
|
|
1374
|
+
set value(val) {
|
|
1375
|
+
this.setProperty("value", val);
|
|
1376
|
+
}
|
|
1377
|
+
get name() {
|
|
1378
|
+
return this.getProperty("name");
|
|
1379
|
+
}
|
|
1380
|
+
set name(val) {
|
|
1381
|
+
this.setProperty("name", val);
|
|
1382
|
+
}
|
|
1383
|
+
get multiple() {
|
|
1384
|
+
return this.getProperty("multiple");
|
|
1385
|
+
}
|
|
1386
|
+
set multiple(value) {
|
|
1387
|
+
this.setProperty("multiple", value);
|
|
1388
|
+
}
|
|
1389
|
+
get compact() {
|
|
1390
|
+
return this.getProperty("compact");
|
|
1391
|
+
}
|
|
1392
|
+
set compact(value) {
|
|
1393
|
+
this.setProperty("compact", value);
|
|
1394
|
+
}
|
|
1395
|
+
get placeholder() {
|
|
1396
|
+
return this.getProperty("placeholder");
|
|
1397
|
+
}
|
|
1398
|
+
set placeholder(val) {
|
|
1399
|
+
this.setProperty("placeholder", val);
|
|
1400
|
+
}
|
|
1401
|
+
get label() {
|
|
1402
|
+
return this.getProperty("label");
|
|
1403
|
+
}
|
|
1404
|
+
set label(val) {
|
|
1405
|
+
this.setProperty("label", val);
|
|
1406
|
+
}
|
|
1407
|
+
get disabled() {
|
|
1408
|
+
return this.getProperty("disabled");
|
|
1409
|
+
}
|
|
1410
|
+
set disabled(value) {
|
|
1411
|
+
this.setProperty("disabled", value);
|
|
1412
|
+
}
|
|
1413
|
+
get loading() {
|
|
1414
|
+
return this.getProperty("loading");
|
|
1415
|
+
}
|
|
1416
|
+
set loading(value) {
|
|
1417
|
+
this.setProperty("loading", value);
|
|
1418
|
+
}
|
|
1419
|
+
get readonly() {
|
|
1420
|
+
return this.getProperty("readonly");
|
|
1421
|
+
}
|
|
1422
|
+
set readonly(value) {
|
|
1423
|
+
this.setProperty("readonly", value);
|
|
1424
|
+
}
|
|
1425
|
+
get clearable() {
|
|
1426
|
+
return this.getProperty("clearable");
|
|
1427
|
+
}
|
|
1428
|
+
set clearable(value) {
|
|
1429
|
+
this.setProperty("clearable", value);
|
|
1430
|
+
}
|
|
1431
|
+
get required() {
|
|
1432
|
+
return this.getProperty("required");
|
|
1433
|
+
}
|
|
1434
|
+
set required(value) {
|
|
1435
|
+
this.setProperty("required", value);
|
|
1436
|
+
}
|
|
1437
|
+
get notSearchable() {
|
|
1438
|
+
return this.getProperty("notSearchable");
|
|
1439
|
+
}
|
|
1440
|
+
set notSearchable(value) {
|
|
1441
|
+
this.setProperty("notSearchable", value);
|
|
1442
|
+
}
|
|
1443
|
+
get externalSearch() {
|
|
1444
|
+
return this.getProperty("externalSearch");
|
|
1445
|
+
}
|
|
1446
|
+
set externalSearch(value) {
|
|
1447
|
+
this.setProperty("externalSearch", value);
|
|
1448
|
+
}
|
|
1449
|
+
get debounce() {
|
|
1450
|
+
return this.getProperty("debounce");
|
|
1451
|
+
}
|
|
1452
|
+
set debounce(value) {
|
|
1453
|
+
const numValue = typeof value === "string" ? parseInt(value, 10) : value;
|
|
1454
|
+
this.setProperty("debounce", numValue);
|
|
1455
|
+
}
|
|
1456
|
+
get size() {
|
|
1457
|
+
return this.getProperty("size");
|
|
1458
|
+
}
|
|
1459
|
+
set size(value) {
|
|
1460
|
+
this.setProperty("size", value);
|
|
1461
|
+
}
|
|
1462
|
+
get align() {
|
|
1463
|
+
return this.getProperty("align");
|
|
1464
|
+
}
|
|
1465
|
+
set align(value) {
|
|
1466
|
+
this.setProperty("align", value);
|
|
1467
|
+
}
|
|
1468
|
+
get placement() {
|
|
1469
|
+
return this.getProperty("placement");
|
|
1470
|
+
}
|
|
1471
|
+
set placement(value) {
|
|
1472
|
+
this.setProperty("placement", value);
|
|
1473
|
+
}
|
|
1474
|
+
get flavor() {
|
|
1475
|
+
return this.getProperty("flavor");
|
|
1476
|
+
}
|
|
1477
|
+
set flavor(value) {
|
|
1478
|
+
this.setProperty("flavor", value);
|
|
1479
|
+
}
|
|
1480
|
+
get form() {
|
|
1481
|
+
return this._internals.form;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1935
1484
|
TySelect.properties = {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
if (isNaN(num))
|
|
2083
|
-
return 0;
|
|
2084
|
-
return Math.max(0, Math.min(5000, num));
|
|
2085
|
-
},
|
|
2086
|
-
},
|
|
2087
|
-
"available-label": {
|
|
2088
|
-
type: "string",
|
|
2089
|
-
visual: true,
|
|
2090
|
-
default: "Available",
|
|
2091
|
-
},
|
|
2092
|
-
"no-options-message": {
|
|
2093
|
-
type: "string",
|
|
2094
|
-
visual: true,
|
|
2095
|
-
default: "No options available",
|
|
2096
|
-
},
|
|
2097
|
-
loading: {
|
|
2098
|
-
type: "boolean",
|
|
2099
|
-
visual: true,
|
|
2100
|
-
default: false,
|
|
2101
|
-
},
|
|
2102
|
-
// Any string is accepted: built-ins get static CSS, other identifiers
|
|
2103
|
-
// become custom flavors (see _syncCustomFlavor), garbage degrades to
|
|
2104
|
-
// the default look.
|
|
2105
|
-
flavor: {
|
|
2106
|
-
type: "string",
|
|
2107
|
-
visual: true,
|
|
2108
|
-
default: "neutral",
|
|
2109
|
-
},
|
|
1485
|
+
value: {
|
|
1486
|
+
type: "string",
|
|
1487
|
+
visual: true,
|
|
1488
|
+
formValue: true,
|
|
1489
|
+
emitChange: false,
|
|
1490
|
+
default: "",
|
|
1491
|
+
coerce: (v) => {
|
|
1492
|
+
if (Array.isArray(v)) {
|
|
1493
|
+
return v.join(",");
|
|
1494
|
+
}
|
|
1495
|
+
if (v === null || v === undefined) {
|
|
1496
|
+
return "";
|
|
1497
|
+
}
|
|
1498
|
+
return String(v);
|
|
1499
|
+
},
|
|
1500
|
+
},
|
|
1501
|
+
name: {
|
|
1502
|
+
type: "string",
|
|
1503
|
+
default: "",
|
|
1504
|
+
},
|
|
1505
|
+
multiple: {
|
|
1506
|
+
type: "boolean",
|
|
1507
|
+
visual: true,
|
|
1508
|
+
default: false,
|
|
1509
|
+
},
|
|
1510
|
+
compact: {
|
|
1511
|
+
type: "boolean",
|
|
1512
|
+
visual: true,
|
|
1513
|
+
default: false,
|
|
1514
|
+
},
|
|
1515
|
+
placeholder: {
|
|
1516
|
+
type: "string",
|
|
1517
|
+
visual: true,
|
|
1518
|
+
default: "Select...",
|
|
1519
|
+
},
|
|
1520
|
+
label: {
|
|
1521
|
+
type: "string",
|
|
1522
|
+
visual: true,
|
|
1523
|
+
default: "",
|
|
1524
|
+
},
|
|
1525
|
+
disabled: {
|
|
1526
|
+
type: "boolean",
|
|
1527
|
+
visual: true,
|
|
1528
|
+
default: false,
|
|
1529
|
+
},
|
|
1530
|
+
readonly: {
|
|
1531
|
+
type: "boolean",
|
|
1532
|
+
visual: true,
|
|
1533
|
+
default: false,
|
|
1534
|
+
},
|
|
1535
|
+
required: {
|
|
1536
|
+
type: "boolean",
|
|
1537
|
+
visual: true,
|
|
1538
|
+
default: false,
|
|
1539
|
+
},
|
|
1540
|
+
clearable: {
|
|
1541
|
+
type: "boolean",
|
|
1542
|
+
visual: true,
|
|
1543
|
+
default: true,
|
|
1544
|
+
aliases: { "not-clearable": false },
|
|
1545
|
+
},
|
|
1546
|
+
externalSearch: {
|
|
1547
|
+
type: "boolean",
|
|
1548
|
+
visual: true,
|
|
1549
|
+
default: false,
|
|
1550
|
+
aliases: { "external-search": true },
|
|
1551
|
+
},
|
|
1552
|
+
allowCreate: {
|
|
1553
|
+
type: "boolean",
|
|
1554
|
+
visual: true,
|
|
1555
|
+
default: false,
|
|
1556
|
+
aliases: { "allow-create": true },
|
|
1557
|
+
},
|
|
1558
|
+
createTransform: {
|
|
1559
|
+
type: "string",
|
|
1560
|
+
visual: false,
|
|
1561
|
+
default: "none",
|
|
1562
|
+
aliases: { "create-transform": true },
|
|
1563
|
+
coerce: (v) => (v === "slug" ? "slug" : "none"),
|
|
1564
|
+
},
|
|
1565
|
+
notSearchable: {
|
|
1566
|
+
type: "boolean",
|
|
1567
|
+
visual: true,
|
|
1568
|
+
default: false,
|
|
1569
|
+
},
|
|
1570
|
+
align: {
|
|
1571
|
+
type: "string",
|
|
1572
|
+
visual: true,
|
|
1573
|
+
default: "start",
|
|
1574
|
+
validate: (v) => ["start", "center", "end"].includes(v),
|
|
1575
|
+
coerce: (v) => v === "end" ? "end" : v === "center" ? "center" : "start",
|
|
1576
|
+
},
|
|
1577
|
+
placement: {
|
|
1578
|
+
type: "string",
|
|
1579
|
+
visual: true,
|
|
1580
|
+
default: "",
|
|
1581
|
+
},
|
|
1582
|
+
size: {
|
|
1583
|
+
type: "string",
|
|
1584
|
+
visual: true,
|
|
1585
|
+
default: DEFAULT_SIZE,
|
|
1586
|
+
validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
|
|
1587
|
+
coerce: (v) => {
|
|
1588
|
+
if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
|
|
1589
|
+
console.warn(`[ty-select] Invalid size. Using ${DEFAULT_SIZE}.`);
|
|
1590
|
+
return DEFAULT_SIZE;
|
|
1591
|
+
}
|
|
1592
|
+
return v;
|
|
1593
|
+
},
|
|
1594
|
+
},
|
|
1595
|
+
debounce: {
|
|
1596
|
+
type: "number",
|
|
1597
|
+
default: 0,
|
|
1598
|
+
validate: (v) => v >= 0 && v <= 5000,
|
|
1599
|
+
coerce: (v) => {
|
|
1600
|
+
const num = Number(v);
|
|
1601
|
+
if (isNaN(num))
|
|
1602
|
+
return 0;
|
|
1603
|
+
return Math.max(0, Math.min(5000, num));
|
|
1604
|
+
},
|
|
1605
|
+
},
|
|
1606
|
+
"available-label": {
|
|
1607
|
+
type: "string",
|
|
1608
|
+
visual: true,
|
|
1609
|
+
default: "Available",
|
|
1610
|
+
},
|
|
1611
|
+
"selected-label": {
|
|
1612
|
+
type: "string",
|
|
1613
|
+
visual: true,
|
|
1614
|
+
default: "Selected",
|
|
1615
|
+
},
|
|
1616
|
+
"no-options-message": {
|
|
1617
|
+
type: "string",
|
|
1618
|
+
visual: true,
|
|
1619
|
+
default: "No options available",
|
|
1620
|
+
},
|
|
1621
|
+
loading: {
|
|
1622
|
+
type: "boolean",
|
|
1623
|
+
visual: true,
|
|
1624
|
+
default: false,
|
|
1625
|
+
},
|
|
1626
|
+
flavor: {
|
|
1627
|
+
type: "string",
|
|
1628
|
+
visual: true,
|
|
1629
|
+
default: "neutral",
|
|
1630
|
+
},
|
|
2110
1631
|
};
|
|
2111
|
-
// Register the custom element
|
|
2112
1632
|
if (!customElements.get("ty-select")) {
|
|
2113
|
-
|
|
1633
|
+
customElements.define("ty-select", TySelect);
|
|
2114
1634
|
}
|
|
2115
|
-
//# sourceMappingURL=select.js.map
|