tyrell-components 1.0.0-TC9 → 1.0.0-rc.21

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