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,145 @@
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
+ * Plugin: "dropdown_header" (Tom Select)
103
+ * Copyright (c) contributors
104
+ *
105
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
106
+ * file except in compliance with the License. You may obtain a copy of the License at:
107
+ * http://www.apache.org/licenses/LICENSE-2.0
108
+ *
109
+ * Unless required by applicable law or agreed to in writing, software distributed under
110
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
111
+ * ANY KIND, either express or implied. See the License for the specific language
112
+ * governing permissions and limitations under the License.
113
+ *
114
+ */
115
+function plugin (userOptions) {
116
+  const self = this;
117
+  const options = Object.assign({
118
+    className: 'clear-button',
119
+    title: 'Clear All',
120
+    html: data => {
121
+      return `<div class="${data.className}" title="${data.title}">&#10799;</div>`;
122
+    }
123
+  }, userOptions);
124
+  self.on('initialize', () => {
125
+    var button = getDom(options.html(options));
126
+    button.addEventListener('click', evt => {
127
+      if (self.isDisabled) {
128
+        return;
129
+      }
130
+
131
+      self.clear();
132
+
133
+      if (self.settings.mode === 'single' && self.settings.allowEmptyOption) {
134
+        self.addItem('');
135
+      }
136
+
137
+      evt.preventDefault();
138
+      evt.stopPropagation();
139
+    });
140
+    self.control.appendChild(button);
141
+  });
142
+}
143
+
144
+export { plugin as default };
145
+//# sourceMappingURL=plugin.js.map