Add Tom-Select lib

This commit is contained in:
jf-cbd
2025-11-13 10:48:06 +01:00
parent cef8fbc859
commit 7733f13d14
354 changed files with 53014 additions and 2 deletions

View File

@@ -0,0 +1,171 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.caret_position = factory());
})(this, (function () { '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'
*
*/
/**
* Iterates over arrays and hashes.
*
* ```
* iterate(this.items, function(item, id) {
* // invoked for each item
* });
* ```
*
*/
const iterate = (object, callback) => {
if (Array.isArray(object)) {
object.forEach(callback);
} else {
for (var key in object) {
if (object.hasOwnProperty(key)) {
callback(object[key], key);
}
}
}
};
/**
* Remove css classes
*
*/
const removeClasses = (elmts, ...classes) => {
var norm_classes = classesArray(classes);
elmts = castAsArray(elmts);
elmts.map(el => {
norm_classes.map(cls => {
el.classList.remove(cls);
});
});
};
/**
* Return arguments
*
*/
const classesArray = args => {
var classes = [];
iterate(args, _classes => {
if (typeof _classes === 'string') {
_classes = _classes.trim().split(/[\t\n\f\r\s]/);
}
if (Array.isArray(_classes)) {
classes = classes.concat(_classes);
}
});
return classes.filter(Boolean);
};
/**
* Create an array from arg if it's not already an array
*
*/
const castAsArray = arg => {
if (!Array.isArray(arg)) {
arg = [arg];
}
return arg;
};
/**
* Get the index of an element amongst sibling nodes of the same type
*
*/
const nodeIndex = (el, amongst) => {
if (!el) return -1;
amongst = amongst || el.nodeName;
var i = 0;
while (el = el.previousElementSibling) {
if (el.matches(amongst)) {
i++;
}
}
return i;
};
/**
* Plugin: "dropdown_input" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
var self = this;
/**
* Moves the caret to the specified index.
*
* The input must be moved by leaving it in place and moving the
* siblings, due to the fact that focus cannot be restored once lost
* on mobile webkit devices
*
*/
self.hook('instead', 'setCaret', new_pos => {
if (self.settings.mode === 'single' || !self.control.contains(self.control_input)) {
new_pos = self.items.length;
} else {
new_pos = Math.max(0, Math.min(self.items.length, new_pos));
if (new_pos != self.caretPos && !self.isPending) {
self.controlChildren().forEach((child, j) => {
if (j < new_pos) {
self.control_input.insertAdjacentElement('beforebegin', child);
} else {
self.control.appendChild(child);
}
});
}
}
self.caretPos = new_pos;
});
self.hook('instead', 'moveCaret', direction => {
if (!self.isFocused) return;
// move caret before or after selected items
const last_active = self.getLastActive(direction);
if (last_active) {
const idx = nodeIndex(last_active);
self.setCaret(direction > 0 ? idx + 1 : idx);
self.setActiveItem();
removeClasses(last_active, 'last-active');
// move caret left or right of current position
} else {
self.setCaret(self.caretPos + direction);
}
});
}
return plugin;
}));
//# sourceMappingURL=caret_position.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.change_listener = factory());
})(this, (function () { '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'
*
*/
/**
* Add event helper
*
*/
const addEvent = (target, type, callback, options) => {
target.addEventListener(type, callback, options);
};
/**
* Plugin: "change_listener" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
addEvent(this.input, 'change', () => {
this.sync();
});
}
return plugin;
}));
//# sourceMappingURL=change_listener.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,187 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.checkbox_options = factory());
})(this, (function () { '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'
*
*/
const hash_key = value => {
if (typeof value === 'undefined' || value === null) return null;
return get_hash(value);
};
const get_hash = value => {
if (typeof value === 'boolean') return value ? '1' : '0';
return value + '';
};
/**
* Prevent default
*
*/
const preventDefault = (evt, stop = false) => {
if (evt) {
evt.preventDefault();
if (stop) {
evt.stopPropagation();
}
}
};
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Plugin: "checkbox_options" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin (userOptions) {
var self = this;
var orig_onOptionSelect = self.onOptionSelect;
self.settings.hideSelected = false;
const cbOptions = Object.assign({
// so that the user may add different ones as well
className: "tomselect-checkbox",
// the following default to the historic plugin's values
checkedClassNames: undefined,
uncheckedClassNames: undefined
}, userOptions);
var UpdateChecked = function UpdateChecked(checkbox, toCheck) {
if (toCheck) {
checkbox.checked = true;
if (cbOptions.uncheckedClassNames) {
checkbox.classList.remove(...cbOptions.uncheckedClassNames);
}
if (cbOptions.checkedClassNames) {
checkbox.classList.add(...cbOptions.checkedClassNames);
}
} else {
checkbox.checked = false;
if (cbOptions.checkedClassNames) {
checkbox.classList.remove(...cbOptions.checkedClassNames);
}
if (cbOptions.uncheckedClassNames) {
checkbox.classList.add(...cbOptions.uncheckedClassNames);
}
}
};
// update the checkbox for an option
var UpdateCheckbox = function UpdateCheckbox(option) {
setTimeout(() => {
var checkbox = option.querySelector('input.' + cbOptions.className);
if (checkbox instanceof HTMLInputElement) {
UpdateChecked(checkbox, option.classList.contains('selected'));
}
}, 1);
};
// add checkbox to option template
self.hook('after', 'setupTemplates', () => {
var orig_render_option = self.settings.render.option;
self.settings.render.option = (data, escape_html) => {
var rendered = getDom(orig_render_option.call(self, data, escape_html));
var checkbox = document.createElement('input');
if (cbOptions.className) {
checkbox.classList.add(cbOptions.className);
}
checkbox.addEventListener('click', function (evt) {
preventDefault(evt);
});
checkbox.type = 'checkbox';
const hashed = hash_key(data[self.settings.valueField]);
UpdateChecked(checkbox, !!(hashed && self.items.indexOf(hashed) > -1));
rendered.prepend(checkbox);
return rendered;
};
});
// uncheck when item removed
self.on('item_remove', value => {
var option = self.getOption(value);
if (option) {
// if dropdown hasn't been opened yet, the option won't exist
option.classList.remove('selected'); // selected class won't be removed yet
UpdateCheckbox(option);
}
});
// check when item added
self.on('item_add', value => {
var option = self.getOption(value);
if (option) {
// if dropdown hasn't been opened yet, the option won't exist
UpdateCheckbox(option);
}
});
// remove items when selected option is clicked
self.hook('instead', 'onOptionSelect', (evt, option) => {
if (option.classList.contains('selected')) {
option.classList.remove('selected');
self.removeItem(option.dataset.value);
self.refreshOptions();
preventDefault(evt, true);
return;
}
orig_onOptionSelect.call(self, evt, option);
UpdateCheckbox(option);
});
}
return plugin;
}));
//# sourceMappingURL=checkbox_options.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,81 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.clear_button = factory());
})(this, (function () { 'use strict';
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Plugin: "dropdown_header" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin (userOptions) {
const self = this;
const options = Object.assign({
className: 'clear-button',
title: 'Clear All',
html: data => {
return `<div class="${data.className}" title="${data.title}">&#10799;</div>`;
}
}, userOptions);
self.on('initialize', () => {
var button = getDom(options.html(options));
button.addEventListener('click', evt => {
if (self.isLocked) return;
self.clear();
if (self.settings.mode === 'single' && self.settings.allowEmptyOption) {
self.addItem('');
}
evt.preventDefault();
evt.stopPropagation();
});
self.control.appendChild(button);
});
}
return plugin;
}));
//# sourceMappingURL=clear_button.js.map

