Browse code

Add tom select npm package

Benjamin Roth authored on02/02/2023 12:00:30
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,293 @@
1
+/**
2
+* Tom Select v2.2.2
3
+* Licensed under the Apache License, Version 2.0 (the "License");
4
+*/
5
+
6
+(function (global, factory) {
7
+  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+  typeof define === 'function' && define.amd ? define(factory) :
9
+  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.dropdown_input = factory());
10
+})(this, (function () { 'use strict';
11
+
12
+  const KEY_ESC = 27;
13
+  const KEY_TAB = 9;
14
+  typeof navigator === 'undefined' ? false : /Mac/.test(navigator.userAgent);
15
+   // ctrl key or apple key for ma
16
+
17
+  /*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
18
+  const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}\u{2bc}]';
19
+  /** @type {TUnicodeMap} */
20
+
21
+  const latin_convert = {};
22
+  /** @type {TUnicodeMap} */
23
+
24
+  const latin_condensed = {
25
+    '/': '⁄∕',
26
+    '0': '߀',
27
+    "a": "ⱥɐɑ",
28
+    "aa": "ꜳ",
29
+    "ae": "æǽǣ",
30
+    "ao": "ꜵ",
31
+    "au": "ꜷ",
32
+    "av": "ꜹꜻ",
33
+    "ay": "ꜽ",
34
+    "b": "ƀɓƃ",
35
+    "c": "ꜿƈȼↄ",
36
+    "d": "đɗɖᴅƌꮷԁɦ",
37
+    "e": "ɛǝᴇɇ",
38
+    "f": "ꝼƒ",
39
+    "g": "ǥɠꞡᵹꝿɢ",
40
+    "h": "ħⱨⱶɥ",
41
+    "i": "ɨı",
42
+    "j": "ɉȷ",
43
+    "k": "ƙⱪꝁꝃꝅꞣ",
44
+    "l": "łƚɫⱡꝉꝇꞁɭ",
45
+    "m": "ɱɯϻ",
46
+    "n": "ꞥƞɲꞑᴎлԉ",
47
+    "o": "øǿɔɵꝋꝍᴑ",
48
+    "oe": "œ",
49
+    "oi": "ƣ",
50
+    "oo": "ꝏ",
51
+    "ou": "ȣ",
52
+    "p": "ƥᵽꝑꝓꝕρ",
53
+    "q": "ꝗꝙɋ",
54
+    "r": "ɍɽꝛꞧꞃ",
55
+    "s": "ßȿꞩꞅʂ",
56
+    "t": "ŧƭʈⱦꞇ",
57
+    "th": "þ",
58
+    "tz": "ꜩ",
59
+    "u": "ʉ",
60
+    "v": "ʋꝟʌ",
61
+    "vy": "ꝡ",
62
+    "w": "ⱳ",
63
+    "y": "ƴɏỿ",
64
+    "z": "ƶȥɀⱬꝣ",
65
+    "hv": "ƕ"
66
+  };
67
+
68
+  for (let latin in latin_condensed) {
69
+    let unicode = latin_condensed[latin] || '';
70
+
71
+    for (let i = 0; i < unicode.length; i++) {
72
+      let char = unicode.substring(i, i + 1);
73
+      latin_convert[char] = latin;
74
+    }
75
+  }
76
+
77
+  new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
78
+
79
+  /**
80
+   * Iterates over arrays and hashes.
81
+   *
82
+   * ```
83
+   * iterate(this.items, function(item, id) {
84
+   *    // invoked for each item
85
+   * });
86
+   * ```
87
+   *
88
+   */
89
+
90
+  const iterate = (object, callback) => {
91
+    if (Array.isArray(object)) {
92
+      object.forEach(callback);
93
+    } else {
94
+      for (var key in object) {
95
+        if (object.hasOwnProperty(key)) {
96
+          callback(object[key], key);
97
+        }
98
+      }
99
+    }
100
+  };
101
+
102
+  /**
103
+   * Return a dom element from either a dom query string, jQuery object, a dom element or html string
104
+   * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
105
+   *
106
+   * param query should be {}
107
+   */
108
+
109
+  const getDom = query => {
110
+    if (query.jquery) {
111
+      return query[0];
112
+    }
113
+
114
+    if (query instanceof HTMLElement) {
115
+      return query;
116
+    }
117
+
118
+    if (isHtmlString(query)) {
119
+      var tpl = document.createElement('template');
120
+      tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
121
+
122
+      return tpl.content.firstChild;
123
+    }
124
+
125
+    return document.querySelector(query);
126
+  };
127
+  const isHtmlString = arg => {
128
+    if (typeof arg === 'string' && arg.indexOf('<') > -1) {
129
+      return true;
130
+    }
131
+
132
+    return false;
133
+  };
134
+  /**
135
+   * Add css classes
136
+   *
137
+   */
138
+
139
+  const addClasses = (elmts, ...classes) => {
140
+    var norm_classes = classesArray(classes);
141
+    elmts = castAsArray(elmts);
142
+    elmts.map(el => {
143
+      norm_classes.map(cls => {
144
+        el.classList.add(cls);
145
+      });
146
+    });
147
+  };
148
+  /**
149
+   * Return arguments
150
+   *
151
+   */
152
+
153
+  const classesArray = args => {
154
+    var classes = [];
155
+    iterate(args, _classes => {
156
+      if (typeof _classes === 'string') {
157
+        _classes = _classes.trim().split(/[\11\12\14\15\40]/);
158
+      }
159
+
160
+      if (Array.isArray(_classes)) {
161
+        classes = classes.concat(_classes);
162
+      }
163
+    });
164
+    return classes.filter(Boolean);
165
+  };
166
+  /**
167
+   * Create an array from arg if it's not already an array
168
+   *
169
+   */
170
+
171
+  const castAsArray = arg => {
172
+    if (!Array.isArray(arg)) {
173
+      arg = [arg];
174
+    }
175
+
176
+    return arg;
177
+  };
178
+
179
+  /**
180
+   * Converts a scalar to its best string representation
181
+   * for hash keys and HTML attribute values.
182
+   *
183
+   * Transformations:
184
+   *   'str'     -> 'str'
185
+   *   null      -> ''
186
+   *   undefined -> ''
187
+   *   true      -> '1'
188
+   *   false     -> '0'
189
+   *   0         -> '0'
190
+   *   1         -> '1'
191
+   *
192
+   */
193
+  /**
194
+   * Prevent default
195
+   *
196
+   */
197
+
198
+  const preventDefault = (evt, stop = false) => {
199
+    if (evt) {
200
+      evt.preventDefault();
201
+
202
+      if (stop) {
203
+        evt.stopPropagation();
204
+      }
205
+    }
206
+  };
207
+  /**
208
+   * Add event helper
209
+   *
210
+   */
211
+
212
+  const addEvent = (target, type, callback, options) => {
213
+    target.addEventListener(type, callback, options);
214
+  };
215
+
216
+  /**
217
+   * Plugin: "dropdown_input" (Tom Select)
218
+   * Copyright (c) contributors
219
+   *
220
+   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
221
+   * file except in compliance with the License. You may obtain a copy of the License at:
222
+   * http://www.apache.org/licenses/LICENSE-2.0
223
+   *
224
+   * Unless required by applicable law or agreed to in writing, software distributed under
225
+   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
226
+   * ANY KIND, either express or implied. See the License for the specific language
227
+   * governing permissions and limitations under the License.
228
+   *
229
+   */
230
+  function plugin () {
231
+    const self = this;
232
+    self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown
233
+
234
+    self.hook('before', 'setup', () => {
235
+      self.focus_node = self.control;
236
+      addClasses(self.control_input, 'dropdown-input');
237
+      const div = getDom('<div class="dropdown-input-wrap">');
238
+      div.append(self.control_input);
239
+      self.dropdown.insertBefore(div, self.dropdown.firstChild); // set a placeholder in the select control
240
+
241
+      const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />');
242
+      placeholder.placeholder = self.settings.placeholder || '';
243
+      self.control.append(placeholder);
244
+    });
245
+    self.on('initialize', () => {
246
+      // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input
247
+      self.control_input.addEventListener('keydown', evt => {
248
+        //addEvent(self.control_input,'keydown' as const,(evt:KeyboardEvent) =>{
249
+        switch (evt.keyCode) {
250
+          case KEY_ESC:
251
+            if (self.isOpen) {
252
+              preventDefault(evt, true);
253
+              self.close();
254
+            }
255
+
256
+            self.clearActiveItems();
257
+            return;
258
+
259
+          case KEY_TAB:
260
+            self.focus_node.tabIndex = -1;
261
+            break;
262
+        }
263
+
264
+        return self.onKeyDown.call(self, evt);
265
+      });
266
+      self.on('blur', () => {
267
+        self.focus_node.tabIndex = self.isDisabled ? -1 : self.tabIndex;
268
+      }); // give the control_input focus when the dropdown is open
269
+
270
+      self.on('dropdown_open', () => {
271
+        self.control_input.focus();
272
+      }); // prevent onBlur from closing when focus is on the control_input
273
+
274
+      const orig_onBlur = self.onBlur;
275
+      self.hook('instead', 'onBlur', evt => {
276
+        if (evt && evt.relatedTarget == self.control_input) return;
277
+        return orig_onBlur.call(self);
278
+      });
279
+      addEvent(self.control_input, 'blur', () => self.onBlur()); // return focus to control to allow further keyboard input
280
+
281
+      self.hook('before', 'close', () => {
282
+        if (!self.isOpen) return;
283
+        self.focus_node.focus({
284
+          preventScroll: true
285
+        });
286
+      });
287
+    });
288
+  }
289
+
290
+  return plugin;
291
+
292
+}));
293
+//# sourceMappingURL=dropdown_input.js.map