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.
Files changed (393) hide show
  1. package/AGENTS.md +122 -0
  2. package/CHANGELOG.md +1541 -0
  3. package/README.md +71 -53
  4. package/bin/tyrell.mjs +77 -0
  5. package/css/tyrell-colors-static.css +1 -0
  6. package/css/tyrell-theme.css +1 -0
  7. package/css/tyrell.css +1 -1783
  8. package/dist/tyrell-colors-static.css +1 -0
  9. package/dist/tyrell-theme.css +1 -0
  10. package/dist/tyrell.css +1 -1783
  11. package/dist/tyrell.js +1 -1
  12. package/guides/AGENT_INSTRUCTIONS.md +124 -0
  13. package/guides/AI_GUIDE.md +53 -0
  14. package/guides/CSS_GUIDE.md +1016 -0
  15. package/guides/DATASTAR_TY_GUIDE.md +657 -0
  16. package/guides/ICONS_GUIDE.md +212 -0
  17. package/guides/TY_GUIDE.md +937 -0
  18. package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
  19. package/guides/clj/CODE_SPLITTING.md +279 -0
  20. package/guides/clj/COMPONENT_GUIDE.md +391 -0
  21. package/guides/clj/HELIX_TY_GUIDE.md +428 -0
  22. package/guides/clj/I18N_GUIDE.md +478 -0
  23. package/guides/clj/LAYOUT_GUIDE.md +273 -0
  24. package/guides/clj/QUICKSTART.md +266 -0
  25. package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
  26. package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
  27. package/guides/clj/ROUTING_GUIDE.md +346 -0
  28. package/guides/clj/UIX_TY_GUIDE.md +319 -0
  29. package/guides/js/HTMX_TY_GUIDE.md +252 -0
  30. package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
  31. package/guides/js/REACT_TY_GUIDE.md +983 -0
  32. package/guides/js/SVELTE_TY_GUIDE.md +682 -0
  33. package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
  34. package/guides/js/VUE_TY_GUIDE.md +738 -0
  35. package/lib/base/ty-component.d.ts +57 -13
  36. package/lib/base/ty-component.js +266 -292
  37. package/lib/components/button.d.ts +33 -18
  38. package/lib/components/button.js +317 -267
  39. package/lib/components/calendar-month.d.ts +30 -47
  40. package/lib/components/calendar-month.js +455 -429
  41. package/lib/components/calendar-navigation.d.ts +41 -49
  42. package/lib/components/calendar-navigation.js +287 -346
  43. package/lib/components/calendar.d.ts +73 -83
  44. package/lib/components/calendar.js +837 -762
  45. package/lib/components/checkbox.d.ts +26 -75
  46. package/lib/components/checkbox.js +298 -391
  47. package/lib/components/copy.d.ts +20 -60
  48. package/lib/components/copy.js +276 -380
  49. package/lib/components/date-picker.d.ts +100 -183
  50. package/lib/components/date-picker.js +1155 -1570
  51. package/lib/components/file-upload.d.ts +16 -15
  52. package/lib/components/file-upload.js +436 -426
  53. package/lib/components/icon.d.ts +3 -24
  54. package/lib/components/icon.js +141 -230
  55. package/lib/components/input.d.ts +93 -108
  56. package/lib/components/input.js +734 -710
  57. package/lib/components/modal.d.ts +39 -29
  58. package/lib/components/modal.js +419 -438
  59. package/lib/components/option.d.ts +20 -35
  60. package/lib/components/option.js +184 -309
  61. package/lib/components/popup.d.ts +2 -17
  62. package/lib/components/popup.js +353 -347
  63. package/lib/components/radio.d.ts +33 -25
  64. package/lib/components/radio.js +433 -422
  65. package/lib/components/resize-observer.d.ts +3 -30
  66. package/lib/components/resize-observer.js +71 -103
  67. package/lib/components/scroll-container.d.ts +21 -14
  68. package/lib/components/scroll-container.js +292 -234
  69. package/lib/components/select.d.ts +458 -0
  70. package/lib/components/select.js +1458 -0
  71. package/lib/components/selected-tags.d.ts +60 -0
  72. package/lib/components/selected-tags.js +225 -0
  73. package/lib/components/sortable.d.ts +175 -0
  74. package/lib/components/sortable.js +1844 -0
  75. package/lib/components/step.d.ts +1 -6
  76. package/lib/components/step.js +62 -68
  77. package/lib/components/switch.d.ts +15 -15
  78. package/lib/components/switch.js +237 -231
  79. package/lib/components/tab.d.ts +50 -7
  80. package/lib/components/tab.js +203 -69
  81. package/lib/components/tabs.d.ts +19 -64
  82. package/lib/components/tabs.js +600 -618
  83. package/lib/components/tag.d.ts +14 -52
  84. package/lib/components/tag.js +231 -306
  85. package/lib/components/textarea.d.ts +58 -89
  86. package/lib/components/textarea.js +523 -573
  87. package/lib/components/tooltip.d.ts +8 -13
  88. package/lib/components/tooltip.js +322 -409
  89. package/lib/components/wizard.d.ts +7 -54
  90. package/lib/components/wizard.js +376 -606
  91. package/lib/icons/fontawesome/brands.d.ts +0 -1
  92. package/lib/icons/fontawesome/brands.js +0 -8
  93. package/lib/icons/fontawesome/regular.d.ts +0 -1
  94. package/lib/icons/fontawesome/regular.js +0 -8
  95. package/lib/icons/fontawesome/solid.d.ts +0 -1
  96. package/lib/icons/fontawesome/solid.js +0 -8
  97. package/lib/icons/heroicons/micro.d.ts +0 -1
  98. package/lib/icons/heroicons/micro.js +392 -400
  99. package/lib/icons/heroicons/mini.d.ts +0 -1
  100. package/lib/icons/heroicons/mini.js +382 -390
  101. package/lib/icons/heroicons/outline.d.ts +0 -1
  102. package/lib/icons/heroicons/outline.js +337 -345
  103. package/lib/icons/heroicons/solid.d.ts +0 -1
  104. package/lib/icons/heroicons/solid.js +407 -415
  105. package/lib/icons/lucide.d.ts +0 -1
  106. package/lib/icons/lucide.js +24479 -26351
  107. package/lib/icons/material/filled.d.ts +0 -1
  108. package/lib/icons/material/filled.js +9653 -9663
  109. package/lib/icons/material/outlined.d.ts +0 -1
  110. package/lib/icons/material/outlined.js +10271 -10281
  111. package/lib/icons/material/round.d.ts +0 -1
  112. package/lib/icons/material/round.js +10495 -10505
  113. package/lib/icons/material/sharp.d.ts +0 -1
  114. package/lib/icons/material/sharp.js +9905 -9915
  115. package/lib/icons/material/two-tone.d.ts +0 -1
  116. package/lib/icons/material/two-tone.js +12792 -12802
  117. package/lib/index.d.ts +7 -4
  118. package/lib/index.js +26 -39
  119. package/lib/styles/button.d.ts +24 -7
  120. package/lib/styles/button.js +285 -445
  121. package/lib/styles/calendar-month.d.ts +7 -6
  122. package/lib/styles/calendar-month.js +158 -226
  123. package/lib/styles/calendar-navigation.d.ts +2 -6
  124. package/lib/styles/calendar-navigation.js +108 -127
  125. package/lib/styles/calendar.d.ts +3 -3
  126. package/lib/styles/calendar.js +87 -23
  127. package/lib/styles/checkbox.d.ts +7 -6
  128. package/lib/styles/checkbox.js +101 -15
  129. package/lib/styles/copy.d.ts +3 -2
  130. package/lib/styles/copy.js +91 -71
  131. package/lib/styles/custom-scrollbar.d.ts +1 -2
  132. package/lib/styles/custom-scrollbar.js +80 -115
  133. package/lib/styles/date-picker.d.ts +4 -6
  134. package/lib/styles/date-picker.js +321 -388
  135. package/lib/styles/field-size.d.ts +6 -0
  136. package/lib/styles/field-size.js +91 -0
  137. package/lib/styles/file-upload.d.ts +1 -2
  138. package/lib/styles/file-upload.js +143 -188
  139. package/lib/styles/icon.d.ts +2 -6
  140. package/lib/styles/icon.js +92 -170
  141. package/lib/styles/input.d.ts +4 -7
  142. package/lib/styles/input.js +148 -643
  143. package/lib/styles/modal.d.ts +1 -2
  144. package/lib/styles/modal.js +127 -108
  145. package/lib/styles/option.d.ts +2 -6
  146. package/lib/styles/option.js +53 -96
  147. package/lib/styles/popup.d.ts +1 -2
  148. package/lib/styles/popup.js +47 -77
  149. package/lib/styles/radio.d.ts +3 -2
  150. package/lib/styles/radio.js +90 -116
  151. package/lib/styles/resize-observer.d.ts +1 -2
  152. package/lib/styles/resize-observer.js +2 -12
  153. package/lib/styles/scroll-container.d.ts +1 -2
  154. package/lib/styles/scroll-container.js +103 -146
  155. package/lib/styles/select-base.d.ts +8 -0
  156. package/lib/styles/select-base.js +752 -0
  157. package/lib/styles/select.d.ts +11 -0
  158. package/lib/styles/select.js +229 -0
  159. package/lib/styles/sortable.d.ts +16 -0
  160. package/lib/styles/sortable.js +85 -0
  161. package/lib/styles/step.d.ts +1 -2
  162. package/lib/styles/step.js +15 -34
  163. package/lib/styles/switch.d.ts +3 -2
  164. package/lib/styles/switch.js +52 -68
  165. package/lib/styles/tab.d.ts +1 -2
  166. package/lib/styles/tab.js +86 -34
  167. package/lib/styles/tabs.d.ts +3 -11
  168. package/lib/styles/tabs.js +204 -162
  169. package/lib/styles/tag.d.ts +2 -6
  170. package/lib/styles/tag.js +168 -362
  171. package/lib/styles/textarea.d.ts +1 -2
  172. package/lib/styles/textarea.js +238 -306
  173. package/lib/styles/tooltip.d.ts +4 -3
  174. package/lib/styles/tooltip.js +3 -131
  175. package/lib/styles/wizard.d.ts +8 -20
  176. package/lib/styles/wizard.js +306 -295
  177. package/lib/types/common.d.ts +9 -8
  178. package/lib/types/common.js +8 -5
  179. package/lib/utils/calendar-utils.d.ts +49 -65
  180. package/lib/utils/calendar-utils.js +158 -343
  181. package/lib/utils/custom-scrollbar.d.ts +6 -20
  182. package/lib/utils/custom-scrollbar.js +273 -317
  183. package/lib/utils/flavor-sheet.d.ts +31 -0
  184. package/lib/utils/flavor-sheet.js +17 -0
  185. package/lib/utils/icon-registry.d.ts +0 -15
  186. package/lib/utils/icon-registry.js +138 -279
  187. package/lib/utils/icons.d.ts +9 -0
  188. package/lib/utils/icons.js +1 -0
  189. package/lib/utils/loader-registry.d.ts +2 -3
  190. package/lib/utils/loader-registry.js +3 -35
  191. package/lib/utils/locale.d.ts +2 -80
  192. package/lib/utils/locale.js +30 -205
  193. package/lib/utils/mobile.d.ts +0 -1
  194. package/lib/utils/mobile.js +1 -18
  195. package/lib/utils/number-format.d.ts +6 -24
  196. package/lib/utils/number-format.js +53 -136
  197. package/lib/utils/positioning.d.ts +72 -22
  198. package/lib/utils/positioning.js +224 -298
  199. package/lib/utils/property-capture.d.ts +5 -27
  200. package/lib/utils/property-capture.js +36 -144
  201. package/lib/utils/property-manager.d.ts +6 -6
  202. package/lib/utils/property-manager.js +127 -196
  203. package/lib/utils/resize-observer.d.ts +0 -1
  204. package/lib/utils/resize-observer.js +23 -59
  205. package/lib/utils/scroll-lock.d.ts +10 -11
  206. package/lib/utils/scroll-lock.js +165 -173
  207. package/lib/utils/styles.d.ts +0 -6
  208. package/lib/utils/styles.js +17 -48
  209. package/lib/utils/upgrade-properties.d.ts +21 -0
  210. package/lib/utils/upgrade-properties.js +47 -0
  211. package/lib/utils/validity.d.ts +122 -0
  212. package/lib/utils/validity.js +289 -0
  213. package/lib/version.d.ts +1 -2
  214. package/lib/version.js +1 -11
  215. package/package.json +66 -18
  216. package/lib/base/ty-component.d.ts.map +0 -1
  217. package/lib/base/ty-component.js.map +0 -1
  218. package/lib/components/button.d.ts.map +0 -1
  219. package/lib/components/button.js.map +0 -1
  220. package/lib/components/calendar-month.d.ts.map +0 -1
  221. package/lib/components/calendar-month.js.map +0 -1
  222. package/lib/components/calendar-navigation.d.ts.map +0 -1
  223. package/lib/components/calendar-navigation.js.map +0 -1
  224. package/lib/components/calendar.d.ts.map +0 -1
  225. package/lib/components/calendar.js.map +0 -1
  226. package/lib/components/checkbox.d.ts.map +0 -1
  227. package/lib/components/checkbox.js.map +0 -1
  228. package/lib/components/copy.d.ts.map +0 -1
  229. package/lib/components/copy.js.map +0 -1
  230. package/lib/components/date-picker.d.ts.map +0 -1
  231. package/lib/components/date-picker.js.map +0 -1
  232. package/lib/components/dropdown.d.ts +0 -404
  233. package/lib/components/dropdown.d.ts.map +0 -1
  234. package/lib/components/dropdown.js +0 -1563
  235. package/lib/components/dropdown.js.map +0 -1
  236. package/lib/components/file-upload.d.ts.map +0 -1
  237. package/lib/components/file-upload.js.map +0 -1
  238. package/lib/components/icon.d.ts.map +0 -1
  239. package/lib/components/icon.js.map +0 -1
  240. package/lib/components/input.d.ts.map +0 -1
  241. package/lib/components/input.js.map +0 -1
  242. package/lib/components/modal.d.ts.map +0 -1
  243. package/lib/components/modal.js.map +0 -1
  244. package/lib/components/multiselect.d.ts +0 -408
  245. package/lib/components/multiselect.d.ts.map +0 -1
  246. package/lib/components/multiselect.js +0 -1611
  247. package/lib/components/multiselect.js.map +0 -1
  248. package/lib/components/option.d.ts.map +0 -1
  249. package/lib/components/option.js.map +0 -1
  250. package/lib/components/popup.d.ts.map +0 -1
  251. package/lib/components/popup.js.map +0 -1
  252. package/lib/components/radio.d.ts.map +0 -1
  253. package/lib/components/radio.js.map +0 -1
  254. package/lib/components/resize-observer.d.ts.map +0 -1
  255. package/lib/components/resize-observer.js.map +0 -1
  256. package/lib/components/scroll-container.d.ts.map +0 -1
  257. package/lib/components/scroll-container.js.map +0 -1
  258. package/lib/components/step.d.ts.map +0 -1
  259. package/lib/components/step.js.map +0 -1
  260. package/lib/components/switch.d.ts.map +0 -1
  261. package/lib/components/switch.js.map +0 -1
  262. package/lib/components/tab.d.ts.map +0 -1
  263. package/lib/components/tab.js.map +0 -1
  264. package/lib/components/tabs.d.ts.map +0 -1
  265. package/lib/components/tabs.js.map +0 -1
  266. package/lib/components/tag.d.ts.map +0 -1
  267. package/lib/components/tag.js.map +0 -1
  268. package/lib/components/textarea.d.ts.map +0 -1
  269. package/lib/components/textarea.js.map +0 -1
  270. package/lib/components/tooltip.d.ts.map +0 -1
  271. package/lib/components/tooltip.js.map +0 -1
  272. package/lib/components/wizard.d.ts.map +0 -1
  273. package/lib/components/wizard.js.map +0 -1
  274. package/lib/icons/fontawesome/brands.d.ts.map +0 -1
  275. package/lib/icons/fontawesome/brands.js.map +0 -1
  276. package/lib/icons/fontawesome/regular.d.ts.map +0 -1
  277. package/lib/icons/fontawesome/regular.js.map +0 -1
  278. package/lib/icons/fontawesome/solid.d.ts.map +0 -1
  279. package/lib/icons/fontawesome/solid.js.map +0 -1
  280. package/lib/icons/heroicons/micro.d.ts.map +0 -1
  281. package/lib/icons/heroicons/micro.js.map +0 -1
  282. package/lib/icons/heroicons/mini.d.ts.map +0 -1
  283. package/lib/icons/heroicons/mini.js.map +0 -1
  284. package/lib/icons/heroicons/outline.d.ts.map +0 -1
  285. package/lib/icons/heroicons/outline.js.map +0 -1
  286. package/lib/icons/heroicons/solid.d.ts.map +0 -1
  287. package/lib/icons/heroicons/solid.js.map +0 -1
  288. package/lib/icons/lucide.d.ts.map +0 -1
  289. package/lib/icons/lucide.js.map +0 -1
  290. package/lib/icons/material/filled.d.ts.map +0 -1
  291. package/lib/icons/material/filled.js.map +0 -1
  292. package/lib/icons/material/outlined.d.ts.map +0 -1
  293. package/lib/icons/material/outlined.js.map +0 -1
  294. package/lib/icons/material/round.d.ts.map +0 -1
  295. package/lib/icons/material/round.js.map +0 -1
  296. package/lib/icons/material/sharp.d.ts.map +0 -1
  297. package/lib/icons/material/sharp.js.map +0 -1
  298. package/lib/icons/material/two-tone.d.ts.map +0 -1
  299. package/lib/icons/material/two-tone.js.map +0 -1
  300. package/lib/index.d.ts.map +0 -1
  301. package/lib/index.js.map +0 -1
  302. package/lib/styles/button.d.ts.map +0 -1
  303. package/lib/styles/button.js.map +0 -1
  304. package/lib/styles/calendar-month.d.ts.map +0 -1
  305. package/lib/styles/calendar-month.js.map +0 -1
  306. package/lib/styles/calendar-navigation.d.ts.map +0 -1
  307. package/lib/styles/calendar-navigation.js.map +0 -1
  308. package/lib/styles/calendar.d.ts.map +0 -1
  309. package/lib/styles/calendar.js.map +0 -1
  310. package/lib/styles/checkbox.d.ts.map +0 -1
  311. package/lib/styles/checkbox.js.map +0 -1
  312. package/lib/styles/copy.d.ts.map +0 -1
  313. package/lib/styles/copy.js.map +0 -1
  314. package/lib/styles/custom-scrollbar.d.ts.map +0 -1
  315. package/lib/styles/custom-scrollbar.js.map +0 -1
  316. package/lib/styles/date-picker.d.ts.map +0 -1
  317. package/lib/styles/date-picker.js.map +0 -1
  318. package/lib/styles/dropdown.d.ts +0 -12
  319. package/lib/styles/dropdown.d.ts.map +0 -1
  320. package/lib/styles/dropdown.js +0 -1048
  321. package/lib/styles/dropdown.js.map +0 -1
  322. package/lib/styles/file-upload.d.ts.map +0 -1
  323. package/lib/styles/file-upload.js.map +0 -1
  324. package/lib/styles/icon.d.ts.map +0 -1
  325. package/lib/styles/icon.js.map +0 -1
  326. package/lib/styles/input.d.ts.map +0 -1
  327. package/lib/styles/input.js.map +0 -1
  328. package/lib/styles/modal.d.ts.map +0 -1
  329. package/lib/styles/modal.js.map +0 -1
  330. package/lib/styles/multiselect.d.ts +0 -6
  331. package/lib/styles/multiselect.d.ts.map +0 -1
  332. package/lib/styles/multiselect.js +0 -837
  333. package/lib/styles/multiselect.js.map +0 -1
  334. package/lib/styles/option.d.ts.map +0 -1
  335. package/lib/styles/option.js.map +0 -1
  336. package/lib/styles/popup.d.ts.map +0 -1
  337. package/lib/styles/popup.js.map +0 -1
  338. package/lib/styles/radio.d.ts.map +0 -1
  339. package/lib/styles/radio.js.map +0 -1
  340. package/lib/styles/resize-observer.d.ts.map +0 -1
  341. package/lib/styles/resize-observer.js.map +0 -1
  342. package/lib/styles/scroll-container.d.ts.map +0 -1
  343. package/lib/styles/scroll-container.js.map +0 -1
  344. package/lib/styles/step.d.ts.map +0 -1
  345. package/lib/styles/step.js.map +0 -1
  346. package/lib/styles/switch.d.ts.map +0 -1
  347. package/lib/styles/switch.js.map +0 -1
  348. package/lib/styles/tab.d.ts.map +0 -1
  349. package/lib/styles/tab.js.map +0 -1
  350. package/lib/styles/tabs.d.ts.map +0 -1
  351. package/lib/styles/tabs.js.map +0 -1
  352. package/lib/styles/tag.d.ts.map +0 -1
  353. package/lib/styles/tag.js.map +0 -1
  354. package/lib/styles/textarea.d.ts.map +0 -1
  355. package/lib/styles/textarea.js.map +0 -1
  356. package/lib/styles/tooltip.d.ts.map +0 -1
  357. package/lib/styles/tooltip.js.map +0 -1
  358. package/lib/styles/wizard.d.ts.map +0 -1
  359. package/lib/styles/wizard.js.map +0 -1
  360. package/lib/types/common.d.ts.map +0 -1
  361. package/lib/types/common.js.map +0 -1
  362. package/lib/utils/calendar-utils.d.ts.map +0 -1
  363. package/lib/utils/calendar-utils.js.map +0 -1
  364. package/lib/utils/custom-scrollbar.d.ts.map +0 -1
  365. package/lib/utils/custom-scrollbar.js.map +0 -1
  366. package/lib/utils/icon-registry.d.ts.map +0 -1
  367. package/lib/utils/icon-registry.js.map +0 -1
  368. package/lib/utils/loader-registry.d.ts.map +0 -1
  369. package/lib/utils/loader-registry.js.map +0 -1
  370. package/lib/utils/locale.d.ts.map +0 -1
  371. package/lib/utils/locale.js.map +0 -1
  372. package/lib/utils/mobile.d.ts.map +0 -1
  373. package/lib/utils/mobile.js.map +0 -1
  374. package/lib/utils/number-format.d.ts.map +0 -1
  375. package/lib/utils/number-format.js.map +0 -1
  376. package/lib/utils/parse-boolean.d.ts +0 -39
  377. package/lib/utils/parse-boolean.d.ts.map +0 -1
  378. package/lib/utils/parse-boolean.js +0 -58
  379. package/lib/utils/parse-boolean.js.map +0 -1
  380. package/lib/utils/positioning.d.ts.map +0 -1
  381. package/lib/utils/positioning.js.map +0 -1
  382. package/lib/utils/property-capture.d.ts.map +0 -1
  383. package/lib/utils/property-capture.js.map +0 -1
  384. package/lib/utils/property-manager.d.ts.map +0 -1
  385. package/lib/utils/property-manager.js.map +0 -1
  386. package/lib/utils/resize-observer.d.ts.map +0 -1
  387. package/lib/utils/resize-observer.js.map +0 -1
  388. package/lib/utils/scroll-lock.d.ts.map +0 -1
  389. package/lib/utils/scroll-lock.js.map +0 -1
  390. package/lib/utils/styles.d.ts.map +0 -1
  391. package/lib/utils/styles.js.map +0 -1
  392. package/lib/version.d.ts.map +0 -1
  393. package/lib/version.js.map +0 -1
