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,180 @@
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_header = factory());
10
+})(this, (function () { 'use strict';
11
+
12
+  /*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
13
+  const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}\u{2bc}]';
14
+  /** @type {TUnicodeMap} */
15
+
16
+  const latin_convert = {};
17
+  /** @type {TUnicodeMap} */
18
+
19
+  const latin_condensed = {
20
+    '/': '⁄∕',
21
+    '0': '߀',
22
+    "a": "ⱥɐɑ",
23
+    "aa": "ꜳ",
24
+    "ae": "æǽǣ",
25
+    "ao": "ꜵ",
26
+    "au": "ꜷ",
27
+    "av": "ꜹꜻ",
28
+    "ay": "ꜽ",
29
+    "b": "ƀɓƃ",
30
+    "c": "ꜿƈȼↄ",
31
+    "d": "đɗɖᴅƌꮷԁɦ",
32
+    "e": "ɛǝᴇɇ",
33
+    "f": "ꝼƒ",
34
+    "g": "ǥɠꞡᵹꝿɢ",
35
+    "h": "ħⱨⱶɥ",
36
+    "i": "ɨı",
37
+    "j": "ɉȷ",
38
+    "k": "ƙⱪꝁꝃꝅꞣ",
39
+    "l": "łƚɫⱡꝉꝇꞁɭ",
40
+    "m": "ɱɯϻ",
41
+    "n": "ꞥƞɲꞑᴎлԉ",
42
+    "o": "øǿɔɵꝋꝍᴑ",
43
+    "oe": "œ",
44
+    "oi": "ƣ",
45
+    "oo": "ꝏ",
46
+    "ou": "ȣ",
47
+    "p": "ƥᵽꝑꝓꝕρ",
48
+    "q": "ꝗꝙɋ",
49
+    "r": "ɍɽꝛꞧꞃ",
50
+    "s": "ßȿꞩꞅʂ",
51
+    "t": "ŧƭʈⱦꞇ",
52
+    "th": "þ",
53
+    "tz": "ꜩ",
54
+    "u": "ʉ",
55
+    "v": "ʋꝟʌ",
56
+    "vy": "ꝡ",
57
+    "w": "ⱳ",
58
+    "y": "ƴɏỿ",
59
+    "z": "ƶȥɀⱬꝣ",
60
+    "hv": "ƕ"
61
+  };
62
+
63
+  for (let latin in latin_condensed) {
64
+    let unicode = latin_condensed[latin] || '';
65
+
66
+    for (let i = 0; i < unicode.length; i++) {
67
+      let char = unicode.substring(i, i + 1);
68
+      latin_convert[char] = latin;
69
+    }
70
+  }
71
+
72
+  new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');
73
+
74
+  /**
75
+   * Return a dom element from either a dom query string, jQuery object, a dom element or html string
76
+   * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518
77
+   *
78
+   * param query should be {}
79
+   */
80
+
81
+  const getDom = query => {
82
+    if (query.jquery) {
83
+      return query[0];
84
+    }
85
+
86
+    if (query instanceof HTMLElement) {
87
+      return query;
88
+    }
89
+
90
+    if (isHtmlString(query)) {
91
+      var tpl = document.createElement('template');
92
+      tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result
93
+
94
+      return tpl.content.firstChild;
95
+    }
96
+
97
+    return document.querySelector(query);
98
+  };
99
+  const isHtmlString = arg => {
100
+    if (typeof arg === 'string' && arg.indexOf('<') > -1) {
101
+      return true;
102
+    }
103
+
104
+    return false;
105
+  };
106
+
107
+  /**
108
+   * Converts a scalar to its best string representation
109
+   * for hash keys and HTML attribute values.
110
+   *
111
+   * Transformations:
112
+   *   'str'     -> 'str'
113
+   *   null      -> ''
114
+   *   undefined -> ''
115
+   *   true      -> '1'
116
+   *   false     -> '0'
117
+   *   0         -> '0'
118
+   *   1         -> '1'
119
+   *
120
+   */
121
+  /**
122
+   * Prevent default
123
+   *
124
+   */
125
+
126
+  const preventDefault = (evt, stop = false) => {
127
+    if (evt) {
128
+      evt.preventDefault();
129
+
130
+      if (stop) {
131
+        evt.stopPropagation();
132
+      }
133
+    }
134
+  };
135
+
136
+  /**
137
+   * Plugin: "dropdown_header" (Tom Select)
138
+   * Copyright (c) contributors
139
+   *
140
+   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
141
+   * file except in compliance with the License. You may obtain a copy of the License at:
142
+   * http://www.apache.org/licenses/LICENSE-2.0
143
+   *
144
+   * Unless required by applicable law or agreed to in writing, software distributed under
145
+   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
146
+   * ANY KIND, either express or implied. See the License for the specific language
147
+   * governing permissions and limitations under the License.
148
+   *
149
+   */
150
+  function plugin (userOptions) {
151
+    const self = this;
152
+    const options = Object.assign({
153
+      title: 'Untitled',
154
+      headerClass: 'dropdown-header',
155
+      titleRowClass: 'dropdown-header-title',
156
+      labelClass: 'dropdown-header-label',
157
+      closeClass: 'dropdown-header-close',
158
+      html: data => {
159
+        return '<div class="' + data.headerClass + '">' + '<div class="' + data.titleRowClass + '">' + '<span class="' + data.labelClass + '">' + data.title + '</span>' + '<a class="' + data.closeClass + '">&times;</a>' + '</div>' + '</div>';
160
+      }
161
+    }, userOptions);
162
+    self.on('initialize', () => {
163
+      var header = getDom(options.html(options));
164
+      var close_link = header.querySelector('.' + options.closeClass);
165
+
166
+      if (close_link) {
167
+        close_link.addEventListener('click', evt => {
168
+          preventDefault(evt, true);
169
+          self.close();
170
+        });
171
+      }
172
+
173
+      self.dropdown.insertBefore(header, self.dropdown.firstChild);
174
+    });
175
+  }
176
+
177
+  return plugin;
178
+
179
+}));
180
+//# sourceMappingURL=dropdown_header.js.map