alchemy_cms 8.3.10 → 8.4.0

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 (370) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +58 -10
  4. data/app/assets/builds/alchemy/admin/page-select.css +1 -1
  5. data/app/assets/builds/alchemy/admin/print.css +1 -1
  6. data/app/assets/builds/alchemy/admin/remote-select.css +1 -0
  7. data/app/assets/builds/alchemy/admin/tags-autocomplete.css +1 -0
  8. data/app/assets/builds/alchemy/admin.css +4 -4
  9. data/app/assets/builds/alchemy/alchemy_admin.min.js +1 -1
  10. data/app/assets/builds/alchemy/alchemy_admin.min.js.map +1 -1
  11. data/app/assets/builds/alchemy/dark-theme.css +1 -1
  12. data/app/assets/builds/alchemy/light-theme.css +1 -1
  13. data/app/assets/builds/alchemy/preview.min.js +1 -1
  14. data/app/assets/builds/alchemy/theme.css +1 -1
  15. data/app/assets/builds/alchemy/welcome.css +1 -1
  16. data/app/assets/builds/tinymce/skins/content/alchemy/content.min.css +1 -1
  17. data/app/assets/builds/tinymce/skins/content/alchemy-dark/content.min.css +1 -1
  18. data/app/assets/builds/tinymce/skins/ui/alchemy/skin.min.css +1 -1
  19. data/app/assets/builds/tinymce/skins/ui/alchemy-dark/skin.min.css +1 -1
  20. data/app/assets/images/alchemy/icons-sprite.svg +1 -1
  21. data/app/components/alchemy/admin/dashboard/widgets/greeting.html.erb +1 -1
  22. data/app/components/alchemy/admin/dashboard/widgets/news_reader.html.erb +38 -0
  23. data/app/components/alchemy/admin/dashboard/widgets/news_reader.rb +54 -0
  24. data/app/components/alchemy/admin/dashboard/widgets/online_users.html.erb +1 -1
  25. data/app/components/alchemy/admin/dashboard/widgets/recent_pages.html.erb +1 -1
  26. data/app/components/alchemy/admin/dashboard/widgets/system_info.html.erb +11 -3
  27. data/app/components/alchemy/admin/dashboard/widgets/system_info.rb +6 -1
  28. data/app/components/alchemy/admin/element_editor.html.erb +1 -1
  29. data/app/components/alchemy/admin/element_select.rb +30 -20
  30. data/app/components/alchemy/admin/element_status_indicators.html.erb +16 -0
  31. data/app/components/alchemy/admin/element_status_indicators.rb +31 -0
  32. data/app/components/alchemy/admin/link_dialog/external_tab.rb +2 -1
  33. data/app/components/alchemy/admin/main_navigation/entry.rb +61 -0
  34. data/app/components/alchemy/admin/main_navigation/menu.rb +21 -0
  35. data/app/components/alchemy/admin/main_navigation/sub_navigation.rb +31 -0
  36. data/app/components/alchemy/admin/page_node.html.erb +1 -1
  37. data/app/components/alchemy/admin/page_permitted_roles_select.html.erb +11 -0
  38. data/app/components/alchemy/admin/page_permitted_roles_select.rb +35 -0
  39. data/app/components/alchemy/admin/page_select.rb +18 -8
  40. data/app/components/alchemy/admin/preview_time_select.rb +1 -1
  41. data/app/components/alchemy/admin/toolbar_button.rb +43 -20
  42. data/app/components/alchemy/admin/uploader_button.rb +66 -0
  43. data/app/components/alchemy/ingredients/base_editor.rb +10 -1
  44. data/app/components/alchemy/ingredients/boolean_editor.rb +1 -0
  45. data/app/components/alchemy/ingredients/color_editor.rb +6 -3
  46. data/app/components/alchemy/ingredients/datetime_view.rb +1 -1
  47. data/app/components/alchemy/ingredients/picture_view.rb +2 -4
  48. data/app/components/alchemy/menubar.html.erb +157 -0
  49. data/app/components/alchemy/menubar.rb +15 -0
  50. data/app/controllers/alchemy/admin/attachments_controller.rb +12 -9
  51. data/app/controllers/alchemy/admin/base_controller.rb +34 -21
  52. data/app/controllers/alchemy/admin/dashboard_controller.rb +4 -0
  53. data/app/controllers/alchemy/admin/elements_controller.rb +4 -23
  54. data/app/controllers/alchemy/admin/languages_controller.rb +1 -1
  55. data/app/controllers/alchemy/admin/nodes_controller.rb +1 -1
  56. data/app/controllers/alchemy/admin/pages_controller.rb +1 -1
  57. data/app/controllers/alchemy/admin/pictures_controller.rb +6 -3
  58. data/app/controllers/alchemy/admin/resources_controller.rb +5 -5
  59. data/app/controllers/alchemy/admin/sites_controller.rb +1 -1
  60. data/app/controllers/alchemy/base_controller.rb +24 -16
  61. data/app/controllers/alchemy/pages_controller.rb +29 -8
  62. data/app/controllers/alchemy/sitemap_controller.rb +58 -0
  63. data/app/controllers/concerns/alchemy/admin/csp_protection.rb +43 -0
  64. data/app/controllers/concerns/alchemy/admin/current_language.rb +1 -1
  65. data/app/controllers/concerns/alchemy/admin/resource_filter.rb +3 -1
  66. data/{lib → app/controllers/concerns}/alchemy/controller_actions.rb +13 -0
  67. data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +4 -4
  68. data/app/helpers/alchemy/admin/base_helper.rb +4 -1
  69. data/app/helpers/alchemy/admin/form_helper.rb +0 -2
  70. data/app/helpers/alchemy/admin/navigation_helper.rb +10 -181
  71. data/app/helpers/alchemy/elements_block_helper.rb +14 -0
  72. data/app/helpers/alchemy/resources_helper.rb +15 -1
  73. data/app/javascript/alchemy_admin/components/attachment_select.js +11 -20
  74. data/app/javascript/alchemy_admin/components/auto_submit.js +2 -4
  75. data/app/javascript/alchemy_admin/components/button.js +0 -6
  76. data/app/javascript/alchemy_admin/components/clear_schedule_button.js +21 -0
  77. data/app/javascript/alchemy_admin/components/color_select.js +50 -45
  78. data/app/javascript/alchemy_admin/components/conditional_field.js +50 -0
  79. data/app/javascript/alchemy_admin/components/dirty_guard.js +77 -0
  80. data/app/javascript/alchemy_admin/components/dom_id_select.js +17 -10
  81. data/app/javascript/alchemy_admin/components/element_editor/delete_element_button.js +7 -2
  82. data/app/javascript/alchemy_admin/components/element_editor.js +29 -56
  83. data/app/javascript/alchemy_admin/components/element_select.js +26 -66
  84. data/app/javascript/alchemy_admin/components/icon.js +9 -4
  85. data/app/javascript/alchemy_admin/{image_cropper.js → components/image_cropper.js} +39 -53
  86. data/app/javascript/alchemy_admin/components/image_overlay_link.js +14 -0
  87. data/app/javascript/alchemy_admin/components/index.js +12 -1
  88. data/app/javascript/alchemy_admin/components/main_navi_entry.js +75 -0
  89. data/app/javascript/alchemy_admin/components/menu_node.js +73 -0
  90. data/app/javascript/alchemy_admin/components/news_reader.js +109 -0
  91. data/app/javascript/alchemy_admin/components/node_folder.js +36 -0
  92. data/app/javascript/alchemy_admin/components/node_form.js +34 -0
  93. data/app/javascript/alchemy_admin/components/node_select.js +25 -30
  94. data/app/javascript/alchemy_admin/components/node_tree.js +56 -0
  95. data/app/javascript/alchemy_admin/components/page_node.js +2 -1
  96. data/app/javascript/alchemy_admin/components/page_select.js +16 -34
  97. data/app/javascript/alchemy_admin/components/picture_archive.js +92 -0
  98. data/app/javascript/alchemy_admin/components/picture_editor.js +2 -1
  99. data/app/javascript/alchemy_admin/components/preview_window.js +11 -3
  100. data/app/javascript/alchemy_admin/components/remote_select.js +461 -81
  101. data/app/javascript/alchemy_admin/components/select.js +26 -88
  102. data/app/javascript/alchemy_admin/components/sitemap.js +2 -1
  103. data/app/javascript/alchemy_admin/components/sortable_elements.js +2 -1
  104. data/app/javascript/alchemy_admin/components/tags_autocomplete.js +63 -48
  105. data/app/javascript/alchemy_admin/components/tinymce.js +2 -1
  106. data/app/javascript/alchemy_admin/components/uploader/file_upload.js +3 -2
  107. data/app/javascript/alchemy_admin/components/uploader.js +19 -3
  108. data/app/javascript/alchemy_admin/confirm_dialog.js +7 -1
  109. data/app/javascript/alchemy_admin/dialog.js +182 -110
  110. data/app/javascript/alchemy_admin/hotkeys.js +0 -5
  111. data/app/javascript/alchemy_admin/i18n.js +3 -9
  112. data/app/javascript/alchemy_admin/image_overlay.js +58 -42
  113. data/app/javascript/alchemy_admin/initializer.js +2 -2
  114. data/app/javascript/alchemy_admin/link_dialog.js +15 -2
  115. data/app/javascript/alchemy_admin/routes.js +18 -0
  116. data/app/javascript/alchemy_admin/turbo_stream_actions.js +88 -0
  117. data/app/javascript/alchemy_admin/utils/ajax.js +14 -3
  118. data/app/javascript/alchemy_admin/utils/events.js +5 -0
  119. data/app/javascript/alchemy_admin/utils/json_script.js +12 -0
  120. data/app/javascript/alchemy_admin/utils/tom_select.js +171 -0
  121. data/app/javascript/alchemy_admin.js +2 -19
  122. data/app/javascript/preview.js +131 -113
  123. data/app/jobs/alchemy/invalidate_elements_cache_job.rb +1 -1
  124. data/app/models/alchemy/admin/content_security_policy.rb +143 -0
  125. data/app/models/alchemy/admin/filters/base.rb +7 -0
  126. data/app/models/alchemy/admin/filters/datepicker.rb +1 -1
  127. data/app/models/alchemy/admin/filters/select.rb +20 -7
  128. data/app/models/alchemy/attachment.rb +14 -7
  129. data/app/models/alchemy/cache_control.rb +104 -0
  130. data/app/models/alchemy/current.rb +1 -1
  131. data/app/models/alchemy/eager_loading.rb +0 -2
  132. data/app/models/alchemy/element.rb +23 -8
  133. data/app/models/alchemy/element_definition.rb +1 -0
  134. data/app/models/alchemy/elements_repository.rb +11 -0
  135. data/app/models/alchemy/folded_page.rb +5 -1
  136. data/app/models/alchemy/ingredient.rb +26 -0
  137. data/app/models/alchemy/ingredients/datetime.rb +1 -1
  138. data/app/models/alchemy/ingredients/link.rb +2 -0
  139. data/app/models/alchemy/ingredients/picture.rb +3 -0
  140. data/app/models/alchemy/ingredients/text.rb +2 -0
  141. data/app/models/alchemy/language.rb +19 -7
  142. data/app/models/alchemy/legacy_page_url.rb +6 -1
  143. data/app/models/alchemy/node.rb +51 -0
  144. data/app/models/alchemy/page/page_natures.rb +41 -8
  145. data/app/models/alchemy/page/page_scopes.rb +23 -0
  146. data/app/models/alchemy/page/sitemap_cache_key.rb +56 -0
  147. data/app/models/alchemy/page.rb +88 -32
  148. data/app/models/alchemy/page_definition.rb +1 -1
  149. data/app/models/alchemy/page_mutex.rb +16 -0
  150. data/app/models/alchemy/page_version.rb +24 -1
  151. data/app/models/alchemy/permissions.rb +6 -5
  152. data/app/models/alchemy/picture.rb +15 -7
  153. data/app/models/alchemy/picture_description.rb +22 -0
  154. data/app/models/alchemy/picture_thumb.rb +18 -0
  155. data/app/models/alchemy/publishable/timestamp_resolver.rb +70 -0
  156. data/app/models/alchemy/resource.rb +1 -1
  157. data/app/models/alchemy/safe_url_validator.rb +34 -0
  158. data/app/models/alchemy/site.rb +8 -3
  159. data/app/models/alchemy/storage_adapter/active_storage/preprocessor.rb +7 -3
  160. data/app/models/alchemy/storage_adapter/active_storage.rb +4 -1
  161. data/app/models/alchemy/tag.rb +10 -4
  162. data/{lib → app/models/concerns}/alchemy/filetypes.rb +5 -0
  163. data/app/models/concerns/alchemy/picture_thumbnails.rb +61 -6
  164. data/app/models/concerns/alchemy/publishable.rb +14 -29
  165. data/app/models/concerns/alchemy/taggable.rb +92 -0
  166. data/app/models/concerns/alchemy/user_methods.rb +95 -0
  167. data/app/services/alchemy/duplicate_element.rb +5 -2
  168. data/app/services/alchemy/element_preloader.rb +1 -2
  169. data/app/stylesheets/alchemy/_custom-properties.scss +1 -0
  170. data/app/stylesheets/alchemy/_extends.scss +0 -8
  171. data/app/stylesheets/alchemy/_themes.scss +10 -9
  172. data/app/stylesheets/alchemy/admin/_empty-state.scss +29 -0
  173. data/app/stylesheets/alchemy/admin/_help.scss +10 -0
  174. data/app/stylesheets/alchemy/admin/_tom-select.scss +104 -15
  175. data/app/stylesheets/alchemy/admin/archive.scss +56 -11
  176. data/app/stylesheets/alchemy/admin/base.scss +4 -5
  177. data/app/stylesheets/alchemy/admin/buttons.scss +12 -1
  178. data/app/stylesheets/alchemy/admin/dashboard.scss +150 -20
  179. data/app/stylesheets/alchemy/admin/dialogs.scss +27 -36
  180. data/app/stylesheets/alchemy/admin/element-select.scss +1 -1
  181. data/app/stylesheets/alchemy/admin/elements.scss +8 -24
  182. data/app/stylesheets/alchemy/admin/flash.scss +2 -1
  183. data/app/stylesheets/alchemy/admin/forms.scss +60 -24
  184. data/app/stylesheets/alchemy/admin/frame.scss +40 -4
  185. data/app/stylesheets/alchemy/admin/image_library.scss +9 -12
  186. data/app/stylesheets/alchemy/admin/navigation.scss +17 -14
  187. data/app/stylesheets/alchemy/admin/node-select.scss +13 -37
  188. data/app/stylesheets/alchemy/admin/nodes.scss +1 -1
  189. data/app/stylesheets/alchemy/admin/page-select.scss +6 -97
  190. data/app/stylesheets/alchemy/admin/print.scss +0 -4
  191. data/app/stylesheets/alchemy/admin/remote-select.scss +170 -0
  192. data/app/stylesheets/alchemy/admin/search.scss +2 -3
  193. data/app/stylesheets/alchemy/admin/selects.scss +1 -294
  194. data/app/stylesheets/alchemy/admin/sitemap.scss +2 -1
  195. data/app/stylesheets/alchemy/admin/tables.scss +7 -1
  196. data/app/stylesheets/alchemy/admin/tags-autocomplete.scss +17 -0
  197. data/app/stylesheets/alchemy/admin/tags.scss +0 -13
  198. data/app/stylesheets/alchemy/admin/toolbar.scss +9 -6
  199. data/app/stylesheets/alchemy/admin/upload.scss +61 -1
  200. data/app/stylesheets/alchemy/admin.scss +4 -1
  201. data/app/stylesheets/tinymce/skins/ui/alchemy/skin.scss +19 -0
  202. data/app/stylesheets/tinymce/skins/ui/alchemy-dark/skin.scss +19 -0
  203. data/app/types/alchemy/cache_control_type.rb +84 -0
  204. data/app/views/alchemy/_edit_mode.html.erb +1 -1
  205. data/app/views/alchemy/_menubar.html.erb +2 -154
  206. data/app/views/alchemy/_preview_mode_code.html.erb +0 -3
  207. data/app/views/alchemy/admin/_left_menu.html.erb +18 -5
  208. data/app/views/alchemy/admin/_top_menu.html.erb +1 -1
  209. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +5 -4
  210. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +3 -3
  211. data/app/views/alchemy/admin/attachments/_files_list.html.erb +71 -83
  212. data/app/views/alchemy/admin/attachments/assign.turbo_stream.erb +8 -0
  213. data/app/views/alchemy/admin/attachments/index.html.erb +32 -7
  214. data/app/views/alchemy/admin/clipboard/insert.turbo_stream.erb +1 -1
  215. data/app/views/alchemy/admin/crop.html.erb +20 -20
  216. data/app/views/alchemy/admin/dashboard/_footer.html.erb +0 -3
  217. data/app/views/alchemy/admin/dashboard/_top.html.erb +1 -0
  218. data/app/views/alchemy/admin/dashboard/help.html.erb +84 -57
  219. data/app/views/alchemy/admin/dashboard/license.html.erb +6 -0
  220. data/app/views/alchemy/admin/elements/_footer.html.erb +0 -1
  221. data/app/views/alchemy/admin/elements/_form.html.erb +1 -1
  222. data/app/views/alchemy/admin/elements/_header.html.erb +2 -19
  223. data/app/views/alchemy/admin/elements/_preview_text_quote.html.erb +3 -0
  224. data/app/views/alchemy/admin/elements/_schedule.html.erb +7 -7
  225. data/app/views/alchemy/admin/elements/_toolbar.html.erb +1 -1
  226. data/app/views/alchemy/admin/elements/create.turbo_stream.erb +1 -1
  227. data/app/views/alchemy/admin/elements/index.html.erb +1 -1
  228. data/app/views/alchemy/admin/elements/publish.turbo_stream.erb +2 -2
  229. data/app/views/alchemy/admin/elements/update.turbo_stream.erb +31 -0
  230. data/app/views/alchemy/admin/ingredients/update.turbo_stream.erb +6 -3
  231. data/app/views/alchemy/admin/languages/_table.html.erb +0 -2
  232. data/app/views/alchemy/admin/languages/index.html.erb +25 -29
  233. data/app/views/alchemy/admin/layoutpages/_layoutpage.html.erb +1 -3
  234. data/app/views/alchemy/admin/layoutpages/edit.html.erb +1 -1
  235. data/app/views/alchemy/admin/layoutpages/index.html.erb +26 -7
  236. data/app/views/alchemy/admin/nodes/_form.html.erb +3 -21
  237. data/app/views/alchemy/admin/nodes/_node.html.erb +93 -88
  238. data/app/views/alchemy/admin/nodes/index.html.erb +15 -23
  239. data/app/views/alchemy/admin/pages/_create_language_form.html.erb +2 -6
  240. data/app/views/alchemy/admin/pages/_form.html.erb +2 -1
  241. data/app/views/alchemy/admin/pages/_publication_fields.html.erb +1 -1
  242. data/app/views/alchemy/admin/pages/_table.html.erb +2 -4
  243. data/app/views/alchemy/admin/pages/_toolbar.html.erb +2 -1
  244. data/app/views/alchemy/admin/pages/edit.html.erb +10 -21
  245. data/app/views/alchemy/admin/pages/flush.turbo_stream.erb +1 -1
  246. data/app/views/alchemy/admin/pages/index.html.erb +26 -31
  247. data/app/views/alchemy/admin/pages/info.html.erb +2 -2
  248. data/app/views/alchemy/admin/pages/update.turbo_stream.erb +2 -2
  249. data/app/views/alchemy/admin/partials/_language_tree_select.html.erb +1 -1
  250. data/app/views/alchemy/admin/partials/_routes.html.erb +24 -48
  251. data/app/views/alchemy/admin/pictures/_archive.html.erb +3 -17
  252. data/app/views/alchemy/admin/pictures/_archive_overlay.html.erb +1 -1
  253. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +5 -3
  254. data/app/views/alchemy/admin/pictures/_form.html.erb +0 -1
  255. data/app/views/alchemy/admin/pictures/_infos.html.erb +5 -1
  256. data/app/views/alchemy/admin/pictures/_picture.html.erb +1 -1
  257. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +3 -4
  258. data/app/views/alchemy/admin/pictures/assign.turbo_stream.erb +7 -0
  259. data/app/views/alchemy/admin/pictures/index.html.erb +38 -30
  260. data/app/views/alchemy/admin/pictures/show.html.erb +41 -41
  261. data/app/views/alchemy/admin/resources/_empty_state.html.erb +27 -0
  262. data/app/views/alchemy/admin/resources/_pagination.html.erb +1 -1
  263. data/app/views/alchemy/admin/resources/_per_page_select.html.erb +1 -1
  264. data/app/views/alchemy/admin/resources/_resource_table.html.erb +0 -2
  265. data/app/views/alchemy/admin/resources/_resource_usage_info.html.erb +3 -2
  266. data/app/views/alchemy/admin/resources/index.html.erb +32 -13
  267. data/app/views/alchemy/admin/sites/index.html.erb +24 -22
  268. data/app/views/alchemy/admin/styleguide/index.html.erb +35 -12
  269. data/app/views/alchemy/admin/tags/index.html.erb +27 -25
  270. data/app/views/alchemy/admin/tinymce/_setup.html.erb +6 -8
  271. data/app/views/alchemy/admin/translations/_en.js +3 -0
  272. data/app/views/alchemy/admin/uploader/_button.html.erb +11 -17
  273. data/app/views/alchemy/admin/uploader/_setup.html.erb +3 -3
  274. data/app/views/alchemy/pages/sitemap.xml.erb +2 -0
  275. data/app/views/kaminari/alchemy/_first_page.html.erb +1 -2
  276. data/app/views/kaminari/alchemy/_gap.html.erb +0 -1
  277. data/app/views/kaminari/alchemy/_last_page.html.erb +1 -2
  278. data/app/views/kaminari/alchemy/_next_page.html.erb +1 -2
  279. data/app/views/kaminari/alchemy/_page.html.erb +1 -2
  280. data/app/views/kaminari/alchemy/_paginator.html.erb +0 -1
  281. data/app/views/kaminari/alchemy/_prev_page.html.erb +1 -2
  282. data/app/views/layouts/alchemy/admin/dialog.html.erb +3 -0
  283. data/app/views/layouts/alchemy/admin.html.erb +5 -6
  284. data/config/brakeman.ignore +23 -1
  285. data/config/importmap.rb +10 -8
  286. data/config/initializers/dragonfly.rb +21 -17
  287. data/config/locales/alchemy.en.yml +53 -12
  288. data/config/routes.rb +3 -3
  289. data/db/migrate/20260727120000_add_permitted_roles_to_alchemy_pages.rb +23 -0
  290. data/db/migrate/20260820120000_add_cached_tag_list_to_taggables.rb +57 -0
  291. data/lib/alchemy/configuration/number_option.rb +13 -0
  292. data/lib/alchemy/configuration/proc_option.rb +13 -0
  293. data/lib/alchemy/configuration.rb +2 -0
  294. data/lib/alchemy/configurations/admin_components.rb +30 -0
  295. data/lib/alchemy/configurations/format_matchers.rb +7 -1
  296. data/lib/alchemy/configurations/main.rb +103 -4
  297. data/lib/alchemy/configurations/menu.rb +91 -0
  298. data/lib/alchemy/configurations/menu_item.rb +123 -0
  299. data/lib/alchemy/configurations/sitemap.rb +1 -0
  300. data/lib/alchemy/configurations/uploader.rb +15 -1
  301. data/lib/alchemy/engine.rb +0 -6
  302. data/lib/alchemy/i18n.rb +26 -0
  303. data/lib/alchemy/modules.rb +52 -50
  304. data/lib/alchemy/tasks/generate_thumbnails.rb +99 -0
  305. data/lib/alchemy/tasks/tidy.rb +1 -1
  306. data/lib/alchemy/test_support/capybara_helpers.rb +48 -37
  307. data/lib/alchemy/test_support/current_language_shared_examples.rb +1 -1
  308. data/lib/alchemy/test_support/factories/dummy_user_factory.rb +4 -1
  309. data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +132 -0
  310. data/lib/alchemy/test_support/shared_ingredient_examples.rb +52 -0
  311. data/lib/alchemy/test_support/shared_publishable_examples.rb +39 -4
  312. data/lib/alchemy/upgrader/eight_four.rb +237 -0
  313. data/lib/alchemy/upgrader/register_module_rewriter.rb +177 -0
  314. data/lib/alchemy/upgrader.rb +2 -1
  315. data/lib/alchemy/version.rb +1 -1
  316. data/lib/alchemy.rb +0 -1
  317. data/lib/alchemy_cms.rb +0 -13
  318. data/lib/generators/alchemy/elements/templates/view.html.erb +1 -1
  319. data/lib/generators/alchemy/elements/templates/view.html.haml +1 -1
  320. data/lib/generators/alchemy/elements/templates/view.html.slim +1 -1
  321. data/lib/generators/alchemy/install/install_generator.rb +2 -13
  322. data/lib/generators/alchemy/install/templates/alchemy.rb.tt +24 -9
  323. data/lib/generators/alchemy/module/module_generator.rb +1 -0
  324. data/lib/generators/alchemy/module/templates/ability.rb.tt +1 -1
  325. data/lib/generators/alchemy/module/templates/module_config.rb.tt +16 -18
  326. data/lib/generators/alchemy/user_columns_migration/templates/migration.rb.tt +19 -0
  327. data/lib/generators/alchemy/user_columns_migration/user_columns_migration_generator.rb +30 -0
  328. data/lib/tasks/alchemy/thumbnails.rake +16 -29
  329. data/lib/tasks/alchemy/upgrade.rake +45 -3
  330. data/vendor/javascript/cropperjs.min.js +3 -3
  331. data/vendor/javascript/floating-ui.min.js +1 -1
  332. data/vendor/javascript/tinymce.min.js +5 -5
  333. data/vendor/javascript/tom-select.min.js +1 -1
  334. metadata +85 -65
  335. data/app/javascript/alchemy_admin/components/action.js +0 -50
  336. data/app/javascript/alchemy_admin/dirty.js +0 -55
  337. data/app/javascript/alchemy_admin/node_tree.js +0 -82
  338. data/app/javascript/alchemy_admin/picture_selector.js +0 -67
  339. data/app/javascript/alchemy_admin/templates/compiled.js +0 -1
  340. data/app/javascript/alchemy_admin/templates/node_folder.hbs +0 -3
  341. data/app/stylesheets/alchemy/admin/attachment-select.scss +0 -19
  342. data/app/views/alchemy/admin/_main_navi.html.erb +0 -6
  343. data/app/views/alchemy/admin/attachments/assign.js.erb +0 -15
  344. data/app/views/alchemy/admin/pages/_page_layout_filter.html.erb +0 -30
  345. data/app/views/alchemy/admin/partials/_main_navigation_entry.html.erb +0 -20
  346. data/app/views/alchemy/admin/partials/_sub_navigation.html.erb +0 -11
  347. data/app/views/alchemy/admin/pictures/assign.js.erb +0 -13
  348. data/app/views/alchemy/base/error_notice.js.erb +0 -1
  349. data/app/views/alchemy/base/permission_denied.js.erb +0 -3
  350. data/app/views/alchemy/base/redirect.js.erb +0 -11
  351. data/config/alchemy/config.yml +0 -217
  352. data/config/alchemy/modules.yml +0 -82
  353. data/config/initializers/rails_live_reload.rb +0 -13
  354. data/lib/alchemy/dev_support/live_reload_watcher.rb +0 -5
  355. data/lib/alchemy/taggable.rb +0 -49
  356. data/lib/generators/alchemy/install/templates/dragonfly.rb.tt +0 -34
  357. data/vendor/assets/stylesheets/alchemy_admin/select2.css +0 -1
  358. data/vendor/javascript/handlebars.min.js +0 -29
  359. data/vendor/javascript/jquery.min.js +0 -2
  360. data/vendor/javascript/rails-ujs.min.js +0 -1
  361. data/vendor/javascript/select2.min.js +0 -23
  362. /data/{lib → app/controllers/concerns}/alchemy/ability_helper.rb +0 -0
  363. /data/{lib → app/controllers/concerns}/alchemy/admin/locale.rb +0 -0
  364. /data/{lib → app/controllers/concerns}/alchemy/admin/preview_time.rb +0 -0
  365. /data/{lib → app/controllers/concerns}/alchemy/admin/timezone.rb +0 -0
  366. /data/{lib → app/controllers/concerns}/alchemy/configuration_methods.rb +0 -0
  367. /data/{lib → app/models}/alchemy/admin/preview_url.rb +0 -0
  368. /data/{lib → app/models/concerns}/alchemy/hints.rb +0 -0
  369. /data/{lib → app/models/concerns}/alchemy/name_conversions.rb +0 -0
  370. /data/{lib → app/services}/alchemy/elements_finder.rb +0 -0
