tyrell-components 1.0.0-TC9 → 1.0.0-rc.22
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/AGENTS.md +122 -0
- package/CHANGELOG.md +1541 -0
- package/README.md +71 -53
- package/bin/tyrell.mjs +77 -0
- package/css/tyrell-colors-static.css +1 -0
- package/css/tyrell-theme.css +1 -0
- package/css/tyrell.css +1 -1783
- package/dist/tyrell-colors-static.css +1 -0
- package/dist/tyrell-theme.css +1 -0
- package/dist/tyrell.css +1 -1783
- package/dist/tyrell.js +1 -1
- package/guides/AGENT_INSTRUCTIONS.md +124 -0
- package/guides/AI_GUIDE.md +53 -0
- package/guides/CSS_GUIDE.md +1016 -0
- package/guides/DATASTAR_TY_GUIDE.md +657 -0
- package/guides/ICONS_GUIDE.md +212 -0
- package/guides/TY_GUIDE.md +937 -0
- package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
- package/guides/clj/CODE_SPLITTING.md +279 -0
- package/guides/clj/COMPONENT_GUIDE.md +391 -0
- package/guides/clj/HELIX_TY_GUIDE.md +428 -0
- package/guides/clj/I18N_GUIDE.md +478 -0
- package/guides/clj/LAYOUT_GUIDE.md +273 -0
- package/guides/clj/QUICKSTART.md +266 -0
- package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
- package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
- package/guides/clj/ROUTING_GUIDE.md +346 -0
- package/guides/clj/UIX_TY_GUIDE.md +319 -0
- package/guides/js/HTMX_TY_GUIDE.md +252 -0
- package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
- package/guides/js/REACT_TY_GUIDE.md +983 -0
- package/guides/js/SVELTE_TY_GUIDE.md +682 -0
- package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
- package/guides/js/VUE_TY_GUIDE.md +738 -0
- package/lib/base/ty-component.d.ts +57 -13
- package/lib/base/ty-component.js +266 -292
- package/lib/components/button.d.ts +33 -18
- package/lib/components/button.js +317 -267
- package/lib/components/calendar-month.d.ts +30 -47
- package/lib/components/calendar-month.js +455 -429
- package/lib/components/calendar-navigation.d.ts +41 -49
- package/lib/components/calendar-navigation.js +287 -346
- package/lib/components/calendar.d.ts +73 -83
- package/lib/components/calendar.js +837 -762
- package/lib/components/checkbox.d.ts +26 -75
- package/lib/components/checkbox.js +298 -391
- package/lib/components/copy.d.ts +20 -60
- package/lib/components/copy.js +276 -380
- package/lib/components/date-picker.d.ts +100 -183
- package/lib/components/date-picker.js +1155 -1570
- package/lib/components/file-upload.d.ts +16 -15
- package/lib/components/file-upload.js +436 -426
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +93 -108
- package/lib/components/input.js +734 -710
- package/lib/components/modal.d.ts +39 -29
- package/lib/components/modal.js +419 -438
- package/lib/components/option.d.ts +20 -35
- package/lib/components/option.js +184 -309
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +353 -347
- package/lib/components/radio.d.ts +33 -25
- package/lib/components/radio.js +433 -422
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +71 -103
- package/lib/components/scroll-container.d.ts +21 -14
- package/lib/components/scroll-container.js +292 -234
- package/lib/components/select.d.ts +458 -0
- package/lib/components/select.js +1458 -0
- package/lib/components/selected-tags.d.ts +60 -0
- package/lib/components/selected-tags.js +225 -0
- package/lib/components/sortable.d.ts +175 -0
- package/lib/components/sortable.js +1844 -0
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +15 -15
- package/lib/components/switch.js +237 -231
- package/lib/components/tab.d.ts +50 -7
- package/lib/components/tab.js +203 -69
- package/lib/components/tabs.d.ts +19 -64
- package/lib/components/tabs.js +600 -618
- package/lib/components/tag.d.ts +14 -52
- package/lib/components/tag.js +231 -306
- package/lib/components/textarea.d.ts +58 -89
- package/lib/components/textarea.js +523 -573
- package/lib/components/tooltip.d.ts +8 -13
- package/lib/components/tooltip.js +322 -409
- package/lib/components/wizard.d.ts +7 -54
- package/lib/components/wizard.js +376 -606
- 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 +7 -4
- package/lib/index.js +26 -39
- package/lib/styles/button.d.ts +24 -7
- package/lib/styles/button.js +285 -445
- package/lib/styles/calendar-month.d.ts +7 -6
- package/lib/styles/calendar-month.js +158 -226
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +108 -127
- package/lib/styles/calendar.d.ts +3 -3
- package/lib/styles/calendar.js +87 -23
- package/lib/styles/checkbox.d.ts +7 -6
- package/lib/styles/checkbox.js +101 -15
- package/lib/styles/copy.d.ts +3 -2
- package/lib/styles/copy.js +91 -71
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +4 -6
- package/lib/styles/date-picker.js +321 -388
- 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 +4 -7
- package/lib/styles/input.js +148 -643
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +127 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +53 -96
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +47 -77
- package/lib/styles/radio.d.ts +3 -2
- package/lib/styles/radio.js +90 -116
- 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 +103 -146
- package/lib/styles/select-base.d.ts +8 -0
- package/lib/styles/select-base.js +752 -0
- package/lib/styles/select.d.ts +11 -0
- package/lib/styles/select.js +229 -0
- package/lib/styles/sortable.d.ts +16 -0
- package/lib/styles/sortable.js +85 -0
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +15 -34
- package/lib/styles/switch.d.ts +3 -2
- package/lib/styles/switch.js +52 -68
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +86 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +204 -162
- package/lib/styles/tag.d.ts +2 -6
- package/lib/styles/tag.js +168 -362
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +238 -306
- package/lib/styles/tooltip.d.ts +4 -3
- package/lib/styles/tooltip.js +3 -131
- package/lib/styles/wizard.d.ts +8 -20
- package/lib/styles/wizard.js +306 -295
- package/lib/types/common.d.ts +9 -8
- package/lib/types/common.js +8 -5
- package/lib/utils/calendar-utils.d.ts +49 -65
- package/lib/utils/calendar-utils.js +158 -343
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +31 -0
- package/lib/utils/flavor-sheet.js +17 -0
- package/lib/utils/icon-registry.d.ts +0 -15
- package/lib/utils/icon-registry.js +138 -279
- package/lib/utils/icons.d.ts +9 -0
- package/lib/utils/icons.js +1 -0
- package/lib/utils/loader-registry.d.ts +2 -3
- package/lib/utils/loader-registry.js +3 -35
- package/lib/utils/locale.d.ts +2 -80
- package/lib/utils/locale.js +30 -205
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -24
- package/lib/utils/number-format.js +53 -136
- package/lib/utils/positioning.d.ts +72 -22
- package/lib/utils/positioning.js +224 -298
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +6 -6
- package/lib/utils/property-manager.js +127 -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 +10 -11
- package/lib/utils/scroll-lock.js +165 -173
- package/lib/utils/styles.d.ts +0 -6
- package/lib/utils/styles.js +17 -48
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +66 -18
- 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/dropdown.d.ts +0 -404
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1563
- package/lib/components/dropdown.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/multiselect.d.ts +0 -408
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1611
- package/lib/components/multiselect.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/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/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -1048
- package/lib/styles/dropdown.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 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -837
- 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/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/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.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
|
@@ -0,0 +1,1458 @@
|
|
|
1
|
+
import { DEFAULT_SIZE } from "../types/common.js";
|
|
2
|
+
import { ensureStyles } from "../utils/styles.js";
|
|
3
|
+
import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
|
|
4
|
+
import { selectBaseStyles, selectCustomFlavorCss } from "../styles/select-base.js";
|
|
5
|
+
import { selectStyles } from "../styles/select.js";
|
|
6
|
+
import { getLoaderSvg } from "../utils/loader-registry.js";
|
|
7
|
+
import { lockScroll, unlockScroll } from "../utils/scroll-lock.js";
|
|
8
|
+
import { computeAnchoredPosition, placementToAnchored } from "../utils/positioning.js";
|
|
9
|
+
import { isMobileTouch } from "../utils/mobile.js";
|
|
10
|
+
import { TyComponent } from "../base/ty-component.js";
|
|
11
|
+
import { CustomScrollbar, isCustomScrollbarEnabled, } from "../utils/custom-scrollbar.js";
|
|
12
|
+
import { REQUIRED_ICON_SVG } from "../utils/icons.js";
|
|
13
|
+
import { nativeMessage } from "../utils/validity.js";
|
|
14
|
+
let selectCount = 0;
|
|
15
|
+
const SEARCH_AUTO_THRESHOLD = 7;
|
|
16
|
+
const TABBABLE = 'button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
17
|
+
function triggerFocusTarget(trigger) {
|
|
18
|
+
if (trigger.matches(TABBABLE))
|
|
19
|
+
return trigger;
|
|
20
|
+
return (trigger.shadowRoot?.querySelector(TABBABLE) ?? trigger.querySelector(TABBABLE));
|
|
21
|
+
}
|
|
22
|
+
const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
|
|
23
|
+
<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" />
|
|
24
|
+
</svg>`;
|
|
25
|
+
function slugify(text) {
|
|
26
|
+
return text
|
|
27
|
+
.trim()
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/\s+/g, "_")
|
|
30
|
+
.replace(/[^a-z0-9_]/g, "")
|
|
31
|
+
.replace(/_+/g, "_")
|
|
32
|
+
.replace(/^_|_$/g, "");
|
|
33
|
+
}
|
|
34
|
+
const SEARCH_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
35
|
+
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
|
|
36
|
+
</svg>`;
|
|
37
|
+
const CLEAR_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
38
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
39
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
40
|
+
</svg>`;
|
|
41
|
+
function assign(slot, nodes) {
|
|
42
|
+
if (!slot)
|
|
43
|
+
return;
|
|
44
|
+
const current = slot.assignedNodes();
|
|
45
|
+
if (current.length === nodes.length && nodes.every((n, i) => current[i] === n))
|
|
46
|
+
return;
|
|
47
|
+
slot.assign(...nodes);
|
|
48
|
+
}
|
|
49
|
+
const NAMED_SLOTS = ["trigger", "start", "end", "loading"];
|
|
50
|
+
function isMarked(el) {
|
|
51
|
+
const attr = el.getAttribute("selected");
|
|
52
|
+
return attr !== null && !/^(false|0)$/i.test(attr.trim());
|
|
53
|
+
}
|
|
54
|
+
export class TySelect extends TyComponent {
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
this._uid = ++selectCount;
|
|
58
|
+
this._state = {
|
|
59
|
+
open: false,
|
|
60
|
+
search: "",
|
|
61
|
+
highlightedIndex: -1,
|
|
62
|
+
filteredTags: [],
|
|
63
|
+
mode: "desktop",
|
|
64
|
+
};
|
|
65
|
+
this._scrollLockId = null;
|
|
66
|
+
this._keyboardHandler = null;
|
|
67
|
+
this._searchDebounceTimer = null;
|
|
68
|
+
this._optionsScrollbar = null;
|
|
69
|
+
this._childObserver = null;
|
|
70
|
+
this._customFlavorSheet = null;
|
|
71
|
+
this._ariaTrigger = null;
|
|
72
|
+
this._ariaObserver = null;
|
|
73
|
+
this._triggerTextObserver = null;
|
|
74
|
+
const shadow = this.shadowRoot;
|
|
75
|
+
ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
|
|
76
|
+
ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
|
|
77
|
+
}
|
|
78
|
+
onConnect() {
|
|
79
|
+
this._childObserver = new MutationObserver((records) => {
|
|
80
|
+
if (records.some((r) => r.target !== this || r.type !== "attributes" || r.attributeName === "has-trigger")) {
|
|
81
|
+
this.render();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this._childObserver.observe(this, {
|
|
85
|
+
childList: true,
|
|
86
|
+
subtree: true,
|
|
87
|
+
characterData: true,
|
|
88
|
+
attributes: true,
|
|
89
|
+
attributeFilter: ["value", "label", "selected", "hidden", "filtered-out", "has-trigger"],
|
|
90
|
+
});
|
|
91
|
+
this._syncCustomFlavor();
|
|
92
|
+
if (!this._keyboardHandler) {
|
|
93
|
+
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
94
|
+
document.addEventListener("keydown", this._keyboardHandler, true);
|
|
95
|
+
}
|
|
96
|
+
if (this._rendered)
|
|
97
|
+
this.render();
|
|
98
|
+
}
|
|
99
|
+
_syncCustomFlavor() {
|
|
100
|
+
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getProperty("flavor"), ({ base }) => selectCustomFlavorCss(base));
|
|
101
|
+
}
|
|
102
|
+
onDisconnect() {
|
|
103
|
+
if (this._state.open)
|
|
104
|
+
this.close();
|
|
105
|
+
if (this._keyboardHandler) {
|
|
106
|
+
document.removeEventListener("keydown", this._keyboardHandler, true);
|
|
107
|
+
this._keyboardHandler = null;
|
|
108
|
+
}
|
|
109
|
+
if (this._searchDebounceTimer !== null) {
|
|
110
|
+
clearTimeout(this._searchDebounceTimer);
|
|
111
|
+
this._searchDebounceTimer = null;
|
|
112
|
+
}
|
|
113
|
+
this._destroyOptionsScrollbar();
|
|
114
|
+
this._childObserver?.disconnect();
|
|
115
|
+
this._childObserver = null;
|
|
116
|
+
}
|
|
117
|
+
onPropertiesChanged(changes) {
|
|
118
|
+
for (const { name, newValue } of changes) {
|
|
119
|
+
switch (name) {
|
|
120
|
+
case "flavor":
|
|
121
|
+
this._syncCustomFlavor();
|
|
122
|
+
break;
|
|
123
|
+
case "multiple": {
|
|
124
|
+
const values = this.getSelectedValues();
|
|
125
|
+
if (!newValue && values.length > 1) {
|
|
126
|
+
this.updateComponentValue([values[0]]);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
applyLoadingState() {
|
|
134
|
+
const loading = this.getProperty("loading");
|
|
135
|
+
const svg = loading ? getLoaderSvg() : null;
|
|
136
|
+
this.shadowRoot.querySelectorAll(".dropdown-options-wrapper").forEach((wrapper) => {
|
|
137
|
+
wrapper.classList.toggle("loading", loading);
|
|
138
|
+
if (loading) {
|
|
139
|
+
wrapper.setAttribute("aria-busy", "true");
|
|
140
|
+
const spinner = wrapper.querySelector(".dropdown-loading-spinner");
|
|
141
|
+
if (spinner && svg)
|
|
142
|
+
spinner.innerHTML = svg;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
wrapper.removeAttribute("aria-busy");
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getFormValue() {
|
|
150
|
+
const name = this.name;
|
|
151
|
+
if (!name || this.externalSelection)
|
|
152
|
+
return null;
|
|
153
|
+
const selectedValues = this.getSelectedValues();
|
|
154
|
+
if (!this.multiple) {
|
|
155
|
+
return selectedValues[0] ?? "";
|
|
156
|
+
}
|
|
157
|
+
if (selectedValues.length === 0)
|
|
158
|
+
return null;
|
|
159
|
+
const formData = new FormData();
|
|
160
|
+
selectedValues.forEach((value) => formData.append(name, value));
|
|
161
|
+
return formData;
|
|
162
|
+
}
|
|
163
|
+
focus(options) {
|
|
164
|
+
if (this.disabled)
|
|
165
|
+
return;
|
|
166
|
+
const trigger = this.slottedTrigger();
|
|
167
|
+
const target = trigger && triggerFocusTarget(trigger);
|
|
168
|
+
if (target) {
|
|
169
|
+
target.focus(options);
|
|
170
|
+
const root = target.getRootNode();
|
|
171
|
+
if (root.activeElement === target)
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
175
|
+
if (stub)
|
|
176
|
+
stub.focus(options);
|
|
177
|
+
else
|
|
178
|
+
super.focus(options);
|
|
179
|
+
}
|
|
180
|
+
parseValue(value) {
|
|
181
|
+
if (!value)
|
|
182
|
+
return [];
|
|
183
|
+
return value
|
|
184
|
+
.split(",")
|
|
185
|
+
.map((v) => v.trim())
|
|
186
|
+
.filter((v) => v !== "");
|
|
187
|
+
}
|
|
188
|
+
getSelectedValues() {
|
|
189
|
+
if (this.externalSelection)
|
|
190
|
+
return [];
|
|
191
|
+
return this.parseValue(this.getProperty("value"));
|
|
192
|
+
}
|
|
193
|
+
getTagElements() {
|
|
194
|
+
return Array.from(this.querySelectorAll("ty-option"));
|
|
195
|
+
}
|
|
196
|
+
getOfferedTags() {
|
|
197
|
+
return this.getTagElements()
|
|
198
|
+
.filter((el) => !el.hasAttribute("hidden"))
|
|
199
|
+
.map((el) => this.getTagData(el));
|
|
200
|
+
}
|
|
201
|
+
getTagData(element) {
|
|
202
|
+
const own = element.value;
|
|
203
|
+
const value = typeof own === "string"
|
|
204
|
+
? own
|
|
205
|
+
: element.getAttribute("value") ?? (element.textContent || "").trim();
|
|
206
|
+
const text = element.getAttribute("label") || element.textContent || "";
|
|
207
|
+
return { value, text, element };
|
|
208
|
+
}
|
|
209
|
+
findOption(value) {
|
|
210
|
+
return this.getTagElements().find((el) => this.getTagData(el).value === value);
|
|
211
|
+
}
|
|
212
|
+
paintOptions(shown) {
|
|
213
|
+
const external = this.externalSelection;
|
|
214
|
+
const selected = new Set(this.getSelectedValues());
|
|
215
|
+
for (const el of this.getTagElements()) {
|
|
216
|
+
el.checked = external
|
|
217
|
+
? isMarked(el)
|
|
218
|
+
: selected.has(this.getTagData(el).value);
|
|
219
|
+
el.inTrigger = el === shown;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
shownOption() {
|
|
223
|
+
if (this.multiple || this._state.open)
|
|
224
|
+
return null;
|
|
225
|
+
const value = this.getSelectedValues()[0];
|
|
226
|
+
const option = value === undefined ? undefined : this.findOption(value);
|
|
227
|
+
return option && option.parentElement === this ? option : null;
|
|
228
|
+
}
|
|
229
|
+
assignSlots(shown) {
|
|
230
|
+
const shadow = this.shadowRoot;
|
|
231
|
+
const named = new Map(NAMED_SLOTS.map((n) => [n, []]));
|
|
232
|
+
const list = [];
|
|
233
|
+
for (const node of Array.from(this.childNodes)) {
|
|
234
|
+
if (node === shown)
|
|
235
|
+
continue;
|
|
236
|
+
if (node instanceof Element && named.has(node.slot))
|
|
237
|
+
named.get(node.slot).push(node);
|
|
238
|
+
else if (node instanceof Element || node instanceof Text)
|
|
239
|
+
list.push(node);
|
|
240
|
+
}
|
|
241
|
+
for (const [name, nodes] of named) {
|
|
242
|
+
assign(shadow.querySelector(`slot[name="${name}"]`), nodes);
|
|
243
|
+
}
|
|
244
|
+
assign(shadow.querySelector('slot[name="selected"]'), shown ? [shown] : []);
|
|
245
|
+
assign(shadow.querySelector("#options-slot"), list);
|
|
246
|
+
}
|
|
247
|
+
syncTrigger() {
|
|
248
|
+
const shown = this.shownOption();
|
|
249
|
+
this.assignSlots(shown);
|
|
250
|
+
this.paintOptions(shown);
|
|
251
|
+
this.updateSelectionDisplay(shown);
|
|
252
|
+
}
|
|
253
|
+
updateComponentValue(newValues, dispatchChange = false, action = "set", item = null, reveal = dispatchChange) {
|
|
254
|
+
const oldValues = this.getSelectedValues();
|
|
255
|
+
const sameSet = [...newValues].sort().join("\u0000") === [...oldValues].sort().join("\u0000");
|
|
256
|
+
if (sameSet)
|
|
257
|
+
return;
|
|
258
|
+
this.setProperty("value", newValues.join(","));
|
|
259
|
+
if (dispatchChange) {
|
|
260
|
+
this.dispatchChangeEvent({
|
|
261
|
+
value: this.multiple ? [...newValues] : (newValues[0] ?? null),
|
|
262
|
+
values: newValues,
|
|
263
|
+
items: this.getSelectedItems(newValues),
|
|
264
|
+
action,
|
|
265
|
+
item,
|
|
266
|
+
});
|
|
267
|
+
if (reveal)
|
|
268
|
+
this.revealValidity();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
getSelectedItems(values) {
|
|
272
|
+
const byValue = new Map(this.getTagElements().map((el) => [this.getTagData(el).value, el]));
|
|
273
|
+
return values.map((value) => {
|
|
274
|
+
const el = byValue.get(value);
|
|
275
|
+
return {
|
|
276
|
+
value,
|
|
277
|
+
label: el?.getAttribute("label") || el?.textContent?.trim() || value,
|
|
278
|
+
flavor: el?.getAttribute("flavor") ?? null,
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
calculatePosition() {
|
|
283
|
+
const shadow = this.shadowRoot;
|
|
284
|
+
const stub = shadow.querySelector(".select-stub");
|
|
285
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
286
|
+
if (!stub || !dialog)
|
|
287
|
+
return;
|
|
288
|
+
const stubRect = stub.getBoundingClientRect();
|
|
289
|
+
const MAX_POPUP_ESTIMATE = 440;
|
|
290
|
+
const dialogRect = dialog.getBoundingClientRect();
|
|
291
|
+
const estimatedHeight = Math.min(dialogRect.height || 200, MAX_POPUP_ESTIMATE);
|
|
292
|
+
const wrapPadding = 20;
|
|
293
|
+
const cssWidth = parseFloat(getComputedStyle(this).getPropertyValue("--ty-select-popup-width"));
|
|
294
|
+
const popupWidth = !isNaN(cssWidth)
|
|
295
|
+
? cssWidth
|
|
296
|
+
: Math.max(stubRect.width, 320);
|
|
297
|
+
const anchored = placementToAnchored(this.getProperty("placement"));
|
|
298
|
+
const pos = computeAnchoredPosition({
|
|
299
|
+
anchorRect: stubRect,
|
|
300
|
+
popupWidth,
|
|
301
|
+
popupHeight: estimatedHeight,
|
|
302
|
+
align: anchored.align,
|
|
303
|
+
side: anchored.side,
|
|
304
|
+
gap: 8,
|
|
305
|
+
});
|
|
306
|
+
const positionBelow = pos.below;
|
|
307
|
+
const x = pos.x - wrapPadding;
|
|
308
|
+
const y = (positionBelow ? pos.topY : pos.bottomY) - wrapPadding;
|
|
309
|
+
const width = popupWidth + wrapPadding + wrapPadding;
|
|
310
|
+
dialog.style.setProperty("--dropdown-x", `${x}px`);
|
|
311
|
+
dialog.style.setProperty("--dropdown-y", `${y}px`);
|
|
312
|
+
dialog.style.setProperty("--dropdown-width", `${width}px`);
|
|
313
|
+
dialog.style.setProperty("--dropdown-padding", `${wrapPadding}px`);
|
|
314
|
+
dialog.classList.toggle("position-below", positionBelow);
|
|
315
|
+
dialog.classList.toggle("position-above", !positionBelow);
|
|
316
|
+
}
|
|
317
|
+
_setupOptionsScrollbar() {
|
|
318
|
+
if (!isCustomScrollbarEnabled())
|
|
319
|
+
return;
|
|
320
|
+
const shadow = this.shadowRoot;
|
|
321
|
+
const optionsDiv = shadow.querySelector(".dropdown-options");
|
|
322
|
+
const optionsWrapper = shadow.querySelector(".dropdown-options-wrapper");
|
|
323
|
+
if (!optionsDiv || !optionsWrapper)
|
|
324
|
+
return;
|
|
325
|
+
this._destroyOptionsScrollbar();
|
|
326
|
+
optionsDiv.classList.add("ty-custom-scroll");
|
|
327
|
+
this._optionsScrollbar = new CustomScrollbar(optionsDiv, {
|
|
328
|
+
vertical: true,
|
|
329
|
+
});
|
|
330
|
+
if (this._optionsScrollbar.trackY) {
|
|
331
|
+
optionsWrapper.appendChild(this._optionsScrollbar.trackY);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
_destroyOptionsScrollbar() {
|
|
335
|
+
if (this._optionsScrollbar) {
|
|
336
|
+
this._optionsScrollbar.trackY?.remove();
|
|
337
|
+
this._optionsScrollbar.destroy();
|
|
338
|
+
this._optionsScrollbar = null;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
open() {
|
|
342
|
+
if (this.disabled || this.readonly || this._state.open)
|
|
343
|
+
return;
|
|
344
|
+
if (this._state.mode === "mobile")
|
|
345
|
+
this.openMobileModal();
|
|
346
|
+
else
|
|
347
|
+
this.openDropdown();
|
|
348
|
+
}
|
|
349
|
+
close() {
|
|
350
|
+
if (this._state.mode === "mobile")
|
|
351
|
+
this.closeMobileModal();
|
|
352
|
+
else
|
|
353
|
+
this.closeDropdown();
|
|
354
|
+
}
|
|
355
|
+
lockPageScroll() {
|
|
356
|
+
this._scrollLockId = `select-${this.id || "anon"}-${this._uid}`;
|
|
357
|
+
lockScroll(this._scrollLockId);
|
|
358
|
+
}
|
|
359
|
+
unlockPageScroll() {
|
|
360
|
+
if (this._scrollLockId) {
|
|
361
|
+
unlockScroll(this._scrollLockId);
|
|
362
|
+
this._scrollLockId = null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
setExpanded(expanded) {
|
|
366
|
+
this.shadowRoot.querySelector(".select-stub")?.setAttribute("aria-expanded", String(expanded));
|
|
367
|
+
this.triggerAriaTarget()?.setAttribute("aria-expanded", String(expanded));
|
|
368
|
+
}
|
|
369
|
+
openDropdown() {
|
|
370
|
+
const shadow = this.shadowRoot;
|
|
371
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
372
|
+
if (!dialog)
|
|
373
|
+
return;
|
|
374
|
+
this.setExpanded(true);
|
|
375
|
+
this.lockPageScroll();
|
|
376
|
+
this._state.open = true;
|
|
377
|
+
this.syncTrigger();
|
|
378
|
+
dialog.showModal();
|
|
379
|
+
this.calculatePosition();
|
|
380
|
+
dialog.classList.add("open");
|
|
381
|
+
shadow.querySelector(".dropdown-chevron")?.classList.add("open");
|
|
382
|
+
shadow.querySelector(".dropdown-search-chevron")?.classList.add("open");
|
|
383
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
384
|
+
this._state.highlightedIndex = -1;
|
|
385
|
+
this.updateOptionsVisibility(true);
|
|
386
|
+
this._setupOptionsScrollbar();
|
|
387
|
+
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
388
|
+
if (searchInput && this.shouldShowSearch()) {
|
|
389
|
+
setTimeout(() => searchInput.focus(), 100);
|
|
390
|
+
}
|
|
391
|
+
this.fireOpenEvent();
|
|
392
|
+
}
|
|
393
|
+
closeDropdown() {
|
|
394
|
+
const shadow = this.shadowRoot;
|
|
395
|
+
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
396
|
+
if (!dialog)
|
|
397
|
+
return;
|
|
398
|
+
this.setExpanded(false);
|
|
399
|
+
this._destroyOptionsScrollbar();
|
|
400
|
+
dialog.classList.remove("open", "position-above", "position-below");
|
|
401
|
+
dialog.close();
|
|
402
|
+
this.unlockPageScroll();
|
|
403
|
+
this._state.open = false;
|
|
404
|
+
this._state.highlightedIndex = -1;
|
|
405
|
+
this.syncTrigger();
|
|
406
|
+
shadow.querySelector(".dropdown-chevron")?.classList.remove("open");
|
|
407
|
+
shadow.querySelector(".dropdown-search-chevron")?.classList.remove("open");
|
|
408
|
+
this.resetSearch(".dropdown-search-input");
|
|
409
|
+
this.fireCloseEvent();
|
|
410
|
+
}
|
|
411
|
+
openMobileModal() {
|
|
412
|
+
const shadow = this.shadowRoot;
|
|
413
|
+
const dialog = shadow.querySelector(".mobile-dialog");
|
|
414
|
+
if (!dialog)
|
|
415
|
+
return;
|
|
416
|
+
this.setExpanded(true);
|
|
417
|
+
this.lockPageScroll();
|
|
418
|
+
this._state.open = true;
|
|
419
|
+
this.syncTrigger();
|
|
420
|
+
dialog.showModal();
|
|
421
|
+
dialog.getBoundingClientRect();
|
|
422
|
+
dialog.classList.add("open");
|
|
423
|
+
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
424
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
425
|
+
this.updateTagVisibility(tags, tags);
|
|
426
|
+
requestAnimationFrame(() => this.updateMobileSelectedState());
|
|
427
|
+
this.fireOpenEvent();
|
|
428
|
+
}
|
|
429
|
+
closeMobileModal() {
|
|
430
|
+
const shadow = this.shadowRoot;
|
|
431
|
+
const dialog = shadow.querySelector(".mobile-dialog");
|
|
432
|
+
if (!dialog)
|
|
433
|
+
return;
|
|
434
|
+
this.setExpanded(false);
|
|
435
|
+
dialog.classList.remove("open");
|
|
436
|
+
dialog.close();
|
|
437
|
+
this.unlockPageScroll();
|
|
438
|
+
this._state.open = false;
|
|
439
|
+
this._state.highlightedIndex = -1;
|
|
440
|
+
this.syncTrigger();
|
|
441
|
+
this.resetSearch(".mobile-search-input");
|
|
442
|
+
this.fireCloseEvent();
|
|
443
|
+
}
|
|
444
|
+
resetSearch(inputSelector) {
|
|
445
|
+
const hadQuery = this._state.search !== "";
|
|
446
|
+
this._state.search = "";
|
|
447
|
+
const searchInput = this.shadowRoot.querySelector(inputSelector);
|
|
448
|
+
if (searchInput)
|
|
449
|
+
searchInput.value = "";
|
|
450
|
+
if (this.externalSearch) {
|
|
451
|
+
if (hadQuery) {
|
|
452
|
+
if (this._searchDebounceTimer !== null) {
|
|
453
|
+
clearTimeout(this._searchDebounceTimer);
|
|
454
|
+
this._searchDebounceTimer = null;
|
|
455
|
+
}
|
|
456
|
+
this.fireSearchEvent("");
|
|
457
|
+
}
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
461
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
462
|
+
this.updateTagVisibility(allTags, allTags);
|
|
463
|
+
this.clearHighlights(allTags);
|
|
464
|
+
}
|
|
465
|
+
handleStubClick(e) {
|
|
466
|
+
e.preventDefault();
|
|
467
|
+
e.stopPropagation();
|
|
468
|
+
this.open();
|
|
469
|
+
}
|
|
470
|
+
handleClearClick(e) {
|
|
471
|
+
e.preventDefault();
|
|
472
|
+
e.stopPropagation();
|
|
473
|
+
if (this.disabled || this.readonly) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
this.clear();
|
|
477
|
+
this.revealValidity();
|
|
478
|
+
}
|
|
479
|
+
handleStubKeydown(e) {
|
|
480
|
+
if (this.disabled || this.readonly || this._state.open)
|
|
481
|
+
return;
|
|
482
|
+
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
483
|
+
e.preventDefault();
|
|
484
|
+
this.open();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
handleTagClick(e) {
|
|
488
|
+
const target = e.target;
|
|
489
|
+
const tag = target.closest("ty-option");
|
|
490
|
+
if (!tag || tag.hasAttribute("disabled"))
|
|
491
|
+
return;
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
e.stopPropagation();
|
|
494
|
+
this.selectByTag(tag);
|
|
495
|
+
}
|
|
496
|
+
selectByTag(tag) {
|
|
497
|
+
const tagValue = this.getTagData(tag).value;
|
|
498
|
+
if (this.externalSelection) {
|
|
499
|
+
const selected = !this.multiple || !isMarked(tag);
|
|
500
|
+
this.dispatchChangeEvent({
|
|
501
|
+
value: tagValue,
|
|
502
|
+
values: [],
|
|
503
|
+
items: [],
|
|
504
|
+
action: !this.multiple ? "set" : selected ? "add" : "remove",
|
|
505
|
+
item: tagValue,
|
|
506
|
+
selected,
|
|
507
|
+
});
|
|
508
|
+
if (!this.multiple)
|
|
509
|
+
this.close();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (!this.multiple) {
|
|
513
|
+
this.updateComponentValue([tagValue], true, "set", tagValue);
|
|
514
|
+
this.close();
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const currentValues = this.getSelectedValues();
|
|
518
|
+
if (currentValues.includes(tagValue)) {
|
|
519
|
+
this.updateComponentValue(currentValues.filter((v) => v !== tagValue), true, "remove", tagValue);
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
this.updateComponentValue([...currentValues, tagValue], true, "add", tagValue);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
tryCreateFromSearch() {
|
|
526
|
+
if (!this.allowCreate)
|
|
527
|
+
return false;
|
|
528
|
+
const query = (this._state.search || "").trim();
|
|
529
|
+
if (!query)
|
|
530
|
+
return false;
|
|
531
|
+
const queryLower = query.toLowerCase();
|
|
532
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
533
|
+
const existing = allTags.find((t) => t.value.toLowerCase() === queryLower ||
|
|
534
|
+
t.text.toLowerCase() === queryLower);
|
|
535
|
+
if (existing) {
|
|
536
|
+
this.selectByTag(existing.element);
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
const rawLabel = query;
|
|
540
|
+
const defaultValue = this.createTransform === "slug" ? slugify(rawLabel) : rawLabel;
|
|
541
|
+
if (!defaultValue)
|
|
542
|
+
return true;
|
|
543
|
+
const detail = { value: defaultValue, label: rawLabel };
|
|
544
|
+
const event = new CustomEvent("create", {
|
|
545
|
+
detail,
|
|
546
|
+
bubbles: true,
|
|
547
|
+
composed: true,
|
|
548
|
+
cancelable: true,
|
|
549
|
+
});
|
|
550
|
+
this.dispatchEvent(event);
|
|
551
|
+
if (event.defaultPrevented)
|
|
552
|
+
return true;
|
|
553
|
+
const finalValue = detail.value;
|
|
554
|
+
const option = document.createElement("ty-option");
|
|
555
|
+
option.setAttribute("value", finalValue);
|
|
556
|
+
option.textContent = rawLabel;
|
|
557
|
+
this.appendChild(option);
|
|
558
|
+
if (this.externalSelection) {
|
|
559
|
+
this.selectByTag(option);
|
|
560
|
+
if (this.multiple)
|
|
561
|
+
this.clearSearchAfterCreate();
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
if (!this.multiple) {
|
|
565
|
+
this.updateComponentValue([finalValue], true, "create", finalValue);
|
|
566
|
+
this.close();
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
this.updateComponentValue([...this.getSelectedValues(), finalValue], true, "create", finalValue);
|
|
570
|
+
this.clearSearchAfterCreate();
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
clearSearchAfterCreate() {
|
|
574
|
+
this._state.search = "";
|
|
575
|
+
this._state.highlightedIndex = -1;
|
|
576
|
+
const input = this.searchInput();
|
|
577
|
+
if (input)
|
|
578
|
+
input.value = "";
|
|
579
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
580
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
581
|
+
this.updateTagVisibility(allTags, allTags);
|
|
582
|
+
this.updateOptionsVisibility(true);
|
|
583
|
+
this.clearHighlights(allTags);
|
|
584
|
+
this.updateMobileSelectedState();
|
|
585
|
+
input?.focus();
|
|
586
|
+
}
|
|
587
|
+
searchInput() {
|
|
588
|
+
return this.shadowRoot.querySelector(".dropdown-search-input, .mobile-search-input");
|
|
589
|
+
}
|
|
590
|
+
handleSearchInput(e) {
|
|
591
|
+
if (this._state.mode === "mobile")
|
|
592
|
+
this.expandMobileSection("available");
|
|
593
|
+
const query = e.target.value;
|
|
594
|
+
this._state.search = query;
|
|
595
|
+
if (this.externalSearch) {
|
|
596
|
+
this.dispatchSearchEvent(query);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const allTags = this.getOfferedTags();
|
|
600
|
+
const filtered = this.filterTags(allTags, query);
|
|
601
|
+
this._state.filteredTags = filtered;
|
|
602
|
+
this._state.highlightedIndex = -1;
|
|
603
|
+
this.updateTagVisibility(filtered, allTags);
|
|
604
|
+
this.updateOptionsVisibility(filtered.length > 0);
|
|
605
|
+
this.updateMobileSelectedState();
|
|
606
|
+
this.clearHighlights(allTags);
|
|
607
|
+
}
|
|
608
|
+
handleKeyboard(e) {
|
|
609
|
+
if (!this._state.open)
|
|
610
|
+
return;
|
|
611
|
+
const filteredTags = this._state.filteredTags;
|
|
612
|
+
const highlighted = this._state.highlightedIndex;
|
|
613
|
+
switch (e.key) {
|
|
614
|
+
case "Escape":
|
|
615
|
+
e.preventDefault();
|
|
616
|
+
e.stopPropagation();
|
|
617
|
+
this.close();
|
|
618
|
+
this.focus();
|
|
619
|
+
break;
|
|
620
|
+
case "Enter":
|
|
621
|
+
e.preventDefault();
|
|
622
|
+
e.stopPropagation();
|
|
623
|
+
if (highlighted >= 0 && highlighted < filteredTags.length) {
|
|
624
|
+
this.selectByTag(filteredTags[highlighted].element);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
this.tryCreateFromSearch();
|
|
628
|
+
}
|
|
629
|
+
break;
|
|
630
|
+
case "ArrowUp":
|
|
631
|
+
case "ArrowDown": {
|
|
632
|
+
e.preventDefault();
|
|
633
|
+
e.stopPropagation();
|
|
634
|
+
const next = this.nextEnabledTagIndex(filteredTags, highlighted, e.key === "ArrowDown" ? 1 : -1);
|
|
635
|
+
this._state.highlightedIndex = next;
|
|
636
|
+
this.highlightTag(filteredTags, next);
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
nextEnabledTagIndex(tags, fromIndex, direction) {
|
|
642
|
+
const count = tags.length;
|
|
643
|
+
if (count === 0)
|
|
644
|
+
return -1;
|
|
645
|
+
let index = fromIndex === -1
|
|
646
|
+
? (direction === 1 ? 0 : count - 1)
|
|
647
|
+
: (fromIndex + direction + count) % count;
|
|
648
|
+
for (let i = 0; i < count; i++) {
|
|
649
|
+
const el = tags[index].element;
|
|
650
|
+
if (!el.hasAttribute("disabled") && !el.hasAttribute("hidden") && !el.hasAttribute("filtered-out"))
|
|
651
|
+
return index;
|
|
652
|
+
index = (index + direction + count) % count;
|
|
653
|
+
}
|
|
654
|
+
return -1;
|
|
655
|
+
}
|
|
656
|
+
filterTags(tags, query) {
|
|
657
|
+
if (!query || query.trim() === "") {
|
|
658
|
+
return tags;
|
|
659
|
+
}
|
|
660
|
+
const searchLower = query.toLowerCase();
|
|
661
|
+
return tags.filter(({ text }) => text.toLowerCase().includes(searchLower));
|
|
662
|
+
}
|
|
663
|
+
updateTagVisibility(filteredTags, allTags) {
|
|
664
|
+
const visibleValues = new Set(filteredTags.map((tag) => tag.value));
|
|
665
|
+
allTags.forEach(({ value, element }) => {
|
|
666
|
+
element.toggleAttribute("filtered-out", !visibleValues.has(value));
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
updateOptionsVisibility(hasOptions) {
|
|
670
|
+
const options = this.shadowRoot.querySelector(".dropdown-options");
|
|
671
|
+
if (options) {
|
|
672
|
+
options.style.display = hasOptions ? "" : "none";
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
clearHighlights(tags) {
|
|
676
|
+
tags.forEach(({ element }) => {
|
|
677
|
+
element.removeAttribute("highlighted");
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
highlightTag(tags, index) {
|
|
681
|
+
this.clearHighlights(tags);
|
|
682
|
+
if (index >= 0 && index < tags.length) {
|
|
683
|
+
const { element } = tags[index];
|
|
684
|
+
element.setAttribute("highlighted", "");
|
|
685
|
+
element.scrollIntoView({
|
|
686
|
+
behavior: "smooth",
|
|
687
|
+
block: "nearest",
|
|
688
|
+
inline: "nearest",
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
dispatchSearchEvent(query) {
|
|
693
|
+
if (this._searchDebounceTimer !== null) {
|
|
694
|
+
clearTimeout(this._searchDebounceTimer);
|
|
695
|
+
this._searchDebounceTimer = null;
|
|
696
|
+
}
|
|
697
|
+
const debounce = this.getProperty("debounce");
|
|
698
|
+
if (debounce > 0) {
|
|
699
|
+
this._searchDebounceTimer = window.setTimeout(() => {
|
|
700
|
+
this.fireSearchEvent(query);
|
|
701
|
+
this._searchDebounceTimer = null;
|
|
702
|
+
}, debounce);
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
this.fireSearchEvent(query);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
fireSearchEvent(query) {
|
|
709
|
+
this.dispatchEvent(new CustomEvent("search", {
|
|
710
|
+
detail: {
|
|
711
|
+
query,
|
|
712
|
+
element: this,
|
|
713
|
+
},
|
|
714
|
+
bubbles: true,
|
|
715
|
+
composed: true,
|
|
716
|
+
}));
|
|
717
|
+
}
|
|
718
|
+
fireOpenEvent() {
|
|
719
|
+
this.dispatchEvent(new CustomEvent("open", {
|
|
720
|
+
detail: { mode: this._state.mode, element: this },
|
|
721
|
+
}));
|
|
722
|
+
if (this.externalSearch) {
|
|
723
|
+
this.fireSearchEvent("");
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
fireCloseEvent() {
|
|
727
|
+
this.dispatchEvent(new CustomEvent("close", {
|
|
728
|
+
detail: { mode: this._state.mode, element: this },
|
|
729
|
+
}));
|
|
730
|
+
}
|
|
731
|
+
dispatchChangeEvent(detail) {
|
|
732
|
+
this.dispatchEvent(new CustomEvent("change", {
|
|
733
|
+
detail,
|
|
734
|
+
bubbles: true,
|
|
735
|
+
cancelable: true,
|
|
736
|
+
}));
|
|
737
|
+
}
|
|
738
|
+
render() {
|
|
739
|
+
if (!this.shadowRoot.querySelector(".select-container"))
|
|
740
|
+
this.build();
|
|
741
|
+
this.syncTrigger();
|
|
742
|
+
if (this._state.open)
|
|
743
|
+
this.refreshOpenList();
|
|
744
|
+
this.updateSearchVisibility();
|
|
745
|
+
this.applyLoadingState();
|
|
746
|
+
this.syncFieldChrome();
|
|
747
|
+
this.syncTriggerSlot();
|
|
748
|
+
this.updateMobileSelectedState();
|
|
749
|
+
this.updateFormValue();
|
|
750
|
+
this.updateValidity();
|
|
751
|
+
}
|
|
752
|
+
refreshOpenList() {
|
|
753
|
+
const offered = this.getOfferedTags();
|
|
754
|
+
const filtered = this.externalSearch ? offered : this.filterTags(offered, this._state.search);
|
|
755
|
+
if (!this.externalSearch) {
|
|
756
|
+
this.updateTagVisibility(filtered, this.getTagElements().map((el) => this.getTagData(el)));
|
|
757
|
+
}
|
|
758
|
+
const highlighted = this._state.filteredTags[this._state.highlightedIndex]?.element;
|
|
759
|
+
this._state.filteredTags = filtered;
|
|
760
|
+
this._state.highlightedIndex = filtered.findIndex((t) => t.element === highlighted);
|
|
761
|
+
}
|
|
762
|
+
syncFieldChrome() {
|
|
763
|
+
const shadow = this.shadowRoot;
|
|
764
|
+
const container = shadow.querySelector(".select-container");
|
|
765
|
+
const labelText = this.label;
|
|
766
|
+
const required = this.required;
|
|
767
|
+
const disabled = this.disabled;
|
|
768
|
+
const labelId = `select-label-${this._uid}`;
|
|
769
|
+
let label = container.querySelector(":scope > .ty-field-label");
|
|
770
|
+
if (labelText) {
|
|
771
|
+
if (!label) {
|
|
772
|
+
label = document.createElement("label");
|
|
773
|
+
label.className = "ty-field-label";
|
|
774
|
+
label.id = labelId;
|
|
775
|
+
container.prepend(label);
|
|
776
|
+
}
|
|
777
|
+
label.innerHTML = `${labelText}${required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}`;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
label?.remove();
|
|
781
|
+
}
|
|
782
|
+
const error = this.error || "";
|
|
783
|
+
const errorId = `select-error-${this._uid}`;
|
|
784
|
+
let errorLine = container.querySelector(":scope > .error-message");
|
|
785
|
+
if (error) {
|
|
786
|
+
if (!errorLine) {
|
|
787
|
+
errorLine = document.createElement("div");
|
|
788
|
+
errorLine.className = "error-message";
|
|
789
|
+
errorLine.id = errorId;
|
|
790
|
+
container.append(errorLine);
|
|
791
|
+
}
|
|
792
|
+
errorLine.textContent = error;
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
errorLine?.remove();
|
|
796
|
+
}
|
|
797
|
+
const stub = shadow.querySelector(".select-stub");
|
|
798
|
+
stub.classList.toggle("disabled", disabled);
|
|
799
|
+
stub.classList.toggle("compact", this.compact);
|
|
800
|
+
stub.classList.toggle("error", !!error);
|
|
801
|
+
stub.tabIndex = disabled || this.triggerTakesFocus() ? -1 : 0;
|
|
802
|
+
stub.toggleAttribute("disabled", disabled);
|
|
803
|
+
if (disabled)
|
|
804
|
+
stub.setAttribute("aria-disabled", "true");
|
|
805
|
+
else
|
|
806
|
+
stub.removeAttribute("aria-disabled");
|
|
807
|
+
if (labelText && !this.triggerTakesFocus())
|
|
808
|
+
stub.setAttribute("aria-labelledby", labelId);
|
|
809
|
+
else
|
|
810
|
+
stub.removeAttribute("aria-labelledby");
|
|
811
|
+
this.syncTriggerName();
|
|
812
|
+
if (error) {
|
|
813
|
+
stub.setAttribute("aria-invalid", "true");
|
|
814
|
+
stub.setAttribute("aria-describedby", errorId);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
stub.removeAttribute("aria-invalid");
|
|
818
|
+
stub.removeAttribute("aria-describedby");
|
|
819
|
+
}
|
|
820
|
+
this.syncTriggerAria();
|
|
821
|
+
shadow
|
|
822
|
+
.querySelectorAll(".dropdown-search-input, .mobile-search-input")
|
|
823
|
+
.forEach((input) => (input.disabled = disabled));
|
|
824
|
+
}
|
|
825
|
+
syncTriggerAria() {
|
|
826
|
+
const error = this.error || "";
|
|
827
|
+
const trigger = error ? (this.triggerAriaTarget() ?? this.slottedTrigger()) : null;
|
|
828
|
+
if (this._ariaTrigger && this._ariaTrigger !== trigger) {
|
|
829
|
+
this._ariaTrigger.removeAttribute("aria-invalid");
|
|
830
|
+
this._ariaTrigger.removeAttribute("aria-description");
|
|
831
|
+
}
|
|
832
|
+
if (trigger) {
|
|
833
|
+
if (trigger.getAttribute("aria-invalid") !== "true")
|
|
834
|
+
trigger.setAttribute("aria-invalid", "true");
|
|
835
|
+
if (trigger.getAttribute("aria-description") !== error)
|
|
836
|
+
trigger.setAttribute("aria-description", error);
|
|
837
|
+
}
|
|
838
|
+
this._ariaTrigger = trigger;
|
|
839
|
+
this._ariaObserver ?? (this._ariaObserver = new MutationObserver(() => this.syncTriggerAria()));
|
|
840
|
+
this._ariaObserver.disconnect();
|
|
841
|
+
if (trigger) {
|
|
842
|
+
this._ariaObserver.observe(trigger, {
|
|
843
|
+
attributes: true,
|
|
844
|
+
attributeFilter: ["aria-invalid", "aria-description"],
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
updateValidity() {
|
|
849
|
+
if (this.disabled || this.externalSelection) {
|
|
850
|
+
this.applyValidity({});
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
if (this.required && this.getSelectedValues().length === 0) {
|
|
854
|
+
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
855
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this.multiple }), stub ?? undefined);
|
|
856
|
+
}
|
|
857
|
+
else {
|
|
858
|
+
this.applyValidity({});
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
syncTriggerSlot() {
|
|
862
|
+
const shadow = this.shadowRoot;
|
|
863
|
+
const slot = shadow.querySelector('slot[name="trigger"]');
|
|
864
|
+
const hasTrigger = slot.assignedElements().length > 0;
|
|
865
|
+
const stub = shadow.querySelector(".select-stub");
|
|
866
|
+
stub.classList.toggle("custom-trigger", hasTrigger);
|
|
867
|
+
if (this.hasAttribute("has-trigger") !== hasTrigger) {
|
|
868
|
+
this.toggleAttribute("has-trigger", hasTrigger);
|
|
869
|
+
}
|
|
870
|
+
const trigger = this.slottedTrigger();
|
|
871
|
+
const target = this.triggerAriaTarget();
|
|
872
|
+
stub.tabIndex = this.disabled || target ? -1 : 0;
|
|
873
|
+
if (target) {
|
|
874
|
+
target.setAttribute("aria-haspopup", "listbox");
|
|
875
|
+
target.setAttribute("aria-expanded", String(this._state.open));
|
|
876
|
+
if (!target.matches("button, a[href], input, select, textarea") && !target.hasAttribute("role")) {
|
|
877
|
+
target.setAttribute("role", "button");
|
|
878
|
+
}
|
|
879
|
+
stub.setAttribute("role", "none");
|
|
880
|
+
for (const a of ["aria-haspopup", "aria-expanded", "aria-controls", "aria-labelledby"])
|
|
881
|
+
stub.removeAttribute(a);
|
|
882
|
+
}
|
|
883
|
+
else if (stub.getAttribute("role") !== "combobox") {
|
|
884
|
+
stub.setAttribute("role", "combobox");
|
|
885
|
+
stub.setAttribute("aria-haspopup", "listbox");
|
|
886
|
+
stub.setAttribute("aria-expanded", String(this._state.open));
|
|
887
|
+
stub.setAttribute("aria-controls", `select-listbox-${this._uid}`);
|
|
888
|
+
}
|
|
889
|
+
this._triggerTextObserver?.disconnect();
|
|
890
|
+
if (trigger) {
|
|
891
|
+
this._triggerTextObserver ?? (this._triggerTextObserver = new MutationObserver(() => this.syncTriggerName()));
|
|
892
|
+
this._triggerTextObserver.observe(trigger, { childList: true, characterData: true, subtree: true });
|
|
893
|
+
}
|
|
894
|
+
this.syncTriggerName();
|
|
895
|
+
if (trigger && trigger.localName.includes("-") && !customElements.get(trigger.localName)) {
|
|
896
|
+
customElements.whenDefined(trigger.localName).then(() => requestAnimationFrame(() => this.syncTriggerSlot()));
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
slottedTrigger() {
|
|
900
|
+
return this.querySelector(':scope > [slot="trigger"]');
|
|
901
|
+
}
|
|
902
|
+
triggerTakesFocus() {
|
|
903
|
+
return !!this.triggerAriaTarget();
|
|
904
|
+
}
|
|
905
|
+
triggerAriaTarget() {
|
|
906
|
+
const trigger = this.slottedTrigger();
|
|
907
|
+
return trigger ? triggerFocusTarget(trigger) : null;
|
|
908
|
+
}
|
|
909
|
+
syncTriggerName() {
|
|
910
|
+
const trigger = this.slottedTrigger();
|
|
911
|
+
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
912
|
+
if (!stub)
|
|
913
|
+
return;
|
|
914
|
+
const text = (trigger?.textContent || "").replace(/\s+/g, " ").trim();
|
|
915
|
+
const label = this.label ? String(this.label) : "";
|
|
916
|
+
const target = this.triggerAriaTarget();
|
|
917
|
+
if (!target) {
|
|
918
|
+
if (trigger && !label && text)
|
|
919
|
+
stub.setAttribute("aria-label", text);
|
|
920
|
+
else
|
|
921
|
+
stub.removeAttribute("aria-label");
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
stub.removeAttribute("aria-label");
|
|
925
|
+
const owned = target.hasAttribute("data-ty-select-name");
|
|
926
|
+
if (target.hasAttribute("aria-label") && !owned)
|
|
927
|
+
return;
|
|
928
|
+
if (label) {
|
|
929
|
+
const name = text ? `${label}: ${text}` : label;
|
|
930
|
+
if (target.getAttribute("aria-label") !== name)
|
|
931
|
+
target.setAttribute("aria-label", name);
|
|
932
|
+
target.setAttribute("data-ty-select-name", "");
|
|
933
|
+
}
|
|
934
|
+
else if (owned) {
|
|
935
|
+
target.removeAttribute("aria-label");
|
|
936
|
+
target.removeAttribute("data-ty-select-name");
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
build() {
|
|
940
|
+
const shadow = this.shadowRoot;
|
|
941
|
+
const mobile = isMobileTouch();
|
|
942
|
+
this._state.mode = mobile ? "mobile" : "desktop";
|
|
943
|
+
const listboxId = `select-listbox-${this._uid}`;
|
|
944
|
+
const multiselectable = this.multiple ? 'aria-multiselectable="true"' : "";
|
|
945
|
+
const loadingHtml = `
|
|
946
|
+
<div class="dropdown-loading" aria-hidden="true">
|
|
947
|
+
<slot name="loading">
|
|
948
|
+
<span class="dropdown-loading-spinner"></span>
|
|
949
|
+
<span class="dropdown-loading-text">Searching…</span>
|
|
950
|
+
</slot>
|
|
951
|
+
</div>`;
|
|
952
|
+
const desktopPopup = `
|
|
953
|
+
<dialog class="dropdown-dialog">
|
|
954
|
+
<div class="dropdown-header">
|
|
955
|
+
<div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
|
|
956
|
+
<input class="dropdown-search-input" type="text" placeholder="Search..." />
|
|
957
|
+
<div class="dropdown-search-chevron">${CHEVRON_DOWN_SVG}</div>
|
|
958
|
+
</div>
|
|
959
|
+
<div class="dropdown-options-wrapper">
|
|
960
|
+
<div class="dropdown-options" id="${listboxId}" role="listbox" ${multiselectable}>
|
|
961
|
+
<slot id="options-slot"></slot>
|
|
962
|
+
</div>
|
|
963
|
+
${loadingHtml}
|
|
964
|
+
</div>
|
|
965
|
+
</dialog>`;
|
|
966
|
+
const label = this.label;
|
|
967
|
+
const mobilePopup = `
|
|
968
|
+
<dialog class="mobile-dialog">
|
|
969
|
+
<div class="mobile-dialog-content">
|
|
970
|
+
<div class="mobile-search-header">
|
|
971
|
+
${label ? `<span class="mobile-header-label">${label}</span>` : ""}
|
|
972
|
+
<div class="mobile-header-content">
|
|
973
|
+
<div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
|
|
974
|
+
<input class="mobile-search-input" type="text"
|
|
975
|
+
placeholder="${label ? `Search ${label}...` : "Search..."}" autofocus />
|
|
976
|
+
<button class="mobile-close-button" type="button" aria-label="Close">${CLEAR_ICON_SVG}</button>
|
|
977
|
+
</div>
|
|
978
|
+
</div>
|
|
979
|
+
<div class="mobile-body" data-expanded="available">
|
|
980
|
+
<!-- Selected strip, pinned above the list; collapses when empty -->
|
|
981
|
+
<div class="mobile-selected-section" data-empty="true">
|
|
982
|
+
<button class="section-header" type="button" data-section="selected" aria-expanded="false">
|
|
983
|
+
<span class="section-title"></span>
|
|
984
|
+
${CHEVRON_DOWN_SVG}
|
|
985
|
+
</button>
|
|
986
|
+
<div class="section-content mobile-selected-chips"></div>
|
|
987
|
+
</div>
|
|
988
|
+
<div class="mobile-available-section" data-empty="false">
|
|
989
|
+
<button class="section-header" type="button" data-section="available" aria-expanded="true">
|
|
990
|
+
<span class="section-title"></span>
|
|
991
|
+
${CHEVRON_DOWN_SVG}
|
|
992
|
+
</button>
|
|
993
|
+
<div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${multiselectable}>
|
|
994
|
+
<slot id="options-slot"></slot>
|
|
995
|
+
<div class="empty-state">${this.getProperty("no-options-message")}</div>
|
|
996
|
+
${loadingHtml}
|
|
997
|
+
</div>
|
|
998
|
+
</div>
|
|
999
|
+
</div>
|
|
1000
|
+
</div>
|
|
1001
|
+
</dialog>`;
|
|
1002
|
+
shadow.innerHTML = `
|
|
1003
|
+
<div class="select-container dropdown-mode-${this._state.mode}">
|
|
1004
|
+
<div class="dropdown-wrapper">
|
|
1005
|
+
<div class="dropdown-stub select-stub"
|
|
1006
|
+
role="combobox"
|
|
1007
|
+
aria-haspopup="listbox"
|
|
1008
|
+
aria-expanded="false"
|
|
1009
|
+
aria-controls="${listboxId}"
|
|
1010
|
+
tabindex="0">
|
|
1011
|
+
<slot name="trigger">
|
|
1012
|
+
<slot name="start"></slot>
|
|
1013
|
+
<slot name="selected"></slot>
|
|
1014
|
+
<span class="dropdown-placeholder"></span>
|
|
1015
|
+
<span class="select-count" hidden></span>
|
|
1016
|
+
<slot name="end"></slot>
|
|
1017
|
+
<button class="select-clear" type="button" aria-label="Clear selection" hidden>
|
|
1018
|
+
${CLEAR_ICON_SVG}
|
|
1019
|
+
</button>
|
|
1020
|
+
<div class="dropdown-chevron">${CHEVRON_DOWN_SVG}</div>
|
|
1021
|
+
</slot>
|
|
1022
|
+
</div>
|
|
1023
|
+
${mobile ? mobilePopup : desktopPopup}
|
|
1024
|
+
</div>
|
|
1025
|
+
</div>
|
|
1026
|
+
`;
|
|
1027
|
+
const stub = shadow.querySelector(".select-stub");
|
|
1028
|
+
stub.addEventListener("click", (e) => this.handleStubClick(e));
|
|
1029
|
+
stub.addEventListener("keydown", (e) => this.handleStubKeydown(e));
|
|
1030
|
+
shadow.querySelector(".select-clear").addEventListener("click", (e) => this.handleClearClick(e));
|
|
1031
|
+
shadow.querySelector('slot[name="trigger"]').addEventListener("slotchange", () => {
|
|
1032
|
+
this.syncTriggerSlot();
|
|
1033
|
+
this.syncFieldChrome();
|
|
1034
|
+
});
|
|
1035
|
+
shadow.querySelector("#options-slot").addEventListener("click", (e) => this.handleTagClick(e));
|
|
1036
|
+
const searchInput = this.searchInput();
|
|
1037
|
+
searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
|
|
1038
|
+
const dialog = shadow.querySelector("dialog");
|
|
1039
|
+
dialog.addEventListener("click", (e) => {
|
|
1040
|
+
if (e.target === dialog)
|
|
1041
|
+
this.close();
|
|
1042
|
+
});
|
|
1043
|
+
dialog.addEventListener("cancel", (e) => {
|
|
1044
|
+
e.preventDefault();
|
|
1045
|
+
this.close();
|
|
1046
|
+
this.focus();
|
|
1047
|
+
});
|
|
1048
|
+
this.syncOnOutsideClose(dialog);
|
|
1049
|
+
if (mobile) {
|
|
1050
|
+
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
1051
|
+
header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
|
|
1052
|
+
});
|
|
1053
|
+
shadow.querySelector(".mobile-close-button").addEventListener("click", () => this.close());
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
searchInput.addEventListener("click", (e) => {
|
|
1057
|
+
e.stopPropagation();
|
|
1058
|
+
e.preventDefault();
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
syncOnOutsideClose(dialog) {
|
|
1063
|
+
new MutationObserver(() => {
|
|
1064
|
+
if (this._state.open && !dialog.open)
|
|
1065
|
+
this.close();
|
|
1066
|
+
}).observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
1067
|
+
}
|
|
1068
|
+
updateMobileSelectedState() {
|
|
1069
|
+
if (this._state.mode !== "mobile")
|
|
1070
|
+
return;
|
|
1071
|
+
const shadow = this.shadowRoot;
|
|
1072
|
+
this.renderMobileSelectedChips();
|
|
1073
|
+
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1074
|
+
if (availableSection) {
|
|
1075
|
+
const selected = new Set(this.getSelectedValues());
|
|
1076
|
+
const shown = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out"));
|
|
1077
|
+
const visibleAvailable = shown.filter(({ value }) => !selected.has(value)).length;
|
|
1078
|
+
availableSection.setAttribute("data-empty", String(shown.length === 0));
|
|
1079
|
+
this.setMobileSectionTitle(availableSection, this.getProperty("available-label"), visibleAvailable);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
setMobileSectionTitle(section, label, n) {
|
|
1083
|
+
const title = section.querySelector(".section-title");
|
|
1084
|
+
if (!title)
|
|
1085
|
+
return;
|
|
1086
|
+
const count = document.createElement("span");
|
|
1087
|
+
count.className = "section-count";
|
|
1088
|
+
count.textContent = `(${n})`;
|
|
1089
|
+
title.replaceChildren(`${label} `, count);
|
|
1090
|
+
}
|
|
1091
|
+
expandMobileSection(section) {
|
|
1092
|
+
const shadow = this.shadowRoot;
|
|
1093
|
+
const body = shadow?.querySelector(".mobile-body");
|
|
1094
|
+
if (!body)
|
|
1095
|
+
return;
|
|
1096
|
+
if (section === "selected" && this.getSelectedValues().length === 0)
|
|
1097
|
+
return;
|
|
1098
|
+
body.dataset.expanded = section;
|
|
1099
|
+
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
1100
|
+
const owns = header.dataset.section === section;
|
|
1101
|
+
header.setAttribute("aria-expanded", String(owns));
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
renderMobileSelectedChips() {
|
|
1105
|
+
const shadow = this.shadowRoot;
|
|
1106
|
+
const section = shadow.querySelector(".mobile-selected-section");
|
|
1107
|
+
const host = shadow.querySelector(".mobile-selected-chips");
|
|
1108
|
+
if (!section || !host)
|
|
1109
|
+
return;
|
|
1110
|
+
const selected = this.getSelectedValues();
|
|
1111
|
+
section.setAttribute("data-empty", String(selected.length === 0));
|
|
1112
|
+
this.setMobileSectionTitle(section, this.getProperty("selected-label"), selected.length);
|
|
1113
|
+
if (selected.length === 0)
|
|
1114
|
+
this.expandMobileSection("available");
|
|
1115
|
+
host.textContent = "";
|
|
1116
|
+
for (const { value, label } of this.getSelectedItems(selected)) {
|
|
1117
|
+
const chip = document.createElement("button");
|
|
1118
|
+
chip.type = "button";
|
|
1119
|
+
chip.className = "mobile-selected-chip";
|
|
1120
|
+
chip.dataset.value = value;
|
|
1121
|
+
chip.setAttribute("aria-label", `Remove ${label}`);
|
|
1122
|
+
chip.innerHTML = `<span class="chip-label"></span>${CLEAR_ICON_SVG}`;
|
|
1123
|
+
chip.querySelector(".chip-label").textContent = label;
|
|
1124
|
+
chip.addEventListener("click", (e) => {
|
|
1125
|
+
e.preventDefault();
|
|
1126
|
+
e.stopPropagation();
|
|
1127
|
+
this.deselectValue(value);
|
|
1128
|
+
});
|
|
1129
|
+
host.appendChild(chip);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
shouldShowSearch() {
|
|
1133
|
+
if (this.externalSearch || this.allowCreate)
|
|
1134
|
+
return true;
|
|
1135
|
+
if (this.notSearchable)
|
|
1136
|
+
return false;
|
|
1137
|
+
return this.getTagElements().length > SEARCH_AUTO_THRESHOLD;
|
|
1138
|
+
}
|
|
1139
|
+
updateSearchVisibility() {
|
|
1140
|
+
const shadow = this.shadowRoot;
|
|
1141
|
+
const show = this.shouldShowSearch();
|
|
1142
|
+
const header = shadow.querySelector(".dropdown-header");
|
|
1143
|
+
if (header)
|
|
1144
|
+
header.hidden = !show;
|
|
1145
|
+
shadow
|
|
1146
|
+
.querySelectorAll(".mobile-search-input, .mobile-header-content .dropdown-search-icon")
|
|
1147
|
+
.forEach((el) => (el.hidden = !show));
|
|
1148
|
+
}
|
|
1149
|
+
updateSelectionDisplay(shown) {
|
|
1150
|
+
const stub = this.shadowRoot.querySelector(".select-stub");
|
|
1151
|
+
const values = this.getSelectedValues();
|
|
1152
|
+
const count = values.length;
|
|
1153
|
+
stub.classList.toggle("has-selection", count > 0);
|
|
1154
|
+
stub.classList.toggle("has-option", shown !== null);
|
|
1155
|
+
const badge = stub.querySelector(".select-count");
|
|
1156
|
+
badge.textContent = String(count);
|
|
1157
|
+
badge.hidden = count === 0 || !this.multiple || !this.compact;
|
|
1158
|
+
const clearBtn = stub.querySelector(".select-clear");
|
|
1159
|
+
clearBtn.hidden = !(count > 0 && !this.noClear && !this.disabled && !this.readonly);
|
|
1160
|
+
const textEl = stub.querySelector(".dropdown-placeholder");
|
|
1161
|
+
textEl.hidden = shown !== null;
|
|
1162
|
+
const text = this._state.open || count === 0 || (this.multiple && this.compact)
|
|
1163
|
+
? null
|
|
1164
|
+
: this.getSelectedItems(values).map((i) => i.label).join(", ");
|
|
1165
|
+
textEl.textContent = text ?? this.placeholder;
|
|
1166
|
+
textEl.classList.toggle("placeholder-shown", text === null);
|
|
1167
|
+
}
|
|
1168
|
+
deselectValue(value) {
|
|
1169
|
+
const current = this.getSelectedValues();
|
|
1170
|
+
if (!current.includes(value))
|
|
1171
|
+
return;
|
|
1172
|
+
this.updateComponentValue(current.filter((v) => v !== value), true, "remove", value);
|
|
1173
|
+
}
|
|
1174
|
+
clear() {
|
|
1175
|
+
this.updateComponentValue([], true, "clear", null, false);
|
|
1176
|
+
}
|
|
1177
|
+
get value() {
|
|
1178
|
+
return this.getSelectedValues().join(",");
|
|
1179
|
+
}
|
|
1180
|
+
set value(val) {
|
|
1181
|
+
this.setProperty("value", val);
|
|
1182
|
+
}
|
|
1183
|
+
get name() {
|
|
1184
|
+
return this.getProperty("name");
|
|
1185
|
+
}
|
|
1186
|
+
set name(val) {
|
|
1187
|
+
this.setProperty("name", val);
|
|
1188
|
+
}
|
|
1189
|
+
get multiple() {
|
|
1190
|
+
return this.getProperty("multiple");
|
|
1191
|
+
}
|
|
1192
|
+
set multiple(value) {
|
|
1193
|
+
this.setProperty("multiple", value);
|
|
1194
|
+
}
|
|
1195
|
+
get compact() {
|
|
1196
|
+
return this.getProperty("compact");
|
|
1197
|
+
}
|
|
1198
|
+
set compact(value) {
|
|
1199
|
+
this.setProperty("compact", value);
|
|
1200
|
+
}
|
|
1201
|
+
get placeholder() {
|
|
1202
|
+
return this.getProperty("placeholder");
|
|
1203
|
+
}
|
|
1204
|
+
set placeholder(val) {
|
|
1205
|
+
this.setProperty("placeholder", val);
|
|
1206
|
+
}
|
|
1207
|
+
get label() {
|
|
1208
|
+
return this.getProperty("label");
|
|
1209
|
+
}
|
|
1210
|
+
set label(val) {
|
|
1211
|
+
this.setProperty("label", val);
|
|
1212
|
+
}
|
|
1213
|
+
get disabled() {
|
|
1214
|
+
return this.getProperty("disabled");
|
|
1215
|
+
}
|
|
1216
|
+
set disabled(value) {
|
|
1217
|
+
this.setProperty("disabled", value);
|
|
1218
|
+
}
|
|
1219
|
+
get loading() {
|
|
1220
|
+
return this.getProperty("loading");
|
|
1221
|
+
}
|
|
1222
|
+
set loading(value) {
|
|
1223
|
+
this.setProperty("loading", value);
|
|
1224
|
+
}
|
|
1225
|
+
get readonly() {
|
|
1226
|
+
return this.getProperty("readonly");
|
|
1227
|
+
}
|
|
1228
|
+
set readonly(value) {
|
|
1229
|
+
this.setProperty("readonly", value);
|
|
1230
|
+
}
|
|
1231
|
+
get noClear() {
|
|
1232
|
+
return this.getProperty("noClear");
|
|
1233
|
+
}
|
|
1234
|
+
set noClear(value) {
|
|
1235
|
+
this.setProperty("noClear", value);
|
|
1236
|
+
}
|
|
1237
|
+
get required() {
|
|
1238
|
+
return this.getProperty("required");
|
|
1239
|
+
}
|
|
1240
|
+
set required(value) {
|
|
1241
|
+
this.setProperty("required", value);
|
|
1242
|
+
}
|
|
1243
|
+
get error() {
|
|
1244
|
+
return this.getProperty("error");
|
|
1245
|
+
}
|
|
1246
|
+
set error(value) {
|
|
1247
|
+
this.setProperty("error", value);
|
|
1248
|
+
}
|
|
1249
|
+
get notSearchable() {
|
|
1250
|
+
return this.getProperty("notSearchable");
|
|
1251
|
+
}
|
|
1252
|
+
set notSearchable(value) {
|
|
1253
|
+
this.setProperty("notSearchable", value);
|
|
1254
|
+
}
|
|
1255
|
+
get externalSearch() {
|
|
1256
|
+
return this.getProperty("externalSearch");
|
|
1257
|
+
}
|
|
1258
|
+
set externalSearch(value) {
|
|
1259
|
+
this.setProperty("externalSearch", value);
|
|
1260
|
+
}
|
|
1261
|
+
get externalSelection() {
|
|
1262
|
+
return this.getProperty("externalSelection");
|
|
1263
|
+
}
|
|
1264
|
+
set externalSelection(value) {
|
|
1265
|
+
this.setProperty("externalSelection", value);
|
|
1266
|
+
}
|
|
1267
|
+
get allowCreate() {
|
|
1268
|
+
return this.getProperty("allowCreate");
|
|
1269
|
+
}
|
|
1270
|
+
set allowCreate(value) {
|
|
1271
|
+
this.setProperty("allowCreate", value);
|
|
1272
|
+
}
|
|
1273
|
+
get createTransform() {
|
|
1274
|
+
return this.getProperty("createTransform");
|
|
1275
|
+
}
|
|
1276
|
+
set createTransform(value) {
|
|
1277
|
+
this.setProperty("createTransform", value);
|
|
1278
|
+
}
|
|
1279
|
+
get debounce() {
|
|
1280
|
+
return this.getProperty("debounce");
|
|
1281
|
+
}
|
|
1282
|
+
set debounce(value) {
|
|
1283
|
+
const numValue = typeof value === "string" ? parseInt(value, 10) : value;
|
|
1284
|
+
this.setProperty("debounce", numValue);
|
|
1285
|
+
}
|
|
1286
|
+
get size() {
|
|
1287
|
+
return this.getProperty("size");
|
|
1288
|
+
}
|
|
1289
|
+
set size(value) {
|
|
1290
|
+
this.setProperty("size", value);
|
|
1291
|
+
}
|
|
1292
|
+
get placement() {
|
|
1293
|
+
return this.getProperty("placement");
|
|
1294
|
+
}
|
|
1295
|
+
set placement(value) {
|
|
1296
|
+
this.setProperty("placement", value);
|
|
1297
|
+
}
|
|
1298
|
+
get flavor() {
|
|
1299
|
+
return this.getProperty("flavor");
|
|
1300
|
+
}
|
|
1301
|
+
set flavor(value) {
|
|
1302
|
+
this.setProperty("flavor", value);
|
|
1303
|
+
}
|
|
1304
|
+
get form() {
|
|
1305
|
+
return this._internals.form;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
TySelect.slotAssignment = "manual";
|
|
1309
|
+
TySelect.properties = {
|
|
1310
|
+
value: {
|
|
1311
|
+
type: "string",
|
|
1312
|
+
visual: true,
|
|
1313
|
+
formValue: true,
|
|
1314
|
+
emitChange: false,
|
|
1315
|
+
default: "",
|
|
1316
|
+
coerce: (v) => {
|
|
1317
|
+
if (Array.isArray(v)) {
|
|
1318
|
+
return v.join(",");
|
|
1319
|
+
}
|
|
1320
|
+
if (v === null || v === undefined) {
|
|
1321
|
+
return "";
|
|
1322
|
+
}
|
|
1323
|
+
return String(v);
|
|
1324
|
+
},
|
|
1325
|
+
},
|
|
1326
|
+
name: {
|
|
1327
|
+
type: "string",
|
|
1328
|
+
default: "",
|
|
1329
|
+
},
|
|
1330
|
+
multiple: {
|
|
1331
|
+
type: "boolean",
|
|
1332
|
+
visual: true,
|
|
1333
|
+
default: false,
|
|
1334
|
+
},
|
|
1335
|
+
compact: {
|
|
1336
|
+
type: "boolean",
|
|
1337
|
+
visual: true,
|
|
1338
|
+
default: false,
|
|
1339
|
+
},
|
|
1340
|
+
placeholder: {
|
|
1341
|
+
type: "string",
|
|
1342
|
+
visual: true,
|
|
1343
|
+
default: "Select...",
|
|
1344
|
+
},
|
|
1345
|
+
label: {
|
|
1346
|
+
type: "string",
|
|
1347
|
+
visual: true,
|
|
1348
|
+
default: "",
|
|
1349
|
+
},
|
|
1350
|
+
disabled: {
|
|
1351
|
+
type: "boolean",
|
|
1352
|
+
visual: true,
|
|
1353
|
+
default: false,
|
|
1354
|
+
},
|
|
1355
|
+
readonly: {
|
|
1356
|
+
type: "boolean",
|
|
1357
|
+
visual: true,
|
|
1358
|
+
default: false,
|
|
1359
|
+
},
|
|
1360
|
+
required: {
|
|
1361
|
+
type: "boolean",
|
|
1362
|
+
visual: true,
|
|
1363
|
+
default: false,
|
|
1364
|
+
},
|
|
1365
|
+
error: {
|
|
1366
|
+
type: "string",
|
|
1367
|
+
visual: true,
|
|
1368
|
+
default: "",
|
|
1369
|
+
},
|
|
1370
|
+
noClear: {
|
|
1371
|
+
type: "boolean",
|
|
1372
|
+
visual: true,
|
|
1373
|
+
default: false,
|
|
1374
|
+
},
|
|
1375
|
+
externalSearch: {
|
|
1376
|
+
type: "boolean",
|
|
1377
|
+
visual: true,
|
|
1378
|
+
default: false,
|
|
1379
|
+
},
|
|
1380
|
+
externalSelection: {
|
|
1381
|
+
type: "boolean",
|
|
1382
|
+
visual: true,
|
|
1383
|
+
default: false,
|
|
1384
|
+
},
|
|
1385
|
+
allowCreate: {
|
|
1386
|
+
type: "boolean",
|
|
1387
|
+
visual: true,
|
|
1388
|
+
default: false,
|
|
1389
|
+
},
|
|
1390
|
+
createTransform: {
|
|
1391
|
+
type: "string",
|
|
1392
|
+
visual: false,
|
|
1393
|
+
default: "none",
|
|
1394
|
+
coerce: (v) => (v === "slug" ? "slug" : "none"),
|
|
1395
|
+
},
|
|
1396
|
+
notSearchable: {
|
|
1397
|
+
type: "boolean",
|
|
1398
|
+
visual: true,
|
|
1399
|
+
default: false,
|
|
1400
|
+
},
|
|
1401
|
+
placement: {
|
|
1402
|
+
type: "string",
|
|
1403
|
+
visual: true,
|
|
1404
|
+
default: "",
|
|
1405
|
+
},
|
|
1406
|
+
size: {
|
|
1407
|
+
type: "string",
|
|
1408
|
+
visual: true,
|
|
1409
|
+
default: DEFAULT_SIZE,
|
|
1410
|
+
validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
|
|
1411
|
+
coerce: (v) => {
|
|
1412
|
+
if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
|
|
1413
|
+
console.warn(`[ty-select] Invalid size. Using ${DEFAULT_SIZE}.`);
|
|
1414
|
+
return DEFAULT_SIZE;
|
|
1415
|
+
}
|
|
1416
|
+
return v;
|
|
1417
|
+
},
|
|
1418
|
+
},
|
|
1419
|
+
debounce: {
|
|
1420
|
+
type: "number",
|
|
1421
|
+
default: 0,
|
|
1422
|
+
validate: (v) => v >= 0 && v <= 5000,
|
|
1423
|
+
coerce: (v) => {
|
|
1424
|
+
const num = Number(v);
|
|
1425
|
+
if (isNaN(num))
|
|
1426
|
+
return 0;
|
|
1427
|
+
return Math.max(0, Math.min(5000, num));
|
|
1428
|
+
},
|
|
1429
|
+
},
|
|
1430
|
+
"available-label": {
|
|
1431
|
+
type: "string",
|
|
1432
|
+
visual: true,
|
|
1433
|
+
default: "Available",
|
|
1434
|
+
},
|
|
1435
|
+
"selected-label": {
|
|
1436
|
+
type: "string",
|
|
1437
|
+
visual: true,
|
|
1438
|
+
default: "Selected",
|
|
1439
|
+
},
|
|
1440
|
+
"no-options-message": {
|
|
1441
|
+
type: "string",
|
|
1442
|
+
visual: true,
|
|
1443
|
+
default: "No options available",
|
|
1444
|
+
},
|
|
1445
|
+
loading: {
|
|
1446
|
+
type: "boolean",
|
|
1447
|
+
visual: true,
|
|
1448
|
+
default: false,
|
|
1449
|
+
},
|
|
1450
|
+
flavor: {
|
|
1451
|
+
type: "string",
|
|
1452
|
+
visual: true,
|
|
1453
|
+
default: "neutral",
|
|
1454
|
+
},
|
|
1455
|
+
};
|
|
1456
|
+
if (!customElements.get("ty-select")) {
|
|
1457
|
+
customElements.define("ty-select", TySelect);
|
|
1458
|
+
}
|