File diff suppressed because one or more lines are too long

228
node_modules/tom-select/dist/js/plugins/drag_drop.js generated vendored Normal file
View File

@@ -0,0 +1,228 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.drag_drop = factory());
})(this, (function () { '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
*
*/
const preventDefault = (evt, stop = false) => {
if (evt) {
evt.preventDefault();
if (stop) {
evt.stopPropagation();
}
}
};
/**
* Add event helper
*
*/
const addEvent = (target, type, callback, options) => {
target.addEventListener(type, callback, options);
};
/**
* Iterates over arrays and hashes.
*
* ```
* iterate(this.items, function(item, id) {
* // invoked for each item
* });
* ```
*
*/
const iterate = (object, callback) => {
if (Array.isArray(object)) {
object.forEach(callback);
} else {
for (var key in object) {
if (object.hasOwnProperty(key)) {
callback(object[key], key);
}
}
}
};
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Set attributes of an element
*
*/
const setAttr = (el, attrs) => {
iterate(attrs, (val, attr) => {
if (val == null) {
el.removeAttribute(attr);
} else {
el.setAttribute(attr, '' + val);
}
});
};
/**
* Plugin: "drag_drop" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
const insertAfter = (referenceNode, newNode) => {
var _referenceNode$parent;
(_referenceNode$parent = referenceNode.parentNode) == null || _referenceNode$parent.insertBefore(newNode, referenceNode.nextSibling);
};
const insertBefore = (referenceNode, newNode) => {
var _referenceNode$parent2;
(_referenceNode$parent2 = referenceNode.parentNode) == null || _referenceNode$parent2.insertBefore(newNode, referenceNode);
};
const isBefore = (referenceNode, newNode) => {
do {
var _newNode;
newNode = (_newNode = newNode) == null ? void 0 : _newNode.previousElementSibling;
if (referenceNode == newNode) {
return true;
}
} while (newNode && newNode.previousElementSibling);
return false;
};
function plugin () {
var self = this;
if (self.settings.mode !== 'multi') return;
var orig_lock = self.lock;
var orig_unlock = self.unlock;
let sortable = true;
let drag_item;
/**
* Add draggable attribute to item
*/
self.hook('after', 'setupTemplates', () => {
var orig_render_item = self.settings.render.item;
self.settings.render.item = (data, escape) => {
const item = getDom(orig_render_item.call(self, data, escape));
setAttr(item, {
'draggable': 'true'
});
// prevent doc_mousedown (see tom-select.ts)
const mousedown = evt => {
if (!sortable) preventDefault(evt);
evt.stopPropagation();
};
const dragStart = evt => {
drag_item = item;
setTimeout(() => {
item.classList.add('ts-dragging');
}, 0);
};
const dragOver = evt => {
evt.preventDefault();
item.classList.add('ts-drag-over');
moveitem(item, drag_item);
};
const dragLeave = () => {
item.classList.remove('ts-drag-over');
};
const moveitem = (targetitem, dragitem) => {
if (dragitem === undefined) return;
if (isBefore(dragitem, item)) {
insertAfter(targetitem, dragitem);
} else {
insertBefore(targetitem, dragitem);
}
};
const dragend = () => {
var _drag_item;
document.querySelectorAll('.ts-drag-over').forEach(el => el.classList.remove('ts-drag-over'));
(_drag_item = drag_item) == null || _drag_item.classList.remove('ts-dragging');
drag_item = undefined;
var values = [];
self.control.querySelectorAll(`[data-value]`).forEach(el => {
if (el.dataset.value) {
let value = el.dataset.value;
if (value) {
values.push(value);
}
}
});
self.setValue(values);
};
addEvent(item, 'mousedown', mousedown);
addEvent(item, 'dragstart', dragStart);
addEvent(item, 'dragenter', dragOver);
addEvent(item, 'dragover', dragOver);
addEvent(item, 'dragleave', dragLeave);
addEvent(item, 'dragend', dragend);
return item;
};
});
self.hook('instead', 'lock', () => {
sortable = false;
return orig_lock.call(self);
});
self.hook('instead', 'unlock', () => {
sortable = true;
return orig_unlock.call(self);
});
}
return plugin;
}));
//# sourceMappingURL=drag_drop.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,110 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.dropdown_header = factory());
})(this, (function () { '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
*
*/
const preventDefault = (evt, stop = false) => {
if (evt) {
evt.preventDefault();
if (stop) {
evt.stopPropagation();
}
}
};
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Plugin: "dropdown_header" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin (userOptions) {
const self = this;
const options = Object.assign({
title: 'Untitled',
headerClass: 'dropdown-header',
titleRowClass: 'dropdown-header-title',
labelClass: 'dropdown-header-label',
closeClass: 'dropdown-header-close',
html: data => {
return '<div class="' + data.headerClass + '">' + '<div class="' + data.titleRowClass + '">' + '<span class="' + data.labelClass + '">' + data.title + '</span>' + '<a class="' + data.closeClass + '">&times;</a>' + '</div>' + '</div>';
}
}, userOptions);
self.on('initialize', () => {
var header = getDom(options.html(options));
var close_link = header.querySelector('.' + options.closeClass);
if (close_link) {
close_link.addEventListener('click', evt => {
preventDefault(evt, true);
self.close();
});
}
self.dropdown.insertBefore(header, self.dropdown.firstChild);
});
}
return plugin;
}));
//# sourceMappingURL=dropdown_header.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,222 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.dropdown_input = factory());
})(this, (function () { 'use strict';
const KEY_ESC = 27;
const KEY_TAB = 9;
// 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
*
*/
const preventDefault = (evt, stop = false) => {
if (evt) {
evt.preventDefault();
if (stop) {
evt.stopPropagation();
}
}
};
/**
* Add event helper
*
*/
const addEvent = (target, type, callback, options) => {
target.addEventListener(type, callback, options);
};
/**
* Iterates over arrays and hashes.
*
* ```
* iterate(this.items, function(item, id) {
* // invoked for each item
* });
* ```
*
*/
const iterate = (object, callback) => {
if (Array.isArray(object)) {
object.forEach(callback);
} else {
for (var key in object) {
if (object.hasOwnProperty(key)) {
callback(object[key], key);
}
}
}
};
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Add css classes
*
*/
const addClasses = (elmts, ...classes) => {
var norm_classes = classesArray(classes);
elmts = castAsArray(elmts);
elmts.map(el => {
norm_classes.map(cls => {
el.classList.add(cls);
});
});
};
/**
* Return arguments
*
*/
const classesArray = args => {
var classes = [];
iterate(args, _classes => {
if (typeof _classes === 'string') {
_classes = _classes.trim().split(/[\t\n\f\r\s]/);
}
if (Array.isArray(_classes)) {
classes = classes.concat(_classes);
}
});
return classes.filter(Boolean);
};
/**
* Create an array from arg if it's not already an array
*
*/
const castAsArray = arg => {
if (!Array.isArray(arg)) {
arg = [arg];
}
return arg;
};
/**
* Plugin: "dropdown_input" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
const self = this;
self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
self.hook('before', 'setup', () => {
self.focus_node = self.control;
addClasses(self.control_input, 'dropdown-input');
const div = getDom('<div class="dropdown-input-wrap">');
div.append(self.control_input);
self.dropdown.insertBefore(div, self.dropdown.firstChild);
// set a placeholder in the select control
const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />');
placeholder.placeholder = self.settings.placeholder || '';
self.control.append(placeholder);
});
self.on('initialize', () => {
// set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
self.control_input.addEventListener('keydown', evt => {
//addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
switch (evt.keyCode) {
case KEY_ESC:
if (self.isOpen) {
preventDefault(evt, true);
self.close();
}
self.clearActiveItems();
return;
case KEY_TAB:
self.focus_node.tabIndex = -1;
break;
}
return self.onKeyDown.call(self, evt);
});
self.on('blur', () => {
self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
});
// give the control_input focus when the dropdown is open
self.on('dropdown_open', () => {
self.control_input.focus();
});
// prevent onBlur from closing when focus is on the control_input
const orig_onBlur = self.onBlur;
self.hook('instead', 'onBlur', evt => {
if (evt && evt.relatedTarget == self.control_input) return;
return orig_onBlur.call(self);
});
addEvent(self.control_input, 'blur', () => self.onBlur());
// return focus to control to allow further keyboard input
self.hook('before', 'close', () => {
if (!self.isOpen) return;
self.focus_node.focus({
preventScroll: true
});
});
});
}
return plugin;
}));
//# sourceMappingURL=dropdown_input.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,82 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.input_autogrow = factory());
})(this, (function () { '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'
*
*/
/**
* Add event helper
*
*/
const addEvent = (target, type, callback, options) => {
target.addEventListener(type, callback, options);
};
/**
* Plugin: "input_autogrow" (Tom Select)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
var self = this;
self.on('initialize', () => {
var test_input = document.createElement('span');
var control = self.control_input;
test_input.style.cssText = 'position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ';
self.wrapper.appendChild(test_input);
var transfer_styles = ['letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform'];
for (const style_name of transfer_styles) {
// @ts-ignore TS7015 https://stackoverflow.com/a/50506154/697576
test_input.style[style_name] = control.style[style_name];
}
/**
* Set the control width
*
*/
var resize = () => {
test_input.textContent = control.value;
control.style.width = test_input.clientWidth + 'px';
};
resize();
self.on('update item_add item_remove', resize);
addEvent(control, 'input', resize);
addEvent(control, 'keyup', resize);
addEvent(control, 'blur', resize);
addEvent(control, 'update', resize);
});
}
return plugin;
}));
//# sourceMappingURL=input_autogrow.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.no_active_items = factory());
})(this, (function () { 'use strict';
/**
* Plugin: "no_active_items" (Tom Select)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
this.hook('instead', 'setActiveItem', () => {});
this.hook('instead', 'selectAll', () => {});
}
return plugin;
}));
//# sourceMappingURL=no_active_items.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"no_active_items.js","sources":["../../../src/plugins/no_active_items/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"no_active_items\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport type TomSelect from '../../tom-select.ts';\n\nexport default function(this:TomSelect) {\n\tthis.hook('instead','setActiveItem',() => {});\n\tthis.hook('instead','selectAll',() => {});\n};\n"],"names":["hook"],"mappings":";;;;;;;;;;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAIe,eAAyB,IAAA;GACvC,IAAI,CAACA,IAAI,CAAC,SAAS,EAAC,eAAe,EAAC,MAAM,EAAE,CAAC;GAC7C,IAAI,CAACA,IAAI,CAAC,SAAS,EAAC,WAAW,EAAC,MAAM,EAAE,CAAC;CAC1C;;;;;;;;"}

View File

@@ -0,0 +1,40 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.no_backspace_delete = factory());
})(this, (function () { 'use strict';
/**
* Plugin: "input_autogrow" (Tom Select)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
var self = this;
var orig_deleteSelection = self.deleteSelection;
this.hook('instead', 'deleteSelection', evt => {
if (self.activeItems.length) {
return orig_deleteSelection.call(self, evt);
}
return false;
});
}
return plugin;
}));
//# sourceMappingURL=no_backspace_delete.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"no_backspace_delete.js","sources":["../../../src/plugins/no_backspace_delete/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"input_autogrow\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport type TomSelect from '../../tom-select.ts';\n\nexport default function(this:TomSelect) {\n\tvar self = this;\n\tvar orig_deleteSelection = self.deleteSelection;\n\n\tthis.hook('instead','deleteSelection',(evt:KeyboardEvent) => {\n\n\t\tif( self.activeItems.length ){\n\t\t\treturn orig_deleteSelection.call(self, evt);\n\t\t}\n\n\t\treturn false;\n\t});\n\n};\n"],"names":["self","orig_deleteSelection","deleteSelection","hook","evt","activeItems","length","call"],"mappings":";;;;;;;;;;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAIe,eAAyB,IAAA;GACvC,IAAIA,IAAI,GAAG,IAAI;CACf,EAAA,IAAIC,oBAAoB,GAAGD,IAAI,CAACE,eAAe;GAE/C,IAAI,CAACC,IAAI,CAAC,SAAS,EAAC,iBAAiB,EAAEC,GAAiB,IAAK;CAE5D,IAAA,IAAIJ,IAAI,CAACK,WAAW,CAACC,MAAM,EAAE;CAC5B,MAAA,OAAOL,oBAAoB,CAACM,IAAI,CAACP,IAAI,EAAEI,GAAG,CAAC;CAC5C;CAEA,IAAA,OAAO,KAAK;CACb,GAAC,CAAC;CAEH;;;;;;;;"}

View File

@@ -0,0 +1,94 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.optgroup_columns = factory());
})(this, (function () { 'use strict';
const KEY_LEFT = 37;
const KEY_RIGHT = 39;
// ctrl key or apple key for ma
/**
* Get the closest node to the evt.target matching the selector
* Stops at wrapper
*
*/
const parentMatch = (target, selector, wrapper) => {
while (target && target.matches) {
if (target.matches(selector)) {
return target;
}
target = target.parentNode;
}
};
/**
* Get the index of an element amongst sibling nodes of the same type
*
*/
const nodeIndex = (el, amongst) => {
if (!el) return -1;
amongst = amongst || el.nodeName;
var i = 0;
while (el = el.previousElementSibling) {
if (el.matches(amongst)) {
i++;
}
}
return i;
};
/**
* Plugin: "optgroup_columns" (Tom Select.js)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
var self = this;
var orig_keydown = self.onKeyDown;
self.hook('instead', 'onKeyDown', evt => {
var index, option, options, optgroup;
if (!self.isOpen || !(evt.keyCode === KEY_LEFT || evt.keyCode === KEY_RIGHT)) {
return orig_keydown.call(self, evt);
}
self.ignoreHover = true;
optgroup = parentMatch(self.activeOption, '[data-group]');
index = nodeIndex(self.activeOption, '[data-selectable]');
if (!optgroup) {
return;
}
if (evt.keyCode === KEY_LEFT) {
optgroup = optgroup.previousSibling;
} else {
optgroup = optgroup.nextSibling;
}
if (!optgroup) {
return;
}
options = optgroup.querySelectorAll('[data-selectable]');
option = options[Math.min(options.length - 1, index)];
if (option) {
self.setActiveOption(option);
}
});
}
return plugin;
}));
//# sourceMappingURL=optgroup_columns.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,142 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.remove_button = factory());
})(this, (function () { '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'
*
*/
/**
* Escapes a string for use within HTML.
*
*/
const escape_html = str => {
return (str + '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
};
/**
* Prevent default
*
*/
const preventDefault = (evt, stop = false) => {
if (evt) {
evt.preventDefault();
if (stop) {
evt.stopPropagation();
}
}
};
/**
* Add event helper
*
*/
const addEvent = (target, type, callback, options) => {
target.addEventListener(type, callback, options);
};
/**
* Return a dom element from either a dom query string, jQuery object, a dom element or html string
* https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
*
* param query should be {}
*/
const getDom = query => {
if (query.jquery) {
return query[0];
}
if (query instanceof HTMLElement) {
return query;
}
if (isHtmlString(query)) {
var tpl = document.createElement('template');
tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
return tpl.content.firstChild;
}
return document.querySelector(query);
};
const isHtmlString = arg => {
if (typeof arg === 'string' && arg.indexOf('<') > -1) {
return true;
}
return false;
};
/**
* Plugin: "remove_button" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin (userOptions) {
const options = Object.assign({
label: '&times;',
title: 'Remove',
className: 'remove',
append: true
}, userOptions);
//options.className = 'remove-single';
var self = this;
// override the render method to add remove button to each item
if (!options.append) {
return;
}
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
self.hook('after', 'setupTemplates', () => {
var orig_render_item = self.settings.render.item;
self.settings.render.item = (data, escape) => {
var item = getDom(orig_render_item.call(self, data, escape));
var close_button = getDom(html);
item.appendChild(close_button);
addEvent(close_button, 'mousedown', evt => {
preventDefault(evt, true);
});
addEvent(close_button, 'click', evt => {
if (self.isLocked) return;
// propagating will trigger the dropdown to show for single mode
preventDefault(evt, true);
if (self.isLocked) return;
if (!self.shouldDelete([item], evt)) return;
self.removeItem(item);
self.refreshOptions(false);
self.inputState();
});
return item;
};
});
}
return plugin;
}));
//# sourceMappingURL=remove_button.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,50 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.restore_on_backspace = factory());
})(this, (function () { 'use strict';
/**
* Plugin: "restore_on_backspace" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin (userOptions) {
const self = this;
const options = Object.assign({
text: option => {
return option[self.settings.labelField];
}
}, userOptions);
self.on('item_remove', function (value) {
if (!self.isFocused) {
return;
}
if (self.control_input.value.trim() === '') {
var option = self.options[value];
if (option) {
self.setTextboxValue(options.text.call(self, option));
}
}
});
}
return plugin;
}));
//# sourceMappingURL=restore_on_backspace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"restore_on_backspace.js","sources":["../../../src/plugins/restore_on_backspace/plugin.ts"],"sourcesContent":["/**\n * Plugin: \"restore_on_backspace\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\nimport type TomSelect from '../../tom-select.ts';\nimport { TomOption } from '../../types/index.ts';\n\ntype TPluginOptions = {\n\ttext?:(option:TomOption)=>string,\n};\n\nexport default function(this:TomSelect, userOptions:TPluginOptions) {\n\tconst self = this;\n\n\tconst options = Object.assign({\n\t\ttext: (option:TomOption) => {\n\t\t\treturn option[self.settings.labelField];\n\t\t}\n\t},userOptions);\n\n\tself.on('item_remove',function(value:string){\n\t\tif( !self.isFocused ){\n\t\t\treturn;\n\t\t}\n\n\t\tif( self.control_input.value.trim() === '' ){\n\t\t\tvar option = self.options[value];\n\t\t\tif( option ){\n\t\t\t\tself.setTextboxValue(options.text.call(self, option));\n\t\t\t}\n\t\t}\n\t});\n\n};\n"],"names":["userOptions","self","options","Object","assign","text","option","settings","labelField","on","value","isFocused","control_input","trim","setTextboxValue","call"],"mappings":";;;;;;;;;;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAQe,eAAA,EAAyBA,WAA0B,EAAE;GACnE,MAAMC,IAAI,GAAG,IAAI;CAEjB,EAAA,MAAMC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAAC;KAC7BC,IAAI,EAAGC,MAAgB,IAAK;CAC3B,MAAA,OAAOA,MAAM,CAACL,IAAI,CAACM,QAAQ,CAACC,UAAU,CAAC;CACxC;IACA,EAACR,WAAW,CAAC;CAEdC,EAAAA,IAAI,CAACQ,EAAE,CAAC,aAAa,EAAC,UAASC,KAAY,EAAC;CAC3C,IAAA,IAAI,CAACT,IAAI,CAACU,SAAS,EAAE;CACpB,MAAA;CACD;KAEA,IAAIV,IAAI,CAACW,aAAa,CAACF,KAAK,CAACG,IAAI,EAAE,KAAK,EAAE,EAAE;CAC3C,MAAA,IAAIP,MAAM,GAAGL,IAAI,CAACC,OAAO,CAACQ,KAAK,CAAC;CAChC,MAAA,IAAIJ,MAAM,EAAE;CACXL,QAAAA,IAAI,CAACa,eAAe,CAACZ,OAAO,CAACG,IAAI,CAACU,IAAI,CAACd,IAAI,EAAEK,MAAM,CAAC,CAAC;CACtD;CACD;CACD,GAAC,CAAC;CAEH;;;;;;;;"}

View File

@@ -0,0 +1,280 @@
/**
* Tom Select v2.4.3
* Licensed under the Apache License, Version 2.0 (the "License");
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.virtual_scroll = factory());
})(this, (function () { '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'
*
*/
/**
* Iterates over arrays and hashes.
*
* ```
* iterate(this.items, function(item, id) {
* // invoked for each item
* });
* ```
*
*/
const iterate = (object, callback) => {
if (Array.isArray(object)) {
object.forEach(callback);
} else {
for (var key in object) {
if (object.hasOwnProperty(key)) {
callback(object[key], key);
}
}
}
};
/**
* Add css classes
*
*/
const addClasses = (elmts, ...classes) => {
var norm_classes = classesArray(classes);
elmts = castAsArray(elmts);
elmts.map(el => {
norm_classes.map(cls => {
el.classList.add(cls);
});
});
};
/**
* Return arguments
*
*/
const classesArray = args => {
var classes = [];
iterate(args, _classes => {
if (typeof _classes === 'string') {
_classes = _classes.trim().split(/[\t\n\f\r\s]/);
}
if (Array.isArray(_classes)) {
classes = classes.concat(_classes);
}
});
return classes.filter(Boolean);
};
/**
* Create an array from arg if it's not already an array
*
*/
const castAsArray = arg => {
if (!Array.isArray(arg)) {
arg = [arg];
}
return arg;
};
/**
* Plugin: "restore_on_backspace" (Tom Select)
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*/
function plugin () {
const self = this;
const orig_canLoad = self.canLoad;
const orig_clearActiveOption = self.clearActiveOption;
const orig_loadCallback = self.loadCallback;
var pagination = {};
var dropdown_content;
var loading_more = false;
var load_more_opt;
var default_values = [];
if (!self.settings.shouldLoadMore) {
// return true if additional results should be loaded
self.settings.shouldLoadMore = () => {
const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop);
if (scroll_percent > 0.9) {
return true;
}
if (self.activeOption) {
var selectable = self.selectable();
var index = Array.from(selectable).indexOf(self.activeOption);
if (index >= selectable.length - 2) {
return true;
}
}
return false;
};
}
if (!self.settings.firstUrl) {
throw 'virtual_scroll plugin requires a firstUrl() method';
}
// in order for virtual scrolling to work,
// options need to be ordered the same way they're returned from the remote data source
self.settings.sortField = [{
field: '$order'
}, {
field: '$score'
}];
// can we load more results for given query?
const canLoadMore = query => {
if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) {
return false;
}
if (query in pagination && pagination[query]) {
return true;
}
return false;
};
const clearFilter = (option, value) => {
if (self.items.indexOf(value) >= 0 || default_values.indexOf(value) >= 0) {
return true;
}
return false;
};
// set the next url that will be
self.setNextUrl = (value, next_url) => {
pagination[value] = next_url;
};
// getUrl() to be used in settings.load()
self.getUrl = query => {
if (query in pagination) {
const next_url = pagination[query];
pagination[query] = false;
return next_url;
}
// if the user goes back to a previous query
// we need to load the first page again
self.clearPagination();
return self.settings.firstUrl.call(self, query);
};
// clear pagination
self.clearPagination = () => {
pagination = {};
};
// don't clear the active option (and cause unwanted dropdown scroll)
// while loading more results
self.hook('instead', 'clearActiveOption', () => {
if (loading_more) {
return;
}
return orig_clearActiveOption.call(self);
});
// override the canLoad method
self.hook('instead', 'canLoad', query => {
// first time the query has been seen
if (!(query in pagination)) {
return orig_canLoad.call(self, query);
}
return canLoadMore(query);
});
// wrap the load
self.hook('instead', 'loadCallback', (options, optgroups) => {
if (!loading_more) {
self.clearOptions(clearFilter);
} else if (load_more_opt) {
const first_option = options[0];
if (first_option !== undefined) {
load_more_opt.dataset.value = first_option[self.settings.valueField];
}
}
orig_loadCallback.call(self, options, optgroups);
loading_more = false;
});
// add templates to dropdown
// loading_more if we have another url in the queue
// no_more_results if we don't have another url in the queue
self.hook('after', 'refreshOptions', () => {
const query = self.lastValue;
var option;
if (canLoadMore(query)) {
option = self.render('loading_more', {
query: query
});
if (option) {
option.setAttribute('data-selectable', ''); // so that navigating dropdown with [down] keypresses can navigate to this node
load_more_opt = option;
}
} else if (query in pagination && !dropdown_content.querySelector('.no-results')) {
option = self.render('no_more_results', {
query: query
});
}
if (option) {
addClasses(option, self.settings.optionClass);
dropdown_content.append(option);
}
});
// add scroll listener and default templates
self.on('initialize', () => {
default_values = Object.keys(self.options);
dropdown_content = self.dropdown_content;
// default templates
self.settings.render = Object.assign({}, {
loading_more: () => {
return `<div class="loading-more-results">Loading more results ... </div>`;
},
no_more_results: () => {
return `<div class="no-more-results">No more results</div>`;
}
}, self.settings.render);
// watch dropdown content scroll position
dropdown_content.addEventListener('scroll', () => {
if (!self.settings.shouldLoadMore.call(self)) {
return;
}
// !important: this will get checked again in load() but we still need to check here otherwise loading_more will be set to true
if (!canLoadMore(self.lastValue)) {
return;
}
// don't call load() too much
if (loading_more) return;
loading_more = true;
self.load.call(self, self.lastValue);
});
});
}
return plugin;
}));
//# sourceMappingURL=virtual_scroll.js.map

File diff suppressed because one or more lines are too long