@@ -1,1611 +0,0 @@
1
- /**
2
- * TyMultiselect Web Component
3
- * PORTED FROM: clj/ty/components/multiselect.cljs
4
- *
5
- * A multiselect dropdown component using ty-tag for selections with:
6
- * - Tag-only options (only ty-tag elements supported)
7
- * - Multiple selection with visual tags
8
- * - Desktop mode with smart positioning
9
- * - Mobile mode with full-screen modal
10
- * - Search and filtering capabilities
11
- * - Keyboard navigation
12
- * - Form association for native form submission with multiple values
13
- * - Scroll locking when dropdown is open
14
- * - Outside click to close
15
- *
16
- * @example
17
- * ```html
18
- * <!-- Basic multiselect -->
19
- * <ty-multiselect label="Skills" placeholder="Select skills" required>
20
- * <ty-tag value="js">JavaScript</ty-tag>
21
- * <ty-tag value="ts">TypeScript</ty-tag>
22
- * <ty-tag value="py">Python</ty-tag>
23
- * </ty-multiselect>
24
- *
25
- * <!-- With pre-selected values -->
26
- * <ty-multiselect value="js,ts">
27
- * <ty-tag value="js">JavaScript</ty-tag>
28
- * <ty-tag value="ts">TypeScript</ty-tag>
29
- * <ty-tag value="py">Python</ty-tag>
30
- * </ty-multiselect>
31
- *
32
- * <!-- With rich tag content -->
33
- * <ty-multiselect label="Team Members">
34
- * <ty-tag value="1" flavor="primary">
35
- * <div class="flex items-center gap-2">
36
- * <img src="avatar1.jpg" class="w-6 h-6 rounded-full" />
37
- * <span>John Doe</span>
38
- * </div>
39
- * </ty-tag>
40
- * </ty-multiselect>
41
- * ```
42
- */
43
- import { ensureStyles } from '../utils/styles.js';
44
- import { multiselectStyles } from '../styles/multiselect.js';
45
- import { getLoaderSvg } from '../utils/loader-registry.js';
46
- import { lockScroll, unlockScroll } from '../utils/scroll-lock.js';
47
- import { isMobileTouch } from '../utils/mobile.js';
48
- import { TyComponent } from '../base/ty-component.js';
49
- import { CustomScrollbar, isCustomScrollbarEnabled } from '../utils/custom-scrollbar.js';
50
- // ============================================================================
51
- // Element Hash Utility (for consistent scroll lock IDs)
52
- // ============================================================================
53
- /**
54
- * Counter for generating unique element IDs
55
- */
56
- let elementIdCounter = 0;
57
- /**
58
- * WeakMap to store consistent element hashes
59
- * Automatically garbage collects when element is destroyed
60
- */
61
- const elementIds = new WeakMap();
62
- /**
63
- * Get a consistent unique ID for an element
64
- * Returns the same ID for the same element across multiple calls
65
- *
66
- * @param element - The element to hash
67
- * @returns A consistent numeric hash for the element
68
- */
69
- function getElementHash(element) {
70
- let id = elementIds.get(element);
71
- if (id === undefined) {
72
- id = ++elementIdCounter;
73
- elementIds.set(element, id);
74
- }
75
- return id;
76
- }
77
- // ============================================================================
78
- // SVG Icons
79
- // ============================================================================
80
- /**
81
- * Required indicator SVG icon (from Lucide)
82
- */
83
- const REQUIRED_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-asterisk"><path d="M12 6v12"/><path d="M17.196 9 6.804 15"/><path d="m6.804 9 10.392 6"/></svg>`;
84
- /**
85
- * Chevron down icon SVG
86
- */
87
- const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
88
- <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" />
89
- </svg>`;
90
- /**
91
- * Ty Multiselect Component
92
- */
93
- export class TyMultiselect extends TyComponent {
94
- // Debug: Log when expandedSection changes
95
- set expandedSection(value) {
96
- this._state.expandedSection = value;
97
- }
98
- get expandedSection() {
99
- return this._state.expandedSection;
100
- }
101
- constructor() {
102
- super(); // TyComponent handles attachInternals() and attachShadow()
103
- // ============================================================================
104
- // INTERNAL STATE
105
- // ============================================================================
106
- this._name = '';
107
- this._placeholder = 'Select options...';
108
- this._label = '';
109
- this._disabled = false;
110
- this._readonly = false;
111
- this._required = false;
112
- this._externalSearch = false;
113
- this._loading = false;
114
- this._scrollLockId = null;
115
- this._size = 'md';
116
- this._selectedLabel = 'Selected';
117
- this._availableLabel = 'Available';
118
- this._noSelectionMessage = 'No items selected';
119
- this._noOptionsMessage = 'No options available';
120
- // Component state
121
- this._state = {
122
- open: false,
123
- search: '',
124
- highlightedIndex: -1,
125
- filteredTags: [],
126
- selectedValues: [],
127
- mode: 'desktop', // Updated dynamically on render via syncMode()
128
- expandedSection: 'selected' // Will be corrected by toggleSection call
129
- };
130
- // Event handler references for cleanup
131
- this._stubClickHandler = null;
132
- this._tagClickHandler = null;
133
- this._tagDismissHandler = null;
134
- this._searchInputHandler = null;
135
- this._blockSearchClick = null;
136
- this._keyboardHandler = null;
137
- // Debounce properties for search event
138
- this._debounce = 0;
139
- this._searchDebounceTimer = null;
140
- // Custom scrollbar for options list
141
- this._optionsScrollbar = null;
142
- const shadow = this.shadowRoot;
143
- ensureStyles(shadow, { css: multiselectStyles, id: 'ty-multiselect' });
144
- // DON'T render here - wait for onConnect() to initialize values first
145
- // This matches dropdown.ts pattern and prevents showing empty state
146
- }
147
- /**
148
- * Called when component is connected to DOM
149
- * TyComponent handles property capture automatically
150
- */
151
- onConnect() {
152
- // SAFETY: Close any open dialogs to prevent scroll locking
153
- const shadow = this.shadowRoot;
154
- const dialogs = shadow.querySelectorAll('dialog');
155
- dialogs.forEach(dialog => {
156
- if (dialog.open) {
157
- console.warn('⚠️ Found open dialog on connect, closing it');
158
- dialog.close();
159
- }
160
- });
161
- // Render FIRST to create DOM structure
162
- this.render();
163
- // THEN initialize and sync tags (after DOM exists)
164
- requestAnimationFrame(() => {
165
- this.initializeState();
166
- // Visual updates happen automatically via onPropertiesChanged
167
- });
168
- }
169
- /**
170
- * Called when component is disconnected from DOM
171
- * Clean up event listeners and timers
172
- */
173
- onDisconnect() {
174
- // CRITICAL: Close all dialogs to prevent scroll locking
175
- const shadow = this.shadowRoot;
176
- const dialogs = shadow.querySelectorAll('dialog');
177
- dialogs.forEach(dialog => {
178
- if (dialog.open) {
179
- dialog.close();
180
- }
181
- });
182
- // Clean up document-level listeners
183
- if (this._keyboardHandler) {
184
- document.removeEventListener('keydown', this._keyboardHandler);
185
- this._keyboardHandler = null;
186
- }
187
- // Clear any pending debounce timer
188
- if (this._searchDebounceTimer !== null) {
189
- clearTimeout(this._searchDebounceTimer);
190
- this._searchDebounceTimer = null;
191
- }
192
- // Cleanup custom scrollbar
193
- this._destroyOptionsScrollbar();
194
- }
195
- /**
196
- * Called when properties change
197
- * Handle state synchronization BEFORE render
198
- */
199
- onPropertiesChanged(changes) {
200
- for (const { name, newValue } of changes) {
201
- switch (name) {
202
- case 'value':
203
- const selectedValues = this.parseValue(newValue);
204
- this._state.selectedValues = selectedValues;
205
- // CRITICAL: Only sync tags if we're connected and tags exist
206
- // During initial property setup (before onConnect), tags don't exist yet
207
- if (this.isConnected && this.shadowRoot) {
208
- this.syncSelectedTags(selectedValues);
209
- this.updateSelectionDisplay();
210
- this.updateMobileSelectedState();
211
- }
212
- else {
213
- console.warn('💜 [multiselect] onPropertiesChanged - NOT connected yet, skipping sync (will happen in initializeState)');
214
- }
215
- break;
216
- case 'name':
217
- this._name = newValue || '';
218
- break;
219
- case 'placeholder':
220
- this._placeholder = newValue || 'Select options...';
221
- // No need to update display - placeholder text change doesn't affect visibility
222
- break;
223
- case 'label':
224
- this._label = newValue || '';
225
- break;
226
- case 'disabled':
227
- this._disabled = newValue;
228
- break;
229
- case 'readonly':
230
- this._readonly = newValue;
231
- break;
232
- case 'required':
233
- this._required = newValue;
234
- break;
235
- case 'externalSearch':
236
- this._externalSearch = newValue;
237
- break;
238
- case 'size':
239
- this._size = newValue;
240
- break;
241
- case 'debounce':
242
- this._debounce = newValue;
243
- break;
244
- case 'selected-label':
245
- this._selectedLabel = newValue || 'Selected';
246
- break;
247
- case 'available-label':
248
- this._availableLabel = newValue || 'Available';
249
- break;
250
- case 'no-selection-message':
251
- this._noSelectionMessage = newValue || 'No items selected';
252
- break;
253
- case 'no-options-message':
254
- this._noOptionsMessage = newValue || 'No options available';
255
- break;
256
- case 'loading':
257
- this._loading = newValue;
258
- this.applyLoadingState();
259
- break;
260
- }
261
- }
262
- }
263
- /**
264
- * Toggle the loading visual state on the open popup.
265
- * Replaces the available-options area with a centered spinner; search input stays usable.
266
- * Pulls the latest registered loader SVG on each call so registry changes
267
- * take effect on the next loading toggle.
268
- */
269
- applyLoadingState() {
270
- const shadow = this.shadowRoot;
271
- if (!shadow)
272
- return;
273
- const svg = this._loading ? getLoaderSvg() : null;
274
- shadow.querySelectorAll('.dropdown-options-wrapper').forEach((wrapper) => {
275
- wrapper.classList.toggle('loading', this._loading);
276
- if (this._loading) {
277
- wrapper.setAttribute('aria-busy', 'true');
278
- const spinner = wrapper.querySelector('.dropdown-loading-spinner');
279
- if (spinner && svg)
280
- spinner.innerHTML = svg;
281
- }
282
- else {
283
- wrapper.removeAttribute('aria-busy');
284
- }
285
- });
286
- }
287
- /**
288
- * Get the form value for this component
289
- * Returns FormData with multiple entries (HTMX standard)
290
- */
291
- getFormValue() {
292
- const selectedValues = this._state.selectedValues;
293
- if (this._name && selectedValues.length > 0) {
294
- const formData = new FormData();
295
- selectedValues.forEach(value => {
296
- formData.append(this._name, value);
297
- });
298
- return formData;
299
- }
300
- return null;
301
- }
302
- /**
303
- * Parse multiselect value (comma-separated string to array)
304
- */
305
- parseValue(value) {
306
- // Defensive check: ensure value is actually a string before calling .trim()
307
- if (!value || typeof value !== 'string' || value.trim() === '')
308
- return [];
309
- return value.split(',').map(v => v.trim()).filter(v => v !== '');
310
- }
311
- /**
312
- * Initialize component state from attributes
313
- * Reads from both property and attribute (like ClojureScript version)
314
- */
315
- initializeState() {
316
- const initialValue = this.getProperty('value') || '';
317
- if (initialValue) {
318
- // Explicit value provided - sync tags directly
319
- // DON'T use updateComponentValue() because the property is already set!
320
- const selectedValues = this.parseValue(initialValue);
321
- // Update internal state
322
- this._state.selectedValues = selectedValues;
323
- // Sync the tags to match the property value
324
- this.syncSelectedTags(selectedValues);
325
- // Update the visual display
326
- this.updateSelectionDisplay();
327
- this.updateMobileSelectedState();
328
- }
329
- else {
330
- // No explicit value - check for pre-selected tags
331
- const allTags = this.getTagElements();
332
- const preSelectedTags = allTags
333
- .filter(tag => tag.hasAttribute('selected'))
334
- .map(tag => this.getTagData(tag).value);
335
- if (preSelectedTags.length > 0) {
336
- // Set the property value and sync (updateComponentValue handles everything)
337
- this.updateComponentValue(preSelectedTags, false);
338
- }
339
- }
340
- }
341
- // ============================================================================
342
- // TAG MANAGEMENT METHODS (Phase 2)
343
- // ============================================================================
344
- /**
345
- * Get all ty-tag elements from the component (ALL slots)
346
- */
347
- getTagElements() {
348
- // Get ALL ty-tag children, regardless of slot assignment
349
- const tags = Array.from(this.querySelectorAll('ty-tag'));
350
- return tags;
351
- }
352
- /**
353
- * Extract value and text from a ty-tag element
354
- */
355
- getTagData(element) {
356
- // Get value from either property or attribute
357
- const value = element.value || element.getAttribute('value') || element.textContent || '';
358
- const text = element.textContent || '';
359
- return { value, text, element };
360
- }
361
- /**
362
- * Select a tag - set selected state, move to selected slot, make dismissible
363
- */
364
- selectTag(tag) {
365
- const tagValue = this.getTagData(tag).value;
366
- // Set selected attribute
367
- tag.setAttribute('selected', '');
368
- // Move to selected slot
369
- tag.setAttribute('slot', 'selected');
370
- // Make dismissible
371
- tag.setAttribute('dismissible', 'true');
372
- // Force re-slotting by removing and re-adding
373
- const parent = tag.parentNode;
374
- if (parent) {
375
- parent.removeChild(tag);
376
- parent.appendChild(tag);
377
- }
378
- else {
379
- console.warn(`⚠️ [multiselect] - No parent for "${tagValue}"!`);
380
- }
381
- }
382
- /**
383
- * Deselect a tag - remove selected state, remove from selected slot, remove dismissible
384
- */
385
- deselectTag(tag) {
386
- // Remove selected attribute
387
- tag.removeAttribute('selected');
388
- // Remove from selected slot
389
- tag.removeAttribute('slot');
390
- // Remove dismissible
391
- tag.removeAttribute('dismissible');
392
- // Force re-slotting by removing and re-adding
393
- const parent = tag.parentNode;
394
- if (parent) {
395
- parent.removeChild(tag);
396
- parent.appendChild(tag);
397
- }
398
- }
399
- /**
400
- * Get array of currently selected values from tags (ALWAYS reads from DOM)
401
- */
402
- getSelectedValues() {
403
- return this.getTagElements()
404
- .filter(tag => tag.hasAttribute('selected'))
405
- .map(tag => this.getTagData(tag).value)
406
- .filter(value => value !== '');
407
- }
408
- /**
409
- * Check if all available tags are selected
410
- */
411
- allTagsSelected() {
412
- const tags = this.getTagElements();
413
- if (tags.length === 0)
414
- return false;
415
- const selectedCount = tags.filter(tag => tag.hasAttribute('selected')).length;
416
- return selectedCount === tags.length;
417
- }
418
- /**
419
- * Sync tag selection states with desired values
420
- */
421
- syncSelectedTags(selectedValues) {
422
- const selectedSet = new Set(selectedValues);
423
- const tags = this.getTagElements();
424
- tags.forEach(tag => {
425
- const tagValue = this.getTagData(tag).value;
426
- const shouldBeSelected = selectedSet.has(tagValue);
427
- const isSelected = tag.hasAttribute('selected');
428
- if (shouldBeSelected && !isSelected) {
429
- this.selectTag(tag);
430
- }
431
- else if (!shouldBeSelected && isSelected) {
432
- this.deselectTag(tag);
433
- }
434
- });
435
- }
436
- /**
437
- * Central update function - synchronizes everything
438
- * Uses TyComponent's property system for proper lifecycle
439
- */
440
- updateComponentValue(newValues, dispatchChange = false, action = 'set', item = null) {
441
- const oldValues = this.getSelectedValues();
442
- const valueStr = newValues.join(',');
443
- // Only update if changed
444
- if (JSON.stringify(newValues.sort()) !== JSON.stringify(oldValues.sort())) {
445
- // Use TyComponent's property system - this will trigger:
446
- // 1. onPropertiesChanged() → syncs tags via syncSelectedTags()
447
- // 2. onPropertiesChanged() → updates placeholder via updateSelectionDisplay()
448
- // 3. updateFormValue() → automatic (formValue: true in config)
449
- // 4. render() → automatic if visual properties changed
450
- this.setProperty('value', valueStr);
451
- // Dispatch custom multiselect change event (with action/item details)
452
- if (dispatchChange) {
453
- this.dispatchChangeEvent({
454
- values: newValues,
455
- action,
456
- item
457
- });
458
- }
459
- }
460
- else {
461
- }
462
- }
463
- // ============================================================================
464
- // DROPDOWN METHODS (Phase 3 & 4)
465
- // ============================================================================
466
- /**
467
- * Calculate and set dropdown position with smart direction detection
468
- */
469
- calculatePosition() {
470
- const shadow = this.shadowRoot;
471
- const stub = shadow.querySelector('.multiselect-stub');
472
- const dialog = shadow.querySelector('.dropdown-dialog');
473
- if (!stub || !dialog)
474
- return;
475
- const stubRect = stub.getBoundingClientRect();
476
- const viewportHeight = window.innerHeight;
477
- const viewportWidth = window.innerWidth;
478
- // Get dialog dimensions (it's already shown with showModal)
479
- const dialogRect = dialog.getBoundingClientRect();
480
- const estimatedHeight = dialogRect.height || 200;
481
- const padding = 8;
482
- const wrapPadding = 20;
483
- // Available space calculations
484
- const spaceBelow = viewportHeight - stubRect.bottom;
485
- const spaceRight = viewportWidth - stubRect.left;
486
- // Smart direction logic
487
- const positionBelow = spaceBelow >= estimatedHeight + padding;
488
- const fitsHorizontally = spaceRight >= stubRect.width;
489
- // Calculate position coordinates
490
- const x = fitsHorizontally
491
- ? stubRect.left - wrapPadding
492
- : Math.max(padding, viewportWidth - stubRect.width - padding);
493
- const y = positionBelow
494
- ? stubRect.top - wrapPadding
495
- : viewportHeight - stubRect.bottom - wrapPadding;
496
- const width = stubRect.width + wrapPadding + wrapPadding;
497
- // Set CSS variables for positioning
498
- this.style.setProperty('--dropdown-x', `${x}px`);
499
- this.style.setProperty('--dropdown-y', `${y}px`);
500
- this.style.setProperty('--dropdown-width', `${width}px`);
501
- this.style.setProperty('--dropdown-offset-x', '0px');
502
- this.style.setProperty('--dropdown-offset-y', '0px');
503
- this.style.setProperty('--dropdown-padding', `${wrapPadding}px`);
504
- // Set direction classes for CSS styling
505
- if (positionBelow) {
506
- dialog.classList.add('position-below');
507
- dialog.classList.remove('position-above');
508
- }
509
- else {
510
- dialog.classList.add('position-above');
511
- dialog.classList.remove('position-below');
512
- }
513
- // Optional: Store direction for debugging
514
- this.style.setProperty('--dropdown-direction', positionBelow ? 'below' : 'above');
515
- }
516
- // ============================================================================
517
- // CUSTOM SCROLLBAR FOR OPTIONS
518
- // ============================================================================
519
- _setupOptionsScrollbar() {
520
- if (!isCustomScrollbarEnabled())
521
- return;
522
- const shadow = this.shadowRoot;
523
- const optionsDiv = shadow.querySelector('.dropdown-options');
524
- const optionsWrapper = shadow.querySelector('.dropdown-options-wrapper');
525
- if (!optionsDiv || !optionsWrapper)
526
- return;
527
- this._destroyOptionsScrollbar();
528
- optionsDiv.classList.add('ty-custom-scroll');
529
- this._optionsScrollbar = new CustomScrollbar(optionsDiv, { vertical: true });
530
- if (this._optionsScrollbar.trackY) {
531
- optionsWrapper.appendChild(this._optionsScrollbar.trackY);
532
- }
533
- }
534
- _destroyOptionsScrollbar() {
535
- if (this._optionsScrollbar) {
536
- this._optionsScrollbar.trackY?.remove();
537
- this._optionsScrollbar.destroy();
538
- this._optionsScrollbar = null;
539
- }
540
- }
541
- /**
542
- * Open dropdown dialog (desktop mode)
543
- *
544
- * `<dialog>.showModal()` puts the dialog in the top layer with a backdrop, but
545
- * does NOT prevent the page behind it from scrolling. We use the shared scroll
546
- * lock utility (overflow:hidden on <html>) to keep wheel/touch scrolling from
547
- * leaking through to the body — same behavior <ty-dropdown> and <ty-modal>
548
- * implement.
549
- */
550
- openDropdown() {
551
- const shadow = this.shadowRoot;
552
- const dialog = shadow.querySelector('.dropdown-dialog');
553
- if (!dialog)
554
- return;
555
- // Lock body scroll while dropdown is open
556
- const lockId = `multiselect-${this.id || 'anon'}-${getElementHash(this)}`;
557
- this._scrollLockId = lockId;
558
- lockScroll(lockId);
559
- // Show modal
560
- dialog.showModal();
561
- dialog.classList.add('open');
562
- // Position dropdown AFTER showing modal
563
- this.calculatePosition();
564
- // Update component state
565
- this._state.open = true;
566
- // Update visual states
567
- const chevron = shadow.querySelector('.dropdown-chevron');
568
- if (chevron)
569
- chevron.classList.add('open');
570
- const searchChevron = shadow.querySelector('.dropdown-search-chevron');
571
- if (searchChevron)
572
- searchChevron.classList.add('open');
573
- // Initialize options state
574
- const tags = this.getTagElements().map(el => this.getTagData(el));
575
- this._state.filteredTags = tags;
576
- this._state.highlightedIndex = -1;
577
- // Ensure options area is visible (may have been hidden from previous search)
578
- this.updateOptionsVisibility(true);
579
- // Setup custom scrollbar on options
580
- this._setupOptionsScrollbar();
581
- // Focus search input
582
- const searchInput = shadow.querySelector('.dropdown-search-input');
583
- if (searchInput) {
584
- setTimeout(() => searchInput.focus(), 100);
585
- }
586
- }
587
- /**
588
- * Close dropdown dialog (desktop mode)
589
- */
590
- closeDropdown() {
591
- const shadow = this.shadowRoot;
592
- const dialog = shadow.querySelector('.dropdown-dialog');
593
- if (!dialog)
594
- return;
595
- // Destroy custom scrollbar
596
- this._destroyOptionsScrollbar();
597
- // Close dialog
598
- dialog.classList.remove('open');
599
- dialog.classList.remove('position-above');
600
- dialog.classList.remove('position-below');
601
- dialog.close();
602
- // Unlock body scroll (paired with the lock in openDropdown)
603
- if (this._scrollLockId) {
604
- unlockScroll(this._scrollLockId);
605
- this._scrollLockId = null;
606
- }
607
- // Update state
608
- this._state.open = false;
609
- this._state.highlightedIndex = -1;
610
- // Update visual states
611
- const chevron = shadow.querySelector('.dropdown-chevron');
612
- if (chevron)
613
- chevron.classList.remove('open');
614
- const searchChevron = shadow.querySelector('.dropdown-search-chevron');
615
- if (searchChevron)
616
- searchChevron.classList.remove('open');
617
- // Reset search and restore all tags
618
- const hadQuery = this._state.search !== '';
619
- this._state.search = '';
620
- const searchInput = shadow.querySelector('.dropdown-search-input');
621
- if (searchInput) {
622
- searchInput.value = '';
623
- }
624
- if (this._externalSearch) {
625
- // External mode — notify consumer so it can reset its own filtered state.
626
- // Bypass the debounce timer (which would delay the clear by `debounce` ms);
627
- // close-time should be immediate so the consumer's filtered state syncs
628
- // before the dropdown reopens. Only fire if there was actually a query.
629
- if (hadQuery) {
630
- if (this._searchDebounceTimer !== null) {
631
- clearTimeout(this._searchDebounceTimer);
632
- this._searchDebounceTimer = null;
633
- }
634
- this.fireSearchEvent('');
635
- }
636
- }
637
- else {
638
- // Internal mode — restore visibility of all tags ourselves
639
- const allTags = this.getTagElements().map(el => this.getTagData(el));
640
- this._state.filteredTags = allTags;
641
- this.updateTagVisibility(allTags, allTags);
642
- this.clearHighlights(allTags);
643
- }
644
- }
645
- /**
646
- * Open mobile modal (mobile mode)
647
- * Now using <dialog> element for native z-index management
648
- */
649
- openMobileModal() {
650
- const shadow = this.shadowRoot;
651
- const dialog = shadow.querySelector('.mobile-dialog');
652
- if (!dialog)
653
- return;
654
- // Lock body scroll while mobile modal is open
655
- const lockId = `multiselect-${this.id || 'anon'}-${getElementHash(this)}`;
656
- this._scrollLockId = lockId;
657
- lockScroll(lockId);
658
- // Show dialog using native API (handles z-index automatically)
659
- dialog.showModal();
660
- dialog.classList.add('open');
661
- const stub_slot = shadow.querySelector('#stub-slot');
662
- const mobile_slot = shadow.querySelector('#mobile-slot');
663
- stub_slot.name = "selected-blocked";
664
- mobile_slot.name = "selected";
665
- // Update component state
666
- this._state.open = true;
667
- // Initialize options state
668
- const tags = this.getTagElements().map(el => this.getTagData(el));
669
- this._state.filteredTags = tags;
670
- // Focus search input
671
- const searchInput = shadow.querySelector('.mobile-search-input');
672
- if (searchInput) {
673
- // Small delay to ensure dialog is ready
674
- setTimeout(() => searchInput.focus(), 100);
675
- }
676
- // Initialize sections (available expanded by default)
677
- this._state.expandedSection = 'available';
678
- this.syncSectionStates();
679
- // Update state after slots are ready
680
- requestAnimationFrame(() => {
681
- this.updateMobileSelectedState();
682
- });
683
- }
684
- /**
685
- * Close mobile modal (mobile mode)
686
- * Now using <dialog> element for native management
687
- */
688
- closeMobileModal() {
689
- const shadow = this.shadowRoot;
690
- const dialog = shadow.querySelector('.mobile-dialog');
691
- if (!dialog)
692
- return;
693
- // Close immediately — ::backdrop doesn't support transitions
694
- dialog.classList.remove('open');
695
- dialog.close();
696
- // Unlock body scroll (paired with the lock in openMobileModal)
697
- if (this._scrollLockId) {
698
- unlockScroll(this._scrollLockId);
699
- this._scrollLockId = null;
700
- }
701
- const stub_slot = shadow.querySelector('#stub-slot');
702
- const mobile_slot = shadow.querySelector('#mobile-slot');
703
- stub_slot.name = "selected";
704
- mobile_slot.name = "selected-blocked";
705
- // Update state
706
- this._state.open = false;
707
- this._state.highlightedIndex = -1;
708
- // Reset search
709
- const hadQuery = this._state.search !== '';
710
- this._state.search = '';
711
- const searchInput = shadow.querySelector('.mobile-search-input');
712
- if (searchInput) {
713
- searchInput.value = '';
714
- }
715
- if (this._externalSearch) {
716
- // External mode — notify consumer that the search was cleared on close
717
- // (bypass debounce, see desktop close path for rationale).
718
- if (hadQuery) {
719
- if (this._searchDebounceTimer !== null) {
720
- clearTimeout(this._searchDebounceTimer);
721
- this._searchDebounceTimer = null;
722
- }
723
- this.fireSearchEvent('');
724
- }
725
- }
726
- else {
727
- // Internal mode — unhide all tags ourselves
728
- const allTags = this.getTagElements();
729
- allTags.forEach(el => el.removeAttribute('hidden'));
730
- }
731
- }
732
- // ============================================================================
733
- // EVENT HANDLERS (Phase 5 & 6)
734
- // ============================================================================
735
- handleStubClick(e) {
736
- e.preventDefault();
737
- e.stopPropagation();
738
- if (this._disabled || this._readonly) {
739
- return;
740
- }
741
- // Don't open if all tags are already selected
742
- if (this.allTagsSelected()) {
743
- return;
744
- }
745
- this.openDropdown();
746
- }
747
- handleTagClick(e) {
748
- const target = e.target;
749
- // Find the ty-tag element
750
- const tag = target.tagName === 'TY-TAG'
751
- ? target
752
- : target.closest('ty-tag');
753
- if (!tag || tag.hasAttribute('disabled'))
754
- return;
755
- if (tag.hasAttribute('selected'))
756
- return; // Already selected
757
- e.preventDefault();
758
- e.stopPropagation();
759
- const tagValue = this.getTagData(tag).value;
760
- const currentValues = this.getSelectedValues();
761
- const newValues = [...currentValues, tagValue];
762
- // Use central update function with change event
763
- this.updateComponentValue(newValues, true, 'add', tagValue);
764
- // Auto-close if all tags selected
765
- if (this.allTagsSelected()) {
766
- if (this._state.mode === 'desktop') {
767
- this.closeDropdown();
768
- }
769
- else {
770
- this.closeMobileModal();
771
- }
772
- }
773
- }
774
- handleTagDismiss(e) {
775
- e.preventDefault();
776
- e.stopPropagation();
777
- const customEvent = e;
778
- const tag = customEvent.detail?.target;
779
- if (!tag)
780
- return;
781
- const tagValue = this.getTagData(tag).value;
782
- const currentValues = this.getSelectedValues();
783
- const newValues = currentValues.filter(v => v !== tagValue);
784
- // Use central update function with change event
785
- this.updateComponentValue(newValues, true, 'remove', tagValue);
786
- }
787
- blockSearchClick(e) {
788
- e.stopPropagation();
789
- e.preventDefault();
790
- }
791
- handleSearchInput(e) {
792
- const target = e.target;
793
- const query = target.value;
794
- // Update search state
795
- this._state.search = query;
796
- if (this._externalSearch) {
797
- // External (remote) search: parent owns filtering — delegate via event.
798
- // Tag visibility is left untouched; consumer is expected to update children.
799
- this.dispatchSearchEvent(query);
800
- return;
801
- }
802
- // Internal search: filter tags locally
803
- const allTags = this.getTagElements().map(el => this.getTagData(el));
804
- // Only filter from non-selected tags
805
- const availableTags = allTags.filter(t => !t.element.hasAttribute('selected'));
806
- const filtered = this.filterTags(availableTags, query);
807
- // Update state
808
- this._state.filteredTags = filtered;
809
- this._state.highlightedIndex = -1;
810
- // Update visibility
811
- this.updateTagVisibility(filtered, allTags);
812
- // Hide options area if no results
813
- this.updateOptionsVisibility(filtered.length > 0);
814
- // Clear highlights
815
- this.clearHighlights(allTags);
816
- }
817
- handleKeyboard(e) {
818
- if (!this._state.open)
819
- return;
820
- const shadow = this.shadowRoot;
821
- const searchInput = shadow.querySelector('.dropdown-search-input');
822
- const target = e.target;
823
- // Only handle navigation keys when dropdown is open and either:
824
- // 1. Event comes from search input, OR
825
- // 2. Event comes from document but search input is not focused
826
- const shouldHandle = target === searchInput ||
827
- document.activeElement !== searchInput;
828
- if (!shouldHandle)
829
- return;
830
- // Get current state values
831
- const filteredTags = this._state.filteredTags;
832
- const tagsCount = filteredTags.length;
833
- const currentHighlightedIndex = this._state.highlightedIndex;
834
- switch (e.key) {
835
- case 'Escape':
836
- e.preventDefault();
837
- e.stopPropagation();
838
- this.closeDropdown();
839
- break;
840
- case 'Enter':
841
- e.preventDefault();
842
- e.stopPropagation();
843
- // Select highlighted tag if any
844
- if (currentHighlightedIndex >= 0 && currentHighlightedIndex < tagsCount) {
845
- const tag = filteredTags[currentHighlightedIndex];
846
- this.handleTagClick({ target: tag.element });
847
- }
848
- break;
849
- case 'ArrowUp':
850
- e.preventDefault();
851
- e.stopPropagation();
852
- let newIndexUp;
853
- if (tagsCount === 0) {
854
- newIndexUp = -1;
855
- }
856
- else if (currentHighlightedIndex === -1) {
857
- // Nothing highlighted, go to last tag
858
- newIndexUp = tagsCount - 1;
859
- }
860
- else if (currentHighlightedIndex === 0) {
861
- // At first tag, wrap to last
862
- newIndexUp = tagsCount - 1;
863
- }
864
- else {
865
- // Move up one
866
- newIndexUp = currentHighlightedIndex - 1;
867
- }
868
- this._state.highlightedIndex = newIndexUp;
869
- this.highlightTag(filteredTags, newIndexUp);
870
- break;
871
- case 'ArrowDown':
872
- e.preventDefault();
873
- e.stopPropagation();
874
- let newIndexDown;
875
- if (tagsCount === 0) {
876
- newIndexDown = -1;
877
- }
878
- else if (currentHighlightedIndex === -1) {
879
- // Nothing highlighted, go to first tag
880
- newIndexDown = 0;
881
- }
882
- else if (currentHighlightedIndex === tagsCount - 1) {
883
- // At last tag, wrap to first
884
- newIndexDown = 0;
885
- }
886
- else {
887
- // Move down one
888
- newIndexDown = currentHighlightedIndex + 1;
889
- }
890
- this._state.highlightedIndex = newIndexDown;
891
- this.highlightTag(filteredTags, newIndexDown);
892
- break;
893
- }
894
- }
895
- // ============================================================================
896
- // SEARCH & FILTERING HELPERS (Phase 6)
897
- // ============================================================================
898
- /**
899
- * Filter tags based on search query
900
- */
901
- filterTags(tags, query) {
902
- if (!query || query.trim() === '') {
903
- return tags;
904
- }
905
- const searchLower = query.toLowerCase();
906
- return tags.filter(({ text }) => text.toLowerCase().includes(searchLower));
907
- }
908
- /**
909
- * Update visibility of tags based on filtered list
910
- */
911
- updateTagVisibility(filteredTags, allTags) {
912
- const visibleValues = new Set(filteredTags.map(tag => tag.value));
913
- allTags.forEach(({ value, element }) => {
914
- if (visibleValues.has(value)) {
915
- element.removeAttribute('hidden');
916
- }
917
- else {
918
- element.setAttribute('hidden', '');
919
- }
920
- });
921
- }
922
- /**
923
- * Show/hide the dropdown options area
924
- */
925
- updateOptionsVisibility(hasOptions) {
926
- const shadow = this.shadowRoot;
927
- const options = shadow.querySelector('.dropdown-options');
928
- if (options) {
929
- options.style.display = hasOptions ? '' : 'none';
930
- }
931
- }
932
- /**
933
- * Clear all tag highlights
934
- */
935
- clearHighlights(tags) {
936
- tags.forEach(({ element }) => {
937
- element.removeAttribute('highlighted');
938
- });
939
- }
940
- /**
941
- * Highlight tag at specific index
942
- */
943
- highlightTag(tags, index) {
944
- this.clearHighlights(tags);
945
- if (index >= 0 && index < tags.length) {
946
- const { element } = tags[index];
947
- element.setAttribute('highlighted', '');
948
- // Scroll into view
949
- element.scrollIntoView({
950
- behavior: 'smooth',
951
- block: 'nearest',
952
- inline: 'nearest'
953
- });
954
- }
955
- }
956
- /**
957
- * Dispatch search event for external search handling
958
- * With optional debounce support
959
- */
960
- dispatchSearchEvent(query) {
961
- // Clear existing timer
962
- if (this._searchDebounceTimer !== null) {
963
- clearTimeout(this._searchDebounceTimer);
964
- this._searchDebounceTimer = null;
965
- }
966
- // If debounce is set, debounce the event
967
- if (this._debounce > 0) {
968
- this._searchDebounceTimer = window.setTimeout(() => {
969
- this.fireSearchEvent(query);
970
- this._searchDebounceTimer = null;
971
- }, this._debounce);
972
- }
973
- else {
974
- // Fire immediately if no debounce
975
- this.fireSearchEvent(query);
976
- }
977
- }
978
- /**
979
- * Fire the actual search event
980
- */
981
- fireSearchEvent(query) {
982
- this.dispatchEvent(new CustomEvent('search', {
983
- detail: {
984
- query,
985
- element: this
986
- },
987
- bubbles: true,
988
- composed: true
989
- }));
990
- }
991
- // ============================================================================
992
- // CHANGE EVENT DISPATCHING (Phase 5)
993
- // ============================================================================
994
- /**
995
- * Dispatch custom change event
996
- */
997
- dispatchChangeEvent(detail) {
998
- this.dispatchEvent(new CustomEvent('change', {
999
- detail,
1000
- bubbles: true,
1001
- cancelable: true
1002
- }));
1003
- }
1004
- // ============================================================================
1005
- // RENDERING
1006
- // ============================================================================
1007
- /**
1008
- * Main render method (required by TyComponent)
1009
- * Delegates to mode-specific renderer
1010
- */
1011
- render() {
1012
- // Sync mode on every render so rotation/resize is picked up
1013
- this._state.mode = isMobileTouch() ? 'mobile' : 'desktop';
1014
- if (this._state.mode === 'mobile') {
1015
- this.renderMobile();
1016
- }
1017
- else {
1018
- this.renderDesktop();
1019
- }
1020
- // Loading wrapper is rendered dynamically — re-apply each render
1021
- this.applyLoadingState();
1022
- }
1023
- /**
1024
- * Setup event listeners
1025
- */
1026
- setupEventListeners() {
1027
- const shadow = this.shadowRoot;
1028
- const stub = shadow.querySelector('.multiselect-stub');
1029
- const optionsSlot = shadow.querySelector('#options-slot');
1030
- const searchInput = shadow.querySelector('.dropdown-search-input');
1031
- if (stub) {
1032
- this._stubClickHandler = this.handleStubClick.bind(this);
1033
- stub.addEventListener('click', this._stubClickHandler);
1034
- }
1035
- // Add tag click handler to slot
1036
- if (optionsSlot) {
1037
- this._tagClickHandler = this.handleTagClick.bind(this);
1038
- optionsSlot.addEventListener('click', this._tagClickHandler);
1039
- }
1040
- // Add search input handlers
1041
- if (searchInput) {
1042
- this._searchInputHandler = this.handleSearchInput.bind(this);
1043
- this._blockSearchClick = this.blockSearchClick.bind(this);
1044
- searchInput.addEventListener('input', this._searchInputHandler);
1045
- searchInput.addEventListener('click', this._blockSearchClick);
1046
- // searchInput.addEventListener('blur', this._searchBlurHandler)
1047
- }
1048
- // Setup dialog backdrop click handler
1049
- const dialog = shadow.querySelector('.dropdown-dialog');
1050
- if (dialog) {
1051
- dialog.addEventListener('click', (e) => {
1052
- // Only close if clicking directly on the dialog (backdrop), not its children
1053
- if (e.target === dialog) {
1054
- this.closeDropdown();
1055
- }
1056
- });
1057
- }
1058
- // Setup keyboard handler
1059
- this._keyboardHandler = this.handleKeyboard.bind(this);
1060
- document.addEventListener('keydown', this._keyboardHandler);
1061
- // Listen for dismiss events from selected tags
1062
- this._tagDismissHandler = this.handleTagDismiss.bind(this);
1063
- this.addEventListener('dismiss', this._tagDismissHandler);
1064
- }
1065
- /**
1066
- * Build CSS class list for stub
1067
- */
1068
- buildStubClasses() {
1069
- const classes = [this._size];
1070
- if (this._disabled)
1071
- classes.push('disabled');
1072
- return classes.join(' ');
1073
- }
1074
- /**
1075
- * Render desktop mode with dialog
1076
- */
1077
- renderDesktop() {
1078
- const shadow = this.shadowRoot;
1079
- // Only set innerHTML and setup listeners if container doesn't exist
1080
- if (!shadow.querySelector('.multiselect-container')) {
1081
- const stubClasses = this.buildStubClasses();
1082
- const labelHtml = this._label ? `
1083
- <label class="dropdown-label">
1084
- ${this._label}
1085
- ${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
1086
- </label>
1087
- ` : '';
1088
- const searchPlaceholder = 'Search...';
1089
- shadow.innerHTML = `
1090
- <div class="multiselect-container dropdown-mode-mobile">
1091
- ${labelHtml}
1092
- <div class="dropdown-wrapper">
1093
- <div class="dropdown-stub multiselect-stub ${stubClasses}"
1094
- ${this._disabled ? 'disabled' : ''}>
1095
- <slot name="start"></slot>
1096
- <div class="multiselect-chips">
1097
- <slot name="selected"></slot>
1098
- </div>
1099
- <span class="dropdown-placeholder">${this._placeholder}</span>
1100
- <div class="dropdown-chevron">
1101
- ${CHEVRON_DOWN_SVG}
1102
- </div>
1103
- </div>
1104
- <dialog class="dropdown-dialog">
1105
- <div class="dropdown-header">
1106
- <input
1107
- class="dropdown-search-input ${this._size}"
1108
- type="text"
1109
- placeholder="${searchPlaceholder}"
1110
- ${this._disabled ? 'disabled' : ''}
1111
- />
1112
- <div class="dropdown-search-chevron">
1113
- ${CHEVRON_DOWN_SVG}
1114
- </div>
1115
- </div>
1116
- <div class="dropdown-options-wrapper">
1117
- <div class="dropdown-options">
1118
- <slot id="options-slot"></slot>
1119
- </div>
1120
- <div class="dropdown-loading" aria-hidden="true">
1121
- <span class="dropdown-loading-spinner"></span>
1122
- <span class="dropdown-loading-text">Searching…</span>
1123
- </div>
1124
- </div>
1125
- </dialog>
1126
- </div>
1127
- </div>
1128
- `;
1129
- // Setup event listeners ONCE
1130
- this.setupEventListeners();
1131
- // Don't initialize here - will be done in connectedCallback
1132
- // after properties are set and children are available
1133
- }
1134
- // Always update placeholder visibility on re-render
1135
- this.updateSelectionDisplay();
1136
- }
1137
- /**
1138
- * Render mobile mode with full-screen modal
1139
- * Following dropdown.ts mobile structure
1140
- */
1141
- renderMobile() {
1142
- const shadow = this.shadowRoot;
1143
- // Only set innerHTML and setup listeners if container doesn't exist
1144
- if (!shadow.querySelector('.multiselect-container')) {
1145
- const stubClasses = this.buildStubClasses();
1146
- const labelHtml = this._label ? `
1147
- <label class="dropdown-label">
1148
- ${this._label}
1149
- ${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
1150
- </label>
1151
- ` : '';
1152
- // Close button SVG (X icon)
1153
- const closeButtonSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1154
- <line x1="18" y1="6" x2="6" y2="18"></line>
1155
- <line x1="6" y1="6" x2="18" y2="18"></line>
1156
- </svg>`;
1157
- // Search placeholder: "Search <label>..." or just "Search..."
1158
- const searchPlaceholder = this._label ? `Search ${this._label}...` : 'Search...';
1159
- // Search is always available — only the mode (internal vs external) varies.
1160
- const searchHeaderHtml = `
1161
- <div class="mobile-search-header">
1162
- ${this._label ? `<span class="mobile-header-label">${this._label}</span>` : ''}
1163
- <div class="mobile-header-content">
1164
- <input
1165
- class="mobile-search-input ${this._size}"
1166
- type="text"
1167
- placeholder="${searchPlaceholder}"
1168
- ${this._disabled ? 'disabled' : ''}
1169
- />
1170
- <button class="mobile-close-button" type="button" aria-label="Close">
1171
- ${closeButtonSvg}
1172
- </button>
1173
- </div>
1174
- </div>
1175
- `;
1176
- shadow.innerHTML = `
1177
- <div class="multiselect-container dropdown-mode-mobile">
1178
- ${labelHtml}
1179
- <div class="dropdown-wrapper">
1180
- <div class="dropdown-stub multiselect-stub ${stubClasses}"
1181
- ${this._disabled ? 'disabled' : ''}>
1182
- <slot name="start"></slot>
1183
- <div class="multiselect-chips">
1184
- <slot id="stub-slot" name="selected"></slot>
1185
- </div>
1186
- <span class="dropdown-placeholder">${this._placeholder}</span>
1187
- <div class="dropdown-chevron">
1188
- ${CHEVRON_DOWN_SVG}
1189
- </div>
1190
- </div>
1191
-
1192
- <dialog class="mobile-dialog">
1193
- <div class="mobile-dialog-content">
1194
-
1195
- <!-- HEADER (matches dropdown.ts) -->
1196
- ${searchHeaderHtml}
1197
-
1198
- <!-- BODY (two sections for multiselect) -->
1199
- <div class="mobile-body">
1200
-
1201
- <!-- SELECTED SECTION (collapsed by default) -->
1202
- <div class="mobile-selected-section" data-expanded="false" data-empty="true">
1203
- <div class="section-header">
1204
- <span class="section-title">${this._selectedLabel} <span class="section-count">(0)</span></span>
1205
- <span class="section-chevron">${CHEVRON_DOWN_SVG}</span>
1206
- </div>
1207
- <div class="section-content">
1208
- <slot id="mobile-slot" name="selected"></slot>
1209
- <div class="empty-state">${this._noSelectionMessage}</div>
1210
- </div>
1211
- </div>
1212
-
1213
- <!-- AVAILABLE SECTION (expanded by default) -->
1214
- <div class="mobile-available-section" data-expanded="true" data-empty="false">
1215
- <div class="section-header">
1216
- <span class="section-title">${this._availableLabel}</span>
1217
- </div>
1218
- <div class="section-content dropdown-options-wrapper">
1219
- <slot id="options-slot"></slot>
1220
- <div class="empty-state">${this._noOptionsMessage}</div>
1221
- <div class="dropdown-loading" aria-hidden="true">
1222
- <span class="dropdown-loading-spinner"></span>
1223
- <span class="dropdown-loading-text">Searching…</span>
1224
- </div>
1225
- </div>
1226
- </div>
1227
-
1228
- </div>
1229
- </div>
1230
- </dialog>
1231
- </div>
1232
- </div>
1233
- `;
1234
- // Setup event listeners ONCE
1235
- this.setupMobileEventListeners();
1236
- }
1237
- // Always update placeholder visibility
1238
- this.updateSelectionDisplay();
1239
- }
1240
- /**
1241
- * Setup event listeners for mobile mode
1242
- * Using <dialog> element - backdrop clicks handled natively
1243
- */
1244
- setupMobileEventListeners() {
1245
- const shadow = this.shadowRoot;
1246
- const stub = shadow.querySelector('.multiselect-stub');
1247
- const optionsSlot = shadow.querySelector('#options-slot');
1248
- const searchInput = shadow.querySelector('.mobile-search-input');
1249
- const closeButton = shadow.querySelector('.mobile-close-button');
1250
- const dialog = shadow.querySelector('.mobile-dialog');
1251
- // Get both section headers
1252
- const selectedHeader = shadow.querySelector('.mobile-selected-section .section-header');
1253
- const availableHeader = shadow.querySelector('.mobile-available-section .section-header');
1254
- if (stub) {
1255
- stub.addEventListener('click', (e) => this.handleMobileStubClick(e));
1256
- }
1257
- // Add tag click handler to slot
1258
- if (optionsSlot) {
1259
- optionsSlot.addEventListener('click', (e) => this.handleMobileTagClick(e));
1260
- }
1261
- // Add search input handlers (if searchable)
1262
- if (searchInput) {
1263
- searchInput.addEventListener('input', (e) => this.handleSearchInput(e));
1264
- }
1265
- // Toggle section expansion on header click
1266
- if (selectedHeader) {
1267
- selectedHeader.addEventListener('click', () => this.toggleSection('selected'));
1268
- }
1269
- if (availableHeader) {
1270
- availableHeader.addEventListener('click', () => this.toggleSection('available'));
1271
- }
1272
- // Close button click
1273
- if (closeButton) {
1274
- closeButton.addEventListener('click', () => this.closeMobileModal());
1275
- }
1276
- this._tagDismissHandler = this.handleTagDismiss.bind(this);
1277
- this.addEventListener('dismiss', this._tagDismissHandler);
1278
- // Backdrop click to close (native dialog behavior)
1279
- if (dialog) {
1280
- dialog.addEventListener('click', (e) => {
1281
- // Only close if clicking directly on the dialog element (backdrop)
1282
- // Not if clicking on its children (dialog-content)
1283
- if (e.target === dialog) {
1284
- this.closeMobileModal();
1285
- }
1286
- });
1287
- // Also handle Escape key via cancel event
1288
- dialog.addEventListener('cancel', (e) => {
1289
- e.preventDefault(); // Prevent default to handle it our way
1290
- this.closeMobileModal();
1291
- });
1292
- }
1293
- }
1294
- /**
1295
- * Handle mobile stub click - open modal
1296
- */
1297
- handleMobileStubClick(e) {
1298
- e.preventDefault();
1299
- e.stopPropagation();
1300
- if (this._disabled || this._readonly) {
1301
- return;
1302
- }
1303
- // Don't open if all tags are already selected
1304
- if (this.allTagsSelected()) {
1305
- return;
1306
- }
1307
- this.openMobileModal();
1308
- }
1309
- /**
1310
- * Handle mobile tag click - select and potentially close
1311
- */
1312
- handleMobileTagClick(e) {
1313
- // Use the same tag click handler as desktop
1314
- // It already handles mobile mode for auto-close
1315
- this.handleTagClick(e);
1316
- }
1317
- /**
1318
- * Toggle section expansion (mobile only)
1319
- * Clicking expanded section collapses it and expands the other
1320
- * Clicking collapsed section expands it and collapses the other
1321
- */
1322
- toggleSection(section) {
1323
- const shadow = this.shadowRoot;
1324
- const selectedSection = shadow.querySelector('.mobile-selected-section');
1325
- const availableSection = shadow.querySelector('.mobile-available-section');
1326
- if (!selectedSection || !availableSection)
1327
- return;
1328
- // If clicking already expanded section, collapse it and expand the other
1329
- if (this._state.expandedSection === section) {
1330
- const otherSection = section === 'selected' ? 'available' : 'selected';
1331
- this._state.expandedSection = otherSection;
1332
- }
1333
- else {
1334
- // Expand clicked section
1335
- this._state.expandedSection = section;
1336
- }
1337
- // Update DOM attributes
1338
- selectedSection.setAttribute('data-expanded', String(this._state.expandedSection === 'selected'));
1339
- availableSection.setAttribute('data-expanded', String(this._state.expandedSection === 'available'));
1340
- }
1341
- /**
1342
- * Sync section states to DOM without toggle logic
1343
- */
1344
- syncSectionStates() {
1345
- const shadow = this.shadowRoot;
1346
- const selectedSection = shadow.querySelector('.mobile-selected-section');
1347
- const availableSection = shadow.querySelector('.mobile-available-section');
1348
- if (!selectedSection || !availableSection)
1349
- return;
1350
- // Update DOM attributes to match current state
1351
- selectedSection.setAttribute('data-expanded', String(this._state.expandedSection === 'selected'));
1352
- availableSection.setAttribute('data-expanded', String(this._state.expandedSection === 'available'));
1353
- }
1354
- /**
1355
- * Update mobile selected section state (collapsed view, empty states, etc.)
1356
- */
1357
- updateMobileSelectedState() {
1358
- if (this._state.mode !== 'mobile')
1359
- return;
1360
- const shadow = this.shadowRoot;
1361
- const selectedSection = shadow.querySelector('.mobile-selected-section');
1362
- const availableSection = shadow.querySelector('.mobile-available-section');
1363
- const sectionCountSpan = shadow.querySelector('.section-count');
1364
- if (selectedSection) {
1365
- const selectedCount = this._state.selectedValues.length;
1366
- const hasSelected = selectedCount > 0;
1367
- selectedSection.setAttribute('data-empty', String(!hasSelected));
1368
- // Update header count
1369
- if (sectionCountSpan) {
1370
- sectionCountSpan.textContent = `(${selectedCount})`;
1371
- }
1372
- }
1373
- if (availableSection) {
1374
- const allTags = this.getTagElements();
1375
- const availableCount = allTags.filter(tag => !tag.hasAttribute('selected')).length;
1376
- const hasAvailable = availableCount > 0;
1377
- availableSection.setAttribute('data-empty', String(!hasAvailable));
1378
- // Update available header count
1379
- const availableTitleSpan = shadow.querySelector('.mobile-available-section .section-title');
1380
- if (availableTitleSpan) {
1381
- availableTitleSpan.textContent = `${this._availableLabel} (${availableCount})`;
1382
- }
1383
- }
1384
- }
1385
- /**
1386
- * Update selection display (show/hide placeholder)
1387
- * Matches dropdown.ts pattern - uses CSS via has-selection class
1388
- */
1389
- updateSelectionDisplay() {
1390
- const shadow = this.shadowRoot;
1391
- const stub = shadow.querySelector('.multiselect-stub');
1392
- if (!stub)
1393
- return;
1394
- const tags = this.getTagElements();
1395
- const selectedTags = tags.filter(tag => tag.hasAttribute('selected'));
1396
- const hasSelected = selectedTags.length > 0;
1397
- if (hasSelected) {
1398
- stub.classList.add('has-selection');
1399
- }
1400
- else {
1401
- stub.classList.remove('has-selection');
1402
- }
1403
- }
1404
- // ============================================================================
1405
- // PUBLIC API - Getters/Setters
1406
- // ============================================================================
1407
- get value() {
1408
- // Always read from DOM - tags with 'selected' attribute are source of truth
1409
- return this.getSelectedValues().join(',');
1410
- }
1411
- set value(val) {
1412
- this.setProperty('value', val);
1413
- }
1414
- get name() {
1415
- return this.getProperty('name');
1416
- }
1417
- set name(val) {
1418
- this.setProperty('name', val);
1419
- }
1420
- get placeholder() {
1421
- return this.getProperty('placeholder');
1422
- }
1423
- set placeholder(val) {
1424
- this.setProperty('placeholder', val);
1425
- }
1426
- get label() {
1427
- return this.getProperty('label');
1428
- }
1429
- set label(val) {
1430
- this.setProperty('label', val);
1431
- }
1432
- get disabled() {
1433
- return this.getProperty('disabled');
1434
- }
1435
- set disabled(value) {
1436
- this.setProperty('disabled', value);
1437
- }
1438
- get loading() {
1439
- return this.getProperty('loading');
1440
- }
1441
- set loading(value) {
1442
- this.setProperty('loading', value);
1443
- }
1444
- get readonly() {
1445
- return this.getProperty('readonly');
1446
- }
1447
- set readonly(value) {
1448
- this.setProperty('readonly', value);
1449
- }
1450
- get required() {
1451
- return this.getProperty('required');
1452
- }
1453
- set required(value) {
1454
- this.setProperty('required', value);
1455
- }
1456
- get externalSearch() {
1457
- return this.getProperty('externalSearch');
1458
- }
1459
- set externalSearch(value) {
1460
- this.setProperty('externalSearch', value);
1461
- }
1462
- get debounce() {
1463
- return this.getProperty('debounce');
1464
- }
1465
- set debounce(value) {
1466
- const numValue = typeof value === 'string' ? parseInt(value, 10) : value;
1467
- this.setProperty('debounce', numValue);
1468
- }
1469
- get size() {
1470
- return this.getProperty('size');
1471
- }
1472
- set size(value) {
1473
- this.setProperty('size', value);
1474
- }
1475
- get flavor() {
1476
- return this.getProperty('flavor');
1477
- }
1478
- set flavor(value) {
1479
- this.setProperty('flavor', value);
1480
- }
1481
- get form() {
1482
- return this._internals.form;
1483
- }
1484
- }
1485
- // ============================================================================
1486
- // PROPERTY CONFIGURATION - Declarative property lifecycle
1487
- // ============================================================================
1488
- TyMultiselect.properties = {
1489
- value: {
1490
- type: 'string',
1491
- visual: true,
1492
- formValue: true,
1493
- emitChange: false,
1494
- default: '',
1495
- coerce: (v) => {
1496
- // Handle array input (from React, Reagent, etc.)
1497
- if (Array.isArray(v)) {
1498
- return v.join(',');
1499
- }
1500
- // Handle null/undefined
1501
- if (v === null || v === undefined) {
1502
- return '';
1503
- }
1504
- // String already
1505
- return String(v);
1506
- }
1507
- },
1508
- name: {
1509
- type: 'string',
1510
- default: ''
1511
- },
1512
- placeholder: {
1513
- type: 'string',
1514
- visual: true,
1515
- default: 'Select options...'
1516
- },
1517
- label: {
1518
- type: 'string',
1519
- visual: true,
1520
- default: ''
1521
- },
1522
- disabled: {
1523
- type: 'boolean',
1524
- visual: true,
1525
- default: false
1526
- },
1527
- readonly: {
1528
- type: 'boolean',
1529
- visual: true,
1530
- default: false
1531
- },
1532
- required: {
1533
- type: 'boolean',
1534
- visual: true,
1535
- default: false
1536
- },
1537
- externalSearch: {
1538
- type: 'boolean',
1539
- visual: true,
1540
- default: false,
1541
- aliases: { 'external-search': true }
1542
- },
1543
- size: {
1544
- type: 'string',
1545
- visual: true,
1546
- default: 'md',
1547
- validate: (v) => ['sm', 'md', 'lg'].includes(v),
1548
- coerce: (v) => {
1549
- if (!['sm', 'md', 'lg'].includes(v)) {
1550
- console.warn(`[ty-multiselect] Invalid size. Using md.`);
1551
- return 'md';
1552
- }
1553
- return v;
1554
- }
1555
- },
1556
- flavor: {
1557
- type: 'string',
1558
- visual: true,
1559
- default: 'neutral',
1560
- validate: (v) => ['primary', 'secondary', 'success', 'danger', 'warning', 'neutral'].includes(v),
1561
- coerce: (v) => {
1562
- const valid = ['primary', 'secondary', 'success', 'danger', 'warning', 'neutral'];
1563
- if (!valid.includes(v)) {
1564
- console.warn(`[ty-multiselect] Invalid flavor. Using neutral.`);
1565
- return 'neutral';
1566
- }
1567
- return v;
1568
- }
1569
- },
1570
- debounce: {
1571
- type: 'number',
1572
- default: 0,
1573
- validate: (v) => v >= 0 && v <= 5000,
1574
- coerce: (v) => {
1575
- const num = Number(v);
1576
- if (isNaN(num))
1577
- return 0;
1578
- return Math.max(0, Math.min(5000, num));
1579
- }
1580
- },
1581
- 'selected-label': {
1582
- type: 'string',
1583
- visual: true,
1584
- default: 'Selected'
1585
- },
1586
- 'available-label': {
1587
- type: 'string',
1588
- visual: true,
1589
- default: 'Available'
1590
- },
1591
- 'no-selection-message': {
1592
- type: 'string',
1593
- visual: true,
1594
- default: 'No items selected'
1595
- },
1596
- 'no-options-message': {
1597
- type: 'string',
1598
- visual: true,
1599
- default: 'No options available'
1600
- },
1601
- loading: {
1602
- type: 'boolean',
1603
- visual: true,
1604
- default: false
1605
- }
1606
- };
1607
- // Register the custom element
1608
- if (!customElements.get('ty-multiselect')) {
1609
- customElements.define('ty-multiselect', TyMultiselect);
1610
- }
1611
- //# sourceMappingURL=multiselect.js.map