@@ -1 +1 @@
1
- function t(t,e){t.split(/\s+/).forEach(t=>{e(t)})}class e{constructor(){this._events={}}on(e,i){t(e,t=>{const e=this._events[t]||[];e.push(i),this._events[t]=e})}off(e,i){var s=arguments.length;0!==s?t(e,t=>{if(1===s)return void delete this._events[t];const e=this._events[t];void 0!==e&&(e.splice(e.indexOf(i),1),this._events[t]=e)}):this._events={}}trigger(e,...i){var s=this;t(e,t=>{const e=s._events[t];void 0!==e&&e.forEach(t=>{t.apply(s,i)})})}}const i=t=>(t=t.filter(Boolean)).length<2?t[0]||"":1==l(t)?"["+t.join("")+"]":"(?:"+t.join("|")+")",s=t=>{if(!o(t))return t.join("");let e="",i=0;const s=()=>{i>1&&(e+="{"+i+"}")};return t.forEach((n,o)=>{n!==t[o-1]?(s(),e+=n,i=1):i++}),s(),e},n=t=>{let e=Array.from(t);return i(e)},o=t=>new Set(t).size!==t.length,r=t=>(t+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1"),l=t=>t.reduce((t,e)=>Math.max(t,a(e)),0),a=t=>Array.from(t).length,c=t=>{if(1===t.length)return[[t]];let e=[];const i=t.substring(1);return c(i).forEach(function(i){let s=i.slice(0);s[0]=t.charAt(0)+s[0],e.push(s),s=i.slice(0),s.unshift(t.charAt(0)),e.push(s)}),e},d=[[0,65535]];let p,u;const h={},g={"/":"⁄∕",0:"߀",a:"ⱥɐɑ",aa:"ꜳ",ae:"æǽǣ",ao:"ꜵ",au:"ꜷ",av:"ꜹꜻ",ay:"ꜽ",b:"ƀɓƃ",c:"ꜿƈȼↄ",d:"đɗɖᴅƌꮷԁɦ",e:"ɛǝᴇɇ",f:"ꝼƒ",g:"ǥɠꞡᵹꝿɢ",h:"ħⱨⱶɥ",i:"ɨı",j:"ɉȷ",k:"ƙⱪꝁꝃꝅꞣ",l:"łƚɫⱡꝉꝇꞁɭ",m:"ɱɯϻ",n:"ꞥƞɲꞑᴎлԉ",o:"øǿɔɵꝋꝍᴑ",oe:"œ",oi:"ƣ",oo:"ꝏ",ou:"ȣ",p:"ƥᵽꝑꝓꝕρ",q:"ꝗꝙɋ",r:"ɍɽꝛꞧꞃ",s:"ßȿꞩꞅʂ",t:"ŧƭʈⱦꞇ",th:"þ",tz:"ꜩ",u:"ʉ",v:"ʋꝟʌ",vy:"ꝡ",w:"ⱳ",y:"ƴɏỿ",z:"ƶȥɀⱬꝣ",hv:"ƕ"};for(let t in g){let e=g[t]||"";for(let i=0;i<e.length;i++){let s=e.substring(i,i+1);h[s]=t}}const f=new RegExp(Object.keys(h).join("|")+"|[̀-ͯ·ʾʼ]","gu"),m=(t,e="NFKD")=>t.normalize(e),v=t=>Array.from(t).reduce((t,e)=>t+y(e),""),y=t=>(t=m(t).toLowerCase().replace(f,t=>h[t]||""),m(t,"NFC"));const O=t=>{const e={},i=(t,i)=>{const s=e[t]||new Set,o=new RegExp("^"+n(s)+"$","iu");i.match(o)||(s.add(r(i)),e[t]=s)};for(let e of function*(t){for(const[e,i]of t)for(let t=e;t<=i;t++){let e=String.fromCharCode(t),i=v(e);i!=e.toLowerCase()&&(i.length>3||0!=i.length&&(yield{folded:i,composed:e,code_point:t}))}}(t))i(e.folded,e.folded),i(e.folded,e.composed);return e},b=t=>{const e=O(t),s={};let o=[];for(let t in e){let i=e[t];i&&(s[t]=n(i)),t.length>1&&o.push(r(t))}o.sort((t,e)=>e.length-t.length);const l=i(o);return u=new RegExp("^"+l,"u"),s},w=(t,e=1)=>(e=Math.max(e,t.length-1),i(c(t).map(t=>((t,e=1)=>{let i=0;return t=t.map(t=>(p[t]&&(i+=t.length),p[t]||t)),i>=e?s(t):""})(t,e)))),S=(t,e=!0)=>{let n=t.length>1?1:0;return i(t.map(t=>{let i=[];const o=e?t.length():t.length()-1;for(let e=0;e<o;e++)i.push(w(t.substrs[e]||"",n));return s(i)}))},I=(t,e)=>{for(const i of e){if(i.start!=t.start||i.end!=t.end)continue;if(i.substrs.join("")!==t.substrs.join(""))continue;let e=t.parts;const s=t=>{for(const i of e){if(i.start===t.start&&i.substr===t.substr)return!1;if(1!=t.length&&1!=i.length){if(t.start<i.start&&t.end>i.start)return!0;if(i.start<t.start&&i.end>t.start)return!0}}return!1};if(!(i.parts.filter(s).length>0))return!0}return!1};class A{parts;substrs;start;end;constructor(){this.parts=[],this.substrs=[],this.start=0,this.end=0}add(t){t&&(this.parts.push(t),this.substrs.push(t.substr),this.start=Math.min(t.start,this.start),this.end=Math.max(t.end,this.end))}last(){return this.parts[this.parts.length-1]}length(){return this.parts.length}clone(t,e){let i=new A,s=JSON.parse(JSON.stringify(this.parts)),n=s.pop();for(const t of s)i.add(t);let o=e.substr.substring(0,t-n.start),r=o.length;return i.add({start:n.start,end:n.start+r,length:r,substr:o}),i}}const C=t=>{void 0===p&&(p=b(d)),t=v(t);let e="",i=[new A];for(let s=0;s<t.length;s++){let n=t.substring(s).match(u);const o=t.substring(s,s+1),r=n?n[0]:null;let l=[],a=new Set;for(const t of i){const e=t.last();if(!e||1==e.length||e.end<=s)if(r){const e=r.length;t.add({start:s,end:s+e,length:e,substr:r}),a.add("1")}else t.add({start:s,end:s+1,length:1,substr:o}),a.add("2");else if(r){let i=t.clone(s,e);const n=r.length;i.add({start:s,end:s+n,length:n,substr:r}),l.push(i)}else a.add("3")}if(l.length>0){l=l.sort((t,e)=>t.length()-e.length());for(let t of l)I(t,i)||i.push(t)}else if(s>0&&1==a.size&&!a.has("3")){e+=S(i,!1);let t=new A;const s=i[0];s&&t.add(s.last()),i=[t]}}return e+=S(i,!0),e},_=(t,e)=>{if(t)return t[e]},x=(t,e)=>{if(t){for(var i,s=e.split(".");(i=s.shift())&&(t=t[i]););return t}},F=(t,e,i)=>{var s,n;return t?(t+="",null==e.regex||-1===(n=t.search(e.regex))?0:(s=e.string.length/t.length,0===n&&(s+=.5),s*i)):0},L=(t,e)=>{var i=t[e];if("function"==typeof i)return i;i&&!Array.isArray(i)&&(t[e]=[i])},k=(t,e)=>{if(Array.isArray(t))t.forEach(e);else for(var i in t)t.hasOwnProperty(i)&&e(t[i],i)},E=(t,e)=>"number"==typeof t&&"number"==typeof e?t>e?1:t<e?-1:0:(t=v(t+"").toLowerCase())>(e=v(e+"").toLowerCase())?1:e>t?-1:0;class T{items;settings;constructor(t,e){this.items=t,this.settings=e||{diacritics:!0}}tokenize(t,e,i){if(!t||!t.length)return[];const s=[],n=t.split(/\s+/);var o;return i&&(o=new RegExp("^("+Object.keys(i).map(r).join("|")+"):(.*)$")),n.forEach(t=>{let i,n=null,l=null;o&&(i=t.match(o))&&(n=i[1],t=i[2]),t.length>0&&(l=this.settings.diacritics?C(t)||null:r(t),l&&e&&(l="\\b"+l)),s.push({string:t,regex:l?new RegExp(l,"iu"):null,field:n})}),s}getScoreFunction(t,e){var i=this.prepareSearch(t,e);return this._getScoreFunction(i)}_getScoreFunction(t){const e=t.tokens,i=e.length;if(!i)return function(){return 0};const s=t.options.fields,n=t.weights,o=s.length,r=t.getAttrFn;if(!o)return function(){return 1};const l=1===o?function(t,e){const i=s[0].field;return F(r(e,i),t,n[i]||1)}:function(t,e){var i=0;if(t.field){const s=r(e,t.field);!t.regex&&s?i+=1/o:i+=F(s,t,1)}else k(n,(s,n)=>{i+=F(r(e,n),t,s)});return i/o};return 1===i?function(t){return l(e[0],t)}:"and"===t.options.conjunction?function(t){var s,n=0;for(let i of e){if((s=l(i,t))<=0)return 0;n+=s}return n/i}:function(t){var s=0;return k(e,e=>{s+=l(e,t)}),s/i}}getSortFunction(t,e){var i=this.prepareSearch(t,e);return this._getSortFunction(i)}_getSortFunction(t){var e,i=[];const s=this,n=t.options,o=!t.query&&n.sort_empty?n.sort_empty:n.sort;if("function"==typeof o)return o.bind(this);const r=function(e,i){return"$score"===e?i.score:t.getAttrFn(s.items[i.id],e)};if(o)for(let e of o)(t.query||"$score"!==e.field)&&i.push(e);if(t.query){e=!0;for(let t of i)if("$score"===t.field){e=!1;break}e&&i.unshift({field:"$score",direction:"desc"})}else i=i.filter(t=>"$score"!==t.field);return i.length?function(t,e){var s,n;for(let o of i){if(n=o.field,s=("desc"===o.direction?-1:1)*E(r(n,t),r(n,e)))return s}return 0}:null}prepareSearch(t,e){const i={};var s=Object.assign({},e);if(L(s,"sort"),L(s,"sort_empty"),s.fields){L(s,"fields");const t=[];s.fields.forEach(e=>{"string"==typeof e&&(e={field:e,weight:1}),t.push(e),i[e.field]="weight"in e?e.weight:1}),s.fields=t}return{options:s,query:t.toLowerCase().trim(),tokens:this.tokenize(t,s.respect_word_boundaries,i),total:0,items:[],weights:i,getAttrFn:s.nesting?x:_}}search(t,e){var i,s,n=this;s=this.prepareSearch(t,e),e=s.options,t=s.query;const o=e.score||n._getScoreFunction(s);t.length?k(n.items,(t,n)=>{i=o(t),(!1===e.filter||i>0)&&s.items.push({score:i,id:n})}):k(n.items,(t,e)=>{s.items.push({score:1,id:e})});const r=n._getSortFunction(s);return r&&s.items.sort(r),s.total=s.items.length,"number"==typeof e.limit&&(s.items=s.items.slice(0,e.limit)),s}}const P=t=>null==t?null:D(t),D=t=>"boolean"==typeof t?t?"1":"0":t+"",$=t=>(t+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),V=(t,e)=>{var i;return function(s,n){var o=this;i&&(o.loading=Math.max(o.loading-1,0),clearTimeout(i)),i=setTimeout(function(){i=null,o.loadedSearches[s]=!0,t.call(o,s,n)},e)}},j=(t,e,i)=>{var s,n=t.trigger,o={};for(s of(t.trigger=function(){var i=arguments[0];if(-1===e.indexOf(i))return n.apply(t,arguments);o[i]=arguments},i.apply(t,[]),t.trigger=n,e))s in o&&n.apply(t,o[s])},q=(t,e=!1)=>{t&&(t.preventDefault(),e&&t.stopPropagation())},N=(t,e,i,s)=>{t.addEventListener(e,i,s)},R=(t,e)=>!!e&&(!!e[t]&&1===(e.altKey?1:0)+(e.ctrlKey?1:0)+(e.shiftKey?1:0)+(e.metaKey?1:0)),H=(t,e)=>{const i=t.getAttribute("id");return i||(t.setAttribute("id",e),e)},M=t=>t.replace(/[\\"']/g,"\\$&"),z=(t,e)=>{e&&t.append(e)},B=(t,e)=>{if(Array.isArray(t))t.forEach(e);else for(var i in t)t.hasOwnProperty(i)&&e(t[i],i)},K=t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(G(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)},G=t=>"string"==typeof t&&t.indexOf("<")>-1,Q=(t,e)=>{var i=document.createEvent("HTMLEvents");i.initEvent(e,!0,!1),t.dispatchEvent(i)},W=(t,e)=>{Object.assign(t.style,e)},J=(t,...e)=>{var i=X(e);(t=Y(t)).map(t=>{i.map(e=>{t.classList.add(e)})})},U=(t,...e)=>{var i=X(e);(t=Y(t)).map(t=>{i.map(e=>{t.classList.remove(e)})})},X=t=>{var e=[];return B(t,t=>{"string"==typeof t&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},Y=t=>(Array.isArray(t)||(t=[t]),t),Z=(t,e,i)=>{if(!i||i.contains(t))for(;t&&t.matches;){if(t.matches(e))return t;t=t.parentNode}},tt=(t,e=0)=>e>0?t[t.length-1]:t[0],et=(t,e)=>{if(!t)return-1;e=e||t.nodeName;for(var i=0;t=t.previousElementSibling;)t.matches(e)&&i++;return i},it=(t,e)=>{B(e,(e,i)=>{null==e?t.removeAttribute(i):t.setAttribute(i,""+e)})},st=(t,e)=>{t.parentNode&&t.parentNode.replaceChild(e,t)},nt=(t,e)=>{if(null===e)return;if("string"==typeof e){if(!e.length)return;e=new RegExp(e,"i")}const i=t=>3===t.nodeType?(t=>{var i=t.data.match(e);if(i&&t.data.length>0){var s=document.createElement("span");s.className="highlight";var n=t.splitText(i.index);n.splitText(i[0].length);var o=n.cloneNode(!0);return s.appendChild(o),st(n,s),1}return 0})(t):((t=>{1!==t.nodeType||!t.childNodes||/(script|style)/i.test(t.tagName)||"highlight"===t.className&&"SPAN"===t.tagName||Array.from(t.childNodes).forEach(t=>{i(t)})})(t),0);i(t)},ot="undefined"!=typeof navigator&&/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey";var rt={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,clearAfterSelect:!1,highlight:!0,openOnFocus:!0,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,refreshThrottle:300,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:'<input type="text" autocomplete="off" size="1" />',copyClassesToDropdown:!1,placeholder:null,hidePlaceholder:null,shouldLoad:function(t){return t.length>0},render:{}};function lt(t,e){var i=Object.assign({},rt,e),s=i.dataAttr,n=i.labelField,o=i.valueField,r=i.disabledField,l=i.optgroupField,a=i.optgroupLabelField,c=i.optgroupValueField,d=t.tagName.toLowerCase(),p=t.getAttribute("placeholder")||t.getAttribute("data-placeholder");if(!p&&!i.allowEmptyOption){let e=t.querySelector('option[value=""]');e&&(p=e.textContent)}var u={placeholder:p,options:[],optgroups:[],items:[],maxItems:null};return"select"===d?(()=>{var e,d=u.options,p={},h=1;let g=0;var f=t=>{var e=Object.assign({},t.dataset),i=s&&e[s];return"string"==typeof i&&i.length&&(e=Object.assign(e,JSON.parse(i))),e},m=(t,e)=>{var s=P(t.value);if(null!=s&&(s||i.allowEmptyOption)){if(p.hasOwnProperty(s)){if(e){var a=p[s][l];a?Array.isArray(a)?a.push(e):p[s][l]=[a,e]:p[s][l]=e}}else{var c=f(t);c[n]=c[n]||t.textContent,c[o]=c[o]||s,c[r]=c[r]||t.disabled,c[l]=c[l]||e,c.$option=t,c.$order=c.$order||++g,p[s]=c,d.push(c)}t.selected&&u.items.push(s)}};u.maxItems=t.hasAttribute("multiple")?null:1,B(t.children,t=>{var i,s,n;"optgroup"===(e=t.tagName.toLowerCase())?((n=f(i=t))[a]=n[a]||i.getAttribute("label")||"",n[c]=n[c]||h++,n[r]=n[r]||i.disabled,n.$order=n.$order||++g,u.optgroups.push(n),s=n[c],B(i.children,t=>{m(t,s)})):"option"===e&&m(t)})})():(()=>{var e,r;const l=t.getAttribute(s);if(l)u.options=JSON.parse(l),B(u.options,t=>{u.items.push(t[o])});else{var a=null!==(r=null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.trim())&&void 0!==r?r:"";if(!i.allowEmptyOption&&!a.length)return;const s=a.split(i.delimiter);B(s,t=>{const e={};e[n]=t,e[o]=t,u.options.push(e)}),u.items=s}})(),Object.assign({},rt,u,e)}var at=0;class ct extends(function(t){return t.plugins={},class extends t{constructor(){super(...arguments),this.plugins={names:[],settings:{},requested:{},loaded:{}}}static define(e,i){t.plugins[e]={name:e,fn:i}}initializePlugins(t){var e,i;const s=this,n=[];if(Array.isArray(t))t.forEach(t=>{"string"==typeof t?n.push(t):(s.plugins.settings[t.name]=t.options,n.push(t.name))});else if(t)for(e in t)t.hasOwnProperty(e)&&(s.plugins.settings[e]=t[e],n.push(e));for(;i=n.shift();)s.require(i)}loadPlugin(e){var i=this,s=i.plugins,n=t.plugins[e];if(!t.plugins.hasOwnProperty(e))throw new Error('Unable to find "'+e+'" plugin');s.requested[e]=!0,s.loaded[e]=n.fn.apply(i,[i.plugins.settings[e]||{}]),s.names.push(e)}require(t){var e=this,i=e.plugins;if(!e.plugins.loaded.hasOwnProperty(t)){if(i.requested[t])throw new Error('Plugin has circular dependency ("'+t+'")');e.loadPlugin(t)}return i.loaded[t]}}}(e)){constructor(t,e){var i;super(),this.order=0,this.isOpen=!1,this.isDisabled=!1,this.isReadOnly=!1,this.isInvalid=!1,this.isValid=!0,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.isDropdownContentStale=!0,this.ignoreFocus=!1,this.ignoreHover=!1,this.hasOptions=!1,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.refreshTimeout=null,at++;var s=K(t);if(s.tomselect)throw new Error("Tom Select already initialized on this element");s.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(s,null)).getPropertyValue("direction");const n=lt(s,e);this.settings=n,this.input=s,this.tabIndex=s.tabIndex||0,this.is_select_tag="select"===s.tagName.toLowerCase(),this.rtl=/rtl/i.test(i),this.inputId=H(s,"tomselect-"+at),this.isRequired=s.required,this.sifter=new T(this.options,{diacritics:n.diacritics}),n.mode=n.mode||(1===n.maxItems?"single":"multi"),"boolean"!=typeof n.hideSelected&&(n.hideSelected="multi"===n.mode),"boolean"!=typeof n.hidePlaceholder&&(n.hidePlaceholder="multi"!==n.mode);var o=n.createFilter;"function"!=typeof o&&("string"==typeof o&&(o=new RegExp(o)),o instanceof RegExp?n.createFilter=t=>o.test(t):n.createFilter=t=>this.settings.duplicates||!this.options[t]),this.initializePlugins(n.plugins),this.setupCallbacks(),this.setupTemplates();const r=K("<div>"),l=K("<div>"),a=this._render("dropdown"),c=K('<div role="listbox" tabindex="-1">'),d=this.input.getAttribute("class")||"",p=n.mode;var u;if(J(r,n.wrapperClass,d,p),J(l,n.controlClass),z(r,l),J(a,n.dropdownClass,p),n.copyClassesToDropdown&&J(a,d),J(c,n.dropdownContentClass),z(a,c),K(n.dropdownParent||r).appendChild(a),G(n.controlInput)){u=K(n.controlInput);B(["autocorrect","autocapitalize","autocomplete","spellcheck","aria-label"],t=>{s.getAttribute(t)&&it(u,{[t]:s.getAttribute(t)})}),u.tabIndex=-1,l.appendChild(u),this.focus_node=u}else n.controlInput?(u=K(n.controlInput),this.focus_node=u):(u=K("<input/>"),this.focus_node=l);this.wrapper=r,this.dropdown=a,this.dropdown_content=c,this.control=l,this.control_input=u,this.setup()}setup(){const t=this,e=t.settings,i=t.control_input,s=t.dropdown,n=t.dropdown_content,o=t.wrapper,l=t.control,a=t.input,c=t.focus_node,d={passive:!0},p=t.inputId+"-ts-dropdown";it(n,{id:p}),it(c,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":p});const u=H(c,t.inputId+"-ts-control"),h="label[for='"+(t=>t.replace(/['"\\]/g,"\\$&"))(t.inputId)+"']",g=document.querySelector(h),f=t.focus.bind(t);if(g){N(g,"click",f),it(g,{for:u});const e=H(g,t.inputId+"-ts-label");it(c,{"aria-labelledby":e}),it(n,{"aria-labelledby":e})}if(o.style.width=a.style.width,o.style.minWidth=a.style.minWidth,o.style.maxWidth=a.style.maxWidth,t.plugins.names.length){const e="plugin-"+t.plugins.names.join(" plugin-");J([o,s],e)}(null===e.maxItems||e.maxItems>1)&&t.is_select_tag&&it(a,{multiple:"multiple"}),e.placeholder&&it(i,{placeholder:e.placeholder}),!e.splitOn&&e.delimiter&&(e.splitOn=new RegExp("\\s*"+r(e.delimiter)+"+\\s*")),e.load&&e.loadThrottle&&(e.load=V(e.load,e.loadThrottle)),N(s,"mousemove",()=>{t.ignoreHover=!1}),N(s,"mouseenter",e=>{var i=Z(e.target,"[data-selectable]",s);i&&t.onOptionHover(e,i)},{capture:!0}),N(s,"click",e=>{const i=Z(e.target,"[data-selectable]");i&&(t.onOptionSelect(e,i),q(e,!0))}),N(l,"click",e=>{var s=Z(e.target,"[data-ts-item]",l);s&&t.onItemSelect(e,s)?q(e,!0):""==i.value&&(t.onClick(),q(e,!0))}),N(c,"keydown",e=>t.onKeyDown(e)),N(i,"keypress",e=>t.onKeyPress(e)),N(i,"input",e=>t.onInput(e)),N(c,"blur",e=>t.onBlur(e)),N(c,"focus",e=>t.onFocus(e)),N(i,"paste",e=>t.onPaste(e));const m=e=>{const n=e.composedPath()[0];if(!o.contains(n)&&!s.contains(n))return t.isFocused&&t.blur(),void t.inputState();n==i&&t.isOpen?e.stopPropagation():q(e,!0)},v=()=>{t.isOpen&&t.positionDropdown()},y=()=>{t.isValid&&(t.isValid=!1,t.isInvalid=!0,t.refreshState())};N(a,"invalid",y),N(document,"mousedown",m),N(window,"scroll",v,d),N(window,"resize",v,d),this._destroy=()=>{a.removeEventListener("invalid",y),document.removeEventListener("mousedown",m),window.removeEventListener("scroll",v),window.removeEventListener("resize",v),g&&g.removeEventListener("click",f)},this.revertSettings={innerHTML:a.innerHTML,tabIndex:a.tabIndex},a.tabIndex=-1,a.insertAdjacentElement("afterend",t.wrapper),t.sync(!1),e.items=[],delete e.optgroups,delete e.options,t.refreshItems(),t.close(!1),t.inputState(),t.isSetup=!0,t.on("change",this.onChange),J(a,"tomselected","ts-hidden-accessible"),t.trigger("initialize"),!0===e.preload&&t.preload()}setupOptions(t=[],e=[]){this.addOptions(t),B(e,t=>{this.registerOptionGroup(t)})}setupTemplates(){var t=this,e=t.settings.labelField,i=t.settings.optgroupLabelField,s={optgroup:t=>{let e=document.createElement("div");return e.className="optgroup",e.appendChild(t.options),e},optgroup_header:(t,e)=>'<div class="optgroup-header">'+e(t[i])+"</div>",option:(t,i)=>"<div>"+i(t[e])+"</div>",item:(t,i)=>"<div>"+i(t[e])+"</div>",option_create:(t,e)=>'<div class="create">Add <strong>'+e(t.input)+"</strong>&hellip;</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"};t.settings.render=Object.assign({},s,t.settings.render)}setupCallbacks(){var t,e,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(t in i)(e=this.settings[i[t]])&&this.on(t,e)}sync(t=!0){const e=this,i=t?lt(e.input,{delimiter:e.settings.delimiter,allowEmptyOption:e.settings.allowEmptyOption}):e.settings;e.setupOptions(i.options,i.optgroups),e.setValue(i.items||[],!0),e.input.disabled?e.disable():e.input.readOnly?e.setReadOnly(!0):e.enable(),e.lastQuery=null}onClick(){var t=this;if(t.activeItems.length>0)return t.clearActiveItems(),void t.focus();t.isFocused&&t.isOpen?t.blur():t.focus()}onMouseDown(){}onChange(){Q(this.input,"input"),Q(this.input,"change")}onPaste(t){var e=this;e.isInputHidden||e.isLocked?q(t):e.settings.splitOn&&setTimeout(()=>{var t=e.inputValue();if(t.match(e.settings.splitOn)){var i=t.trim().split(e.settings.splitOn);B(i,t=>{P(t)&&(this.options[t]?e.addItem(t):e.createItem(t))})}},0)}onKeyPress(t){var e=this;if(!e.isLocked){var i=String.fromCharCode(t.keyCode||t.which);return e.settings.create&&"multi"===e.settings.mode&&i===e.settings.delimiter?(e.createItem(),void q(t)):void 0}q(t)}onKeyDown(t){var e=this;if(e.ignoreHover=!0,e.isLocked)9!==t.keyCode&&q(t);else{switch(t.keyCode){case 65:if(R(ot,t)&&""==e.control_input.value)return q(t),void e.selectAll();break;case 27:return e.isOpen&&(q(t,!0),e.close()),void e.clearActiveItems();case 40:if(!e.isOpen&&e.hasOptions)e.open();else if(e.activeOption){let t=e.getAdjacent(e.activeOption,1);t&&e.setActiveOption(t)}return void q(t);case 38:if(e.activeOption){let t=e.getAdjacent(e.activeOption,-1);t&&e.setActiveOption(t)}return void q(t);case 13:return void(e.canSelect(e.activeOption)?(e.onOptionSelect(t,e.activeOption),q(t)):(e.settings.create&&e.createItem()||document.activeElement==e.control_input&&e.isOpen)&&q(t));case 37:return void e.advanceSelection(-1,t);case 39:return void e.advanceSelection(1,t);case 9:return void(e.settings.selectOnTab&&(e.canSelect(e.activeOption)?(e.onOptionSelect(t,e.activeOption),q(t)):e.settings.create&&e.createItem()&&q(t)));case 8:case 46:return void e.deleteSelection(t)}e.isInputHidden&&!R(ot,t)&&q(t)}}onInput(t){if(this.isLocked)return;const e=this.inputValue();this.lastValue!==e&&(this.lastValue=e,""!=e?(this.refreshTimeout&&window.clearTimeout(this.refreshTimeout),this.refreshTimeout=((t,e)=>e>0?window.setTimeout(t,e):(t.call(null),null))(()=>{this.refreshTimeout=null,this._onInput()},this.settings.refreshThrottle)):this._onInput())}_onInput(){const t=this.lastValue;this.settings.shouldLoad.call(this,t)&&this.load(t),this.refreshOptions(),this.trigger("type",t)}onOptionHover(t,e){this.ignoreHover||this.setActiveOption(e,!1)}onFocus(t){var e=this,i=e.isFocused;if(e.isDisabled||e.isReadOnly)return e.blur(),void q(t);e.ignoreFocus||(e.isFocused=!0,"focus"===e.settings.preload&&e.preload(),i||e.trigger("focus"),e.activeItems.length||(e.inputState(),e.refreshOptions(!!e.settings.openOnFocus)),e.refreshState())}onBlur(t){if(!1!==document.hasFocus()){var e=this;if(e.isFocused){e.isFocused=!1,e.ignoreFocus=!1;var i=()=>{e.close(),e.setActiveItem(),e.setCaret(e.items.length),e.trigger("blur")};e.settings.create&&e.settings.createOnBlur?e.createItem(null,i):i()}}}onOptionSelect(t,e){var i,s=this;e.parentElement&&e.parentElement.matches("[data-disabled]")||(e.classList.contains("create")?s.createItem(null,()=>{s.settings.closeAfterSelect?s.close():s.settings.clearAfterSelect&&s.setTextboxValue()}):void 0!==(i=e.dataset.value)&&(s.isDropdownContentStale=s.settings.hideSelected,s.addItem(i),s.settings.closeAfterSelect?s.close():s.settings.clearAfterSelect&&s.setTextboxValue(),!s.settings.hideSelected&&t.type&&/click/.test(t.type)&&s.setActiveOption(e)))}canSelect(t){return!!(this.isOpen&&t&&this.dropdown_content.contains(t))}onItemSelect(t,e){var i=this;return!i.isLocked&&"multi"===i.settings.mode&&(q(t),i.setActiveItem(e,t),!0)}canLoad(t){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(t)}load(t){const e=this;if(!e.canLoad(t))return;J(e.wrapper,e.settings.loadingClass),e.loading++;const i=e.loadCallback.bind(e);e.settings.load.call(e,t,i)}loadCallback(t,e){const i=this;i.loading=Math.max(i.loading-1,0),i.isDropdownContentStale=!0,i.clearActiveOption(),i.setupOptions(t,e),i.refreshOptions(i.isFocused&&!i.isInputHidden),i.loading||U(i.wrapper,i.settings.loadingClass),i.trigger("load",t,e)}preload(){var t=this.wrapper.classList;t.contains("preloaded")||(t.add("preloaded"),this.load(""))}setTextboxValue(t=""){var e=this.control_input;e.value!==t&&(e.value=t,Q(e,"update"),this.lastValue=t)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(t,e){j(this,e?[]:["change"],()=>{this.clear(e),this.addItems(t,e)})}setMaxItems(t){0===t&&(t=null),this.settings.maxItems=t,this.refreshState()}setActiveItem(t,e){var i,s,n,o,r,l,a=this;if("single"!==a.settings.mode){if(!t)return a.clearActiveItems(),void(a.isFocused&&a.inputState());if("click"===(i=e&&e.type.toLowerCase())&&R("shiftKey",e)&&a.activeItems.length){for(l=a.getLastActive(),(n=Array.prototype.indexOf.call(a.control.children,l))>(o=Array.prototype.indexOf.call(a.control.children,t))&&(r=n,n=o,o=r),s=n;s<=o;s++)t=a.control.children[s],-1===a.activeItems.indexOf(t)&&a.setActiveItemClass(t);q(e)}else"click"===i&&R(ot,e)||"keydown"===i&&R("shiftKey",e)?t.classList.contains("active")?a.removeActiveItem(t):a.setActiveItemClass(t):(a.clearActiveItems(),a.setActiveItemClass(t));a.inputState(),a.isFocused||a.focus()}}setActiveItemClass(t){const e=this,i=e.control.querySelector(".last-active");i&&U(i,"last-active"),J(t,"active last-active"),e.trigger("item_select",t),-1==e.activeItems.indexOf(t)&&e.activeItems.push(t)}removeActiveItem(t){var e=this.activeItems.indexOf(t);this.activeItems.splice(e,1),U(t,"active")}clearActiveItems(){U(this.activeItems,"active"),this.activeItems=[]}setActiveOption(t,e=!0){t!==this.activeOption&&(this.clearActiveOption(),t&&(this.activeOption=t,it(this.focus_node,{"aria-activedescendant":t.getAttribute("id")}),it(t,{"aria-selected":"true"}),J(t,"active"),e&&this.scrollToOption(t)))}scrollToOption(t,e){if(!t)return;const i=this.dropdown_content,s=i.clientHeight,n=i.scrollTop||0,o=t.offsetHeight,r=t.getBoundingClientRect().top-i.getBoundingClientRect().top+n;r+o>s+n?this.scroll(r-s+o,e):r<n&&this.scroll(r,e)}scroll(t,e){const i=this.dropdown_content;e&&(i.style.scrollBehavior=e),i.scrollTop=t,i.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(U(this.activeOption,"active"),it(this.activeOption,{"aria-selected":null})),this.activeOption=null,it(this.focus_node,{"aria-activedescendant":null})}selectAll(){const t=this;if("single"===t.settings.mode)return;const e=t.controlChildren();e.length&&(t.inputState(),t.close(),t.activeItems=e,B(e,e=>{t.setActiveItemClass(e)}))}inputState(){var t=this;t.control.contains(t.control_input)&&(it(t.control_input,{placeholder:t.settings.placeholder}),t.activeItems.length>0||!t.isFocused&&t.settings.hidePlaceholder&&t.items.length>0?(t.setTextboxValue(),t.isInputHidden=!0):(t.settings.hidePlaceholder&&t.items.length>0&&it(t.control_input,{placeholder:""}),t.isInputHidden=!1),t.wrapper.classList.toggle("input-hidden",t.isInputHidden))}inputValue(){return this.control_input.value.trim()}focus(){var t=this;if(t.isDisabled||t.isReadOnly)return;t.ignoreFocus=!0;const e=this.control_input.offsetWidth?this.control_input:this.focus_node;e.focus(),setTimeout(()=>{t.ignoreFocus=!1;e.getRootNode().activeElement===e&&this.onFocus()},0)}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(t){return this.sifter.getScoreFunction(t,this.getSearchOptions())}getSearchOptions(){var t=this.settings,e=t.sortField;return"string"==typeof t.sortField&&(e=[{field:t.sortField}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}}search(t){var e,i,s=this,n=this.getSearchOptions();if(s.settings.score&&"function"!=typeof(i=s.settings.score.call(s,t)))throw new Error('Tom Select "score" setting must be a function that returns a function');return s.isDropdownContentStale||t!==s.lastQuery?(s.lastQuery=t,/(.)\1{15,}/.test(t)&&(t=""),e=s.sifter.search(t,Object.assign(n,{score:i})),s.currentResults=e):e=Object.assign({},s.currentResults),s.settings.hideSelected&&(e.items=e.items.filter(t=>{let e=P(t.id);return!(null!==e&&-1!==s.items.indexOf(e))})),e}refreshOptions(t=!0){var e,i,s,n,o,r,l,a,c,d;const p={},u=[];var h=this,g=h.inputValue();const f=g===h.lastQuery||""==g&&null==h.lastQuery;var m=h.search(g),v=null,y=h.settings.shouldOpen||!1,O=h.dropdown_content;f&&(v=h.activeOption)&&(c=v.closest("[data-group]")),n=m.items.length,"number"==typeof h.settings.maxOptions&&(n=Math.min(n,h.settings.maxOptions)),n>0&&(y=!0);const b=(t,e)=>{let i=p[t];if(void 0!==i){let t=u[i];if(void 0!==t)return[i,t.fragment]}let s=document.createDocumentFragment();return i=u.length,u.push({fragment:s,order:e,optgroup:t}),[i,s]};for(e=0;e<n;e++){let t=m.items[e];if(!t)continue;let n=t.id,l=h.options[n];if(void 0===l)continue;let a=D(n),d=h.getOption(a,!0);for(h.settings.hideSelected||d.classList.toggle("selected",h.items.includes(a)),o=l[h.settings.optgroupField]||"",i=0,s=(r=Array.isArray(o)?o:[o])&&r.length;i<s;i++){o=r[i];let t=l.$order,e=h.optgroups[o];var w;if(void 0===e&&"function"==typeof h.settings.optionGroupRegister)(w=h.settings.optionGroupRegister.apply(h,[o]))&&h.registerOptionGroup(w);e=h.optgroups[o],void 0===e?o="":t=e.$order;const[s,a]=b(o,t);i>0&&(d=d.cloneNode(!0),it(d,{id:l.$id+"-clone-"+i,"aria-selected":null}),d.classList.add("ts-cloned"),U(d,"active"),h.activeOption&&h.activeOption.dataset.value==n&&c&&c.dataset.group===o.toString()&&(v=d)),a.appendChild(d),""!=o&&(p[o]=s)}}var S;h.settings.lockOptgroupOrder&&u.sort((t,e)=>t.order-e.order),l=document.createDocumentFragment(),B(u,t=>{let e=t.fragment,i=t.optgroup;if(!e||!e.children.length)return;let s=h.optgroups[i];if(void 0!==s){let t=document.createDocumentFragment(),i=h.render("optgroup_header",s);z(t,i),z(t,e);let n=h.render("optgroup",{group:s,options:t});z(l,n)}else z(l,e)}),O.innerHTML="",z(O,l),h.isDropdownContentStale=!1,h.settings.highlight&&(S=O.querySelectorAll("span.highlight"),Array.prototype.forEach.call(S,function(t){var e=t.parentNode;e.replaceChild(t.firstChild,t),e.normalize()}),m.query.length&&m.tokens.length&&B(m.tokens,t=>{nt(O,t.regex)}));var I=t=>{let e=h.render(t,{input:g});return e&&(y=!0,O.insertBefore(e,O.firstChild)),e};if(h.loading?I("loading"):h.settings.shouldLoad.call(h,g)?0===m.items.length&&I("no_results"):I("not_loading"),(a=h.canCreate(g))&&(d=I("option_create")),h.hasOptions=m.items.length>0||a,y){if(m.items.length>0){if(v||"single"!==h.settings.mode||null==h.items[0]||(v=h.getOption(h.items[0])),!O.contains(v)){let t=0;d&&!h.settings.addPrecedence&&(t=1),v=h.selectable()[t]}}else d&&(v=d);t&&!h.isOpen&&(h.open(),h.scrollToOption(v,"auto")),h.setActiveOption(v)}else h.clearActiveOption(),t&&h.isOpen&&h.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(t,e=!1){const i=this;if(Array.isArray(t))return i.addOptions(t,e),!1;const s=P(t[i.settings.valueField]);return null===s||i.options.hasOwnProperty(s)?(i.updateOption(t[i.settings.valueField],t),!1):(t.$order=t.$order||++i.order,t.$id=i.inputId+"-opt-"+t.$order,i.options[s]=t,i.isDropdownContentStale=!0,e&&(i.userOptions[s]=e,i.trigger("option_add",s,t)),s)}addOptions(t,e=!1){B(t,t=>{this.addOption(t,e)})}registerOption(t){return this.addOption(t)}registerOptionGroup(t){var e=P(t[this.settings.optgroupValueField]);return null!==e&&(t.$order=t.$order||++this.order,this.optgroups[e]=t,e)}addOptionGroup(t,e){var i;e[this.settings.optgroupValueField]=t,(i=this.registerOptionGroup(e))&&this.trigger("optgroup_add",i,e)}removeOptionGroup(t){this.optgroups.hasOwnProperty(t)&&(delete this.optgroups[t],this.clearCache(),this.trigger("optgroup_remove",t))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(t,e){const i=this;var s,n;const o=P(t),r=P(e[i.settings.valueField]);if(null===o)return;const l=i.options[o];if(null==l)return;if("string"!=typeof r)throw new Error("Value must be set in option data");const a=i.getOption(o),c=i.getItem(o);if(e.$order=e.$order||l.$order,delete i.options[o],i.uncacheValue(r),i.options[r]=e,a){if(i.dropdown_content.contains(a)){const t=i._render("option",e);st(a,t),i.activeOption===a&&i.setActiveOption(t)}a.remove()}c&&(-1!==(n=i.items.indexOf(o))&&i.items.splice(n,1,r),s=i._render("item",e),c.classList.contains("active")&&J(s,"active"),st(c,s)),i.isDropdownContentStale=!0}removeOption(t,e){const i=this;t=D(t),i.uncacheValue(t),delete i.userOptions[t],delete i.options[t],i.isDropdownContentStale=!0,i.trigger("option_remove",t),i.removeItem(t,e)}clearOptions(t){const e=(t||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const i={};B(this.options,(t,s)=>{e(t,s)&&(i[s]=t)}),this.options=this.sifter.items=i,this.isDropdownContentStale=!0,this.trigger("option_clear")}clearFilter(t,e){return this.items.indexOf(e)>=0}getOption(t,e=!1){const i=P(t);if(null===i)return null;const s=this.options[i];if(null!=s){if(s.$div)return s.$div;if(e)return this._render("option",s)}return null}getAdjacent(t,e,i="option"){var s;if(!t)return null;s="item"==i?this.controlChildren():this.dropdown_content.querySelectorAll("[data-selectable]");for(let i=0;i<s.length;i++)if(s[i]==t)return e>0?s[i+1]:s[i-1];return null}getItem(t){if("object"==typeof t)return t;var e=P(t);return null!==e?this.control.querySelector(`[data-value="${M(e)}"]`):null}addItems(t,e){var i=this,s=Array.isArray(t)?t:[t];const n=(s=s.filter(t=>-1===i.items.indexOf(t)))[s.length-1];s.forEach(t=>{i.isPending=t!==n,i.addItem(t,e)})}addItem(t,e){j(this,e?[]:["change","dropdown_close"],()=>{var i,s;const n=this,o=n.settings.mode,r=P(t);if((!r||-1===n.items.indexOf(r)||("single"===o&&n.close(),"single"!==o&&n.settings.duplicates))&&null!==r&&n.options.hasOwnProperty(r)&&("single"===o&&n.clear(e),"multi"!==o||!n.isFull())){if(i=n._render("item",n.options[r]),n.control.contains(i)&&(i=i.cloneNode(!0)),s=n.isFull(),n.items.splice(n.caretPos,0,r),n.insertAtCaret(i),n.isSetup){if(!n.isPending&&n.settings.hideSelected){let t=n.getOption(r),e=n.getAdjacent(t,1);e&&n.setActiveOption(e)}n.settings.clearAfterSelect&&n.setTextboxValue(),n.isPending||n.settings.closeAfterSelect||n.refreshOptions(n.isFocused&&"single"!==o),0!=n.settings.closeAfterSelect&&n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",r,i),n.isPending||n.updateOriginalInput({silent:e})}(!n.isPending||!s&&n.isFull())&&(n.inputState(),n.refreshState())}})}removeItem(t=null,e){const i=this;if(!(t=i.getItem(t)))return;var s,n;const o=t.dataset.value;s=et(t),t.remove(),t.classList.contains("active")&&(n=i.activeItems.indexOf(t),i.activeItems.splice(n,1),U(t,"active")),i.items.splice(s,1),i.isDropdownContentStale=!0,!i.settings.persist&&i.userOptions.hasOwnProperty(o)&&i.removeOption(o,e),s<i.caretPos&&i.setCaret(i.caretPos-1),i.updateOriginalInput({silent:e}),i.refreshState(),i.positionDropdown(),i.trigger("item_remove",o,t)}createItem(t=null,e=()=>{}){3===arguments.length&&(e=arguments[2]),"function"!=typeof e&&(e=()=>{});var i,s=this,n=s.caretPos;if(t=t||s.inputValue(),!s.canCreate(t)){return P(t)&&this.options[t]&&s.addItem(t),e(),!1}s.lock();var o=!1,r=t=>{if(s.unlock(),!t||"object"!=typeof t)return e();var i=P(t[s.settings.valueField]);if("string"!=typeof i)return e();s.setTextboxValue(),s.addOption(t,!0),s.setCaret(n),s.addItem(i),e(t),o=!0};return i="function"==typeof s.settings.create?s.settings.create.call(this,t,r):{[s.settings.labelField]:t,[s.settings.valueField]:t},o||r(i),!0}refreshItems(){var t=this;t.isDropdownContentStale=!0,t.isSetup&&t.addItems(t.items),t.updateOriginalInput(),t.refreshState()}refreshState(){const t=this;t.refreshValidityState();const e=t.isFull(),i=t.isLocked;t.wrapper.classList.toggle("rtl",t.rtl);const s=t.wrapper.classList;var n;s.toggle("focus",t.isFocused),s.toggle("disabled",t.isDisabled),s.toggle("readonly",t.isReadOnly),s.toggle("required",t.isRequired),s.toggle("invalid",!t.isValid),s.toggle("locked",i),s.toggle("full",e),s.toggle("input-active",t.isFocused&&!t.isInputHidden),s.toggle("dropdown-active",t.isOpen),s.toggle("has-options",(n=t.options,0===Object.keys(n).length)),s.toggle("has-items",t.items.length>0)}refreshValidityState(){var t=this;t.input.validity&&(t.isValid=t.input.validity.valid,t.isInvalid=!t.isValid)}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(t={}){const e=this;var i,s;const n=e.input.querySelector('option[value=""]');if(e.is_select_tag){const o=[],r=e.input.querySelectorAll("option:checked").length;function l(t,i,s){return t||(t=K('<option value="'+$(i)+'">'+$(s)+"</option>")),t!=n&&e.input.append(t),o.push(t),(t!=n||r>0)&&(t.selected=!0),t}e.input.querySelectorAll("option:checked").forEach(t=>{t.selected=!1}),0==e.items.length&&"single"==e.settings.mode?l(n,"",""):e.items.forEach(t=>{if(i=e.options[t],s=i[e.settings.labelField]||"",o.includes(i.$option)){l(e.input.querySelector(`option[value="${M(t)}"]:not(:checked)`),t,s)}else i.$option=l(i.$option,t,s)})}else e.input.value=e.getValue();e.isSetup&&(t.silent||e.trigger("change",e.getValue()))}open(){var t=this;t.isLocked||t.isOpen||"multi"===t.settings.mode&&t.isFull()||(t.isOpen=!0,it(t.focus_node,{"aria-expanded":"true"}),t.refreshState(),W(t.dropdown,{visibility:"hidden",display:"block"}),t.positionDropdown(),W(t.dropdown,{visibility:"visible",display:"block"}),t.focus(),t.trigger("dropdown_open",t.dropdown))}close(t=!0){var e=this,i=e.isOpen;t&&(e.setTextboxValue(),"single"===e.settings.mode&&e.items.length&&e.inputState()),e.isOpen=!1,it(e.focus_node,{"aria-expanded":"false"}),W(e.dropdown,{display:"none"}),e.settings.hideSelected&&e.clearActiveOption(),e.refreshState(),i&&e.trigger("dropdown_close",e.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var t=this.control,e=t.getBoundingClientRect(),i=t.offsetHeight+e.top+window.scrollY,s=e.left+window.scrollX;W(this.dropdown,{width:e.width+"px",top:i+"px",left:s+"px"})}}clear(t){var e=this;if(e.items.length){var i=e.controlChildren();B(i,t=>{e.removeItem(t,!0)}),e.inputState(),t||e.updateOriginalInput(),e.trigger("clear")}}insertAtCaret(t){const e=this,i=e.caretPos,s=e.control;s.insertBefore(t,s.children[i]||null),e.setCaret(i+1)}deleteSelection(t){var e,i,s,n,o,r=this;e=t&&8===t.keyCode?-1:1,i={start:(o=r.control_input).selectionStart||0,length:(o.selectionEnd||0)-(o.selectionStart||0)};const l=[];if(r.activeItems.length)n=tt(r.activeItems,e),s=et(n),e>0&&s++,B(r.activeItems,t=>l.push(t));else if((r.isFocused||"single"===r.settings.mode)&&r.items.length){const t=r.controlChildren();let s;e<0&&0===i.start&&0===i.length?s=t[r.caretPos-1]:e>0&&i.start===r.inputValue().length&&(s=t[r.caretPos]),void 0!==s&&l.push(s)}if(!r.shouldDelete(l,t))return!1;for(q(t,!0),void 0!==s&&r.setCaret(s);l.length;)r.removeItem(l.pop());return r.inputState(),r.positionDropdown(),r.refreshOptions(!1),!0}shouldDelete(t,e){const i=t.map(t=>t.dataset.value);return!(!i.length||"function"==typeof this.settings.onDelete&&!1===this.settings.onDelete.call(this,i,e))}advanceSelection(t,e){var i,s,n=this;n.rtl&&(t*=-1),n.inputValue().length||(R(ot,e)||R("shiftKey",e)?(s=(i=n.getLastActive(t))?i.classList.contains("active")?n.getAdjacent(i,t,"item"):i:t>0?n.control_input.nextElementSibling:n.control_input.previousElementSibling)&&(s.classList.contains("active")&&n.removeActiveItem(i),n.setActiveItemClass(s)):n.moveCaret(t))}moveCaret(t){}getLastActive(t){let e=this.control.querySelector(".last-active");if(e)return e;var i=this.control.querySelectorAll(".active");return i?tt(i,t):void 0}setCaret(t){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(!0)}unlock(){this.setLocked(!1)}setLocked(t=this.isReadOnly||this.isDisabled){this.isLocked=t,this.refreshState()}disable(){this.setDisabled(!0),this.close()}enable(){this.setDisabled(!1)}setDisabled(t){this.focus_node.tabIndex=t?-1:this.tabIndex,this.isDisabled=t,this.input.disabled=t,this.control_input.disabled=t,this.setLocked()}setReadOnly(t){this.isReadOnly=t,this.input.readOnly=t,this.control_input.readOnly=t,this.setLocked()}destroy(){var t=this,e=t.revertSettings;t.trigger("destroy"),t.off(),t.wrapper.remove(),t.dropdown.remove(),t.input.innerHTML=e.innerHTML,t.input.tabIndex=e.tabIndex,U(t.input,"tomselected","ts-hidden-accessible"),t._destroy(),delete t.input.tomselect}render(t,e){var i,s;const n=this;if("function"!=typeof this.settings.render[t])return null;if(!(s=n.settings.render[t].call(this,e,$)))return null;if(s=K(s),"option"===t||"option_create"===t?e[n.settings.disabledField]?it(s,{"aria-disabled":"true"}):it(s,{"data-selectable":""}):"optgroup"===t&&(i=e.group[n.settings.optgroupValueField],it(s,{"data-group":i}),e.group[n.settings.disabledField]&&it(s,{"data-disabled":""})),"option"===t||"item"===t){const i=D(e[n.settings.valueField]);it(s,{"data-value":i}),"item"===t?(J(s,n.settings.itemClass),it(s,{"data-ts-item":""})):(J(s,n.settings.optionClass),it(s,{role:"option",id:e.$id}),e.$div=s,n.options[i]=e)}return s}_render(t,e){const i=this.render(t,e);if(null==i)throw"HTMLElement expected";return i}clearCache(){B(this.options,t=>{t.$div&&(t.$div.remove(),delete t.$div)})}uncacheValue(t){const e=this.getOption(t);e&&e.remove()}canCreate(t){return this.settings.create&&t.length>0&&this.settings.createFilter.call(this,t)}hook(t,e,i){var s=this,n=s[e];s[e]=function(){var e,o;return"after"===t&&(e=n.apply(s,arguments)),o=i.apply(s,arguments),"instead"===t?o:("before"===t&&(e=n.apply(s,arguments)),e)}}}const dt=t=>"string"==typeof t&&t.indexOf("<")>-1;const pt=(t,e=!1)=>{t&&(t.preventDefault(),e&&t.stopPropagation())},ut=(t,e,i,s)=>{t.addEventListener(e,i,s)},ht=t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(gt(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)},gt=t=>"string"==typeof t&&t.indexOf("<")>-1;ct.define("clear_button",function(t){const e=this,i=Object.assign({className:"clear-button",title:"Clear All",role:"button",tabindex:0,html:t=>`<div class="${t.className}" title="${t.title}" role="${t.role}" tabindex="${t.tabindex}">&times;</div>`},t);e.on("initialize",()=>{var t=(t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(dt(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)})(i.html(i));t.addEventListener("click",t=>{e.isLocked||(e.clear(),"single"===e.settings.mode&&e.settings.allowEmptyOption&&e.addItem(""),e.refreshOptions(!1),t.preventDefault(),t.stopPropagation())}),e.control.appendChild(t)})}),ct.define("remove_button",function(t){const e=Object.assign({label:"&times;",title:"Remove",className:"remove",append:!0},t);var i=this;if(e.append){var s='<a href="javascript:void(0)" class="'+e.className+'" tabindex="-1" title="'+((e.title+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")+'">')+e.label+"</a>";i.hook("after","setupTemplates",()=>{var t=i.settings.render.item;i.settings.render.item=(e,n)=>{var o=ht(t.call(i,e,n)),r=ht(s);return o.appendChild(r),ut(r,"mousedown",t=>{pt(t,!0)}),ut(r,"click",t=>{i.isLocked||(pt(t,!0),i.isLocked||i.shouldDelete([o],t)&&(i.removeItem(o),i.refreshOptions(!1),i.inputState()))}),o}})}});export{ct as default};
1
+ function t(t,e){t.split(/\s+/).forEach(t=>{e(t)})}class e{constructor(){this._events={}}on(e,i){t(e,t=>{const e=this._events[t]||[];e.push(i),this._events[t]=e})}off(e,i){var s=arguments.length;0!==s?t(e,t=>{if(1===s)return void delete this._events[t];const e=this._events[t];void 0!==e&&(e.splice(e.indexOf(i),1),this._events[t]=e)}):this._events={}}trigger(e,...i){var s=this;t(e,t=>{const e=s._events[t];void 0!==e&&e.forEach(t=>{t.apply(s,i)})})}}const i=t=>(t=t.filter(Boolean)).length<2?t[0]||"":1==l(t)?"["+t.join("")+"]":"(?:"+t.join("|")+")",s=t=>{if(!o(t))return t.join("");let e="",i=0;const s=()=>{i>1&&(e+="{"+i+"}")};return t.forEach((n,o)=>{n!==t[o-1]?(s(),e+=n,i=1):i++}),s(),e},n=t=>{let e=Array.from(t);return i(e)},o=t=>new Set(t).size!==t.length,r=t=>(t+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1"),l=t=>t.reduce((t,e)=>Math.max(t,a(e)),0),a=t=>Array.from(t).length,c=t=>{if(1===t.length)return[[t]];let e=[];const i=t.substring(1);return c(i).forEach(function(i){let s=i.slice(0);s[0]=t.charAt(0)+s[0],e.push(s),s=i.slice(0),s.unshift(t.charAt(0)),e.push(s)}),e},d=[[0,65535]];let u,p;const h={},g={"/":"⁄∕",0:"߀",a:"ⱥɐɑ",aa:"ꜳ",ae:"æǽǣ",ao:"ꜵ",au:"ꜷ",av:"ꜹꜻ",ay:"ꜽ",b:"ƀɓƃ",c:"ꜿƈȼↄ",d:"đɗɖᴅƌꮷԁɦ",e:"ɛǝᴇɇ",f:"ꝼƒ",g:"ǥɠꞡᵹꝿɢ",h:"ħⱨⱶɥ",i:"ɨı",j:"ɉȷ",k:"ƙⱪꝁꝃꝅꞣ",l:"łƚɫⱡꝉꝇꞁɭ",m:"ɱɯϻ",n:"ꞥƞɲꞑᴎлԉ",o:"øǿɔɵꝋꝍᴑ",oe:"œ",oi:"ƣ",oo:"ꝏ",ou:"ȣ",p:"ƥᵽꝑꝓꝕρ",q:"ꝗꝙɋ",r:"ɍɽꝛꞧꞃ",s:"ßȿꞩꞅʂ",t:"ŧƭʈⱦꞇ",th:"þ",tz:"ꜩ",u:"ʉ",v:"ʋꝟʌ",vy:"ꝡ",w:"ⱳ",y:"ƴɏỿ",z:"ƶȥɀⱬꝣ",hv:"ƕ"};for(let t in g){let e=g[t]||"";for(let i=0;i<e.length;i++){let s=e.substring(i,i+1);h[s]=t}}const f=new RegExp(Object.keys(h).join("|")+"|[̀-ͯ·ʾʼ]","gu"),m=(t,e="NFKD")=>t.normalize(e),v=t=>Array.from(t).reduce((t,e)=>t+O(e),""),O=t=>(t=m(t).toLowerCase().replace(f,t=>h[t]||""),m(t,"NFC"));const y=t=>{const e={},i=(t,i)=>{const s=e[t]||new Set,o=new RegExp("^"+n(s)+"$","iu");i.match(o)||(s.add(r(i)),e[t]=s)};for(let e of function*(t){for(const[e,i]of t)for(let t=e;t<=i;t++){let e=String.fromCharCode(t),i=v(e);i!=e.toLowerCase()&&(i.length>3||0!=i.length&&(yield{folded:i,composed:e,code_point:t}))}}(t))i(e.folded,e.folded),i(e.folded,e.composed);return e},b=t=>{const e=y(t),s={};let o=[];for(let t in e){let i=e[t];i&&(s[t]=n(i)),t.length>1&&o.push(r(t))}o.sort((t,e)=>e.length-t.length);const l=i(o);return p=new RegExp("^"+l,"u"),s},w=(t,e=1)=>(e=Math.max(e,t.length-1),i(c(t).map(t=>((t,e=1)=>{let i=0;return t=t.map(t=>(u[t]&&(i+=t.length),u[t]||t)),i>=e?s(t):""})(t,e)))),S=(t,e=!0)=>{let n=t.length>1?1:0;return i(t.map(t=>{let i=[];const o=e?t.length():t.length()-1;for(let e=0;e<o;e++)i.push(w(t.substrs[e]||"",n));return s(i)}))},A=(t,e)=>{for(const i of e){if(i.start!=t.start||i.end!=t.end)continue;if(i.substrs.join("")!==t.substrs.join(""))continue;let e=t.parts;const s=t=>{for(const i of e){if(i.start===t.start&&i.substr===t.substr)return!1;if(1!=t.length&&1!=i.length){if(t.start<i.start&&t.end>i.start)return!0;if(i.start<t.start&&i.end>t.start)return!0}}return!1};if(!(i.parts.filter(s).length>0))return!0}return!1};class I{parts;substrs;start;end;constructor(){this.parts=[],this.substrs=[],this.start=0,this.end=0}add(t){t&&(this.parts.push(t),this.substrs.push(t.substr),this.start=Math.min(t.start,this.start),this.end=Math.max(t.end,this.end))}last(){return this.parts[this.parts.length-1]}length(){return this.parts.length}clone(t,e){let i=new I,s=JSON.parse(JSON.stringify(this.parts)),n=s.pop();for(const t of s)i.add(t);let o=e.substr.substring(0,t-n.start),r=o.length;return i.add({start:n.start,end:n.start+r,length:r,substr:o}),i}}const _=t=>{void 0===u&&(u=b(d)),t=v(t);let e="",i=[new I];for(let s=0;s<t.length;s++){let n=t.substring(s).match(p);const o=t.substring(s,s+1),r=n?n[0]:null;let l=[],a=new Set;for(const t of i){const e=t.last();if(!e||1==e.length||e.end<=s)if(r){const e=r.length;t.add({start:s,end:s+e,length:e,substr:r}),a.add("1")}else t.add({start:s,end:s+1,length:1,substr:o}),a.add("2");else if(r){let i=t.clone(s,e);const n=r.length;i.add({start:s,end:s+n,length:n,substr:r}),l.push(i)}else a.add("3")}if(l.length>0){l=l.sort((t,e)=>t.length()-e.length());for(let t of l)A(t,i)||i.push(t)}else if(s>0&&1==a.size&&!a.has("3")){e+=S(i,!1);let t=new I;const s=i[0];s&&t.add(s.last()),i=[t]}}return e+=S(i,!0),e},C=(t,e)=>{if(t)return t[e]},x=(t,e)=>{if(t){for(var i,s=e.split(".");(i=s.shift())&&(t=t[i]););return t}},F=(t,e,i)=>{var s,n;return t?(t+="",null==e.regex||-1===(n=t.search(e.regex))?0:(s=e.string.length/t.length,0===n&&(s+=.5),s*i)):0},L=(t,e)=>{var i=t[e];if("function"==typeof i)return i;i&&!Array.isArray(i)&&(t[e]=[i])},k=(t,e)=>{if(Array.isArray(t))t.forEach(e);else for(var i in t)t.hasOwnProperty(i)&&e(t[i],i)},E=(t,e)=>"number"==typeof t&&"number"==typeof e?t>e?1:t<e?-1:0:(t=v(t+"").toLowerCase())>(e=v(e+"").toLowerCase())?1:e>t?-1:0;class T{items;settings;constructor(t,e){this.items=t,this.settings=e||{diacritics:!0}}tokenize(t,e,i){if(!t||!t.length)return[];const s=[],n=t.split(/\s+/);var o;return i&&(o=new RegExp("^("+Object.keys(i).map(r).join("|")+"):(.*)$")),n.forEach(t=>{let i,n=null,l=null;o&&(i=t.match(o))&&(n=i[1],t=i[2]),t.length>0&&(l=this.settings.diacritics?_(t)||null:r(t),l&&e&&(l="\\b"+l)),s.push({string:t,regex:l?new RegExp(l,"iu"):null,field:n})}),s}getScoreFunction(t,e){var i=this.prepareSearch(t,e);return this._getScoreFunction(i)}_getScoreFunction(t){const e=t.tokens,i=e.length;if(!i)return function(){return 0};const s=t.options.fields,n=t.weights,o=s.length,r=t.getAttrFn;if(!o)return function(){return 1};const l=1===o?function(t,e){const i=s[0].field;return F(r(e,i),t,n[i]||1)}:function(t,e){var i=0;if(t.field){const s=r(e,t.field);!t.regex&&s?i+=1/o:i+=F(s,t,1)}else k(n,(s,n)=>{i+=F(r(e,n),t,s)});return i/o};return 1===i?function(t){return l(e[0],t)}:"and"===t.options.conjunction?function(t){var s,n=0;for(let i of e){if((s=l(i,t))<=0)return 0;n+=s}return n/i}:function(t){var s=0;return k(e,e=>{s+=l(e,t)}),s/i}}getSortFunction(t,e){var i=this.prepareSearch(t,e);return this._getSortFunction(i)}_getSortFunction(t){var e,i=[];const s=this,n=t.options,o=!t.query&&n.sort_empty?n.sort_empty:n.sort;if("function"==typeof o)return o.bind(this);const r=function(e,i){return"$score"===e?i.score:t.getAttrFn(s.items[i.id],e)};if(o)for(let e of o)(t.query||"$score"!==e.field)&&i.push(e);if(t.query){e=!0;for(let t of i)if("$score"===t.field){e=!1;break}e&&i.unshift({field:"$score",direction:"desc"})}else i=i.filter(t=>"$score"!==t.field);return i.length?function(t,e){var s,n;for(let o of i){if(n=o.field,s=("desc"===o.direction?-1:1)*E(r(n,t),r(n,e)))return s}return 0}:null}prepareSearch(t,e){const i={};var s=Object.assign({},e);if(L(s,"sort"),L(s,"sort_empty"),s.fields){L(s,"fields");const t=[];s.fields.forEach(e=>{"string"==typeof e&&(e={field:e,weight:1}),t.push(e),i[e.field]="weight"in e?e.weight:1}),s.fields=t}return{options:s,query:t.toLowerCase().trim(),tokens:this.tokenize(t,s.respect_word_boundaries,i),total:0,items:[],weights:i,getAttrFn:s.nesting?x:C}}search(t,e){var i,s,n=this;s=this.prepareSearch(t,e),e=s.options,t=s.query;const o=e.score||n._getScoreFunction(s);t.length?k(n.items,(t,n)=>{i=o(t),(!1===e.filter||i>0)&&s.items.push({score:i,id:n})}):k(n.items,(t,e)=>{s.items.push({score:1,id:e})});const r=n._getSortFunction(s);return r&&s.items.sort(r),s.total=s.items.length,"number"==typeof e.limit&&(s.items=s.items.slice(0,e.limit)),s}}const P=t=>null==t?null:V(t),V=t=>"boolean"==typeof t?t?"1":"0":t+"",$=t=>(t+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),D=(t,e)=>e>0?window.setTimeout(t,e):(t.call(null),null),j=(t,e)=>{var i;return function(s,n){var o=this;i&&(o.loading=Math.max(o.loading-1,0),clearTimeout(i)),i=setTimeout(function(){i=null,o.loadedSearches[s]=!0,t.call(o,s,n)},e)}},q=(t,e,i)=>{var s,n=t.trigger,o={};for(s of(t.trigger=function(){var i=arguments[0];if(-1===e.indexOf(i))return n.apply(t,arguments);o[i]=arguments},i.apply(t,[]),t.trigger=n,e))s in o&&n.apply(t,o[s])},N=t=>({start:t.selectionStart||0,length:(t.selectionEnd||0)-(t.selectionStart||0)}),H=(t,e=!1)=>{t&&(t.preventDefault(),e&&t.stopPropagation())},R=(t,e,i,s)=>{t.addEventListener(e,i,s)},M=(t,e)=>!!e&&(!!e[t]&&1===(e.altKey?1:0)+(e.ctrlKey?1:0)+(e.shiftKey?1:0)+(e.metaKey?1:0)),z=(t,e)=>{const i=t.getAttribute("id");return i||(t.setAttribute("id",e),e)},B=t=>t.replace(/[\\"']/g,"\\$&"),K=(t,e)=>{e&&t.append(e)},G=(t,e)=>{if(Array.isArray(t))t.forEach(e);else for(var i in t)t.hasOwnProperty(i)&&e(t[i],i)},U=t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(Q(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)},Q=t=>"string"==typeof t&&t.indexOf("<")>-1,W=(t,e)=>{var i=document.createEvent("HTMLEvents");i.initEvent(e,!0,!1),t.dispatchEvent(i)},J=(t,e)=>{Object.assign(t.style,e)},X=(t,...e)=>{var i=Z(e);(t=tt(t)).map(t=>{i.map(e=>{t.classList.add(e)})})},Y=(t,...e)=>{var i=Z(e);(t=tt(t)).map(t=>{i.map(e=>{t.classList.remove(e)})})},Z=t=>{var e=[];return G(t,t=>{"string"==typeof t&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},tt=t=>(Array.isArray(t)||(t=[t]),t),et=(t,e,i)=>{if(!i||i.contains(t))for(;t&&t.matches;){if(t.matches(e))return t;t=t.parentNode}},it=(t,e=0)=>e>0?t[t.length-1]:t[0],st=(t,e)=>{if(!t)return-1;e=e||t.nodeName;for(var i=0;t=t.previousElementSibling;)t.matches(e)&&i++;return i},nt=(t,e)=>{G(e,(e,i)=>{null==e?t.removeAttribute(i):t.setAttribute(i,""+e)})},ot=(t,e)=>{t.parentNode&&t.parentNode.replaceChild(e,t)},rt=(t,e)=>{if(null===e)return;if("string"==typeof e){if(!e.length)return;e=new RegExp(e,"i")}const i=t=>3===t.nodeType?(t=>{var i=t.data.match(e);if(i&&t.data.length>0){var s=document.createElement("span");s.className="highlight";var n=t.splitText(i.index);n.splitText(i[0].length);var o=n.cloneNode(!0);return s.appendChild(o),ot(n,s),1}return 0})(t):((t=>{1!==t.nodeType||!t.childNodes||/(script|style)/i.test(t.tagName)||"highlight"===t.className&&"SPAN"===t.tagName||Array.from(t.childNodes).forEach(t=>{i(t)})})(t),0);i(t)},lt="undefined"!=typeof navigator&&/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey";var at={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,clearAfterSelect:!1,highlight:!0,openOnFocus:!0,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,refreshThrottle:300,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:'<input type="text" autocomplete="off" size="1" />',copyClassesToDropdown:!1,placeholder:null,hidePlaceholder:null,shouldLoad:function(t){return t.length>0},render:{}};function ct(t,e){var i=Object.assign({},at,e),s=i.dataAttr,n=i.labelField,o=i.valueField,r=i.disabledField,l=i.optgroupField,a=i.optgroupLabelField,c=i.optgroupValueField,d=t.tagName.toLowerCase(),u=t.getAttribute("placeholder")||t.getAttribute("data-placeholder");if(!u&&!i.allowEmptyOption){let e=t.querySelector('option[value=""]');e&&(u=e.textContent)}var p={placeholder:u,options:[],optgroups:[],items:[],maxItems:null};return"select"===d?(()=>{var e,d=p.options,u={},h=1;let g=0;var f=t=>{var e=Object.assign({},t.dataset),i=s&&e[s];return"string"==typeof i&&i.length&&(e=Object.assign(e,JSON.parse(i))),e},m=(t,e)=>{var s=P(t.value);if(null!=s&&(s||i.allowEmptyOption)){if(u.hasOwnProperty(s)){if(e){var a=u[s][l];a?Array.isArray(a)?a.push(e):u[s][l]=[a,e]:u[s][l]=e}}else{var c=f(t);c[n]=c[n]||t.textContent,c[o]=c[o]||s,c[r]=c[r]||t.disabled,c[l]=c[l]||e,c.$option=t,c.$order=c.$order||++g,u[s]=c,d.push(c)}t.selected&&p.items.push(s)}};p.maxItems=t.hasAttribute("multiple")?null:1,G(t.children,t=>{var i,s,n;"optgroup"===(e=t.tagName.toLowerCase())?((n=f(i=t))[a]=n[a]||i.getAttribute("label")||"",n[c]=n[c]||h++,n[r]=n[r]||i.disabled,n.$order=n.$order||++g,p.optgroups.push(n),s=n[c],G(i.children,t=>{m(t,s)})):"option"===e&&m(t)})})():(()=>{var e,r;const l=t.getAttribute(s);if(l)p.options=JSON.parse(l),G(p.options,t=>{p.items.push(t[o])});else{var a=null!==(r=null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.trim())&&void 0!==r?r:"";if(!i.allowEmptyOption&&!a.length)return;const s=a.split(i.delimiter);G(s,t=>{const e={};e[n]=t,e[o]=t,p.options.push(e)}),p.items=s}})(),Object.assign({},at,p,e)}var dt=0;class ut extends(function(t){return t.plugins={},class extends t{constructor(){super(...arguments),this.plugins={names:[],settings:{},requested:{},loaded:{}}}static define(e,i){t.plugins[e]={name:e,fn:i}}initializePlugins(t){var e,i;const s=this,n=[];if(Array.isArray(t))t.forEach(t=>{"string"==typeof t?n.push(t):(s.plugins.settings[t.name]=t.options,n.push(t.name))});else if(t)for(e in t)t.hasOwnProperty(e)&&(s.plugins.settings[e]=t[e],n.push(e));for(;i=n.shift();)s.require(i)}loadPlugin(e){var i=this,s=i.plugins,n=t.plugins[e];if(!t.plugins.hasOwnProperty(e))throw new Error('Unable to find "'+e+'" plugin');s.requested[e]=!0,s.loaded[e]=n.fn.apply(i,[i.plugins.settings[e]||{}]),s.names.push(e)}require(t){var e=this,i=e.plugins;if(!e.plugins.loaded.hasOwnProperty(t)){if(i.requested[t])throw new Error('Plugin has circular dependency ("'+t+'")');e.loadPlugin(t)}return i.loaded[t]}}}(e)){constructor(t,e){var i;super(),this.order=0,this.isOpen=!1,this.isDisabled=!1,this.isReadOnly=!1,this.isInvalid=!1,this.isValid=!0,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.isDropdownContentStale=!0,this.ignoreFocus=!1,this.ignoreHover=!1,this.hasOptions=!1,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.refreshTimeout=null,dt++;var s=U(t);if(s.tomselect)throw new Error("Tom Select already initialized on this element");s.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(s,null)).getPropertyValue("direction");const n=ct(s,e);this.settings=n,this.input=s,this.tabIndex=s.tabIndex||0,this.is_select_tag="select"===s.tagName.toLowerCase(),this.rtl=/rtl/i.test(i),this.inputId=z(s,"tomselect-"+dt),this.isRequired=s.required,this.sifter=new T(this.options,{diacritics:n.diacritics}),n.mode=n.mode||(1===n.maxItems?"single":"multi"),"boolean"!=typeof n.hideSelected&&(n.hideSelected="multi"===n.mode),"boolean"!=typeof n.hidePlaceholder&&(n.hidePlaceholder="multi"!==n.mode);var o=n.createFilter;"function"!=typeof o&&("string"==typeof o&&(o=new RegExp(o)),o instanceof RegExp?n.createFilter=t=>o.test(t):n.createFilter=t=>this.settings.duplicates||!this.options[t]),this.initializePlugins(n.plugins),this.setupCallbacks(),this.setupTemplates();const r=U("<div>"),l=U("<div>"),a=this._render("dropdown"),c=U('<div role="listbox" tabindex="-1">'),d=this.input.getAttribute("class")||"",u=n.mode;var p;if(X(r,n.wrapperClass,d,u),X(l,n.controlClass),K(r,l),X(a,n.dropdownClass,u),n.copyClassesToDropdown&&X(a,d),X(c,n.dropdownContentClass),K(a,c),U(n.dropdownParent||r).appendChild(a),Q(n.controlInput)){p=U(n.controlInput);G(["autocorrect","autocapitalize","autocomplete","spellcheck","aria-label"],t=>{s.getAttribute(t)&&nt(p,{[t]:s.getAttribute(t)})}),p.tabIndex=-1,l.appendChild(p),this.focus_node=p}else n.controlInput?(p=U(n.controlInput),this.focus_node=p):(p=U("<input/>"),this.focus_node=l);this.wrapper=r,this.dropdown=a,this.dropdown_content=c,this.control=l,this.control_input=p,this.setup()}setup(){const t=this,e=t.settings,i=t.control_input,s=t.dropdown,n=t.dropdown_content,o=t.wrapper,l=t.control,a=t.input,c=t.focus_node,d={passive:!0},u=t.inputId+"-ts-dropdown";nt(n,{id:u}),nt(c,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":u});const p=z(c,t.inputId+"-ts-control"),h="label[for='"+(t=>t.replace(/['"\\]/g,"\\$&"))(t.inputId)+"']",g=document.querySelector(h),f=t.focus.bind(t);if(g){R(g,"click",f),nt(g,{for:p});const e=z(g,t.inputId+"-ts-label");nt(c,{"aria-labelledby":e}),nt(n,{"aria-labelledby":e})}if(o.style.width=a.style.width,o.style.minWidth=a.style.minWidth,o.style.maxWidth=a.style.maxWidth,t.plugins.names.length){const e="plugin-"+t.plugins.names.join(" plugin-");X([o,s],e)}(null===e.maxItems||e.maxItems>1)&&t.is_select_tag&&nt(a,{multiple:"multiple"}),e.placeholder&&nt(i,{placeholder:e.placeholder}),!e.splitOn&&e.delimiter&&(e.splitOn=new RegExp("\\s*"+r(e.delimiter)+"+\\s*")),e.load&&e.loadThrottle&&(e.load=j(e.load,e.loadThrottle)),R(s,"mousemove",()=>{t.ignoreHover=!1}),R(s,"mouseenter",e=>{var i=et(e.target,"[data-selectable]",s);i&&t.onOptionHover(e,i)},{capture:!0}),R(s,"click",e=>{const i=et(e.target,"[data-selectable]");i&&(t.onOptionSelect(e,i),H(e,!0))}),R(l,"click",e=>{var s=et(e.target,"[data-ts-item]",l);s&&t.onItemSelect(e,s)?H(e,!0):""==i.value&&(t.onClick(),H(e,!0))}),R(c,"keydown",e=>t.onKeyDown(e)),R(i,"keypress",e=>t.onKeyPress(e)),R(i,"input",e=>t.onInput(e)),R(c,"blur",e=>t.onBlur(e)),R(c,"focus",e=>t.onFocus(e)),R(i,"paste",e=>t.onPaste(e));const m=e=>{const n=e.composedPath()[0];if(!o.contains(n)&&!s.contains(n))return t.isFocused&&t.blur(),void t.inputState();n==i&&t.isOpen?e.stopPropagation():H(e,!0)},v=()=>{t.isOpen&&t.positionDropdown()},O=()=>{t.isValid&&(t.isValid=!1,t.isInvalid=!0,t.refreshState())};R(a,"invalid",O),R(document,"mousedown",m),R(window,"scroll",v,d),R(window,"resize",v,d),this._destroy=()=>{a.removeEventListener("invalid",O),document.removeEventListener("mousedown",m),window.removeEventListener("scroll",v),window.removeEventListener("resize",v),g&&g.removeEventListener("click",f)},this.revertSettings={innerHTML:a.innerHTML,tabIndex:a.tabIndex},a.tabIndex=-1,a.insertAdjacentElement("afterend",t.wrapper),t.sync(!1),e.items=[],delete e.optgroups,delete e.options,t.refreshItems(),t.close(!1),t.inputState(),t.isSetup=!0,t.on("change",this.onChange),X(a,"tomselected","ts-hidden-accessible"),t.trigger("initialize"),!0===e.preload&&t.preload()}setupOptions(t=[],e=[]){this.addOptions(t),G(e,t=>{this.registerOptionGroup(t)})}setupTemplates(){var t=this,e=t.settings.labelField,i=t.settings.optgroupLabelField,s={optgroup:t=>{let e=document.createElement("div");return e.className="optgroup",e.appendChild(t.options),e},optgroup_header:(t,e)=>'<div class="optgroup-header">'+e(t[i])+"</div>",option:(t,i)=>"<div>"+i(t[e])+"</div>",item:(t,i)=>"<div>"+i(t[e])+"</div>",option_create:(t,e)=>'<div class="create">Add <strong>'+e(t.input)+"</strong>&hellip;</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"};t.settings.render=Object.assign({},s,t.settings.render)}setupCallbacks(){var t,e,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(t in i)(e=this.settings[i[t]])&&this.on(t,e)}sync(t=!0){const e=this,i=t?ct(e.input,{delimiter:e.settings.delimiter,allowEmptyOption:e.settings.allowEmptyOption}):e.settings;e.setupOptions(i.options,i.optgroups),e.setValue(i.items||[],!0),e.input.disabled?e.disable():e.input.readOnly?e.setReadOnly(!0):e.enable(),e.lastQuery=null}onClick(){var t=this;if(t.activeItems.length>0)return t.clearActiveItems(),void t.focus();t.isFocused&&t.isOpen?t.blur():t.focus()}onMouseDown(){}onChange(){W(this.input,"input"),W(this.input,"change")}onPaste(t){var e=this;e.isInputHidden||e.isLocked?H(t):e.settings.splitOn&&setTimeout(()=>{var t=e.inputValue();if(t.match(e.settings.splitOn)){var i=t.trim().split(e.settings.splitOn);G(i,t=>{P(t)&&(this.options[t]?e.addItem(t):e.createItem(t))})}},0)}onKeyPress(t){var e=this;if(!e.isLocked){var i=String.fromCharCode(t.keyCode||t.which);return e.settings.create&&"multi"===e.settings.mode&&i===e.settings.delimiter?(e.createItem(),void H(t)):void 0}H(t)}onKeyDown(t){var e=this;if(e.ignoreHover=!0,e.isLocked)9!==t.keyCode&&H(t);else{switch(t.keyCode){case 65:if(M(lt,t)&&""==e.control_input.value)return H(t),void e.selectAll();break;case 27:return e.isOpen&&(H(t,!0),e.close()),void e.clearActiveItems();case 40:if(!e.isOpen&&e.hasOptions)e.open();else if(e.activeOption){let t=e.getAdjacent(e.activeOption,1);t&&e.setActiveOption(t)}return void H(t);case 38:if(e.activeOption){let t=e.getAdjacent(e.activeOption,-1);t&&e.setActiveOption(t)}return void H(t);case 13:return void(e.canSelect(e.activeOption)?(e.onOptionSelect(t,e.activeOption),H(t)):(e.settings.create&&e.createItem()||document.activeElement==e.control_input&&e.isOpen)&&H(t));case 37:return void e.advanceSelection(-1,t);case 39:return void e.advanceSelection(1,t);case 9:return void(e.settings.selectOnTab&&(e.canSelect(e.activeOption)?(e.onOptionSelect(t,e.activeOption),H(t)):e.settings.create&&e.createItem()&&H(t)));case 8:case 46:return void e.deleteSelection(t)}e.isInputHidden&&!M(lt,t)&&H(t)}}onInput(t){if(this.isLocked)return;const e=this.inputValue();this.lastValue!==e&&(this.lastValue=e,""!=e?(this.refreshTimeout&&window.clearTimeout(this.refreshTimeout),this.refreshTimeout=D(()=>{this.refreshTimeout=null,this._onInput()},this.settings.refreshThrottle)):this._onInput())}_onInput(){const t=this.lastValue;this.settings.shouldLoad.call(this,t)&&this.load(t),this.refreshOptions(),this.trigger("type",t)}onOptionHover(t,e){this.ignoreHover||this.setActiveOption(e,!1)}onFocus(t){var e=this,i=e.isFocused;if(e.isDisabled||e.isReadOnly)return e.blur(),void H(t);e.ignoreFocus||(e.isFocused=!0,"focus"===e.settings.preload&&e.preload(),i||e.trigger("focus"),e.activeItems.length||(e.inputState(),e.refreshOptions(!!e.settings.openOnFocus)),e.refreshState())}onBlur(t){if(!1!==document.hasFocus()){var e=this;if(e.isFocused){e.isFocused=!1,e.ignoreFocus=!1;var i=()=>{e.close(),e.setActiveItem(),e.setCaret(e.items.length),e.trigger("blur")};e.settings.create&&e.settings.createOnBlur?e.createItem(null,i):i()}}}onOptionSelect(t,e){var i,s=this;e.parentElement&&e.parentElement.matches("[data-disabled]")||(e.classList.contains("create")?s.createItem(null,()=>{s.settings.closeAfterSelect?s.close():s.settings.clearAfterSelect&&s.setTextboxValue()}):void 0!==(i=e.dataset.value)&&(s.isDropdownContentStale=s.settings.hideSelected,s.addItem(i),s.settings.closeAfterSelect?s.close():s.settings.clearAfterSelect&&s.setTextboxValue(),!s.settings.hideSelected&&t.type&&/click/.test(t.type)&&s.setActiveOption(e)))}canSelect(t){return!!(this.isOpen&&t&&this.dropdown_content.contains(t))}onItemSelect(t,e){var i=this;return!i.isLocked&&"multi"===i.settings.mode&&(H(t),i.setActiveItem(e,t),!0)}canLoad(t){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(t)}load(t){const e=this;if(!e.canLoad(t))return;X(e.wrapper,e.settings.loadingClass),e.loading++;const i=e.loadCallback.bind(e);e.settings.load.call(e,t,i)}loadCallback(t,e){const i=this;i.loading=Math.max(i.loading-1,0),i.isDropdownContentStale=!0,i.clearActiveOption(),i.setupOptions(t,e),i.refreshOptions(i.isFocused&&!i.isInputHidden),i.loading||Y(i.wrapper,i.settings.loadingClass),i.trigger("load",t,e)}preload(){var t=this.wrapper.classList;t.contains("preloaded")||(t.add("preloaded"),this.load(""))}setTextboxValue(t=""){var e=this.control_input;e.value!==t&&(e.value=t,W(e,"update"),this.lastValue=t)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(t,e){q(this,e?[]:["change"],()=>{this.clear(e),this.addItems(t,e)})}setMaxItems(t){0===t&&(t=null),this.settings.maxItems=t,this.refreshState()}setActiveItem(t,e){var i,s,n,o,r,l,a=this;if("single"!==a.settings.mode){if(!t)return a.clearActiveItems(),void(a.isFocused&&a.inputState());if("click"===(i=e&&e.type.toLowerCase())&&M("shiftKey",e)&&a.activeItems.length){for(l=a.getLastActive(),(n=Array.prototype.indexOf.call(a.control.children,l))>(o=Array.prototype.indexOf.call(a.control.children,t))&&(r=n,n=o,o=r),s=n;s<=o;s++)t=a.control.children[s],-1===a.activeItems.indexOf(t)&&a.setActiveItemClass(t);H(e)}else"click"===i&&M(lt,e)||"keydown"===i&&M("shiftKey",e)?t.classList.contains("active")?a.removeActiveItem(t):a.setActiveItemClass(t):(a.clearActiveItems(),a.setActiveItemClass(t));a.inputState(),a.isFocused||a.focus()}}setActiveItemClass(t){const e=this,i=e.control.querySelector(".last-active");i&&Y(i,"last-active"),X(t,"active last-active"),e.trigger("item_select",t),-1==e.activeItems.indexOf(t)&&e.activeItems.push(t)}removeActiveItem(t){var e=this.activeItems.indexOf(t);this.activeItems.splice(e,1),Y(t,"active")}clearActiveItems(){Y(this.activeItems,"active"),this.activeItems=[]}setActiveOption(t,e=!0){t!==this.activeOption&&(this.clearActiveOption(),t&&(this.activeOption=t,nt(this.focus_node,{"aria-activedescendant":t.getAttribute("id")}),nt(t,{"aria-selected":"true"}),X(t,"active"),e&&this.scrollToOption(t)))}scrollToOption(t,e){if(!t)return;const i=this.dropdown_content,s=i.clientHeight,n=i.scrollTop||0,o=t.offsetHeight,r=t.getBoundingClientRect().top-i.getBoundingClientRect().top+n;r+o>s+n?this.scroll(r-s+o,e):r<n&&this.scroll(r,e)}scroll(t,e){const i=this.dropdown_content;e&&(i.style.scrollBehavior=e),i.scrollTop=t,i.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(Y(this.activeOption,"active"),nt(this.activeOption,{"aria-selected":null})),this.activeOption=null,nt(this.focus_node,{"aria-activedescendant":null})}selectAll(){const t=this;if("single"===t.settings.mode)return;const e=t.controlChildren();e.length&&(t.inputState(),t.close(),t.activeItems=e,G(e,e=>{t.setActiveItemClass(e)}))}inputState(){var t=this;t.control.contains(t.control_input)&&(nt(t.control_input,{placeholder:t.settings.placeholder}),t.activeItems.length>0||!t.isFocused&&t.settings.hidePlaceholder&&t.items.length>0?(t.setTextboxValue(),t.isInputHidden=!0):(t.settings.hidePlaceholder&&t.items.length>0&&nt(t.control_input,{placeholder:""}),t.isInputHidden=!1),t.wrapper.classList.toggle("input-hidden",t.isInputHidden))}inputValue(){return this.control_input.value.trim()}focus(){var t=this;if(t.isDisabled||t.isReadOnly)return;t.ignoreFocus=!0;const e=this.control_input.offsetWidth?this.control_input:this.focus_node;e.focus(),setTimeout(()=>{t.ignoreFocus=!1;e.getRootNode().activeElement===e&&this.onFocus()},0)}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(t){return this.sifter.getScoreFunction(t,this.getSearchOptions())}getSearchOptions(){var t=this.settings,e=t.sortField;return"string"==typeof t.sortField&&(e=[{field:t.sortField}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}}search(t){var e,i,s=this,n=this.getSearchOptions();if(s.settings.score&&"function"!=typeof(i=s.settings.score.call(s,t)))throw new Error('Tom Select "score" setting must be a function that returns a function');return s.isDropdownContentStale||t!==s.lastQuery?(s.lastQuery=t,/(.)\1{15,}/.test(t)&&(t=""),e=s.sifter.search(t,Object.assign(n,{score:i})),s.currentResults=e):e=Object.assign({},s.currentResults),s.settings.hideSelected&&(e.items=e.items.filter(t=>{let e=P(t.id);return!(null!==e&&-1!==s.items.indexOf(e))})),e}refreshOptions(t=!0){var e,i,s,n,o,r,l,a,c,d;const u={},p=[];var h=this,g=h.inputValue();const f=g===h.lastQuery||""==g&&null==h.lastQuery;var m=h.search(g),v=null,O=h.settings.shouldOpen||!1,y=h.dropdown_content;f&&(v=h.activeOption)&&(c=v.closest("[data-group]")),n=m.items.length,"number"==typeof h.settings.maxOptions&&(n=Math.min(n,h.settings.maxOptions)),n>0&&(O=!0);const b=(t,e)=>{let i=u[t];if(void 0!==i){let t=p[i];if(void 0!==t)return[i,t.fragment]}let s=document.createDocumentFragment();return i=p.length,p.push({fragment:s,order:e,optgroup:t}),[i,s]};for(e=0;e<n;e++){let t=m.items[e];if(!t)continue;let n=t.id,l=h.options[n];if(void 0===l)continue;let a=V(n),d=h.getOption(a,!0);for(h.settings.hideSelected||d.classList.toggle("selected",h.items.includes(a)),o=l[h.settings.optgroupField]||"",i=0,s=(r=Array.isArray(o)?o:[o])&&r.length;i<s;i++){o=r[i];let t=l.$order,e=h.optgroups[o];var w;if(void 0===e&&"function"==typeof h.settings.optionGroupRegister)(w=h.settings.optionGroupRegister.apply(h,[o]))&&h.registerOptionGroup(w);e=h.optgroups[o],void 0===e?o="":t=e.$order;const[s,a]=b(o,t);i>0&&(d=d.cloneNode(!0),nt(d,{id:l.$id+"-clone-"+i,"aria-selected":null}),d.classList.add("ts-cloned"),Y(d,"active"),h.activeOption&&h.activeOption.dataset.value==n&&c&&c.dataset.group===o.toString()&&(v=d)),a.appendChild(d),""!=o&&(u[o]=s)}}var S;h.settings.lockOptgroupOrder&&p.sort((t,e)=>t.order-e.order),l=document.createDocumentFragment(),G(p,t=>{let e=t.fragment,i=t.optgroup;if(!e||!e.children.length)return;let s=h.optgroups[i];if(void 0!==s){let t=document.createDocumentFragment(),i=h.render("optgroup_header",s);K(t,i),K(t,e);let n=h.render("optgroup",{group:s,options:t});K(l,n)}else K(l,e)}),y.innerHTML="",K(y,l),h.isDropdownContentStale=!1,h.settings.highlight&&(S=y.querySelectorAll("span.highlight"),Array.prototype.forEach.call(S,function(t){var e=t.parentNode;e.replaceChild(t.firstChild,t),e.normalize()}),m.query.length&&m.tokens.length&&G(m.tokens,t=>{rt(y,t.regex)}));var A=t=>{let e=h.render(t,{input:g});return e&&(O=!0,y.insertBefore(e,y.firstChild)),e};if(h.loading?A("loading"):h.settings.shouldLoad.call(h,g)?0===m.items.length&&A("no_results"):A("not_loading"),(a=h.canCreate(g))&&(d=A("option_create")),h.hasOptions=m.items.length>0||a,O){if(m.items.length>0){if(v||"single"!==h.settings.mode||null==h.items[0]||(v=h.getOption(h.items[0])),!y.contains(v)){let t=0;d&&!h.settings.addPrecedence&&(t=1),v=h.selectable()[t]}}else d&&(v=d);t&&!h.isOpen&&(h.open(),h.scrollToOption(v,"auto")),h.setActiveOption(v)}else h.clearActiveOption(),t&&h.isOpen&&h.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(t,e=!1){const i=this;if(Array.isArray(t))return i.addOptions(t,e),!1;const s=P(t[i.settings.valueField]);return null===s||i.options.hasOwnProperty(s)?(i.updateOption(t[i.settings.valueField],t),!1):(t.$order=t.$order||++i.order,t.$id=i.inputId+"-opt-"+t.$order,i.options[s]=t,i.isDropdownContentStale=!0,e&&(i.userOptions[s]=e,i.trigger("option_add",s,t)),s)}addOptions(t,e=!1){G(t,t=>{this.addOption(t,e)})}registerOption(t){return this.addOption(t)}registerOptionGroup(t){var e=P(t[this.settings.optgroupValueField]);return null!==e&&(t.$order=t.$order||++this.order,this.optgroups[e]=t,e)}addOptionGroup(t,e){var i;e[this.settings.optgroupValueField]=t,(i=this.registerOptionGroup(e))&&this.trigger("optgroup_add",i,e)}removeOptionGroup(t){this.optgroups.hasOwnProperty(t)&&(delete this.optgroups[t],this.clearCache(),this.trigger("optgroup_remove",t))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(t,e){const i=this;var s,n;const o=P(t),r=P(e[i.settings.valueField]);if(null===o)return;const l=i.options[o];if(null==l)return;if("string"!=typeof r)throw new Error("Value must be set in option data");const a=i.getOption(o),c=i.getItem(o);if(e.$order=e.$order||l.$order,delete i.options[o],i.uncacheValue(r),i.options[r]=e,a){if(i.dropdown_content.contains(a)){const t=i._render("option",e);ot(a,t),i.activeOption===a&&i.setActiveOption(t)}a.remove()}c&&(-1!==(n=i.items.indexOf(o))&&i.items.splice(n,1,r),s=i._render("item",e),c.classList.contains("active")&&X(s,"active"),ot(c,s)),i.isDropdownContentStale=!0}removeOption(t,e){const i=this;t=V(t),i.uncacheValue(t),delete i.userOptions[t],delete i.options[t],i.isDropdownContentStale=!0,i.trigger("option_remove",t),i.removeItem(t,e)}clearOptions(t){const e=(t||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const i={};G(this.options,(t,s)=>{e(t,s)&&(i[s]=t)}),this.options=this.sifter.items=i,this.isDropdownContentStale=!0,this.trigger("option_clear")}clearFilter(t,e){return this.items.indexOf(e)>=0}getOption(t,e=!1){const i=P(t);if(null===i)return null;const s=this.options[i];if(null!=s){if(s.$div)return s.$div;if(e)return this._render("option",s)}return null}getAdjacent(t,e,i="option"){var s;if(!t)return null;s="item"==i?this.controlChildren():this.dropdown_content.querySelectorAll("[data-selectable]");for(let i=0;i<s.length;i++)if(s[i]==t)return e>0?s[i+1]:s[i-1];return null}getItem(t){if("object"==typeof t)return t;var e=P(t);return null!==e?this.control.querySelector(`[data-value="${B(e)}"]`):null}addItems(t,e){var i=this,s=Array.isArray(t)?t:[t];const n=(s=s.filter(t=>-1===i.items.indexOf(t)))[s.length-1];s.forEach(t=>{i.isPending=t!==n,i.addItem(t,e)})}addItem(t,e){q(this,e?[]:["change","dropdown_close"],()=>{var i,s;const n=this,o=n.settings.mode,r=P(t);if((!r||-1===n.items.indexOf(r)||("single"===o&&n.close(),"single"!==o&&n.settings.duplicates))&&null!==r&&n.options.hasOwnProperty(r)&&("single"===o&&n.clear(e),"multi"!==o||!n.isFull())){if(i=n._render("item",n.options[r]),n.control.contains(i)&&(i=i.cloneNode(!0)),s=n.isFull(),n.items.splice(n.caretPos,0,r),n.insertAtCaret(i),n.isSetup){if(!n.isPending&&n.settings.hideSelected){let t=n.getOption(r),e=n.getAdjacent(t,1);e&&n.setActiveOption(e)}n.settings.clearAfterSelect&&n.setTextboxValue(),n.isPending||n.settings.closeAfterSelect||n.refreshOptions(n.isFocused&&"single"!==o),0!=n.settings.closeAfterSelect&&n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",r,i),n.isPending||n.updateOriginalInput({silent:e})}(!n.isPending||!s&&n.isFull())&&(n.inputState(),n.refreshState())}})}removeItem(t=null,e){const i=this;if(!(t=i.getItem(t)))return;var s,n;const o=t.dataset.value;s=st(t),t.remove(),t.classList.contains("active")&&(n=i.activeItems.indexOf(t),i.activeItems.splice(n,1),Y(t,"active")),i.items.splice(s,1),i.isDropdownContentStale=!0,!i.settings.persist&&i.userOptions.hasOwnProperty(o)&&i.removeOption(o,e),s<i.caretPos&&i.setCaret(i.caretPos-1),i.updateOriginalInput({silent:e}),i.refreshState(),i.positionDropdown(),i.trigger("item_remove",o,t)}createItem(t=null,e=()=>{}){3===arguments.length&&(e=arguments[2]),"function"!=typeof e&&(e=()=>{});var i,s=this,n=s.caretPos;if(t=t||s.inputValue(),!s.canCreate(t)){return P(t)&&this.options[t]&&s.addItem(t),e(),!1}s.lock();var o=!1,r=t=>{if(s.unlock(),!t||"object"!=typeof t)return e();var i=P(t[s.settings.valueField]);if("string"!=typeof i)return e();s.setTextboxValue(),s.addOption(t,!0),s.setCaret(n),s.addItem(i),e(t),o=!0};return i="function"==typeof s.settings.create?s.settings.create.call(this,t,r):{[s.settings.labelField]:t,[s.settings.valueField]:t},o||r(i),!0}refreshItems(){var t=this;t.isDropdownContentStale=!0,t.isSetup&&t.addItems(t.items),t.updateOriginalInput(),t.refreshState()}refreshState(){const t=this;t.refreshValidityState();const e=t.isFull(),i=t.isLocked;t.wrapper.classList.toggle("rtl",t.rtl);const s=t.wrapper.classList;var n;s.toggle("focus",t.isFocused),s.toggle("disabled",t.isDisabled),s.toggle("readonly",t.isReadOnly),s.toggle("required",t.isRequired),s.toggle("invalid",!t.isValid),s.toggle("locked",i),s.toggle("full",e),s.toggle("input-active",t.isFocused&&!t.isInputHidden),s.toggle("dropdown-active",t.isOpen),s.toggle("has-options",(n=t.options,0===Object.keys(n).length)),s.toggle("has-items",t.items.length>0)}refreshValidityState(){var t=this;t.input.validity&&(t.isValid=t.input.validity.valid,t.isInvalid=!t.isValid)}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(t={}){const e=this;var i,s;const n=e.input.querySelector('option[value=""]');if(e.is_select_tag){const o=[],r=e.input.querySelectorAll("option:checked").length;function l(t,i,s){return t||(t=U('<option value="'+$(i)+'">'+$(s)+"</option>")),t!=n&&e.input.append(t),o.push(t),(t!=n||r>0||"multi"==e.settings.mode)&&(t.selected=!0),t}e.input.querySelectorAll("option:checked").forEach(t=>{t.selected=!1}),0==e.items.length&&"single"==e.settings.mode?l(n,"",""):e.items.forEach(t=>{if(i=e.options[t],s=i[e.settings.labelField]||"",o.includes(i.$option)){l(e.input.querySelector(`option[value="${B(t)}"]:not(:checked)`),t,s)}else i.$option=l(i.$option,t,s)})}else e.input.value=e.getValue();e.isSetup&&(t.silent||e.trigger("change",e.getValue()))}open(){var t=this;t.isLocked||t.isOpen||"multi"===t.settings.mode&&t.isFull()||(t.isOpen=!0,nt(t.focus_node,{"aria-expanded":"true"}),t.refreshState(),J(t.dropdown,{visibility:"hidden",display:"block"}),t.positionDropdown(),J(t.dropdown,{visibility:"visible",display:"block"}),t.focus(),t.trigger("dropdown_open",t.dropdown))}close(t=!0){var e=this,i=e.isOpen;t&&(e.setTextboxValue(),"single"===e.settings.mode&&e.items.length&&e.inputState()),e.isOpen=!1,nt(e.focus_node,{"aria-expanded":"false"}),J(e.dropdown,{display:"none"}),e.settings.hideSelected&&e.clearActiveOption(),e.refreshState(),i&&e.trigger("dropdown_close",e.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var t=this.control,e=t.getBoundingClientRect(),i=t.offsetHeight+e.top+window.scrollY,s=e.left+window.scrollX;J(this.dropdown,{width:e.width+"px",top:i+"px",left:s+"px"})}}clear(t){var e=this;if(e.items.length){var i=e.controlChildren();G(i,t=>{e.removeItem(t,!0)}),e.inputState(),t||e.updateOriginalInput(),e.trigger("clear")}}insertAtCaret(t){const e=this,i=e.caretPos,s=e.control;s.insertBefore(t,s.children[i]||null),e.setCaret(i+1)}deleteSelection(t){var e,i,s,n,o=this;e=t&&8===t.keyCode?-1:1,i=N(o.control_input);const r=[];if(o.activeItems.length)n=it(o.activeItems,e),s=st(n),e>0&&s++,G(o.activeItems,t=>r.push(t));else if((o.isFocused||"single"===o.settings.mode)&&o.items.length){const t=o.controlChildren();let s;e<0&&0===i.start&&0===i.length?s=t[o.caretPos-1]:e>0&&i.start===o.inputValue().length&&(s=t[o.caretPos]),void 0!==s&&r.push(s)}if(!o.shouldDelete(r,t))return!1;for(H(t,!0),void 0!==s&&o.setCaret(s);r.length;)o.removeItem(r.pop());return o.inputState(),o.positionDropdown(),o.refreshOptions(!1),!0}shouldDelete(t,e){const i=t.map(t=>t.dataset.value);return!(!i.length||"function"==typeof this.settings.onDelete&&!1===this.settings.onDelete.call(this,i,e))}advanceSelection(t,e){var i,s,n=this;n.rtl&&(t*=-1),n.inputValue().length||(M(lt,e)||M("shiftKey",e)?(s=(i=n.getLastActive(t))?i.classList.contains("active")?n.getAdjacent(i,t,"item"):i:t>0?n.control_input.nextElementSibling:n.control_input.previousElementSibling)&&(s.classList.contains("active")&&n.removeActiveItem(i),n.setActiveItemClass(s)):n.moveCaret(t))}moveCaret(t){}getLastActive(t){let e=this.control.querySelector(".last-active");if(e)return e;var i=this.control.querySelectorAll(".active");return i?it(i,t):void 0}setCaret(t){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(!0)}unlock(){this.setLocked(!1)}setLocked(t=this.isReadOnly||this.isDisabled){this.isLocked=t,this.refreshState()}disable(){this.setDisabled(!0),this.close()}enable(){this.setDisabled(!1)}setDisabled(t){this.focus_node.tabIndex=t?-1:this.tabIndex,this.isDisabled=t,this.input.disabled=t,this.control_input.disabled=t,this.setLocked()}setReadOnly(t){this.isReadOnly=t,this.input.readOnly=t,this.control_input.readOnly=t,this.setLocked()}destroy(){var t=this,e=t.revertSettings;t.trigger("destroy"),t.off(),t.wrapper.remove(),t.dropdown.remove(),t.input.innerHTML=e.innerHTML,t.input.tabIndex=e.tabIndex,Y(t.input,"tomselected","ts-hidden-accessible"),t._destroy(),delete t.input.tomselect}render(t,e){var i,s;const n=this;if("function"!=typeof this.settings.render[t])return null;if(!(s=n.settings.render[t].call(this,e,$)))return null;if(s=U(s),"option"===t||"option_create"===t?e[n.settings.disabledField]?nt(s,{"aria-disabled":"true"}):nt(s,{"data-selectable":""}):"optgroup"===t&&(i=e.group[n.settings.optgroupValueField],nt(s,{"data-group":i}),e.group[n.settings.disabledField]&&nt(s,{"data-disabled":""})),"option"===t||"item"===t){const i=V(e[n.settings.valueField]);nt(s,{"data-value":i}),"item"===t?(X(s,n.settings.itemClass),nt(s,{"data-ts-item":""})):(X(s,n.settings.optionClass),nt(s,{role:"option",id:e.$id}),e.$div=s,n.options[i]=e)}return s}_render(t,e){const i=this.render(t,e);if(null==i)throw"HTMLElement expected";return i}clearCache(){G(this.options,t=>{t.$div&&(t.$div.remove(),delete t.$div)})}uncacheValue(t){const e=this.getOption(t);e&&e.remove()}canCreate(t){return this.settings.create&&t.length>0&&this.settings.createFilter.call(this,t)}hook(t,e,i){var s=this,n=s[e];s[e]=function(){var e,o;return"after"===t&&(e=n.apply(s,arguments)),o=i.apply(s,arguments),"instead"===t?o:("before"===t&&(e=n.apply(s,arguments)),e)}}}const pt=t=>"string"==typeof t&&t.indexOf("<")>-1;const ht=(t,e=!1)=>{t&&(t.preventDefault(),e&&t.stopPropagation())},gt=(t,e,i,s)=>{t.addEventListener(e,i,s)},ft=t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(mt(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)},mt=t=>"string"==typeof t&&t.indexOf("<")>-1;const vt=t=>{var e=[];return((t,e)=>{if(Array.isArray(t))t.forEach(e);else for(var i in t)t.hasOwnProperty(i)&&e(t[i],i)})(t,t=>{"string"==typeof t&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},Ot=t=>(Array.isArray(t)||(t=[t]),t);ut.define("clear_button",function(t){const e=this,i=Object.assign({className:"clear-button",title:"Clear All",role:"button",tabindex:0,html:t=>`<div class="${t.className}" title="${t.title}" role="${t.role}" tabindex="${t.tabindex}">&times;</div>`},t);e.on("initialize",()=>{var t=(t=>{if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(pt(t)){var e=document.createElement("template");return e.innerHTML=t.trim(),e.content.firstChild}return document.querySelector(t)})(i.html(i));t.addEventListener("click",t=>{e.isLocked||(e.clear(),"single"===e.settings.mode&&e.settings.allowEmptyOption&&e.addItem(""),e.refreshOptions(!1),t.preventDefault(),t.stopPropagation())}),e.control.appendChild(t)})}),ut.define("remove_button",function(t){const e=this,i=Object.assign({label:"×",title:"Remove",className:"remove",tabindex:-1,role:"button",html:t=>{var e;const i=document.createElement("div");return i.className=t.className||"",i.title=t.title||"",i.setAttribute("role",t.role||"button"),i.tabIndex=null!=(e=t.tabindex)?e:-1,i.textContent=t.label||"",i}},t);e.hook("after","setupTemplates",()=>{var t=e.settings.render.item;e.settings.render.item=(s,n)=>{var o=ft(t.call(e,s,n)),r=ft(i.html(i));return o.appendChild(r),gt(r,"mousedown",t=>{ht(t,!0)}),gt(r,"click",t=>{e.isLocked||(ht(t,!0),e.isLocked||e.shouldDelete([o],t)&&(e.removeItem(o),e.refreshOptions(!1),e.inputState()))}),o}})}),ut.define("virtual_scroll",function(){const t=this,e=t.canLoad,i=t.clearActiveOption,s=t.loadCallback;var n,o,r,l={},a=!1,c=[],d=!1,u=[],p=[];if(t.settings.shouldLoadMore||(t.settings.shouldLoadMore=()=>{if(n.clientHeight/(n.scrollHeight-n.scrollTop)>.9)return!0;if(t.activeOption){var e=t.selectable();if(Array.from(e).indexOf(t.activeOption)>=e.length-2)return!0}return!1}),!t.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method";t.settings.sortField=[{field:"$order"},{field:"$score"}];const h=e=>!(null!==t.settings.maxOptions&&"number"==typeof t.settings.maxOptions&&n.children.length>=t.settings.maxOptions)&&!(!(e in l)||!l[e]),g=(e,i)=>t.items.indexOf(i)>=0||c.indexOf(i)>=0;t.setNextUrl=(t,e)=>{l[t]=e},t.getUrl=e=>{if(e in l){const t=l[e];return l[e]=!1,t}return t.clearPagination(),t.settings.firstUrl.call(t,e)},t.clearPagination=()=>{l={}},t.hook("instead","clearActiveOption",()=>{if(!a)return i.call(t)}),t.hook("instead","canLoad",i=>i in l?h(i):e.call(t,i)),t.hook("instead","loadCallback",(e,i)=>{if(a){if(o){const i=e[0];void 0!==i&&(o.dataset.value=i[t.settings.valueField])}}else{const e=""!==t.lastValue?(e,i)=>t.items.indexOf(i)>=0||p.indexOf(i)>=0:g;t.clearOptions(e)}s.call(t,e,i),a||d||(d=!0,""===t.lastValue&&(c=Object.keys(t.options),r=l[""],u=Object.values(t.options))),a=!1}),t.hook("before","refreshOptions",()=>{t.activeOption&&"option"!==t.activeOption.getAttribute("role")&&t.setActiveOption(t.activeOption.previousElementSibling)}),t.hook("after","refreshOptions",()=>{const e=t.lastValue;var i;h(e)?(i=t.render("loading_more",{query:e}))&&(i.setAttribute("data-selectable",""),o=i):e in l&&!n.querySelector(".no-results")&&(i=t.render("no_more_results",{query:e})),i&&(((t,...e)=>{var i=vt(e);(t=Ot(t)).map(t=>{i.map(e=>{t.classList.add(e)})})})(i,t.settings.optionClass),n.append(i))});const f=()=>{d&&(t.addOptions(u),t.clearOptions(g),r&&(l[""]=r))};t.on("type",e=>{""===e&&(f(),t.refreshOptions(!1))}),t.on("dropdown_close",f),t.on("initialize",()=>{p=Object.keys(t.options),c=Object.keys(t.options),n=t.dropdown_content,t.settings.render=Object.assign({},{loading_more:()=>'<div class="loading-more-results">Loading more results ... </div>',no_more_results:()=>'<div class="no-more-results">No more results</div>'},t.settings.render),n.addEventListener("scroll",()=>{t.settings.shouldLoadMore.call(t)&&h(t.lastValue)&&(a||(a=!0,t.load.call(t,t.lastValue)))})})});export{R as addEvent,B as addSlashes,K as append,q as debounce_events,ut as default,$ as escape_html,z as getId,N as getSelection,V as get_hash,P as hash_key,M as isKeyDown,G as iterate,j as loadDebounce,H as preventDefault,D as timeout};