@tabler/core 1.0.0-beta10 → 1.0.0-beta11

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 (398) hide show
  1. package/README.md +33 -11
  2. package/dist/css/demo.css +2 -2
  3. package/dist/css/demo.min.css +2 -2
  4. package/dist/css/demo.rtl.css +2 -2
  5. package/dist/css/demo.rtl.min.css +2 -2
  6. package/dist/css/tabler-flags.css +2 -2
  7. package/dist/css/tabler-flags.min.css +2 -2
  8. package/dist/css/tabler-flags.rtl.css +2 -2
  9. package/dist/css/tabler-flags.rtl.min.css +2 -2
  10. package/dist/css/tabler-payments.css +2 -2
  11. package/dist/css/tabler-payments.min.css +2 -2
  12. package/dist/css/tabler-payments.rtl.css +2 -2
  13. package/dist/css/tabler-payments.rtl.min.css +2 -2
  14. package/dist/css/tabler-vendors.css +143 -29
  15. package/dist/css/tabler-vendors.min.css +3 -3
  16. package/dist/css/tabler-vendors.rtl.css +143 -29
  17. package/dist/css/tabler-vendors.rtl.min.css +3 -3
  18. package/dist/css/tabler.css +5741 -2725
  19. package/dist/css/tabler.min.css +4 -4
  20. package/dist/css/tabler.rtl.css +5743 -2743
  21. package/dist/css/tabler.rtl.min.css +4 -4
  22. package/dist/js/demo.js +2 -2
  23. package/dist/js/demo.min.js +2 -2
  24. package/dist/js/tabler.esm.js +1637 -1515
  25. package/dist/js/tabler.esm.min.js +3 -3
  26. package/dist/js/tabler.js +1637 -1515
  27. package/dist/js/tabler.min.js +3 -3
  28. package/dist/libs/apexcharts/dist/apexcharts.amd.js +2 -0
  29. package/dist/libs/apexcharts/dist/apexcharts.common.js +14 -0
  30. package/dist/libs/apexcharts/dist/apexcharts.css +691 -0
  31. package/dist/libs/apexcharts/dist/apexcharts.esm.js +14 -0
  32. package/dist/libs/apexcharts/dist/apexcharts.js +31960 -0
  33. package/dist/libs/apexcharts/dist/apexcharts.min.js +4 -4
  34. package/dist/libs/apexcharts/dist/locales/ar.json +63 -0
  35. package/dist/libs/apexcharts/dist/locales/ca.json +55 -0
  36. package/dist/libs/apexcharts/dist/locales/cs.json +55 -0
  37. package/dist/libs/apexcharts/dist/locales/de.json +55 -0
  38. package/dist/libs/apexcharts/dist/locales/el.json +55 -0
  39. package/dist/libs/apexcharts/dist/locales/en.json +55 -0
  40. package/dist/libs/apexcharts/dist/locales/es.json +55 -0
  41. package/dist/libs/apexcharts/dist/locales/et.json +63 -0
  42. package/dist/libs/apexcharts/dist/locales/fa.json +55 -0
  43. package/dist/libs/apexcharts/dist/locales/fi.json +55 -0
  44. package/dist/libs/apexcharts/dist/locales/fr.json +55 -0
  45. package/dist/libs/apexcharts/dist/locales/he.json +55 -0
  46. package/dist/libs/apexcharts/dist/locales/hi.json +55 -0
  47. package/dist/libs/apexcharts/dist/locales/hr.json +55 -0
  48. package/dist/libs/apexcharts/dist/locales/hu.json +64 -0
  49. package/dist/libs/apexcharts/dist/locales/hy.json +55 -0
  50. package/dist/libs/apexcharts/dist/locales/id.json +47 -0
  51. package/dist/libs/apexcharts/dist/locales/it.json +55 -0
  52. package/dist/libs/apexcharts/dist/locales/ja.json +55 -0
  53. package/dist/libs/apexcharts/dist/locales/ka.json +55 -0
  54. package/dist/libs/apexcharts/dist/locales/ko.json +55 -0
  55. package/dist/libs/apexcharts/dist/locales/lt.json +55 -0
  56. package/dist/libs/apexcharts/dist/locales/lv.json +64 -0
  57. package/dist/libs/apexcharts/dist/locales/nb.json +55 -0
  58. package/dist/libs/apexcharts/dist/locales/nl.json +55 -0
  59. package/dist/libs/apexcharts/dist/locales/pl.json +55 -0
  60. package/dist/libs/apexcharts/dist/locales/pt-br.json +55 -0
  61. package/dist/libs/apexcharts/dist/locales/pt.json +55 -0
  62. package/dist/libs/apexcharts/dist/locales/rs.json +55 -0
  63. package/dist/libs/apexcharts/dist/locales/ru.json +55 -0
  64. package/dist/libs/apexcharts/dist/locales/se.json +55 -0
  65. package/dist/libs/apexcharts/dist/locales/sk.json +55 -0
  66. package/dist/libs/apexcharts/dist/locales/sl.json +55 -0
  67. package/dist/libs/apexcharts/dist/locales/sq.json +55 -0
  68. package/dist/libs/apexcharts/dist/locales/th.json +55 -0
  69. package/dist/libs/apexcharts/dist/locales/tr.json +55 -0
  70. package/dist/libs/apexcharts/dist/locales/ua.json +55 -0
  71. package/dist/libs/apexcharts/dist/locales/zh-cn.json +55 -0
  72. package/dist/libs/apexcharts/dist/locales/zh-tw.json +55 -0
  73. package/dist/libs/bootstrap/dist/js/bootstrap.bundle.js +7066 -0
  74. package/dist/libs/bootstrap/dist/js/bootstrap.bundle.js.map +1 -0
  75. package/dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js +3 -3
  76. package/dist/libs/bootstrap/dist/js/bootstrap.bundle.min.js.map +1 -0
  77. package/dist/libs/bootstrap/dist/js/bootstrap.esm.js +5204 -0
  78. package/dist/libs/bootstrap/dist/js/bootstrap.esm.js.map +1 -0
  79. package/dist/libs/bootstrap/dist/js/bootstrap.esm.min.js +7 -0
  80. package/dist/libs/bootstrap/dist/js/bootstrap.esm.min.js.map +1 -0
  81. package/dist/libs/bootstrap/dist/js/bootstrap.js +5251 -0
  82. package/dist/libs/bootstrap/dist/js/bootstrap.js.map +1 -0
  83. package/dist/libs/bootstrap/dist/js/bootstrap.min.js +7 -0
  84. package/dist/libs/bootstrap/dist/js/bootstrap.min.js.map +1 -0
  85. package/dist/libs/countup.js/dist/countUp.d.ts +61 -0
  86. package/dist/libs/countup.js/dist/countUp.js +25 -22
  87. package/dist/libs/countup.js/dist/countUp.min.js +1 -0
  88. package/dist/libs/countup.js/dist/countUp.umd.js +293 -0
  89. package/dist/libs/countup.js/dist/countUp.withPolyfill.min.js +1 -0
  90. package/dist/libs/dropzone/dist/basic.css +1 -0
  91. package/dist/libs/dropzone/dist/basic.css.map +1 -0
  92. package/dist/libs/dropzone/dist/dropzone-min.js +2 -0
  93. package/dist/libs/dropzone/dist/dropzone-min.js.map +1 -0
  94. package/dist/libs/dropzone/dist/dropzone.css +1 -0
  95. package/dist/libs/dropzone/dist/dropzone.css.map +1 -0
  96. package/dist/libs/dropzone/dist/dropzone.js +3068 -0
  97. package/dist/libs/dropzone/dist/dropzone.js.map +1 -0
  98. package/dist/libs/dropzone/dist/dropzone.mjs +2111 -0
  99. package/dist/libs/dropzone/dist/dropzone.mjs.map +1 -0
  100. package/dist/libs/fslightbox/LICENSE +21 -0
  101. package/dist/libs/fslightbox/README.md +62 -0
  102. package/dist/libs/fslightbox/index.js +1 -0
  103. package/dist/libs/fslightbox/jest-setup.js +1 -0
  104. package/dist/libs/fslightbox/package.json +72 -0
  105. package/dist/libs/jsvectormap/dist/js/jsvectormap.js +2663 -0
  106. package/dist/libs/jsvectormap/dist/js/jsvectormap.min.js +1 -1
  107. package/dist/libs/jsvectormap/dist/maps/world-merc.js +1 -1
  108. package/dist/libs/jsvectormap/dist/maps/world.js +1 -1
  109. package/dist/libs/list.js/dist/list.js +2020 -0
  110. package/dist/libs/list.js/dist/list.js.map +1 -0
  111. package/dist/libs/list.js/dist/list.min.js.map +1 -0
  112. package/dist/libs/litepicker/dist/bundle.js +52 -0
  113. package/dist/libs/litepicker/dist/css/litepicker.css +13 -0
  114. package/dist/libs/litepicker/dist/css/plugins/keyboardnav.js.css +12 -0
  115. package/dist/libs/litepicker/dist/css/plugins/mobilefriendly.js.css +133 -0
  116. package/dist/libs/litepicker/dist/css/plugins/multiselect.js.css +54 -0
  117. package/dist/libs/litepicker/dist/css/plugins/ranges.js.css +81 -0
  118. package/dist/libs/litepicker/dist/js/main.js +13 -0
  119. package/dist/libs/litepicker/dist/litepicker.amd.js +12 -0
  120. package/dist/libs/litepicker/dist/litepicker.commonjs2.js +12 -0
  121. package/dist/libs/litepicker/dist/litepicker.umd.js +12 -0
  122. package/dist/libs/litepicker/dist/nocss/litepicker.amd.js +12 -0
  123. package/dist/libs/litepicker/dist/nocss/litepicker.commonjs2.js +12 -0
  124. package/dist/libs/litepicker/dist/nocss/litepicker.js +12 -0
  125. package/dist/libs/litepicker/dist/nocss/litepicker.umd.js +12 -0
  126. package/dist/libs/litepicker/dist/nocss/plugins/keyboardnav.js +11 -0
  127. package/dist/libs/litepicker/dist/nocss/plugins/mobilefriendly.js +11 -0
  128. package/dist/libs/litepicker/dist/nocss/plugins/multiselect.js +11 -0
  129. package/dist/libs/litepicker/dist/nocss/plugins/ranges.js +11 -0
  130. package/dist/libs/litepicker/dist/plugins/keyboardnav.js +11 -0
  131. package/dist/libs/litepicker/dist/plugins/mobilefriendly.js +11 -0
  132. package/dist/libs/litepicker/dist/plugins/multiselect.js +11 -0
  133. package/dist/libs/litepicker/dist/plugins/ranges.js +11 -0
  134. package/dist/libs/litepicker/dist/types/calendar.d.ts +14 -0
  135. package/dist/libs/litepicker/dist/types/core.d.ts +23 -0
  136. package/dist/libs/litepicker/dist/types/datetime.d.ts +41 -0
  137. package/dist/libs/litepicker/dist/types/index.d.ts +4 -0
  138. package/dist/libs/litepicker/dist/types/interfaces.d.ts +80 -0
  139. package/dist/libs/litepicker/dist/types/litepicker.d.ts +25 -0
  140. package/dist/libs/litepicker/dist/types/methods.d.ts +20 -0
  141. package/dist/libs/litepicker/dist/types/utils.d.ts +4 -0
  142. package/dist/libs/litepicker/dist/types/window.d.ts +6 -0
  143. package/dist/libs/nouislider/dist/nouislider.css +304 -0
  144. package/dist/libs/nouislider/dist/nouislider.d.ts +198 -0
  145. package/dist/libs/nouislider/dist/nouislider.js +2254 -0
  146. package/dist/libs/nouislider/dist/nouislider.min.css +1 -0
  147. package/dist/libs/nouislider/dist/nouislider.min.js +1 -1
  148. package/dist/libs/nouislider/dist/nouislider.min.mjs +1 -0
  149. package/dist/libs/nouislider/dist/nouislider.mjs +2243 -0
  150. package/dist/libs/plyr/dist/plyr.css +1 -0
  151. package/dist/libs/plyr/dist/plyr.js +8764 -0
  152. package/dist/libs/plyr/dist/plyr.min.js +2 -0
  153. package/dist/libs/plyr/dist/plyr.min.js.map +1 -0
  154. package/dist/libs/plyr/dist/plyr.min.mjs +1 -0
  155. package/dist/libs/plyr/dist/plyr.min.mjs.map +1 -0
  156. package/dist/libs/plyr/dist/plyr.mjs +8756 -0
  157. package/dist/libs/plyr/dist/plyr.polyfilled.js +9301 -0
  158. package/dist/libs/plyr/dist/plyr.polyfilled.min.js +2 -0
  159. package/dist/libs/plyr/dist/plyr.polyfilled.min.js.map +1 -0
  160. package/dist/libs/plyr/dist/plyr.polyfilled.min.mjs +1 -0
  161. package/dist/libs/plyr/dist/plyr.polyfilled.min.mjs.map +1 -0
  162. package/dist/libs/plyr/dist/plyr.polyfilled.mjs +9293 -0
  163. package/dist/libs/plyr/dist/plyr.svg +1 -0
  164. package/dist/libs/tinymce/CHANGELOG.md +2957 -0
  165. package/dist/libs/tinymce/README.md +71 -0
  166. package/dist/libs/tinymce/bower.json +27 -0
  167. package/dist/libs/tinymce/composer.json +52 -0
  168. package/dist/libs/tinymce/icons/default/icons.js +182 -0
  169. package/dist/libs/tinymce/icons/default/icons.min.js +1 -0
  170. package/dist/libs/tinymce/icons/default/index.js +7 -0
  171. package/dist/libs/tinymce/license.txt +21 -0
  172. package/dist/libs/tinymce/models/dom/index.js +7 -0
  173. package/dist/libs/tinymce/models/dom/model.js +7975 -0
  174. package/dist/libs/tinymce/models/dom/model.min.js +4 -0
  175. package/dist/libs/tinymce/package.json +32 -0
  176. package/dist/libs/tinymce/plugins/advlist/index.js +7 -0
  177. package/dist/libs/tinymce/plugins/advlist/plugin.js +246 -0
  178. package/dist/libs/tinymce/plugins/advlist/plugin.min.js +4 -0
  179. package/dist/libs/tinymce/plugins/anchor/index.js +7 -0
  180. package/dist/libs/tinymce/plugins/anchor/plugin.js +195 -0
  181. package/dist/libs/tinymce/plugins/anchor/plugin.min.js +4 -0
  182. package/dist/libs/tinymce/plugins/autolink/index.js +7 -0
  183. package/dist/libs/tinymce/plugins/autolink/plugin.js +232 -0
  184. package/dist/libs/tinymce/plugins/autolink/plugin.min.js +4 -0
  185. package/dist/libs/tinymce/plugins/autoresize/index.js +7 -0
  186. package/dist/libs/tinymce/plugins/autoresize/plugin.js +156 -0
  187. package/dist/libs/tinymce/plugins/autoresize/plugin.min.js +4 -0
  188. package/dist/libs/tinymce/plugins/autosave/index.js +7 -0
  189. package/dist/libs/tinymce/plugins/autosave/plugin.js +232 -0
  190. package/dist/libs/tinymce/plugins/autosave/plugin.min.js +4 -0
  191. package/dist/libs/tinymce/plugins/charmap/index.js +7 -0
  192. package/dist/libs/tinymce/plugins/charmap/plugin.js +1636 -0
  193. package/dist/libs/tinymce/plugins/charmap/plugin.min.js +4 -0
  194. package/dist/libs/tinymce/plugins/code/index.js +7 -0
  195. package/dist/libs/tinymce/plugins/code/plugin.js +85 -0
  196. package/dist/libs/tinymce/plugins/code/plugin.min.js +4 -0
  197. package/dist/libs/tinymce/plugins/codesample/index.js +7 -0
  198. package/dist/libs/tinymce/plugins/codesample/plugin.js +2451 -0
  199. package/dist/libs/tinymce/plugins/codesample/plugin.min.js +4 -0
  200. package/dist/libs/tinymce/plugins/directionality/index.js +7 -0
  201. package/dist/libs/tinymce/plugins/directionality/plugin.js +384 -0
  202. package/dist/libs/tinymce/plugins/directionality/plugin.min.js +4 -0
  203. package/dist/libs/tinymce/plugins/emoticons/index.js +7 -0
  204. package/dist/libs/tinymce/plugins/emoticons/js/emojiimages.js +1 -0
  205. package/dist/libs/tinymce/plugins/emoticons/js/emojiimages.min.js +3 -0
  206. package/dist/libs/tinymce/plugins/emoticons/js/emojis.js +1 -0
  207. package/dist/libs/tinymce/plugins/emoticons/js/emojis.min.js +2 -0
  208. package/dist/libs/tinymce/plugins/emoticons/plugin.js +577 -0
  209. package/dist/libs/tinymce/plugins/emoticons/plugin.min.js +4 -0
  210. package/dist/libs/tinymce/plugins/fullscreen/index.js +7 -0
  211. package/dist/libs/tinymce/plugins/fullscreen/plugin.js +1190 -0
  212. package/dist/libs/tinymce/plugins/fullscreen/plugin.min.js +4 -0
  213. package/dist/libs/tinymce/plugins/help/index.js +7 -0
  214. package/dist/libs/tinymce/plugins/help/plugin.js +848 -0
  215. package/dist/libs/tinymce/plugins/help/plugin.min.js +4 -0
  216. package/dist/libs/tinymce/plugins/image/index.js +7 -0
  217. package/dist/libs/tinymce/plugins/image/plugin.js +1475 -0
  218. package/dist/libs/tinymce/plugins/image/plugin.min.js +4 -0
  219. package/dist/libs/tinymce/plugins/importcss/index.js +7 -0
  220. package/dist/libs/tinymce/plugins/importcss/plugin.js +342 -0
  221. package/dist/libs/tinymce/plugins/importcss/plugin.min.js +4 -0
  222. package/dist/libs/tinymce/plugins/insertdatetime/index.js +7 -0
  223. package/dist/libs/tinymce/plugins/insertdatetime/plugin.js +176 -0
  224. package/dist/libs/tinymce/plugins/insertdatetime/plugin.min.js +4 -0
  225. package/dist/libs/tinymce/plugins/link/index.js +7 -0
  226. package/dist/libs/tinymce/plugins/link/plugin.js +1190 -0
  227. package/dist/libs/tinymce/plugins/link/plugin.min.js +4 -0
  228. package/dist/libs/tinymce/plugins/lists/index.js +7 -0
  229. package/dist/libs/tinymce/plugins/lists/plugin.js +1820 -0
  230. package/dist/libs/tinymce/plugins/lists/plugin.min.js +4 -0
  231. package/dist/libs/tinymce/plugins/media/index.js +7 -0
  232. package/dist/libs/tinymce/plugins/media/plugin.js +1157 -0
  233. package/dist/libs/tinymce/plugins/media/plugin.min.js +4 -0
  234. package/dist/libs/tinymce/plugins/nonbreaking/index.js +7 -0
  235. package/dist/libs/tinymce/plugins/nonbreaking/plugin.js +111 -0
  236. package/dist/libs/tinymce/plugins/nonbreaking/plugin.min.js +4 -0
  237. package/dist/libs/tinymce/plugins/pagebreak/index.js +7 -0
  238. package/dist/libs/tinymce/plugins/pagebreak/plugin.js +105 -0
  239. package/dist/libs/tinymce/plugins/pagebreak/plugin.min.js +4 -0
  240. package/dist/libs/tinymce/plugins/preview/index.js +7 -0
  241. package/dist/libs/tinymce/plugins/preview/plugin.js +97 -0
  242. package/dist/libs/tinymce/plugins/preview/plugin.min.js +4 -0
  243. package/dist/libs/tinymce/plugins/quickbars/index.js +7 -0
  244. package/dist/libs/tinymce/plugins/quickbars/plugin.js +421 -0
  245. package/dist/libs/tinymce/plugins/quickbars/plugin.min.js +4 -0
  246. package/dist/libs/tinymce/plugins/save/index.js +7 -0
  247. package/dist/libs/tinymce/plugins/save/plugin.js +118 -0
  248. package/dist/libs/tinymce/plugins/save/plugin.min.js +4 -0
  249. package/dist/libs/tinymce/plugins/searchreplace/index.js +7 -0
  250. package/dist/libs/tinymce/plugins/searchreplace/plugin.js +1079 -0
  251. package/dist/libs/tinymce/plugins/searchreplace/plugin.min.js +4 -0
  252. package/dist/libs/tinymce/plugins/table/index.js +7 -0
  253. package/dist/libs/tinymce/plugins/table/plugin.js +3393 -0
  254. package/dist/libs/tinymce/plugins/table/plugin.min.js +4 -0
  255. package/dist/libs/tinymce/plugins/template/index.js +7 -0
  256. package/dist/libs/tinymce/plugins/template/plugin.js +548 -0
  257. package/dist/libs/tinymce/plugins/template/plugin.min.js +4 -0
  258. package/dist/libs/tinymce/plugins/visualblocks/index.js +7 -0
  259. package/dist/libs/tinymce/plugins/visualblocks/plugin.js +98 -0
  260. package/dist/libs/tinymce/plugins/visualblocks/plugin.min.js +4 -0
  261. package/dist/libs/tinymce/plugins/visualchars/index.js +7 -0
  262. package/dist/libs/tinymce/plugins/visualchars/plugin.js +506 -0
  263. package/dist/libs/tinymce/plugins/visualchars/plugin.min.js +4 -0
  264. package/dist/libs/tinymce/plugins/wordcount/index.js +7 -0
  265. package/dist/libs/tinymce/plugins/wordcount/plugin.js +404 -0
  266. package/dist/libs/tinymce/plugins/wordcount/plugin.min.js +4 -0
  267. package/dist/libs/tinymce/skins/content/dark/content.css +66 -0
  268. package/dist/libs/tinymce/skins/content/dark/content.min.css +1 -0
  269. package/dist/libs/tinymce/skins/content/default/content.css +61 -0
  270. package/dist/libs/tinymce/skins/content/default/content.min.css +1 -0
  271. package/dist/libs/tinymce/skins/content/document/content.css +66 -0
  272. package/dist/libs/tinymce/skins/content/document/content.min.css +1 -0
  273. package/dist/libs/tinymce/skins/content/tinymce-5/content.css +61 -0
  274. package/dist/libs/tinymce/skins/content/tinymce-5/content.min.css +1 -0
  275. package/dist/libs/tinymce/skins/content/tinymce-5-dark/content.css +66 -0
  276. package/dist/libs/tinymce/skins/content/tinymce-5-dark/content.min.css +1 -0
  277. package/dist/libs/tinymce/skins/content/writer/content.css +62 -0
  278. package/dist/libs/tinymce/skins/content/writer/content.min.css +1 -0
  279. package/dist/libs/tinymce/skins/ui/oxide/content.css +747 -0
  280. package/dist/libs/tinymce/skins/ui/oxide/content.inline.css +741 -0
  281. package/dist/libs/tinymce/skins/ui/oxide/content.inline.min.css +1 -0
  282. package/dist/libs/tinymce/skins/ui/oxide/content.min.css +1 -0
  283. package/dist/libs/tinymce/skins/ui/oxide/skin.css +3074 -0
  284. package/dist/libs/tinymce/skins/ui/oxide/skin.min.css +1 -0
  285. package/dist/libs/tinymce/skins/ui/oxide/skin.shadowdom.css +30 -0
  286. package/dist/libs/tinymce/skins/ui/oxide/skin.shadowdom.min.css +1 -0
  287. package/dist/libs/tinymce/skins/ui/oxide-dark/content.css +728 -0
  288. package/dist/libs/tinymce/skins/ui/oxide-dark/content.inline.css +741 -0
  289. package/dist/libs/tinymce/skins/ui/oxide-dark/content.inline.min.css +1 -0
  290. package/dist/libs/tinymce/skins/ui/oxide-dark/content.min.css +1 -0
  291. package/dist/libs/tinymce/skins/ui/oxide-dark/skin.css +3077 -0
  292. package/dist/libs/tinymce/skins/ui/oxide-dark/skin.min.css +1 -0
  293. package/dist/libs/tinymce/skins/ui/oxide-dark/skin.shadowdom.css +30 -0
  294. package/dist/libs/tinymce/skins/ui/oxide-dark/skin.shadowdom.min.css +1 -0
  295. package/dist/libs/tinymce/skins/ui/tinymce-5/content.css +747 -0
  296. package/dist/libs/tinymce/skins/ui/tinymce-5/content.inline.css +741 -0
  297. package/dist/libs/tinymce/skins/ui/tinymce-5/content.inline.min.css +1 -0
  298. package/dist/libs/tinymce/skins/ui/tinymce-5/content.min.css +1 -0
  299. package/dist/libs/tinymce/skins/ui/tinymce-5/skin.css +3158 -0
  300. package/dist/libs/tinymce/skins/ui/tinymce-5/skin.min.css +1 -0
  301. package/dist/libs/tinymce/skins/ui/tinymce-5/skin.shadowdom.css +30 -0
  302. package/dist/libs/tinymce/skins/ui/tinymce-5/skin.shadowdom.min.css +1 -0
  303. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/content.css +728 -0
  304. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/content.inline.css +741 -0
  305. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/content.inline.min.css +1 -0
  306. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/content.min.css +1 -0
  307. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/skin.css +3158 -0
  308. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/skin.min.css +1 -0
  309. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/skin.shadowdom.css +30 -0
  310. package/dist/libs/tinymce/skins/ui/tinymce-5-dark/skin.shadowdom.min.css +1 -0
  311. package/dist/libs/tinymce/themes/silver/index.js +7 -0
  312. package/dist/libs/tinymce/themes/silver/theme.js +26184 -0
  313. package/dist/libs/tinymce/themes/silver/theme.min.js +4 -0
  314. package/dist/libs/tinymce/tinymce.d.ts +2895 -0
  315. package/dist/libs/tinymce/tinymce.js +29400 -0
  316. package/dist/libs/tinymce/tinymce.min.js +4 -0
  317. package/dist/libs/tom-select/dist/js/plugins/caret_position.js +170 -0
  318. package/dist/libs/tom-select/dist/js/plugins/caret_position.js.map +1 -0
  319. package/dist/libs/tom-select/dist/js/plugins/change_listener.js +58 -0
  320. package/dist/libs/tom-select/dist/js/plugins/change_listener.js.map +1 -0
  321. package/dist/libs/tom-select/dist/js/plugins/checkbox_options.js +182 -0
  322. package/dist/libs/tom-select/dist/js/plugins/checkbox_options.js.map +1 -0
  323. package/dist/libs/tom-select/dist/js/plugins/clear_button.js +99 -0
  324. package/dist/libs/tom-select/dist/js/plugins/clear_button.js.map +1 -0
  325. package/dist/libs/tom-select/dist/js/plugins/drag_drop.js +70 -0
  326. package/dist/libs/tom-select/dist/js/plugins/drag_drop.js.map +1 -0
  327. package/dist/libs/tom-select/dist/js/plugins/dropdown_header.js +126 -0
  328. package/dist/libs/tom-select/dist/js/plugins/dropdown_header.js.map +1 -0
  329. package/dist/libs/tom-select/dist/js/plugins/dropdown_input.js +240 -0
  330. package/dist/libs/tom-select/dist/js/plugins/dropdown_input.js.map +1 -0
  331. package/dist/libs/tom-select/dist/js/plugins/input_autogrow.js +84 -0
  332. package/dist/libs/tom-select/dist/js/plugins/input_autogrow.js.map +1 -0
  333. package/dist/libs/tom-select/dist/js/plugins/no_active_items.js +33 -0
  334. package/dist/libs/tom-select/dist/js/plugins/no_active_items.js.map +1 -0
  335. package/dist/libs/tom-select/dist/js/plugins/no_backspace_delete.js +40 -0
  336. package/dist/libs/tom-select/dist/js/plugins/no_backspace_delete.js.map +1 -0
  337. package/dist/libs/tom-select/dist/js/plugins/optgroup_columns.js +117 -0
  338. package/dist/libs/tom-select/dist/js/plugins/optgroup_columns.js.map +1 -0
  339. package/dist/libs/tom-select/dist/js/plugins/remove_button.js +154 -0
  340. package/dist/libs/tom-select/dist/js/plugins/remove_button.js.map +1 -0
  341. package/dist/libs/tom-select/dist/js/plugins/restore_on_backspace.js +51 -0
  342. package/dist/libs/tom-select/dist/js/plugins/restore_on_backspace.js.map +1 -0
  343. package/dist/libs/tom-select/dist/js/plugins/virtual_scroll.js +279 -0
  344. package/dist/libs/tom-select/dist/js/plugins/virtual_scroll.js.map +1 -0
  345. package/dist/libs/tom-select/dist/js/tom-select.base.js +4165 -0
  346. package/dist/libs/tom-select/dist/js/tom-select.base.js.map +1 -0
  347. package/dist/libs/tom-select/dist/js/tom-select.base.min.js +144 -144
  348. package/dist/libs/tom-select/dist/js/tom-select.base.min.js.map +1 -0
  349. package/dist/libs/tom-select/dist/js/tom-select.complete.js +4978 -0
  350. package/dist/libs/tom-select/dist/js/tom-select.complete.js.map +1 -0
  351. package/dist/libs/tom-select/dist/js/tom-select.complete.min.js +363 -0
  352. package/dist/libs/tom-select/dist/js/tom-select.complete.min.js.map +1 -0
  353. package/dist/libs/tom-select/dist/js/tom-select.popular.js +4419 -0
  354. package/dist/libs/tom-select/dist/js/tom-select.popular.js.map +1 -0
  355. package/dist/libs/tom-select/dist/js/tom-select.popular.min.js +323 -0
  356. package/dist/libs/tom-select/dist/js/tom-select.popular.min.js.map +1 -0
  357. package/package.json +50 -29
  358. package/src/scss/_bootstrap-components.scss +1 -1
  359. package/src/scss/_bootstrap-config.scss +1 -0
  360. package/src/scss/_core.scss +1 -0
  361. package/src/scss/_mixins-override.scss +26 -26
  362. package/src/scss/_variables.scss +17 -9
  363. package/src/scss/demo.scss +4 -4
  364. package/src/scss/layout/_core.scss +23 -15
  365. package/src/scss/layout/_dark.scss +17 -13
  366. package/src/scss/layout/_navbar.scss +11 -10
  367. package/src/scss/mixins/_functions.scss +0 -14
  368. package/src/scss/mixins/_mixins.scss +29 -3
  369. package/src/scss/tabler-vendors.scss +4 -0
  370. package/src/scss/ui/_accordion.scss +4 -0
  371. package/src/scss/ui/_alerts.scss +7 -7
  372. package/src/scss/ui/_avatars.scss +11 -11
  373. package/src/scss/ui/_breadcrumbs.scss +1 -1
  374. package/src/scss/ui/_buttons.scss +89 -105
  375. package/src/scss/ui/_cards.scss +25 -28
  376. package/src/scss/ui/_carousel.scss +1 -1
  377. package/src/scss/ui/_datagrid.scss +17 -0
  378. package/src/scss/ui/_flags.scss +1 -1
  379. package/src/scss/ui/_forms.scss +7 -6
  380. package/src/scss/ui/_grid.scss +5 -5
  381. package/src/scss/ui/_legend.scss +1 -1
  382. package/src/scss/ui/_lists.scss +4 -4
  383. package/src/scss/ui/_modals.scss +1 -1
  384. package/src/scss/ui/_nav.scss +1 -1
  385. package/src/scss/ui/_offcanvas.scss +1 -1
  386. package/src/scss/ui/_progress.scss +2 -2
  387. package/src/scss/ui/_status.scss +27 -26
  388. package/src/scss/ui/_toasts.scss +2 -2
  389. package/src/scss/ui/forms/_form-custom.scss +2 -2
  390. package/src/scss/ui/forms/_form-imagecheck.scss +1 -1
  391. package/src/scss/ui/forms/_validation.scss +1 -1
  392. package/src/scss/utils/_colors.scss +9 -7
  393. package/src/scss/vendor/_dropzone.scss +27 -0
  394. package/src/scss/vendor/_fslightbox.scss +13 -0
  395. package/src/scss/vendor/_jsvectormap.scss +5 -5
  396. package/src/scss/vendor/_litepicker.scss +4 -4
  397. package/src/scss/vendor/_plyr.scss +3 -0
  398. package/src/scss/vendor/_tinymce.scss +25 -0
