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