tom-select
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
loose: true, | ||
bugfixes: true, | ||
modules: false | ||
} | ||
] | ||
], | ||
"presets": | ||
[ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
loose: true, | ||
bugfixes: true, | ||
modules: false | ||
} | ||
], | ||
"@babel/typescript" | ||
], | ||
} |
@@ -9,3 +9,3 @@ | ||
eleventyConfig.addPassthroughCopy({'build/css':'css'}); | ||
eleventyConfig.addPassthroughCopy({'src':'esm'}); | ||
eleventyConfig.addPassthroughCopy({'build/esm':'esm'}); | ||
@@ -12,0 +12,0 @@ |
@@ -132,7 +132,2 @@ module.exports = function(config) { | ||
{ | ||
pattern: 'src/**/*', | ||
type: 'module', | ||
included: false, | ||
}, | ||
{ | ||
pattern: 'test/tests/esm-module.js', | ||
@@ -148,3 +143,9 @@ type: 'module', | ||
'test/support/*.js', | ||
'test/tests/*.js' | ||
'test/tests/*.js', | ||
{ | ||
pattern: 'build/**/*', | ||
included: false, | ||
}, | ||
], | ||
@@ -173,4 +174,7 @@ preprocessors: { | ||
browsers: browsers, | ||
singleRun: true | ||
singleRun: true, | ||
browserDisconnectTolerance: 3, | ||
browserDisconnectTimeout: 10000, | ||
browserNoActivityTimeout: 120000 | ||
}); | ||
}; |
@@ -11,3 +11,3 @@ import resolve from '@rollup/plugin-node-resolve'; // so Rollup can find `node_modules` | ||
var tom_select_path = path.resolve( 'src/tom-select.js' ); | ||
var tom_select_path = path.resolve( 'src/tom-select.ts' ); | ||
var configs = []; | ||
@@ -20,5 +20,41 @@ const banner = `/** | ||
const extensions = [ | ||
'.js', '.jsx', '.ts', '.tsx', | ||
]; | ||
var babel_config = babel({ | ||
extensions: extensions, | ||
babelHelpers: 'bundled', | ||
configFile: path.resolve(__dirname,'babel.config.json'), | ||
}); | ||
var resolve_config = resolve({ | ||
extensions: extensions, | ||
// pass custom options to the resolve plugin | ||
customResolveOptions: { | ||
moduleDirectory: 'node_modules' | ||
} | ||
}); | ||
// esm | ||
configs.push({ | ||
input: path.resolve(__dirname,'../src/tom-select.complete.ts'), | ||
output:{ | ||
dir: path.resolve(__dirname,'../build/esm'), | ||
format: 'esm', | ||
preserveModules: true, | ||
sourcemap: true, | ||
banner: banner, | ||
}, | ||
plugins:[babel_config,resolve_config] | ||
}); | ||
var terser_config = terser({ | ||
mangle: true, | ||
toplevel: true, | ||
format: { | ||
semicolons: false, | ||
comments: function (node, comment) { | ||
@@ -36,2 +72,3 @@ var text = comment.value; | ||
function createConfig( input, output, plugins ){ | ||
@@ -51,14 +88,5 @@ | ||
config.plugins = [ | ||
resolve({ | ||
// pass custom options to the resolve plugin | ||
customResolveOptions: { | ||
moduleDirectory: 'node_modules' | ||
} | ||
}), | ||
resolve_config, | ||
babel_config, | ||
commonjs(), | ||
babel({ | ||
babelHelpers: 'bundled', | ||
configFile: path.resolve(__dirname,'babel.config.json'), | ||
}), | ||
bundleSize(), | ||
@@ -68,3 +96,3 @@ visualizer({ | ||
filename: `stats/${config.output.file}.html`, | ||
}), | ||
}) | ||
]; | ||
@@ -95,3 +123,3 @@ | ||
// prevents tom-select.js from being bundled in with plugin.js umd | ||
// prevents tom-select.ts from being bundled in with plugin.js umd | ||
config.output.globals = {} | ||
@@ -107,3 +135,3 @@ config.output.globals[tom_select_path] = 'TomSelect'; | ||
files.map(function(file){ | ||
let input = path.resolve(__dirname,'../src/plugins',file,'plugin.js'); | ||
let input = path.resolve(__dirname,'../src/plugins',file,'plugin.ts'); | ||
let output = {file:`build/js/plugins/${file}.js`,'name':file}; | ||
@@ -122,8 +150,8 @@ pluginConfig( input, output); | ||
// tom-select.base | ||
configCore('src/tom-select.js','tom-select.base.js') | ||
configCore('src/tom-select.js','tom-select.base.min.js',[terser_config]); | ||
configCore('src/tom-select.ts','tom-select.base.js') | ||
configCore('src/tom-select.ts','tom-select.base.min.js',[terser_config]); | ||
// tom-select.complete | ||
configCore('src/tom-select.complete.js','tom-select.complete.js'); | ||
configCore('src/tom-select.complete.js','tom-select.complete.min.js',[terser_config]); | ||
configCore('src/tom-select.complete.ts','tom-select.complete.js'); | ||
configCore('src/tom-select.complete.ts','tom-select.complete.min.js',[terser_config]); | ||
@@ -130,0 +158,0 @@ |
@@ -8,3 +8,6 @@ { | ||
"strict": false, | ||
"target": "esnext", | ||
"module": "esnext", | ||
"noUnusedLocals": true, | ||
}, | ||
} |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -26,3 +26,3 @@ }(this, (function (TomSelect) { 'use strict'; | ||
diacritics: true, | ||
create: false, | ||
create: null, | ||
createOnBlur: false, | ||
@@ -38,3 +38,3 @@ createFilter: null, | ||
selectOnTab: false, | ||
preload: false, | ||
preload: null, | ||
allowEmptyOption: false, | ||
@@ -111,4 +111,2 @@ closeAfterSelect: false, | ||
* | ||
* @param {string} value | ||
* @returns {string|null} | ||
*/ | ||
@@ -120,3 +118,11 @@ function hash_key(value) { | ||
} | ||
/** | ||
* Prevent default | ||
* | ||
*/ | ||
function addEvent(target, type, callback, options) { | ||
target.addEventListener(type, callback, options); | ||
} | ||
function getSettings(input, settings_user) { | ||
@@ -135,3 +141,3 @@ var settings = Object.assign({}, defaults, settings_user); | ||
if (!placeholder && !settings.allowEmptyOption) { | ||
var option = input.querySelector('option[value=""]'); | ||
let option = input.querySelector('option[value=""]'); | ||
@@ -144,6 +150,7 @@ if (option) { | ||
var settings_element = { | ||
'placeholder': placeholder, | ||
'options': [], | ||
'optgroups': [], | ||
'items': [] | ||
placeholder: placeholder, | ||
options: [], | ||
optgroups: [], | ||
items: [], | ||
maxItems: null | ||
}; | ||
@@ -155,3 +162,3 @@ /** | ||
var init_select = function init_select() { | ||
var init_select = () => { | ||
var i, n, tagName, children; | ||
@@ -161,3 +168,3 @@ var options = settings_element.options; | ||
var readData = function readData(el) { | ||
var readData = el => { | ||
var data = Object.assign({}, el.dataset); // get plain object from DOMStringMap | ||
@@ -174,3 +181,3 @@ | ||
var addOption = function addOption(option, group) { | ||
var addOption = (option, group) => { | ||
var value = hash_key(option.value); | ||
@@ -211,3 +218,3 @@ if (!value && !settings.allowEmptyOption) return; // if the option already exists, it's probably been | ||
var addGroup = function addGroup(optgroup) { | ||
var addGroup = optgroup => { | ||
var i, n, id, optgroup_data, options; | ||
@@ -250,3 +257,3 @@ id = optgroup.getAttribute('label'); | ||
var init_textbox = function init_textbox() { | ||
var init_textbox = () => { | ||
var i, n, values, option; | ||
@@ -303,3 +310,3 @@ var data_raw = input.getAttribute(attr_data); | ||
var changed = false; | ||
self.input.addEventListener('change', function () { | ||
addEvent(self.input, 'change', () => { | ||
// prevent infinite loops | ||
@@ -306,0 +313,0 @@ if (changed) { |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -32,5 +32,5 @@ }(this, (function (TomSelect) { 'use strict'; | ||
TomSelect__default['default'].define('drag_drop', function (options) { | ||
var self = this; | ||
if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".'); | ||
if (this.settings.mode !== 'multi') return; | ||
var self = this; | ||
if (self.settings.mode !== 'multi') return; | ||
var orig_lock = self.lock; | ||
@@ -48,3 +48,3 @@ var orig_unlock = self.unlock; | ||
}); | ||
self.hook('after', 'setup', function () { | ||
self.hook('after', 'setup', () => { | ||
var $control = $(self.control).sortable({ | ||
@@ -54,3 +54,3 @@ items: '[data-value]', | ||
disabled: self.isLocked, | ||
start: function start(e, ui) { | ||
start: (e, ui) => { | ||
ui.placeholder.css('width', ui.helper.css('width')); | ||
@@ -61,3 +61,3 @@ $control.css({ | ||
}, | ||
stop: function stop() { | ||
stop: () => { | ||
$control.css({ | ||
@@ -64,0 +64,0 @@ overflow: 'hidden' |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -21,4 +21,3 @@ }(this, (function (TomSelect) { 'use strict'; | ||
* | ||
* @param {any} query .. should be {HTMLElement|string|JQuery} | ||
* @return {HTMLElement} | ||
* param query should be {} | ||
*/ | ||
@@ -35,6 +34,6 @@ function getDom(query) { | ||
if (query.indexOf('<') > -1) { | ||
var div = document.createElement('div'); | ||
let div = document.createElement('div'); | ||
div.innerHTML = query.trim(); // Never return a text node of whitespace as the result | ||
return div.querySelector(':first-child'); | ||
return div.firstChild; | ||
} | ||
@@ -67,7 +66,7 @@ | ||
closeClass: 'dropdown-header-close', | ||
html: function html(data) { | ||
html: data => { | ||
return '<div class="' + data.headerClass + '">' + '<div class="' + data.titleRowClass + '">' + '<span class="' + data.labelClass + '">' + data.title + '</span>' + '<a href="javascript:void(0)" class="' + data.closeClass + '">×</a>' + '</div>' + '</div>'; | ||
} | ||
}, options); | ||
self.hook('after', 'setup', function () { | ||
self.hook('after', 'setup', () => { | ||
var header = getDom(options.html(options)); | ||
@@ -74,0 +73,0 @@ self.dropdown.insertBefore(header, self.dropdown.firstChild); |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -18,2 +18,25 @@ }(this, (function (TomSelect) { 'use strict'; | ||
/** | ||
* Converts a scalar to its best string representation | ||
* for hash keys and HTML attribute values. | ||
* | ||
* Transformations: | ||
* 'str' -> 'str' | ||
* null -> '' | ||
* undefined -> '' | ||
* true -> '1' | ||
* false -> '0' | ||
* 0 -> '0' | ||
* 1 -> '1' | ||
* | ||
*/ | ||
/** | ||
* Prevent default | ||
* | ||
*/ | ||
function addEvent(target, type, callback, options) { | ||
target.addEventListener(type, callback, options); | ||
} | ||
/** | ||
* Plugin: "input_autogrow" (Tom Select) | ||
@@ -33,3 +56,3 @@ * | ||
var self = this; | ||
self.hook('after', 'setup', function () { | ||
self.hook('after', 'setup', () => { | ||
var test_input = document.createElement('span'); | ||
@@ -41,4 +64,4 @@ var control = this.control_input; | ||
for (var i = 0, n = transfer_styles.length; i < n; i++) { | ||
var style_name = transfer_styles[i]; | ||
for (let i = 0, n = transfer_styles.length; i < n; i++) { | ||
let style_name = transfer_styles[i]; | ||
test_input.style[style_name] = control.style[style_name]; | ||
@@ -52,3 +75,3 @@ } | ||
var resize = function resize() { | ||
var resize = () => { | ||
test_input.textContent = control.value; | ||
@@ -58,6 +81,6 @@ control.style.width = test_input.clientWidth + 'px'; | ||
control.addEventListener('input', resize); | ||
control.addEventListener('keyup', resize); | ||
control.addEventListener('blur', resize); | ||
control.addEventListener('update', resize); | ||
addEvent(control, 'input', resize); | ||
addEvent(control, 'keyup', resize); | ||
addEvent(control, 'blur', resize); | ||
addEvent(control, 'update', resize); | ||
}); | ||
@@ -64,0 +87,0 @@ }); |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -31,5 +31,5 @@ }(this, (function (TomSelect) { 'use strict'; | ||
TomSelect__default['default'].define('no_backspace_delete', function (options) { | ||
this.hook('instead', 'setActiveItem', function () {}); | ||
this.hook('instead', 'selectAll', function () {}); | ||
this.hook('instead', 'deleteSelection', function () {}); | ||
this.hook('instead', 'setActiveItem', () => {}); | ||
this.hook('instead', 'selectAll', () => {}); | ||
this.hook('instead', 'deleteSelection', () => {}); | ||
}); | ||
@@ -36,0 +36,0 @@ |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -17,5 +17,5 @@ }(this, (function (TomSelect) { 'use strict'; | ||
var KEY_LEFT = 37; | ||
var KEY_RIGHT = 39; | ||
var IS_MAC = /Mac/.test(navigator.userAgent); | ||
const KEY_LEFT = 37; | ||
const KEY_RIGHT = 39; | ||
const IS_MAC = /Mac/.test(navigator.userAgent); | ||
// ctrl key or apple key for ma | ||
@@ -27,4 +27,3 @@ | ||
* | ||
* @param {any} query .. should be {HTMLElement|string|JQuery} | ||
* @return {HTMLElement} | ||
* param query should be {} | ||
*/ | ||
@@ -35,6 +34,2 @@ /** | ||
* | ||
* param {HTMLElement} target | ||
* @param {string} selector | ||
* @param {HTMLElement} [wrapper=null] | ||
* return {HTMLElement} | ||
*/ | ||
@@ -58,5 +53,2 @@ | ||
* | ||
* @param {Element} el | ||
* @param {string} [amongst=null] | ||
* @return {number} | ||
*/ | ||
@@ -63,0 +55,0 @@ |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -21,4 +21,3 @@ }(this, (function (TomSelect) { 'use strict'; | ||
* | ||
* @param {any} query .. should be {HTMLElement|string|JQuery} | ||
* @return {HTMLElement} | ||
* param query should be {} | ||
*/ | ||
@@ -35,6 +34,6 @@ function getDom(query) { | ||
if (query.indexOf('<') > -1) { | ||
var div = document.createElement('div'); | ||
let div = document.createElement('div'); | ||
div.innerHTML = query.trim(); // Never return a text node of whitespace as the result | ||
return div.querySelector(':first-child'); | ||
return div.firstChild; | ||
} | ||
@@ -58,4 +57,2 @@ | ||
* | ||
* @param {string} value | ||
* @returns {string|null} | ||
*/ | ||
@@ -65,4 +62,2 @@ /** | ||
* | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
@@ -73,4 +68,26 @@ | ||
} | ||
/** | ||
* Prevent default | ||
* | ||
*/ | ||
function preventDefault(evt, stop = false) { | ||
if (evt) { | ||
evt.preventDefault(); | ||
if (stop) { | ||
evt.stopPropagation(); | ||
} | ||
} | ||
} | ||
/** | ||
* Prevent default | ||
* | ||
*/ | ||
function addEvent(target, type, callback, options) { | ||
target.addEventListener(type, callback, options); | ||
} | ||
/** | ||
* Plugin: "remove_button" (Tom Select) | ||
@@ -104,3 +121,3 @@ * Copyright (c) contributors | ||
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; | ||
self.hook('after', 'setupTemplates', function () { | ||
self.hook('after', 'setupTemplates', () => { | ||
var orig_render_item = self.settings.render.item; | ||
@@ -112,14 +129,8 @@ | ||
rendered.appendChild(close_button); | ||
close_button.addEventListener('mousedown', function (evt) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
addEvent(close_button, 'mousedown', evt => { | ||
preventDefault(evt, true); | ||
}); | ||
close_button.addEventListener('click', function (evt) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); // propagating will trigger the dropdown to show for single mode | ||
if (self.settings.mode !== 'single') { | ||
evt.stopPropagation(); | ||
} | ||
addEvent(close_button, 'click', evt => { | ||
// propagating will trigger the dropdown to show for single mode | ||
preventDefault(evt, true); | ||
if (self.isLocked) return; | ||
@@ -126,0 +137,0 @@ var value = rendered.dataset.value; |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -7,4 +7,4 @@ */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.js')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.js'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../tom-select.ts')) : | ||
typeof define === 'function' && define.amd ? define(['../../tom-select.ts'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TomSelect)); | ||
@@ -17,7 +17,36 @@ }(this, (function (TomSelect) { 'use strict'; | ||
var KEY_BACKSPACE = 8; | ||
var IS_MAC = /Mac/.test(navigator.userAgent); | ||
const KEY_BACKSPACE = 8; | ||
const IS_MAC = /Mac/.test(navigator.userAgent); | ||
// ctrl key or apple key for ma | ||
/** | ||
* Converts a scalar to its best string representation | ||
* for hash keys and HTML attribute values. | ||
* | ||
* Transformations: | ||
* 'str' -> 'str' | ||
* null -> '' | ||
* undefined -> '' | ||
* true -> '1' | ||
* false -> '0' | ||
* 0 -> '0' | ||
* 1 -> '1' | ||
* | ||
*/ | ||
/** | ||
* Prevent default | ||
* | ||
*/ | ||
function preventDefault(evt, stop = false) { | ||
if (evt) { | ||
evt.preventDefault(); | ||
if (stop) { | ||
evt.stopPropagation(); | ||
} | ||
} | ||
} | ||
/** | ||
* Plugin: "restore_on_backspace" (Tom Select) | ||
@@ -58,3 +87,3 @@ * Copyright (c) contributors | ||
evt.preventDefault(); | ||
preventDefault(evt); | ||
return; | ||
@@ -61,0 +90,0 @@ } |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).TomSelect=e()}(this,(function(){"use strict";function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var e=function(){function t(){this._events={}}var e=t.prototype;return e.on=function(t,e){this._events[t]=this._events[t]||[],this._events[t].push(e)},e.off=function(t,e){var i=arguments.length;return 0===i?delete this._events:1===i?delete this._events[t]:(this._events=this._events||{},void(t in this._events!=!1&&this._events[t].splice(this._events[t].indexOf(e),1)))},e.trigger=function(t){if(this._events=this._events||{},t in this._events!=!1)for(var e=0;e<this._events[t].length;e++)this._events[t][e].apply(this,Array.prototype.slice.call(arguments,1))},t}();var i=function(t,e){return"number"==typeof t&&"number"==typeof e?t>e?1:t<e?-1:0:(t=o(String(t||"")))>(e=o(String(e||"")))?1:e>t?-1:0},n=function(t,e,i){if(t&&e){if(!i)return t[e];for(var n=e.split(".");n.length&&(t=t[n.shift()]););return t}},s={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶ]"},o=function(){var t,e,i,n,o="",r={};for(i in s)if(s.hasOwnProperty(i))for(o+=n=s[i].substring(2,s[i].length-1),t=0,e=n.length;t<e;t++)r[n.charAt(t)]=i;var l=new RegExp("["+o+"]","g");return function(t){return t.replace(l,(function(t){return r[t]})).toLowerCase()}}(),r=function(){function t(t,e){this.items=t,this.settings=e||{diacritics:!0}}var e=t.prototype;return e.tokenize=function(t,e){if(!(t=String(t||"").toLowerCase().trim())||!t.length)return[];var i,n,o,r,l=[],a=t.split(/ +/);for(i=0,n=a.length;i<n;i++){if(o=(a[i]+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.settings.diacritics)for(r in s)s.hasOwnProperty(r)&&(o=o.replace(new RegExp(r,"g"),s[r]));e&&(o="\\b"+o),l.push({string:a[i],regex:new RegExp(o,"i")})}return l},e.iterator=function(t,e){var i;i=Array.isArray(t)?Array.prototype.forEach||function(t){for(var e=0,i=this.length;e<i;e++)t(this[e],e,this)}:function(t){for(var e in this)this.hasOwnProperty(e)&&t(this[e],e,this)},i.apply(t,[e])},e.getScoreFunction=function(t,e){var i,s,o,r;void 0===e&&(e=null),t=this.prepareSearch(t,e),s=t.tokens,i=t.options.fields,o=s.length,r=t.options.nesting;var l,a=function(t,e){var i,n;return t?-1===(n=(t=String(t||"")).search(e.regex))?0:(i=e.string.length/t.length,0===n&&(i+=.5),i):0},u=(l=i.length)?1===l?function(t,e){return a(n(e,i[0],r),t)}:function(t,e){for(var s=0,o=0;s<l;s++)o+=a(n(e,i[s],r),t);return o/l}:function(){return 0};return o?1===o?function(t){return u(s[0],t)}:"and"===t.options.conjunction?function(t){for(var e,i=0,n=0;i<o;i++){if((e=u(s[i],t))<=0)return 0;n+=e}return n/o}:function(t){for(var e=0,i=0;e<o;e++)i+=u(s[e],t);return i/o}:function(){return 0}},e.getSortFunction=function(t,e){var s,o,r,l,a,u,c,p,d,h,g;if(g=!(t=(r=this).prepareSearch(t,e)).query&&e.sort_empty||e.sort,d=function(t,i){return"$score"===t?i.score:n(r.items[i.id],t,e.nesting)},a=[],g)for(s=0,o=g.length;s<o;s++)(t.query||"$score"!==g[s].field)&&a.push(g[s]);if(t.query){for(h=!0,s=0,o=a.length;s<o;s++)if("$score"===a[s].field){h=!1;break}h&&a.unshift({field:"$score",direction:"desc"})}else for(s=0,o=a.length;s<o;s++)if("$score"===a[s].field){a.splice(s,1);break}for(p=[],s=0,o=a.length;s<o;s++)p.push("desc"===a[s].direction?-1:1);return(u=a.length)?1===u?(l=a[0].field,c=p[0],function(t,e){return c*i(d(l,t),d(l,e))}):function(t,e){var n,s,o;for(n=0;n<u;n++)if(o=a[n].field,s=p[n]*i(d(o,t),d(o,e)))return s;return 0}:null},e.prepareSearch=function(t,e){if("object"==typeof t)return t;var i=(e=Object.assign({},e)).fields,n=e.sort,s=e.sort_empty;return i&&!Array.isArray(i)&&(e.fields=[i]),n&&!Array.isArray(n)&&(e.sort=[n]),s&&!Array.isArray(s)&&(e.sort_empty=[s]),{options:e,query:String(t||"").toLowerCase(),tokens:this.tokenize(t,e.respect_word_boundaries),total:0,items:[]}},e.search=function(t,e){var i,n,s,o,r=this;return n=this.prepareSearch(t,e),e=n.options,t=n.query,o=e.score||r.getScoreFunction(n),t.length?r.iterator(r.items,(function(t,s){i=o(t),(!1===e.filter||i>0)&&n.items.push({score:i,id:s})})):r.iterator(r.items,(function(t,e){n.items.push({score:1,id:e})})),(s=r.getSortFunction(n,e))&&n.items.sort(s),n.total=n.items.length,"number"==typeof e.limit&&(n.items=n.items.slice(0,e.limit)),n},t}();function l(t,e){if("string"!=typeof e||e.length){var i="string"==typeof e?new RegExp(e,"i"):e;!function t(e){var n=0;if(3===e.nodeType){var s=e.data.search(i);if(s>=0&&e.data.length>0){var o=e.data.match(i),r=document.createElement("span");r.className="highlight";var l=e.splitText(s),a=(l.splitText(o[0].length),l.cloneNode(!0));r.appendChild(a),l.parentNode.replaceChild(r,l),n=1}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&("highlight"!==e.className||"SPAN"!==e.tagName))for(var u=0;u<e.childNodes.length;++u)u+=t(e.childNodes[u]);return n}(t)}}var a,u=/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey",c={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,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-control",inputClass:"ts-input",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:null,copyClassesToDropdown:!0,render:{}};function p(t){return null==t?null:"boolean"==typeof t?t?"1":"0":t+""}function d(t){return(t+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function h(t,e,i){var n,s=t.trigger,o={};for(n in t.trigger=function(){var i=arguments[0];if(-1===e.indexOf(i))return s.apply(t,arguments);o[i]=arguments},i.apply(t,[]),t.trigger=s,o)o.hasOwnProperty(n)&&s.apply(t,o[n])}function g(t){if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(t.indexOf("<")>-1){var e=document.createElement("div");return e.innerHTML=t.trim(),e.querySelector(":first-child")}return document.querySelector(t)}function f(t,e){var i=document.createEvent("HTMLEvents");i.initEvent(e,!0,!1),t.dispatchEvent(i)}function v(t,e){Object.keys(e).forEach((function(i){t.style[i]=e[i]}))}function m(t){var e=O.apply(null,arguments);(t=w(t)).map((function(t){e.map((function(e){t.classList.add(e)}))}))}function y(t){var e=O.apply(null,arguments);(t=w(t)).map((function(t){e.map((function(e){t.classList.remove(e)}))}))}function O(){for(var t=[],e=1;e<arguments.length;e++){var i=arguments[e];"string"==typeof i&&(i=i.trim().split(/[\11\12\14\15\40]/)),Array.isArray(i)&&(t=t.concat(i))}return t.filter(Boolean)}function w(t){return Array.isArray(t)||(t=[t]),t}function b(t,e,i){if(!i||i.contains(t))for(;t&&t.matches;){if(t.matches(e))return t;t=t.parentNode}}function C(t,e){return e>0?t[t.length-1]:t[0]}function A(t,e){if(!t)return-1;e=e||t.nodeName;for(var i=0;t=t.previousElementSibling;)t.matches(e)&&i++;return i}return function(e){function i(t,i){var n,s,o=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n=e.call(this)||this);if((t=g(t)).tomselect)throw new Error("Tom Select already initialized on this element");return t.tomselect=o,n.control_input=null,n.wrapper=null,n.dropdown=null,n._destroy=null,n.control=null,n.sifter=null,n.dropdown_content=null,s=(window.getComputedStyle&&window.getComputedStyle(t,null)).getPropertyValue("direction"),n.order=0,n.settings=function(t,e){var i=Object.assign({},c,e),n=i.dataAttr,s=i.labelField,o=i.valueField,r=i.disabledField,l=i.optgroupField,a=i.optgroupLabelField,u=i.optgroupValueField,d=t.tagName.toLowerCase(),h=t.getAttribute("placeholder")||t.getAttribute("data-placeholder");if(!h&&!i.allowEmptyOption){var g=t.querySelector('option[value=""]');g&&(h=g.textContent)}var f={placeholder:h,options:[],optgroups:[],items:[]};return"select"===d?function(){var e,c,d,h,g=f.options,v={},m=function(t){var e=Object.assign({},t.dataset),i=n&&e[n];return"string"==typeof i&&i.length&&(e=Object.assign(e,JSON.parse(i))),e},y=function(t,e){var n=p(t.value);if(n||i.allowEmptyOption)if(v.hasOwnProperty(n)){if(e){var a=v[n][l];a?Array.isArray(a)?a.push(e):v[n][l]=[a,e]:v[n][l]=e}}else{var u=m(t);u[s]=u[s]||t.textContent,u[o]=u[o]||n,u[r]=u[r]||t.disabled,u[l]=u[l]||e,v[n]=u,g.push(u),t.selected&&f.items.push(n)}},O=function(t){var e,i,n,s,o;for((n=t.getAttribute("label"))&&((s=m(t))[a]=n,s[u]=n,s[r]=t.disabled,f.optgroups.push(s)),e=0,i=(o=t.children).length;e<i;e++)y(o[e],n)};for(f.maxItems=t.hasAttribute("multiple")?null:1,e=0,c=(h=t.children).length;e<c;e++)"optgroup"===(d=h[e].tagName.toLowerCase())?O(h[e]):"option"===d&&y(h[e])}():function(){var e,r,l,a,u=t.getAttribute(n);if(u)for(f.options=JSON.parse(u),e=0,r=f.options.length;e<r;e++)f.items.push(f.options[e][o]);else{var c=t.value.trim()||"";if(!i.allowEmptyOption&&!c.length)return;for(e=0,r=(l=c.split(i.delimiter)).length;e<r;e++)(a={})[s]=l[e],a[o]=l[e],f.options.push(a);f.items=l}}(),Object.assign({},c,f,e)}(t,i),n.input=t,n.tabIndex=t.getAttribute("tabindex")||"",n.is_select_tag="select"===t.tagName.toLowerCase(),n.rtl=/rtl/i.test(s),n.highlightedValue=null,n.isBlurring=!1,n.isOpen=!1,n.isDisabled=!1,n.isRequired=t.required,n.isInvalid=!1,n.isLocked=!1,n.isFocused=!1,n.isInputHidden=!1,n.isSetup=!1,n.ignoreFocus=!1,n.ignoreBlur=!1,n.ignoreHover=!1,n.hasOptions=!1,n.currentResults=null,n.lastValue="",n.caretPos=0,n.loading=0,n.loadedSearches={},n.activeOption=null,n.activeItems=[],n.optgroups={},n.options={},n.userOptions={},n.items=[],n.renderCache={item:{},option:{}},o.settings.load&&o.settings.loadThrottle&&(o.settings.load=o.loadDebounce(o.settings.load,o.settings.loadThrottle)),o.sifter=new r(n.options,{diacritics:o.settings.diacritics}),o.setupOptions(o.settings.options,o.settings.optgroups),delete o.settings.optgroups,delete o.settings.options,o.settings.mode=o.settings.mode||(1===o.settings.maxItems?"single":"multi"),"boolean"!=typeof o.settings.hideSelected&&(o.settings.hideSelected="multi"===o.settings.mode),"string"==typeof o.settings.createFilter&&(o.settings.createFilter=new RegExp(o.settings.createFilter)),o.initializePlugins(o.settings.plugins),o.setupCallbacks(),o.setupTemplates(),o.setup(),n}t(i,e);var n=i.prototype;return n.setup=function(){var t,e,i,n,s,o,r,l,a,u=this,c=u.settings,p=u.input,d={passive:!0};if(o=u.settings.mode,r=p.getAttribute("class")||"",m(t=g("<div>"),c.wrapperClass,r,o),m(e=g('<div class="items">'),c.inputClass),t.append(e),m(n=u.render("dropdown"),c.dropdownClass,o),m(s=g('<div style="scroll-behavior: smooth;">'),c.dropdownContentClass),n.append(s),g(c.dropdownParent||t).appendChild(n),c.controlInput)i=g(c.controlInput);else{i=g('<input type="text" autocomplete="off" />');for(var h=["autocorrect","autocapitalize","autocomplete"],f=0;f<h.length;f++){var v=h[f];p.getAttribute(v)&&i.setAttribute(v,p.getAttribute(v))}}if(c.controlInput||(i.setAttribute("tabindex",p.disabled?"-1":u.tabIndex),e.appendChild(i)),a=p.getAttribute("id")){i.setAttribute("id",a+"-tomselected");var y=document.querySelector("label[for='"+a+"']");y&&y.setAttribute("for",a+"-tomselected")}if(u.settings.copyClassesToDropdown&&m(n,r),t.style.width=p.style.width,u.plugins.names.length&&(l="plugin-"+u.plugins.names.join(" plugin-"),m([t,n],l)),(null===c.maxItems||c.maxItems>1)&&u.is_select_tag&&p.setAttribute("multiple","multiple"),u.settings.placeholder&&i.setAttribute("placeholder",c.placeholder),!u.settings.splitOn&&u.settings.delimiter){var O=u.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");u.settings.splitOn=new RegExp("\\s*"+O+"+\\s*")}u.control=e,u.control_input=i,u.wrapper=t,u.dropdown=n,u.dropdown_content=s,u.control_input.type=p.type,n.addEventListener("mouseenter",(function(t){var e=b(t.target,"[data-selectable]",n);if(e)return u.onOptionHover.call(u,t,e)}),!0),e.addEventListener("mousedown",(function(t){var i=b(t.target,"."+u.settings.itemClass,e);return i?u.onItemSelect.call(u,t,i):u.onMouseDown.call(u,t)})),e.addEventListener("click",(function(){u.onClick.apply(u,arguments)})),i.addEventListener("mousedown",(function(t){t.stopPropagation()})),i.addEventListener("keydown",(function(){return u.onKeyDown.apply(u,arguments)})),i.addEventListener("keyup",(function(){return u.onKeyUp.apply(u,arguments)})),i.addEventListener("keypress",(function(){return u.onKeyPress.apply(u,arguments)})),i.addEventListener("resize",(function(){u.positionDropdown.apply(u,[])}),d),i.addEventListener("blur",(function(){return u.onBlur.apply(u,arguments)})),i.addEventListener("focus",(function(){return u.ignoreBlur=!1,u.onFocus.apply(u,arguments)})),i.addEventListener("paste",(function(){return u.onPaste.apply(u,arguments)}));var w=function(t){var e=b(t.target,"[data-selectable]",u.dropdown);e||u.wrapper.contains(t.target)?(t.preventDefault(),t.stopPropagation(),e&&u.onOptionSelect(t,e)):u.isFocused&&u.blur(t.target)},C=function(){u.isOpen&&u.positionDropdown.apply(u,arguments)},A=function(){u.ignoreHover=!1};document.addEventListener("mousedown",w),window.addEventListener("sroll",C,d),window.addEventListener("resize",C,d),window.addEventListener("mousemove",A,d),u._destroy=function(){document.removeEventListener("mousedown",w),window.removeEventListener("mousemove",A),window.removeEventListener("sroll",C),window.removeEventListener("resize",C)};for(var I=[];p.children.length>0;)I.push(p.children[0]),p.children[0].remove();this.revertSettings={children:I,tabindex:p.getAttribute("tabindex")},p.setAttribute("tabindex",-1),p.setAttribute("hidden","hidden"),p.insertAdjacentElement("afterend",u.wrapper),u.setValue(c.items),delete c.items,p.addEventListener("invalid",(function(t){t.preventDefault(),u.isInvalid||(u.isInvalid=!0,u.refreshState())})),u.updateOriginalInput(),u.refreshItems(),u.refreshState(),u.isSetup=!0,p.disabled&&u.disable(),u.on("change",this.onChange),m(p,"tomselected"),u.trigger("initialize"),!0===c.preload&&u.onSearchChange("")},n.setupOptions=function(t,e){var i,n;for(e=e||[],i=0,n=(t=t||[]).length;i<n;i++)this.registerOption(t[i]);for(i=0,n=e.length;i<n;i++)this.registerOptionGroup(e[i])},n.setupTemplates=function(){var t=this,e=t.settings.labelField,i=t.settings.optgroupLabelField,n={optgroup:function(t,e){var i=document.createElement("div");return i.className="optgroup",i.appendChild(t.options),i},optgroup_header:function(t,e){return'<div class="optgroup-header">'+e(t[i])+"</div>"},option:function(t,i){return"<div>"+i(t[e])+"</div>"},item:function(t,i){return"<div>"+i(t[e])+"</div>"},option_create:function(t,e){return'<div class="create">Add <strong>'+e(t.input)+"</strong>…</div>"},no_results:function(t,e){return'<div class="no-results">No results found</div>'},loading:function(t,e){return'<div class="spinner"></div>'},dropdown:function(){return'<div style="display:none"></div>'}};t.settings.render=Object.assign({},n,t.settings.render)},n.setupCallbacks=function(){var t,e,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",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)},n.onClick=function(t){var e=this;e.isFocused&&e.isOpen||(e.focus(),t.preventDefault())},n.onMouseDown=function(t){var e=this;if(e.isFocused){if(t.target!==e.control_input)return"single"===e.settings.mode?e.isOpen?e.close():e.open():e.setActiveItem(),!1}else window.setTimeout((function(){e.focus()}),0)},n.onChange=function(){f(this.input,"change")},n.onPaste=function(t){var e=this;e.isFull()||e.isInputHidden||e.isLocked?t.preventDefault():e.settings.splitOn&&setTimeout((function(){var t=e.inputValue();if(t.match(e.settings.splitOn))for(var i=t.trim().split(e.settings.splitOn),n=0,s=i.length;n<s;n++)e.createItem(i[n])}),0)},n.onKeyPress=function(t){if(this.isLocked)return t&&t.preventDefault();var e=String.fromCharCode(t.keyCode||t.which);return this.settings.create&&"multi"===this.settings.mode&&e===this.settings.delimiter?(this.createItem(),t.preventDefault(),!1):void 0},n.onKeyDown=function(t){var e=this;t.target,e.control_input;if(e.ignoreHover=!0,e.isLocked)9!==t.keyCode&&t.preventDefault();else{switch(t.keyCode){case 65:if(e.isKeyDown(u,t))return void e.selectAll();break;case 27:return void(e.isOpen&&(t.preventDefault(),t.stopPropagation(),e.close()));case 40:if(!e.isOpen&&e.hasOptions)e.open();else if(e.activeOption){var i=e.getAdjacent(e.activeOption,1);i&&e.setActiveOption(i,!0)}return void t.preventDefault();case 38:if(e.activeOption){var n=e.getAdjacent(e.activeOption,-1);n&&e.setActiveOption(n,!0)}return void t.preventDefault();case 13:return void(e.isOpen&&e.activeOption&&(e.onOptionSelect(t,e.activeOption),t.preventDefault()));case 37:return void e.advanceSelection(-1,t);case 39:return void e.advanceSelection(1,t);case 9:return e.settings.selectOnTab&&e.isOpen&&e.activeOption&&(e.onOptionSelect(t,e.activeOption),t.preventDefault()),void(e.settings.create&&e.createItem()&&t.preventDefault());case 8:case 46:return void e.deleteSelection(t)}!e.isInputHidden||e.isKeyDown(u,t)||t.preventDefault()}},n.onKeyUp=function(t){var e=this;if(e.isLocked)return t&&t.preventDefault();var i=e.inputValue();e.lastValue!==i&&(e.lastValue=i,e.onSearchChange(i),e.refreshOptions(),e.trigger("type",i))},n.onSearchChange=function(t){var e=this,i=e.settings.load;i&&(e.loadedSearches.hasOwnProperty(t)||(e.loadedSearches[t]=!0,e.load((function(n){i.apply(e,[t,n])}))))},n.onFocus=function(t){void 0===t&&(t=null);var e=this,i=e.isFocused;if(e.isDisabled)return e.blur(),t&&t.preventDefault(),!1;e.ignoreFocus||(e.isFocused=!0,"focus"===e.settings.preload&&e.onSearchChange(""),i||e.trigger("focus"),e.activeItems.length||(e.showInput(),e.setActiveItem(),e.refreshOptions(!!e.settings.openOnFocus)),e.refreshState())},n.onBlur=function(t,e){var i=this;if(i.isFocused){if(i.isFocused=!1,i.ignoreFocus=!1,!i.ignoreBlur&&document.activeElement===i.dropdown_content)return i.ignoreBlur=!0,void i.onFocus(t);var n=function(){i.close(),i.setActiveItem(),i.setActiveOption(),i.setCaret(i.items.length),i.refreshState(),e&&e.focus&&e.focus(),i.isBlurring=!1,i.trigger("blur")};i.isBlurring=!0,i.settings.create&&i.settings.createOnBlur?i.createItem(null,!1,n):n()}},n.onOptionHover=function(t,e){this.ignoreHover||this.setActiveOption(e,!1)},n.onOptionSelect=function(t,e){var i,n=this;e&&(e.parentElement&&e.parentElement.matches("[data-disabled]")||(e.classList.contains("create")?n.createItem(null,!0,(function(){n.settings.closeAfterSelect&&n.close()})):void 0!==(i=e.dataset.value)&&(n.lastQuery=null,n.addItem(i),n.settings.closeAfterSelect?n.close():!n.settings.hideSelected&&t.type&&/mouse/.test(t.type)&&n.setActiveOption(n.getOption(i)))))},n.onItemSelect=function(t,e){var i=this;i.isLocked||"multi"===i.settings.mode&&(t.preventDefault(),i.setActiveItem(e,t))},n.load=function(t){var e=this;m(e.wrapper,e.settings.loadingClass),e.loading++,t.call(e,(function(t,i){e.loading=Math.max(e.loading-1,0),e.lastQuery=null,e.setupOptions(t,i),e.refreshOptions(e.isFocused&&!e.isInputHidden),e.loading||y(e.wrapper,e.settings.loadingClass),e.trigger("load",t)}))},n.loadDebounce=function(t,e){var i;return function(){var n=this,s=arguments;i&&(n.loading=Math.max(n.loading-1,0)),window.clearTimeout(i),i=window.setTimeout((function(){i=null,t.apply(n,s)}),e)}},n.setTextboxValue=function(t){var e=this.control_input;e.value!==t&&(e.value=t,f(e,"update"),this.lastValue=t)},n.getValue=function(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)},n.setValue=function(t,e){void 0===e&&(e=!1),h(this,e?[]:["change"],(function(){this.clear(e),this.addItems(t,e)}))},n.setActiveItem=function(t,e){var i,n,s,o,r,l;if(void 0===t&&(t=null),void 0===e&&(e=null),"single"!==this.settings.mode){if(!t)return y(this.activeItems,"active"),this.activeItems=[],void(this.isFocused&&this.showInput());if("mousedown"===(i=e&&e.type.toLowerCase())&&this.isKeyDown("shiftKey",e)&&this.activeItems.length){for(l=this.getLastActive(),(s=Array.prototype.indexOf.call(this.control.children,l))>(o=Array.prototype.indexOf.call(this.control.children,t))&&(r=s,s=o,o=r),n=s;n<=o;n++)t=this.control.children[n],-1===this.activeItems.indexOf(t)&&this.setActiveItemClass(t);e.preventDefault()}else"mousedown"===i&&this.isKeyDown(u,e)||"keydown"===i&&this.isKeyDown("shiftKey",e)?t.classList.contains("active")?this.removeActiveItem(t):this.setActiveItemClass(t):(y(this.activeItems,"active"),this.activeItems=[],this.setActiveItemClass(t));this.hideInput(),this.isFocused||this.focus()}},n.setActiveItemClass=function(t){var e=this.control.querySelector(".last-active");e&&y(e,"last-active"),m(t,"active last-active"),-1==this.activeItems.indexOf(t)&&this.activeItems.push(t)},n.removeActiveItem=function(t){var e=this.activeItems.indexOf(t);this.activeItems.splice(e,1),y(t,"active")},n.setActiveOption=function(t,e){var i,n,s;if(void 0===t&&(t=null),void 0===e&&(e=!1),t!==this.activeOption&&(this.activeOption&&y(this.activeOption,"active"),this.activeOption=null,t&&(this.activeOption=t,m(t,"active"),e))){i=this.dropdown_content.clientHeight;var o=this.dropdown_content.scrollTop||0;n=this.activeOption.offsetHeight,(s=this.activeOption.getBoundingClientRect().top-this.dropdown_content.getBoundingClientRect().top+o)+n>i+o?this.dropdown_content.scrollTop=s-i+n:s<o&&(this.dropdown_content.scrollTop=s)}},n.selectAll=function(){"single"!==this.settings.mode&&(this.activeItems=this.controlChildren(),this.activeItems.length&&(m(this.activeItems,"active"),this.hideInput(),this.close()),this.focus())},n.hideInput=function(){this.settings.controlInput||(this.setTextboxValue(""),v(this.control_input,{opacity:0,position:"absolute",left:(this.rtl?1e4:-1e4)+"px"}),this.isInputHidden=!0)},n.showInput=function(){this.settings.controlInput||(v(this.control_input,{opacity:1,position:"relative",left:0}),this.isInputHidden=!1)},n.inputValue=function(){return this.control_input.value.trim()},n.focus=function(){var t=this;t.isDisabled||(t.ignoreFocus=!0,t.control_input.focus(),window.setTimeout((function(){t.ignoreFocus=!1,t.onFocus()}),0))},n.blur=function(t){void 0===t&&(t=null),this.control_input.blur(),this.onBlur(null,t)},n.getScoreFunction=function(t){return this.sifter.getScoreFunction(t,this.getSearchOptions())},n.getSearchOptions=function(){var t=this.settings,e=t.sortField;return"string"==typeof e&&(e=[{field:e}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}},n.search=function(t){var e,i,n,s=this,o=s.settings,r=this.getSearchOptions();if(o.score&&"function"!=typeof(n=s.settings.score.call(this,t)))throw new Error('Tom Select "score" setting must be a function that returns a function');if(t!==s.lastQuery?(s.lastQuery=t,i=s.sifter.search(t,Object.assign(r,{score:n})),s.currentResults=i):i=Object.assign({},s.currentResults),o.hideSelected)for(e=i.items.length-1;e>=0;e--)-1!==s.items.indexOf(p(i.items[e].id))&&i.items.splice(e,1);return i},n.refreshOptions=function(t){var e,i,n,s,o,r,a,u,c,d,h,g,f;void 0===t&&(t=!0);var v,O=this,w=O.inputValue(),b=O.search(w),C=O.activeOption&&p(O.activeOption.dataset.value),A=!1;for(s=b.items.length,"number"==typeof O.settings.maxOptions&&(s=Math.min(s,O.settings.maxOptions)),s>0&&(A=!0),o={},r=[],e=0;e<s;e++){var I=O.options[b.items[e].id],_=p(I[O.settings.valueField]),S=O.getOption(_);for(S||(S=O.render("option",I)),a=I[O.settings.optgroupField]||"",i=0,n=(u=Array.isArray(a)?a:[a])&&u.length;i<n;i++)a=u[i],O.optgroups.hasOwnProperty(a)||(a=""),o.hasOwnProperty(a)||(o[a]=document.createDocumentFragment(),r.push(a)),i>0&&y(S=S.cloneNode(!0),"active"),o[a].appendChild(S)}for(this.settings.lockOptgroupOrder&&r.sort((function(t,e){return(O.optgroups[t].$order||0)-(O.optgroups[e].$order||0)})),c=document.createDocumentFragment(),e=0,s=r.length;e<s;e++)if(a=r[e],O.optgroups.hasOwnProperty(a)&&o[a].children.length){var F=document.createDocumentFragment();F.appendChild(O.render("optgroup_header",O.optgroups[a])),F.appendChild(o[a]);var x=O.render("optgroup",{group:O.optgroups[a],options:F});c.appendChild(x)}else c.appendChild(o[a]);if(O.dropdown_content.innerHTML="",O.dropdown_content.appendChild(c),O.settings.highlight&&(O.dropdown_content,v=document.querySelectorAll("span.highlight"),Array.prototype.forEach.call(v,(function(t,e){var i=t.parentNode;i.replaceChild(t.firstChild,t),i.normalize()})),b.query.length&&b.tokens.length))for(e=0,s=b.tokens.length;e<s;e++)l(O.dropdown_content,b.tokens[e].regex);if(!O.settings.hideSelected)for(e=0,s=O.items.length;e<s;e++){var L=O.getOption(O.items[e]);L&&m(L,"selected")}var D=function(t){A=!0;var e=O.render(t,{input:w});return O.dropdown_content.insertBefore(e,O.dropdown_content.firstChild),e};if(O.loading?D("loading"):0===b.items.length&&O.settings.render.no_results&&w.length&&D("no_results"),(d=O.canCreate(w))&&(f=D("option_create")),O.hasOptions=b.items.length>0||d,A){if(b.items.length>0)if((g=C&&O.getOption(C))&&O.dropdown_content.contains(g))h=g;else if("single"===O.settings.mode&&O.items.length)h=O.getOption(O.items[0]);else{var E=0;f&&!O.settings.addPrecedence&&(E=1),h=O.selectable()[E]}else h=f;O.setActiveOption(h),t&&!O.isOpen&&O.open()}else O.setActiveOption(),t&&O.isOpen&&O.close()},n.selectable=function(){return this.dropdown_content.querySelectorAll("[data-selectable]")},n.addOption=function(t){var e,i,n,s=this;if(Array.isArray(t))for(e=0,i=t.length;e<i;e++)s.addOption(t[e]);else(n=s.registerOption(t))&&(s.userOptions[n]=!0,s.lastQuery=null,s.trigger("option_add",n,t))},n.registerOption=function(t){var e=p(t[this.settings.valueField]);return null!=e&&!this.options.hasOwnProperty(e)&&(t.$order=t.$order||++this.order,this.options[e]=t,e)},n.registerOptionGroup=function(t){var e=p(t[this.settings.optgroupValueField]);return!!e&&(t.$order=t.$order||++this.order,this.optgroups[e]=t,e)},n.addOptionGroup=function(t,e){var i;e[this.settings.optgroupValueField]=t,(i=this.registerOptionGroup(e))&&this.trigger("optgroup_add",i,e)},n.removeOptionGroup=function(t){this.optgroups.hasOwnProperty(t)&&(delete this.optgroups[t],this.clearCache(),this.trigger("optgroup_remove",t))},n.clearOptionGroups=function(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")},n.updateOption=function(t,e){var i,n,s,o,r,l,a,u=this;if(t=p(t),s=p(e[u.settings.valueField]),null!==t&&u.options.hasOwnProperty(t)){if("string"!=typeof s)throw new Error("Value must be set in option data");a=u.options[t].$order,s!==t&&(delete u.options[t],-1!==(o=u.items.indexOf(t))&&u.items.splice(o,1,s)),e.$order=e.$order||a,u.options[s]=e,r=u.renderCache.item,l=u.renderCache.option,r&&(delete r[t],delete r[s]),l&&(delete l[t],delete l[s]),-1!==u.items.indexOf(s)&&(i=u.getItem(t),n=u.render("item",e),i.classList.contains("active")&&m(n,"active"),i.parentNode.insertBefore(n,i),i.remove()),u.lastQuery=null,u.isOpen&&u.refreshOptions(!1)}},n.removeOption=function(t,e){var i=this;t=p(t);var n=i.renderCache.item,s=i.renderCache.option;n&&delete n[t],s&&delete s[t],delete i.userOptions[t],delete i.options[t],i.lastQuery=null,i.trigger("option_remove",t),i.removeItem(t,e)},n.clearOptions=function(){this.loadedSearches={},this.userOptions={},this.clearCache();var t={};for(var e in this.options)this.options.hasOwnProperty(e)&&this.items.indexOf(e)>=0&&(t[e]=this.options[e]);this.options=this.sifter.items=t,this.lastQuery=null,this.trigger("option_clear")},n.getOption=function(t){return this.renderCache.option.hasOwnProperty(t)?this.renderCache.option[t]:this.getElementWithValue(t,this.selectable())},n.getAdjacent=function(t,e,i){if(void 0===i&&(i="option"),t){var n=this,s=n.settings.optionClass,o=n.dropdown;"item"==i&&(o=n.control,s=n.settings.itemClass);for(var r=o.querySelectorAll("."+s),l=0;l<r.length;l++)if(r[l]==t)return e>0?r[l+1]:r[l-1]}},n.getElementWithValue=function(t,e){if(null!=(t=p(t)))for(var i=0,n=e.length;i<n;i++)if(e[i].getAttribute("data-value")===t)return e[i]},n.getItem=function(t){return this.getElementWithValue(t,this.control.children)},n.addItems=function(t,e){void 0===e&&(e=!1),this.buffer=document.createDocumentFragment();for(var i=this.control.children,n=0;n<i.length;n++)this.buffer.appendChild(i[n]);for(var s=Array.isArray(t)?t:[t],o=0,r=s.length;o<r;o++)this.isPending=o<r-1,this.addItem(s[o],e);var l=this.control;l.insertBefore(this.buffer,l.firstChild),this.buffer=null},n.addItem=function(t,e){void 0===e&&(e=!1),h(this,e?[]:["change"],(function(){var i,n,s=this,o=s.settings.mode;if(t=p(t),(-1===s.items.indexOf(t)||("single"===o&&s.close(),"single"!==o&&s.settings.duplicates))&&s.options.hasOwnProperty(t)&&("single"===o&&s.clear(e),("multi"!==o||!s.isFull())&&(i=s.render("item",s.options[t]),this.control.contains(i)&&(i=i.cloneNode(!0)),n=s.isFull(),s.items.splice(s.caretPos,0,t),s.insertAtCaret(i),(!s.isPending||!n&&s.isFull())&&s.refreshState(),s.isSetup))){var r=s.selectable();if(!s.isPending){var l=s.getOption(t),a=s.getAdjacent(l,1);s.refreshOptions(s.isFocused&&"single"!==o),a&&s.setActiveOption(a)}!r.length||s.isFull()?s.close():s.isPending||s.positionDropdown(),s.trigger("item_add",t,i),s.isPending||s.updateOriginalInput({silent:e})}}))},n.removeItem=function(t,e){var i,n;void 0===e&&(e=!1);var s=this.getItem(t);s&&(t=p(s.dataset.value),-1!==(i=this.items.indexOf(t))&&(s.remove(),s.classList.contains("active")&&(n=this.activeItems.indexOf(s),this.activeItems.splice(n,1),y(s,"active")),this.items.splice(i,1),this.lastQuery=null,!this.settings.persist&&this.userOptions.hasOwnProperty(t)&&this.removeOption(t,e),i<this.caretPos&&this.setCaret(this.caretPos-1),this.refreshState(),this.updateOriginalInput({silent:e}),this.positionDropdown(),this.trigger("item_remove",t,s)))},n.createItem=function(t,e,i){void 0===t&&(t=null),void 0===e&&(e=!0),void 0===i&&(i=null);var n,s=this,o=s.caretPos;if(t=t||s.inputValue(),"function"!=typeof i&&(i=function(){}),!s.canCreate(t))return i(),!1;s.lock();var r=!1,l=function(t){if(s.unlock(),!t||"object"!=typeof t)return i();var n=p(t[s.settings.valueField]);if("string"!=typeof n)return i();s.setTextboxValue(""),s.addOption(t),s.setCaret(o),s.addItem(n),s.refreshOptions(e&&"single"!==s.settings.mode),i(t),r=!0};return"function"==typeof s.settings.create?n=s.settings.create.apply(this,[t,l]):((n={})[s.settings.labelField]=t,n[s.settings.valueField]=t),r||l(n),!0},n.refreshItems=function(){this.lastQuery=null,this.isSetup&&this.addItems(this.items),this.refreshState(),this.updateOriginalInput()},n.refreshState=function(){var t=this;t.refreshValidityState();var e=t.isFull(),i=t.isLocked;t.wrapper.classList.toggle("rtl",t.rtl);var n,s=t.control.classList;s.toggle("focus",t.isFocused),s.toggle("disabled",t.isDisabled),s.toggle("required",t.isRequired),s.toggle("invalid",t.isInvalid),s.toggle("locked",i),s.toggle("full",e),s.toggle("not-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)},n.refreshValidityState=function(){if(this.input.checkValidity){var t=!this.input.checkValidity();this.isInvalid=t,this.control_input.required=t,this.input.required=!t}},n.isFull=function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},n.updateOriginalInput=function(t){var e,i,n,s,o=this;if(t=t||{},o.is_select_tag){for(n=[],e=0,i=o.items.length;e<i;e++)s=o.options[o.items[e]][o.settings.labelField]||"",n.push('<option value="'+d(o.items[e])+'" selected="selected">'+d(s)+"</option>");n.length||this.input.hasAttribute("multiple")||n.push('<option value="" selected="selected"></option>'),o.input.innerHTML=n.join("")}else o.input.value=o.getValue(),o.input.setAttribute("value",o.input.value);o.isSetup&&(t.silent||o.trigger("change",o.input.value))},n.open=function(){var t=this;t.isLocked||t.isOpen||"multi"===t.settings.mode&&t.isFull()||(t.focus(),t.isOpen=!0,t.refreshState(),v(t.dropdown,{visibility:"hidden",display:"block"}),t.positionDropdown(),v(t.dropdown,{visibility:"visible",display:"block"}),t.trigger("dropdown_open",t.dropdown))},n.close=function(){var t=this,e=t.isOpen;"single"===t.settings.mode&&t.items.length&&(t.hideInput(),t.isBlurring||t.blur()),t.isOpen=!1,v(t.dropdown,{display:"none"}),t.setActiveOption(),t.refreshState(),e&&t.trigger("dropdown_close",t.dropdown)},n.positionDropdown=function(){if("body"===this.settings.dropdownParent){var t=this.control,e=t.getBoundingClientRect(),i=t.offsetHeight+e.top+window.scrollY,n=e.left+window.scrollX;v(this.dropdown,{width:e.width+"px",top:i+"px",left:n+"px"})}},n.clear=function(t){if(this.items.length){for(var e=this.controlChildren(),i=0;i<e.length;i++)e[i].remove();this.items=[],this.lastQuery=null,this.setCaret(0),this.setActiveItem(),this.updateOriginalInput({silent:t}),this.refreshState(),this.showInput(),this.trigger("clear")}},n.insertAtCaret=function(t){var e=Math.min(this.caretPos,this.items.length),i=this.buffer||this.control;0===e?i.insertBefore(t,i.firstChild):i.insertBefore(t,i.children[e]),this.setCaret(e+1)},n.deleteSelection=function(t){var e,i,n,s,o,r,l,a=this;if(n=t&&8===t.keyCode?-1:1,s={start:(l=a.control_input).selectionStart,length:l.selectionEnd-l.selectionStart},o=[],a.activeItems.length){for(r=A(C(a.activeItems,n)),n>0&&r++,e=0,i=a.activeItems.length;e<i;e++)o.push(a.activeItems[e].dataset.value);t&&(t.preventDefault(),t.stopPropagation())}else(a.isFocused||"single"===a.settings.mode)&&a.items.length&&(n<0&&0===s.start&&0===s.length?o.push(a.items[a.caretPos-1]):n>0&&s.start===a.inputValue().length&&o.push(a.items[a.caretPos]));if(!o.length||"function"==typeof a.settings.onDelete&&!1===a.settings.onDelete.apply(a,[o,t]))return!1;for(void 0!==r&&a.setCaret(r);o.length;)a.removeItem(o.pop());return a.showInput(),a.positionDropdown(),a.refreshOptions(!1),!0},n.advanceSelection=function(t,e){var i,n;if(0!==t)if(this.rtl&&(t*=-1),this.isKeyDown(u,e)||this.isKeyDown("shiftKey",e)){n=this.getLastActive(t);var s=this.getAdjacent(n,t,"item");s&&(s.classList.contains("active")&&this.removeActiveItem(n),this.setActiveItemClass(s))}else this.isFocused&&!this.isInputHidden?this.inputValue().length||this.setCaret(this.caretPos+t):(n=this.getLastActive(t))&&(i=A(n),this.setCaret(t>0?i+1:i),this.setActiveItem())},n.getLastActive=function(t){var e=this.control.querySelector(".last-active");return e||function(t,e,i){var n=t.querySelectorAll(e);if(n)return C(n,i)}(this.control,".active",t)},n.setCaret=function(t){var e=this;if(t="single"===e.settings.mode||e.settings.controlInput?e.items.length:Math.max(0,Math.min(e.items.length,t)),!e.settings.controlInput&&!e.isPending){var i,n,s=this.controlChildren(),o=s.length;for(i=0;i<o;i++)n=s[i],i<t?e.control_input.insertAdjacentElement("beforebegin",n):e.control.appendChild(n)}e.caretPos=t},n.controlChildren=function(){return Array.prototype.filter.call(this.control.children,(function(t){return"INPUT"!==t.nodeName}))},n.lock=function(){this.close(),this.isLocked=!0,this.refreshState()},n.unlock=function(){this.isLocked=!1,this.refreshState()},n.disable=function(){this.input.disabled=!0,this.control_input.disabled=!0,this.control_input.tabIndex=-1,this.isDisabled=!0,this.lock()},n.enable=function(){this.input.disabled=!1,this.control_input.disabled=!1,this.control_input.tabIndex=this.tabIndex,this.isDisabled=!1,this.unlock()},n.destroy=function(){var t=this.revertSettings;this.trigger("destroy"),this.off(),this.wrapper.remove(),this.dropdown.remove(),this.input.innerHTML="",t.tabindex?this.input.setAttribute("tabindex",t.tabindex):this.input.removeAttribute("tabindex"),y(this.input,"tomselected"),this.input.removeAttribute("hidden");for(var e=0;e<t.children.length;e++)this.input.appendChild(t.children[e]);this._destroy(),delete this.input.tomselect},n.render=function(t,e){var i,n,s;void 0===e&&(e=null);var o=this;return"option"!==t&&"item"!==t||(i=p(e[o.settings.valueField]),!o.renderCache[t].hasOwnProperty(i))?(s=g(o.settings.render[t].apply(this,[e,d])),"option"===t||"option_create"===t?e[o.settings.disabledField]||s.setAttribute("data-selectable",""):"optgroup"===t&&(n=e.group[o.settings.optgroupValueField],s.setAttribute("data-group",n),e.group[o.settings.disabledField]&&s.setAttribute("data-disabled","")),"option"!==t&&"item"!==t||(s.setAttribute("data-value",i),m(s,"item"===t?o.settings.itemClass:o.settings.optionClass),o.renderCache[t][i]=s),s):o.renderCache[t][i]},n.clearCache=function(t){void 0===t&&(t=null);null===t?this.renderCache={item:{},option:{}}:this.renderCache[t]={}},n.canCreate=function(t){if(!this.settings.create)return!1;var e=this.settings.createFilter;return t.length&&("function"!=typeof e||e.call(this,t))&&(!(e instanceof RegExp)||e.test(t))},n.isKeyDown=function(t,e){return!!e&&(!!e[t]&&1===Number(e.altKey)+Number(e.ctrlKey)+Number(e.shiftKey)+Number(e.metaKey))},n.hook=function(t,e,i){var n=this,s=n[e];n[e]=function(){var e,o;return"after"===t&&(e=s.apply(n,arguments)),o=i.apply(n,arguments),"instead"===t?o:("before"===t&&(e=s.apply(n,arguments)),e)}},i}(((a=e).plugins={},function(e){function i(){return e.apply(this,arguments)||this}t(i,e),i.define=function(t,e){a.plugins[t]={name:t,fn:e}};var n=i.prototype;return n.initializePlugins=function(t){var e,i,n,s=this,o=[];if(s.plugins={names:[],settings:{},requested:{},loaded:{}},Array.isArray(t))for(e=0,i=t.length;e<i;e++)"string"==typeof t[e]?o.push(t[e]):(s.plugins.settings[t[e].name]=t[e].options,o.push(t[e].name));else if(t)for(n in t)t.hasOwnProperty(n)&&(s.plugins.settings[n]=t[n],o.push(n));for(;o.length;)s.require(o.shift())},n.loadPlugin=function(t){var e=this,i=e.plugins,n=a.plugins[t];if(!a.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin');i.requested[t]=!0,i.loaded[t]=n.fn.apply(e,[e.plugins.settings[t]||{}]),i.names.push(t)},n.require=function(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]},i}(a)))}));var tomSelect=function(t,e){return new TomSelect(t,e)}; | ||
var e,t | ||
e=this,t=function(){"use strict" | ||
class e{constructor(){this._events={}}on(e,t){this._events[e]=this._events[e]||[],this._events[e].push(t)}off(e,t){var i=arguments.length | ||
return 0===i?delete this._events:1===i?delete this._events[e]:(this._events=this._events||{},void(e in this._events!=0&&this._events[e].splice(this._events[e].indexOf(t),1)))}trigger(e){if(this._events=this._events||{},e in this._events!=0)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}}var t=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:e<t?-1:0:(e=n(String(e||"")))>(t=n(String(t||"")))?1:t>e?-1:0},i=function(e,t,i){if(e&&t){if(!i)return e[t] | ||
for(var s=t.split(".");s.length&&(e=e[s.shift()]););return e}},s={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶ]"},n=function(){var e,t,i,n,r="",o={} | ||
for(i in s)if(s.hasOwnProperty(i))for(r+=n=s[i].substring(2,s[i].length-1),e=0,t=n.length;e<t;e++)o[n.charAt(e)]=i | ||
var l=new RegExp("["+r+"]","g") | ||
return function(e){return e.replace(l,(function(e){return o[e]})).toLowerCase()}}() | ||
class r{constructor(e,t){this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t){if(!(e=String(e||"").toLowerCase().trim())||!e.length)return[] | ||
var i,n,r,o,l=[],a=e.split(/ +/) | ||
for(i=0,n=a.length;i<n;i++){if(r=(a[i]+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.settings.diacritics)for(o in s)s.hasOwnProperty(o)&&(r=r.replace(new RegExp(o,"g"),s[o])) | ||
t&&(r="\\b"+r),l.push({string:a[i],regex:new RegExp(r,"i")})}return l}iterator(e,t){(Array.isArray(e)?Array.prototype.forEach||function(e){for(var t=0,i=this.length;t<i;t++)e(this[t],t,this)}:function(e){for(var t in this)this.hasOwnProperty(t)&&e(this[t],t,this)}).apply(e,[t])}getScoreFunction(e,t){var s,n,r,o | ||
e=this.prepareSearch(e,t),n=e.tokens,s=e.options.fields,r=n.length,o=e.options.nesting | ||
var l,a=function(e,t){var i,s | ||
return e?-1===(s=(e=String(e||"")).search(t.regex))?0:(i=t.string.length/e.length,0===s&&(i+=.5),i):0},p=(l=s.length)?1===l?function(e,t){return a(i(t,s[0],o),e)}:function(e,t){for(var n=0,r=0;n<l;n++)r+=a(i(t,s[n],o),e) | ||
return r/l}:function(){return 0} | ||
return r?1===r?function(e){return p(n[0],e)}:"and"===e.options.conjunction?function(e){for(var t,i=0,s=0;i<r;i++){if((t=p(n[i],e))<=0)return 0 | ||
s+=t}return s/r}:function(e){for(var t=0,i=0;t<r;t++)i+=p(n[t],e) | ||
return i/r}:function(){return 0}}getSortFunction(e,s){var n,r,o,l,a,p,d,c,u,h,g | ||
if(g=!(e=(o=this).prepareSearch(e,s)).query&&s.sort_empty||s.sort,u=function(e,t){return"$score"===e?t.score:i(o.items[t.id],e,s.nesting)},a=[],g)for(n=0,r=g.length;n<r;n++)(e.query||"$score"!==g[n].field)&&a.push(g[n]) | ||
if(e.query){for(h=!0,n=0,r=a.length;n<r;n++)if("$score"===a[n].field){h=!1 | ||
break}h&&a.unshift({field:"$score",direction:"desc"})}else for(n=0,r=a.length;n<r;n++)if("$score"===a[n].field){a.splice(n,1) | ||
break}for(c=[],n=0,r=a.length;n<r;n++)c.push("desc"===a[n].direction?-1:1) | ||
return(p=a.length)?1===p?(l=a[0].field,d=c[0],function(e,i){return d*t(u(l,e),u(l,i))}):function(e,i){var s,n,r | ||
for(s=0;s<p;s++)if(r=a[s].field,n=c[s]*t(u(r,e),u(r,i)))return n | ||
return 0}:null}prepareSearch(e,t){if("object"==typeof e)return e | ||
var i=(t=Object.assign({},t)).fields,s=t.sort,n=t.sort_empty | ||
return i&&!Array.isArray(i)&&(t.fields=[i]),s&&!Array.isArray(s)&&(t.sort=[s]),n&&!Array.isArray(n)&&(t.sort_empty=[n]),{options:t,query:String(e||"").toLowerCase(),tokens:this.tokenize(e,t.respect_word_boundaries),total:0,items:[]}}search(e,t){var i,s,n,r,o=this | ||
return s=this.prepareSearch(e,t),t=s.options,e=s.query,r=t.score||o.getScoreFunction(s),e.length?o.iterator(o.items,(function(e,n){i=r(e),(!1===t.filter||i>0)&&s.items.push({score:i,id:n})})):o.iterator(o.items,(function(e,t){s.items.push({score:1,id:t})})),(n=o.getSortFunction(s,t))&&s.items.sort(n),s.total=s.items.length,"number"==typeof t.limit&&(s.items=s.items.slice(0,t.limit)),s}}function o(e,t){if("string"!=typeof t||t.length){var i="string"==typeof t?new RegExp(t,"i"):t | ||
!function e(t){var s=0 | ||
if(3===t.nodeType){var n=t.data.search(i) | ||
if(n>=0&&t.data.length>0){var r=t.data.match(i),o=document.createElement("span") | ||
o.className="highlight" | ||
var l=t.splitText(n) | ||
l.splitText(r[0].length) | ||
var a=l.cloneNode(!0) | ||
o.appendChild(a),l.parentNode.replaceChild(o,l),s=1}}else if(1===t.nodeType&&t.childNodes&&!/(script|style)/i.test(t.tagName)&&("highlight"!==t.className||"SPAN"!==t.tagName))for(var p=0;p<t.childNodes.length;++p)p+=e(t.childNodes[p]) | ||
return s}(e)}}const l=/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey" | ||
var a={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,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-control",inputClass:"ts-input",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:null,copyClassesToDropdown:!0,render:{}} | ||
function p(e){return null==e?null:"boolean"==typeof e?e?"1":"0":e+""}function d(e){return(e+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function c(e,t){var i,s=this | ||
return function(){var n=arguments | ||
i&&(this.loading=Math.max(this.loading-1,0)),clearTimeout(i),i=setTimeout((function(){i=null,e.apply(s,n)}),t)}}function u(e,t,i){var s,n=e.trigger,r={} | ||
for(s in e.trigger=function(){var i=arguments[0] | ||
if(-1===t.indexOf(i))return n.apply(e,arguments) | ||
r[i]=arguments},i.apply(e,[]),e.trigger=n,r)r.hasOwnProperty(s)&&n.apply(e,r[s])}function h(e,t=!1){e&&(e.preventDefault(),t&&e.stopPropagation())}function g(e,t,i,s){e.addEventListener(t,i,s)}function v(e,t){return!!t&&!!t[e]&&1==(t.altKey?1:0)+(t.ctrlKey?1:0)+(t.shiftKey?1:0)+(t.metaKey?1:0)}function f(e){if(e.jquery)return e[0] | ||
if(e instanceof HTMLElement)return e | ||
if(e.indexOf("<")>-1){let t=document.createElement("div") | ||
return t.innerHTML=e.trim(),t.firstChild}return document.querySelector(e)}function m(e,t){var i=document.createEvent("HTMLEvents") | ||
i.initEvent(t,!0,!1),e.dispatchEvent(i)}function y(e,t){Object.keys(t).forEach((function(i){e.style[i]=t[i]}))}function O(e,...t){var i=b(t);(e=C(e)).map((e=>{i.map((t=>{e.classList.add(t)}))}))}function w(e,...t){var i=b(t);(e=C(e)).map((e=>{i.map((t=>{e.classList.remove(t)}))}))}function b(e){var t=[] | ||
for(let i=0;i<e.length;i++){let s=e[i] | ||
"string"==typeof s&&(s=s.trim().split(/[\11\12\14\15\40]/)),Array.isArray(s)&&(t=t.concat(s))}return t.filter(Boolean)}function C(e){return Array.isArray(e)||(e=[e]),e}function I(e,t,i){if(!i||i.contains(e))for(;e&&e.matches;){if(e.matches(t))return e | ||
e=e.parentNode}}function A(e,t){return t>0?e[e.length-1]:e[0]}function _(e,t){if(!e)return-1 | ||
t=t||e.nodeName | ||
for(var i=0;e=e.previousElementSibling;)e.matches(t)&&i++ | ||
return i}class S extends(function(e){return e.plugins={},class extends e{static define(t,i){e.plugins[t]={name:t,fn:i}}initializePlugins(e){var t,i,s,n=this,r=[] | ||
if(n.plugins={names:[],settings:{},requested:{},loaded:{}},Array.isArray(e))for(t=0,i=e.length;t<i;t++)"string"==typeof e[t]?r.push(e[t]):(n.plugins.settings[e[t].name]=e[t].options,r.push(e[t].name)) | ||
else if(e)for(s in e)e.hasOwnProperty(s)&&(n.plugins.settings[s]=e[s],r.push(s)) | ||
for(;r.length;)n.require(r.shift())}loadPlugin(t){var i=this,s=i.plugins,n=e.plugins[t] | ||
if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin') | ||
s.requested[t]=!0,s.loaded[t]=n.fn.apply(i,[i.plugins.settings[t]||{}]),s.names.push(t)}require(e){var t=this,i=t.plugins | ||
if(!t.plugins.loaded.hasOwnProperty(e)){if(i.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")') | ||
t.loadPlugin(e)}return i.loaded[e]}}}(e)){constructor(e,t){var i | ||
if(super(),(e=f(e)).tomselect)throw new Error("Tom Select already initialized on this element") | ||
e.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(e,null)).getPropertyValue("direction"),this.order=0,this.settings=function(e,t){var i=Object.assign({},a,t),s=i.dataAttr,n=i.labelField,r=i.valueField,o=i.disabledField,l=i.optgroupField,d=i.optgroupLabelField,c=i.optgroupValueField,u=e.tagName.toLowerCase(),h=e.getAttribute("placeholder")||e.getAttribute("data-placeholder") | ||
if(!h&&!i.allowEmptyOption){let t=e.querySelector('option[value=""]') | ||
t&&(h=t.textContent)}var g={placeholder:h,options:[],optgroups:[],items:[],maxItems:null} | ||
return"select"===u?(()=>{var t,a,u,h,v=g.options,f={},m=e=>{var t=Object.assign({},e.dataset),i=s&&t[s] | ||
return"string"==typeof i&&i.length&&(t=Object.assign(t,JSON.parse(i))),t},y=(e,t)=>{var s=p(e.value) | ||
if(s||i.allowEmptyOption)if(f.hasOwnProperty(s)){if(t){var a=f[s][l] | ||
a?Array.isArray(a)?a.push(t):f[s][l]=[a,t]:f[s][l]=t}}else{var d=m(e) | ||
d[n]=d[n]||e.textContent,d[r]=d[r]||s,d[o]=d[o]||e.disabled,d[l]=d[l]||t,f[s]=d,v.push(d),e.selected&&g.items.push(s)}},O=e=>{var t,i,s,n,r | ||
for((s=e.getAttribute("label"))&&((n=m(e))[d]=s,n[c]=s,n[o]=e.disabled,g.optgroups.push(n)),t=0,i=(r=e.children).length;t<i;t++)y(r[t],s)} | ||
for(g.maxItems=e.hasAttribute("multiple")?null:1,t=0,a=(h=e.children).length;t<a;t++)"optgroup"===(u=h[t].tagName.toLowerCase())?O(h[t]):"option"===u&&y(h[t])})():(()=>{var t,o,l,a,p=e.getAttribute(s) | ||
if(p)for(g.options=JSON.parse(p),t=0,o=g.options.length;t<o;t++)g.items.push(g.options[t][r]) | ||
else{var d=e.value.trim()||"" | ||
if(!i.allowEmptyOption&&!d.length)return | ||
for(t=0,o=(l=d.split(i.delimiter)).length;t<o;t++)(a={})[n]=l[t],a[r]=l[t],g.options.push(a) | ||
g.items=l}})(),Object.assign({},a,g,t)}(e,t),this.input=e,this.tabIndex=e.getAttribute("tabindex")||null,this.is_select_tag="select"===e.tagName.toLowerCase(),this.rtl=/rtl/i.test(i),this.isBlurring=!1,this.isOpen=!1,this.isDisabled=!1,this.isRequired=e.required,this.isInvalid=!1,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.ignoreFocus=!1,this.ignoreBlur=!1,this.ignoreHover=!1,this.hasOptions=!1,this.currentResults=null,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.renderCache={item:{},option:{}},this.settings.load&&this.settings.loadThrottle&&(this.settings.load=c.call(this,this.settings.load,this.settings.loadThrottle)),this.sifter=new r(this.options,{diacritics:this.settings.diacritics}),this.setupOptions(this.settings.options,this.settings.optgroups),delete this.settings.optgroups,delete this.settings.options,this.settings.mode=this.settings.mode||(1===this.settings.maxItems?"single":"multi"),"boolean"!=typeof this.settings.hideSelected&&(this.settings.hideSelected="multi"===this.settings.mode) | ||
var s=this.settings.createFilter | ||
"function"!=typeof s&&("string"==typeof s&&(s=new RegExp(s)),s instanceof RegExp?this.settings.createFilter=e=>s.test(e):this.settings.createFilter=()=>!0),this.initializePlugins(this.settings.plugins),this.setupCallbacks(),this.setupTemplates(),this.setup()}setup(){var e,t,i,s,n,r,o,l,a,p=this,d=p.settings,c=p.input | ||
const u={passive:!0} | ||
if(r=p.settings.mode,o=c.getAttribute("class")||"",O(e=f("<div>"),d.wrapperClass,o,r),O(t=f('<div class="items">'),d.inputClass),e.append(t),O(s=p.render("dropdown"),d.dropdownClass,r),O(n=f('<div style="scroll-behavior: smooth;">'),d.dropdownContentClass),s.append(n),f(d.dropdownParent||e).appendChild(s),d.controlInput)i=f(d.controlInput) | ||
else{i=f('<input type="text" autocomplete="off" />') | ||
var v=["autocorrect","autocapitalize","autocomplete"] | ||
for(let e=0;e<v.length;e++){let t=v[e] | ||
c.getAttribute(t)&&i.setAttribute(t,c.getAttribute(t))}}if(d.controlInput||(i.setAttribute("tabindex",c.disabled?"-1":p.tabIndex),t.appendChild(i)),a=c.getAttribute("id")){i.setAttribute("id",a+"-tomselected") | ||
var m=document.querySelector("label[for='"+a+"']") | ||
m&&m.setAttribute("for",a+"-tomselected")}if(p.settings.copyClassesToDropdown&&O(s,o),e.style.width=c.style.width,p.plugins.names.length&&(l="plugin-"+p.plugins.names.join(" plugin-"),O([e,s],l)),(null===d.maxItems||d.maxItems>1)&&p.is_select_tag&&c.setAttribute("multiple","multiple"),p.settings.placeholder&&i.setAttribute("placeholder",d.placeholder),!p.settings.splitOn&&p.settings.delimiter){var y=p.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&") | ||
p.settings.splitOn=new RegExp("\\s*"+y+"+\\s*")}p.control=t,p.control_input=i,p.wrapper=e,p.dropdown=s,p.dropdown_content=n,p.control_input.type=c.type,g(s,"mouseenter",(e=>{var t=I(e.target,"[data-selectable]",s) | ||
if(t)return p.onOptionHover(e,t)}),{capture:!0}),g(t,"mousedown",(e=>{var i=I(e.target,"."+p.settings.itemClass,t) | ||
return i?p.onItemSelect(e,i):p.onMouseDown(e)})),g(t,"click",(e=>p.onClick(e))),g(i,"mousedown",(e=>e.stopPropagation())),g(i,"keydown",(e=>p.onKeyDown(e))),g(i,"keyup",(e=>p.onKeyUp(e))),g(i,"keypress",(e=>p.onKeyPress(e))),g(i,"resize",(()=>p.positionDropdown()),u),g(i,"blur",(e=>p.onBlur(e))),g(i,"focus",(e=>{p.ignoreBlur=!1,p.onFocus(e)})),g(i,"paste",(e=>p.onPaste(e))) | ||
var w=e=>{var t=I(e.target,"[data-selectable]",p.dropdown) | ||
t||p.wrapper.contains(e.target)?(h(e,!0),t&&p.onOptionSelect(e,t)):p.isFocused&&p.blur(e.target)},b=()=>{p.isOpen&&p.positionDropdown()},C=()=>{p.ignoreHover=!1} | ||
g(document,"mousedown",w),g(window,"sroll",b,u),g(window,"resize",b,u),g(window,"mousemove",C,u),p._destroy=()=>{document.removeEventListener("mousedown",w),window.removeEventListener("mousemove",C),window.removeEventListener("sroll",b),window.removeEventListener("resize",b)} | ||
for(var A=[];c.children.length>0;)A.push(c.children[0]),c.children[0].remove() | ||
this.revertSettings={children:A,tabindex:c.getAttribute("tabindex")},c.tabIndex=-1,c.setAttribute("hidden","hidden"),c.insertAdjacentElement("afterend",p.wrapper),p.setValue(d.items),delete d.items,g(c,"invalid",(e=>{h(e),p.isInvalid||(p.isInvalid=!0,p.refreshState())})),p.updateOriginalInput(),p.refreshItems(),p.refreshState(),p.isSetup=!0,c.disabled&&p.disable(),p.on("change",this.onChange),O(c,"tomselected"),p.trigger("initialize"),!0===d.preload&&p.load("")}setupOptions(e,t){var i,s | ||
for(t=t||[],i=0,s=(e=e||[]).length;i<s;i++)this.registerOption(e[i]) | ||
for(i=0,s=t.length;i<s;i++)this.registerOptionGroup(t[i])}setupTemplates(){var e=this,t=e.settings.labelField,i=e.settings.optgroupLabelField,s={optgroup:(e,t)=>{let i=document.createElement("div") | ||
return i.className="optgroup",i.appendChild(e.options),i},optgroup_header:(e,t)=>'<div class="optgroup-header">'+t(e[i])+"</div>",option:(e,i)=>"<div>"+i(e[t])+"</div>",item:(e,i)=>"<div>"+i(e[t])+"</div>",option_create:(e,t)=>'<div class="create">Add <strong>'+t(e.input)+"</strong>…</div>",no_results:(e,t)=>'<div class="no-results">No results found</div>',loading:(e,t)=>'<div class="spinner"></div>',dropdown:()=>'<div style="display:none"></div>'} | ||
e.settings.render=Object.assign({},s,e.settings.render)}setupCallbacks(){var e,t,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",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(e in i)(t=this.settings[i[e]])&&this.on(e,t)}onClick(e){var t=this | ||
t.isFocused&&t.isOpen||(t.focus(),h(e))}onMouseDown(e){var t=this | ||
if(t.isFocused){if(e.target!==t.control_input)return"single"===t.settings.mode?t.isOpen?t.close():t.open():t.setActiveItem(),!1}else setTimeout((()=>t.focus()),0)}onChange(){m(this.input,"change")}onPaste(e){var t=this | ||
t.isFull()||t.isInputHidden||t.isLocked?h(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue() | ||
if(e.match(t.settings.splitOn))for(var i=e.trim().split(t.settings.splitOn),s=0,n=i.length;s<n;s++)t.createItem(i[s])}),0)}onKeyPress(e){var t=this | ||
if(!t.isLocked){var i=String.fromCharCode(e.keyCode||e.which) | ||
return t.settings.create&&"multi"===t.settings.mode&&i===t.settings.delimiter?(t.createItem(),void h(e)):void 0}h(e)}onKeyDown(e){var t=this | ||
if(t.ignoreHover=!0,t.isLocked)9!==e.keyCode&&h(e) | ||
else{switch(e.keyCode){case 65:if(v(l,e))return void t.selectAll() | ||
break | ||
case 27:return void(t.isOpen&&(h(e,!0),t.close())) | ||
case 40:if(!t.isOpen&&t.hasOptions)t.open() | ||
else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1) | ||
e&&t.setActiveOption(e,!0)}return void h(e) | ||
case 38:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1) | ||
e&&t.setActiveOption(e,!0)}return void h(e) | ||
case 13:return void(t.isOpen&&t.activeOption&&(t.onOptionSelect(e,t.activeOption),h(e))) | ||
case 37:return void t.advanceSelection(-1,e) | ||
case 39:return void t.advanceSelection(1,e) | ||
case 9:return t.settings.selectOnTab&&t.isOpen&&t.activeOption&&(t.onOptionSelect(e,t.activeOption),h(e)),void(t.settings.create&&t.createItem()&&h(e)) | ||
case 8:case 46:return void t.deleteSelection(e)}!t.isInputHidden||v(l,e)||h(e)}}onKeyUp(e){var t=this | ||
if(t.isLocked)h(e) | ||
else{var i=t.inputValue() | ||
t.lastValue!==i&&(t.lastValue=i,t.load(i),t.refreshOptions(),t.trigger("type",i))}}onFocus(e){var t=this,i=t.isFocused | ||
if(t.isDisabled)return t.blur(),void h(e) | ||
t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.load(""),i||t.trigger("focus"),t.activeItems.length||(t.showInput(),t.setActiveItem(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e,t){var i=this | ||
if(i.isFocused){if(i.isFocused=!1,i.ignoreFocus=!1,!i.ignoreBlur&&document.activeElement===i.dropdown_content)return i.ignoreBlur=!0,void i.onFocus(e) | ||
var s=()=>{i.close(),i.setActiveItem(),i.setActiveOption(),i.setCaret(i.items.length),i.refreshState(),t&&t.focus&&t.focus(),i.isBlurring=!1,i.trigger("blur")} | ||
i.isBlurring=!0,i.settings.create&&i.settings.createOnBlur?i.createItem(null,!1,s):s()}}onOptionHover(e,t){this.ignoreHover||this.setActiveOption(t,!1)}onOptionSelect(e,t){var i,s=this | ||
t&&(t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?s.createItem(null,!0,(()=>{s.settings.closeAfterSelect&&s.close()})):void 0!==(i=t.dataset.value)&&(s.lastQuery=null,s.addItem(i),s.settings.closeAfterSelect?s.close():!s.settings.hideSelected&&e.type&&/mouse/.test(e.type)&&s.setActiveOption(s.getOption(i)))))}onItemSelect(e,t){var i=this | ||
i.isLocked||"multi"===i.settings.mode&&(h(e),i.setActiveItem(t,e))}load(e){var t=this,i=t.settings.load | ||
i&&(t.loadedSearches.hasOwnProperty(e)||(t.loadedSearches[e]=!0,O(t.wrapper,t.settings.loadingClass),t.loading++,i.call(t,e,(function(e,i){t.loading=Math.max(t.loading-1,0),t.lastQuery=null,t.setupOptions(e,i),t.refreshOptions(t.isFocused&&!t.isInputHidden),t.loading||w(t.wrapper,t.settings.loadingClass),t.trigger("load",e,i)}))))}onSearchChange(e){this.load(e)}setTextboxValue(e){var t=this.control_input | ||
t.value!==e&&(t.value=e,m(t,"update"),this.lastValue=e)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){u(this,t?[]:["change"],(()=>{this.clear(t),this.addItems(e,t)}))}setActiveItem(e,t){var i,s,n,r,o,a,p=this | ||
if("single"!==p.settings.mode){if(!e)return w(p.activeItems,"active"),p.activeItems=[],void(p.isFocused&&p.showInput()) | ||
if("mousedown"===(i=t&&t.type.toLowerCase())&&v("shiftKey",t)&&p.activeItems.length){for(a=p.getLastActive(),(n=Array.prototype.indexOf.call(p.control.children,a))>(r=Array.prototype.indexOf.call(p.control.children,e))&&(o=n,n=r,r=o),s=n;s<=r;s++)e=p.control.children[s],-1===p.activeItems.indexOf(e)&&p.setActiveItemClass(e) | ||
h(t)}else"mousedown"===i&&v(l,t)||"keydown"===i&&v("shiftKey",t)?e.classList.contains("active")?p.removeActiveItem(e):p.setActiveItemClass(e):(w(p.activeItems,"active"),p.activeItems=[],p.setActiveItemClass(e)) | ||
p.hideInput(),p.isFocused||p.focus()}}setActiveItemClass(e){var t=this.control.querySelector(".last-active") | ||
t&&w(t,"last-active"),O(e,"active last-active"),-1==this.activeItems.indexOf(e)&&this.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e) | ||
this.activeItems.splice(t,1),w(e,"active")}setActiveOption(e,t){var i,s,n | ||
if(e!==this.activeOption&&(this.activeOption&&w(this.activeOption,"active"),this.activeOption=null,e&&(this.activeOption=e,O(e,"active"),t))){i=this.dropdown_content.clientHeight | ||
let e=this.dropdown_content.scrollTop||0 | ||
s=this.activeOption.offsetHeight,(n=this.activeOption.getBoundingClientRect().top-this.dropdown_content.getBoundingClientRect().top+e)+s>i+e?this.dropdown_content.scrollTop=n-i+s:n<e&&(this.dropdown_content.scrollTop=n)}}selectAll(){"single"!==this.settings.mode&&(this.activeItems=this.controlChildren(),this.activeItems.length&&(O(this.activeItems,"active"),this.hideInput(),this.close()),this.focus())}hideInput(){this.settings.controlInput||(this.setTextboxValue(""),y(this.control_input,{opacity:0,position:"absolute",left:(this.rtl?1e4:-1e4)+"px"}),this.isInputHidden=!0)}showInput(){this.settings.controlInput||(y(this.control_input,{opacity:1,position:"relative",left:0}),this.isInputHidden=!1)}inputValue(){return this.control_input.value.trim()}focus(){var e=this | ||
e.isDisabled||(e.ignoreFocus=!0,e.control_input.focus(),setTimeout((()=>{e.ignoreFocus=!1,e.onFocus()}),0))}blur(e){this.control_input.blur(),this.onBlur(null,e)}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e,t=this.settings | ||
return"string"==typeof t.sortField&&(e=[{field:t.sortField}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}}search(e){var t,i,s,n=this,r=n.settings,o=this.getSearchOptions() | ||
if(r.score&&"function"!=typeof(s=n.settings.score.call(n,e)))throw new Error('Tom Select "score" setting must be a function that returns a function') | ||
if(e!==n.lastQuery?(n.lastQuery=e,i=n.sifter.search(e,Object.assign(o,{score:s})),n.currentResults=i):i=Object.assign({},n.currentResults),r.hideSelected)for(t=i.items.length-1;t>=0;t--)-1!==n.items.indexOf(p(i.items[t].id))&&i.items.splice(t,1) | ||
return i}refreshOptions(e=!0){var t,i,s,n,r,l,a,d,c,u,h,g,v,f=this,m=f.inputValue(),y=f.search(m),b=f.activeOption&&p(f.activeOption.dataset.value),C=!1 | ||
for(n=y.items.length,"number"==typeof f.settings.maxOptions&&(n=Math.min(n,f.settings.maxOptions)),n>0&&(C=!0),r={},l=[],t=0;t<n;t++){let e=f.options[y.items[t].id],n=p(e[f.settings.valueField]),o=f.getOption(n) | ||
for(o||(o=f.render("option",e)),a=e[f.settings.optgroupField]||"",i=0,s=(d=Array.isArray(a)?a:[a])&&d.length;i<s;i++)a=d[i],f.optgroups.hasOwnProperty(a)||(a=""),r.hasOwnProperty(a)||(r[a]=document.createDocumentFragment(),l.push(a)),i>0&&(o=o.cloneNode(!0),w(o,"active")),r[a].appendChild(o)}for(this.settings.lockOptgroupOrder&&l.sort(((e,t)=>(f.optgroups[e].$order||0)-(f.optgroups[t].$order||0))),c=document.createDocumentFragment(),t=0,n=l.length;t<n;t++)if(a=l[t],f.optgroups.hasOwnProperty(a)&&r[a].children.length){let e=document.createDocumentFragment() | ||
e.appendChild(f.render("optgroup_header",f.optgroups[a])),e.appendChild(r[a]) | ||
let t=f.render("optgroup",{group:f.optgroups[a],options:e}) | ||
c.appendChild(t)}else c.appendChild(r[a]) | ||
if(f.dropdown_content.innerHTML="",f.dropdown_content.appendChild(c),f.settings.highlight&&(f.dropdown_content,v=document.querySelectorAll("span.highlight"),Array.prototype.forEach.call(v,(function(e,t){var i=e.parentNode | ||
i.replaceChild(e.firstChild,e),i.normalize()})),y.query.length&&y.tokens.length))for(t=0,n=y.tokens.length;t<n;t++)o(f.dropdown_content,y.tokens[t].regex) | ||
if(!f.settings.hideSelected)for(t=0,n=f.items.length;t<n;t++){let e=f.getOption(f.items[t]) | ||
e&&O(e,"selected")}var I=e=>{C=!0 | ||
let t=f.render(e,{input:m}) | ||
return f.dropdown_content.insertBefore(t,f.dropdown_content.firstChild),t} | ||
if(f.loading?I("loading"):0===y.items.length&&f.settings.render.no_results&&m.length&&I("no_results"),(u=f.canCreate(m))&&(g=I("option_create")),f.hasOptions=y.items.length>0||u,C){if(y.items.length>0){if(!(h=b&&f.getOption(b))||!f.dropdown_content.contains(h)){let e=0 | ||
g&&!f.settings.addPrecedence&&(e=1),h=f.selectable()[e]}}else h=g | ||
f.setActiveOption(h),e&&!f.isOpen&&f.open()}else f.setActiveOption(),e&&f.isOpen&&f.close()}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e){var t,i,s,n=this | ||
if(Array.isArray(e))for(t=0,i=e.length;t<i;t++)n.addOption(e[t]) | ||
else(s=n.registerOption(e))&&(n.userOptions[s]=!0,n.lastQuery=null,n.trigger("option_add",s,e))}registerOption(e){var t=p(e[this.settings.valueField]) | ||
return null!=t&&!this.options.hasOwnProperty(t)&&(e.$order=e.$order||++this.order,this.options[t]=e,t)}registerOptionGroup(e){var t=p(e[this.settings.optgroupValueField]) | ||
return!!t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var i | ||
t[this.settings.optgroupValueField]=e,(i=this.registerOptionGroup(t))&&this.trigger("optgroup_add",i,t)}removeOptionGroup(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.clearCache(),this.trigger("optgroup_remove",e))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(e,t){var i,s,n,r,o,l,a,d=this | ||
if(e=p(e),n=p(t[d.settings.valueField]),null!==e&&d.options.hasOwnProperty(e)){if("string"!=typeof n)throw new Error("Value must be set in option data") | ||
a=d.options[e].$order,n!==e&&(delete d.options[e],-1!==(r=d.items.indexOf(e))&&d.items.splice(r,1,n)),t.$order=t.$order||a,d.options[n]=t,o=d.renderCache.item,l=d.renderCache.option,o&&(delete o[e],delete o[n]),l&&(delete l[e],delete l[n]),-1!==d.items.indexOf(n)&&(i=d.getItem(e),s=d.render("item",t),i.classList.contains("active")&&O(s,"active"),i.parentNode.insertBefore(s,i),i.remove()),d.lastQuery=null,d.isOpen&&d.refreshOptions(!1)}}removeOption(e,t){var i=this | ||
e=p(e) | ||
var s=i.renderCache.item,n=i.renderCache.option | ||
s&&delete s[e],n&&delete n[e],delete i.userOptions[e],delete i.options[e],i.lastQuery=null,i.trigger("option_remove",e),i.removeItem(e,t)}clearOptions(){this.loadedSearches={},this.userOptions={},this.clearCache() | ||
var e={} | ||
for(let t in this.options)this.options.hasOwnProperty(t)&&this.items.indexOf(t)>=0&&(e[t]=this.options[t]) | ||
this.options=this.sifter.items=e,this.lastQuery=null,this.trigger("option_clear")}getOption(e){return this.renderCache.option.hasOwnProperty(e)?this.renderCache.option[e]:this.getElementWithValue(e,this.selectable())}getAdjacent(e,t,i="option"){if(e){var s=this,n=s.settings.optionClass,r=s.dropdown | ||
"item"==i&&(r=s.control,n=s.settings.itemClass) | ||
var o=r.querySelectorAll("."+n) | ||
for(let i=0;i<o.length;i++)if(o[i]==e)return t>0?o[i+1]:o[i-1]}}getElementWithValue(e,t){if(null!=(e=p(e)))for(var i=0,s=t.length;i<s;i++){let s=t[i] | ||
if(s.getAttribute("data-value")===e)return s}}getItem(e){return this.getElementWithValue(e,this.control.children)}addItems(e,t){this.buffer=document.createDocumentFragment() | ||
var i=this.control.children | ||
for(let e=0;e<i.length;e++)this.buffer.appendChild(i[e]) | ||
var s=Array.isArray(e)?e:[e] | ||
for(let e=0,i=s.length;e<i;e++)this.isPending=e<i-1,this.addItem(s[e],t) | ||
var n=this.control | ||
n.insertBefore(this.buffer,n.firstChild),this.buffer=null}addItem(e,t){u(this,t?[]:["change"],(()=>{var i,s,n=this,r=n.settings.mode | ||
if(e=p(e),(-1===n.items.indexOf(e)||("single"===r&&n.close(),"single"!==r&&n.settings.duplicates))&&n.options.hasOwnProperty(e)&&("single"===r&&n.clear(t),("multi"!==r||!n.isFull())&&(i=n.render("item",n.options[e]),n.control.contains(i)&&(i=i.cloneNode(!0)),s=n.isFull(),n.items.splice(n.caretPos,0,e),n.insertAtCaret(i),(!n.isPending||!s&&n.isFull())&&n.refreshState(),n.isSetup))){let s=n.selectable() | ||
if(!n.isPending){let t=n.getOption(e),i=n.getAdjacent(t,1) | ||
n.refreshOptions(n.isFocused&&"single"!==r),i&&n.setActiveOption(i)}!s.length||n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",e,i),n.isPending||n.updateOriginalInput({silent:t})}}))}removeItem(e,t){var i,s,n=this,r=n.getItem(e) | ||
r&&(e=p(r.dataset.value),-1!==(i=n.items.indexOf(e))&&(r.remove(),r.classList.contains("active")&&(s=n.activeItems.indexOf(r),n.activeItems.splice(s,1),w(r,"active")),n.items.splice(i,1),n.lastQuery=null,!n.settings.persist&&n.userOptions.hasOwnProperty(e)&&n.removeOption(e,t),i<n.caretPos&&n.setCaret(n.caretPos-1),n.refreshState(),n.updateOriginalInput({silent:t}),n.positionDropdown(),n.trigger("item_remove",e,r)))}createItem(e,t=!0,i){var s,n=this,r=n.caretPos | ||
if(e=e||n.inputValue(),"function"!=typeof i&&(i=()=>{}),!n.canCreate(e))return i(),!1 | ||
n.lock() | ||
var o=!1,l=e=>{if(n.unlock(),!e||"object"!=typeof e)return i() | ||
var s=p(e[n.settings.valueField]) | ||
if("string"!=typeof s)return i() | ||
n.setTextboxValue(""),n.addOption(e),n.setCaret(r),n.addItem(s),n.refreshOptions(t&&"single"!==n.settings.mode),i(e),o=!0} | ||
return s="function"==typeof n.settings.create?n.settings.create.call(this,e,l):{[n.settings.labelField]:e,[n.settings.valueField]:e},o||l(s),!0}refreshItems(){var e=this | ||
e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.refreshState(),e.updateOriginalInput()}refreshState(){var e=this | ||
e.refreshValidityState() | ||
var t=e.isFull(),i=e.isLocked | ||
e.wrapper.classList.toggle("rtl",e.rtl) | ||
var s,n=e.control.classList | ||
n.toggle("focus",e.isFocused),n.toggle("disabled",e.isDisabled),n.toggle("required",e.isRequired),n.toggle("invalid",e.isInvalid),n.toggle("locked",i),n.toggle("full",t),n.toggle("not-full",!t),n.toggle("input-active",e.isFocused&&!e.isInputHidden),n.toggle("dropdown-active",e.isOpen),n.toggle("has-options",(s=e.options,0===Object.keys(s).length)),n.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this | ||
if(e.input.checkValidity){var t=!e.input.checkValidity() | ||
e.isInvalid=t,e.control_input.required=t,e.input.required=!t}}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){var t,i,s,n,r=this | ||
if(r.is_select_tag){for(s=[],t=0,i=r.items.length;t<i;t++)n=r.options[r.items[t]][r.settings.labelField]||"",s.push('<option value="'+d(r.items[t])+'" selected="selected">'+d(n)+"</option>") | ||
s.length||this.input.hasAttribute("multiple")||s.push('<option value="" selected="selected"></option>'),r.input.innerHTML=s.join("")}else r.input.value=r.getValue(),r.input.setAttribute("value",r.input.value) | ||
r.isSetup&&(e.silent||r.trigger("change",r.input.value))}open(){var e=this | ||
e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.focus(),e.isOpen=!0,e.refreshState(),y(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),y(e.dropdown,{visibility:"visible",display:"block"}),e.trigger("dropdown_open",e.dropdown))}close(){var e=this,t=e.isOpen | ||
"single"===e.settings.mode&&e.items.length&&(e.hideInput(),e.isBlurring||e.blur()),e.isOpen=!1,y(e.dropdown,{display:"none"}),e.setActiveOption(),e.refreshState(),t&&e.trigger("dropdown_close",e.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control,t=e.getBoundingClientRect(),i=e.offsetHeight+t.top+window.scrollY,s=t.left+window.scrollX | ||
y(this.dropdown,{width:t.width+"px",top:i+"px",left:s+"px"})}}clear(e){var t=this | ||
if(t.items.length){var i=t.controlChildren() | ||
for(let e=0;e<i.length;e++)i[e].remove() | ||
t.items=[],t.lastQuery=null,t.setCaret(0),t.setActiveItem(),t.updateOriginalInput({silent:e}),t.refreshState(),t.showInput(),t.trigger("clear")}}insertAtCaret(e){var t=this,i=Math.min(t.caretPos,t.items.length),s=t.buffer||t.control | ||
0===i?s.insertBefore(e,s.firstChild):s.insertBefore(e,s.children[i]),t.setCaret(i+1)}deleteSelection(e){var t,i,s,n,r,o,l,a=this | ||
if(s=e&&8===e.keyCode?-1:1,n={start:(l=a.control_input).selectionStart,length:l.selectionEnd-l.selectionStart},r=[],a.activeItems.length){for(o=_(A(a.activeItems,s)),s>0&&o++,t=0,i=a.activeItems.length;t<i;t++)r.push(a.activeItems[t].dataset.value) | ||
h(e,!0)}else(a.isFocused||"single"===a.settings.mode)&&a.items.length&&(s<0&&0===n.start&&0===n.length?r.push(a.items[a.caretPos-1]):s>0&&n.start===a.inputValue().length&&r.push(a.items[a.caretPos])) | ||
if(!r.length||"function"==typeof a.settings.onDelete&&!1===a.settings.onDelete.call(a,r,e))return!1 | ||
for(void 0!==o&&a.setCaret(o);r.length;)a.removeItem(r.pop()) | ||
return a.showInput(),a.positionDropdown(),a.refreshOptions(!1),!0}advanceSelection(e,t){var i,s,n=this | ||
if(0!==e)if(n.rtl&&(e*=-1),v(l,t)||v("shiftKey",t)){s=n.getLastActive(e) | ||
let t=n.getAdjacent(s,e,"item") | ||
t&&(t.classList.contains("active")&&n.removeActiveItem(s),n.setActiveItemClass(t))}else n.isFocused&&!n.isInputHidden?n.inputValue().length||n.setCaret(n.caretPos+e):(s=n.getLastActive(e))&&(i=_(s),n.setCaret(e>0?i+1:i),n.setActiveItem())}getLastActive(e){let t=this.control.querySelector(".last-active") | ||
if(t)return t | ||
var i=this.control.querySelectorAll(".active") | ||
return i?A(i,e):void 0}setCaret(e){var t=this | ||
if(e="single"===t.settings.mode||t.settings.controlInput?t.items.length:Math.max(0,Math.min(t.items.length,e)),!t.settings.controlInput&&!t.isPending){var i,s,n=t.controlChildren(),r=n.length | ||
for(i=0;i<r;i++)s=n[i],i<e?t.control_input.insertAdjacentElement("beforebegin",s):t.control.appendChild(s)}t.caretPos=e}controlChildren(){return Array.prototype.filter.call(this.control.children,(e=>"INPUT"!==e.nodeName))}lock(){this.close(),this.isLocked=!0,this.refreshState()}unlock(){this.isLocked=!1,this.refreshState()}disable(){var e=this | ||
e.input.disabled=!0,e.control_input.disabled=!0,e.control_input.tabIndex=-1,e.isDisabled=!0,e.lock()}enable(){var e=this | ||
e.input.disabled=!1,e.control_input.disabled=!1,e.control_input.tabIndex=e.tabIndex,e.isDisabled=!1,e.unlock()}destroy(){var e=this,t=e.revertSettings | ||
e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML="",t.tabindex?e.input.setAttribute("tabindex",t.tabindex):e.input.removeAttribute("tabindex"),w(e.input,"tomselected"),e.input.removeAttribute("hidden") | ||
for(let i=0;i<t.children.length;i++)e.input.appendChild(t.children[i]) | ||
e._destroy(),delete e.input.tomselect}render(e,t){var i,s,n,r=this | ||
return"option"!==e&&"item"!==e||(i=p(t[r.settings.valueField]),!r.renderCache[e].hasOwnProperty(i))?(n=f(r.settings.render[e].call(this,t,d)),"option"===e||"option_create"===e?t[r.settings.disabledField]||n.setAttribute("data-selectable",""):"optgroup"===e&&(s=t.group[r.settings.optgroupValueField],n.setAttribute("data-group",s),t.group[r.settings.disabledField]&&n.setAttribute("data-disabled","")),"option"!==e&&"item"!==e||(n.setAttribute("data-value",i),O(n,"item"===e?r.settings.itemClass:r.settings.optionClass),r.renderCache[e][i]=n),n):r.renderCache[e][i]}clearCache(e){void 0===e?this.renderCache={item:{},option:{}}:this.renderCache[e]={}}canCreate(e){return this.settings.create&&e.length&&this.settings.createFilter.call(this,e)}hook(e,t,i){var s=this,n=s[t] | ||
s[t]=function(){var t,r | ||
return"after"===e&&(t=n.apply(s,arguments)),r=i.apply(s,arguments),"instead"===e?r:("before"===e&&(t=n.apply(s,arguments)),t)}}}return S},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TomSelect=t() | ||
//# sourceMappingURL=tom-select.base.min.js.map |
/** | ||
* Tom Select v1.0.0 | ||
* Tom Select v1.1.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).TomSelect=e()}(this,(function(){"use strict";function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var e=function(){function t(){this._events={}}var e=t.prototype;return e.on=function(t,e){this._events[t]=this._events[t]||[],this._events[t].push(e)},e.off=function(t,e){var i=arguments.length;return 0===i?delete this._events:1===i?delete this._events[t]:(this._events=this._events||{},void(t in this._events!=!1&&this._events[t].splice(this._events[t].indexOf(e),1)))},e.trigger=function(t){if(this._events=this._events||{},t in this._events!=!1)for(var e=0;e<this._events[t].length;e++)this._events[t][e].apply(this,Array.prototype.slice.call(arguments,1))},t}();var i=function(t,e){return"number"==typeof t&&"number"==typeof e?t>e?1:t<e?-1:0:(t=o(String(t||"")))>(e=o(String(e||"")))?1:e>t?-1:0},n=function(t,e,i){if(t&&e){if(!i)return t[e];for(var n=e.split(".");n.length&&(t=t[n.shift()]););return t}},s={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶ]"},o=function(){var t,e,i,n,o="",r={};for(i in s)if(s.hasOwnProperty(i))for(o+=n=s[i].substring(2,s[i].length-1),t=0,e=n.length;t<e;t++)r[n.charAt(t)]=i;var a=new RegExp("["+o+"]","g");return function(t){return t.replace(a,(function(t){return r[t]})).toLowerCase()}}(),r=function(){function t(t,e){this.items=t,this.settings=e||{diacritics:!0}}var e=t.prototype;return e.tokenize=function(t,e){if(!(t=String(t||"").toLowerCase().trim())||!t.length)return[];var i,n,o,r,a=[],l=t.split(/ +/);for(i=0,n=l.length;i<n;i++){if(o=(l[i]+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.settings.diacritics)for(r in s)s.hasOwnProperty(r)&&(o=o.replace(new RegExp(r,"g"),s[r]));e&&(o="\\b"+o),a.push({string:l[i],regex:new RegExp(o,"i")})}return a},e.iterator=function(t,e){var i;i=Array.isArray(t)?Array.prototype.forEach||function(t){for(var e=0,i=this.length;e<i;e++)t(this[e],e,this)}:function(t){for(var e in this)this.hasOwnProperty(e)&&t(this[e],e,this)},i.apply(t,[e])},e.getScoreFunction=function(t,e){var i,s,o,r;void 0===e&&(e=null),t=this.prepareSearch(t,e),s=t.tokens,i=t.options.fields,o=s.length,r=t.options.nesting;var a,l=function(t,e){var i,n;return t?-1===(n=(t=String(t||"")).search(e.regex))?0:(i=e.string.length/t.length,0===n&&(i+=.5),i):0},u=(a=i.length)?1===a?function(t,e){return l(n(e,i[0],r),t)}:function(t,e){for(var s=0,o=0;s<a;s++)o+=l(n(e,i[s],r),t);return o/a}:function(){return 0};return o?1===o?function(t){return u(s[0],t)}:"and"===t.options.conjunction?function(t){for(var e,i=0,n=0;i<o;i++){if((e=u(s[i],t))<=0)return 0;n+=e}return n/o}:function(t){for(var e=0,i=0;e<o;e++)i+=u(s[e],t);return i/o}:function(){return 0}},e.getSortFunction=function(t,e){var s,o,r,a,l,u,c,p,d,h,f;if(f=!(t=(r=this).prepareSearch(t,e)).query&&e.sort_empty||e.sort,d=function(t,i){return"$score"===t?i.score:n(r.items[i.id],t,e.nesting)},l=[],f)for(s=0,o=f.length;s<o;s++)(t.query||"$score"!==f[s].field)&&l.push(f[s]);if(t.query){for(h=!0,s=0,o=l.length;s<o;s++)if("$score"===l[s].field){h=!1;break}h&&l.unshift({field:"$score",direction:"desc"})}else for(s=0,o=l.length;s<o;s++)if("$score"===l[s].field){l.splice(s,1);break}for(p=[],s=0,o=l.length;s<o;s++)p.push("desc"===l[s].direction?-1:1);return(u=l.length)?1===u?(a=l[0].field,c=p[0],function(t,e){return c*i(d(a,t),d(a,e))}):function(t,e){var n,s,o;for(n=0;n<u;n++)if(o=l[n].field,s=p[n]*i(d(o,t),d(o,e)))return s;return 0}:null},e.prepareSearch=function(t,e){if("object"==typeof t)return t;var i=(e=Object.assign({},e)).fields,n=e.sort,s=e.sort_empty;return i&&!Array.isArray(i)&&(e.fields=[i]),n&&!Array.isArray(n)&&(e.sort=[n]),s&&!Array.isArray(s)&&(e.sort_empty=[s]),{options:e,query:String(t||"").toLowerCase(),tokens:this.tokenize(t,e.respect_word_boundaries),total:0,items:[]}},e.search=function(t,e){var i,n,s,o,r=this;return n=this.prepareSearch(t,e),e=n.options,t=n.query,o=e.score||r.getScoreFunction(n),t.length?r.iterator(r.items,(function(t,s){i=o(t),(!1===e.filter||i>0)&&n.items.push({score:i,id:s})})):r.iterator(r.items,(function(t,e){n.items.push({score:1,id:e})})),(s=r.getSortFunction(n,e))&&n.items.sort(s),n.total=n.items.length,"number"==typeof e.limit&&(n.items=n.items.slice(0,e.limit)),n},t}();function a(t,e){if("string"!=typeof e||e.length){var i="string"==typeof e?new RegExp(e,"i"):e;!function t(e){var n=0;if(3===e.nodeType){var s=e.data.search(i);if(s>=0&&e.data.length>0){var o=e.data.match(i),r=document.createElement("span");r.className="highlight";var a=e.splitText(s),l=(a.splitText(o[0].length),a.cloneNode(!0));r.appendChild(l),a.parentNode.replaceChild(r,a),n=1}}else if(1===e.nodeType&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&("highlight"!==e.className||"SPAN"!==e.tagName))for(var u=0;u<e.childNodes.length;++u)u+=t(e.childNodes[u]);return n}(t)}}var l=/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey",u={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,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-control",inputClass:"ts-input",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:null,copyClassesToDropdown:!0,render:{}};function c(t){return null==t?null:"boolean"==typeof t?t?"1":"0":t+""}function p(t){return(t+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function d(t,e,i){var n,s=t.trigger,o={};for(n in t.trigger=function(){var i=arguments[0];if(-1===e.indexOf(i))return s.apply(t,arguments);o[i]=arguments},i.apply(t,[]),t.trigger=s,o)o.hasOwnProperty(n)&&s.apply(t,o[n])}function h(t,e){var i=Object.assign({},u,e),n=i.dataAttr,s=i.labelField,o=i.valueField,r=i.disabledField,a=i.optgroupField,l=i.optgroupLabelField,p=i.optgroupValueField,d=t.tagName.toLowerCase(),h=t.getAttribute("placeholder")||t.getAttribute("data-placeholder");if(!h&&!i.allowEmptyOption){var f=t.querySelector('option[value=""]');f&&(h=f.textContent)}var g={placeholder:h,options:[],optgroups:[],items:[]};return"select"===d?function(){var e,u,d,h,f=g.options,v={},m=function(t){var e=Object.assign({},t.dataset),i=n&&e[n];return"string"==typeof i&&i.length&&(e=Object.assign(e,JSON.parse(i))),e},y=function(t,e){var n=c(t.value);if(n||i.allowEmptyOption)if(v.hasOwnProperty(n)){if(e){var l=v[n][a];l?Array.isArray(l)?l.push(e):v[n][a]=[l,e]:v[n][a]=e}}else{var u=m(t);u[s]=u[s]||t.textContent,u[o]=u[o]||n,u[r]=u[r]||t.disabled,u[a]=u[a]||e,v[n]=u,f.push(u),t.selected&&g.items.push(n)}},w=function(t){var e,i,n,s,o;for((n=t.getAttribute("label"))&&((s=m(t))[l]=n,s[p]=n,s[r]=t.disabled,g.optgroups.push(s)),e=0,i=(o=t.children).length;e<i;e++)y(o[e],n)};for(g.maxItems=t.hasAttribute("multiple")?null:1,e=0,u=(h=t.children).length;e<u;e++)"optgroup"===(d=h[e].tagName.toLowerCase())?w(h[e]):"option"===d&&y(h[e])}():function(){var e,r,a,l,u=t.getAttribute(n);if(u)for(g.options=JSON.parse(u),e=0,r=g.options.length;e<r;e++)g.items.push(g.options[e][o]);else{var c=t.value.trim()||"";if(!i.allowEmptyOption&&!c.length)return;for(e=0,r=(a=c.split(i.delimiter)).length;e<r;e++)(l={})[s]=a[e],l[o]=a[e],g.options.push(l);g.items=a}}(),Object.assign({},u,g,e)}function f(t){if(t.jquery)return t[0];if(t instanceof HTMLElement)return t;if(t.indexOf("<")>-1){var e=document.createElement("div");return e.innerHTML=t.trim(),e.querySelector(":first-child")}return document.querySelector(t)}function g(t,e){var i=document.createEvent("HTMLEvents");i.initEvent(e,!0,!1),t.dispatchEvent(i)}function v(t,e){Object.keys(e).forEach((function(i){t.style[i]=e[i]}))}function m(t){var e=w.apply(null,arguments);(t=b(t)).map((function(t){e.map((function(e){t.classList.add(e)}))}))}function y(t){var e=w.apply(null,arguments);(t=b(t)).map((function(t){e.map((function(e){t.classList.remove(e)}))}))}function w(){for(var t=[],e=1;e<arguments.length;e++){var i=arguments[e];"string"==typeof i&&(i=i.trim().split(/[\11\12\14\15\40]/)),Array.isArray(i)&&(t=t.concat(i))}return t.filter(Boolean)}function b(t){return Array.isArray(t)||(t=[t]),t}function O(t,e,i){if(!i||i.contains(t))for(;t&&t.matches;){if(t.matches(e))return t;t=t.parentNode}}function C(t,e){return e>0?t[t.length-1]:t[0]}function A(t,e){if(!t)return-1;e=e||t.nodeName;for(var i=0;t=t.previousElementSibling;)t.matches(e)&&i++;return i}var I,_=function(e){function i(t,i){var n,s,o=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n=e.call(this)||this);if((t=f(t)).tomselect)throw new Error("Tom Select already initialized on this element");return t.tomselect=o,n.control_input=null,n.wrapper=null,n.dropdown=null,n._destroy=null,n.control=null,n.sifter=null,n.dropdown_content=null,s=(window.getComputedStyle&&window.getComputedStyle(t,null)).getPropertyValue("direction"),n.order=0,n.settings=h(t,i),n.input=t,n.tabIndex=t.getAttribute("tabindex")||"",n.is_select_tag="select"===t.tagName.toLowerCase(),n.rtl=/rtl/i.test(s),n.highlightedValue=null,n.isBlurring=!1,n.isOpen=!1,n.isDisabled=!1,n.isRequired=t.required,n.isInvalid=!1,n.isLocked=!1,n.isFocused=!1,n.isInputHidden=!1,n.isSetup=!1,n.ignoreFocus=!1,n.ignoreBlur=!1,n.ignoreHover=!1,n.hasOptions=!1,n.currentResults=null,n.lastValue="",n.caretPos=0,n.loading=0,n.loadedSearches={},n.activeOption=null,n.activeItems=[],n.optgroups={},n.options={},n.userOptions={},n.items=[],n.renderCache={item:{},option:{}},o.settings.load&&o.settings.loadThrottle&&(o.settings.load=o.loadDebounce(o.settings.load,o.settings.loadThrottle)),o.sifter=new r(n.options,{diacritics:o.settings.diacritics}),o.setupOptions(o.settings.options,o.settings.optgroups),delete o.settings.optgroups,delete o.settings.options,o.settings.mode=o.settings.mode||(1===o.settings.maxItems?"single":"multi"),"boolean"!=typeof o.settings.hideSelected&&(o.settings.hideSelected="multi"===o.settings.mode),"string"==typeof o.settings.createFilter&&(o.settings.createFilter=new RegExp(o.settings.createFilter)),o.initializePlugins(o.settings.plugins),o.setupCallbacks(),o.setupTemplates(),o.setup(),n}t(i,e);var n=i.prototype;return n.setup=function(){var t,e,i,n,s,o,r,a,l,u=this,c=u.settings,p=u.input,d={passive:!0};if(o=u.settings.mode,r=p.getAttribute("class")||"",m(t=f("<div>"),c.wrapperClass,r,o),m(e=f('<div class="items">'),c.inputClass),t.append(e),m(n=u.render("dropdown"),c.dropdownClass,o),m(s=f('<div style="scroll-behavior: smooth;">'),c.dropdownContentClass),n.append(s),f(c.dropdownParent||t).appendChild(n),c.controlInput)i=f(c.controlInput);else{i=f('<input type="text" autocomplete="off" />');for(var h=["autocorrect","autocapitalize","autocomplete"],g=0;g<h.length;g++){var v=h[g];p.getAttribute(v)&&i.setAttribute(v,p.getAttribute(v))}}if(c.controlInput||(i.setAttribute("tabindex",p.disabled?"-1":u.tabIndex),e.appendChild(i)),l=p.getAttribute("id")){i.setAttribute("id",l+"-tomselected");var y=document.querySelector("label[for='"+l+"']");y&&y.setAttribute("for",l+"-tomselected")}if(u.settings.copyClassesToDropdown&&m(n,r),t.style.width=p.style.width,u.plugins.names.length&&(a="plugin-"+u.plugins.names.join(" plugin-"),m([t,n],a)),(null===c.maxItems||c.maxItems>1)&&u.is_select_tag&&p.setAttribute("multiple","multiple"),u.settings.placeholder&&i.setAttribute("placeholder",c.placeholder),!u.settings.splitOn&&u.settings.delimiter){var w=u.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");u.settings.splitOn=new RegExp("\\s*"+w+"+\\s*")}u.control=e,u.control_input=i,u.wrapper=t,u.dropdown=n,u.dropdown_content=s,u.control_input.type=p.type,n.addEventListener("mouseenter",(function(t){var e=O(t.target,"[data-selectable]",n);if(e)return u.onOptionHover.call(u,t,e)}),!0),e.addEventListener("mousedown",(function(t){var i=O(t.target,"."+u.settings.itemClass,e);return i?u.onItemSelect.call(u,t,i):u.onMouseDown.call(u,t)})),e.addEventListener("click",(function(){u.onClick.apply(u,arguments)})),i.addEventListener("mousedown",(function(t){t.stopPropagation()})),i.addEventListener("keydown",(function(){return u.onKeyDown.apply(u,arguments)})),i.addEventListener("keyup",(function(){return u.onKeyUp.apply(u,arguments)})),i.addEventListener("keypress",(function(){return u.onKeyPress.apply(u,arguments)})),i.addEventListener("resize",(function(){u.positionDropdown.apply(u,[])}),d),i.addEventListener("blur",(function(){return u.onBlur.apply(u,arguments)})),i.addEventListener("focus",(function(){return u.ignoreBlur=!1,u.onFocus.apply(u,arguments)})),i.addEventListener("paste",(function(){return u.onPaste.apply(u,arguments)}));var b=function(t){var e=O(t.target,"[data-selectable]",u.dropdown);e||u.wrapper.contains(t.target)?(t.preventDefault(),t.stopPropagation(),e&&u.onOptionSelect(t,e)):u.isFocused&&u.blur(t.target)},C=function(){u.isOpen&&u.positionDropdown.apply(u,arguments)},A=function(){u.ignoreHover=!1};document.addEventListener("mousedown",b),window.addEventListener("sroll",C,d),window.addEventListener("resize",C,d),window.addEventListener("mousemove",A,d),u._destroy=function(){document.removeEventListener("mousedown",b),window.removeEventListener("mousemove",A),window.removeEventListener("sroll",C),window.removeEventListener("resize",C)};for(var I=[];p.children.length>0;)I.push(p.children[0]),p.children[0].remove();this.revertSettings={children:I,tabindex:p.getAttribute("tabindex")},p.setAttribute("tabindex",-1),p.setAttribute("hidden","hidden"),p.insertAdjacentElement("afterend",u.wrapper),u.setValue(c.items),delete c.items,p.addEventListener("invalid",(function(t){t.preventDefault(),u.isInvalid||(u.isInvalid=!0,u.refreshState())})),u.updateOriginalInput(),u.refreshItems(),u.refreshState(),u.isSetup=!0,p.disabled&&u.disable(),u.on("change",this.onChange),m(p,"tomselected"),u.trigger("initialize"),!0===c.preload&&u.onSearchChange("")},n.setupOptions=function(t,e){var i,n;for(e=e||[],i=0,n=(t=t||[]).length;i<n;i++)this.registerOption(t[i]);for(i=0,n=e.length;i<n;i++)this.registerOptionGroup(e[i])},n.setupTemplates=function(){var t=this,e=t.settings.labelField,i=t.settings.optgroupLabelField,n={optgroup:function(t,e){var i=document.createElement("div");return i.className="optgroup",i.appendChild(t.options),i},optgroup_header:function(t,e){return'<div class="optgroup-header">'+e(t[i])+"</div>"},option:function(t,i){return"<div>"+i(t[e])+"</div>"},item:function(t,i){return"<div>"+i(t[e])+"</div>"},option_create:function(t,e){return'<div class="create">Add <strong>'+e(t.input)+"</strong>…</div>"},no_results:function(t,e){return'<div class="no-results">No results found</div>'},loading:function(t,e){return'<div class="spinner"></div>'},dropdown:function(){return'<div style="display:none"></div>'}};t.settings.render=Object.assign({},n,t.settings.render)},n.setupCallbacks=function(){var t,e,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",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)},n.onClick=function(t){var e=this;e.isFocused&&e.isOpen||(e.focus(),t.preventDefault())},n.onMouseDown=function(t){var e=this;if(e.isFocused){if(t.target!==e.control_input)return"single"===e.settings.mode?e.isOpen?e.close():e.open():e.setActiveItem(),!1}else window.setTimeout((function(){e.focus()}),0)},n.onChange=function(){g(this.input,"change")},n.onPaste=function(t){var e=this;e.isFull()||e.isInputHidden||e.isLocked?t.preventDefault():e.settings.splitOn&&setTimeout((function(){var t=e.inputValue();if(t.match(e.settings.splitOn))for(var i=t.trim().split(e.settings.splitOn),n=0,s=i.length;n<s;n++)e.createItem(i[n])}),0)},n.onKeyPress=function(t){if(this.isLocked)return t&&t.preventDefault();var e=String.fromCharCode(t.keyCode||t.which);return this.settings.create&&"multi"===this.settings.mode&&e===this.settings.delimiter?(this.createItem(),t.preventDefault(),!1):void 0},n.onKeyDown=function(t){var e=this;t.target,e.control_input;if(e.ignoreHover=!0,e.isLocked)9!==t.keyCode&&t.preventDefault();else{switch(t.keyCode){case 65:if(e.isKeyDown(l,t))return void e.selectAll();break;case 27:return void(e.isOpen&&(t.preventDefault(),t.stopPropagation(),e.close()));case 40:if(!e.isOpen&&e.hasOptions)e.open();else if(e.activeOption){var i=e.getAdjacent(e.activeOption,1);i&&e.setActiveOption(i,!0)}return void t.preventDefault();case 38:if(e.activeOption){var n=e.getAdjacent(e.activeOption,-1);n&&e.setActiveOption(n,!0)}return void t.preventDefault();case 13:return void(e.isOpen&&e.activeOption&&(e.onOptionSelect(t,e.activeOption),t.preventDefault()));case 37:return void e.advanceSelection(-1,t);case 39:return void e.advanceSelection(1,t);case 9:return e.settings.selectOnTab&&e.isOpen&&e.activeOption&&(e.onOptionSelect(t,e.activeOption),t.preventDefault()),void(e.settings.create&&e.createItem()&&t.preventDefault());case 8:case 46:return void e.deleteSelection(t)}!e.isInputHidden||e.isKeyDown(l,t)||t.preventDefault()}},n.onKeyUp=function(t){var e=this;if(e.isLocked)return t&&t.preventDefault();var i=e.inputValue();e.lastValue!==i&&(e.lastValue=i,e.onSearchChange(i),e.refreshOptions(),e.trigger("type",i))},n.onSearchChange=function(t){var e=this,i=e.settings.load;i&&(e.loadedSearches.hasOwnProperty(t)||(e.loadedSearches[t]=!0,e.load((function(n){i.apply(e,[t,n])}))))},n.onFocus=function(t){void 0===t&&(t=null);var e=this,i=e.isFocused;if(e.isDisabled)return e.blur(),t&&t.preventDefault(),!1;e.ignoreFocus||(e.isFocused=!0,"focus"===e.settings.preload&&e.onSearchChange(""),i||e.trigger("focus"),e.activeItems.length||(e.showInput(),e.setActiveItem(),e.refreshOptions(!!e.settings.openOnFocus)),e.refreshState())},n.onBlur=function(t,e){var i=this;if(i.isFocused){if(i.isFocused=!1,i.ignoreFocus=!1,!i.ignoreBlur&&document.activeElement===i.dropdown_content)return i.ignoreBlur=!0,void i.onFocus(t);var n=function(){i.close(),i.setActiveItem(),i.setActiveOption(),i.setCaret(i.items.length),i.refreshState(),e&&e.focus&&e.focus(),i.isBlurring=!1,i.trigger("blur")};i.isBlurring=!0,i.settings.create&&i.settings.createOnBlur?i.createItem(null,!1,n):n()}},n.onOptionHover=function(t,e){this.ignoreHover||this.setActiveOption(e,!1)},n.onOptionSelect=function(t,e){var i,n=this;e&&(e.parentElement&&e.parentElement.matches("[data-disabled]")||(e.classList.contains("create")?n.createItem(null,!0,(function(){n.settings.closeAfterSelect&&n.close()})):void 0!==(i=e.dataset.value)&&(n.lastQuery=null,n.addItem(i),n.settings.closeAfterSelect?n.close():!n.settings.hideSelected&&t.type&&/mouse/.test(t.type)&&n.setActiveOption(n.getOption(i)))))},n.onItemSelect=function(t,e){var i=this;i.isLocked||"multi"===i.settings.mode&&(t.preventDefault(),i.setActiveItem(e,t))},n.load=function(t){var e=this;m(e.wrapper,e.settings.loadingClass),e.loading++,t.call(e,(function(t,i){e.loading=Math.max(e.loading-1,0),e.lastQuery=null,e.setupOptions(t,i),e.refreshOptions(e.isFocused&&!e.isInputHidden),e.loading||y(e.wrapper,e.settings.loadingClass),e.trigger("load",t)}))},n.loadDebounce=function(t,e){var i;return function(){var n=this,s=arguments;i&&(n.loading=Math.max(n.loading-1,0)),window.clearTimeout(i),i=window.setTimeout((function(){i=null,t.apply(n,s)}),e)}},n.setTextboxValue=function(t){var e=this.control_input;e.value!==t&&(e.value=t,g(e,"update"),this.lastValue=t)},n.getValue=function(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)},n.setValue=function(t,e){void 0===e&&(e=!1),d(this,e?[]:["change"],(function(){this.clear(e),this.addItems(t,e)}))},n.setActiveItem=function(t,e){var i,n,s,o,r,a;if(void 0===t&&(t=null),void 0===e&&(e=null),"single"!==this.settings.mode){if(!t)return y(this.activeItems,"active"),this.activeItems=[],void(this.isFocused&&this.showInput());if("mousedown"===(i=e&&e.type.toLowerCase())&&this.isKeyDown("shiftKey",e)&&this.activeItems.length){for(a=this.getLastActive(),(s=Array.prototype.indexOf.call(this.control.children,a))>(o=Array.prototype.indexOf.call(this.control.children,t))&&(r=s,s=o,o=r),n=s;n<=o;n++)t=this.control.children[n],-1===this.activeItems.indexOf(t)&&this.setActiveItemClass(t);e.preventDefault()}else"mousedown"===i&&this.isKeyDown(l,e)||"keydown"===i&&this.isKeyDown("shiftKey",e)?t.classList.contains("active")?this.removeActiveItem(t):this.setActiveItemClass(t):(y(this.activeItems,"active"),this.activeItems=[],this.setActiveItemClass(t));this.hideInput(),this.isFocused||this.focus()}},n.setActiveItemClass=function(t){var e=this.control.querySelector(".last-active");e&&y(e,"last-active"),m(t,"active last-active"),-1==this.activeItems.indexOf(t)&&this.activeItems.push(t)},n.removeActiveItem=function(t){var e=this.activeItems.indexOf(t);this.activeItems.splice(e,1),y(t,"active")},n.setActiveOption=function(t,e){var i,n,s;if(void 0===t&&(t=null),void 0===e&&(e=!1),t!==this.activeOption&&(this.activeOption&&y(this.activeOption,"active"),this.activeOption=null,t&&(this.activeOption=t,m(t,"active"),e))){i=this.dropdown_content.clientHeight;var o=this.dropdown_content.scrollTop||0;n=this.activeOption.offsetHeight,(s=this.activeOption.getBoundingClientRect().top-this.dropdown_content.getBoundingClientRect().top+o)+n>i+o?this.dropdown_content.scrollTop=s-i+n:s<o&&(this.dropdown_content.scrollTop=s)}},n.selectAll=function(){"single"!==this.settings.mode&&(this.activeItems=this.controlChildren(),this.activeItems.length&&(m(this.activeItems,"active"),this.hideInput(),this.close()),this.focus())},n.hideInput=function(){this.settings.controlInput||(this.setTextboxValue(""),v(this.control_input,{opacity:0,position:"absolute",left:(this.rtl?1e4:-1e4)+"px"}),this.isInputHidden=!0)},n.showInput=function(){this.settings.controlInput||(v(this.control_input,{opacity:1,position:"relative",left:0}),this.isInputHidden=!1)},n.inputValue=function(){return this.control_input.value.trim()},n.focus=function(){var t=this;t.isDisabled||(t.ignoreFocus=!0,t.control_input.focus(),window.setTimeout((function(){t.ignoreFocus=!1,t.onFocus()}),0))},n.blur=function(t){void 0===t&&(t=null),this.control_input.blur(),this.onBlur(null,t)},n.getScoreFunction=function(t){return this.sifter.getScoreFunction(t,this.getSearchOptions())},n.getSearchOptions=function(){var t=this.settings,e=t.sortField;return"string"==typeof e&&(e=[{field:e}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}},n.search=function(t){var e,i,n,s=this,o=s.settings,r=this.getSearchOptions();if(o.score&&"function"!=typeof(n=s.settings.score.call(this,t)))throw new Error('Tom Select "score" setting must be a function that returns a function');if(t!==s.lastQuery?(s.lastQuery=t,i=s.sifter.search(t,Object.assign(r,{score:n})),s.currentResults=i):i=Object.assign({},s.currentResults),o.hideSelected)for(e=i.items.length-1;e>=0;e--)-1!==s.items.indexOf(c(i.items[e].id))&&i.items.splice(e,1);return i},n.refreshOptions=function(t){var e,i,n,s,o,r,l,u,p,d,h,f,g;void 0===t&&(t=!0);var v,w=this,b=w.inputValue(),O=w.search(b),C=w.activeOption&&c(w.activeOption.dataset.value),A=!1;for(s=O.items.length,"number"==typeof w.settings.maxOptions&&(s=Math.min(s,w.settings.maxOptions)),s>0&&(A=!0),o={},r=[],e=0;e<s;e++){var I=w.options[O.items[e].id],_=c(I[w.settings.valueField]),S=w.getOption(_);for(S||(S=w.render("option",I)),l=I[w.settings.optgroupField]||"",i=0,n=(u=Array.isArray(l)?l:[l])&&u.length;i<n;i++)l=u[i],w.optgroups.hasOwnProperty(l)||(l=""),o.hasOwnProperty(l)||(o[l]=document.createDocumentFragment(),r.push(l)),i>0&&y(S=S.cloneNode(!0),"active"),o[l].appendChild(S)}for(this.settings.lockOptgroupOrder&&r.sort((function(t,e){return(w.optgroups[t].$order||0)-(w.optgroups[e].$order||0)})),p=document.createDocumentFragment(),e=0,s=r.length;e<s;e++)if(l=r[e],w.optgroups.hasOwnProperty(l)&&o[l].children.length){var x=document.createDocumentFragment();x.appendChild(w.render("optgroup_header",w.optgroups[l])),x.appendChild(o[l]);var F=w.render("optgroup",{group:w.optgroups[l],options:x});p.appendChild(F)}else p.appendChild(o[l]);if(w.dropdown_content.innerHTML="",w.dropdown_content.appendChild(p),w.settings.highlight&&(w.dropdown_content,v=document.querySelectorAll("span.highlight"),Array.prototype.forEach.call(v,(function(t,e){var i=t.parentNode;i.replaceChild(t.firstChild,t),i.normalize()})),O.query.length&&O.tokens.length))for(e=0,s=O.tokens.length;e<s;e++)a(w.dropdown_content,O.tokens[e].regex);if(!w.settings.hideSelected)for(e=0,s=w.items.length;e<s;e++){var k=w.getOption(w.items[e]);k&&m(k,"selected")}var L=function(t){A=!0;var e=w.render(t,{input:b});return w.dropdown_content.insertBefore(e,w.dropdown_content.firstChild),e};if(w.loading?L("loading"):0===O.items.length&&w.settings.render.no_results&&b.length&&L("no_results"),(d=w.canCreate(b))&&(g=L("option_create")),w.hasOptions=O.items.length>0||d,A){if(O.items.length>0)if((f=C&&w.getOption(C))&&w.dropdown_content.contains(f))h=f;else if("single"===w.settings.mode&&w.items.length)h=w.getOption(w.items[0]);else{var E=0;g&&!w.settings.addPrecedence&&(E=1),h=w.selectable()[E]}else h=g;w.setActiveOption(h),t&&!w.isOpen&&w.open()}else w.setActiveOption(),t&&w.isOpen&&w.close()},n.selectable=function(){return this.dropdown_content.querySelectorAll("[data-selectable]")},n.addOption=function(t){var e,i,n,s=this;if(Array.isArray(t))for(e=0,i=t.length;e<i;e++)s.addOption(t[e]);else(n=s.registerOption(t))&&(s.userOptions[n]=!0,s.lastQuery=null,s.trigger("option_add",n,t))},n.registerOption=function(t){var e=c(t[this.settings.valueField]);return null!=e&&!this.options.hasOwnProperty(e)&&(t.$order=t.$order||++this.order,this.options[e]=t,e)},n.registerOptionGroup=function(t){var e=c(t[this.settings.optgroupValueField]);return!!e&&(t.$order=t.$order||++this.order,this.optgroups[e]=t,e)},n.addOptionGroup=function(t,e){var i;e[this.settings.optgroupValueField]=t,(i=this.registerOptionGroup(e))&&this.trigger("optgroup_add",i,e)},n.removeOptionGroup=function(t){this.optgroups.hasOwnProperty(t)&&(delete this.optgroups[t],this.clearCache(),this.trigger("optgroup_remove",t))},n.clearOptionGroups=function(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")},n.updateOption=function(t,e){var i,n,s,o,r,a,l,u=this;if(t=c(t),s=c(e[u.settings.valueField]),null!==t&&u.options.hasOwnProperty(t)){if("string"!=typeof s)throw new Error("Value must be set in option data");l=u.options[t].$order,s!==t&&(delete u.options[t],-1!==(o=u.items.indexOf(t))&&u.items.splice(o,1,s)),e.$order=e.$order||l,u.options[s]=e,r=u.renderCache.item,a=u.renderCache.option,r&&(delete r[t],delete r[s]),a&&(delete a[t],delete a[s]),-1!==u.items.indexOf(s)&&(i=u.getItem(t),n=u.render("item",e),i.classList.contains("active")&&m(n,"active"),i.parentNode.insertBefore(n,i),i.remove()),u.lastQuery=null,u.isOpen&&u.refreshOptions(!1)}},n.removeOption=function(t,e){var i=this;t=c(t);var n=i.renderCache.item,s=i.renderCache.option;n&&delete n[t],s&&delete s[t],delete i.userOptions[t],delete i.options[t],i.lastQuery=null,i.trigger("option_remove",t),i.removeItem(t,e)},n.clearOptions=function(){this.loadedSearches={},this.userOptions={},this.clearCache();var t={};for(var e in this.options)this.options.hasOwnProperty(e)&&this.items.indexOf(e)>=0&&(t[e]=this.options[e]);this.options=this.sifter.items=t,this.lastQuery=null,this.trigger("option_clear")},n.getOption=function(t){return this.renderCache.option.hasOwnProperty(t)?this.renderCache.option[t]:this.getElementWithValue(t,this.selectable())},n.getAdjacent=function(t,e,i){if(void 0===i&&(i="option"),t){var n=this,s=n.settings.optionClass,o=n.dropdown;"item"==i&&(o=n.control,s=n.settings.itemClass);for(var r=o.querySelectorAll("."+s),a=0;a<r.length;a++)if(r[a]==t)return e>0?r[a+1]:r[a-1]}},n.getElementWithValue=function(t,e){if(null!=(t=c(t)))for(var i=0,n=e.length;i<n;i++)if(e[i].getAttribute("data-value")===t)return e[i]},n.getItem=function(t){return this.getElementWithValue(t,this.control.children)},n.addItems=function(t,e){void 0===e&&(e=!1),this.buffer=document.createDocumentFragment();for(var i=this.control.children,n=0;n<i.length;n++)this.buffer.appendChild(i[n]);for(var s=Array.isArray(t)?t:[t],o=0,r=s.length;o<r;o++)this.isPending=o<r-1,this.addItem(s[o],e);var a=this.control;a.insertBefore(this.buffer,a.firstChild),this.buffer=null},n.addItem=function(t,e){void 0===e&&(e=!1),d(this,e?[]:["change"],(function(){var i,n,s=this,o=s.settings.mode;if(t=c(t),(-1===s.items.indexOf(t)||("single"===o&&s.close(),"single"!==o&&s.settings.duplicates))&&s.options.hasOwnProperty(t)&&("single"===o&&s.clear(e),("multi"!==o||!s.isFull())&&(i=s.render("item",s.options[t]),this.control.contains(i)&&(i=i.cloneNode(!0)),n=s.isFull(),s.items.splice(s.caretPos,0,t),s.insertAtCaret(i),(!s.isPending||!n&&s.isFull())&&s.refreshState(),s.isSetup))){var r=s.selectable();if(!s.isPending){var a=s.getOption(t),l=s.getAdjacent(a,1);s.refreshOptions(s.isFocused&&"single"!==o),l&&s.setActiveOption(l)}!r.length||s.isFull()?s.close():s.isPending||s.positionDropdown(),s.trigger("item_add",t,i),s.isPending||s.updateOriginalInput({silent:e})}}))},n.removeItem=function(t,e){var i,n;void 0===e&&(e=!1);var s=this.getItem(t);s&&(t=c(s.dataset.value),-1!==(i=this.items.indexOf(t))&&(s.remove(),s.classList.contains("active")&&(n=this.activeItems.indexOf(s),this.activeItems.splice(n,1),y(s,"active")),this.items.splice(i,1),this.lastQuery=null,!this.settings.persist&&this.userOptions.hasOwnProperty(t)&&this.removeOption(t,e),i<this.caretPos&&this.setCaret(this.caretPos-1),this.refreshState(),this.updateOriginalInput({silent:e}),this.positionDropdown(),this.trigger("item_remove",t,s)))},n.createItem=function(t,e,i){void 0===t&&(t=null),void 0===e&&(e=!0),void 0===i&&(i=null);var n,s=this,o=s.caretPos;if(t=t||s.inputValue(),"function"!=typeof i&&(i=function(){}),!s.canCreate(t))return i(),!1;s.lock();var r=!1,a=function(t){if(s.unlock(),!t||"object"!=typeof t)return i();var n=c(t[s.settings.valueField]);if("string"!=typeof n)return i();s.setTextboxValue(""),s.addOption(t),s.setCaret(o),s.addItem(n),s.refreshOptions(e&&"single"!==s.settings.mode),i(t),r=!0};return"function"==typeof s.settings.create?n=s.settings.create.apply(this,[t,a]):((n={})[s.settings.labelField]=t,n[s.settings.valueField]=t),r||a(n),!0},n.refreshItems=function(){this.lastQuery=null,this.isSetup&&this.addItems(this.items),this.refreshState(),this.updateOriginalInput()},n.refreshState=function(){var t=this;t.refreshValidityState();var e=t.isFull(),i=t.isLocked;t.wrapper.classList.toggle("rtl",t.rtl);var n,s=t.control.classList;s.toggle("focus",t.isFocused),s.toggle("disabled",t.isDisabled),s.toggle("required",t.isRequired),s.toggle("invalid",t.isInvalid),s.toggle("locked",i),s.toggle("full",e),s.toggle("not-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)},n.refreshValidityState=function(){if(this.input.checkValidity){var t=!this.input.checkValidity();this.isInvalid=t,this.control_input.required=t,this.input.required=!t}},n.isFull=function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},n.updateOriginalInput=function(t){var e,i,n,s,o=this;if(t=t||{},o.is_select_tag){for(n=[],e=0,i=o.items.length;e<i;e++)s=o.options[o.items[e]][o.settings.labelField]||"",n.push('<option value="'+p(o.items[e])+'" selected="selected">'+p(s)+"</option>");n.length||this.input.hasAttribute("multiple")||n.push('<option value="" selected="selected"></option>'),o.input.innerHTML=n.join("")}else o.input.value=o.getValue(),o.input.setAttribute("value",o.input.value);o.isSetup&&(t.silent||o.trigger("change",o.input.value))},n.open=function(){var t=this;t.isLocked||t.isOpen||"multi"===t.settings.mode&&t.isFull()||(t.focus(),t.isOpen=!0,t.refreshState(),v(t.dropdown,{visibility:"hidden",display:"block"}),t.positionDropdown(),v(t.dropdown,{visibility:"visible",display:"block"}),t.trigger("dropdown_open",t.dropdown))},n.close=function(){var t=this,e=t.isOpen;"single"===t.settings.mode&&t.items.length&&(t.hideInput(),t.isBlurring||t.blur()),t.isOpen=!1,v(t.dropdown,{display:"none"}),t.setActiveOption(),t.refreshState(),e&&t.trigger("dropdown_close",t.dropdown)},n.positionDropdown=function(){if("body"===this.settings.dropdownParent){var t=this.control,e=t.getBoundingClientRect(),i=t.offsetHeight+e.top+window.scrollY,n=e.left+window.scrollX;v(this.dropdown,{width:e.width+"px",top:i+"px",left:n+"px"})}},n.clear=function(t){if(this.items.length){for(var e=this.controlChildren(),i=0;i<e.length;i++)e[i].remove();this.items=[],this.lastQuery=null,this.setCaret(0),this.setActiveItem(),this.updateOriginalInput({silent:t}),this.refreshState(),this.showInput(),this.trigger("clear")}},n.insertAtCaret=function(t){var e=Math.min(this.caretPos,this.items.length),i=this.buffer||this.control;0===e?i.insertBefore(t,i.firstChild):i.insertBefore(t,i.children[e]),this.setCaret(e+1)},n.deleteSelection=function(t){var e,i,n,s,o,r,a,l=this;if(n=t&&8===t.keyCode?-1:1,s={start:(a=l.control_input).selectionStart,length:a.selectionEnd-a.selectionStart},o=[],l.activeItems.length){for(r=A(C(l.activeItems,n)),n>0&&r++,e=0,i=l.activeItems.length;e<i;e++)o.push(l.activeItems[e].dataset.value);t&&(t.preventDefault(),t.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(n<0&&0===s.start&&0===s.length?o.push(l.items[l.caretPos-1]):n>0&&s.start===l.inputValue().length&&o.push(l.items[l.caretPos]));if(!o.length||"function"==typeof l.settings.onDelete&&!1===l.settings.onDelete.apply(l,[o,t]))return!1;for(void 0!==r&&l.setCaret(r);o.length;)l.removeItem(o.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!1),!0},n.advanceSelection=function(t,e){var i,n;if(0!==t)if(this.rtl&&(t*=-1),this.isKeyDown(l,e)||this.isKeyDown("shiftKey",e)){n=this.getLastActive(t);var s=this.getAdjacent(n,t,"item");s&&(s.classList.contains("active")&&this.removeActiveItem(n),this.setActiveItemClass(s))}else this.isFocused&&!this.isInputHidden?this.inputValue().length||this.setCaret(this.caretPos+t):(n=this.getLastActive(t))&&(i=A(n),this.setCaret(t>0?i+1:i),this.setActiveItem())},n.getLastActive=function(t){var e=this.control.querySelector(".last-active");return e||function(t,e,i){var n=t.querySelectorAll(e);if(n)return C(n,i)}(this.control,".active",t)},n.setCaret=function(t){var e=this;if(t="single"===e.settings.mode||e.settings.controlInput?e.items.length:Math.max(0,Math.min(e.items.length,t)),!e.settings.controlInput&&!e.isPending){var i,n,s=this.controlChildren(),o=s.length;for(i=0;i<o;i++)n=s[i],i<t?e.control_input.insertAdjacentElement("beforebegin",n):e.control.appendChild(n)}e.caretPos=t},n.controlChildren=function(){return Array.prototype.filter.call(this.control.children,(function(t){return"INPUT"!==t.nodeName}))},n.lock=function(){this.close(),this.isLocked=!0,this.refreshState()},n.unlock=function(){this.isLocked=!1,this.refreshState()},n.disable=function(){this.input.disabled=!0,this.control_input.disabled=!0,this.control_input.tabIndex=-1,this.isDisabled=!0,this.lock()},n.enable=function(){this.input.disabled=!1,this.control_input.disabled=!1,this.control_input.tabIndex=this.tabIndex,this.isDisabled=!1,this.unlock()},n.destroy=function(){var t=this.revertSettings;this.trigger("destroy"),this.off(),this.wrapper.remove(),this.dropdown.remove(),this.input.innerHTML="",t.tabindex?this.input.setAttribute("tabindex",t.tabindex):this.input.removeAttribute("tabindex"),y(this.input,"tomselected"),this.input.removeAttribute("hidden");for(var e=0;e<t.children.length;e++)this.input.appendChild(t.children[e]);this._destroy(),delete this.input.tomselect},n.render=function(t,e){var i,n,s;void 0===e&&(e=null);var o=this;return"option"!==t&&"item"!==t||(i=c(e[o.settings.valueField]),!o.renderCache[t].hasOwnProperty(i))?(s=f(o.settings.render[t].apply(this,[e,p])),"option"===t||"option_create"===t?e[o.settings.disabledField]||s.setAttribute("data-selectable",""):"optgroup"===t&&(n=e.group[o.settings.optgroupValueField],s.setAttribute("data-group",n),e.group[o.settings.disabledField]&&s.setAttribute("data-disabled","")),"option"!==t&&"item"!==t||(s.setAttribute("data-value",i),m(s,"item"===t?o.settings.itemClass:o.settings.optionClass),o.renderCache[t][i]=s),s):o.renderCache[t][i]},n.clearCache=function(t){void 0===t&&(t=null);null===t?this.renderCache={item:{},option:{}}:this.renderCache[t]={}},n.canCreate=function(t){if(!this.settings.create)return!1;var e=this.settings.createFilter;return t.length&&("function"!=typeof e||e.call(this,t))&&(!(e instanceof RegExp)||e.test(t))},n.isKeyDown=function(t,e){return!!e&&(!!e[t]&&1===Number(e.altKey)+Number(e.ctrlKey)+Number(e.shiftKey)+Number(e.metaKey))},n.hook=function(t,e,i){var n=this,s=n[e];n[e]=function(){var e,o;return"after"===t&&(e=s.apply(n,arguments)),o=i.apply(n,arguments),"instead"===t?o:("before"===t&&(e=s.apply(n,arguments)),e)}},i}(((I=e).plugins={},function(e){function i(){return e.apply(this,arguments)||this}t(i,e),i.define=function(t,e){I.plugins[t]={name:t,fn:e}};var n=i.prototype;return n.initializePlugins=function(t){var e,i,n,s=this,o=[];if(s.plugins={names:[],settings:{},requested:{},loaded:{}},Array.isArray(t))for(e=0,i=t.length;e<i;e++)"string"==typeof t[e]?o.push(t[e]):(s.plugins.settings[t[e].name]=t[e].options,o.push(t[e].name));else if(t)for(n in t)t.hasOwnProperty(n)&&(s.plugins.settings[n]=t[n],o.push(n));for(;o.length;)s.require(o.shift())},n.loadPlugin=function(t){var e=this,i=e.plugins,n=I.plugins[t];if(!I.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin');i.requested[t]=!0,i.loaded[t]=n.fn.apply(e,[e.plugins.settings[t]||{}]),i.names.push(t)},n.require=function(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]},i}(I)));return _.define("change_listener",(function(t){var e=this,i=!1;e.input.addEventListener("change",(function(){if(i)i=!1;else{i=!0;var t=h(e.input,{});e.setupOptions(t.options,t.optgroups),e.setValue(t.items)}}))})),_.define("drag_drop",(function(t){if(!$.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var e=this,i=e.lock,n=e.unlock;e.hook("instead","lock",(function(){var t=e.control.dataset.sortable;return t&&t.disable(),i.apply(e,arguments)})),e.hook("instead","unlock",(function(){var t=e.control.dataset.sortable;return t&&t.enable(),n.apply(e,arguments)})),e.hook("after","setup",(function(){var t=$(e.control).sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:e.isLocked,start:function(e,i){i.placeholder.css("width",i.helper.css("width")),t.css({overflow:"visible"})},stop:function(){t.css({overflow:"hidden"});var i=[];t.children("[data-value]").each((function(){i.push($(this).attr("data-value"))})),e.setValue(i)}})}))}})),_.define("dropdown_header",(function(t){var e=this;t=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:function(t){return'<div class="'+t.headerClass+'"><div class="'+t.titleRowClass+'"><span class="'+t.labelClass+'">'+t.title+'</span><a href="javascript:void(0)" class="'+t.closeClass+'">×</a></div></div>'}},t),e.hook("after","setup",(function(){var i=f(t.html(t));e.dropdown.insertBefore(i,e.dropdown.firstChild)}))})),_.define("input_autogrow",(function(t){var e=this;e.hook("after","setup",(function(){var t=document.createElement("span"),i=this.control_input;t.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",e.wrapper.appendChild(t);for(var n=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"],s=0,o=n.length;s<o;s++){var r=n[s];t.style[r]=i.style[r]}var a=function(){t.textContent=i.value,i.style.width=t.clientWidth+"px"};i.addEventListener("input",a),i.addEventListener("keyup",a),i.addEventListener("blur",a),i.addEventListener("update",a)}))})),_.define("no_backspace_delete",(function(t){this.hook("instead","setActiveItem",(function(){})),this.hook("instead","selectAll",(function(){})),this.hook("instead","deleteSelection",(function(){}))})),_.define("optgroup_columns",(function(t){var e=this,i=e.onKeyDown;e.hook("instead","onKeyDown",(function(t){var n,s,o,r;if(!e.isOpen||37!==t.keyCode&&39!==t.keyCode)return i.apply(e,arguments);e.ignoreHover=!0,r=O(e.activeOption,"[data-group]"),n=A(e.activeOption,"[data-selectable]"),(r=37===t.keyCode?r.previousSibling:r.nextSibling)&&(s=(o=r.querySelectorAll("[data-selectable]"))[Math.min(o.length-1,n)])&&e.setActiveOption(s)}))})),_.define("remove_button",(function(t){t=Object.assign({label:"×",title:"Remove",className:"remove",append:!0},t);var e=this;if(t.append){var i='<a href="javascript:void(0)" class="'+t.className+'" tabindex="-1" title="'+p(t.title)+'">'+t.label+"</a>";e.hook("after","setupTemplates",(function(){var t=e.settings.render.item;e.settings.render.item=function(){var n=f(t.apply(e,arguments)),s=f(i);return n.appendChild(s),s.addEventListener("mousedown",(function(t){t.preventDefault(),t.stopPropagation()})),s.addEventListener("click",(function(t){if(t.preventDefault(),t.stopPropagation(),"single"!==e.settings.mode&&t.stopPropagation(),!e.isLocked){var i=n.dataset.value;e.removeItem(i),e.refreshOptions(!1)}})),n}}))}})),_.define("restore_on_backspace",(function(t){var e=this;t.text=t.text||function(t){return t[e.settings.labelField]};var i=e.onKeyDown;e.hook("instead","onKeyDown",(function(n){var s,o;return 8===n.keyCode&&""===e.control_input.value&&!e.activeItems.length&&(s=e.caretPos-1)>=0&&s<e.items.length?(o=e.options[e.items[s]],e.deleteSelection(n)&&(e.setTextboxValue(t.text.call(e,o)),e.refreshOptions(!0)),void n.preventDefault()):i.apply(e,arguments)}))})),_}));var tomSelect=function(t,e){return new TomSelect(t,e)}; | ||
var e,t | ||
e=this,t=function(){"use strict" | ||
class e{constructor(){this._events={}}on(e,t){this._events[e]=this._events[e]||[],this._events[e].push(t)}off(e,t){var i=arguments.length | ||
return 0===i?delete this._events:1===i?delete this._events[e]:(this._events=this._events||{},void(e in this._events!=0&&this._events[e].splice(this._events[e].indexOf(t),1)))}trigger(e){if(this._events=this._events||{},e in this._events!=0)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}}var t=function(e,t){return"number"==typeof e&&"number"==typeof t?e>t?1:e<t?-1:0:(e=n(String(e||"")))>(t=n(String(t||"")))?1:t>e?-1:0},i=function(e,t,i){if(e&&t){if(!i)return e[t] | ||
for(var s=t.split(".");s.length&&(e=e[s.shift()]););return e}},s={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶ]"},n=function(){var e,t,i,n,r="",o={} | ||
for(i in s)if(s.hasOwnProperty(i))for(r+=n=s[i].substring(2,s[i].length-1),e=0,t=n.length;e<t;e++)o[n.charAt(e)]=i | ||
var l=new RegExp("["+r+"]","g") | ||
return function(e){return e.replace(l,(function(e){return o[e]})).toLowerCase()}}() | ||
class r{constructor(e,t){this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t){if(!(e=String(e||"").toLowerCase().trim())||!e.length)return[] | ||
var i,n,r,o,l=[],a=e.split(/ +/) | ||
for(i=0,n=a.length;i<n;i++){if(r=(a[i]+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),this.settings.diacritics)for(o in s)s.hasOwnProperty(o)&&(r=r.replace(new RegExp(o,"g"),s[o])) | ||
t&&(r="\\b"+r),l.push({string:a[i],regex:new RegExp(r,"i")})}return l}iterator(e,t){(Array.isArray(e)?Array.prototype.forEach||function(e){for(var t=0,i=this.length;t<i;t++)e(this[t],t,this)}:function(e){for(var t in this)this.hasOwnProperty(t)&&e(this[t],t,this)}).apply(e,[t])}getScoreFunction(e,t){var s,n,r,o | ||
e=this.prepareSearch(e,t),n=e.tokens,s=e.options.fields,r=n.length,o=e.options.nesting | ||
var l,a=function(e,t){var i,s | ||
return e?-1===(s=(e=String(e||"")).search(t.regex))?0:(i=t.string.length/e.length,0===s&&(i+=.5),i):0},d=(l=s.length)?1===l?function(e,t){return a(i(t,s[0],o),e)}:function(e,t){for(var n=0,r=0;n<l;n++)r+=a(i(t,s[n],o),e) | ||
return r/l}:function(){return 0} | ||
return r?1===r?function(e){return d(n[0],e)}:"and"===e.options.conjunction?function(e){for(var t,i=0,s=0;i<r;i++){if((t=d(n[i],e))<=0)return 0 | ||
s+=t}return s/r}:function(e){for(var t=0,i=0;t<r;t++)i+=d(n[t],e) | ||
return i/r}:function(){return 0}}getSortFunction(e,s){var n,r,o,l,a,d,p,c,u,h,g | ||
if(g=!(e=(o=this).prepareSearch(e,s)).query&&s.sort_empty||s.sort,u=function(e,t){return"$score"===e?t.score:i(o.items[t.id],e,s.nesting)},a=[],g)for(n=0,r=g.length;n<r;n++)(e.query||"$score"!==g[n].field)&&a.push(g[n]) | ||
if(e.query){for(h=!0,n=0,r=a.length;n<r;n++)if("$score"===a[n].field){h=!1 | ||
break}h&&a.unshift({field:"$score",direction:"desc"})}else for(n=0,r=a.length;n<r;n++)if("$score"===a[n].field){a.splice(n,1) | ||
break}for(c=[],n=0,r=a.length;n<r;n++)c.push("desc"===a[n].direction?-1:1) | ||
return(d=a.length)?1===d?(l=a[0].field,p=c[0],function(e,i){return p*t(u(l,e),u(l,i))}):function(e,i){var s,n,r | ||
for(s=0;s<d;s++)if(r=a[s].field,n=c[s]*t(u(r,e),u(r,i)))return n | ||
return 0}:null}prepareSearch(e,t){if("object"==typeof e)return e | ||
var i=(t=Object.assign({},t)).fields,s=t.sort,n=t.sort_empty | ||
return i&&!Array.isArray(i)&&(t.fields=[i]),s&&!Array.isArray(s)&&(t.sort=[s]),n&&!Array.isArray(n)&&(t.sort_empty=[n]),{options:t,query:String(e||"").toLowerCase(),tokens:this.tokenize(e,t.respect_word_boundaries),total:0,items:[]}}search(e,t){var i,s,n,r,o=this | ||
return s=this.prepareSearch(e,t),t=s.options,e=s.query,r=t.score||o.getScoreFunction(s),e.length?o.iterator(o.items,(function(e,n){i=r(e),(!1===t.filter||i>0)&&s.items.push({score:i,id:n})})):o.iterator(o.items,(function(e,t){s.items.push({score:1,id:t})})),(n=o.getSortFunction(s,t))&&s.items.sort(n),s.total=s.items.length,"number"==typeof t.limit&&(s.items=s.items.slice(0,t.limit)),s}}function o(e,t){if("string"!=typeof t||t.length){var i="string"==typeof t?new RegExp(t,"i"):t | ||
!function e(t){var s=0 | ||
if(3===t.nodeType){var n=t.data.search(i) | ||
if(n>=0&&t.data.length>0){var r=t.data.match(i),o=document.createElement("span") | ||
o.className="highlight" | ||
var l=t.splitText(n) | ||
l.splitText(r[0].length) | ||
var a=l.cloneNode(!0) | ||
o.appendChild(a),l.parentNode.replaceChild(o,l),s=1}}else if(1===t.nodeType&&t.childNodes&&!/(script|style)/i.test(t.tagName)&&("highlight"!==t.className||"SPAN"!==t.tagName))for(var d=0;d<t.childNodes.length;++d)d+=e(t.childNodes[d]) | ||
return s}(e)}}const l=/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey" | ||
var a={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,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-control",inputClass:"ts-input",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:null,copyClassesToDropdown:!0,render:{}} | ||
function d(e){return null==e?null:"boolean"==typeof e?e?"1":"0":e+""}function p(e){return(e+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function c(e,t){var i,s=this | ||
return function(){var n=arguments | ||
i&&(this.loading=Math.max(this.loading-1,0)),clearTimeout(i),i=setTimeout((function(){i=null,e.apply(s,n)}),t)}}function u(e,t,i){var s,n=e.trigger,r={} | ||
for(s in e.trigger=function(){var i=arguments[0] | ||
if(-1===t.indexOf(i))return n.apply(e,arguments) | ||
r[i]=arguments},i.apply(e,[]),e.trigger=n,r)r.hasOwnProperty(s)&&n.apply(e,r[s])}function h(e,t=!1){e&&(e.preventDefault(),t&&e.stopPropagation())}function g(e,t,i,s){e.addEventListener(t,i,s)}function v(e,t){return!!t&&!!t[e]&&1==(t.altKey?1:0)+(t.ctrlKey?1:0)+(t.shiftKey?1:0)+(t.metaKey?1:0)}function f(e,t){var i=Object.assign({},a,t),s=i.dataAttr,n=i.labelField,r=i.valueField,o=i.disabledField,l=i.optgroupField,p=i.optgroupLabelField,c=i.optgroupValueField,u=e.tagName.toLowerCase(),h=e.getAttribute("placeholder")||e.getAttribute("data-placeholder") | ||
if(!h&&!i.allowEmptyOption){let t=e.querySelector('option[value=""]') | ||
t&&(h=t.textContent)}var g={placeholder:h,options:[],optgroups:[],items:[],maxItems:null} | ||
return"select"===u?(()=>{var t,a,u,h,v=g.options,f={},m=e=>{var t=Object.assign({},e.dataset),i=s&&t[s] | ||
return"string"==typeof i&&i.length&&(t=Object.assign(t,JSON.parse(i))),t},y=(e,t)=>{var s=d(e.value) | ||
if(s||i.allowEmptyOption)if(f.hasOwnProperty(s)){if(t){var a=f[s][l] | ||
a?Array.isArray(a)?a.push(t):f[s][l]=[a,t]:f[s][l]=t}}else{var p=m(e) | ||
p[n]=p[n]||e.textContent,p[r]=p[r]||s,p[o]=p[o]||e.disabled,p[l]=p[l]||t,f[s]=p,v.push(p),e.selected&&g.items.push(s)}},O=e=>{var t,i,s,n,r | ||
for((s=e.getAttribute("label"))&&((n=m(e))[p]=s,n[c]=s,n[o]=e.disabled,g.optgroups.push(n)),t=0,i=(r=e.children).length;t<i;t++)y(r[t],s)} | ||
for(g.maxItems=e.hasAttribute("multiple")?null:1,t=0,a=(h=e.children).length;t<a;t++)"optgroup"===(u=h[t].tagName.toLowerCase())?O(h[t]):"option"===u&&y(h[t])})():(()=>{var t,o,l,a,d=e.getAttribute(s) | ||
if(d)for(g.options=JSON.parse(d),t=0,o=g.options.length;t<o;t++)g.items.push(g.options[t][r]) | ||
else{var p=e.value.trim()||"" | ||
if(!i.allowEmptyOption&&!p.length)return | ||
for(t=0,o=(l=p.split(i.delimiter)).length;t<o;t++)(a={})[n]=l[t],a[r]=l[t],g.options.push(a) | ||
g.items=l}})(),Object.assign({},a,g,t)}function m(e){if(e.jquery)return e[0] | ||
if(e instanceof HTMLElement)return e | ||
if(e.indexOf("<")>-1){let t=document.createElement("div") | ||
return t.innerHTML=e.trim(),t.firstChild}return document.querySelector(e)}function y(e,t){var i=document.createEvent("HTMLEvents") | ||
i.initEvent(t,!0,!1),e.dispatchEvent(i)}function O(e,t){Object.keys(t).forEach((function(i){e.style[i]=t[i]}))}function w(e,...t){var i=C(t);(e=I(e)).map((e=>{i.map((t=>{e.classList.add(t)}))}))}function b(e,...t){var i=C(t);(e=I(e)).map((e=>{i.map((t=>{e.classList.remove(t)}))}))}function C(e){var t=[] | ||
for(let i=0;i<e.length;i++){let s=e[i] | ||
"string"==typeof s&&(s=s.trim().split(/[\11\12\14\15\40]/)),Array.isArray(s)&&(t=t.concat(s))}return t.filter(Boolean)}function I(e){return Array.isArray(e)||(e=[e]),e}function A(e,t,i){if(!i||i.contains(e))for(;e&&e.matches;){if(e.matches(t))return e | ||
e=e.parentNode}}function _(e,t){return t>0?e[e.length-1]:e[0]}function S(e,t){if(!e)return-1 | ||
t=t||e.nodeName | ||
for(var i=0;e=e.previousElementSibling;)e.matches(t)&&i++ | ||
return i}class x extends(function(e){return e.plugins={},class extends e{static define(t,i){e.plugins[t]={name:t,fn:i}}initializePlugins(e){var t,i,s,n=this,r=[] | ||
if(n.plugins={names:[],settings:{},requested:{},loaded:{}},Array.isArray(e))for(t=0,i=e.length;t<i;t++)"string"==typeof e[t]?r.push(e[t]):(n.plugins.settings[e[t].name]=e[t].options,r.push(e[t].name)) | ||
else if(e)for(s in e)e.hasOwnProperty(s)&&(n.plugins.settings[s]=e[s],r.push(s)) | ||
for(;r.length;)n.require(r.shift())}loadPlugin(t){var i=this,s=i.plugins,n=e.plugins[t] | ||
if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin') | ||
s.requested[t]=!0,s.loaded[t]=n.fn.apply(i,[i.plugins.settings[t]||{}]),s.names.push(t)}require(e){var t=this,i=t.plugins | ||
if(!t.plugins.loaded.hasOwnProperty(e)){if(i.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")') | ||
t.loadPlugin(e)}return i.loaded[e]}}}(e)){constructor(e,t){var i | ||
if(super(),(e=m(e)).tomselect)throw new Error("Tom Select already initialized on this element") | ||
e.tomselect=this,i=(window.getComputedStyle&&window.getComputedStyle(e,null)).getPropertyValue("direction"),this.order=0,this.settings=f(e,t),this.input=e,this.tabIndex=e.getAttribute("tabindex")||null,this.is_select_tag="select"===e.tagName.toLowerCase(),this.rtl=/rtl/i.test(i),this.isBlurring=!1,this.isOpen=!1,this.isDisabled=!1,this.isRequired=e.required,this.isInvalid=!1,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.ignoreFocus=!1,this.ignoreBlur=!1,this.ignoreHover=!1,this.hasOptions=!1,this.currentResults=null,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.renderCache={item:{},option:{}},this.settings.load&&this.settings.loadThrottle&&(this.settings.load=c.call(this,this.settings.load,this.settings.loadThrottle)),this.sifter=new r(this.options,{diacritics:this.settings.diacritics}),this.setupOptions(this.settings.options,this.settings.optgroups),delete this.settings.optgroups,delete this.settings.options,this.settings.mode=this.settings.mode||(1===this.settings.maxItems?"single":"multi"),"boolean"!=typeof this.settings.hideSelected&&(this.settings.hideSelected="multi"===this.settings.mode) | ||
var s=this.settings.createFilter | ||
"function"!=typeof s&&("string"==typeof s&&(s=new RegExp(s)),s instanceof RegExp?this.settings.createFilter=e=>s.test(e):this.settings.createFilter=()=>!0),this.initializePlugins(this.settings.plugins),this.setupCallbacks(),this.setupTemplates(),this.setup()}setup(){var e,t,i,s,n,r,o,l,a,d=this,p=d.settings,c=d.input | ||
const u={passive:!0} | ||
if(r=d.settings.mode,o=c.getAttribute("class")||"",w(e=m("<div>"),p.wrapperClass,o,r),w(t=m('<div class="items">'),p.inputClass),e.append(t),w(s=d.render("dropdown"),p.dropdownClass,r),w(n=m('<div style="scroll-behavior: smooth;">'),p.dropdownContentClass),s.append(n),m(p.dropdownParent||e).appendChild(s),p.controlInput)i=m(p.controlInput) | ||
else{i=m('<input type="text" autocomplete="off" />') | ||
var v=["autocorrect","autocapitalize","autocomplete"] | ||
for(let e=0;e<v.length;e++){let t=v[e] | ||
c.getAttribute(t)&&i.setAttribute(t,c.getAttribute(t))}}if(p.controlInput||(i.setAttribute("tabindex",c.disabled?"-1":d.tabIndex),t.appendChild(i)),a=c.getAttribute("id")){i.setAttribute("id",a+"-tomselected") | ||
var f=document.querySelector("label[for='"+a+"']") | ||
f&&f.setAttribute("for",a+"-tomselected")}if(d.settings.copyClassesToDropdown&&w(s,o),e.style.width=c.style.width,d.plugins.names.length&&(l="plugin-"+d.plugins.names.join(" plugin-"),w([e,s],l)),(null===p.maxItems||p.maxItems>1)&&d.is_select_tag&&c.setAttribute("multiple","multiple"),d.settings.placeholder&&i.setAttribute("placeholder",p.placeholder),!d.settings.splitOn&&d.settings.delimiter){var y=d.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&") | ||
d.settings.splitOn=new RegExp("\\s*"+y+"+\\s*")}d.control=t,d.control_input=i,d.wrapper=e,d.dropdown=s,d.dropdown_content=n,d.control_input.type=c.type,g(s,"mouseenter",(e=>{var t=A(e.target,"[data-selectable]",s) | ||
if(t)return d.onOptionHover(e,t)}),{capture:!0}),g(t,"mousedown",(e=>{var i=A(e.target,"."+d.settings.itemClass,t) | ||
return i?d.onItemSelect(e,i):d.onMouseDown(e)})),g(t,"click",(e=>d.onClick(e))),g(i,"mousedown",(e=>e.stopPropagation())),g(i,"keydown",(e=>d.onKeyDown(e))),g(i,"keyup",(e=>d.onKeyUp(e))),g(i,"keypress",(e=>d.onKeyPress(e))),g(i,"resize",(()=>d.positionDropdown()),u),g(i,"blur",(e=>d.onBlur(e))),g(i,"focus",(e=>{d.ignoreBlur=!1,d.onFocus(e)})),g(i,"paste",(e=>d.onPaste(e))) | ||
var O=e=>{var t=A(e.target,"[data-selectable]",d.dropdown) | ||
t||d.wrapper.contains(e.target)?(h(e,!0),t&&d.onOptionSelect(e,t)):d.isFocused&&d.blur(e.target)},b=()=>{d.isOpen&&d.positionDropdown()},C=()=>{d.ignoreHover=!1} | ||
g(document,"mousedown",O),g(window,"sroll",b,u),g(window,"resize",b,u),g(window,"mousemove",C,u),d._destroy=()=>{document.removeEventListener("mousedown",O),window.removeEventListener("mousemove",C),window.removeEventListener("sroll",b),window.removeEventListener("resize",b)} | ||
for(var I=[];c.children.length>0;)I.push(c.children[0]),c.children[0].remove() | ||
this.revertSettings={children:I,tabindex:c.getAttribute("tabindex")},c.tabIndex=-1,c.setAttribute("hidden","hidden"),c.insertAdjacentElement("afterend",d.wrapper),d.setValue(p.items),delete p.items,g(c,"invalid",(e=>{h(e),d.isInvalid||(d.isInvalid=!0,d.refreshState())})),d.updateOriginalInput(),d.refreshItems(),d.refreshState(),d.isSetup=!0,c.disabled&&d.disable(),d.on("change",this.onChange),w(c,"tomselected"),d.trigger("initialize"),!0===p.preload&&d.load("")}setupOptions(e,t){var i,s | ||
for(t=t||[],i=0,s=(e=e||[]).length;i<s;i++)this.registerOption(e[i]) | ||
for(i=0,s=t.length;i<s;i++)this.registerOptionGroup(t[i])}setupTemplates(){var e=this,t=e.settings.labelField,i=e.settings.optgroupLabelField,s={optgroup:(e,t)=>{let i=document.createElement("div") | ||
return i.className="optgroup",i.appendChild(e.options),i},optgroup_header:(e,t)=>'<div class="optgroup-header">'+t(e[i])+"</div>",option:(e,i)=>"<div>"+i(e[t])+"</div>",item:(e,i)=>"<div>"+i(e[t])+"</div>",option_create:(e,t)=>'<div class="create">Add <strong>'+t(e.input)+"</strong>…</div>",no_results:(e,t)=>'<div class="no-results">No results found</div>',loading:(e,t)=>'<div class="spinner"></div>',dropdown:()=>'<div style="display:none"></div>'} | ||
e.settings.render=Object.assign({},s,e.settings.render)}setupCallbacks(){var e,t,i={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",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(e in i)(t=this.settings[i[e]])&&this.on(e,t)}onClick(e){var t=this | ||
t.isFocused&&t.isOpen||(t.focus(),h(e))}onMouseDown(e){var t=this | ||
if(t.isFocused){if(e.target!==t.control_input)return"single"===t.settings.mode?t.isOpen?t.close():t.open():t.setActiveItem(),!1}else setTimeout((()=>t.focus()),0)}onChange(){y(this.input,"change")}onPaste(e){var t=this | ||
t.isFull()||t.isInputHidden||t.isLocked?h(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue() | ||
if(e.match(t.settings.splitOn))for(var i=e.trim().split(t.settings.splitOn),s=0,n=i.length;s<n;s++)t.createItem(i[s])}),0)}onKeyPress(e){var t=this | ||
if(!t.isLocked){var i=String.fromCharCode(e.keyCode||e.which) | ||
return t.settings.create&&"multi"===t.settings.mode&&i===t.settings.delimiter?(t.createItem(),void h(e)):void 0}h(e)}onKeyDown(e){var t=this | ||
if(t.ignoreHover=!0,t.isLocked)9!==e.keyCode&&h(e) | ||
else{switch(e.keyCode){case 65:if(v(l,e))return void t.selectAll() | ||
break | ||
case 27:return void(t.isOpen&&(h(e,!0),t.close())) | ||
case 40:if(!t.isOpen&&t.hasOptions)t.open() | ||
else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1) | ||
e&&t.setActiveOption(e,!0)}return void h(e) | ||
case 38:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1) | ||
e&&t.setActiveOption(e,!0)}return void h(e) | ||
case 13:return void(t.isOpen&&t.activeOption&&(t.onOptionSelect(e,t.activeOption),h(e))) | ||
case 37:return void t.advanceSelection(-1,e) | ||
case 39:return void t.advanceSelection(1,e) | ||
case 9:return t.settings.selectOnTab&&t.isOpen&&t.activeOption&&(t.onOptionSelect(e,t.activeOption),h(e)),void(t.settings.create&&t.createItem()&&h(e)) | ||
case 8:case 46:return void t.deleteSelection(e)}!t.isInputHidden||v(l,e)||h(e)}}onKeyUp(e){var t=this | ||
if(t.isLocked)h(e) | ||
else{var i=t.inputValue() | ||
t.lastValue!==i&&(t.lastValue=i,t.load(i),t.refreshOptions(),t.trigger("type",i))}}onFocus(e){var t=this,i=t.isFocused | ||
if(t.isDisabled)return t.blur(),void h(e) | ||
t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.load(""),i||t.trigger("focus"),t.activeItems.length||(t.showInput(),t.setActiveItem(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e,t){var i=this | ||
if(i.isFocused){if(i.isFocused=!1,i.ignoreFocus=!1,!i.ignoreBlur&&document.activeElement===i.dropdown_content)return i.ignoreBlur=!0,void i.onFocus(e) | ||
var s=()=>{i.close(),i.setActiveItem(),i.setActiveOption(),i.setCaret(i.items.length),i.refreshState(),t&&t.focus&&t.focus(),i.isBlurring=!1,i.trigger("blur")} | ||
i.isBlurring=!0,i.settings.create&&i.settings.createOnBlur?i.createItem(null,!1,s):s()}}onOptionHover(e,t){this.ignoreHover||this.setActiveOption(t,!1)}onOptionSelect(e,t){var i,s=this | ||
t&&(t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?s.createItem(null,!0,(()=>{s.settings.closeAfterSelect&&s.close()})):void 0!==(i=t.dataset.value)&&(s.lastQuery=null,s.addItem(i),s.settings.closeAfterSelect?s.close():!s.settings.hideSelected&&e.type&&/mouse/.test(e.type)&&s.setActiveOption(s.getOption(i)))))}onItemSelect(e,t){var i=this | ||
i.isLocked||"multi"===i.settings.mode&&(h(e),i.setActiveItem(t,e))}load(e){var t=this,i=t.settings.load | ||
i&&(t.loadedSearches.hasOwnProperty(e)||(t.loadedSearches[e]=!0,w(t.wrapper,t.settings.loadingClass),t.loading++,i.call(t,e,(function(e,i){t.loading=Math.max(t.loading-1,0),t.lastQuery=null,t.setupOptions(e,i),t.refreshOptions(t.isFocused&&!t.isInputHidden),t.loading||b(t.wrapper,t.settings.loadingClass),t.trigger("load",e,i)}))))}onSearchChange(e){this.load(e)}setTextboxValue(e){var t=this.control_input | ||
t.value!==e&&(t.value=e,y(t,"update"),this.lastValue=e)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){u(this,t?[]:["change"],(()=>{this.clear(t),this.addItems(e,t)}))}setActiveItem(e,t){var i,s,n,r,o,a,d=this | ||
if("single"!==d.settings.mode){if(!e)return b(d.activeItems,"active"),d.activeItems=[],void(d.isFocused&&d.showInput()) | ||
if("mousedown"===(i=t&&t.type.toLowerCase())&&v("shiftKey",t)&&d.activeItems.length){for(a=d.getLastActive(),(n=Array.prototype.indexOf.call(d.control.children,a))>(r=Array.prototype.indexOf.call(d.control.children,e))&&(o=n,n=r,r=o),s=n;s<=r;s++)e=d.control.children[s],-1===d.activeItems.indexOf(e)&&d.setActiveItemClass(e) | ||
h(t)}else"mousedown"===i&&v(l,t)||"keydown"===i&&v("shiftKey",t)?e.classList.contains("active")?d.removeActiveItem(e):d.setActiveItemClass(e):(b(d.activeItems,"active"),d.activeItems=[],d.setActiveItemClass(e)) | ||
d.hideInput(),d.isFocused||d.focus()}}setActiveItemClass(e){var t=this.control.querySelector(".last-active") | ||
t&&b(t,"last-active"),w(e,"active last-active"),-1==this.activeItems.indexOf(e)&&this.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e) | ||
this.activeItems.splice(t,1),b(e,"active")}setActiveOption(e,t){var i,s,n | ||
if(e!==this.activeOption&&(this.activeOption&&b(this.activeOption,"active"),this.activeOption=null,e&&(this.activeOption=e,w(e,"active"),t))){i=this.dropdown_content.clientHeight | ||
let e=this.dropdown_content.scrollTop||0 | ||
s=this.activeOption.offsetHeight,(n=this.activeOption.getBoundingClientRect().top-this.dropdown_content.getBoundingClientRect().top+e)+s>i+e?this.dropdown_content.scrollTop=n-i+s:n<e&&(this.dropdown_content.scrollTop=n)}}selectAll(){"single"!==this.settings.mode&&(this.activeItems=this.controlChildren(),this.activeItems.length&&(w(this.activeItems,"active"),this.hideInput(),this.close()),this.focus())}hideInput(){this.settings.controlInput||(this.setTextboxValue(""),O(this.control_input,{opacity:0,position:"absolute",left:(this.rtl?1e4:-1e4)+"px"}),this.isInputHidden=!0)}showInput(){this.settings.controlInput||(O(this.control_input,{opacity:1,position:"relative",left:0}),this.isInputHidden=!1)}inputValue(){return this.control_input.value.trim()}focus(){var e=this | ||
e.isDisabled||(e.ignoreFocus=!0,e.control_input.focus(),setTimeout((()=>{e.ignoreFocus=!1,e.onFocus()}),0))}blur(e){this.control_input.blur(),this.onBlur(null,e)}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e,t=this.settings | ||
return"string"==typeof t.sortField&&(e=[{field:t.sortField}]),{fields:t.searchField,conjunction:t.searchConjunction,sort:e,nesting:t.nesting}}search(e){var t,i,s,n=this,r=n.settings,o=this.getSearchOptions() | ||
if(r.score&&"function"!=typeof(s=n.settings.score.call(n,e)))throw new Error('Tom Select "score" setting must be a function that returns a function') | ||
if(e!==n.lastQuery?(n.lastQuery=e,i=n.sifter.search(e,Object.assign(o,{score:s})),n.currentResults=i):i=Object.assign({},n.currentResults),r.hideSelected)for(t=i.items.length-1;t>=0;t--)-1!==n.items.indexOf(d(i.items[t].id))&&i.items.splice(t,1) | ||
return i}refreshOptions(e=!0){var t,i,s,n,r,l,a,p,c,u,h,g,v,f=this,m=f.inputValue(),y=f.search(m),O=f.activeOption&&d(f.activeOption.dataset.value),C=!1 | ||
for(n=y.items.length,"number"==typeof f.settings.maxOptions&&(n=Math.min(n,f.settings.maxOptions)),n>0&&(C=!0),r={},l=[],t=0;t<n;t++){let e=f.options[y.items[t].id],n=d(e[f.settings.valueField]),o=f.getOption(n) | ||
for(o||(o=f.render("option",e)),a=e[f.settings.optgroupField]||"",i=0,s=(p=Array.isArray(a)?a:[a])&&p.length;i<s;i++)a=p[i],f.optgroups.hasOwnProperty(a)||(a=""),r.hasOwnProperty(a)||(r[a]=document.createDocumentFragment(),l.push(a)),i>0&&(o=o.cloneNode(!0),b(o,"active")),r[a].appendChild(o)}for(this.settings.lockOptgroupOrder&&l.sort(((e,t)=>(f.optgroups[e].$order||0)-(f.optgroups[t].$order||0))),c=document.createDocumentFragment(),t=0,n=l.length;t<n;t++)if(a=l[t],f.optgroups.hasOwnProperty(a)&&r[a].children.length){let e=document.createDocumentFragment() | ||
e.appendChild(f.render("optgroup_header",f.optgroups[a])),e.appendChild(r[a]) | ||
let t=f.render("optgroup",{group:f.optgroups[a],options:e}) | ||
c.appendChild(t)}else c.appendChild(r[a]) | ||
if(f.dropdown_content.innerHTML="",f.dropdown_content.appendChild(c),f.settings.highlight&&(f.dropdown_content,v=document.querySelectorAll("span.highlight"),Array.prototype.forEach.call(v,(function(e,t){var i=e.parentNode | ||
i.replaceChild(e.firstChild,e),i.normalize()})),y.query.length&&y.tokens.length))for(t=0,n=y.tokens.length;t<n;t++)o(f.dropdown_content,y.tokens[t].regex) | ||
if(!f.settings.hideSelected)for(t=0,n=f.items.length;t<n;t++){let e=f.getOption(f.items[t]) | ||
e&&w(e,"selected")}var I=e=>{C=!0 | ||
let t=f.render(e,{input:m}) | ||
return f.dropdown_content.insertBefore(t,f.dropdown_content.firstChild),t} | ||
if(f.loading?I("loading"):0===y.items.length&&f.settings.render.no_results&&m.length&&I("no_results"),(u=f.canCreate(m))&&(g=I("option_create")),f.hasOptions=y.items.length>0||u,C){if(y.items.length>0){if(!(h=O&&f.getOption(O))||!f.dropdown_content.contains(h)){let e=0 | ||
g&&!f.settings.addPrecedence&&(e=1),h=f.selectable()[e]}}else h=g | ||
f.setActiveOption(h),e&&!f.isOpen&&f.open()}else f.setActiveOption(),e&&f.isOpen&&f.close()}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e){var t,i,s,n=this | ||
if(Array.isArray(e))for(t=0,i=e.length;t<i;t++)n.addOption(e[t]) | ||
else(s=n.registerOption(e))&&(n.userOptions[s]=!0,n.lastQuery=null,n.trigger("option_add",s,e))}registerOption(e){var t=d(e[this.settings.valueField]) | ||
return null!=t&&!this.options.hasOwnProperty(t)&&(e.$order=e.$order||++this.order,this.options[t]=e,t)}registerOptionGroup(e){var t=d(e[this.settings.optgroupValueField]) | ||
return!!t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var i | ||
t[this.settings.optgroupValueField]=e,(i=this.registerOptionGroup(t))&&this.trigger("optgroup_add",i,t)}removeOptionGroup(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.clearCache(),this.trigger("optgroup_remove",e))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(e,t){var i,s,n,r,o,l,a,p=this | ||
if(e=d(e),n=d(t[p.settings.valueField]),null!==e&&p.options.hasOwnProperty(e)){if("string"!=typeof n)throw new Error("Value must be set in option data") | ||
a=p.options[e].$order,n!==e&&(delete p.options[e],-1!==(r=p.items.indexOf(e))&&p.items.splice(r,1,n)),t.$order=t.$order||a,p.options[n]=t,o=p.renderCache.item,l=p.renderCache.option,o&&(delete o[e],delete o[n]),l&&(delete l[e],delete l[n]),-1!==p.items.indexOf(n)&&(i=p.getItem(e),s=p.render("item",t),i.classList.contains("active")&&w(s,"active"),i.parentNode.insertBefore(s,i),i.remove()),p.lastQuery=null,p.isOpen&&p.refreshOptions(!1)}}removeOption(e,t){var i=this | ||
e=d(e) | ||
var s=i.renderCache.item,n=i.renderCache.option | ||
s&&delete s[e],n&&delete n[e],delete i.userOptions[e],delete i.options[e],i.lastQuery=null,i.trigger("option_remove",e),i.removeItem(e,t)}clearOptions(){this.loadedSearches={},this.userOptions={},this.clearCache() | ||
var e={} | ||
for(let t in this.options)this.options.hasOwnProperty(t)&&this.items.indexOf(t)>=0&&(e[t]=this.options[t]) | ||
this.options=this.sifter.items=e,this.lastQuery=null,this.trigger("option_clear")}getOption(e){return this.renderCache.option.hasOwnProperty(e)?this.renderCache.option[e]:this.getElementWithValue(e,this.selectable())}getAdjacent(e,t,i="option"){if(e){var s=this,n=s.settings.optionClass,r=s.dropdown | ||
"item"==i&&(r=s.control,n=s.settings.itemClass) | ||
var o=r.querySelectorAll("."+n) | ||
for(let i=0;i<o.length;i++)if(o[i]==e)return t>0?o[i+1]:o[i-1]}}getElementWithValue(e,t){if(null!=(e=d(e)))for(var i=0,s=t.length;i<s;i++){let s=t[i] | ||
if(s.getAttribute("data-value")===e)return s}}getItem(e){return this.getElementWithValue(e,this.control.children)}addItems(e,t){this.buffer=document.createDocumentFragment() | ||
var i=this.control.children | ||
for(let e=0;e<i.length;e++)this.buffer.appendChild(i[e]) | ||
var s=Array.isArray(e)?e:[e] | ||
for(let e=0,i=s.length;e<i;e++)this.isPending=e<i-1,this.addItem(s[e],t) | ||
var n=this.control | ||
n.insertBefore(this.buffer,n.firstChild),this.buffer=null}addItem(e,t){u(this,t?[]:["change"],(()=>{var i,s,n=this,r=n.settings.mode | ||
if(e=d(e),(-1===n.items.indexOf(e)||("single"===r&&n.close(),"single"!==r&&n.settings.duplicates))&&n.options.hasOwnProperty(e)&&("single"===r&&n.clear(t),("multi"!==r||!n.isFull())&&(i=n.render("item",n.options[e]),n.control.contains(i)&&(i=i.cloneNode(!0)),s=n.isFull(),n.items.splice(n.caretPos,0,e),n.insertAtCaret(i),(!n.isPending||!s&&n.isFull())&&n.refreshState(),n.isSetup))){let s=n.selectable() | ||
if(!n.isPending){let t=n.getOption(e),i=n.getAdjacent(t,1) | ||
n.refreshOptions(n.isFocused&&"single"!==r),i&&n.setActiveOption(i)}!s.length||n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",e,i),n.isPending||n.updateOriginalInput({silent:t})}}))}removeItem(e,t){var i,s,n=this,r=n.getItem(e) | ||
r&&(e=d(r.dataset.value),-1!==(i=n.items.indexOf(e))&&(r.remove(),r.classList.contains("active")&&(s=n.activeItems.indexOf(r),n.activeItems.splice(s,1),b(r,"active")),n.items.splice(i,1),n.lastQuery=null,!n.settings.persist&&n.userOptions.hasOwnProperty(e)&&n.removeOption(e,t),i<n.caretPos&&n.setCaret(n.caretPos-1),n.refreshState(),n.updateOriginalInput({silent:t}),n.positionDropdown(),n.trigger("item_remove",e,r)))}createItem(e,t=!0,i){var s,n=this,r=n.caretPos | ||
if(e=e||n.inputValue(),"function"!=typeof i&&(i=()=>{}),!n.canCreate(e))return i(),!1 | ||
n.lock() | ||
var o=!1,l=e=>{if(n.unlock(),!e||"object"!=typeof e)return i() | ||
var s=d(e[n.settings.valueField]) | ||
if("string"!=typeof s)return i() | ||
n.setTextboxValue(""),n.addOption(e),n.setCaret(r),n.addItem(s),n.refreshOptions(t&&"single"!==n.settings.mode),i(e),o=!0} | ||
return s="function"==typeof n.settings.create?n.settings.create.call(this,e,l):{[n.settings.labelField]:e,[n.settings.valueField]:e},o||l(s),!0}refreshItems(){var e=this | ||
e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.refreshState(),e.updateOriginalInput()}refreshState(){var e=this | ||
e.refreshValidityState() | ||
var t=e.isFull(),i=e.isLocked | ||
e.wrapper.classList.toggle("rtl",e.rtl) | ||
var s,n=e.control.classList | ||
n.toggle("focus",e.isFocused),n.toggle("disabled",e.isDisabled),n.toggle("required",e.isRequired),n.toggle("invalid",e.isInvalid),n.toggle("locked",i),n.toggle("full",t),n.toggle("not-full",!t),n.toggle("input-active",e.isFocused&&!e.isInputHidden),n.toggle("dropdown-active",e.isOpen),n.toggle("has-options",(s=e.options,0===Object.keys(s).length)),n.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this | ||
if(e.input.checkValidity){var t=!e.input.checkValidity() | ||
e.isInvalid=t,e.control_input.required=t,e.input.required=!t}}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){var t,i,s,n,r=this | ||
if(r.is_select_tag){for(s=[],t=0,i=r.items.length;t<i;t++)n=r.options[r.items[t]][r.settings.labelField]||"",s.push('<option value="'+p(r.items[t])+'" selected="selected">'+p(n)+"</option>") | ||
s.length||this.input.hasAttribute("multiple")||s.push('<option value="" selected="selected"></option>'),r.input.innerHTML=s.join("")}else r.input.value=r.getValue(),r.input.setAttribute("value",r.input.value) | ||
r.isSetup&&(e.silent||r.trigger("change",r.input.value))}open(){var e=this | ||
e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.focus(),e.isOpen=!0,e.refreshState(),O(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),O(e.dropdown,{visibility:"visible",display:"block"}),e.trigger("dropdown_open",e.dropdown))}close(){var e=this,t=e.isOpen | ||
"single"===e.settings.mode&&e.items.length&&(e.hideInput(),e.isBlurring||e.blur()),e.isOpen=!1,O(e.dropdown,{display:"none"}),e.setActiveOption(),e.refreshState(),t&&e.trigger("dropdown_close",e.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control,t=e.getBoundingClientRect(),i=e.offsetHeight+t.top+window.scrollY,s=t.left+window.scrollX | ||
O(this.dropdown,{width:t.width+"px",top:i+"px",left:s+"px"})}}clear(e){var t=this | ||
if(t.items.length){var i=t.controlChildren() | ||
for(let e=0;e<i.length;e++)i[e].remove() | ||
t.items=[],t.lastQuery=null,t.setCaret(0),t.setActiveItem(),t.updateOriginalInput({silent:e}),t.refreshState(),t.showInput(),t.trigger("clear")}}insertAtCaret(e){var t=this,i=Math.min(t.caretPos,t.items.length),s=t.buffer||t.control | ||
0===i?s.insertBefore(e,s.firstChild):s.insertBefore(e,s.children[i]),t.setCaret(i+1)}deleteSelection(e){var t,i,s,n,r,o,l,a=this | ||
if(s=e&&8===e.keyCode?-1:1,n={start:(l=a.control_input).selectionStart,length:l.selectionEnd-l.selectionStart},r=[],a.activeItems.length){for(o=S(_(a.activeItems,s)),s>0&&o++,t=0,i=a.activeItems.length;t<i;t++)r.push(a.activeItems[t].dataset.value) | ||
h(e,!0)}else(a.isFocused||"single"===a.settings.mode)&&a.items.length&&(s<0&&0===n.start&&0===n.length?r.push(a.items[a.caretPos-1]):s>0&&n.start===a.inputValue().length&&r.push(a.items[a.caretPos])) | ||
if(!r.length||"function"==typeof a.settings.onDelete&&!1===a.settings.onDelete.call(a,r,e))return!1 | ||
for(void 0!==o&&a.setCaret(o);r.length;)a.removeItem(r.pop()) | ||
return a.showInput(),a.positionDropdown(),a.refreshOptions(!1),!0}advanceSelection(e,t){var i,s,n=this | ||
if(0!==e)if(n.rtl&&(e*=-1),v(l,t)||v("shiftKey",t)){s=n.getLastActive(e) | ||
let t=n.getAdjacent(s,e,"item") | ||
t&&(t.classList.contains("active")&&n.removeActiveItem(s),n.setActiveItemClass(t))}else n.isFocused&&!n.isInputHidden?n.inputValue().length||n.setCaret(n.caretPos+e):(s=n.getLastActive(e))&&(i=S(s),n.setCaret(e>0?i+1:i),n.setActiveItem())}getLastActive(e){let t=this.control.querySelector(".last-active") | ||
if(t)return t | ||
var i=this.control.querySelectorAll(".active") | ||
return i?_(i,e):void 0}setCaret(e){var t=this | ||
if(e="single"===t.settings.mode||t.settings.controlInput?t.items.length:Math.max(0,Math.min(t.items.length,e)),!t.settings.controlInput&&!t.isPending){var i,s,n=t.controlChildren(),r=n.length | ||
for(i=0;i<r;i++)s=n[i],i<e?t.control_input.insertAdjacentElement("beforebegin",s):t.control.appendChild(s)}t.caretPos=e}controlChildren(){return Array.prototype.filter.call(this.control.children,(e=>"INPUT"!==e.nodeName))}lock(){this.close(),this.isLocked=!0,this.refreshState()}unlock(){this.isLocked=!1,this.refreshState()}disable(){var e=this | ||
e.input.disabled=!0,e.control_input.disabled=!0,e.control_input.tabIndex=-1,e.isDisabled=!0,e.lock()}enable(){var e=this | ||
e.input.disabled=!1,e.control_input.disabled=!1,e.control_input.tabIndex=e.tabIndex,e.isDisabled=!1,e.unlock()}destroy(){var e=this,t=e.revertSettings | ||
e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML="",t.tabindex?e.input.setAttribute("tabindex",t.tabindex):e.input.removeAttribute("tabindex"),b(e.input,"tomselected"),e.input.removeAttribute("hidden") | ||
for(let i=0;i<t.children.length;i++)e.input.appendChild(t.children[i]) | ||
e._destroy(),delete e.input.tomselect}render(e,t){var i,s,n,r=this | ||
return"option"!==e&&"item"!==e||(i=d(t[r.settings.valueField]),!r.renderCache[e].hasOwnProperty(i))?(n=m(r.settings.render[e].call(this,t,p)),"option"===e||"option_create"===e?t[r.settings.disabledField]||n.setAttribute("data-selectable",""):"optgroup"===e&&(s=t.group[r.settings.optgroupValueField],n.setAttribute("data-group",s),t.group[r.settings.disabledField]&&n.setAttribute("data-disabled","")),"option"!==e&&"item"!==e||(n.setAttribute("data-value",i),w(n,"item"===e?r.settings.itemClass:r.settings.optionClass),r.renderCache[e][i]=n),n):r.renderCache[e][i]}clearCache(e){void 0===e?this.renderCache={item:{},option:{}}:this.renderCache[e]={}}canCreate(e){return this.settings.create&&e.length&&this.settings.createFilter.call(this,e)}hook(e,t,i){var s=this,n=s[t] | ||
s[t]=function(){var t,r | ||
return"after"===e&&(t=n.apply(s,arguments)),r=i.apply(s,arguments),"instead"===e?r:("before"===e&&(t=n.apply(s,arguments)),t)}}}return x.define("change_listener",(function(e){var t=this,i=!1 | ||
g(t.input,"change",(()=>{if(i)i=!1 | ||
else{i=!0 | ||
var e=f(t.input,{}) | ||
t.setupOptions(e.options,e.optgroups),t.setValue(e.items)}}))})),x.define("drag_drop",(function(e){var t=this | ||
if(!$.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".') | ||
if("multi"===t.settings.mode){var i=t.lock,s=t.unlock | ||
t.hook("instead","lock",(function(){var e=t.control.dataset.sortable | ||
return e&&e.disable(),i.apply(t,arguments)})),t.hook("instead","unlock",(function(){var e=t.control.dataset.sortable | ||
return e&&e.enable(),s.apply(t,arguments)})),t.hook("after","setup",(()=>{var e=$(t.control).sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:t.isLocked,start:(t,i)=>{i.placeholder.css("width",i.helper.css("width")),e.css({overflow:"visible"})},stop:()=>{e.css({overflow:"hidden"}) | ||
var i=[] | ||
e.children("[data-value]").each((function(){i.push($(this).attr("data-value"))})),t.setValue(i)}})}))}})),x.define("dropdown_header",(function(e){var t=this | ||
e=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:e=>'<div class="'+e.headerClass+'"><div class="'+e.titleRowClass+'"><span class="'+e.labelClass+'">'+e.title+'</span><a href="javascript:void(0)" class="'+e.closeClass+'">×</a></div></div>'},e),t.hook("after","setup",(()=>{var i=m(e.html(e)) | ||
t.dropdown.insertBefore(i,t.dropdown.firstChild)}))})),x.define("input_autogrow",(function(e){var t=this | ||
t.hook("after","setup",(()=>{var e=document.createElement("span"),i=this.control_input | ||
e.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",t.wrapper.appendChild(e) | ||
var s=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"] | ||
for(let t=0,n=s.length;t<n;t++){let n=s[t] | ||
e.style[n]=i.style[n]}var n=()=>{e.textContent=i.value,i.style.width=e.clientWidth+"px"} | ||
g(i,"input",n),g(i,"keyup",n),g(i,"blur",n),g(i,"update",n)}))})),x.define("no_backspace_delete",(function(e){this.hook("instead","setActiveItem",(()=>{})),this.hook("instead","selectAll",(()=>{})),this.hook("instead","deleteSelection",(()=>{}))})),x.define("optgroup_columns",(function(e){var t=this,i=t.onKeyDown | ||
t.hook("instead","onKeyDown",(function(e){var s,n,r,o | ||
if(!t.isOpen||37!==e.keyCode&&39!==e.keyCode)return i.apply(t,arguments) | ||
t.ignoreHover=!0,o=A(t.activeOption,"[data-group]"),s=S(t.activeOption,"[data-selectable]"),(o=37===e.keyCode?o.previousSibling:o.nextSibling)&&(n=(r=o.querySelectorAll("[data-selectable]"))[Math.min(r.length-1,s)])&&t.setActiveOption(n)}))})),x.define("remove_button",(function(e){e=Object.assign({label:"×",title:"Remove",className:"remove",append:!0},e) | ||
var t=this | ||
if(e.append){var i='<a href="javascript:void(0)" class="'+e.className+'" tabindex="-1" title="'+p(e.title)+'">'+e.label+"</a>" | ||
t.hook("after","setupTemplates",(()=>{var e=t.settings.render.item | ||
t.settings.render.item=function(){var s=m(e.apply(t,arguments)),n=m(i) | ||
return s.appendChild(n),g(n,"mousedown",(e=>{h(e,!0)})),g(n,"click",(e=>{if(h(e,!0),!t.isLocked){var i=s.dataset.value | ||
t.removeItem(i),t.refreshOptions(!1)}})),s}}))}})),x.define("restore_on_backspace",(function(e){var t=this | ||
e.text=e.text||function(e){return e[t.settings.labelField]} | ||
var i=t.onKeyDown | ||
t.hook("instead","onKeyDown",(function(s){var n,r | ||
return 8===s.keyCode&&""===t.control_input.value&&!t.activeItems.length&&(n=t.caretPos-1)>=0&&n<t.items.length?(r=t.options[t.items[n]],t.deleteSelection(s)&&(t.setTextboxValue(e.text.call(t,r)),t.refreshOptions(!0)),void h(s)):i.apply(t,arguments)}))})),x},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TomSelect=t() | ||
//# sourceMappingURL=tom-select.complete.min.js.map |
@@ -10,3 +10,3 @@ --- | ||
```js | ||
var control = tomSelect('#select'); | ||
var control = new TomSelect('#select'); | ||
control.addOption({value:'test'}); | ||
@@ -13,0 +13,0 @@ control.addItem('test'); |
@@ -14,3 +14,3 @@ --- | ||
var handler = function() { /* ... */ }; | ||
var select = tomSelect('#input-id'); | ||
var select = new TomSelect('#input-id'); | ||
select.on('event_name', handler); | ||
@@ -17,0 +17,0 @@ select.off('event_name'); |
@@ -12,3 +12,3 @@ --- | ||
var config = {}; | ||
tomSelect('#select',config); | ||
new TomSelect('#select',config); | ||
</script> | ||
@@ -351,3 +351,3 @@ ``` | ||
<tr> | ||
<td><code>load(query, callback)</code></td> | ||
<td><code>load(query)</code></td> | ||
<td>Invoked when new options should be loaded from the server. Called with the current query string and a callback function to call with the results when they are loaded (or nothing when an error arises).</td> | ||
@@ -442,3 +442,3 @@ <td><code>function</code></td> | ||
<tr> | ||
<td><code>onLoad(data)</code></td> | ||
<td><code>onLoad(options, optgroup)</code></td> | ||
<td>Invoked when new options have been loaded and added to the control (via the <code>load</code> option or <code>load</code> API method).</td> | ||
@@ -455,3 +455,3 @@ <td><code>function</code></td> | ||
```js | ||
tomSelect('#input',{ | ||
new TomSelect('#input',{ | ||
optionClass: 'option', | ||
@@ -458,0 +458,0 @@ itemClass: 'item', |
@@ -17,3 +17,3 @@ --- | ||
```js | ||
tomSelect('#select',{ | ||
new TomSelect('#select',{ | ||
plugins: ['plugin_a', 'plugin_b'] | ||
@@ -26,3 +26,3 @@ }); | ||
```js | ||
tomSelect('#select',{ | ||
new TomSelect('#select',{ | ||
plugins: { | ||
@@ -29,0 +29,0 @@ 'plugin_a': { /* ... */ }, |
@@ -6,33 +6,21 @@ --- | ||
Tom Select was forked from <a href="https://github.com/selectize/selectize.js">selectize.js</a> to provide the same usability without the need for jQuery or any other JavaScript framework. | ||
<div class="lead"> | ||
Tom Select was forked from <a href="https://github.com/selectize/selectize.js">selectize.js</a> with the goal of modernizing the code base, decoupling from jQuery, and expanding functionality. | ||
</div> | ||
## New Features | ||
## New | ||
- support for external control input | ||
- dropdownParent other than 'body' | ||
- no_backspace_delete plugin | ||
## Performance and Usability | ||
- framework agnostic (doesn't require jQuery, Vue or any other JavaScript framework) | ||
- framework agnostic design (works without jQuery or any other JavaScript framework) | ||
- improved keyboard control of selected items | ||
- improved option cache to reduce dom manipulation during searches | ||
- animated scrolling with css instead of JavaScript | ||
- ctrl/shift/cmd key detection | ||
- moved autogrow functionality to input_autogrow plugin | ||
- improved ctrl/shift/cmd key detection | ||
- autogrow functionality moved to input_autogrow plugin | ||
- [integrated plugin hooks](plugins.md) | ||
## Breaking Changes | ||
- removed support for older browsers ES5 | ||
- removed placeholder show/hide | ||
- dataAttr defaults to null instead of "data-data" | ||
- options are appended to optgroup template programmatically | ||
- .ts-* css class names (customizable with scss) | ||
- scss instead of less | ||
- autoprefixer | ||
- nanocss | ||
## Issues / Pull requests | ||
## Fixed | ||
- [#1363](https://github.com/selectize/selectize.js/issues/1363) Autofill disable possibility | ||
@@ -53,4 +41,18 @@ - [#1447](https://github.com/selectize/selectize.js/issues/1447) Enhancement - dropdownParent | ||
## Development | ||
- examples and documentation generated using 11ty | ||
- compiled with Babel | ||
## Breaking Changes | ||
- removed support for older browsers including IE11 | ||
- removed placeholder show/hide | ||
- dataAttr defaults to null instead of "data-data" | ||
- options are appended to optgroup template programmatically | ||
- .ts-* css class names (customizable with scss) | ||
- scss instead of less | ||
- autoprefixer | ||
- nanocss | ||
## Development Environment | ||
- code converted to <a href="https://www.typescriptlang.org/">TypeScript</a> (Tom Select 1.1+) | ||
- compiled with <a href="https://babeljs.io/">Babel</a> | ||
- bundled with <a href="https://rollupjs.org/guide/en/">rollup.js</a> | ||
- examples and documentation generated using <a href="https://www.11ty.dev/">11ty</a> | ||
- tests run on <a href="https://automate.browserstack.com/dashboard/v2/public-build/QXZ2Z2JUaUlSV2REcHRZYzIzQThxemRnNXNQZ0c3Lzh3d01FWE4vSk1oMD0tLVFFTGlUdmxaMWNIL3hCTUJXZk1qanc9PQ==--f7c82c941ca5c14a22f826b97bc02da17c071d5e">Browserstack</a> |
@@ -15,5 +15,6 @@ { | ||
"browser": "dist/js/tom-select.complete.js", | ||
"module": "dist/esm/tom-select.complete.js", | ||
"description": "Tom Select is a versatile and dynamic <select> UI control. Framework agnostic with autocomplete and native-feeling keyboard navigation, it's useful for tagging, contact lists, country selectors, etc.", | ||
"homepage": "https://tom-select.js.org", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Josh Schmidt (https://github.com/oyejorge)", | ||
@@ -34,2 +35,3 @@ "contributors": [ | ||
"@babel/preset-env": "^7.11.0", | ||
"@babel/preset-typescript": "^7.12.1", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
@@ -92,11 +94,9 @@ "@rollup/plugin-commonjs": "^15.1.0", | ||
"browserslist": [ | ||
">= 1%", | ||
"last 1 major version", | ||
"not dead", | ||
">= 0.5%", | ||
"not dead", | ||
"Chrome >= 60", | ||
"Firefox >= 60", | ||
"Edge >= 16", | ||
"iOS >= 10", | ||
"Safari >= 10", | ||
"Android >= 6", | ||
"Edge >= 17", | ||
"iOS >= 10", | ||
"Safari >= 10", | ||
"not Explorer <= 11" | ||
@@ -103,0 +103,0 @@ ], |
@@ -18,3 +18,3 @@ <p align="center"> | ||
With autocomplete and native-feeling keyboard navigation, it's useful for tagging, contact lists, country selectors, and so on. | ||
Tom Select was forked from [Selectize.js](https://tom-select.js.org/docs/selectize.js/) to provide the same powerful UI and API but with a framework agnostic approach. | ||
Tom Select was forked from [selectize.js](https://tom-select.js.org/docs/selectize.js/) with the goal of modernizing the code base, decoupling from jQuery, and expanding functionality. | ||
@@ -58,2 +58,31 @@ | ||
<table class="table mt-5"> | ||
<tr> | ||
<th class="border-top-0">Source</th> | ||
<th class="border-top-0"></th> | ||
</tr> | ||
<tr> | ||
<td><a href="https://github.com/orchidjs/tom-select/">GitHub</a></td> | ||
<td>Clone or <a href="https://github.com/orchidjs/tom-select/archive/master.zip">download</a> the full repo. | ||
All production files (js, css, scss) can be found in the <a href="https://github.com/orchidjs/tom-select/tree/master/dist">/dist folder</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><a href="https://www.npmjs.com/package/tom-select">npm</a></td> | ||
<td><pre><code>npm i tom-select</code></pre> | ||
<div><a href="https://tom-select.js.org/docs/contribute/">Additional CLI usage</a></div> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><a href="https://www.jsdelivr.com/package/npm/tom-select?path=dist">jsDelivr</a></td> | ||
<td>Include the js and css files in your project directly from jsDelivr: | ||
<pre> | ||
<link href="https://cdn.jsdelivr.net/npm/tom-select@1.1/dist/css/tom-select.css" rel="stylesheet"> | ||
<script src="https://cdn.jsdelivr.net/npm/tom-select@1.1/dist/js/tom-select.complete.min.js"></script> | ||
</pre> | ||
</td> | ||
</tr> | ||
</table> | ||
## Files | ||
@@ -60,0 +89,0 @@ - [tom-select.complete.js](https://github.com/orchidjs/tom-select/tree/master/dist/js/tom-select.complete.js) — Includes dependencies and plugins |
@@ -24,3 +24,3 @@ /** | ||
var middlebit = node.splitText(pos); | ||
var endbit = middlebit.splitText(match[0].length); | ||
middlebit.splitText(match[0].length); | ||
var middleclone = middlebit.cloneNode(true); | ||
@@ -30,2 +30,3 @@ spannode.appendChild(middleclone); | ||
skip = 1; | ||
} | ||
@@ -32,0 +33,0 @@ } |
@@ -190,6 +190,6 @@ /** | ||
* @param {object|string} search | ||
* @param {object} options | ||
* @param {object} [options] | ||
* @returns {function} | ||
*/ | ||
getScoreFunction(search, options=null ){ | ||
getScoreFunction(search, options ){ | ||
var self, fields, tokens, token_count, nesting; | ||
@@ -360,3 +360,3 @@ | ||
return function(a, b) { | ||
var i, result, a_value, b_value, field; | ||
var i, result, field; | ||
for (i = 0; i < fields_count; i++) { | ||
@@ -430,3 +430,3 @@ field = fields[i].field; | ||
search(query, options) { | ||
var self = this, value, score, search, calculateScore; | ||
var self = this, score, search; | ||
var fn_sort; | ||
@@ -433,0 +433,0 @@ var fn_score; |
@@ -859,69 +859,2 @@ | ||
describe('isKeyDown()', function() { | ||
var test = setup_test('<select>'); | ||
var instance = test.instance; | ||
var last_keydown; | ||
test.instance.control_input.addEventListener('keydown',function(evt){ | ||
last_keydown = evt; | ||
}); | ||
let keys = ['shift','ctrl','alt','meta']; | ||
for( key in keys){ | ||
key = keys[key]; | ||
syn.type('['+key+']', test.instance.control_input, function(evt) { | ||
console.log('key press',key,'keycode',last_keydown.keyCode); | ||
console.log('shiftKey',last_keydown.shiftKey); | ||
console.log('ctrlKey',last_keydown.ctrlKey); | ||
console.log('altKey',last_keydown.altKey); | ||
console.log('metaKey',last_keydown.metaKey); | ||
syn.type('['+key+'-up]', test.instance.control_input); | ||
}); | ||
} | ||
it_n('should return false if [alt] is pressed', function() { | ||
syn.type('[alt]', test.instance.control_input, function(evt) { | ||
assert.equal( instance.isKeyDown('shiftKey',last_keydown), false); | ||
syn.type('[alt-up]', test.instance.control_input); | ||
}); | ||
}); | ||
it_n('should return false if [alt][shift] is pressed', function() { | ||
syn.type('[alt][shift]', test.instance.control_input, function() { | ||
assert.equal( instance.isKeyDown('shiftKey',last_keydown), false); | ||
syn.type('[alt-up][shift-up]', test.instance.control_input); | ||
}); | ||
}); | ||
it_n('should return false if ['+shortcut_key+'][shift] is pressed', function() { | ||
syn.type('['+shortcut_key+'][shift]', test.instance.control_input, function() { | ||
assert.equal( instance.isKeyDown('shiftKey',last_keydown), false); | ||
assert.equal( instance.isKeyDown('ctrlKey',last_keydown), false); | ||
syn.type('['+shortcut_key+'-up][shift-up]', test.instance.control_input); | ||
}); | ||
}); | ||
it_n('should return true if [shift] is pressed', function() { | ||
syn.type('[shift]', test.instance.control_input, function() { | ||
assert.equal( instance.isKeyDown('shiftKey',last_keydown), true); | ||
syn.type('[shift-up]', test.instance.control_input); | ||
}); | ||
}); | ||
it_n('should return true if ['+shortcut_key+'] is pressed', function() { | ||
syn.type('['+shortcut_key+']', test.instance.control_input, function() { | ||
assert.equal( instance.isKeyDown(shortcut_key+'Key',last_keydown), true); | ||
syn.type('['+shortcut_key+'-up]', test.instance.control_input); | ||
}); | ||
}); | ||
}); | ||
}); |
describe('ESM Module', function(){ | ||
describe('ESM Module', function(d1){ | ||
this.timeout(7000); | ||
it_n('should initialize without exceptions', function(done){ | ||
// currently fails on IOS 10 + FFox 82 | ||
this.skip(); | ||
import('/base/src/tom-select.complete.js').then(function(SelectModule){ | ||
import('/base/build/esm/tom-select.complete.js').then(function(SelectModule){ | ||
var instance = new SelectModule.default('<select>'); | ||
@@ -17,8 +16,53 @@ assert.equal( true, true); | ||
}).catch(function(err){ | ||
assert.equal( true, false); | ||
assert.equal( true, false,'import tom-select.complete.js failed'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
it_n('isKeyDown', function(done){ | ||
var last_keydown; | ||
document.body.addEventListener('keydown',function(evt){ | ||
last_keydown = evt; | ||
}); | ||
import('/base/build/esm/utils.js').then(function(util_module){ | ||
syn.type('[alt]', document.body, function(evt) { | ||
assert.equal( util_module.isKeyDown('shiftKey',last_keydown), false, 'should return false if [alt] is pressed'); | ||
syn.type('[alt-up]', document.body); | ||
}); | ||
syn.type('[alt][shift]', document.body, function() { | ||
assert.equal( util_module.isKeyDown('shiftKey',last_keydown), false, 'should return false if [alt][shift] is pressed'); | ||
syn.type('[alt-up][shift-up]', document.body); | ||
}); | ||
syn.type('['+shortcut_key+'][shift]', document.body, function() { | ||
assert.equal( util_module.isKeyDown('shiftKey',last_keydown), false, 'should return false if ['+shortcut_key+'][shift] is pressed'); | ||
assert.equal( util_module.isKeyDown('ctrlKey',last_keydown), false, 'should return false if ['+shortcut_key+'][shift] is pressed'); | ||
syn.type('['+shortcut_key+'-up][shift-up]', document.body); | ||
}); | ||
syn.type('[shift]', document.body, function() { | ||
assert.equal( util_module.isKeyDown('shiftKey',last_keydown), true, 'should return true if [shift] is pressed'); | ||
syn.type('[shift-up]', document.body); | ||
}); | ||
syn.type('['+shortcut_key+']', document.body, function() { | ||
assert.equal( util_module.isKeyDown(shortcut_key+'Key',last_keydown), true, 'should return true if ['+shortcut_key+'] is pressed'); | ||
syn.type('['+shortcut_key+'-up]', document.body); | ||
}); | ||
done(); | ||
}).catch(function(err){ | ||
assert.equal( true, false, 'import utils.js failed'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,17 @@ | ||
function eventTest(event, html, options){ | ||
var test = setup_test(html, options); | ||
test.counter = 0; | ||
test.instance.on(event, function(){ | ||
assert.equal(test.instance,this); | ||
test.counter++; | ||
}); | ||
return test; | ||
} | ||
describe('Events', function() { | ||
@@ -5,11 +21,8 @@ | ||
it_n('should work as expected', function(done) { | ||
var test = setup_test('<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
var counter = 0; | ||
test.instance.on('focus', function() { counter++; }); | ||
var test = eventTest('focus','<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
syn.click(test.instance.control).delay(1, function() { | ||
expect(counter).to.be.equal(1); | ||
assert.equal(test.counter, 1); | ||
done(); | ||
}); | ||
@@ -21,5 +34,3 @@ }); | ||
it_n('blur event should be called when clicking on body', function(done) { | ||
var test = setup_test('<select id="blur-test"><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
var counter = 0; | ||
test.instance.on('blur', function() { counter++; }); | ||
var test = eventTest('blur','<select id="blur-test"><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
@@ -30,5 +41,5 @@ syn.click(test.instance.control).delay(0, function() { | ||
syn.click($('body')).delay(1, function() { | ||
syn.click(document.body).delay(1, function() { | ||
expect(counter,'onblur event not fired').to.be.equal(1); | ||
expect(test.counter,'onblur event not fired').to.be.equal(1); | ||
done(); | ||
@@ -43,9 +54,7 @@ }); | ||
it_n('should be triggered once', function(done) { | ||
var test = setup_test('<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
var counter = 0; | ||
test.instance.on('change', function() { counter++; }); | ||
var test = eventTest('change','<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {}); | ||
test.instance.setValue('b'); | ||
window.setTimeout(function() { | ||
expect(counter).to.be.equal(1); | ||
expect(test.counter).to.be.equal(1); | ||
done(); | ||
@@ -63,7 +72,4 @@ }, 0); | ||
it_n('should not be triggered when the selected item has not changed', function(done) { | ||
var test = setup_test('<select><option value="a" selected="selected">a</option></select>'); | ||
var test = eventTest('change','<select><option value="a" selected="selected">a</option></select>'); | ||
var counter = 0; | ||
test.instance.on('change', function() { counter++; }); | ||
syn.click(test.instance.control).delay(0, function() { | ||
@@ -73,3 +79,3 @@ syn | ||
.delay(0, function() { | ||
expect(counter).to.be.equal(0); | ||
expect(test.counter).to.be.equal(0); | ||
done(); | ||
@@ -82,9 +88,8 @@ }); | ||
it_n('should not be possible to trigger a disabled option', function(done) { | ||
var test = setup_test(['<select>', | ||
'<option value="a" disabled>Item A</option>', | ||
'<option value="b">Item B</option>', | ||
'</select>'].join(''), {}); | ||
var counter = 0; | ||
test.instance.on('change', function() { counter++; }); | ||
var test = eventTest('change',`<select> | ||
<option value="a" disabled>Item A</option> | ||
<option value="b">Item B</option> | ||
</select>`, {}); | ||
syn.click(test.instance.control).delay(0, function() { | ||
@@ -94,3 +99,3 @@ syn | ||
.delay(0, function() { | ||
expect(counter).to.be.equal(0); | ||
expect(test.counter).to.be.equal(0); | ||
done(); | ||
@@ -102,13 +107,11 @@ }); | ||
it_n('should not be possible to trigger a option under a disabled optgroup', function(done) { | ||
var test = setup_test(['<select>', | ||
'<optgroup label="Group 1">', | ||
'<option value="a">Item A</option>', | ||
'</optgroup>', | ||
'<optgroup label="Group 2" disabled>', | ||
'<option value="b">Item B</option>', | ||
'<option value="c">Item C</option>', | ||
'</optgroup>', | ||
'</select>'].join(''), {}); | ||
var counter = 0; | ||
test.instance.on('change', function() { counter++; }); | ||
var test = eventTest('change',`<select> | ||
<optgroup label="Group 1"> | ||
<option value="a">Item A</option> | ||
</optgroup> | ||
<optgroup label="Group 2" disabled> | ||
<option value="b">Item B</option> | ||
<option value="c">Item C</option> | ||
</optgroup> | ||
</select>`, {}); | ||
@@ -119,3 +122,3 @@ syn.click(test.instance.control).delay(0, function() { | ||
.delay(0, function() { | ||
expect(counter).to.be.equal(0); | ||
expect(test.counter).to.be.equal(0); | ||
done(); | ||
@@ -122,0 +125,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 10 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
2621261
175
33268
100
51
12
60