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

81
node_modules/tom-select/src/contrib/highlight.ts generated vendored Normal file
View File

@@ -0,0 +1,81 @@
/**
* highlight v3 | MIT license | Johann Burkard <jb@eaio.com>
* Highlights arbitrary terms in a node.
*
* - Modified by Marshal <beatgates@gmail.com> 2011-6-24 (added regex)
* - Modified by Brian Reavis <brian@thirdroute.com> 2012-8-27 (cleanup)
*/
import {replaceNode} from '../vanilla.ts';
export const highlight = (element:HTMLElement, regex:string|RegExp) => {
if( regex === null ) return;
// convet string to regex
if( typeof regex === 'string' ){
if( !regex.length ) return;
regex = new RegExp(regex, 'i');
}
// Wrap matching part of text node with highlighting <span>, e.g.
// Soccer -> <span class="highlight">Soc</span>cer for regex = /soc/i
const highlightText = ( node:Text ):number => {
var match = node.data.match(regex);
if( match && node.data.length > 0 ){
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = node.splitText(match.index as number);
middlebit.splitText(match[0]!.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
replaceNode(middlebit, spannode);
return 1;
}
return 0;
};
// Recurse element node, looking for child text nodes to highlight, unless element
// is childless, <script>, <style>, or already highlighted: <span class="hightlight">
const highlightChildren = ( node:Element ):void => {
if( node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName) && ( node.className !== 'highlight' || node.tagName !== 'SPAN' ) ){
Array.from(node.childNodes).forEach(element => {
highlightRecursive(element);
});
}
};
const highlightRecursive = ( node:Node|Element ):number => {
if( node.nodeType === 3 ){
return highlightText(node as Text);
}
highlightChildren(node as Element);
return 0;
};
highlightRecursive( element );
};
/**
* removeHighlight fn copied from highlight v5 and
* edited to remove with(), pass js strict mode, and use without jquery
*/
export const removeHighlight = (el:HTMLElement) => {
var elements = el.querySelectorAll("span.highlight");
Array.prototype.forEach.call(elements, function(el:HTMLElement){
var parent = el.parentNode as Node;
parent.replaceChild(el.firstChild as Node, el);
parent.normalize();
});
};

73
node_modules/tom-select/src/contrib/microevent.ts generated vendored Normal file
View File

@@ -0,0 +1,73 @@
/**
* MicroEvent - to make any js object an event emitter
*
* - pure javascript - server compatible, browser compatible
* - dont rely on the browser doms
* - super simple - you get it immediatly, no mistery, no magic involved
*
* @author Jerome Etienne (https://github.com/jeromeetienne)
*/
type TCallback = (...args:any) => any;
/**
* Execute callback for each event in space separated list of event names
*
*/
function forEvents(events:string,callback:(event:string)=>any){
events.split(/\s+/).forEach((event) =>{
callback(event);
});
}
export default class MicroEvent{
public _events: {[key:string]:TCallback[]};
constructor(){
this._events = {};
}
on(events:string, fct:TCallback){
forEvents(events,(event) => {
const event_array = this._events[event] || [];
event_array.push(fct);
this._events[event] = event_array;
});
}
off(events:string, fct:TCallback){
var n = arguments.length;
if( n === 0 ){
this._events = {};
return;
}
forEvents(events,(event) => {
if (n === 1){
delete this._events[event];
return
}
const event_array = this._events[event];
if( event_array === undefined ) return;
event_array.splice(event_array.indexOf(fct), 1);
this._events[event] = event_array;
});
}
trigger(events:string, ...args:any){
var self = this;
forEvents(events,(event) => {
const event_array = self._events[event];
if( event_array === undefined ) return;
event_array.forEach(fct => {
fct.apply(self, args );
});
});
}
};

137
node_modules/tom-select/src/contrib/microplugin.ts generated vendored Normal file
View File

@@ -0,0 +1,137 @@
/**
* microplugin.js
* Copyright (c) 2013 Brian Reavis & 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.
*
* @author Brian Reavis <brian@thirdroute.com>
*/
type TSettings = {
[key:string]:any
}
type TPlugins = {
names: string[],
settings: TSettings,
requested: {[key:string]:boolean},
loaded: {[key:string]:any}
};
export type TPluginItem = {name:string,options:{}};
export type TPluginHash = {[key:string]:{}};
export default function MicroPlugin(Interface: any ){
Interface.plugins = {};
return class extends Interface{
public plugins:TPlugins = {
names : [],
settings : {},
requested : {},
loaded : {}
};
/**
* Registers a plugin.
*
* @param {function} fn
*/
static define(name:string, fn:(this:any,settings:TSettings)=>any){
Interface.plugins[name] = {
'name' : name,
'fn' : fn
};
}
/**
* Initializes the listed plugins (with options).
* Acceptable formats:
*
* List (without options):
* ['a', 'b', 'c']
*
* List (with options):
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
*
* Hash (with options):
* {'a': { ... }, 'b': { ... }, 'c': { ... }}
*
* @param {array|object} plugins
*/
initializePlugins(plugins:string[]|TPluginItem[]|TPluginHash) {
var key, name;
const self = this;
const queue:string[] = [];
if (Array.isArray(plugins)) {
plugins.forEach((plugin:string|TPluginItem)=>{
if (typeof plugin === 'string') {
queue.push(plugin);
} else {
self.plugins.settings[plugin.name] = plugin.options;
queue.push(plugin.name);
}
});
} else if (plugins) {
for (key in plugins) {
if (plugins.hasOwnProperty(key)) {
self.plugins.settings[key] = plugins[key];
queue.push(key);
}
}
}
while( name = queue.shift() ){
self.require(name);
}
}
loadPlugin(name:string) {
var self = this;
var plugins = self.plugins;
var plugin = Interface.plugins[name];
if (!Interface.plugins.hasOwnProperty(name)) {
throw new Error('Unable to find "' + name + '" plugin');
}
plugins.requested[name] = true;
plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);
plugins.names.push(name);
}
/**
* Initializes a plugin.
*
*/
require(name:string) {
var self = this;
var plugins = self.plugins;
if (!self.plugins.loaded.hasOwnProperty(name)) {
if (plugins.requested[name]) {
throw new Error('Plugin has circular dependency ("' + name + '")');
}
self.loadPlugin(name);
}
return plugins.loaded[name];
}
};
}