@@ -0,0 +1,4978 @@
1
+ /**
2
+ * Tom Select v2.1.0
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ */
5
+
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.TomSelect = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ /**
13
+ * MicroEvent - to make any js object an event emitter
14
+ *
15
+ * - pure javascript - server compatible, browser compatible
16
+ * - dont rely on the browser doms
17
+ * - super simple - you get it immediatly, no mistery, no magic involved
18
+ *
19
+ * @author Jerome Etienne (https://github.com/jeromeetienne)
20
+ */
21
+
22
+ /**
23
+ * Execute callback for each event in space separated list of event names
24
+ *
25
+ */
26
+ function forEvents(events, callback) {
27
+ events.split(/\s+/).forEach(event => {
28
+ callback(event);
29
+ });
30
+ }
31
+
32
+ class MicroEvent {
33
+ constructor() {
34
+ this._events = void 0;
35
+ this._events = {};
36
+ }
37
+
38
+ on(events, fct) {
39
+ forEvents(events, event => {
40
+ this._events[event] = this._events[event] || [];
41
+
42
+ this._events[event].push(fct);
43
+ });
44
+ }
45
+
46
+ off(events, fct) {
47
+ var n = arguments.length;
48
+
49
+ if (n === 0) {
50
+ this._events = {};
51
+ return;
52
+ }
53
+
54
+ forEvents(events, event => {
55
+ if (n === 1) return delete this._events[event];
56
+ if (event in this._events === false) return;
57
+
58
+ this._events[event].splice(this._events[event].indexOf(fct), 1);
59
+ });
60
+ }
61
+
62
+ trigger(events, ...args) {
63
+ var self = this;
64
+ forEvents(events, event => {
65
+ if (event in self._events === false) return;
66
+
67
+ for (let fct of self._events[event]) {
68
+ fct.apply(self, args);
69
+ }
70
+ });
71
+ }
72
+
73
+ }
74
+
75
+ /**
76
+ * microplugin.js
77
+ * Copyright (c) 2013 Brian Reavis & contributors
78
+ *
79
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
80
+ * file except in compliance with the License. You may obtain a copy of the License at:
81
+ * http://www.apache.org/licenses/LICENSE-2.0
82
+ *
83
+ * Unless required by applicable law or agreed to in writing, software distributed under
84
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
85
+ * ANY KIND, either express or implied. See the License for the specific language
86
+ * governing permissions and limitations under the License.
87
+ *
88
+ * @author Brian Reavis <brian@thirdroute.com>
89
+ */
90
+ function MicroPlugin(Interface) {
91
+ Interface.plugins = {};
92
+ return class extends Interface {
93
+ constructor(...args) {
94
+ super(...args);
95
+ this.plugins = {
96
+ names: [],
97
+ settings: {},
98
+ requested: {},
99
+ loaded: {}
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Registers a plugin.
105
+ *
106
+ * @param {function} fn
107
+ */
108
+ static define(name, fn) {
109
+ Interface.plugins[name] = {
110
+ 'name': name,
111
+ 'fn': fn
112
+ };
113
+ }
114
+ /**
115
+ * Initializes the listed plugins (with options).
116
+ * Acceptable formats:
117
+ *
118
+ * List (without options):
119
+ * ['a', 'b', 'c']
120
+ *
121
+ * List (with options):
122
+ * [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
123
+ *
124
+ * Hash (with options):
125
+ * {'a': { ... }, 'b': { ... }, 'c': { ... }}
126
+ *
127
+ * @param {array|object} plugins
128
+ */
129
+
130
+
131
+ initializePlugins(plugins) {
132
+ var key, name;
133
+ const self = this;
134
+ const queue = [];
135
+
136
+ if (Array.isArray(plugins)) {
137
+ plugins.forEach(plugin => {
138
+ if (typeof plugin === 'string') {
139
+ queue.push(plugin);
140
+ } else {
141
+ self.plugins.settings[plugin.name] = plugin.options;
142
+ queue.push(plugin.name);
143
+ }
144
+ });
145
+ } else if (plugins) {
146
+ for (key in plugins) {
147
+ if (plugins.hasOwnProperty(key)) {
148
+ self.plugins.settings[key] = plugins[key];
149
+ queue.push(key);
150
+ }
151
+ }
152
+ }
153
+
154
+ while (name = queue.shift()) {
155
+ self.require(name);
156
+ }
157
+ }
158
+
159
+ loadPlugin(name) {
160
+ var self = this;
161
+ var plugins = self.plugins;
162
+ var plugin = Interface.plugins[name];
163
+
164
+ if (!Interface.plugins.hasOwnProperty(name)) {
165
+ throw new Error('Unable to find "' + name + '" plugin');
166
+ }
167
+
168
+ plugins.requested[name] = true;
169
+ plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);
170
+ plugins.names.push(name);
171
+ }
172
+ /**
173
+ * Initializes a plugin.
174
+ *
175
+ */
176
+
177
+
178
+ require(name) {
179
+ var self = this;
180
+ var plugins = self.plugins;
181
+
182
+ if (!self.plugins.loaded.hasOwnProperty(name)) {
183
+ if (plugins.requested[name]) {
184
+ throw new Error('Plugin has circular dependency ("' + name + '")');
185
+ }
186
+
187
+ self.loadPlugin(name);
188
+ }
189
+
190
+ return plugins.loaded[name];
191
+ }
192
+
193
+ };
194
+ }
195
+
196
+ // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
197
+ // https://github.com/andrewrk/node-diacritics/blob/master/index.js
198
+ var latin_pat;
199
+ const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}]'; // \u{2bc}
200
+
201
+ const accent_reg = new RegExp(accent_pat, 'gu');
202
+ var diacritic_patterns;
203
+ const latin_convert = {
204
+ 'æ': 'ae',
205
+ 'ⱥ': 'a',
206
+ 'ø': 'o'
207
+ };
208
+ const convert_pat = new RegExp(Object.keys(latin_convert).join('|'), 'gu');
209
+ const code_points = [[0, 65535]];
210
+ /**
211
+ * Remove accents
212
+ * via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
213
+ *
214
+ */
215
+
216
+ const asciifold = str => {
217
+ return str.normalize('NFKD').replace(accent_reg, '').toLowerCase().replace(convert_pat, function (foreignletter) {
218
+ return latin_convert[foreignletter];
219
+ });
220
+ };
221
+ /**
222
+ * Convert array of strings to a regular expression
223
+ * ex ['ab','a'] => (?:ab|a)
224
+ * ex ['a','b'] => [ab]
225
+ *
226
+ */
227
+
228
+ const arrayToPattern = (chars, glue = '|') => {
229
+ if (chars.length == 1) {
230
+ return chars[0];
231
+ }
232
+
233
+ var longest = 1;
234
+ chars.forEach(a => {
235
+ longest = Math.max(longest, a.length);
236
+ });
237
+
238
+ if (longest == 1) {
239
+ return '[' + chars.join('') + ']';
240
+ }
241
+
242
+ return '(?:' + chars.join(glue) + ')';
243
+ };
244
+ const escapeToPattern = chars => {
245
+ const escaped = chars.map(diacritic => escape_regex(diacritic));
246
+ return arrayToPattern(escaped);
247
+ };
248
+ /**
249
+ * Get all possible combinations of substrings that add up to the given string
250
+ * https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string
251
+ *
252
+ */
253
+
254
+ const allSubstrings = input => {
255
+ if (input.length === 1) return [[input]];
256
+ var result = [];
257
+ allSubstrings(input.substring(1)).forEach(function (subresult) {
258
+ var tmp = subresult.slice(0);
259
+ tmp[0] = input.charAt(0) + tmp[0];
260
+ result.push(tmp);
261
+ tmp = subresult.slice(0);
262
+ tmp.unshift(input.charAt(0));
263
+ result.push(tmp);
264
+ });
265
+ return result;
266
+ };
267
+ /**
268
+ * Generate a list of diacritics from the list of code points
269
+ *
270
+ */
271
+
272
+ const generateDiacritics = code_points => {
273
+ var diacritics = {};
274
+ code_points.forEach(code_range => {
275
+ for (let i = code_range[0]; i <= code_range[1]; i++) {
276
+ let diacritic = String.fromCharCode(i);
277
+ let latin = asciifold(diacritic);
278
+
279
+ if (latin == diacritic.toLowerCase()) {
280
+ continue;
281
+ } // skip when latin is a string longer than 3 characters long
282
+ // bc the resulting regex patterns will be long
283
+ // eg:
284
+ // latin صلى الله عليه وسلم length 18 code point 65018
285
+ // latin جل جلاله length 8 code point 65019
286
+
287
+
288
+ if (latin.length > 3) {
289
+ continue;
290
+ }
291
+
292
+ if (!(latin in diacritics)) {
293
+ diacritics[latin] = [latin];
294
+ }
295
+
296
+ var patt = new RegExp(escapeToPattern(diacritics[latin]), 'iu');
297
+
298
+ if (diacritic.match(patt)) {
299
+ continue;
300
+ }
301
+
302
+ diacritics[latin].push(diacritic);
303
+ }
304
+ }); // filter out if there's only one character in the list
305
+
306
+ let latin_chars = Object.keys(diacritics);
307
+
308
+ for (let i = 0; i < latin_chars.length; i++) {
309
+ const latin = latin_chars[i];
310
+
311
+ if (diacritics[latin].length < 2) {
312
+ delete diacritics[latin];
313
+ }
314
+ } // latin character pattern
315
+ // match longer substrings first
316
+
317
+
318
+ latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length);
319
+ latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns
320
+ // ae needs:
321
+ // (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))
322
+
323
+ var diacritic_patterns = {};
324
+ latin_chars.sort((a, b) => a.length - b.length).forEach(latin => {
325
+ var substrings = allSubstrings(latin);
326
+ var pattern = substrings.map(sub_pat => {
327
+ sub_pat = sub_pat.map(l => {
328
+ if (diacritics.hasOwnProperty(l)) {
329
+ return escapeToPattern(diacritics[l]);
330
+ }
331
+
332
+ return l;
333
+ });
334
+ return arrayToPattern(sub_pat, '');
335
+ });
336
+ diacritic_patterns[latin] = arrayToPattern(pattern);
337
+ });
338
+ return diacritic_patterns;
339
+ };
340
+ /**
341
+ * Expand a regular expression pattern to include diacritics
342
+ * eg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/
343
+ *
344
+ */
345
+
346
+ const diacriticRegexPoints = regex => {
347
+ if (diacritic_patterns === undefined) {
348
+ diacritic_patterns = generateDiacritics(code_points);
349
+ }
350
+
351
+ const decomposed = regex.normalize('NFKD').toLowerCase();
352
+ return decomposed.split(latin_pat).map(part => {
353
+ // "ffl" or "ffl"
354
+ const no_accent = asciifold(part);
355
+
356
+ if (no_accent == '') {
357
+ return '';
358
+ }
359
+
360
+ if (diacritic_patterns.hasOwnProperty(no_accent)) {
361
+ return diacritic_patterns[no_accent];
362
+ }
363
+
364
+ return part;
365
+ }).join('');
366
+ };
367
+
368
+ // @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
369
+
370
+ /**
371
+ * A property getter resolving dot-notation
372
+ * @param {Object} obj The root object to fetch property on
373
+ * @param {String} name The optionally dotted property name to fetch
374
+ * @return {Object} The resolved property value
375
+ */
376
+ const getAttr = (obj, name) => {
377
+ if (!obj) return;
378
+ return obj[name];
379
+ };
380
+ /**
381
+ * A property getter resolving dot-notation
382
+ * @param {Object} obj The root object to fetch property on
383
+ * @param {String} name The optionally dotted property name to fetch
384
+ * @return {Object} The resolved property value
385
+ */
386
+
387
+ const getAttrNesting = (obj, name) => {
388
+ if (!obj) return;
389
+ var part,
390
+ names = name.split(".");
391
+
392
+ while ((part = names.shift()) && (obj = obj[part]));
393
+
394
+ return obj;
395
+ };
396
+ /**
397
+ * Calculates how close of a match the
398
+ * given value is against a search token.
399
+ *
400
+ */
401
+
402
+ const scoreValue = (value, token, weight) => {
403
+ var score, pos;
404
+ if (!value) return 0;
405
+ value = value + '';
406
+ pos = value.search(token.regex);
407
+ if (pos === -1) return 0;
408
+ score = token.string.length / value.length;
409
+ if (pos === 0) score += 0.5;
410
+ return score * weight;
411
+ };
412
+ /**
413
+ *
414
+ * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error
415
+ */
416
+
417
+ const escape_regex = str => {
418
+ return (str + '').replace(/([\$\(-\+\.\?\[-\^\{-\}])/g, '\\$1');
419
+ };
420
+ /**
421
+ * Cast object property to an array if it exists and has a value
422
+ *
423
+ */
424
+
425
+ const propToArray = (obj, key) => {
426
+ var value = obj[key];
427
+ if (typeof value == 'function') return value;
428
+
429
+ if (value && !Array.isArray(value)) {
430
+ obj[key] = [value];
431
+ }
432
+ };
433
+ /**
434
+ * Iterates over arrays and hashes.
435
+ *
436
+ * ```
437
+ * iterate(this.items, function(item, id) {
438
+ * // invoked for each item
439
+ * });
440
+ * ```
441
+ *
442
+ */
443
+
444
+ const iterate = (object, callback) => {
445
+ if (Array.isArray(object)) {
446
+ object.forEach(callback);
447
+ } else {
448
+ for (var key in object) {
449
+ if (object.hasOwnProperty(key)) {
450
+ callback(object[key], key);
451
+ }
452
+ }
453
+ }
454
+ };
455
+ const cmp = (a, b) => {
456
+ if (typeof a === 'number' && typeof b === 'number') {
457
+ return a > b ? 1 : a < b ? -1 : 0;
458
+ }
459
+
460
+ a = asciifold(a + '').toLowerCase();
461
+ b = asciifold(b + '').toLowerCase();
462
+ if (a > b) return 1;
463
+ if (b > a) return -1;
464
+ return 0;
465
+ };
466
+
467
+ /**
468
+ * sifter.js
469
+ * Copyright (c) 2013–2020 Brian Reavis & contributors
470
+ *
471
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
472
+ * file except in compliance with the License. You may obtain a copy of the License at:
473
+ * http://www.apache.org/licenses/LICENSE-2.0
474
+ *
475
+ * Unless required by applicable law or agreed to in writing, software distributed under
476
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
477
+ * ANY KIND, either express or implied. See the License for the specific language
478
+ * governing permissions and limitations under the License.
479
+ *
480
+ * @author Brian Reavis <brian@thirdroute.com>
481
+ */
482
+
483
+ class Sifter {
484
+ // []|{};
485
+
486
+ /**
487
+ * Textually searches arrays and hashes of objects
488
+ * by property (or multiple properties). Designed
489
+ * specifically for autocomplete.
490
+ *
491
+ */
492
+ constructor(items, settings) {
493
+ this.items = void 0;
494
+ this.settings = void 0;
495
+ this.items = items;
496
+ this.settings = settings || {
497
+ diacritics: true
498
+ };
499
+ }
500
+
501
+ /**
502
+ * Splits a search string into an array of individual
503
+ * regexps to be used to match results.
504
+ *
505
+ */
506
+ tokenize(query, respect_word_boundaries, weights) {
507
+ if (!query || !query.length) return [];
508
+ const tokens = [];
509
+ const words = query.split(/\s+/);
510
+ var field_regex;
511
+
512
+ if (weights) {
513
+ field_regex = new RegExp('^(' + Object.keys(weights).map(escape_regex).join('|') + ')\:(.*)$');
514
+ }
515
+
516
+ words.forEach(word => {
517
+ let field_match;
518
+ let field = null;
519
+ let regex = null; // look for "field:query" tokens
520
+
521
+ if (field_regex && (field_match = word.match(field_regex))) {
522
+ field = field_match[1];
523
+ word = field_match[2];
524
+ }
525
+
526
+ if (word.length > 0) {
527
+ if (this.settings.diacritics) {
528
+ regex = diacriticRegexPoints(word);
529
+ } else {
530
+ regex = escape_regex(word);
531
+ }
532
+
533
+ if (respect_word_boundaries) regex = "\\b" + regex;
534
+ }
535
+
536
+ tokens.push({
537
+ string: word,
538
+ regex: regex ? new RegExp(regex, 'iu') : null,
539
+ field: field
540
+ });
541
+ });
542
+ return tokens;
543
+ }
544
+
545
+ /**
546
+ * Returns a function to be used to score individual results.
547
+ *
548
+ * Good matches will have a higher score than poor matches.
549
+ * If an item is not a match, 0 will be returned by the function.
550
+ *
551
+ * @returns {function}
552
+ */
553
+ getScoreFunction(query, options) {
554
+ var search = this.prepareSearch(query, options);
555
+ return this._getScoreFunction(search);
556
+ }
557
+
558
+ _getScoreFunction(search) {
559
+ const tokens = search.tokens,
560
+ token_count = tokens.length;
561
+
562
+ if (!token_count) {
563
+ return function () {
564
+ return 0;
565
+ };
566
+ }
567
+
568
+ const fields = search.options.fields,
569
+ weights = search.weights,
570
+ field_count = fields.length,
571
+ getAttrFn = search.getAttrFn;
572
+
573
+ if (!field_count) {
574
+ return function () {
575
+ return 1;
576
+ };
577
+ }
578
+ /**
579
+ * Calculates the score of an object
580
+ * against the search query.
581
+ *
582
+ */
583
+
584
+
585
+ const scoreObject = function () {
586
+ if (field_count === 1) {
587
+ return function (token, data) {
588
+ const field = fields[0].field;
589
+ return scoreValue(getAttrFn(data, field), token, weights[field]);
590
+ };
591
+ }
592
+
593
+ return function (token, data) {
594
+ var sum = 0; // is the token specific to a field?
595
+
596
+ if (token.field) {
597
+ const value = getAttrFn(data, token.field);
598
+
599
+ if (!token.regex && value) {
600
+ sum += 1 / field_count;
601
+ } else {
602
+ sum += scoreValue(value, token, 1);
603
+ }
604
+ } else {
605
+ iterate(weights, (weight, field) => {
606
+ sum += scoreValue(getAttrFn(data, field), token, weight);
607
+ });
608
+ }
609
+
610
+ return sum / field_count;
611
+ };
612
+ }();
613
+
614
+ if (token_count === 1) {
615
+ return function (data) {
616
+ return scoreObject(tokens[0], data);
617
+ };
618
+ }
619
+
620
+ if (search.options.conjunction === 'and') {
621
+ return function (data) {
622
+ var i = 0,
623
+ score,
624
+ sum = 0;
625
+
626
+ for (; i < token_count; i++) {
627
+ score = scoreObject(tokens[i], data);
628
+ if (score <= 0) return 0;
629
+ sum += score;
630
+ }
631
+
632
+ return sum / token_count;
633
+ };
634
+ } else {
635
+ return function (data) {
636
+ var sum = 0;
637
+ iterate(tokens, token => {
638
+ sum += scoreObject(token, data);
639
+ });
640
+ return sum / token_count;
641
+ };
642
+ }
643
+ }
644
+
645
+ /**
646
+ * Returns a function that can be used to compare two
647
+ * results, for sorting purposes. If no sorting should
648
+ * be performed, `null` will be returned.
649
+ *
650
+ * @return function(a,b)
651
+ */
652
+ getSortFunction(query, options) {
653
+ var search = this.prepareSearch(query, options);
654
+ return this._getSortFunction(search);
655
+ }
656
+
657
+ _getSortFunction(search) {
658
+ var i, n, implicit_score;
659
+ const self = this,
660
+ options = search.options,
661
+ sort = !search.query && options.sort_empty ? options.sort_empty : options.sort,
662
+ sort_flds = [],
663
+ multipliers = [];
664
+
665
+ if (typeof sort == 'function') {
666
+ return sort.bind(this);
667
+ }
668
+ /**
669
+ * Fetches the specified sort field value
670
+ * from a search result item.
671
+ *
672
+ */
673
+
674
+
675
+ const get_field = function get_field(name, result) {
676
+ if (name === '$score') return result.score;
677
+ return search.getAttrFn(self.items[result.id], name);
678
+ }; // parse options
679
+
680
+
681
+ if (sort) {
682
+ for (i = 0, n = sort.length; i < n; i++) {
683
+ if (search.query || sort[i].field !== '$score') {
684
+ sort_flds.push(sort[i]);
685
+ }
686
+ }
687
+ } // the "$score" field is implied to be the primary
688
+ // sort field, unless it's manually specified
689
+
690
+
691
+ if (search.query) {
692
+ implicit_score = true;
693
+
694
+ for (i = 0, n = sort_flds.length; i < n; i++) {
695
+ if (sort_flds[i].field === '$score') {
696
+ implicit_score = false;
697
+ break;
698
+ }
699
+ }
700
+
701
+ if (implicit_score) {
702
+ sort_flds.unshift({
703
+ field: '$score',
704
+ direction: 'desc'
705
+ });
706
+ }
707
+ } else {
708
+ for (i = 0, n = sort_flds.length; i < n; i++) {
709
+ if (sort_flds[i].field === '$score') {
710
+ sort_flds.splice(i, 1);
711
+ break;
712
+ }
713
+ }
714
+ }
715
+
716
+ for (i = 0, n = sort_flds.length; i < n; i++) {
717
+ multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1);
718
+ } // build function
719
+
720
+
721
+ const sort_flds_count = sort_flds.length;
722
+
723
+ if (!sort_flds_count) {
724
+ return null;
725
+ } else if (sort_flds_count === 1) {
726
+ const sort_fld = sort_flds[0].field;
727
+ const multiplier = multipliers[0];
728
+ return function (a, b) {
729
+ return multiplier * cmp(get_field(sort_fld, a), get_field(sort_fld, b));
730
+ };
731
+ } else {
732
+ return function (a, b) {
733
+ var i, result, field;
734
+
735
+ for (i = 0; i < sort_flds_count; i++) {
736
+ field = sort_flds[i].field;
737
+ result = multipliers[i] * cmp(get_field(field, a), get_field(field, b));
738
+ if (result) return result;
739
+ }
740
+
741
+ return 0;
742
+ };
743
+ }
744
+ }
745
+
746
+ /**
747
+ * Parses a search query and returns an object
748
+ * with tokens and fields ready to be populated
749
+ * with results.
750
+ *
751
+ */
752
+ prepareSearch(query, optsUser) {
753
+ const weights = {};
754
+ var options = Object.assign({}, optsUser);
755
+ propToArray(options, 'sort');
756
+ propToArray(options, 'sort_empty'); // convert fields to new format
757
+
758
+ if (options.fields) {
759
+ propToArray(options, 'fields');
760
+ const fields = [];
761
+ options.fields.forEach(field => {
762
+ if (typeof field == 'string') {
763
+ field = {
764
+ field: field,
765
+ weight: 1
766
+ };
767
+ }
768
+
769
+ fields.push(field);
770
+ weights[field.field] = 'weight' in field ? field.weight : 1;
771
+ });
772
+ options.fields = fields;
773
+ }
774
+
775
+ return {
776
+ options: options,
777
+ query: query.toLowerCase().trim(),
778
+ tokens: this.tokenize(query, options.respect_word_boundaries, weights),
779
+ total: 0,
780
+ items: [],
781
+ weights: weights,
782
+ getAttrFn: options.nesting ? getAttrNesting : getAttr
783
+ };
784
+ }
785
+
786
+ /**
787
+ * Searches through all items and returns a sorted array of matches.
788
+ *
789
+ */
790
+ search(query, options) {
791
+ var self = this,
792
+ score,
793
+ search;
794
+ search = this.prepareSearch(query, options);
795
+ options = search.options;
796
+ query = search.query; // generate result scoring function
797
+
798
+ const fn_score = options.score || self._getScoreFunction(search); // perform search and sort
799
+
800
+
801
+ if (query.length) {
802
+ iterate(self.items, (item, id) => {
803
+ score = fn_score(item);
804
+
805
+ if (options.filter === false || score > 0) {
806
+ search.items.push({
807
+ 'score': score,
808
+ 'id': id
809
+ });
810
+ }
811
+ });
812
+ } else {
813
+ iterate(self.items, (_, id) => {
814
+ search.items.push({
815
+ 'score': 1,
816
+ 'id': id
817
+ });
818
+ });
819
+ }
820
+
821
+ const fn_sort = self._getSortFunction(search);
822
+
823
+ if (fn_sort) search.items.sort(fn_sort); // apply limits
824
+
825
+ search.total = search.items.length;
826
+
827
+ if (typeof options.limit === 'number') {
828
+ search.items = search.items.slice(0, options.limit);
829
+ }
830
+
831
+ return search;
832
+ }
833
+
834
+ }
835
+
836
+ /**
837
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string
838
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
839
+ *
840
+ * param query should be {}
841
+ */
842
+
843
+ const getDom = query => {
844
+ if (query.jquery) {
845
+ return query[0];
846
+ }
847
+
848
+ if (query instanceof HTMLElement) {
849
+ return query;
850
+ }
851
+
852
+ if (isHtmlString(query)) {
853
+ let div = document.createElement('div');
854
+ div.innerHTML = query.trim(); // Never return a text node of whitespace as the result
855
+
856
+ return div.firstChild;
857
+ }
858
+
859
+ return document.querySelector(query);
860
+ };
861
+ const isHtmlString = arg => {
862
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) {
863
+ return true;
864
+ }
865
+
866
+ return false;
867
+ };
868
+ const escapeQuery = query => {
869
+ return query.replace(/['"\\]/g, '\\$&');
870
+ };
871
+ /**
872
+ * Dispatch an event
873
+ *
874
+ */
875
+
876
+ const triggerEvent = (dom_el, event_name) => {
877
+ var event = document.createEvent('HTMLEvents');
878
+ event.initEvent(event_name, true, false);
879
+ dom_el.dispatchEvent(event);
880
+ };
881
+ /**
882
+ * Apply CSS rules to a dom element
883
+ *
884
+ */
885
+
886
+ const applyCSS = (dom_el, css) => {
887
+ Object.assign(dom_el.style, css);
888
+ };
889
+ /**
890
+ * Add css classes
891
+ *
892
+ */
893
+
894
+ const addClasses = (elmts, ...classes) => {
895
+ var norm_classes = classesArray(classes);
896
+ elmts = castAsArray(elmts);
897
+ elmts.map(el => {
898
+ norm_classes.map(cls => {
899
+ el.classList.add(cls);
900
+ });
901
+ });
902
+ };
903
+ /**
904
+ * Remove css classes
905
+ *
906
+ */
907
+
908
+ const removeClasses = (elmts, ...classes) => {
909
+ var norm_classes = classesArray(classes);
910
+ elmts = castAsArray(elmts);
911
+ elmts.map(el => {
912
+ norm_classes.map(cls => {
913
+ el.classList.remove(cls);
914
+ });
915
+ });
916
+ };
917
+ /**
918
+ * Return arguments
919
+ *
920
+ */
921
+
922
+ const classesArray = args => {
923
+ var classes = [];
924
+ iterate(args, _classes => {
925
+ if (typeof _classes === 'string') {
926
+ _classes = _classes.trim().split(/[\11\12\14\15\40]/);
927
+ }
928
+
929
+ if (Array.isArray(_classes)) {
930
+ classes = classes.concat(_classes);
931
+ }
932
+ });
933
+ return classes.filter(Boolean);
934
+ };
935
+ /**
936
+ * Create an array from arg if it's not already an array
937
+ *
938
+ */
939
+
940
+ const castAsArray = arg => {
941
+ if (!Array.isArray(arg)) {
942
+ arg = [arg];
943
+ }
944
+
945
+ return arg;
946
+ };
947
+ /**
948
+ * Get the closest node to the evt.target matching the selector
949
+ * Stops at wrapper
950
+ *
951
+ */
952
+
953
+ const parentMatch = (target, selector, wrapper) => {
954
+ if (wrapper && !wrapper.contains(target)) {
955
+ return;
956
+ }
957
+
958
+ while (target && target.matches) {
959
+ if (target.matches(selector)) {
960
+ return target;
961
+ }
962
+
963
+ target = target.parentNode;
964
+ }
965
+ };
966
+ /**
967
+ * Get the first or last item from an array
968
+ *
969
+ * > 0 - right (last)
970
+ * <= 0 - left (first)
971
+ *
972
+ */
973
+
974
+ const getTail = (list, direction = 0) => {
975
+ if (direction > 0) {
976
+ return list[list.length - 1];
977
+ }
978
+
979
+ return list[0];
980
+ };
981
+ /**
982
+ * Return true if an object is empty
983
+ *
984
+ */
985
+
986
+ const isEmptyObject = obj => {
987
+ return Object.keys(obj).length === 0;
988
+ };
989
+ /**
990
+ * Get the index of an element amongst sibling nodes of the same type
991
+ *
992
+ */
993
+
994
+ const nodeIndex = (el, amongst) => {
995
+ if (!el) return -1;
996
+ amongst = amongst || el.nodeName;
997
+ var i = 0;
998
+
999
+ while (el = el.previousElementSibling) {
1000
+ if (el.matches(amongst)) {
1001
+ i++;
1002
+ }
1003
+ }
1004
+
1005
+ return i;
1006
+ };
1007
+ /**
1008
+ * Set attributes of an element
1009
+ *
1010
+ */
1011
+
1012
+ const setAttr = (el, attrs) => {
1013
+ iterate(attrs, (val, attr) => {
1014
+ if (val == null) {
1015
+ el.removeAttribute(attr);
1016
+ } else {
1017
+ el.setAttribute(attr, '' + val);
1018
+ }
1019
+ });
1020
+ };
1021
+ /**
1022
+ * Replace a node
1023
+ */
1024
+
1025
+ const replaceNode = (existing, replacement) => {
1026
+ if (existing.parentNode) existing.parentNode.replaceChild(replacement, existing);
1027
+ };
1028
+
1029
+ /**
1030
+ * highlight v3 | MIT license | Johann Burkard <jb@eaio.com>
1031
+ * Highlights arbitrary terms in a node.
1032
+ *
1033
+ * - Modified by Marshal <beatgates@gmail.com> 2011-6-24 (added regex)
1034
+ * - Modified by Brian Reavis <brian@thirdroute.com> 2012-8-27 (cleanup)
1035
+ */
1036
+ const highlight = (element, regex) => {
1037
+ if (regex === null) return; // convet string to regex
1038
+
1039
+ if (typeof regex === 'string') {
1040
+ if (!regex.length) return;
1041
+ regex = new RegExp(regex, 'i');
1042
+ } // Wrap matching part of text node with highlighting <span>, e.g.
1043
+ // Soccer -> <span class="highlight">Soc</span>cer for regex = /soc/i
1044
+
1045
+
1046
+ const highlightText = node => {
1047
+ var match = node.data.match(regex);
1048
+
1049
+ if (match && node.data.length > 0) {
1050
+ var spannode = document.createElement('span');
1051
+ spannode.className = 'highlight';
1052
+ var middlebit = node.splitText(match.index);
1053
+ middlebit.splitText(match[0].length);
1054
+ var middleclone = middlebit.cloneNode(true);
1055
+ spannode.appendChild(middleclone);
1056
+ replaceNode(middlebit, spannode);
1057
+ return 1;
1058
+ }
1059
+
1060
+ return 0;
1061
+ }; // Recurse element node, looking for child text nodes to highlight, unless element
1062
+ // is childless, <script>, <style>, or already highlighted: <span class="hightlight">
1063
+
1064
+
1065
+ const highlightChildren = node => {
1066
+ if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName) && (node.className !== 'highlight' || node.tagName !== 'SPAN')) {
1067
+ for (var i = 0; i < node.childNodes.length; ++i) {
1068
+ i += highlightRecursive(node.childNodes[i]);
1069
+ }
1070
+ }
1071
+ };
1072
+
1073
+ const highlightRecursive = node => {
1074
+ if (node.nodeType === 3) {
1075
+ return highlightText(node);
1076
+ }
1077
+
1078
+ highlightChildren(node);
1079
+ return 0;
1080
+ };
1081
+
1082
+ highlightRecursive(element);
1083
+ };
1084
+ /**
1085
+ * removeHighlight fn copied from highlight v5 and
1086
+ * edited to remove with(), pass js strict mode, and use without jquery
1087
+ */
1088
+
1089
+ const removeHighlight = el => {
1090
+ var elements = el.querySelectorAll("span.highlight");
1091
+ Array.prototype.forEach.call(elements, function (el) {
1092
+ var parent = el.parentNode;
1093
+ parent.replaceChild(el.firstChild, el);
1094
+ parent.normalize();
1095
+ });
1096
+ };
1097
+
1098
+ const KEY_A = 65;
1099
+ const KEY_RETURN = 13;
1100
+ const KEY_ESC = 27;
1101
+ const KEY_LEFT = 37;
1102
+ const KEY_UP = 38;
1103
+ const KEY_RIGHT = 39;
1104
+ const KEY_DOWN = 40;
1105
+ const KEY_BACKSPACE = 8;
1106
+ const KEY_DELETE = 46;
1107
+ const KEY_TAB = 9;
1108
+ const IS_MAC = typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);
1109
+ const KEY_SHORTCUT = IS_MAC ? 'metaKey' : 'ctrlKey'; // ctrl key or apple key for ma
1110
+
1111
+ var defaults = {
1112
+ options: [],
1113
+ optgroups: [],
1114
+ plugins: [],
1115
+ delimiter: ',',
1116
+ splitOn: null,
1117
+ // regexp or string for splitting up values from a paste command
1118
+ persist: true,
1119
+ diacritics: true,
1120
+ create: null,
1121
+ createOnBlur: false,
1122
+ createFilter: null,
1123
+ highlight: true,
1124
+ openOnFocus: true,
1125
+ shouldOpen: null,
1126
+ maxOptions: 50,
1127
+ maxItems: null,
1128
+ hideSelected: null,
1129
+ duplicates: false,
1130
+ addPrecedence: false,
1131
+ selectOnTab: false,
1132
+ preload: null,
1133
+ allowEmptyOption: false,
1134
+ //closeAfterSelect: false,
1135
+ loadThrottle: 300,
1136
+ loadingClass: 'loading',
1137
+ dataAttr: null,
1138
+ //'data-data',
1139
+ optgroupField: 'optgroup',
1140
+ valueField: 'value',
1141
+ labelField: 'text',
1142
+ disabledField: 'disabled',
1143
+ optgroupLabelField: 'label',
1144
+ optgroupValueField: 'value',
1145
+ lockOptgroupOrder: false,
1146
+ sortField: '$order',
1147
+ searchField: ['text'],
1148
+ searchConjunction: 'and',
1149
+ mode: null,
1150
+ wrapperClass: 'ts-wrapper',
1151
+ controlClass: 'ts-control',
1152
+ dropdownClass: 'ts-dropdown',
1153
+ dropdownContentClass: 'ts-dropdown-content',
1154
+ itemClass: 'item',
1155
+ optionClass: 'option',
1156
+ dropdownParent: null,
1157
+ controlInput: '<input type="text" autocomplete="off" size="1" />',
1158
+ copyClassesToDropdown: false,
1159
+ placeholder: null,
1160
+ hidePlaceholder: null,
1161
+ shouldLoad: function (query) {
1162
+ return query.length > 0;
1163
+ },
1164
+
1165
+ /*
1166
+ load : null, // function(query, callback) { ... }
1167
+ score : null, // function(search) { ... }
1168
+ onInitialize : null, // function() { ... }
1169
+ onChange : null, // function(value) { ... }
1170
+ onItemAdd : null, // function(value, $item) { ... }
1171
+ onItemRemove : null, // function(value) { ... }
1172
+ onClear : null, // function() { ... }
1173
+ onOptionAdd : null, // function(value, data) { ... }
1174
+ onOptionRemove : null, // function(value) { ... }
1175
+ onOptionClear : null, // function() { ... }
1176
+ onOptionGroupAdd : null, // function(id, data) { ... }
1177
+ onOptionGroupRemove : null, // function(id) { ... }
1178
+ onOptionGroupClear : null, // function() { ... }
1179
+ onDropdownOpen : null, // function(dropdown) { ... }
1180
+ onDropdownClose : null, // function(dropdown) { ... }
1181
+ onType : null, // function(str) { ... }
1182
+ onDelete : null, // function(values) { ... }
1183
+ */
1184
+ render: {
1185
+ /*
1186
+ item: null,
1187
+ optgroup: null,
1188
+ optgroup_header: null,
1189
+ option: null,
1190
+ option_create: null
1191
+ */
1192
+ }
1193
+ };
1194
+
1195
+ /**
1196
+ * Converts a scalar to its best string representation
1197
+ * for hash keys and HTML attribute values.
1198
+ *
1199
+ * Transformations:
1200
+ * 'str' -> 'str'
1201
+ * null -> ''
1202
+ * undefined -> ''
1203
+ * true -> '1'
1204
+ * false -> '0'
1205
+ * 0 -> '0'
1206
+ * 1 -> '1'
1207
+ *
1208
+ */
1209
+ const hash_key = value => {
1210
+ if (typeof value === 'undefined' || value === null) return null;
1211
+ return get_hash(value);
1212
+ };
1213
+ const get_hash = value => {
1214
+ if (typeof value === 'boolean') return value ? '1' : '0';
1215
+ return value + '';
1216
+ };
1217
+ /**
1218
+ * Escapes a string for use within HTML.
1219
+ *
1220
+ */
1221
+
1222
+ const escape_html = str => {
1223
+ return (str + '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
1224
+ };
1225
+ /**
1226
+ * Debounce the user provided load function
1227
+ *
1228
+ */
1229
+
1230
+ const loadDebounce = (fn, delay) => {
1231
+ var timeout;
1232
+ return function (value, callback) {
1233
+ var self = this;
1234
+
1235
+ if (timeout) {
1236
+ self.loading = Math.max(self.loading - 1, 0);
1237
+ clearTimeout(timeout);
1238
+ }
1239
+
1240
+ timeout = setTimeout(function () {
1241
+ timeout = null;
1242
+ self.loadedSearches[value] = true;
1243
+ fn.call(self, value, callback);
1244
+ }, delay);
1245
+ };
1246
+ };
1247
+ /**
1248
+ * Debounce all fired events types listed in `types`
1249
+ * while executing the provided `fn`.
1250
+ *
1251
+ */
1252
+
1253
+ const debounce_events = (self, types, fn) => {
1254
+ var type;
1255
+ var trigger = self.trigger;
1256
+ var event_args = {}; // override trigger method
1257
+
1258
+ self.trigger = function () {
1259
+ var type = arguments[0];
1260
+
1261
+ if (types.indexOf(type) !== -1) {
1262
+ event_args[type] = arguments;
1263
+ } else {
1264
+ return trigger.apply(self, arguments);
1265
+ }
1266
+ }; // invoke provided function
1267
+
1268
+
1269
+ fn.apply(self, []);
1270
+ self.trigger = trigger; // trigger queued events
1271
+
1272
+ for (type of types) {
1273
+ if (type in event_args) {
1274
+ trigger.apply(self, event_args[type]);
1275
+ }
1276
+ }
1277
+ };
1278
+ /**
1279
+ * Determines the current selection within a text input control.
1280
+ * Returns an object containing:
1281
+ * - start
1282
+ * - length
1283
+ *
1284
+ */
1285
+
1286
+ const getSelection = input => {
1287
+ return {
1288
+ start: input.selectionStart || 0,
1289
+ length: (input.selectionEnd || 0) - (input.selectionStart || 0)
1290
+ };
1291
+ };
1292
+ /**
1293
+ * Prevent default
1294
+ *
1295
+ */
1296
+
1297
+ const preventDefault = (evt, stop = false) => {
1298
+ if (evt) {
1299
+ evt.preventDefault();
1300
+
1301
+ if (stop) {
1302
+ evt.stopPropagation();
1303
+ }
1304
+ }
1305
+ };
1306
+ /**
1307
+ * Prevent default
1308
+ *
1309
+ */
1310
+
1311
+ const addEvent = (target, type, callback, options) => {
1312
+ target.addEventListener(type, callback, options);
1313
+ };
1314
+ /**
1315
+ * Return true if the requested key is down
1316
+ * Will return false if more than one control character is pressed ( when [ctrl+shift+a] != [ctrl+a] )
1317
+ * The current evt may not always set ( eg calling advanceSelection() )
1318
+ *
1319
+ */
1320
+
1321
+ const isKeyDown = (key_name, evt) => {
1322
+ if (!evt) {
1323
+ return false;
1324
+ }
1325
+
1326
+ if (!evt[key_name]) {
1327
+ return false;
1328
+ }
1329
+
1330
+ var count = (evt.altKey ? 1 : 0) + (evt.ctrlKey ? 1 : 0) + (evt.shiftKey ? 1 : 0) + (evt.metaKey ? 1 : 0);
1331
+
1332
+ if (count === 1) {
1333
+ return true;
1334
+ }
1335
+
1336
+ return false;
1337
+ };
1338
+ /**
1339
+ * Get the id of an element
1340
+ * If the id attribute is not set, set the attribute with the given id
1341
+ *
1342
+ */
1343
+
1344
+ const getId = (el, id) => {
1345
+ const existing_id = el.getAttribute('id');
1346
+
1347
+ if (existing_id) {
1348
+ return existing_id;
1349
+ }
1350
+
1351
+ el.setAttribute('id', id);
1352
+ return id;
1353
+ };
1354
+ /**
1355
+ * Returns a string with backslashes added before characters that need to be escaped.
1356
+ */
1357
+
1358
+ const addSlashes = str => {
1359
+ return str.replace(/[\\"']/g, '\\$&');
1360
+ };
1361
+ /**
1362
+ *
1363
+ */
1364
+
1365
+ const append = (parent, node) => {
1366
+ if (node) parent.append(node);
1367
+ };
1368
+
1369
+ function getSettings(input, settings_user) {
1370
+ var settings = Object.assign({}, defaults, settings_user);
1371
+ var attr_data = settings.dataAttr;
1372
+ var field_label = settings.labelField;
1373
+ var field_value = settings.valueField;
1374
+ var field_disabled = settings.disabledField;
1375
+ var field_optgroup = settings.optgroupField;
1376
+ var field_optgroup_label = settings.optgroupLabelField;
1377
+ var field_optgroup_value = settings.optgroupValueField;
1378
+ var tag_name = input.tagName.toLowerCase();
1379
+ var placeholder = input.getAttribute('placeholder') || input.getAttribute('data-placeholder');
1380
+
1381
+ if (!placeholder && !settings.allowEmptyOption) {
1382
+ let option = input.querySelector('option[value=""]');
1383
+
1384
+ if (option) {
1385
+ placeholder = option.textContent;
1386
+ }
1387
+ }
1388
+
1389
+ var settings_element = {
1390
+ placeholder: placeholder,
1391
+ options: [],
1392
+ optgroups: [],
1393
+ items: [],
1394
+ maxItems: null
1395
+ };
1396
+ /**
1397
+ * Initialize from a <select> element.
1398
+ *
1399
+ */
1400
+
1401
+ var init_select = () => {
1402
+ var tagName;
1403
+ var options = settings_element.options;
1404
+ var optionsMap = {};
1405
+ var group_count = 1;
1406
+
1407
+ var readData = el => {
1408
+ var data = Object.assign({}, el.dataset); // get plain object from DOMStringMap
1409
+
1410
+ var json = attr_data && data[attr_data];
1411
+
1412
+ if (typeof json === 'string' && json.length) {
1413
+ data = Object.assign(data, JSON.parse(json));
1414
+ }
1415
+
1416
+ return data;
1417
+ };
1418
+
1419
+ var addOption = (option, group) => {
1420
+ var value = hash_key(option.value);
1421
+ if (value == null) return;
1422
+ if (!value && !settings.allowEmptyOption) return; // if the option already exists, it's probably been
1423
+ // duplicated in another optgroup. in this case, push
1424
+ // the current group to the "optgroup" property on the
1425
+ // existing option so that it's rendered in both places.
1426
+
1427
+ if (optionsMap.hasOwnProperty(value)) {
1428
+ if (group) {
1429
+ var arr = optionsMap[value][field_optgroup];
1430
+
1431
+ if (!arr) {
1432
+ optionsMap[value][field_optgroup] = group;
1433
+ } else if (!Array.isArray(arr)) {
1434
+ optionsMap[value][field_optgroup] = [arr, group];
1435
+ } else {
1436
+ arr.push(group);
1437
+ }
1438
+ }
1439
+ } else {
1440
+ var option_data = readData(option);
1441
+ option_data[field_label] = option_data[field_label] || option.textContent;
1442
+ option_data[field_value] = option_data[field_value] || value;
1443
+ option_data[field_disabled] = option_data[field_disabled] || option.disabled;
1444
+ option_data[field_optgroup] = option_data[field_optgroup] || group;
1445
+ option_data.$option = option;
1446
+ optionsMap[value] = option_data;
1447
+ options.push(option_data);
1448
+ }
1449
+
1450
+ if (option.selected) {
1451
+ settings_element.items.push(value);
1452
+ }
1453
+ };
1454
+
1455
+ var addGroup = optgroup => {
1456
+ var id, optgroup_data;
1457
+ optgroup_data = readData(optgroup);
1458
+ optgroup_data[field_optgroup_label] = optgroup_data[field_optgroup_label] || optgroup.getAttribute('label') || '';
1459
+ optgroup_data[field_optgroup_value] = optgroup_data[field_optgroup_value] || group_count++;
1460
+ optgroup_data[field_disabled] = optgroup_data[field_disabled] || optgroup.disabled;
1461
+ settings_element.optgroups.push(optgroup_data);
1462
+ id = optgroup_data[field_optgroup_value];
1463
+ iterate(optgroup.children, option => {
1464
+ addOption(option, id);
1465
+ });
1466
+ };
1467
+
1468
+ settings_element.maxItems = input.hasAttribute('multiple') ? null : 1;
1469
+ iterate(input.children, child => {
1470
+ tagName = child.tagName.toLowerCase();
1471
+
1472
+ if (tagName === 'optgroup') {
1473
+ addGroup(child);
1474
+ } else if (tagName === 'option') {
1475
+ addOption(child);
1476
+ }
1477
+ });
1478
+ };
1479
+ /**
1480
+ * Initialize from a <input type="text"> element.
1481
+ *
1482
+ */
1483
+
1484
+
1485
+ var init_textbox = () => {
1486
+ const data_raw = input.getAttribute(attr_data);
1487
+
1488
+ if (!data_raw) {
1489
+ var value = input.value.trim() || '';
1490
+ if (!settings.allowEmptyOption && !value.length) return;
1491
+ const values = value.split(settings.delimiter);
1492
+ iterate(values, value => {
1493
+ const option = {};
1494
+ option[field_label] = value;
1495
+ option[field_value] = value;
1496
+ settings_element.options.push(option);
1497
+ });
1498
+ settings_element.items = values;
1499
+ } else {
1500
+ settings_element.options = JSON.parse(data_raw);
1501
+ iterate(settings_element.options, opt => {
1502
+ settings_element.items.push(opt[field_value]);
1503
+ });
1504
+ }
1505
+ };
1506
+
1507
+ if (tag_name === 'select') {
1508
+ init_select();
1509
+ } else {
1510
+ init_textbox();
1511
+ }
1512
+
1513
+ return Object.assign({}, defaults, settings_element, settings_user);
1514
+ }
1515
+
1516
+ var instance_i = 0;
1517
+ class TomSelect extends MicroPlugin(MicroEvent) {
1518
+ // @deprecated 1.8
1519
+ constructor(input_arg, user_settings) {
1520
+ super();
1521
+ this.control_input = void 0;
1522
+ this.wrapper = void 0;
1523
+ this.dropdown = void 0;
1524
+ this.control = void 0;
1525
+ this.dropdown_content = void 0;
1526
+ this.focus_node = void 0;
1527
+ this.order = 0;
1528
+ this.settings = void 0;
1529
+ this.input = void 0;
1530
+ this.tabIndex = void 0;
1531
+ this.is_select_tag = void 0;
1532
+ this.rtl = void 0;
1533
+ this.inputId = void 0;
1534
+ this._destroy = void 0;
1535
+ this.sifter = void 0;
1536
+ this.isOpen = false;
1537
+ this.isDisabled = false;
1538
+ this.isRequired = void 0;
1539
+ this.isInvalid = false;
1540
+ this.isValid = true;
1541
+ this.isLocked = false;
1542
+ this.isFocused = false;
1543
+ this.isInputHidden = false;
1544
+ this.isSetup = false;
1545
+ this.ignoreFocus = false;
1546
+ this.ignoreHover = false;
1547
+ this.hasOptions = false;
1548
+ this.currentResults = void 0;
1549
+ this.lastValue = '';
1550
+ this.caretPos = 0;
1551
+ this.loading = 0;
1552
+ this.loadedSearches = {};
1553
+ this.activeOption = null;
1554
+ this.activeItems = [];
1555
+ this.optgroups = {};
1556
+ this.options = {};
1557
+ this.userOptions = {};
1558
+ this.items = [];
1559
+ instance_i++;
1560
+ var dir;
1561
+ var input = getDom(input_arg);
1562
+
1563
+ if (input.tomselect) {
1564
+ throw new Error('Tom Select already initialized on this element');
1565
+ }
1566
+
1567
+ input.tomselect = this; // detect rtl environment
1568
+
1569
+ var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null);
1570
+ dir = computedStyle.getPropertyValue('direction'); // setup default state
1571
+
1572
+ const settings = getSettings(input, user_settings);
1573
+ this.settings = settings;
1574
+ this.input = input;
1575
+ this.tabIndex = input.tabIndex || 0;
1576
+ this.is_select_tag = input.tagName.toLowerCase() === 'select';
1577
+ this.rtl = /rtl/i.test(dir);
1578
+ this.inputId = getId(input, 'tomselect-' + instance_i);
1579
+ this.isRequired = input.required; // search system
1580
+
1581
+ this.sifter = new Sifter(this.options, {
1582
+ diacritics: settings.diacritics
1583
+ }); // option-dependent defaults
1584
+
1585
+ settings.mode = settings.mode || (settings.maxItems === 1 ? 'single' : 'multi');
1586
+
1587
+ if (typeof settings.hideSelected !== 'boolean') {
1588
+ settings.hideSelected = settings.mode === 'multi';
1589
+ }
1590
+
1591
+ if (typeof settings.hidePlaceholder !== 'boolean') {
1592
+ settings.hidePlaceholder = settings.mode !== 'multi';
1593
+ } // set up createFilter callback
1594
+
1595
+
1596
+ var filter = settings.createFilter;
1597
+
1598
+ if (typeof filter !== 'function') {
1599
+ if (typeof filter === 'string') {
1600
+ filter = new RegExp(filter);
1601
+ }
1602
+
1603
+ if (filter instanceof RegExp) {
1604
+ settings.createFilter = input => filter.test(input);
1605
+ } else {
1606
+ settings.createFilter = value => {
1607
+ return this.settings.duplicates || !this.options[value];
1608
+ };
1609
+ }
1610
+ }
1611
+
1612
+ this.initializePlugins(settings.plugins);
1613
+ this.setupCallbacks();
1614
+ this.setupTemplates(); // Create all elements
1615
+
1616
+ const wrapper = getDom('<div>');
1617
+ const control = getDom('<div>');
1618
+
1619
+ const dropdown = this._render('dropdown');
1620
+
1621
+ const dropdown_content = getDom(`<div role="listbox" tabindex="-1">`);
1622
+ const classes = this.input.getAttribute('class') || '';
1623
+ const inputMode = settings.mode;
1624
+ var control_input;
1625
+ addClasses(wrapper, settings.wrapperClass, classes, inputMode);
1626
+ addClasses(control, settings.controlClass);
1627
+ append(wrapper, control);
1628
+ addClasses(dropdown, settings.dropdownClass, inputMode);
1629
+
1630
+ if (settings.copyClassesToDropdown) {
1631
+ addClasses(dropdown, classes);
1632
+ }
1633
+
1634
+ addClasses(dropdown_content, settings.dropdownContentClass);
1635
+ append(dropdown, dropdown_content);
1636
+ getDom(settings.dropdownParent || wrapper).appendChild(dropdown); // default controlInput
1637
+
1638
+ if (isHtmlString(settings.controlInput)) {
1639
+ control_input = getDom(settings.controlInput); // set attributes
1640
+
1641
+ var attrs = ['autocorrect', 'autocapitalize', 'autocomplete'];
1642
+ iterate(attrs, attr => {
1643
+ if (input.getAttribute(attr)) {
1644
+ setAttr(control_input, {
1645
+ [attr]: input.getAttribute(attr)
1646
+ });
1647
+ }
1648
+ });
1649
+ control_input.tabIndex = -1;
1650
+ control.appendChild(control_input);
1651
+ this.focus_node = control_input; // dom element
1652
+ } else if (settings.controlInput) {
1653
+ control_input = getDom(settings.controlInput);
1654
+ this.focus_node = control_input;
1655
+ } else {
1656
+ control_input = getDom('<input/>');
1657
+ this.focus_node = control;
1658
+ }
1659
+
1660
+ this.wrapper = wrapper;
1661
+ this.dropdown = dropdown;
1662
+ this.dropdown_content = dropdown_content;
1663
+ this.control = control;
1664
+ this.control_input = control_input;
1665
+ this.setup();
1666
+ }
1667
+ /**
1668
+ * set up event bindings.
1669
+ *
1670
+ */
1671
+
1672
+
1673
+ setup() {
1674
+ const self = this;
1675
+ const settings = self.settings;
1676
+ const control_input = self.control_input;
1677
+ const dropdown = self.dropdown;
1678
+ const dropdown_content = self.dropdown_content;
1679
+ const wrapper = self.wrapper;
1680
+ const control = self.control;
1681
+ const input = self.input;
1682
+ const focus_node = self.focus_node;
1683
+ const passive_event = {
1684
+ passive: true
1685
+ };
1686
+ const listboxId = self.inputId + '-ts-dropdown';
1687
+ setAttr(dropdown_content, {
1688
+ id: listboxId
1689
+ });
1690
+ setAttr(focus_node, {
1691
+ role: 'combobox',
1692
+ 'aria-haspopup': 'listbox',
1693
+ 'aria-expanded': 'false',
1694
+ 'aria-controls': listboxId
1695
+ });
1696
+ const control_id = getId(focus_node, self.inputId + '-ts-control');
1697
+ const query = "label[for='" + escapeQuery(self.inputId) + "']";
1698
+ const label = document.querySelector(query);
1699
+ const label_click = self.focus.bind(self);
1700
+
1701
+ if (label) {
1702
+ addEvent(label, 'click', label_click);
1703
+ setAttr(label, {
1704
+ for: control_id
1705
+ });
1706
+ const label_id = getId(label, self.inputId + '-ts-label');
1707
+ setAttr(focus_node, {
1708
+ 'aria-labelledby': label_id
1709
+ });
1710
+ setAttr(dropdown_content, {
1711
+ 'aria-labelledby': label_id
1712
+ });
1713
+ }
1714
+
1715
+ wrapper.style.width = input.style.width;
1716
+
1717
+ if (self.plugins.names.length) {
1718
+ const classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-');
1719
+ addClasses([wrapper, dropdown], classes_plugins);
1720
+ }
1721
+
1722
+ if ((settings.maxItems === null || settings.maxItems > 1) && self.is_select_tag) {
1723
+ setAttr(input, {
1724
+ multiple: 'multiple'
1725
+ });
1726
+ }
1727
+
1728
+ if (settings.placeholder) {
1729
+ setAttr(control_input, {
1730
+ placeholder: settings.placeholder
1731
+ });
1732
+ } // if splitOn was not passed in, construct it from the delimiter to allow pasting universally
1733
+
1734
+
1735
+ if (!settings.splitOn && settings.delimiter) {
1736
+ settings.splitOn = new RegExp('\\s*' + escape_regex(settings.delimiter) + '+\\s*');
1737
+ } // debounce user defined load() if loadThrottle > 0
1738
+ // after initializePlugins() so plugins can create/modify user defined loaders
1739
+
1740
+
1741
+ if (settings.load && settings.loadThrottle) {
1742
+ settings.load = loadDebounce(settings.load, settings.loadThrottle);
1743
+ }
1744
+
1745
+ self.control_input.type = input.type;
1746
+ addEvent(dropdown, 'mouseenter', e => {
1747
+ var target_match = parentMatch(e.target, '[data-selectable]', dropdown);
1748
+ if (target_match) self.onOptionHover(e, target_match);
1749
+ }, {
1750
+ capture: true
1751
+ }); // clicking on an option should select it
1752
+
1753
+ addEvent(dropdown, 'click', evt => {
1754
+ const option = parentMatch(evt.target, '[data-selectable]');
1755
+
1756
+ if (option) {
1757
+ self.onOptionSelect(evt, option);
1758
+ preventDefault(evt, true);
1759
+ }
1760
+ });
1761
+ addEvent(control, 'click', evt => {
1762
+ var target_match = parentMatch(evt.target, '[data-ts-item]', control);
1763
+
1764
+ if (target_match && self.onItemSelect(evt, target_match)) {
1765
+ preventDefault(evt, true);
1766
+ return;
1767
+ } // retain focus (see control_input mousedown)
1768
+
1769
+
1770
+ if (control_input.value != '') {
1771
+ return;
1772
+ }
1773
+
1774
+ self.onClick();
1775
+ preventDefault(evt, true);
1776
+ }); // keydown on focus_node for arrow_down/arrow_up
1777
+
1778
+ addEvent(focus_node, 'keydown', e => self.onKeyDown(e)); // keypress and input/keyup
1779
+
1780
+ addEvent(control_input, 'keypress', e => self.onKeyPress(e));
1781
+ addEvent(control_input, 'input', e => self.onInput(e));
1782
+ addEvent(focus_node, 'resize', () => self.positionDropdown(), passive_event);
1783
+ addEvent(focus_node, 'blur', e => self.onBlur(e));
1784
+ addEvent(focus_node, 'focus', e => self.onFocus(e));
1785
+ addEvent(control_input, 'paste', e => self.onPaste(e));
1786
+
1787
+ const doc_mousedown = evt => {
1788
+ // blur if target is outside of this instance
1789
+ // dropdown is not always inside wrapper
1790
+ const target = evt.composedPath()[0];
1791
+
1792
+ if (!wrapper.contains(target) && !dropdown.contains(target)) {
1793
+ if (self.isFocused) {
1794
+ self.blur();
1795
+ }
1796
+
1797
+ self.inputState();
1798
+ return;
1799
+ } // retain focus by preventing native handling. if the
1800
+ // event target is the input it should not be modified.
1801
+ // otherwise, text selection within the input won't work.
1802
+ // Fixes bug #212 which is no covered by tests
1803
+
1804
+
1805
+ if (target == control_input && self.isOpen) {
1806
+ evt.stopPropagation(); // clicking anywhere in the control should not blur the control_input (which would close the dropdown)
1807
+ } else {
1808
+ preventDefault(evt, true);
1809
+ }
1810
+ };
1811
+
1812
+ const win_scroll = () => {
1813
+ if (self.isOpen) {
1814
+ self.positionDropdown();
1815
+ }
1816
+ };
1817
+
1818
+ const win_hover = () => {
1819
+ self.ignoreHover = false;
1820
+ };
1821
+
1822
+ addEvent(document, 'mousedown', doc_mousedown);
1823
+ addEvent(window, 'scroll', win_scroll, passive_event);
1824
+ addEvent(window, 'resize', win_scroll, passive_event);
1825
+ addEvent(window, 'mousemove', win_hover, passive_event);
1826
+
1827
+ this._destroy = () => {
1828
+ document.removeEventListener('mousedown', doc_mousedown);
1829
+ window.removeEventListener('mousemove', win_hover);
1830
+ window.removeEventListener('scroll', win_scroll);
1831
+ window.removeEventListener('resize', win_scroll);
1832
+ if (label) label.removeEventListener('click', label_click);
1833
+ }; // store original html and tab index so that they can be
1834
+ // restored when the destroy() method is called.
1835
+
1836
+
1837
+ this.revertSettings = {
1838
+ innerHTML: input.innerHTML,
1839
+ tabIndex: input.tabIndex
1840
+ };
1841
+ input.tabIndex = -1;
1842
+ input.insertAdjacentElement('afterend', self.wrapper);
1843
+ self.sync(false);
1844
+ settings.items = [];
1845
+ delete settings.optgroups;
1846
+ delete settings.options;
1847
+ addEvent(input, 'invalid', e => {
1848
+ if (self.isValid) {
1849
+ self.isValid = false;
1850
+ self.isInvalid = true;
1851
+ self.refreshState();
1852
+ }
1853
+ });
1854
+ self.updateOriginalInput();
1855
+ self.refreshItems();
1856
+ self.close(false);
1857
+ self.inputState();
1858
+ self.isSetup = true;
1859
+
1860
+ if (input.disabled) {
1861
+ self.disable();
1862
+ } else {
1863
+ self.enable(); //sets tabIndex
1864
+ }
1865
+
1866
+ self.on('change', this.onChange);
1867
+ addClasses(input, 'tomselected', 'ts-hidden-accessible');
1868
+ self.trigger('initialize'); // preload options
1869
+
1870
+ if (settings.preload === true) {
1871
+ self.preload();
1872
+ }
1873
+ }
1874
+ /**
1875
+ * Register options and optgroups
1876
+ *
1877
+ */
1878
+
1879
+
1880
+ setupOptions(options = [], optgroups = []) {
1881
+ // build options table
1882
+ this.addOptions(options); // build optgroup table
1883
+
1884
+ iterate(optgroups, optgroup => {
1885
+ this.registerOptionGroup(optgroup);
1886
+ });
1887
+ }
1888
+ /**
1889
+ * Sets up default rendering functions.
1890
+ */
1891
+
1892
+
1893
+ setupTemplates() {
1894
+ var self = this;
1895
+ var field_label = self.settings.labelField;
1896
+ var field_optgroup = self.settings.optgroupLabelField;
1897
+ var templates = {
1898
+ 'optgroup': data => {
1899
+ let optgroup = document.createElement('div');
1900
+ optgroup.className = 'optgroup';
1901
+ optgroup.appendChild(data.options);
1902
+ return optgroup;
1903
+ },
1904
+ 'optgroup_header': (data, escape) => {
1905
+ return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>';
1906
+ },
1907
+ 'option': (data, escape) => {
1908
+ return '<div>' + escape(data[field_label]) + '</div>';
1909
+ },
1910
+ 'item': (data, escape) => {
1911
+ return '<div>' + escape(data[field_label]) + '</div>';
1912
+ },
1913
+ 'option_create': (data, escape) => {
1914
+ return '<div class="create">Add <strong>' + escape(data.input) + '</strong>&hellip;</div>';
1915
+ },
1916
+ 'no_results': () => {
1917
+ return '<div class="no-results">No results found</div>';
1918
+ },
1919
+ 'loading': () => {
1920
+ return '<div class="spinner"></div>';
1921
+ },
1922
+ 'not_loading': () => {},
1923
+ 'dropdown': () => {
1924
+ return '<div></div>';
1925
+ }
1926
+ };
1927
+ self.settings.render = Object.assign({}, templates, self.settings.render);
1928
+ }
1929
+ /**
1930
+ * Maps fired events to callbacks provided
1931
+ * in the settings used when creating the control.
1932
+ */
1933
+
1934
+
1935
+ setupCallbacks() {
1936
+ var key, fn;
1937
+ var callbacks = {
1938
+ 'initialize': 'onInitialize',
1939
+ 'change': 'onChange',
1940
+ 'item_add': 'onItemAdd',
1941
+ 'item_remove': 'onItemRemove',
1942
+ 'item_select': 'onItemSelect',
1943
+ 'clear': 'onClear',
1944
+ 'option_add': 'onOptionAdd',
1945
+ 'option_remove': 'onOptionRemove',
1946
+ 'option_clear': 'onOptionClear',
1947
+ 'optgroup_add': 'onOptionGroupAdd',
1948
+ 'optgroup_remove': 'onOptionGroupRemove',
1949
+ 'optgroup_clear': 'onOptionGroupClear',
1950
+ 'dropdown_open': 'onDropdownOpen',
1951
+ 'dropdown_close': 'onDropdownClose',
1952
+ 'type': 'onType',
1953
+ 'load': 'onLoad',
1954
+ 'focus': 'onFocus',
1955
+ 'blur': 'onBlur'
1956
+ };
1957
+
1958
+ for (key in callbacks) {
1959
+ fn = this.settings[callbacks[key]];
1960
+ if (fn) this.on(key, fn);
1961
+ }
1962
+ }
1963
+ /**
1964
+ * Sync the Tom Select instance with the original input or select
1965
+ *
1966
+ */
1967
+
1968
+
1969
+ sync(get_settings = true) {
1970
+ const self = this;
1971
+ const settings = get_settings ? getSettings(self.input, {
1972
+ delimiter: self.settings.delimiter
1973
+ }) : self.settings;
1974
+ self.setupOptions(settings.options, settings.optgroups);
1975
+ self.setValue(settings.items || [], true); // silent prevents recursion
1976
+
1977
+ self.lastQuery = null; // so updated options will be displayed in dropdown
1978
+ }
1979
+ /**
1980
+ * Triggered when the main control element
1981
+ * has a click event.
1982
+ *
1983
+ */
1984
+
1985
+
1986
+ onClick() {
1987
+ var self = this;
1988
+
1989
+ if (self.activeItems.length > 0) {
1990
+ self.clearActiveItems();
1991
+ self.focus();
1992
+ return;
1993
+ }
1994
+
1995
+ if (self.isFocused && self.isOpen) {
1996
+ self.blur();
1997
+ } else {
1998
+ self.focus();
1999
+ }
2000
+ }
2001
+ /**
2002
+ * @deprecated v1.7
2003
+ *
2004
+ */
2005
+
2006
+
2007
+ onMouseDown() {}
2008
+ /**
2009
+ * Triggered when the value of the control has been changed.
2010
+ * This should propagate the event to the original DOM
2011
+ * input / select element.
2012
+ */
2013
+
2014
+
2015
+ onChange() {
2016
+ triggerEvent(this.input, 'input');
2017
+ triggerEvent(this.input, 'change');
2018
+ }
2019
+ /**
2020
+ * Triggered on <input> paste.
2021
+ *
2022
+ */
2023
+
2024
+
2025
+ onPaste(e) {
2026
+ var self = this;
2027
+
2028
+ if (self.isInputHidden || self.isLocked) {
2029
+ preventDefault(e);
2030
+ return;
2031
+ } // If a regex or string is included, this will split the pasted
2032
+ // input and create Items for each separate value
2033
+
2034
+
2035
+ if (!self.settings.splitOn) {
2036
+ return;
2037
+ } // Wait for pasted text to be recognized in value
2038
+
2039
+
2040
+ setTimeout(() => {
2041
+ var pastedText = self.inputValue();
2042
+
2043
+ if (!pastedText.match(self.settings.splitOn)) {
2044
+ return;
2045
+ }
2046
+
2047
+ var splitInput = pastedText.trim().split(self.settings.splitOn);
2048
+ iterate(splitInput, piece => {
2049
+ piece = hash_key(piece);
2050
+
2051
+ if (this.options[piece]) {
2052
+ self.addItem(piece);
2053
+ } else {
2054
+ self.createItem(piece);
2055
+ }
2056
+ });
2057
+ }, 0);
2058
+ }
2059
+ /**
2060
+ * Triggered on <input> keypress.
2061
+ *
2062
+ */
2063
+
2064
+
2065
+ onKeyPress(e) {
2066
+ var self = this;
2067
+
2068
+ if (self.isLocked) {
2069
+ preventDefault(e);
2070
+ return;
2071
+ }
2072
+
2073
+ var character = String.fromCharCode(e.keyCode || e.which);
2074
+
2075
+ if (self.settings.create && self.settings.mode === 'multi' && character === self.settings.delimiter) {
2076
+ self.createItem();
2077
+ preventDefault(e);
2078
+ return;
2079
+ }
2080
+ }
2081
+ /**
2082
+ * Triggered on <input> keydown.
2083
+ *
2084
+ */
2085
+
2086
+
2087
+ onKeyDown(e) {
2088
+ var self = this;
2089
+ self.ignoreHover = true;
2090
+
2091
+ if (self.isLocked) {
2092
+ if (e.keyCode !== KEY_TAB) {
2093
+ preventDefault(e);
2094
+ }
2095
+
2096
+ return;
2097
+ }
2098
+
2099
+ switch (e.keyCode) {
2100
+ // ctrl+A: select all
2101
+ case KEY_A:
2102
+ if (isKeyDown(KEY_SHORTCUT, e)) {
2103
+ if (self.control_input.value == '') {
2104
+ preventDefault(e);
2105
+ self.selectAll();
2106
+ return;
2107
+ }
2108
+ }
2109
+
2110
+ break;
2111
+ // esc: close dropdown
2112
+
2113
+ case KEY_ESC:
2114
+ if (self.isOpen) {
2115
+ preventDefault(e, true);
2116
+ self.close();
2117
+ }
2118
+
2119
+ self.clearActiveItems();
2120
+ return;
2121
+ // down: open dropdown or move selection down
2122
+
2123
+ case KEY_DOWN:
2124
+ if (!self.isOpen && self.hasOptions) {
2125
+ self.open();
2126
+ } else if (self.activeOption) {
2127
+ let next = self.getAdjacent(self.activeOption, 1);
2128
+ if (next) self.setActiveOption(next);
2129
+ }
2130
+
2131
+ preventDefault(e);
2132
+ return;
2133
+ // up: move selection up
2134
+
2135
+ case KEY_UP:
2136
+ if (self.activeOption) {
2137
+ let prev = self.getAdjacent(self.activeOption, -1);
2138
+ if (prev) self.setActiveOption(prev);
2139
+ }
2140
+
2141
+ preventDefault(e);
2142
+ return;
2143
+ // return: select active option
2144
+
2145
+ case KEY_RETURN:
2146
+ if (self.canSelect(self.activeOption)) {
2147
+ self.onOptionSelect(e, self.activeOption);
2148
+ preventDefault(e); // if the option_create=null, the dropdown might be closed
2149
+ } else if (self.settings.create && self.createItem()) {
2150
+ preventDefault(e); // don't submit form when searching for a value
2151
+ } else if (document.activeElement == self.control_input && self.isOpen) {
2152
+ preventDefault(e);
2153
+ }
2154
+
2155
+ return;
2156
+ // left: modifiy item selection to the left
2157
+
2158
+ case KEY_LEFT:
2159
+ self.advanceSelection(-1, e);
2160
+ return;
2161
+ // right: modifiy item selection to the right
2162
+
2163
+ case KEY_RIGHT:
2164
+ self.advanceSelection(1, e);
2165
+ return;
2166
+ // tab: select active option and/or create item
2167
+
2168
+ case KEY_TAB:
2169
+ if (self.settings.selectOnTab) {
2170
+ if (self.canSelect(self.activeOption)) {
2171
+ self.onOptionSelect(e, self.activeOption); // prevent default [tab] behaviour of jump to the next field
2172
+ // if select isFull, then the dropdown won't be open and [tab] will work normally
2173
+
2174
+ preventDefault(e);
2175
+ }
2176
+
2177
+ if (self.settings.create && self.createItem()) {
2178
+ preventDefault(e);
2179
+ }
2180
+ }
2181
+
2182
+ return;
2183
+ // delete|backspace: delete items
2184
+
2185
+ case KEY_BACKSPACE:
2186
+ case KEY_DELETE:
2187
+ self.deleteSelection(e);
2188
+ return;
2189
+ } // don't enter text in the control_input when active items are selected
2190
+
2191
+
2192
+ if (self.isInputHidden && !isKeyDown(KEY_SHORTCUT, e)) {
2193
+ preventDefault(e);
2194
+ }
2195
+ }
2196
+ /**
2197
+ * Triggered on <input> keyup.
2198
+ *
2199
+ */
2200
+
2201
+
2202
+ onInput(e) {
2203
+ var self = this;
2204
+
2205
+ if (self.isLocked) {
2206
+ return;
2207
+ }
2208
+
2209
+ var value = self.inputValue();
2210
+
2211
+ if (self.lastValue !== value) {
2212
+ self.lastValue = value;
2213
+
2214
+ if (self.settings.shouldLoad.call(self, value)) {
2215
+ self.load(value);
2216
+ }
2217
+
2218
+ self.refreshOptions();
2219
+ self.trigger('type', value);
2220
+ }
2221
+ }
2222
+ /**
2223
+ * Triggered when the user rolls over
2224
+ * an option in the autocomplete dropdown menu.
2225
+ *
2226
+ */
2227
+
2228
+
2229
+ onOptionHover(evt, option) {
2230
+ if (this.ignoreHover) return;
2231
+ this.setActiveOption(option, false);
2232
+ }
2233
+ /**
2234
+ * Triggered on <input> focus.
2235
+ *
2236
+ */
2237
+
2238
+
2239
+ onFocus(e) {
2240
+ var self = this;
2241
+ var wasFocused = self.isFocused;
2242
+
2243
+ if (self.isDisabled) {
2244
+ self.blur();
2245
+ preventDefault(e);
2246
+ return;
2247
+ }
2248
+
2249
+ if (self.ignoreFocus) return;
2250
+ self.isFocused = true;
2251
+ if (self.settings.preload === 'focus') self.preload();
2252
+ if (!wasFocused) self.trigger('focus');
2253
+
2254
+ if (!self.activeItems.length) {
2255
+ self.showInput();
2256
+ self.refreshOptions(!!self.settings.openOnFocus);
2257
+ }
2258
+
2259
+ self.refreshState();
2260
+ }
2261
+ /**
2262
+ * Triggered on <input> blur.
2263
+ *
2264
+ */
2265
+
2266
+
2267
+ onBlur(e) {
2268
+ if (document.hasFocus() === false) return;
2269
+ var self = this;
2270
+ if (!self.isFocused) return;
2271
+ self.isFocused = false;
2272
+ self.ignoreFocus = false;
2273
+
2274
+ var deactivate = () => {
2275
+ self.close();
2276
+ self.setActiveItem();
2277
+ self.setCaret(self.items.length);
2278
+ self.trigger('blur');
2279
+ };
2280
+
2281
+ if (self.settings.create && self.settings.createOnBlur) {
2282
+ self.createItem(null, false, deactivate);
2283
+ } else {
2284
+ deactivate();
2285
+ }
2286
+ }
2287
+ /**
2288
+ * Triggered when the user clicks on an option
2289
+ * in the autocomplete dropdown menu.
2290
+ *
2291
+ */
2292
+
2293
+
2294
+ onOptionSelect(evt, option) {
2295
+ var value,
2296
+ self = this; // should not be possible to trigger a option under a disabled optgroup
2297
+
2298
+ if (option.parentElement && option.parentElement.matches('[data-disabled]')) {
2299
+ return;
2300
+ }
2301
+
2302
+ if (option.classList.contains('create')) {
2303
+ self.createItem(null, true, () => {
2304
+ if (self.settings.closeAfterSelect) {
2305
+ self.close();
2306
+ }
2307
+ });
2308
+ } else {
2309
+ value = option.dataset.value;
2310
+
2311
+ if (typeof value !== 'undefined') {
2312
+ self.lastQuery = null;
2313
+ self.addItem(value);
2314
+
2315
+ if (self.settings.closeAfterSelect) {
2316
+ self.close();
2317
+ }
2318
+
2319
+ if (!self.settings.hideSelected && evt.type && /click/.test(evt.type)) {
2320
+ self.setActiveOption(option);
2321
+ }
2322
+ }
2323
+ }
2324
+ }
2325
+ /**
2326
+ * Return true if the given option can be selected
2327
+ *
2328
+ */
2329
+
2330
+
2331
+ canSelect(option) {
2332
+ if (this.isOpen && option && this.dropdown_content.contains(option)) {
2333
+ return true;
2334
+ }
2335
+
2336
+ return false;
2337
+ }
2338
+ /**
2339
+ * Triggered when the user clicks on an item
2340
+ * that has been selected.
2341
+ *
2342
+ */
2343
+
2344
+
2345
+ onItemSelect(evt, item) {
2346
+ var self = this;
2347
+
2348
+ if (!self.isLocked && self.settings.mode === 'multi') {
2349
+ preventDefault(evt);
2350
+ self.setActiveItem(item, evt);
2351
+ return true;
2352
+ }
2353
+
2354
+ return false;
2355
+ }
2356
+ /**
2357
+ * Determines whether or not to invoke
2358
+ * the user-provided option provider / loader
2359
+ *
2360
+ * Note, there is a subtle difference between
2361
+ * this.canLoad() and this.settings.shouldLoad();
2362
+ *
2363
+ * - settings.shouldLoad() is a user-input validator.
2364
+ * When false is returned, the not_loading template
2365
+ * will be added to the dropdown
2366
+ *
2367
+ * - canLoad() is lower level validator that checks
2368
+ * the Tom Select instance. There is no inherent user
2369
+ * feedback when canLoad returns false
2370
+ *
2371
+ */
2372
+
2373
+
2374
+ canLoad(value) {
2375
+ if (!this.settings.load) return false;
2376
+ if (this.loadedSearches.hasOwnProperty(value)) return false;
2377
+ return true;
2378
+ }
2379
+ /**
2380
+ * Invokes the user-provided option provider / loader.
2381
+ *
2382
+ */
2383
+
2384
+
2385
+ load(value) {
2386
+ const self = this;
2387
+ if (!self.canLoad(value)) return;
2388
+ addClasses(self.wrapper, self.settings.loadingClass);
2389
+ self.loading++;
2390
+ const callback = self.loadCallback.bind(self);
2391
+ self.settings.load.call(self, value, callback);
2392
+ }
2393
+ /**
2394
+ * Invoked by the user-provided option provider
2395
+ *
2396
+ */
2397
+
2398
+
2399
+ loadCallback(options, optgroups) {
2400
+ const self = this;
2401
+ self.loading = Math.max(self.loading - 1, 0);
2402
+ self.lastQuery = null;
2403
+ self.clearActiveOption(); // when new results load, focus should be on first option
2404
+
2405
+ self.setupOptions(options, optgroups);
2406
+ self.refreshOptions(self.isFocused && !self.isInputHidden);
2407
+
2408
+ if (!self.loading) {
2409
+ removeClasses(self.wrapper, self.settings.loadingClass);
2410
+ }
2411
+
2412
+ self.trigger('load', options, optgroups);
2413
+ }
2414
+
2415
+ preload() {
2416
+ var classList = this.wrapper.classList;
2417
+ if (classList.contains('preloaded')) return;
2418
+ classList.add('preloaded');
2419
+ this.load('');
2420
+ }
2421
+ /**
2422
+ * Sets the input field of the control to the specified value.
2423
+ *
2424
+ */
2425
+
2426
+
2427
+ setTextboxValue(value = '') {
2428
+ var input = this.control_input;
2429
+ var changed = input.value !== value;
2430
+
2431
+ if (changed) {
2432
+ input.value = value;
2433
+ triggerEvent(input, 'update');
2434
+ this.lastValue = value;
2435
+ }
2436
+ }
2437
+ /**
2438
+ * Returns the value of the control. If multiple items
2439
+ * can be selected (e.g. <select multiple>), this returns
2440
+ * an array. If only one item can be selected, this
2441
+ * returns a string.
2442
+ *
2443
+ */
2444
+
2445
+
2446
+ getValue() {
2447
+ if (this.is_select_tag && this.input.hasAttribute('multiple')) {
2448
+ return this.items;
2449
+ }
2450
+
2451
+ return this.items.join(this.settings.delimiter);
2452
+ }
2453
+ /**
2454
+ * Resets the selected items to the given value.
2455
+ *
2456
+ */
2457
+
2458
+
2459
+ setValue(value, silent) {
2460
+ var events = silent ? [] : ['change'];
2461
+ debounce_events(this, events, () => {
2462
+ this.clear(silent);
2463
+ this.addItems(value, silent);
2464
+ });
2465
+ }
2466
+ /**
2467
+ * Resets the number of max items to the given value
2468
+ *
2469
+ */
2470
+
2471
+
2472
+ setMaxItems(value) {
2473
+ if (value === 0) value = null; //reset to unlimited items.
2474
+
2475
+ this.settings.maxItems = value;
2476
+ this.refreshState();
2477
+ }
2478
+ /**
2479
+ * Sets the selected item.
2480
+ *
2481
+ */
2482
+
2483
+
2484
+ setActiveItem(item, e) {
2485
+ var self = this;
2486
+ var eventName;
2487
+ var i, begin, end, swap;
2488
+ var last;
2489
+ if (self.settings.mode === 'single') return; // clear the active selection
2490
+
2491
+ if (!item) {
2492
+ self.clearActiveItems();
2493
+
2494
+ if (self.isFocused) {
2495
+ self.showInput();
2496
+ }
2497
+
2498
+ return;
2499
+ } // modify selection
2500
+
2501
+
2502
+ eventName = e && e.type.toLowerCase();
2503
+
2504
+ if (eventName === 'click' && isKeyDown('shiftKey', e) && self.activeItems.length) {
2505
+ last = self.getLastActive();
2506
+ begin = Array.prototype.indexOf.call(self.control.children, last);
2507
+ end = Array.prototype.indexOf.call(self.control.children, item);
2508
+
2509
+ if (begin > end) {
2510
+ swap = begin;
2511
+ begin = end;
2512
+ end = swap;
2513
+ }
2514
+
2515
+ for (i = begin; i <= end; i++) {
2516
+ item = self.control.children[i];
2517
+
2518
+ if (self.activeItems.indexOf(item) === -1) {
2519
+ self.setActiveItemClass(item);
2520
+ }
2521
+ }
2522
+
2523
+ preventDefault(e);
2524
+ } else if (eventName === 'click' && isKeyDown(KEY_SHORTCUT, e) || eventName === 'keydown' && isKeyDown('shiftKey', e)) {
2525
+ if (item.classList.contains('active')) {
2526
+ self.removeActiveItem(item);
2527
+ } else {
2528
+ self.setActiveItemClass(item);
2529
+ }
2530
+ } else {
2531
+ self.clearActiveItems();
2532
+ self.setActiveItemClass(item);
2533
+ } // ensure control has focus
2534
+
2535
+
2536
+ self.hideInput();
2537
+
2538
+ if (!self.isFocused) {
2539
+ self.focus();
2540
+ }
2541
+ }
2542
+ /**
2543
+ * Set the active and last-active classes
2544
+ *
2545
+ */
2546
+
2547
+
2548
+ setActiveItemClass(item) {
2549
+ const self = this;
2550
+ const last_active = self.control.querySelector('.last-active');
2551
+ if (last_active) removeClasses(last_active, 'last-active');
2552
+ addClasses(item, 'active last-active');
2553
+ self.trigger('item_select', item);
2554
+
2555
+ if (self.activeItems.indexOf(item) == -1) {
2556
+ self.activeItems.push(item);
2557
+ }
2558
+ }
2559
+ /**
2560
+ * Remove active item
2561
+ *
2562
+ */
2563
+
2564
+
2565
+ removeActiveItem(item) {
2566
+ var idx = this.activeItems.indexOf(item);
2567
+ this.activeItems.splice(idx, 1);
2568
+ removeClasses(item, 'active');
2569
+ }
2570
+ /**
2571
+ * Clears all the active items
2572
+ *
2573
+ */
2574
+
2575
+
2576
+ clearActiveItems() {
2577
+ removeClasses(this.activeItems, 'active');
2578
+ this.activeItems = [];
2579
+ }
2580
+ /**
2581
+ * Sets the selected item in the dropdown menu
2582
+ * of available options.
2583
+ *
2584
+ */
2585
+
2586
+
2587
+ setActiveOption(option, scroll = true) {
2588
+ if (option === this.activeOption) {
2589
+ return;
2590
+ }
2591
+
2592
+ this.clearActiveOption();
2593
+ if (!option) return;
2594
+ this.activeOption = option;
2595
+ setAttr(this.focus_node, {
2596
+ 'aria-activedescendant': option.getAttribute('id')
2597
+ });
2598
+ setAttr(option, {
2599
+ 'aria-selected': 'true'
2600
+ });
2601
+ addClasses(option, 'active');
2602
+ if (scroll) this.scrollToOption(option);
2603
+ }
2604
+ /**
2605
+ * Sets the dropdown_content scrollTop to display the option
2606
+ *
2607
+ */
2608
+
2609
+
2610
+ scrollToOption(option, behavior) {
2611
+ if (!option) return;
2612
+ const content = this.dropdown_content;
2613
+ const height_menu = content.clientHeight;
2614
+ const scrollTop = content.scrollTop || 0;
2615
+ const height_item = option.offsetHeight;
2616
+ const y = option.getBoundingClientRect().top - content.getBoundingClientRect().top + scrollTop;
2617
+
2618
+ if (y + height_item > height_menu + scrollTop) {
2619
+ this.scroll(y - height_menu + height_item, behavior);
2620
+ } else if (y < scrollTop) {
2621
+ this.scroll(y, behavior);
2622
+ }
2623
+ }
2624
+ /**
2625
+ * Scroll the dropdown to the given position
2626
+ *
2627
+ */
2628
+
2629
+
2630
+ scroll(scrollTop, behavior) {
2631
+ const content = this.dropdown_content;
2632
+
2633
+ if (behavior) {
2634
+ content.style.scrollBehavior = behavior;
2635
+ }
2636
+
2637
+ content.scrollTop = scrollTop;
2638
+ content.style.scrollBehavior = '';
2639
+ }
2640
+ /**
2641
+ * Clears the active option
2642
+ *
2643
+ */
2644
+
2645
+
2646
+ clearActiveOption() {
2647
+ if (this.activeOption) {
2648
+ removeClasses(this.activeOption, 'active');
2649
+ setAttr(this.activeOption, {
2650
+ 'aria-selected': null
2651
+ });
2652
+ }
2653
+
2654
+ this.activeOption = null;
2655
+ setAttr(this.focus_node, {
2656
+ 'aria-activedescendant': null
2657
+ });
2658
+ }
2659
+ /**
2660
+ * Selects all items (CTRL + A).
2661
+ */
2662
+
2663
+
2664
+ selectAll() {
2665
+ const self = this;
2666
+ if (self.settings.mode === 'single') return;
2667
+ const activeItems = self.controlChildren();
2668
+ if (!activeItems.length) return;
2669
+ self.hideInput();
2670
+ self.close();
2671
+ self.activeItems = activeItems;
2672
+ iterate(activeItems, item => {
2673
+ self.setActiveItemClass(item);
2674
+ });
2675
+ }
2676
+ /**
2677
+ * Determines if the control_input should be in a hidden or visible state
2678
+ *
2679
+ */
2680
+
2681
+
2682
+ inputState() {
2683
+ var self = this;
2684
+ if (!self.control.contains(self.control_input)) return;
2685
+ setAttr(self.control_input, {
2686
+ placeholder: self.settings.placeholder
2687
+ });
2688
+
2689
+ if (self.activeItems.length > 0 || !self.isFocused && self.settings.hidePlaceholder && self.items.length > 0) {
2690
+ self.setTextboxValue();
2691
+ self.isInputHidden = true;
2692
+ } else {
2693
+ if (self.settings.hidePlaceholder && self.items.length > 0) {
2694
+ setAttr(self.control_input, {
2695
+ placeholder: ''
2696
+ });
2697
+ }
2698
+
2699
+ self.isInputHidden = false;
2700
+ }
2701
+
2702
+ self.wrapper.classList.toggle('input-hidden', self.isInputHidden);
2703
+ }
2704
+ /**
2705
+ * Hides the input element out of view, while
2706
+ * retaining its focus.
2707
+ * @deprecated 1.3
2708
+ */
2709
+
2710
+
2711
+ hideInput() {
2712
+ this.inputState();
2713
+ }
2714
+ /**
2715
+ * Restores input visibility.
2716
+ * @deprecated 1.3
2717
+ */
2718
+
2719
+
2720
+ showInput() {
2721
+ this.inputState();
2722
+ }
2723
+ /**
2724
+ * Get the input value
2725
+ */
2726
+
2727
+
2728
+ inputValue() {
2729
+ return this.control_input.value.trim();
2730
+ }
2731
+ /**
2732
+ * Gives the control focus.
2733
+ */
2734
+
2735
+
2736
+ focus() {
2737
+ var self = this;
2738
+ if (self.isDisabled) return;
2739
+ self.ignoreFocus = true;
2740
+
2741
+ if (self.control_input.offsetWidth) {
2742
+ self.control_input.focus();
2743
+ } else {
2744
+ self.focus_node.focus();
2745
+ }
2746
+
2747
+ setTimeout(() => {
2748
+ self.ignoreFocus = false;
2749
+ self.onFocus();
2750
+ }, 0);
2751
+ }
2752
+ /**
2753
+ * Forces the control out of focus.
2754
+ *
2755
+ */
2756
+
2757
+
2758
+ blur() {
2759
+ this.focus_node.blur();
2760
+ this.onBlur();
2761
+ }
2762
+ /**
2763
+ * Returns a function that scores an object
2764
+ * to show how good of a match it is to the
2765
+ * provided query.
2766
+ *
2767
+ * @return {function}
2768
+ */
2769
+
2770
+
2771
+ getScoreFunction(query) {
2772
+ return this.sifter.getScoreFunction(query, this.getSearchOptions());
2773
+ }
2774
+ /**
2775
+ * Returns search options for sifter (the system
2776
+ * for scoring and sorting results).
2777
+ *
2778
+ * @see https://github.com/orchidjs/sifter.js
2779
+ * @return {object}
2780
+ */
2781
+
2782
+
2783
+ getSearchOptions() {
2784
+ var settings = this.settings;
2785
+ var sort = settings.sortField;
2786
+
2787
+ if (typeof settings.sortField === 'string') {
2788
+ sort = [{
2789
+ field: settings.sortField
2790
+ }];
2791
+ }
2792
+
2793
+ return {
2794
+ fields: settings.searchField,
2795
+ conjunction: settings.searchConjunction,
2796
+ sort: sort,
2797
+ nesting: settings.nesting
2798
+ };
2799
+ }
2800
+ /**
2801
+ * Searches through available options and returns
2802
+ * a sorted array of matches.
2803
+ *
2804
+ */
2805
+
2806
+
2807
+ search(query) {
2808
+ var i, result, calculateScore;
2809
+ var self = this;
2810
+ var options = this.getSearchOptions(); // validate user-provided result scoring function
2811
+
2812
+ if (self.settings.score) {
2813
+ calculateScore = self.settings.score.call(self, query);
2814
+
2815
+ if (typeof calculateScore !== 'function') {
2816
+ throw new Error('Tom Select "score" setting must be a function that returns a function');
2817
+ }
2818
+ } // perform search
2819
+
2820
+
2821
+ if (query !== self.lastQuery) {
2822
+ self.lastQuery = query;
2823
+ result = self.sifter.search(query, Object.assign(options, {
2824
+ score: calculateScore
2825
+ }));
2826
+ self.currentResults = result;
2827
+ } else {
2828
+ result = Object.assign({}, self.currentResults);
2829
+ } // filter out selected items
2830
+
2831
+
2832
+ if (self.settings.hideSelected) {
2833
+ for (i = result.items.length - 1; i >= 0; i--) {
2834
+ let hashed = hash_key(result.items[i].id);
2835
+
2836
+ if (hashed && self.items.indexOf(hashed) !== -1) {
2837
+ result.items.splice(i, 1);
2838
+ }
2839
+ }
2840
+ }
2841
+
2842
+ return result;
2843
+ }
2844
+ /**
2845
+ * Refreshes the list of available options shown
2846
+ * in the autocomplete dropdown menu.
2847
+ *
2848
+ */
2849
+
2850
+
2851
+ refreshOptions(triggerDropdown = true) {
2852
+ var i, j, k, n, optgroup, optgroups, html, has_create_option, active_value, active_group;
2853
+ var create;
2854
+ const groups = {};
2855
+ const groups_order = [];
2856
+ var self = this;
2857
+ var query = self.inputValue();
2858
+ var results = self.search(query);
2859
+ var active_option = null; //self.activeOption;
2860
+
2861
+ var show_dropdown = self.settings.shouldOpen || false;
2862
+ var dropdown_content = self.dropdown_content;
2863
+
2864
+ if (self.activeOption) {
2865
+ active_value = self.activeOption.dataset.value;
2866
+ active_group = self.activeOption.closest('[data-group]');
2867
+ } // build markup
2868
+
2869
+
2870
+ n = results.items.length;
2871
+
2872
+ if (typeof self.settings.maxOptions === 'number') {
2873
+ n = Math.min(n, self.settings.maxOptions);
2874
+ }
2875
+
2876
+ if (n > 0) {
2877
+ show_dropdown = true;
2878
+ } // render and group available options individually
2879
+
2880
+
2881
+ for (i = 0; i < n; i++) {
2882
+ // get option dom element
2883
+ let opt_value = results.items[i].id;
2884
+ let option = self.options[opt_value];
2885
+ let option_el = self.getOption(opt_value, true); // toggle 'selected' class
2886
+
2887
+ if (!self.settings.hideSelected) {
2888
+ option_el.classList.toggle('selected', self.items.includes(opt_value));
2889
+ }
2890
+
2891
+ optgroup = option[self.settings.optgroupField] || '';
2892
+ optgroups = Array.isArray(optgroup) ? optgroup : [optgroup];
2893
+
2894
+ for (j = 0, k = optgroups && optgroups.length; j < k; j++) {
2895
+ optgroup = optgroups[j];
2896
+
2897
+ if (!self.optgroups.hasOwnProperty(optgroup)) {
2898
+ optgroup = '';
2899
+ }
2900
+
2901
+ if (!groups.hasOwnProperty(optgroup)) {
2902
+ groups[optgroup] = document.createDocumentFragment();
2903
+ groups_order.push(optgroup);
2904
+ } // nodes can only have one parent, so if the option is in mutple groups, we need a clone
2905
+
2906
+
2907
+ if (j > 0) {
2908
+ option_el = option_el.cloneNode(true);
2909
+ setAttr(option_el, {
2910
+ id: option.$id + '-clone-' + j,
2911
+ 'aria-selected': null
2912
+ });
2913
+ option_el.classList.add('ts-cloned');
2914
+ removeClasses(option_el, 'active');
2915
+ } // make sure we keep the activeOption in the same group
2916
+
2917
+
2918
+ if (!active_option && active_value == opt_value) {
2919
+ if (active_group) {
2920
+ if (active_group.dataset.group === optgroup) {
2921
+ active_option = option_el;
2922
+ }
2923
+ } else {
2924
+ active_option = option_el;
2925
+ }
2926
+ }
2927
+
2928
+ groups[optgroup].appendChild(option_el);
2929
+ }
2930
+ } // sort optgroups
2931
+
2932
+
2933
+ if (this.settings.lockOptgroupOrder) {
2934
+ groups_order.sort((a, b) => {
2935
+ var a_order = self.optgroups[a] && self.optgroups[a].$order || 0;
2936
+ var b_order = self.optgroups[b] && self.optgroups[b].$order || 0;
2937
+ return a_order - b_order;
2938
+ });
2939
+ } // render optgroup headers & join groups
2940
+
2941
+
2942
+ html = document.createDocumentFragment();
2943
+ iterate(groups_order, optgroup => {
2944
+ if (self.optgroups.hasOwnProperty(optgroup) && groups[optgroup].children.length) {
2945
+ let group_options = document.createDocumentFragment();
2946
+ let header = self.render('optgroup_header', self.optgroups[optgroup]);
2947
+ append(group_options, header);
2948
+ append(group_options, groups[optgroup]);
2949
+ let group_html = self.render('optgroup', {
2950
+ group: self.optgroups[optgroup],
2951
+ options: group_options
2952
+ });
2953
+ append(html, group_html);
2954
+ } else {
2955
+ append(html, groups[optgroup]);
2956
+ }
2957
+ });
2958
+ dropdown_content.innerHTML = '';
2959
+ append(dropdown_content, html); // highlight matching terms inline
2960
+
2961
+ if (self.settings.highlight) {
2962
+ removeHighlight(dropdown_content);
2963
+
2964
+ if (results.query.length && results.tokens.length) {
2965
+ iterate(results.tokens, tok => {
2966
+ highlight(dropdown_content, tok.regex);
2967
+ });
2968
+ }
2969
+ } // helper method for adding templates to dropdown
2970
+
2971
+
2972
+ var add_template = template => {
2973
+ let content = self.render(template, {
2974
+ input: query
2975
+ });
2976
+
2977
+ if (content) {
2978
+ show_dropdown = true;
2979
+ dropdown_content.insertBefore(content, dropdown_content.firstChild);
2980
+ }
2981
+
2982
+ return content;
2983
+ }; // add loading message
2984
+
2985
+
2986
+ if (self.loading) {
2987
+ add_template('loading'); // invalid query
2988
+ } else if (!self.settings.shouldLoad.call(self, query)) {
2989
+ add_template('not_loading'); // add no_results message
2990
+ } else if (results.items.length === 0) {
2991
+ add_template('no_results');
2992
+ } // add create option
2993
+
2994
+
2995
+ has_create_option = self.canCreate(query);
2996
+
2997
+ if (has_create_option) {
2998
+ create = add_template('option_create');
2999
+ } // activate
3000
+
3001
+
3002
+ self.hasOptions = results.items.length > 0 || has_create_option;
3003
+
3004
+ if (show_dropdown) {
3005
+ if (results.items.length > 0) {
3006
+ if (!active_option && self.settings.mode === 'single' && self.items.length) {
3007
+ active_option = self.getOption(self.items[0]);
3008
+ }
3009
+
3010
+ if (!dropdown_content.contains(active_option)) {
3011
+ let active_index = 0;
3012
+
3013
+ if (create && !self.settings.addPrecedence) {
3014
+ active_index = 1;
3015
+ }
3016
+
3017
+ active_option = self.selectable()[active_index];
3018
+ }
3019
+ } else if (create) {
3020
+ active_option = create;
3021
+ }
3022
+
3023
+ if (triggerDropdown && !self.isOpen) {
3024
+ self.open();
3025
+ self.scrollToOption(active_option, 'auto');
3026
+ }
3027
+
3028
+ self.setActiveOption(active_option);
3029
+ } else {
3030
+ self.clearActiveOption();
3031
+
3032
+ if (triggerDropdown && self.isOpen) {
3033
+ self.close(false); // if create_option=null, we want the dropdown to close but not reset the textbox value
3034
+ }
3035
+ }
3036
+ }
3037
+ /**
3038
+ * Return list of selectable options
3039
+ *
3040
+ */
3041
+
3042
+
3043
+ selectable() {
3044
+ return this.dropdown_content.querySelectorAll('[data-selectable]');
3045
+ }
3046
+ /**
3047
+ * Adds an available option. If it already exists,
3048
+ * nothing will happen. Note: this does not refresh
3049
+ * the options list dropdown (use `refreshOptions`
3050
+ * for that).
3051
+ *
3052
+ * Usage:
3053
+ *
3054
+ * this.addOption(data)
3055
+ *
3056
+ */
3057
+
3058
+
3059
+ addOption(data, user_created = false) {
3060
+ const self = this; // @deprecated 1.7.7
3061
+ // use addOptions( array, user_created ) for adding multiple options
3062
+
3063
+ if (Array.isArray(data)) {
3064
+ self.addOptions(data, user_created);
3065
+ return false;
3066
+ }
3067
+
3068
+ const key = hash_key(data[self.settings.valueField]);
3069
+
3070
+ if (key === null || self.options.hasOwnProperty(key)) {
3071
+ return false;
3072
+ }
3073
+
3074
+ data.$order = data.$order || ++self.order;
3075
+ data.$id = self.inputId + '-opt-' + data.$order;
3076
+ self.options[key] = data;
3077
+ self.lastQuery = null;
3078
+
3079
+ if (user_created) {
3080
+ self.userOptions[key] = user_created;
3081
+ self.trigger('option_add', key, data);
3082
+ }
3083
+
3084
+ return key;
3085
+ }
3086
+ /**
3087
+ * Add multiple options
3088
+ *
3089
+ */
3090
+
3091
+
3092
+ addOptions(data, user_created = false) {
3093
+ iterate(data, dat => {
3094
+ this.addOption(dat, user_created);
3095
+ });
3096
+ }
3097
+ /**
3098
+ * @deprecated 1.7.7
3099
+ */
3100
+
3101
+
3102
+ registerOption(data) {
3103
+ return this.addOption(data);
3104
+ }
3105
+ /**
3106
+ * Registers an option group to the pool of option groups.
3107
+ *
3108
+ * @return {boolean|string}
3109
+ */
3110
+
3111
+
3112
+ registerOptionGroup(data) {
3113
+ var key = hash_key(data[this.settings.optgroupValueField]);
3114
+ if (key === null) return false;
3115
+ data.$order = data.$order || ++this.order;
3116
+ this.optgroups[key] = data;
3117
+ return key;
3118
+ }
3119
+ /**
3120
+ * Registers a new optgroup for options
3121
+ * to be bucketed into.
3122
+ *
3123
+ */
3124
+
3125
+
3126
+ addOptionGroup(id, data) {
3127
+ var hashed_id;
3128
+ data[this.settings.optgroupValueField] = id;
3129
+
3130
+ if (hashed_id = this.registerOptionGroup(data)) {
3131
+ this.trigger('optgroup_add', hashed_id, data);
3132
+ }
3133
+ }
3134
+ /**
3135
+ * Removes an existing option group.
3136
+ *
3137
+ */
3138
+
3139
+
3140
+ removeOptionGroup(id) {
3141
+ if (this.optgroups.hasOwnProperty(id)) {
3142
+ delete this.optgroups[id];
3143
+ this.clearCache();
3144
+ this.trigger('optgroup_remove', id);
3145
+ }
3146
+ }
3147
+ /**
3148
+ * Clears all existing option groups.
3149
+ */
3150
+
3151
+
3152
+ clearOptionGroups() {
3153
+ this.optgroups = {};
3154
+ this.clearCache();
3155
+ this.trigger('optgroup_clear');
3156
+ }
3157
+ /**
3158
+ * Updates an option available for selection. If
3159
+ * it is visible in the selected items or options
3160
+ * dropdown, it will be re-rendered automatically.
3161
+ *
3162
+ */
3163
+
3164
+
3165
+ updateOption(value, data) {
3166
+ const self = this;
3167
+ var item_new;
3168
+ var index_item;
3169
+ const value_old = hash_key(value);
3170
+ const value_new = hash_key(data[self.settings.valueField]); // sanity checks
3171
+
3172
+ if (value_old === null) return;
3173
+ if (!self.options.hasOwnProperty(value_old)) return;
3174
+ if (typeof value_new !== 'string') throw new Error('Value must be set in option data');
3175
+ const option = self.getOption(value_old);
3176
+ const item = self.getItem(value_old);
3177
+ data.$order = data.$order || self.options[value_old].$order;
3178
+ delete self.options[value_old]; // invalidate render cache
3179
+ // don't remove existing node yet, we'll remove it after replacing it
3180
+
3181
+ self.uncacheValue(value_new);
3182
+ self.options[value_new] = data; // update the option if it's in the dropdown
3183
+
3184
+ if (option) {
3185
+ if (self.dropdown_content.contains(option)) {
3186
+ const option_new = self._render('option', data);
3187
+
3188
+ replaceNode(option, option_new);
3189
+
3190
+ if (self.activeOption === option) {
3191
+ self.setActiveOption(option_new);
3192
+ }
3193
+ }
3194
+
3195
+ option.remove();
3196
+ } // update the item if we have one
3197
+
3198
+
3199
+ if (item) {
3200
+ index_item = self.items.indexOf(value_old);
3201
+
3202
+ if (index_item !== -1) {
3203
+ self.items.splice(index_item, 1, value_new);
3204
+ }
3205
+
3206
+ item_new = self._render('item', data);
3207
+ if (item.classList.contains('active')) addClasses(item_new, 'active');
3208
+ replaceNode(item, item_new);
3209
+ } // invalidate last query because we might have updated the sortField
3210
+
3211
+
3212
+ self.lastQuery = null;
3213
+ }
3214
+ /**
3215
+ * Removes a single option.
3216
+ *
3217
+ */
3218
+
3219
+
3220
+ removeOption(value, silent) {
3221
+ const self = this;
3222
+ value = get_hash(value);
3223
+ self.uncacheValue(value);
3224
+ delete self.userOptions[value];
3225
+ delete self.options[value];
3226
+ self.lastQuery = null;
3227
+ self.trigger('option_remove', value);
3228
+ self.removeItem(value, silent);
3229
+ }
3230
+ /**
3231
+ * Clears all options.
3232
+ */
3233
+
3234
+
3235
+ clearOptions(filter) {
3236
+ const boundFilter = (filter || this.clearFilter).bind(this);
3237
+ this.loadedSearches = {};
3238
+ this.userOptions = {};
3239
+ this.clearCache();
3240
+ const selected = {};
3241
+ iterate(this.options, (option, key) => {
3242
+ if (boundFilter(option, key)) {
3243
+ selected[key] = this.options[key];
3244
+ }
3245
+ });
3246
+ this.options = this.sifter.items = selected;
3247
+ this.lastQuery = null;
3248
+ this.trigger('option_clear');
3249
+ }
3250
+ /**
3251
+ * Used by clearOptions() to decide whether or not an option should be removed
3252
+ * Return true to keep an option, false to remove
3253
+ *
3254
+ */
3255
+
3256
+
3257
+ clearFilter(option, value) {
3258
+ if (this.items.indexOf(value) >= 0) {
3259
+ return true;
3260
+ }
3261
+
3262
+ return false;
3263
+ }
3264
+ /**
3265
+ * Returns the dom element of the option
3266
+ * matching the given value.
3267
+ *
3268
+ */
3269
+
3270
+
3271
+ getOption(value, create = false) {
3272
+ const hashed = hash_key(value);
3273
+
3274
+ if (hashed !== null && this.options.hasOwnProperty(hashed)) {
3275
+ const option = this.options[hashed];
3276
+
3277
+ if (option.$div) {
3278
+ return option.$div;
3279
+ }
3280
+
3281
+ if (create) {
3282
+ return this._render('option', option);
3283
+ }
3284
+ }
3285
+
3286
+ return null;
3287
+ }
3288
+ /**
3289
+ * Returns the dom element of the next or previous dom element of the same type
3290
+ * Note: adjacent options may not be adjacent DOM elements (optgroups)
3291
+ *
3292
+ */
3293
+
3294
+
3295
+ getAdjacent(option, direction, type = 'option') {
3296
+ var self = this,
3297
+ all;
3298
+
3299
+ if (!option) {
3300
+ return null;
3301
+ }
3302
+
3303
+ if (type == 'item') {
3304
+ all = self.controlChildren();
3305
+ } else {
3306
+ all = self.dropdown_content.querySelectorAll('[data-selectable]');
3307
+ }
3308
+
3309
+ for (let i = 0; i < all.length; i++) {
3310
+ if (all[i] != option) {
3311
+ continue;
3312
+ }
3313
+
3314
+ if (direction > 0) {
3315
+ return all[i + 1];
3316
+ }
3317
+
3318
+ return all[i - 1];
3319
+ }
3320
+
3321
+ return null;
3322
+ }
3323
+ /**
3324
+ * Returns the dom element of the item
3325
+ * matching the given value.
3326
+ *
3327
+ */
3328
+
3329
+
3330
+ getItem(item) {
3331
+ if (typeof item == 'object') {
3332
+ return item;
3333
+ }
3334
+
3335
+ var value = hash_key(item);
3336
+ return value !== null ? this.control.querySelector(`[data-value="${addSlashes(value)}"]`) : null;
3337
+ }
3338
+ /**
3339
+ * "Selects" multiple items at once. Adds them to the list
3340
+ * at the current caret position.
3341
+ *
3342
+ */
3343
+
3344
+
3345
+ addItems(values, silent) {
3346
+ var self = this;
3347
+ var items = Array.isArray(values) ? values : [values];
3348
+ items = items.filter(x => self.items.indexOf(x) === -1);
3349
+
3350
+ for (let i = 0, n = items.length; i < n; i++) {
3351
+ self.isPending = i < n - 1;
3352
+ self.addItem(items[i], silent);
3353
+ }
3354
+ }
3355
+ /**
3356
+ * "Selects" an item. Adds it to the list
3357
+ * at the current caret position.
3358
+ *
3359
+ */
3360
+
3361
+
3362
+ addItem(value, silent) {
3363
+ var events = silent ? [] : ['change', 'dropdown_close'];
3364
+ debounce_events(this, events, () => {
3365
+ var item, wasFull;
3366
+ const self = this;
3367
+ const inputMode = self.settings.mode;
3368
+ const hashed = hash_key(value);
3369
+
3370
+ if (hashed && self.items.indexOf(hashed) !== -1) {
3371
+ if (inputMode === 'single') {
3372
+ self.close();
3373
+ }
3374
+
3375
+ if (inputMode === 'single' || !self.settings.duplicates) {
3376
+ return;
3377
+ }
3378
+ }
3379
+
3380
+ if (hashed === null || !self.options.hasOwnProperty(hashed)) return;
3381
+ if (inputMode === 'single') self.clear(silent);
3382
+ if (inputMode === 'multi' && self.isFull()) return;
3383
+ item = self._render('item', self.options[hashed]);
3384
+
3385
+ if (self.control.contains(item)) {
3386
+ // duplicates
3387
+ item = item.cloneNode(true);
3388
+ }
3389
+
3390
+ wasFull = self.isFull();
3391
+ self.items.splice(self.caretPos, 0, hashed);
3392
+ self.insertAtCaret(item);
3393
+
3394
+ if (self.isSetup) {
3395
+ // update menu / remove the option (if this is not one item being added as part of series)
3396
+ if (!self.isPending && self.settings.hideSelected) {
3397
+ let option = self.getOption(hashed);
3398
+ let next = self.getAdjacent(option, 1);
3399
+
3400
+ if (next) {
3401
+ self.setActiveOption(next);
3402
+ }
3403
+ } // refreshOptions after setActiveOption(),
3404
+ // otherwise setActiveOption() will be called by refreshOptions() with the wrong value
3405
+
3406
+
3407
+ if (!self.isPending && !self.settings.closeAfterSelect) {
3408
+ self.refreshOptions(self.isFocused && inputMode !== 'single');
3409
+ } // hide the menu if the maximum number of items have been selected or no options are left
3410
+
3411
+
3412
+ if (self.settings.closeAfterSelect != false && self.isFull()) {
3413
+ self.close();
3414
+ } else if (!self.isPending) {
3415
+ self.positionDropdown();
3416
+ }
3417
+
3418
+ self.trigger('item_add', hashed, item);
3419
+
3420
+ if (!self.isPending) {
3421
+ self.updateOriginalInput({
3422
+ silent: silent
3423
+ });
3424
+ }
3425
+ }
3426
+
3427
+ if (!self.isPending || !wasFull && self.isFull()) {
3428
+ self.inputState();
3429
+ self.refreshState();
3430
+ }
3431
+ });
3432
+ }
3433
+ /**
3434
+ * Removes the selected item matching
3435
+ * the provided value.
3436
+ *
3437
+ */
3438
+
3439
+
3440
+ removeItem(item = null, silent) {
3441
+ const self = this;
3442
+ item = self.getItem(item);
3443
+ if (!item) return;
3444
+ var i, idx;
3445
+ const value = item.dataset.value;
3446
+ i = nodeIndex(item);
3447
+ item.remove();
3448
+
3449
+ if (item.classList.contains('active')) {
3450
+ idx = self.activeItems.indexOf(item);
3451
+ self.activeItems.splice(idx, 1);
3452
+ removeClasses(item, 'active');
3453
+ }
3454
+
3455
+ self.items.splice(i, 1);
3456
+ self.lastQuery = null;
3457
+
3458
+ if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) {
3459
+ self.removeOption(value, silent);
3460
+ }
3461
+
3462
+ if (i < self.caretPos) {
3463
+ self.setCaret(self.caretPos - 1);
3464
+ }
3465
+
3466
+ self.updateOriginalInput({
3467
+ silent: silent
3468
+ });
3469
+ self.refreshState();
3470
+ self.positionDropdown();
3471
+ self.trigger('item_remove', value, item);
3472
+ }
3473
+ /**
3474
+ * Invokes the `create` method provided in the
3475
+ * TomSelect options that should provide the data
3476
+ * for the new item, given the user input.
3477
+ *
3478
+ * Once this completes, it will be added
3479
+ * to the item list.
3480
+ *
3481
+ */
3482
+
3483
+
3484
+ createItem(input = null, triggerDropdown = true, callback = () => {}) {
3485
+ var self = this;
3486
+ var caret = self.caretPos;
3487
+ var output;
3488
+ input = input || self.inputValue();
3489
+
3490
+ if (!self.canCreate(input)) {
3491
+ callback();
3492
+ return false;
3493
+ }
3494
+
3495
+ self.lock();
3496
+ var created = false;
3497
+
3498
+ var create = data => {
3499
+ self.unlock();
3500
+ if (!data || typeof data !== 'object') return callback();
3501
+ var value = hash_key(data[self.settings.valueField]);
3502
+
3503
+ if (typeof value !== 'string') {
3504
+ return callback();
3505
+ }
3506
+
3507
+ self.setTextboxValue();
3508
+ self.addOption(data, true);
3509
+ self.setCaret(caret);
3510
+ self.addItem(value);
3511
+ callback(data);
3512
+ created = true;
3513
+ };
3514
+
3515
+ if (typeof self.settings.create === 'function') {
3516
+ output = self.settings.create.call(this, input, create);
3517
+ } else {
3518
+ output = {
3519
+ [self.settings.labelField]: input,
3520
+ [self.settings.valueField]: input
3521
+ };
3522
+ }
3523
+
3524
+ if (!created) {
3525
+ create(output);
3526
+ }
3527
+
3528
+ return true;
3529
+ }
3530
+ /**
3531
+ * Re-renders the selected item lists.
3532
+ */
3533
+
3534
+
3535
+ refreshItems() {
3536
+ var self = this;
3537
+ self.lastQuery = null;
3538
+
3539
+ if (self.isSetup) {
3540
+ self.addItems(self.items);
3541
+ }
3542
+
3543
+ self.updateOriginalInput();
3544
+ self.refreshState();
3545
+ }
3546
+ /**
3547
+ * Updates all state-dependent attributes
3548
+ * and CSS classes.
3549
+ */
3550
+
3551
+
3552
+ refreshState() {
3553
+ const self = this;
3554
+ self.refreshValidityState();
3555
+ const isFull = self.isFull();
3556
+ const isLocked = self.isLocked;
3557
+ self.wrapper.classList.toggle('rtl', self.rtl);
3558
+ const wrap_classList = self.wrapper.classList;
3559
+ wrap_classList.toggle('focus', self.isFocused);
3560
+ wrap_classList.toggle('disabled', self.isDisabled);
3561
+ wrap_classList.toggle('required', self.isRequired);
3562
+ wrap_classList.toggle('invalid', !self.isValid);
3563
+ wrap_classList.toggle('locked', isLocked);
3564
+ wrap_classList.toggle('full', isFull);
3565
+ wrap_classList.toggle('input-active', self.isFocused && !self.isInputHidden);
3566
+ wrap_classList.toggle('dropdown-active', self.isOpen);
3567
+ wrap_classList.toggle('has-options', isEmptyObject(self.options));
3568
+ wrap_classList.toggle('has-items', self.items.length > 0);
3569
+ }
3570
+ /**
3571
+ * Update the `required` attribute of both input and control input.
3572
+ *
3573
+ * The `required` property needs to be activated on the control input
3574
+ * for the error to be displayed at the right place. `required` also
3575
+ * needs to be temporarily deactivated on the input since the input is
3576
+ * hidden and can't show errors.
3577
+ */
3578
+
3579
+
3580
+ refreshValidityState() {
3581
+ var self = this;
3582
+
3583
+ if (!self.input.validity) {
3584
+ return;
3585
+ }
3586
+
3587
+ self.isValid = self.input.validity.valid;
3588
+ self.isInvalid = !self.isValid;
3589
+ }
3590
+ /**
3591
+ * Determines whether or not more items can be added
3592
+ * to the control without exceeding the user-defined maximum.
3593
+ *
3594
+ * @returns {boolean}
3595
+ */
3596
+
3597
+
3598
+ isFull() {
3599
+ return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems;
3600
+ }
3601
+ /**
3602
+ * Refreshes the original <select> or <input>
3603
+ * element to reflect the current state.
3604
+ *
3605
+ */
3606
+
3607
+
3608
+ updateOriginalInput(opts = {}) {
3609
+ const self = this;
3610
+ var option, label;
3611
+ const empty_option = self.input.querySelector('option[value=""]');
3612
+
3613
+ if (self.is_select_tag) {
3614
+ const selected = [];
3615
+ const has_selected = self.input.querySelectorAll('option:checked').length;
3616
+
3617
+ function AddSelected(option_el, value, label) {
3618
+ if (!option_el) {
3619
+ option_el = getDom('<option value="' + escape_html(value) + '">' + escape_html(label) + '</option>');
3620
+ } // don't move empty option from top of list
3621
+ // fixes bug in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1725293
3622
+
3623
+
3624
+ if (option_el != empty_option) {
3625
+ self.input.append(option_el);
3626
+ }
3627
+
3628
+ selected.push(option_el); // marking empty option as selected can break validation
3629
+ // fixes https://github.com/orchidjs/tom-select/issues/303
3630
+
3631
+ if (option_el != empty_option || has_selected > 0) {
3632
+ option_el.selected = true;
3633
+ }
3634
+
3635
+ return option_el;
3636
+ } // unselect all selected options
3637
+
3638
+
3639
+ self.input.querySelectorAll('option:checked').forEach(option_el => {
3640
+ option_el.selected = false;
3641
+ }); // nothing selected?
3642
+
3643
+ if (self.items.length == 0 && self.settings.mode == 'single') {
3644
+ AddSelected(empty_option, "", ""); // order selected <option> tags for values in self.items
3645
+ } else {
3646
+ self.items.forEach(value => {
3647
+ option = self.options[value];
3648
+ label = option[self.settings.labelField] || '';
3649
+
3650
+ if (selected.includes(option.$option)) {
3651
+ const reuse_opt = self.input.querySelector(`option[value="${addSlashes(value)}"]:not(:checked)`);
3652
+ AddSelected(reuse_opt, value, label);
3653
+ } else {
3654
+ option.$option = AddSelected(option.$option, value, label);
3655
+ }
3656
+ });
3657
+ }
3658
+ } else {
3659
+ self.input.value = self.getValue();
3660
+ }
3661
+
3662
+ if (self.isSetup) {
3663
+ if (!opts.silent) {
3664
+ self.trigger('change', self.getValue());
3665
+ }
3666
+ }
3667
+ }
3668
+ /**
3669
+ * Shows the autocomplete dropdown containing
3670
+ * the available options.
3671
+ */
3672
+
3673
+
3674
+ open() {
3675
+ var self = this;
3676
+ if (self.isLocked || self.isOpen || self.settings.mode === 'multi' && self.isFull()) return;
3677
+ self.isOpen = true;
3678
+ setAttr(self.focus_node, {
3679
+ 'aria-expanded': 'true'
3680
+ });
3681
+ self.refreshState();
3682
+ applyCSS(self.dropdown, {
3683
+ visibility: 'hidden',
3684
+ display: 'block'
3685
+ });
3686
+ self.positionDropdown();
3687
+ applyCSS(self.dropdown, {
3688
+ visibility: 'visible',
3689
+ display: 'block'
3690
+ });
3691
+ self.focus();
3692
+ self.trigger('dropdown_open', self.dropdown);
3693
+ }
3694
+ /**
3695
+ * Closes the autocomplete dropdown menu.
3696
+ */
3697
+
3698
+
3699
+ close(setTextboxValue = true) {
3700
+ var self = this;
3701
+ var trigger = self.isOpen;
3702
+
3703
+ if (setTextboxValue) {
3704
+ // before blur() to prevent form onchange event
3705
+ self.setTextboxValue();
3706
+
3707
+ if (self.settings.mode === 'single' && self.items.length) {
3708
+ self.hideInput();
3709
+ }
3710
+ }
3711
+
3712
+ self.isOpen = false;
3713
+ setAttr(self.focus_node, {
3714
+ 'aria-expanded': 'false'
3715
+ });
3716
+ applyCSS(self.dropdown, {
3717
+ display: 'none'
3718
+ });
3719
+
3720
+ if (self.settings.hideSelected) {
3721
+ self.clearActiveOption();
3722
+ }
3723
+
3724
+ self.refreshState();
3725
+ if (trigger) self.trigger('dropdown_close', self.dropdown);
3726
+ }
3727
+ /**
3728
+ * Calculates and applies the appropriate
3729
+ * position of the dropdown if dropdownParent = 'body'.
3730
+ * Otherwise, position is determined by css
3731
+ */
3732
+
3733
+
3734
+ positionDropdown() {
3735
+ if (this.settings.dropdownParent !== 'body') {
3736
+ return;
3737
+ }
3738
+
3739
+ var context = this.control;
3740
+ var rect = context.getBoundingClientRect();
3741
+ var top = context.offsetHeight + rect.top + window.scrollY;
3742
+ var left = rect.left + window.scrollX;
3743
+ applyCSS(this.dropdown, {
3744
+ width: rect.width + 'px',
3745
+ top: top + 'px',
3746
+ left: left + 'px'
3747
+ });
3748
+ }
3749
+ /**
3750
+ * Resets / clears all selected items
3751
+ * from the control.
3752
+ *
3753
+ */
3754
+
3755
+
3756
+ clear(silent) {
3757
+ var self = this;
3758
+ if (!self.items.length) return;
3759
+ var items = self.controlChildren();
3760
+ iterate(items, item => {
3761
+ self.removeItem(item, true);
3762
+ });
3763
+ self.showInput();
3764
+ if (!silent) self.updateOriginalInput();
3765
+ self.trigger('clear');
3766
+ }
3767
+ /**
3768
+ * A helper method for inserting an element
3769
+ * at the current caret position.
3770
+ *
3771
+ */
3772
+
3773
+
3774
+ insertAtCaret(el) {
3775
+ const self = this;
3776
+ const caret = self.caretPos;
3777
+ const target = self.control;
3778
+ target.insertBefore(el, target.children[caret]);
3779
+ self.setCaret(caret + 1);
3780
+ }
3781
+ /**
3782
+ * Removes the current selected item(s).
3783
+ *
3784
+ */
3785
+
3786
+
3787
+ deleteSelection(e) {
3788
+ var direction, selection, caret, tail;
3789
+ var self = this;
3790
+ direction = e && e.keyCode === KEY_BACKSPACE ? -1 : 1;
3791
+ selection = getSelection(self.control_input); // determine items that will be removed
3792
+
3793
+ const rm_items = [];
3794
+
3795
+ if (self.activeItems.length) {
3796
+ tail = getTail(self.activeItems, direction);
3797
+ caret = nodeIndex(tail);
3798
+
3799
+ if (direction > 0) {
3800
+ caret++;
3801
+ }
3802
+
3803
+ iterate(self.activeItems, item => rm_items.push(item));
3804
+ } else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) {
3805
+ const items = self.controlChildren();
3806
+
3807
+ if (direction < 0 && selection.start === 0 && selection.length === 0) {
3808
+ rm_items.push(items[self.caretPos - 1]);
3809
+ } else if (direction > 0 && selection.start === self.inputValue().length) {
3810
+ rm_items.push(items[self.caretPos]);
3811
+ }
3812
+ }
3813
+
3814
+ if (!self.shouldDelete(rm_items, e)) {
3815
+ return false;
3816
+ }
3817
+
3818
+ preventDefault(e, true); // perform removal
3819
+
3820
+ if (typeof caret !== 'undefined') {
3821
+ self.setCaret(caret);
3822
+ }
3823
+
3824
+ while (rm_items.length) {
3825
+ self.removeItem(rm_items.pop());
3826
+ }
3827
+
3828
+ self.showInput();
3829
+ self.positionDropdown();
3830
+ self.refreshOptions(false);
3831
+ return true;
3832
+ }
3833
+ /**
3834
+ * Return true if the items should be deleted
3835
+ */
3836
+
3837
+
3838
+ shouldDelete(items, evt) {
3839
+ const values = items.map(item => item.dataset.value); // allow the callback to abort
3840
+
3841
+ if (!values.length || typeof this.settings.onDelete === 'function' && this.settings.onDelete(values, evt) === false) {
3842
+ return false;
3843
+ }
3844
+
3845
+ return true;
3846
+ }
3847
+ /**
3848
+ * Selects the previous / next item (depending on the `direction` argument).
3849
+ *
3850
+ * > 0 - right
3851
+ * < 0 - left
3852
+ *
3853
+ */
3854
+
3855
+
3856
+ advanceSelection(direction, e) {
3857
+ var last_active,
3858
+ adjacent,
3859
+ self = this;
3860
+ if (self.rtl) direction *= -1;
3861
+ if (self.inputValue().length) return; // add or remove to active items
3862
+
3863
+ if (isKeyDown(KEY_SHORTCUT, e) || isKeyDown('shiftKey', e)) {
3864
+ last_active = self.getLastActive(direction);
3865
+
3866
+ if (last_active) {
3867
+ if (!last_active.classList.contains('active')) {
3868
+ adjacent = last_active;
3869
+ } else {
3870
+ adjacent = self.getAdjacent(last_active, direction, 'item');
3871
+ } // if no active item, get items adjacent to the control input
3872
+
3873
+ } else if (direction > 0) {
3874
+ adjacent = self.control_input.nextElementSibling;
3875
+ } else {
3876
+ adjacent = self.control_input.previousElementSibling;
3877
+ }
3878
+
3879
+ if (adjacent) {
3880
+ if (adjacent.classList.contains('active')) {
3881
+ self.removeActiveItem(last_active);
3882
+ }
3883
+
3884
+ self.setActiveItemClass(adjacent); // mark as last_active !! after removeActiveItem() on last_active
3885
+ } // move caret to the left or right
3886
+
3887
+ } else {
3888
+ self.moveCaret(direction);
3889
+ }
3890
+ }
3891
+
3892
+ moveCaret(direction) {}
3893
+ /**
3894
+ * Get the last active item
3895
+ *
3896
+ */
3897
+
3898
+
3899
+ getLastActive(direction) {
3900
+ let last_active = this.control.querySelector('.last-active');
3901
+
3902
+ if (last_active) {
3903
+ return last_active;
3904
+ }
3905
+
3906
+ var result = this.control.querySelectorAll('.active');
3907
+
3908
+ if (result) {
3909
+ return getTail(result, direction);
3910
+ }
3911
+ }
3912
+ /**
3913
+ * Moves the caret to the specified index.
3914
+ *
3915
+ * The input must be moved by leaving it in place and moving the
3916
+ * siblings, due to the fact that focus cannot be restored once lost
3917
+ * on mobile webkit devices
3918
+ *
3919
+ */
3920
+
3921
+
3922
+ setCaret(new_pos) {
3923
+ this.caretPos = this.items.length;
3924
+ }
3925
+ /**
3926
+ * Return list of item dom elements
3927
+ *
3928
+ */
3929
+
3930
+
3931
+ controlChildren() {
3932
+ return Array.from(this.control.querySelectorAll('[data-ts-item]'));
3933
+ }
3934
+ /**
3935
+ * Disables user input on the control. Used while
3936
+ * items are being asynchronously created.
3937
+ */
3938
+
3939
+
3940
+ lock() {
3941
+ this.isLocked = true;
3942
+ this.refreshState();
3943
+ }
3944
+ /**
3945
+ * Re-enables user input on the control.
3946
+ */
3947
+
3948
+
3949
+ unlock() {
3950
+ this.isLocked = false;
3951
+ this.refreshState();
3952
+ }
3953
+ /**
3954
+ * Disables user input on the control completely.
3955
+ * While disabled, it cannot receive focus.
3956
+ */
3957
+
3958
+
3959
+ disable() {
3960
+ var self = this;
3961
+ self.input.disabled = true;
3962
+ self.control_input.disabled = true;
3963
+ self.focus_node.tabIndex = -1;
3964
+ self.isDisabled = true;
3965
+ this.close();
3966
+ self.lock();
3967
+ }
3968
+ /**
3969
+ * Enables the control so that it can respond
3970
+ * to focus and user input.
3971
+ */
3972
+
3973
+
3974
+ enable() {
3975
+ var self = this;
3976
+ self.input.disabled = false;
3977
+ self.control_input.disabled = false;
3978
+ self.focus_node.tabIndex = self.tabIndex;
3979
+ self.isDisabled = false;
3980
+ self.unlock();
3981
+ }
3982
+ /**
3983
+ * Completely destroys the control and
3984
+ * unbinds all event listeners so that it can
3985
+ * be garbage collected.
3986
+ */
3987
+
3988
+
3989
+ destroy() {
3990
+ var self = this;
3991
+ var revertSettings = self.revertSettings;
3992
+ self.trigger('destroy');
3993
+ self.off();
3994
+ self.wrapper.remove();
3995
+ self.dropdown.remove();
3996
+ self.input.innerHTML = revertSettings.innerHTML;
3997
+ self.input.tabIndex = revertSettings.tabIndex;
3998
+ removeClasses(self.input, 'tomselected', 'ts-hidden-accessible');
3999
+
4000
+ self._destroy();
4001
+
4002
+ delete self.input.tomselect;
4003
+ }
4004
+ /**
4005
+ * A helper method for rendering "item" and
4006
+ * "option" templates, given the data.
4007
+ *
4008
+ */
4009
+
4010
+
4011
+ render(templateName, data) {
4012
+ if (typeof this.settings.render[templateName] !== 'function') {
4013
+ return null;
4014
+ }
4015
+
4016
+ return this._render(templateName, data);
4017
+ }
4018
+ /**
4019
+ * _render() can be called directly when we know we don't want to hit the cache
4020
+ * return type could be null for some templates, we need https://github.com/microsoft/TypeScript/issues/33014
4021
+ */
4022
+
4023
+
4024
+ _render(templateName, data) {
4025
+ var value = '',
4026
+ id,
4027
+ html;
4028
+ const self = this;
4029
+
4030
+ if (templateName === 'option' || templateName == 'item') {
4031
+ value = get_hash(data[self.settings.valueField]);
4032
+ } // render markup
4033
+
4034
+
4035
+ html = self.settings.render[templateName].call(this, data, escape_html);
4036
+
4037
+ if (html == null) {
4038
+ return html;
4039
+ }
4040
+
4041
+ html = getDom(html); // add mandatory attributes
4042
+
4043
+ if (templateName === 'option' || templateName === 'option_create') {
4044
+ if (data[self.settings.disabledField]) {
4045
+ setAttr(html, {
4046
+ 'aria-disabled': 'true'
4047
+ });
4048
+ } else {
4049
+ setAttr(html, {
4050
+ 'data-selectable': ''
4051
+ });
4052
+ }
4053
+ } else if (templateName === 'optgroup') {
4054
+ id = data.group[self.settings.optgroupValueField];
4055
+ setAttr(html, {
4056
+ 'data-group': id
4057
+ });
4058
+
4059
+ if (data.group[self.settings.disabledField]) {
4060
+ setAttr(html, {
4061
+ 'data-disabled': ''
4062
+ });
4063
+ }
4064
+ }
4065
+
4066
+ if (templateName === 'option' || templateName === 'item') {
4067
+ setAttr(html, {
4068
+ 'data-value': value
4069
+ }); // make sure we have some classes if a template is overwritten
4070
+
4071
+ if (templateName === 'item') {
4072
+ addClasses(html, self.settings.itemClass);
4073
+ setAttr(html, {
4074
+ 'data-ts-item': ''
4075
+ });
4076
+ } else {
4077
+ addClasses(html, self.settings.optionClass);
4078
+ setAttr(html, {
4079
+ role: 'option',
4080
+ id: data.$id
4081
+ }); // update cache
4082
+
4083
+ self.options[value].$div = html;
4084
+ }
4085
+ }
4086
+
4087
+ return html;
4088
+ }
4089
+ /**
4090
+ * Clears the render cache for a template. If
4091
+ * no template is given, clears all render
4092
+ * caches.
4093
+ *
4094
+ */
4095
+
4096
+
4097
+ clearCache() {
4098
+ iterate(this.options, (option, value) => {
4099
+ if (option.$div) {
4100
+ option.$div.remove();
4101
+ delete option.$div;
4102
+ }
4103
+ });
4104
+ }
4105
+ /**
4106
+ * Removes a value from item and option caches
4107
+ *
4108
+ */
4109
+
4110
+
4111
+ uncacheValue(value) {
4112
+ const option_el = this.getOption(value);
4113
+ if (option_el) option_el.remove();
4114
+ }
4115
+ /**
4116
+ * Determines whether or not to display the
4117
+ * create item prompt, given a user input.
4118
+ *
4119
+ */
4120
+
4121
+
4122
+ canCreate(input) {
4123
+ return this.settings.create && input.length > 0 && this.settings.createFilter.call(this, input);
4124
+ }
4125
+ /**
4126
+ * Wraps this.`method` so that `new_fn` can be invoked 'before', 'after', or 'instead' of the original method
4127
+ *
4128
+ * this.hook('instead','onKeyDown',function( arg1, arg2 ...){
4129
+ *
4130
+ * });
4131
+ */
4132
+
4133
+
4134
+ hook(when, method, new_fn) {
4135
+ var self = this;
4136
+ var orig_method = self[method];
4137
+
4138
+ self[method] = function () {
4139
+ var result, result_new;
4140
+
4141
+ if (when === 'after') {
4142
+ result = orig_method.apply(self, arguments);
4143
+ }
4144
+
4145
+ result_new = new_fn.apply(self, arguments);
4146
+
4147
+ if (when === 'instead') {
4148
+ return result_new;
4149
+ }
4150
+
4151
+ if (when === 'before') {
4152
+ result = orig_method.apply(self, arguments);
4153
+ }
4154
+
4155
+ return result;
4156
+ };
4157
+ }
4158
+
4159
+ }
4160
+
4161
+ /**
4162
+ * Plugin: "change_listener" (Tom Select)
4163
+ * Copyright (c) contributors
4164
+ *
4165
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4166
+ * file except in compliance with the License. You may obtain a copy of the License at:
4167
+ * http://www.apache.org/licenses/LICENSE-2.0
4168
+ *
4169
+ * Unless required by applicable law or agreed to in writing, software distributed under
4170
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4171
+ * ANY KIND, either express or implied. See the License for the specific language
4172
+ * governing permissions and limitations under the License.
4173
+ *
4174
+ */
4175
+ function change_listener () {
4176
+ addEvent(this.input, 'change', () => {
4177
+ this.sync();
4178
+ });
4179
+ }
4180
+
4181
+ /**
4182
+ * Plugin: "restore_on_backspace" (Tom Select)
4183
+ * Copyright (c) contributors
4184
+ *
4185
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4186
+ * file except in compliance with the License. You may obtain a copy of the License at:
4187
+ * http://www.apache.org/licenses/LICENSE-2.0
4188
+ *
4189
+ * Unless required by applicable law or agreed to in writing, software distributed under
4190
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4191
+ * ANY KIND, either express or implied. See the License for the specific language
4192
+ * governing permissions and limitations under the License.
4193
+ *
4194
+ */
4195
+ function checkbox_options () {
4196
+ var self = this;
4197
+ var orig_onOptionSelect = self.onOptionSelect;
4198
+ self.settings.hideSelected = false; // update the checkbox for an option
4199
+
4200
+ var UpdateCheckbox = function UpdateCheckbox(option) {
4201
+ setTimeout(() => {
4202
+ var checkbox = option.querySelector('input');
4203
+
4204
+ if (checkbox instanceof HTMLInputElement) {
4205
+ if (option.classList.contains('selected')) {
4206
+ checkbox.checked = true;
4207
+ } else {
4208
+ checkbox.checked = false;
4209
+ }
4210
+ }
4211
+ }, 1);
4212
+ }; // add checkbox to option template
4213
+
4214
+
4215
+ self.hook('after', 'setupTemplates', () => {
4216
+ var orig_render_option = self.settings.render.option;
4217
+
4218
+ self.settings.render.option = (data, escape_html) => {
4219
+ var rendered = getDom(orig_render_option.call(self, data, escape_html));
4220
+ var checkbox = document.createElement('input');
4221
+ checkbox.addEventListener('click', function (evt) {
4222
+ preventDefault(evt);
4223
+ });
4224
+ checkbox.type = 'checkbox';
4225
+ const hashed = hash_key(data[self.settings.valueField]);
4226
+
4227
+ if (hashed && self.items.indexOf(hashed) > -1) {
4228
+ checkbox.checked = true;
4229
+ }
4230
+
4231
+ rendered.prepend(checkbox);
4232
+ return rendered;
4233
+ };
4234
+ }); // uncheck when item removed
4235
+
4236
+ self.on('item_remove', value => {
4237
+ var option = self.getOption(value);
4238
+
4239
+ if (option) {
4240
+ // if dropdown hasn't been opened yet, the option won't exist
4241
+ option.classList.remove('selected'); // selected class won't be removed yet
4242
+
4243
+ UpdateCheckbox(option);
4244
+ }
4245
+ }); // check when item added
4246
+
4247
+ self.on('item_add', value => {
4248
+ var option = self.getOption(value);
4249
+
4250
+ if (option) {
4251
+ // if dropdown hasn't been opened yet, the option won't exist
4252
+ UpdateCheckbox(option);
4253
+ }
4254
+ }); // remove items when selected option is clicked
4255
+
4256
+ self.hook('instead', 'onOptionSelect', (evt, option) => {
4257
+ if (option.classList.contains('selected')) {
4258
+ option.classList.remove('selected');
4259
+ self.removeItem(option.dataset.value);
4260
+ self.refreshOptions();
4261
+ preventDefault(evt, true);
4262
+ return;
4263
+ }
4264
+
4265
+ orig_onOptionSelect.call(self, evt, option);
4266
+ UpdateCheckbox(option);
4267
+ });
4268
+ }
4269
+
4270
+ /**
4271
+ * Plugin: "dropdown_header" (Tom Select)
4272
+ * Copyright (c) contributors
4273
+ *
4274
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4275
+ * file except in compliance with the License. You may obtain a copy of the License at:
4276
+ * http://www.apache.org/licenses/LICENSE-2.0
4277
+ *
4278
+ * Unless required by applicable law or agreed to in writing, software distributed under
4279
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4280
+ * ANY KIND, either express or implied. See the License for the specific language
4281
+ * governing permissions and limitations under the License.
4282
+ *
4283
+ */
4284
+ function clear_button (userOptions) {
4285
+ const self = this;
4286
+ const options = Object.assign({
4287
+ className: 'clear-button',
4288
+ title: 'Clear All',
4289
+ html: data => {
4290
+ return `<div class="${data.className}" title="${data.title}">&times;</div>`;
4291
+ }
4292
+ }, userOptions);
4293
+ self.on('initialize', () => {
4294
+ var button = getDom(options.html(options));
4295
+ button.addEventListener('click', evt => {
4296
+ if (self.isDisabled) {
4297
+ return;
4298
+ }
4299
+
4300
+ self.clear();
4301
+
4302
+ if (self.settings.mode === 'single' && self.settings.allowEmptyOption) {
4303
+ self.addItem('');
4304
+ }
4305
+
4306
+ evt.preventDefault();
4307
+ evt.stopPropagation();
4308
+ });
4309
+ self.control.appendChild(button);
4310
+ });
4311
+ }
4312
+
4313
+ /**
4314
+ * Plugin: "drag_drop" (Tom Select)
4315
+ * Copyright (c) contributors
4316
+ *
4317
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4318
+ * file except in compliance with the License. You may obtain a copy of the License at:
4319
+ * http://www.apache.org/licenses/LICENSE-2.0
4320
+ *
4321
+ * Unless required by applicable law or agreed to in writing, software distributed under
4322
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4323
+ * ANY KIND, either express or implied. See the License for the specific language
4324
+ * governing permissions and limitations under the License.
4325
+ *
4326
+ */
4327
+ function drag_drop () {
4328
+ var self = this;
4329
+ if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');
4330
+ if (self.settings.mode !== 'multi') return;
4331
+ var orig_lock = self.lock;
4332
+ var orig_unlock = self.unlock;
4333
+ self.hook('instead', 'lock', () => {
4334
+ var sortable = $(self.control).data('sortable');
4335
+ if (sortable) sortable.disable();
4336
+ return orig_lock.call(self);
4337
+ });
4338
+ self.hook('instead', 'unlock', () => {
4339
+ var sortable = $(self.control).data('sortable');
4340
+ if (sortable) sortable.enable();
4341
+ return orig_unlock.call(self);
4342
+ });
4343
+ self.on('initialize', () => {
4344
+ var $control = $(self.control).sortable({
4345
+ items: '[data-value]',
4346
+ forcePlaceholderSize: true,
4347
+ disabled: self.isLocked,
4348
+ start: (e, ui) => {
4349
+ ui.placeholder.css('width', ui.helper.css('width'));
4350
+ $control.css({
4351
+ overflow: 'visible'
4352
+ });
4353
+ },
4354
+ stop: () => {
4355
+ $control.css({
4356
+ overflow: 'hidden'
4357
+ });
4358
+ var values = [];
4359
+ $control.children('[data-value]').each(function () {
4360
+ if (this.dataset.value) values.push(this.dataset.value);
4361
+ });
4362
+ self.setValue(values);
4363
+ }
4364
+ });
4365
+ });
4366
+ }
4367
+
4368
+ /**
4369
+ * Plugin: "dropdown_header" (Tom Select)
4370
+ * Copyright (c) contributors
4371
+ *
4372
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4373
+ * file except in compliance with the License. You may obtain a copy of the License at:
4374
+ * http://www.apache.org/licenses/LICENSE-2.0
4375
+ *
4376
+ * Unless required by applicable law or agreed to in writing, software distributed under
4377
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4378
+ * ANY KIND, either express or implied. See the License for the specific language
4379
+ * governing permissions and limitations under the License.
4380
+ *
4381
+ */
4382
+ function dropdown_header (userOptions) {
4383
+ const self = this;
4384
+ const options = Object.assign({
4385
+ title: 'Untitled',
4386
+ headerClass: 'dropdown-header',
4387
+ titleRowClass: 'dropdown-header-title',
4388
+ labelClass: 'dropdown-header-label',
4389
+ closeClass: 'dropdown-header-close',
4390
+ html: data => {
4391
+ return '<div class="' + data.headerClass + '">' + '<div class="' + data.titleRowClass + '">' + '<span class="' + data.labelClass + '">' + data.title + '</span>' + '<a class="' + data.closeClass + '">&times;</a>' + '</div>' + '</div>';
4392
+ }
4393
+ }, userOptions);
4394
+ self.on('initialize', () => {
4395
+ var header = getDom(options.html(options));
4396
+ var close_link = header.querySelector('.' + options.closeClass);
4397
+
4398
+ if (close_link) {
4399
+ close_link.addEventListener('click', evt => {
4400
+ preventDefault(evt, true);
4401
+ self.close();
4402
+ });
4403
+ }
4404
+
4405
+ self.dropdown.insertBefore(header, self.dropdown.firstChild);
4406
+ });
4407
+ }
4408
+
4409
+ /**
4410
+ * Plugin: "dropdown_input" (Tom Select)
4411
+ * Copyright (c) contributors
4412
+ *
4413
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4414
+ * file except in compliance with the License. You may obtain a copy of the License at:
4415
+ * http://www.apache.org/licenses/LICENSE-2.0
4416
+ *
4417
+ * Unless required by applicable law or agreed to in writing, software distributed under
4418
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4419
+ * ANY KIND, either express or implied. See the License for the specific language
4420
+ * governing permissions and limitations under the License.
4421
+ *
4422
+ */
4423
+ function caret_position () {
4424
+ var self = this;
4425
+ /**
4426
+ * Moves the caret to the specified index.
4427
+ *
4428
+ * The input must be moved by leaving it in place and moving the
4429
+ * siblings, due to the fact that focus cannot be restored once lost
4430
+ * on mobile webkit devices
4431
+ *
4432
+ */
4433
+
4434
+ self.hook('instead', 'setCaret', new_pos => {
4435
+ if (self.settings.mode === 'single' || !self.control.contains(self.control_input)) {
4436
+ new_pos = self.items.length;
4437
+ } else {
4438
+ new_pos = Math.max(0, Math.min(self.items.length, new_pos));
4439
+
4440
+ if (new_pos != self.caretPos && !self.isPending) {
4441
+ self.controlChildren().forEach((child, j) => {
4442
+ if (j < new_pos) {
4443
+ self.control_input.insertAdjacentElement('beforebegin', child);
4444
+ } else {
4445
+ self.control.appendChild(child);
4446
+ }
4447
+ });
4448
+ }
4449
+ }
4450
+
4451
+ self.caretPos = new_pos;
4452
+ });
4453
+ self.hook('instead', 'moveCaret', direction => {
4454
+ if (!self.isFocused) return; // move caret before or after selected items
4455
+
4456
+ const last_active = self.getLastActive(direction);
4457
+
4458
+ if (last_active) {
4459
+ const idx = nodeIndex(last_active);
4460
+ self.setCaret(direction > 0 ? idx + 1 : idx);
4461
+ self.setActiveItem();
4462
+ removeClasses(last_active, 'last-active'); // move caret left or right of current position
4463
+ } else {
4464
+ self.setCaret(self.caretPos + direction);
4465
+ }
4466
+ });
4467
+ }
4468
+
4469
+ /**
4470
+ * Plugin: "dropdown_input" (Tom Select)
4471
+ * Copyright (c) contributors
4472
+ *
4473
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4474
+ * file except in compliance with the License. You may obtain a copy of the License at:
4475
+ * http://www.apache.org/licenses/LICENSE-2.0
4476
+ *
4477
+ * Unless required by applicable law or agreed to in writing, software distributed under
4478
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4479
+ * ANY KIND, either express or implied. See the License for the specific language
4480
+ * governing permissions and limitations under the License.
4481
+ *
4482
+ */
4483
+ function dropdown_input () {
4484
+ const self = this;
4485
+ self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
4486
+
4487
+ self.hook('before', 'setup', () => {
4488
+ self.focus_node = self.control;
4489
+ addClasses(self.control_input, 'dropdown-input');
4490
+ const div = getDom('<div class="dropdown-input-wrap">');
4491
+ div.append(self.control_input);
4492
+ self.dropdown.insertBefore(div, self.dropdown.firstChild); // set a placeholder in the select control
4493
+
4494
+ const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />');
4495
+ placeholder.placeholder = self.settings.placeholder || '';
4496
+ self.control.append(placeholder);
4497
+ });
4498
+ self.on('initialize', () => {
4499
+ // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
4500
+ self.control_input.addEventListener('keydown', evt => {
4501
+ //addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
4502
+ switch (evt.keyCode) {
4503
+ case KEY_ESC:
4504
+ if (self.isOpen) {
4505
+ preventDefault(evt, true);
4506
+ self.close();
4507
+ }
4508
+
4509
+ self.clearActiveItems();
4510
+ return;
4511
+
4512
+ case KEY_TAB:
4513
+ self.focus_node.tabIndex = -1;
4514
+ break;
4515
+ }
4516
+
4517
+ return self.onKeyDown.call(self, evt);
4518
+ });
4519
+ self.on('blur', () => {
4520
+ self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
4521
+ }); // give the control_input focus when the dropdown is open
4522
+
4523
+ self.on('dropdown_open', () => {
4524
+ self.control_input.focus();
4525
+ }); // prevent onBlur from closing when focus is on the control_input
4526
+
4527
+ const orig_onBlur = self.onBlur;
4528
+ self.hook('instead', 'onBlur', evt => {
4529
+ if (evt && evt.relatedTarget == self.control_input) return;
4530
+ return orig_onBlur.call(self);
4531
+ });
4532
+ addEvent(self.control_input, 'blur', () => self.onBlur()); // return focus to control to allow further keyboard input
4533
+
4534
+ self.hook('before', 'close', () => {
4535
+ if (!self.isOpen) return;
4536
+ self.focus_node.focus({
4537
+ preventScroll: true
4538
+ });
4539
+ });
4540
+ });
4541
+ }
4542
+
4543
+ /**
4544
+ * Plugin: "input_autogrow" (Tom Select)
4545
+ *
4546
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4547
+ * file except in compliance with the License. You may obtain a copy of the License at:
4548
+ * http://www.apache.org/licenses/LICENSE-2.0
4549
+ *
4550
+ * Unless required by applicable law or agreed to in writing, software distributed under
4551
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4552
+ * ANY KIND, either express or implied. See the License for the specific language
4553
+ * governing permissions and limitations under the License.
4554
+ *
4555
+ */
4556
+ function input_autogrow () {
4557
+ var self = this;
4558
+ self.on('initialize', () => {
4559
+ var test_input = document.createElement('span');
4560
+ var control = self.control_input;
4561
+ test_input.style.cssText = 'position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ';
4562
+ self.wrapper.appendChild(test_input);
4563
+ var transfer_styles = ['letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform'];
4564
+
4565
+ for (const style_name of transfer_styles) {
4566
+ // @ts-ignore TS7015 https://stackoverflow.com/a/50506154/697576
4567
+ test_input.style[style_name] = control.style[style_name];
4568
+ }
4569
+ /**
4570
+ * Set the control width
4571
+ *
4572
+ */
4573
+
4574
+
4575
+ var resize = () => {
4576
+ test_input.textContent = control.value;
4577
+ control.style.width = test_input.clientWidth + 'px';
4578
+ };
4579
+
4580
+ resize();
4581
+ self.on('update item_add item_remove', resize);
4582
+ addEvent(control, 'input', resize);
4583
+ addEvent(control, 'keyup', resize);
4584
+ addEvent(control, 'blur', resize);
4585
+ addEvent(control, 'update', resize);
4586
+ });
4587
+ }
4588
+
4589
+ /**
4590
+ * Plugin: "input_autogrow" (Tom Select)
4591
+ *
4592
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4593
+ * file except in compliance with the License. You may obtain a copy of the License at:
4594
+ * http://www.apache.org/licenses/LICENSE-2.0
4595
+ *
4596
+ * Unless required by applicable law or agreed to in writing, software distributed under
4597
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4598
+ * ANY KIND, either express or implied. See the License for the specific language
4599
+ * governing permissions and limitations under the License.
4600
+ *
4601
+ */
4602
+ function no_backspace_delete () {
4603
+ var self = this;
4604
+ var orig_deleteSelection = self.deleteSelection;
4605
+ this.hook('instead', 'deleteSelection', evt => {
4606
+ if (self.activeItems.length) {
4607
+ return orig_deleteSelection.call(self, evt);
4608
+ }
4609
+
4610
+ return false;
4611
+ });
4612
+ }
4613
+
4614
+ /**
4615
+ * Plugin: "no_active_items" (Tom Select)
4616
+ *
4617
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4618
+ * file except in compliance with the License. You may obtain a copy of the License at:
4619
+ * http://www.apache.org/licenses/LICENSE-2.0
4620
+ *
4621
+ * Unless required by applicable law or agreed to in writing, software distributed under
4622
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4623
+ * ANY KIND, either express or implied. See the License for the specific language
4624
+ * governing permissions and limitations under the License.
4625
+ *
4626
+ */
4627
+ function no_active_items () {
4628
+ this.hook('instead', 'setActiveItem', () => {});
4629
+ this.hook('instead', 'selectAll', () => {});
4630
+ }
4631
+
4632
+ /**
4633
+ * Plugin: "optgroup_columns" (Tom Select.js)
4634
+ * Copyright (c) contributors
4635
+ *
4636
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4637
+ * file except in compliance with the License. You may obtain a copy of the License at:
4638
+ * http://www.apache.org/licenses/LICENSE-2.0
4639
+ *
4640
+ * Unless required by applicable law or agreed to in writing, software distributed under
4641
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4642
+ * ANY KIND, either express or implied. See the License for the specific language
4643
+ * governing permissions and limitations under the License.
4644
+ *
4645
+ */
4646
+ function optgroup_columns () {
4647
+ var self = this;
4648
+ var orig_keydown = self.onKeyDown;
4649
+ self.hook('instead', 'onKeyDown', evt => {
4650
+ var index, option, options, optgroup;
4651
+
4652
+ if (!self.isOpen || !(evt.keyCode === KEY_LEFT || evt.keyCode === KEY_RIGHT)) {
4653
+ return orig_keydown.call(self, evt);
4654
+ }
4655
+
4656
+ self.ignoreHover = true;
4657
+ optgroup = parentMatch(self.activeOption, '[data-group]');
4658
+ index = nodeIndex(self.activeOption, '[data-selectable]');
4659
+
4660
+ if (!optgroup) {
4661
+ return;
4662
+ }
4663
+
4664
+ if (evt.keyCode === KEY_LEFT) {
4665
+ optgroup = optgroup.previousSibling;
4666
+ } else {
4667
+ optgroup = optgroup.nextSibling;
4668
+ }
4669
+
4670
+ if (!optgroup) {
4671
+ return;
4672
+ }
4673
+
4674
+ options = optgroup.querySelectorAll('[data-selectable]');
4675
+ option = options[Math.min(options.length - 1, index)];
4676
+
4677
+ if (option) {
4678
+ self.setActiveOption(option);
4679
+ }
4680
+ });
4681
+ }
4682
+
4683
+ /**
4684
+ * Plugin: "remove_button" (Tom Select)
4685
+ * Copyright (c) contributors
4686
+ *
4687
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4688
+ * file except in compliance with the License. You may obtain a copy of the License at:
4689
+ * http://www.apache.org/licenses/LICENSE-2.0
4690
+ *
4691
+ * Unless required by applicable law or agreed to in writing, software distributed under
4692
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4693
+ * ANY KIND, either express or implied. See the License for the specific language
4694
+ * governing permissions and limitations under the License.
4695
+ *
4696
+ */
4697
+ function remove_button (userOptions) {
4698
+ const options = Object.assign({
4699
+ label: '&times;',
4700
+ title: 'Remove',
4701
+ className: 'remove',
4702
+ append: true
4703
+ }, userOptions); //options.className = 'remove-single';
4704
+
4705
+ var self = this; // override the render method to add remove button to each item
4706
+
4707
+ if (!options.append) {
4708
+ return;
4709
+ }
4710
+
4711
+ var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
4712
+ self.hook('after', 'setupTemplates', () => {
4713
+ var orig_render_item = self.settings.render.item;
4714
+
4715
+ self.settings.render.item = (data, escape) => {
4716
+ var item = getDom(orig_render_item.call(self, data, escape));
4717
+ var close_button = getDom(html);
4718
+ item.appendChild(close_button);
4719
+ addEvent(close_button, 'mousedown', evt => {
4720
+ preventDefault(evt, true);
4721
+ });
4722
+ addEvent(close_button, 'click', evt => {
4723
+ // propagating will trigger the dropdown to show for single mode
4724
+ preventDefault(evt, true);
4725
+ if (self.isLocked) return;
4726
+ if (!self.shouldDelete([item], evt)) return;
4727
+ self.removeItem(item);
4728
+ self.refreshOptions(false);
4729
+ self.inputState();
4730
+ });
4731
+ return item;
4732
+ };
4733
+ });
4734
+ }
4735
+
4736
+ /**
4737
+ * Plugin: "restore_on_backspace" (Tom Select)
4738
+ * Copyright (c) contributors
4739
+ *
4740
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4741
+ * file except in compliance with the License. You may obtain a copy of the License at:
4742
+ * http://www.apache.org/licenses/LICENSE-2.0
4743
+ *
4744
+ * Unless required by applicable law or agreed to in writing, software distributed under
4745
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4746
+ * ANY KIND, either express or implied. See the License for the specific language
4747
+ * governing permissions and limitations under the License.
4748
+ *
4749
+ */
4750
+ function restore_on_backspace (userOptions) {
4751
+ const self = this;
4752
+ const options = Object.assign({
4753
+ text: option => {
4754
+ return option[self.settings.labelField];
4755
+ }
4756
+ }, userOptions);
4757
+ self.on('item_remove', function (value) {
4758
+ if (!self.isFocused) {
4759
+ return;
4760
+ }
4761
+
4762
+ if (self.control_input.value.trim() === '') {
4763
+ var option = self.options[value];
4764
+
4765
+ if (option) {
4766
+ self.setTextboxValue(options.text.call(self, option));
4767
+ }
4768
+ }
4769
+ });
4770
+ }
4771
+
4772
+ /**
4773
+ * Plugin: "restore_on_backspace" (Tom Select)
4774
+ * Copyright (c) contributors
4775
+ *
4776
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
4777
+ * file except in compliance with the License. You may obtain a copy of the License at:
4778
+ * http://www.apache.org/licenses/LICENSE-2.0
4779
+ *
4780
+ * Unless required by applicable law or agreed to in writing, software distributed under
4781
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
4782
+ * ANY KIND, either express or implied. See the License for the specific language
4783
+ * governing permissions and limitations under the License.
4784
+ *
4785
+ */
4786
+ function virtual_scroll () {
4787
+ const self = this;
4788
+ const orig_canLoad = self.canLoad;
4789
+ const orig_clearActiveOption = self.clearActiveOption;
4790
+ const orig_loadCallback = self.loadCallback;
4791
+ var pagination = {};
4792
+ var dropdown_content;
4793
+ var loading_more = false;
4794
+ var load_more_opt;
4795
+ var default_values = [];
4796
+
4797
+ if (!self.settings.shouldLoadMore) {
4798
+ // return true if additional results should be loaded
4799
+ self.settings.shouldLoadMore = () => {
4800
+ const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop);
4801
+
4802
+ if (scroll_percent > 0.9) {
4803
+ return true;
4804
+ }
4805
+
4806
+ if (self.activeOption) {
4807
+ var selectable = self.selectable();
4808
+ var index = [...selectable].indexOf(self.activeOption);
4809
+
4810
+ if (index >= selectable.length - 2) {
4811
+ return true;
4812
+ }
4813
+ }
4814
+
4815
+ return false;
4816
+ };
4817
+ }
4818
+
4819
+ if (!self.settings.firstUrl) {
4820
+ throw 'virtual_scroll plugin requires a firstUrl() method';
4821
+ } // in order for virtual scrolling to work,
4822
+ // options need to be ordered the same way they're returned from the remote data source
4823
+
4824
+
4825
+ self.settings.sortField = [{
4826
+ field: '$order'
4827
+ }, {
4828
+ field: '$score'
4829
+ }]; // can we load more results for given query?
4830
+
4831
+ const canLoadMore = query => {
4832
+ if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) {
4833
+ return false;
4834
+ }
4835
+
4836
+ if (query in pagination && pagination[query]) {
4837
+ return true;
4838
+ }
4839
+
4840
+ return false;
4841
+ };
4842
+
4843
+ const clearFilter = (option, value) => {
4844
+ if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) {
4845
+ return true;
4846
+ }
4847
+
4848
+ return false;
4849
+ }; // set the next url that will be
4850
+
4851
+
4852
+ self.setNextUrl = (value, next_url) => {
4853
+ pagination[value] = next_url;
4854
+ }; // getUrl() to be used in settings.load()
4855
+
4856
+
4857
+ self.getUrl = query => {
4858
+ if (query in pagination) {
4859
+ const next_url = pagination[query];
4860
+ pagination[query] = false;
4861
+ return next_url;
4862
+ } // if the user goes back to a previous query
4863
+ // we need to load the first page again
4864
+
4865
+
4866
+ pagination = {};
4867
+ return self.settings.firstUrl.call(self, query);
4868
+ }; // don't clear the active option (and cause unwanted dropdown scroll)
4869
+ // while loading more results
4870
+
4871
+
4872
+ self.hook('instead', 'clearActiveOption', () => {
4873
+ if (loading_more) {
4874
+ return;
4875
+ }
4876
+
4877
+ return orig_clearActiveOption.call(self);
4878
+ }); // override the canLoad method
4879
+
4880
+ self.hook('instead', 'canLoad', query => {
4881
+ // first time the query has been seen
4882
+ if (!(query in pagination)) {
4883
+ return orig_canLoad.call(self, query);
4884
+ }
4885
+
4886
+ return canLoadMore(query);
4887
+ }); // wrap the load
4888
+
4889
+ self.hook('instead', 'loadCallback', (options, optgroups) => {
4890
+ if (!loading_more) {
4891
+ self.clearOptions(clearFilter);
4892
+ } else if (load_more_opt && options.length > 0) {
4893
+ load_more_opt.dataset.value = options[0][self.settings.valueField];
4894
+ }
4895
+
4896
+ orig_loadCallback.call(self, options, optgroups);
4897
+ loading_more = false;
4898
+ }); // add templates to dropdown
4899
+ // loading_more if we have another url in the queue
4900
+ // no_more_results if we don't have another url in the queue
4901
+
4902
+ self.hook('after', 'refreshOptions', () => {
4903
+ const query = self.lastValue;
4904
+ var option;
4905
+
4906
+ if (canLoadMore(query)) {
4907
+ option = self.render('loading_more', {
4908
+ query: query
4909
+ });
4910
+
4911
+ if (option) {
4912
+ option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node
4913
+
4914
+ load_more_opt = option;
4915
+ }
4916
+ } else if (query in pagination && !dropdown_content.querySelector('.no-results')) {
4917
+ option = self.render('no_more_results', {
4918
+ query: query
4919
+ });
4920
+ }
4921
+
4922
+ if (option) {
4923
+ addClasses(option, self.settings.optionClass);
4924
+ dropdown_content.append(option);
4925
+ }
4926
+ }); // add scroll listener and default templates
4927
+
4928
+ self.on('initialize', () => {
4929
+ default_values = Object.keys(self.options);
4930
+ dropdown_content = self.dropdown_content; // default templates
4931
+
4932
+ self.settings.render = Object.assign({}, {
4933
+ loading_more: () => {
4934
+ return `<div class="loading-more-results">Loading more results ... </div>`;
4935
+ },
4936
+ no_more_results: () => {
4937
+ return `<div class="no-more-results">No more results</div>`;
4938
+ }
4939
+ }, self.settings.render); // watch dropdown content scroll position
4940
+
4941
+ dropdown_content.addEventListener('scroll', () => {
4942
+ if (!self.settings.shouldLoadMore.call(self)) {
4943
+ return;
4944
+ } // !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true
4945
+
4946
+
4947
+ if (!canLoadMore(self.lastValue)) {
4948
+ return;
4949
+ } // don't call load() too much
4950
+
4951
+
4952
+ if (loading_more) return;
4953
+ loading_more = true;
4954
+ self.load.call(self, self.lastValue);
4955
+ });
4956
+ });
4957
+ }
4958
+
4959
+ TomSelect.define('change_listener', change_listener);
4960
+ TomSelect.define('checkbox_options', checkbox_options);
4961
+ TomSelect.define('clear_button', clear_button);
4962
+ TomSelect.define('drag_drop', drag_drop);
4963
+ TomSelect.define('dropdown_header', dropdown_header);
4964
+ TomSelect.define('caret_position', caret_position);
4965
+ TomSelect.define('dropdown_input', dropdown_input);
4966
+ TomSelect.define('input_autogrow', input_autogrow);
4967
+ TomSelect.define('no_backspace_delete', no_backspace_delete);
4968
+ TomSelect.define('no_active_items', no_active_items);
4969
+ TomSelect.define('optgroup_columns', optgroup_columns);
4970
+ TomSelect.define('remove_button', remove_button);
4971
+ TomSelect.define('restore_on_backspace', restore_on_backspace);
4972
+ TomSelect.define('virtual_scroll', virtual_scroll);
4973
+
4974
+ return TomSelect;
4975
+
4976
+ }));
4977
+ var tomSelect=function(el,opts){return new TomSelect(el,opts);}
4978
+ //# sourceMappingURL=tom-select.complete.js.map